-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Move pure comment annotation to Graph.contextParse #3981
Merged
lukastaegert
merged 8 commits into
rollup:master
from
yannayl:fix-module-parse-ast-respect-pure-annotation
Mar 9, 2021
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b899701
Move pure comment annotation to Graph.contextParse
1b78532
Remove unused import
1c599c8
Add test call-marked-pure-with-plugin-parse-ast
2ba2a46
Improv test call-marked-pure-with-plugin-parse-ast
43edcca
Change type CommentDescription -> acorn.Comment
698d2c9
Rename annotations in acron.Node
dc93f2e
Remove '_rollupAnnotations' key from Node.keys
d4e3db5
Remove dead code
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/function/samples/call-marked-pure-with-plugin-parse-ast/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'external function calls marked with pure comment do not have effects and should be removed even if parsed by PluginContext.parse method', | ||
options: { | ||
external: ['socks'], | ||
plugins:[{ | ||
transform(code, _id) { | ||
const comments = []; | ||
const ast = this.parse(code, {onComment: comments}); | ||
if (comments.length != 5 || comments.some(({value}) => !value.includes('PURE'))) { | ||
throw new Error('failed to get comments'); | ||
} | ||
return {ast, code, map: null}; | ||
}, | ||
}], | ||
}, | ||
context: { | ||
require(id) { | ||
if (id === 'socks') { | ||
return () => { | ||
throw new Error('Not all socks were removed.'); | ||
}; | ||
} | ||
} | ||
}, | ||
code(code) { | ||
assert.ok(code.search(/socks\(\)/) === -1); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/function/samples/call-marked-pure-with-plugin-parse-ast/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import socks from 'socks'; | ||
|
||
/*#__PURE__*/ socks(); | ||
/* #__PURE__*/ socks(); | ||
/*#__PURE__ */ socks(); | ||
/* #__PURE__ */ socks(); | ||
// #__PURE__ | ||
socks(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mapping strikes me as unnecessary if you either push the comments into the array in the previous way or change markPureCallExpressions to work with a slightly changed format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I will change it.
In general I try to keep my changes minimal because it's my first contribution and I don't want to accidentally break anything...