Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: print esbuild trailing legal comments #7190

Closed
hyf0 opened this issue Nov 7, 2024 · 4 comments
Closed

codegen: print esbuild trailing legal comments #7190

hyf0 opened this issue Nov 7, 2024 · 4 comments
Assignees
Labels
C-enhancement Category - New feature or request

Comments

@hyf0
Copy link
Contributor

hyf0 commented Nov 7, 2024

//! <script>foo</script>
export let x

console.log('in a') //! Copyright notice 1

console.log('in b') //! Copyright notice 1

console.log('in c') //! Copyright notice 2

export default () => {
	/**
	 * @preserve
	 */
}

output(pure codeggen, without bundling)

//! <script>foo</script>
export let x;
console.log("in a");
console.log("in b");
console.log("in c");
export default () => {};

esbuild

// entry.js
//! <script>foo<\/script>
var x;
console.log("in a");
//! Copyright notice 1
console.log("in b");
//! Copyright notice 1
console.log("in c");
//! Copyright notice 2
var entry_default = () => {
  /**
   * @preserve
   */
};
export {
  entry_default as default,
  x
};
@hyf0
Copy link
Contributor Author

hyf0 commented Nov 7, 2024

It would be nice if the codegen part of playground support comment-related options.

@Boshen Boshen self-assigned this Nov 7, 2024
Boshen added a commit that referenced this issue Nov 11, 2024
Boshen added a commit that referenced this issue Nov 11, 2024
@Boshen Boshen changed the title Print more legal comments codegen: print more legal comments Nov 11, 2024
@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

I fixed the empty body case.

The console.log('in a') //! Copyright notice 1 case contradicts to the documentation https://esbuild.github.io/api/#legal-comments

Note that "statement-level" for JS and "rule-level" for CSS means the comment must appear in a context where multiple statements or rules are allowed such as in the top-level scope or in a statement or rule block. So comments inside expressions or at the declaration level are not considered legal comments.

esbuild's parser saved these trailing comments as statement level comments

https://github.com/evanw/esbuild/blob/9eca46464ed5615cb36a3beb3f7a7b9a8ffbe7cf/internal/js_parser/js_parser.go#L8154-L8166

I'm undecided whether we should handle such cases. It takes a lot more work to handle such cases.

@hyf0
Copy link
Contributor Author

hyf0 commented Nov 11, 2024

Since printing legal comments only have a pratical standard from esbuild, I guess we could wait for users feedback and decide what's next.

@Boshen Boshen changed the title codegen: print more legal comments codegen: print esbuild trailing legal comments Nov 12, 2024
@Boshen
Copy link
Member

Boshen commented Nov 20, 2024

Agree. Close as not planned.

@Boshen Boshen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants