-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix: AST_Accessor missing start / end tokens #1493
Closed
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e587f3b
Fix: AST_Accessor missing start / end tokens - #1492
OndrejSpanel 84adda7
Test case for the fix.
OndrejSpanel 4394fe7
Improved the test case - test tokens against expected values.
OndrejSpanel 37ea9df
Implement createAccessor using embed_tokens.
OndrejSpanel 97e55c3
Travis, please try again.
OndrejSpanel 452e2d3
Testing AST_SymbolRef and AST_ObjectProperty as well.
OndrejSpanel 8aff233
Refactor as required (scope, naming).
OndrejSpanel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var UglifyJS = require('../../'); | ||
var assert = require("assert"); | ||
|
||
describe("Accessor tokens", function() { | ||
it("Should fill the token information for accessors (issue #1492)", function() { | ||
var ast = UglifyJS.parse("var obj = { get latest() { return undefined; } }"); | ||
|
||
/* a possible way to test, but walking through the whole tree seems more robust against possible AST changes | ||
var accessor = ast.body["0"].definitions["0"].value.properties["0"].value; | ||
assert(accessor instanceof UglifyJS.AST_Accessor); | ||
assert(accessor.start !== undefined); | ||
assert(accessor.end !== undefined); | ||
*/ | ||
|
||
// test there are no nodes without tokens | ||
var checkWalker = new UglifyJS.TreeWalker(function(node, descend) { | ||
assert(node.start !== undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, can we be more precise about the value of Preferably with the source code under test spans multiple lines so we can reasonably sure the fields have been populated with sensible values? |
||
assert(node.end !== undefined); | ||
}); | ||
ast.walk(checkWalker); | ||
}); | ||
}); |
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 looks somewhat similar to
embed_tokens()
which is use extensively throughout this file. Would you mind considering whether we can reuse that in this case as well?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 do not mind, however this is beyond my current JS abilities. What I have tried is:
This resulted in a parse error. If you can advise me how do to his properly, I will be glad to implement it.
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'm typing from mobile, but this might work:
If not, I'll be back in a couple of hours and will take a look then.
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.
Tried that (and thought: "Silly me. off course I have to return in JS, this is not Scala "), but I still get the parsing error:
My code was:
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'm confused - did you try my suggestion or yours? Yours has an extra
function() {...}
wrapped around it.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 tried both, first what you wrote, then this - I was afraid your solution executes outside of the get / set scopes, now I see it does not - it returns a function, and executes nothing on its own.
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.
Thanks for clarifying. I'll have a closer look when I get home.
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 have tried your solution once again and I see its error is different. It outputs no parsing error, only the test is not passed, with assertion:
What is the correct result - In the test code
var obj = { get latest() { return undefined; } }
, where should the accessor node start? Pos. 22 is right behindlatest
, pos. 12 is the beginning ofget
.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.
Checking http://lisperator.net/uglifyjs/ast, I think 22 makes more sense as a result,
AST_Accessor
is a child ofAST_Lambda
, and has no name. I am committing your implementation and adjusting the test,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.
@OndrejSpanel thanks for the detailed investigation 👍