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

Support #__PURE__ and #__NO_SIDE_EFFECTS__ notation #9193

Open
Boshen opened this issue Feb 18, 2025 · 8 comments
Open

Support #__PURE__ and #__NO_SIDE_EFFECTS__ notation #9193

Boshen opened this issue Feb 18, 2025 · 8 comments
Assignees
Labels
C-enhancement Category - New feature or request needs-discussion Requires a discussion from the core team

Comments

@Boshen
Copy link
Member

Boshen commented Feb 18, 2025

Background: https://github.com/javascript-compiler-hints/compiler-notations-spec

@Boshen Boshen added the C-enhancement Category - New feature or request label Feb 18, 2025
@Boshen Boshen self-assigned this Feb 18, 2025
@Boshen
Copy link
Member Author

Boshen commented Feb 18, 2025

I propose a no_side_effects: bool field to be added to CallExpression, NewExpression, and Function. These values are set in the parser, or upon construction in the transformer, and read from in codegen and minifier.

@Boshen Boshen added the needs-discussion Requires a discussion from the core team label Feb 18, 2025
@Boshen Boshen changed the title #__PURE__ and #__NO_SIDE_EFFECTS__ notation Support #__PURE__ and #__NO_SIDE_EFFECTS__ notation Feb 18, 2025
@IWANABETHATGUY
Copy link
Contributor

This method did not scale, if the downstream app required more annotation

@Boshen
Copy link
Member Author

Boshen commented Feb 18, 2025

This method did not scale, if the downstream app required more annotation

Can you give us an example?

@IWANABETHATGUY
Copy link
Contributor

vite has a special magic comments vite-ignore to let user explicit control bundler behavior. ref: https://github.com/rolldown/rolldown/blob/b546e53adf0d8fecbca8a9f0dddbcb44cb308a99/crates/rolldown/src/ast_scanner/new_url.rs?plain=1#L35-L43
vitejs/vite#18494, webpack also has some special meaning magic comments

@IWANABETHATGUY
Copy link
Contributor

https://github.com/rolldown/rolldown/blob/b546e53adf0d8fecbca8a9f0dddbcb44cb308a99/crates/rolldown/src/ast_scanner/new_url.rs?plain=1#L35-L43, for now this code works fine when the ast is parsed from source code, but will not work if the ast is generated by transformer. If use the method you proposed, you may need to add many flag to support other widely used tools.

@IWANABETHATGUY
Copy link
Contributor

What about use a hashmap to store leading comments of some generated node, the key should be their Address

@IWANABETHATGUY
Copy link
Contributor

But I think your method is good enough for rolldown and vite

@Boshen
Copy link
Member Author

Boshen commented Feb 18, 2025

#__PURE__ and #__NO_SIDE_EFFECTS__ has semantic meanings that affect the whole compiler pipeline, whereas other annotations don't.

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 needs-discussion Requires a discussion from the core team
Projects
None yet
Development

No branches or pull requests

2 participants