[loose parser] Fix interpretation of f."
Before this the ast produced by parse_dammit crashed in the following
code, as Uglify correctly noticed that f."" is invalid.
sample = 'f."';
loose = require('acorn/acorn_loose');
uglify = require('uglify-js');
out = new uglify.OutputStream();
ast = loose.parse_dammit(sample);
ast = uglify.AST_Node.from_mozilla_ast(ast);
ast.print(out);
// TypeError: Cannot call method 'toString' of undefined
// member_exp.computed = false && member_exp.property == ""
console.log(out.toString());
After this the round-tripped AST looks like: `t.✖;"";`, which is
consistent with how `foo.{` is parsed.
I also considered making it parse as t[""], but as this only turns up in
the wild when people try to use multiline strings, I felt it was better
to be obviously wrong.
This commit is contained in:
parent
6f41a2215d
commit
2de16b8cb0
@ -606,7 +606,7 @@
|
|||||||
if (curLineStart != line && curIndent <= startIndent && tokenStartsLine())
|
if (curLineStart != line && curIndent <= startIndent && tokenStartsLine())
|
||||||
node.property = dummyIdent();
|
node.property = dummyIdent();
|
||||||
else
|
else
|
||||||
node.property = parsePropertyName() || dummyIdent();
|
node.property = parsePropertyAccessor() || dummyIdent();
|
||||||
node.computed = false;
|
node.computed = false;
|
||||||
base = finishNode(node, "MemberExpression");
|
base = finishNode(node, "MemberExpression");
|
||||||
} else if (token.type == tt.bracketL) {
|
} else if (token.type == tt.bracketL) {
|
||||||
@ -735,6 +735,10 @@
|
|||||||
if (token.type === tt.name || token.type.keyword) return parseIdent();
|
if (token.type === tt.name || token.type.keyword) return parseIdent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parsePropertyAccessor() {
|
||||||
|
if (token.type === tt.name || token.type.keyword) return parseIdent();
|
||||||
|
}
|
||||||
|
|
||||||
function parseIdent() {
|
function parseIdent() {
|
||||||
var node = startNode();
|
var node = startNode();
|
||||||
node.name = token.type === tt.name ? token.value : token.type.keyword;
|
node.name = token.type === tt.name ? token.value : token.type.keyword;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user