Implement createAccessor using embed_tokens.

Adjusted test to match expected result.
This commit is contained in:
Ondřej Španěl 2017-02-16 13:55:24 +01:00
parent 4394fe7dcf
commit 37ea9df24f
2 changed files with 6 additions and 14 deletions

View File

@ -1320,12 +1320,9 @@ function parse($TEXT, options) {
var type = start.type; var type = start.type;
var name = as_property_name(); var name = as_property_name();
if (type == "name" && !is("punc", ":")) { if (type == "name" && !is("punc", ":")) {
var createAccessor = function() { var createAccessor = embed_tokens(function() {
var func = function_(AST_Accessor); return function_(AST_Accessor);
func.start = start; });
func.end = prev();
return func;
};
if (name == "get") { if (name == "get") {
a.push(new AST_ObjectGetter({ a.push(new AST_ObjectGetter({
start : start, start : start,

View File

@ -3,19 +3,14 @@ var assert = require("assert");
describe("Accessor tokens", function() { describe("Accessor tokens", function() {
it("Should fill the token information for accessors (issue #1492)", 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; } }"); 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 // test there are no nodes without tokens
var checkWalker = new UglifyJS.TreeWalker(function(node, descend) { var checkWalker = new UglifyJS.TreeWalker(function(node, descend) {
if (node instanceof UglifyJS.AST_Accessor) { if (node instanceof UglifyJS.AST_Accessor) {
assert.equal(node.start.pos, 12); assert.equal(node.start.pos, 22);
assert.equal(node.end.endpos, 46); assert.equal(node.end.endpos, 46);
} }
}); });