Implement createAccessor using embed_tokens.
Adjusted test to match expected result.
This commit is contained in:
parent
4394fe7dcf
commit
37ea9df24f
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user