Support for for (const ...).

Fixes #213.

Also changes API to pass token type to `parseVar` to reduce string comparison ops.
This commit is contained in:
Ingvar Stepanyan
2015-03-10 11:36:15 +02:00
parent ff60ee4fdb
commit 34050d3917
4 changed files with 95 additions and 8 deletions

View File

@@ -14970,6 +14970,55 @@ test("class A { static() {} }", {
locations: true
});
// https://github.com/marijnh/acorn/issues/213
test("for (const x of list) process(x);", {
type: "Program",
body: [{
type: "ForOfStatement",
left: {
type: "VariableDeclaration",
declarations: [{
type: "VariableDeclarator",
id: {
type: "Identifier",
name: "x",
range: [11, 12]
},
init: null,
range: [11, 12]
}],
kind: "const",
range: [5, 12]
},
right: {
type: "Identifier",
name: "list",
range: [16, 20]
},
body: {
type: "ExpressionStatement",
expression: {
type: "CallExpression",
callee: {
type: "Identifier",
name: "process",
range: [22, 29]
},
arguments: [{
type: "Identifier",
name: "x",
range: [30, 31]
}],
range: [22, 32]
},
range: [22, 33]
},
range: [0, 33]
}],
range: [0, 33]
}, {ecmaVersion: 6, ranges: true});
test("class A { *static() {} }", {
type: "Program",
range: [0, 24],

View File

@@ -28682,7 +28682,39 @@ test("const x = 14, y = 3, z = 1977", {
testFail("const a;", "Unexpected token (1:7)", {ecmaVersion: 6});
testFail("for(const x = 0;;);", "Unexpected token (1:4)", {ecmaVersion: 6});
test("for(const x = 0;;);", {
type: "Program",
body: [{
type: "ForStatement",
init: {
type: "VariableDeclaration",
declarations: [{
type: "VariableDeclarator",
id: {
type: "Identifier",
name: "x",
range: [10, 11]
},
init: {
type: "Literal",
value: 0,
range: [14, 15]
},
range: [10, 15]
}],
kind: "const",
range: [4, 15]
},
test: null,
update: null,
body: {
type: "EmptyStatement",
range: [18, 19]
},
range: [0, 19]
}],
range: [0, 19]
}, {ecmaVersion: 6, ranges: true});
testFail("for(x of a);", "Unexpected token (1:6)");