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

Extracted babel-helper-annotate-as-pure #6267

Merged
merged 1 commit into from
Sep 25, 2017

Conversation

Andarist
Copy link
Member

Q                       A
Fixed Issues n/a
Patch: Bug Fix? no
Major: Breaking Change? no
Minor: New Feature? yes
Tests Added/Pass? yes
Spec Compliancy? n/a
License MIT
Doc PR no
Any Dependency Changes? no

This code is extracted from the #6231 and generally already got reviewed. I've split the mentioned PR into 2 because this part is ready and independent, the other one though still needs some discussion and approval.

@babel-bot
Copy link
Collaborator

babel-bot commented Sep 18, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4999/

if (leadingComments === undefined) {
return false;
}
return leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
Copy link
Member

@Jessidhia Jessidhia Sep 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a good way to prevent false positives here (so it doesn't match, say, "#__PURE___")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this test is taken from the UglifyJS' source code, it tests it exactly like this, foo #__PURE__ bar are also allowed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be convenient to have an PureAnnotation node in the Babel AST because It would probably be simpler to detect and manage. I assume babel/minify will also take advantage of it during minification.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xtuc I dont think thats actually possible, because ast -> code -> ast are not inverse operations (in mathematics sense) regarding comments

i.e. if we annotate each CallExpression with a leading comment in fn()()() we'll end up with nice AST - 1 comment for each node, when we generate code, we'll end up with

/*foo*//*foo*//*foo*/fn()()()

And ofc if we go back to AST again we'll end up with 3 comments on the outermost CallExpression

if (leadingComments === undefined) {
return false;
}
return leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be convenient to have an PureAnnotation node in the Babel AST because It would probably be simpler to detect and manage. I assume babel/minify will also take advantage of it during minification.

@existentialism existentialism added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Sep 25, 2017
@Andarist Andarist merged commit 413ffe6 into babel:master Sep 25, 2017
@Andarist Andarist deleted the annotate-as-pure branch September 25, 2017 15:40
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants