diff --git a/lib/parse.js b/lib/parse.js index 718e457f..08de03f2 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1320,12 +1320,9 @@ function parse($TEXT, options) { var type = start.type; var name = as_property_name(); if (type == "name" && !is("punc", ":")) { - var createAccessor = function() { - var func = function_(AST_Accessor); - func.start = start; - func.end = prev(); - return func; - }; + var createAccessor = embed_tokens(function() { + return function_(AST_Accessor); + }); if (name == "get") { a.push(new AST_ObjectGetter({ start : start, diff --git a/test/mocha/accessorTokens-1492.js b/test/mocha/accessorTokens-1492.js index 4428d76a..05300c31 100644 --- a/test/mocha/accessorTokens-1492.js +++ b/test/mocha/accessorTokens-1492.js @@ -3,19 +3,14 @@ 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; } }"); - /* 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) { if (node instanceof UglifyJS.AST_Accessor) { - assert.equal(node.start.pos, 12); + assert.equal(node.start.pos, 22); assert.equal(node.end.endpos, 46); } });