Conflicts:
	acorn.js
This commit is contained in:
Sebastian McKenzie 2015-01-23 23:16:08 +11:00
commit cb76f3f7ba
2 changed files with 58 additions and 4 deletions

View File

@ -659,8 +659,8 @@
var b_stat = {token: "{", isExpr: false}, b_expr = {token: "{", isExpr: true}, b_tmpl = {token: "${", isExpr: true};
var p_stat = {token: "(", isExpr: false}, p_expr = {token: "(", isExpr: true};
var q_tmpl = {token: "`", isExpr: true};
var j_oTag = {token: "<tag", isExpr: false}, j_cTag = {token: "</tag", isExpr: false}, j_expr = {token: "<tag>...</tag>", isExpr: true};
var q_tmpl = {token: "`", isExpr: true}, f_expr = {token: "function", isExpr: true};
function curTokContext() {
return tokContext[tokContext.length - 1];
@ -698,8 +698,14 @@
// Update context info
if (type === _parenR || type === _braceR) {
var out = tokContext.pop();
tokExprAllowed = !(out && out.isExpr);
preserveSpace = out === b_tmpl || curTokContext() === j_expr;
if (out === b_tmpl) {
preserveSpace = true;
} else if (out === b_stat && curTokContext() === f_expr) {
tokContext.pop();
tokExprAllowed = false;
} else {
tokExprAllowed = !(out && out.isExpr);
}
} else if (type === _braceL) {
tokContext.push(braceIsBlock(prevType) ? b_stat : b_expr);
tokExprAllowed = true;
@ -714,7 +720,10 @@
// tokExprAllowed stays unchanged
} else if (type.keyword && prevType == _dot) {
tokExprAllowed = false;
} else if (tokExprAllowed && type == _function) {
} else if (type == _function) {
if (curTokContext() !== b_stat) {
tokContext.push(f_expr);
}
tokExprAllowed = false;
} else if (type === _backQuote) {
if (curTokContext() === q_tmpl) {

View File

@ -28862,3 +28862,48 @@ test("#!/usr/bin/node\n;", {}, {
end: 15
}]
});
// https://github.com/marijnh/acorn/issues/204
test("(function () {} / 1)", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "BinaryExpression",
left: {
type: "FunctionExpression",
id: null,
params: [],
body: {
type: "BlockStatement",
body: []
}
},
operator: "/",
right: {type: "Literal", value: 1}
}
}]
});
test("function f() {} / 1 /", {
type: "Program",
body: [
{
type: "FunctionDeclaration",
id: {type: "Identifier", name: "f"},
params: [],
body: {
type: "BlockStatement",
body: []
}
},
{
type: "ExpressionStatement",
expression: {
type: "Literal",
regex: {pattern: " 1 ", flags: ""},
value: {}
}
}
]
});