Skip to content

Commit

Permalink
Fix: AST_Accessor missing start / end tokens
Browse files Browse the repository at this point in the history
fixes #1492
closes #1493
  • Loading branch information
OndrejSpanel authored and alexlamsl committed Feb 20, 2017
1 parent 4c0abda commit 89e94b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,10 @@ function parse($TEXT, options) {
});
});

var create_accessor = embed_tokens(function() {
return function_(AST_Accessor);
});

var object_ = embed_tokens(function() {
expect("{");
var first = true, a = [];
Expand All @@ -1324,7 +1328,7 @@ function parse($TEXT, options) {
a.push(new AST_ObjectGetter({
start : start,
key : as_atom_node(),
value : function_(AST_Accessor),
value : create_accessor(),
end : prev()
}));
continue;
Expand All @@ -1333,7 +1337,7 @@ function parse($TEXT, options) {
a.push(new AST_ObjectSetter({
start : start,
key : as_atom_node(),
value : function_(AST_Accessor),
value : create_accessor(),
end : prev()
}));
continue;
Expand Down
32 changes: 32 additions & 0 deletions test/mocha/accessorTokens-1492.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var UglifyJS = require('../../');
var assert = require("assert");

describe("Accessor tokens", function() {
it("Should fill the token information for accessors (issue #1492)", function() {
// location 0 1 2 3 4
// 01234567890123456789012345678901234567890123456789
var ast = UglifyJS.parse("var obj = { get latest() { return undefined; } }");

// test all AST_ObjectProperty tokens are set as expected
var checkedAST_ObjectProperty = false;
var checkWalker = new UglifyJS.TreeWalker(function(node, descend) {
if (node instanceof UglifyJS.AST_ObjectProperty) {
checkedAST_ObjectProperty = true;

assert.equal(node.start.pos, 12);
assert.equal(node.end.endpos, 46);

assert(node.key instanceof UglifyJS.AST_SymbolRef);
assert.equal(node.key.start.pos, 16);
assert.equal(node.key.end.endpos, 22);

assert(node.value instanceof UglifyJS.AST_Accessor);
assert.equal(node.value.start.pos, 22);
assert.equal(node.value.end.endpos, 46);

}
});
ast.walk(checkWalker);
assert(checkedAST_ObjectProperty, "AST_ObjectProperty not found");
});
});

0 comments on commit 89e94b2

Please sign in to comment.