Allow static as method name in class (fixes #192).
Add uncommitted tests for #191.
This commit is contained in:
parent
3d9048a692
commit
bc2e01aa03
11
acorn.js
11
acorn.js
@ -2510,14 +2510,17 @@
|
|||||||
expect(_braceL);
|
expect(_braceL);
|
||||||
while (!eat(_braceR)) {
|
while (!eat(_braceR)) {
|
||||||
var method = startNode();
|
var method = startNode();
|
||||||
if (tokType === _name && tokVal === "static") {
|
var isGenerator = eat(_star);
|
||||||
next();
|
parsePropertyName(method);
|
||||||
|
if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" &&
|
||||||
|
method.key.name === "static") {
|
||||||
|
if (isGenerator) unexpected();
|
||||||
method['static'] = true;
|
method['static'] = true;
|
||||||
|
isGenerator = eat(_star);
|
||||||
|
parsePropertyName(method);
|
||||||
} else {
|
} else {
|
||||||
method['static'] = false;
|
method['static'] = false;
|
||||||
}
|
}
|
||||||
var isGenerator = eat(_star);
|
|
||||||
parsePropertyName(method);
|
|
||||||
if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" &&
|
if (tokType !== _parenL && !method.computed && method.key.type === "Identifier" &&
|
||||||
(method.key.name === "get" || method.key.name === "set")) {
|
(method.key.name === "get" || method.key.name === "set")) {
|
||||||
if (isGenerator) unexpected();
|
if (isGenerator) unexpected();
|
||||||
|
|||||||
@ -862,7 +862,7 @@
|
|||||||
var prop = startNode(), isGenerator;
|
var prop = startNode(), isGenerator;
|
||||||
if (options.ecmaVersion >= 6) {
|
if (options.ecmaVersion >= 6) {
|
||||||
if (isClass) {
|
if (isClass) {
|
||||||
if (prop['static'] = (token.type === tt.name && token.value === "static")) next();
|
prop['static'] = false;
|
||||||
} else {
|
} else {
|
||||||
prop.method = false;
|
prop.method = false;
|
||||||
prop.shorthand = false;
|
prop.shorthand = false;
|
||||||
@ -871,6 +871,16 @@
|
|||||||
}
|
}
|
||||||
parsePropertyName(prop);
|
parsePropertyName(prop);
|
||||||
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
|
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
|
||||||
|
if (isClass) {
|
||||||
|
if (prop.key.type === "Identifier" && !prop.computed && prop.key.name === "static" &&
|
||||||
|
(token.type != tt.parenL && token.type != tt.braceL)) {
|
||||||
|
prop['static'] = true;
|
||||||
|
isGenerator = eat(tt.star);
|
||||||
|
parsePropertyName(prop);
|
||||||
|
} else {
|
||||||
|
prop['static'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!isClass && eat(tt.colon)) {
|
if (!isClass && eat(tt.colon)) {
|
||||||
prop.kind = "init";
|
prop.kind = "init";
|
||||||
prop.value = parseExpression(true);
|
prop.value = parseExpression(true);
|
||||||
@ -883,7 +893,7 @@
|
|||||||
}
|
}
|
||||||
prop.value = parseMethod(isGenerator);
|
prop.value = parseMethod(isGenerator);
|
||||||
} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
|
} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
|
||||||
(prop.key.name === "get" || prop.key.name === "set") &&
|
!prop.computed && (prop.key.name === "get" || prop.key.name === "set") &&
|
||||||
(token.type != tt.comma && token.type != tt.braceR)) {
|
(token.type != tt.comma && token.type != tt.braceR)) {
|
||||||
prop.kind = prop.key.name;
|
prop.kind = prop.key.name;
|
||||||
parsePropertyName(prop);
|
parsePropertyName(prop);
|
||||||
|
|||||||
@ -14598,3 +14598,160 @@ test("var [localVar = defaultValue] = obj", {
|
|||||||
locations: true,
|
locations: true,
|
||||||
loose: false
|
loose: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/marijnh/acorn/issues/191
|
||||||
|
|
||||||
|
test("try {} catch ({message}) {}", {
|
||||||
|
type: "Program",
|
||||||
|
range: [0, 27],
|
||||||
|
body: [{
|
||||||
|
type: "TryStatement",
|
||||||
|
range: [0, 27],
|
||||||
|
block: {
|
||||||
|
type: "BlockStatement",
|
||||||
|
range: [4, 6],
|
||||||
|
body: []
|
||||||
|
},
|
||||||
|
handler: {
|
||||||
|
type: "CatchClause",
|
||||||
|
range: [7, 27],
|
||||||
|
param: {
|
||||||
|
type: "ObjectPattern",
|
||||||
|
range: [14, 23],
|
||||||
|
properties: [{
|
||||||
|
type: "Property",
|
||||||
|
range: [15, 22],
|
||||||
|
method: false,
|
||||||
|
shorthand: true,
|
||||||
|
computed: false,
|
||||||
|
key: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [15, 22],
|
||||||
|
name: "message"
|
||||||
|
},
|
||||||
|
kind: "init",
|
||||||
|
value: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [15, 22],
|
||||||
|
name: "message"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
guard: null,
|
||||||
|
body: {
|
||||||
|
type: "BlockStatement",
|
||||||
|
range: [25, 27],
|
||||||
|
body: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
guardedHandlers: [],
|
||||||
|
finalizer: null
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
ecmaVersion: 6,
|
||||||
|
ranges: true,
|
||||||
|
locations: true,
|
||||||
|
loose: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// https://github.com/marijnh/acorn/issues/192
|
||||||
|
|
||||||
|
test("class A { static() {} }", {
|
||||||
|
type: "Program",
|
||||||
|
range: [0, 23],
|
||||||
|
body: [{
|
||||||
|
type: "ClassDeclaration",
|
||||||
|
range: [0, 23],
|
||||||
|
id: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [6, 7],
|
||||||
|
name: "A"
|
||||||
|
},
|
||||||
|
superClass: null,
|
||||||
|
body: {
|
||||||
|
type: "ClassBody",
|
||||||
|
range: [8, 23],
|
||||||
|
body: [{
|
||||||
|
type: "MethodDefinition",
|
||||||
|
range: [10, 21],
|
||||||
|
computed: false,
|
||||||
|
key: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [10, 16],
|
||||||
|
name: "static"
|
||||||
|
},
|
||||||
|
static: false,
|
||||||
|
kind: "",
|
||||||
|
value: {
|
||||||
|
type: "FunctionExpression",
|
||||||
|
range: [16, 21],
|
||||||
|
id: null,
|
||||||
|
params: [],
|
||||||
|
defaults: [],
|
||||||
|
rest: null,
|
||||||
|
generator: false,
|
||||||
|
body: {
|
||||||
|
type: "BlockStatement",
|
||||||
|
range: [19, 21],
|
||||||
|
body: []
|
||||||
|
},
|
||||||
|
expression: false
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
ecmaVersion: 6,
|
||||||
|
ranges: true,
|
||||||
|
locations: true
|
||||||
|
});
|
||||||
|
|
||||||
|
test("class A { *static() {} }", {
|
||||||
|
type: "Program",
|
||||||
|
range: [0, 24],
|
||||||
|
body: [{
|
||||||
|
type: "ClassDeclaration",
|
||||||
|
range: [0, 24],
|
||||||
|
id: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [6, 7],
|
||||||
|
name: "A"
|
||||||
|
},
|
||||||
|
superClass: null,
|
||||||
|
body: {
|
||||||
|
type: "ClassBody",
|
||||||
|
range: [8, 24],
|
||||||
|
body: [{
|
||||||
|
type: "MethodDefinition",
|
||||||
|
range: [10, 22],
|
||||||
|
computed: false,
|
||||||
|
key: {
|
||||||
|
type: "Identifier",
|
||||||
|
range: [11, 17],
|
||||||
|
name: "static"
|
||||||
|
},
|
||||||
|
static: false,
|
||||||
|
kind: "",
|
||||||
|
value: {
|
||||||
|
type: "FunctionExpression",
|
||||||
|
range: [17, 22],
|
||||||
|
id: null,
|
||||||
|
params: [],
|
||||||
|
defaults: [],
|
||||||
|
rest: null,
|
||||||
|
generator: true,
|
||||||
|
body: {
|
||||||
|
type: "BlockStatement",
|
||||||
|
range: [20, 22],
|
||||||
|
body: []
|
||||||
|
},
|
||||||
|
expression: false
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
ecmaVersion: 6,
|
||||||
|
ranges: true,
|
||||||
|
locations: true
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user