[Pkg-javascript-commits] [uglifyjs] 37/228: Fix: AST_Accessor missing start / end tokens
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:14 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit d48a3080ac873ae531a2d87679a26c5941814843
Author: Ondřej Španěl <OndrejSpanel at users.noreply.github.com>
Date: Mon Feb 20 17:14:53 2017 +0800
Fix: AST_Accessor missing start / end tokens
fixes #1492
closes #1493
---
lib/parse.js | 8 ++++++--
test/mocha/accessorTokens-1492.js | 32 ++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/lib/parse.js b/lib/parse.js
index ec82d47..37f06df 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -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 = [];
@@ -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;
@@ -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;
diff --git a/test/mocha/accessorTokens-1492.js b/test/mocha/accessorTokens-1492.js
new file mode 100644
index 0000000..861414e
--- /dev/null
+++ b/test/mocha/accessorTokens-1492.js
@@ -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");
+ });
+});
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list