Remove unused state variable in_parameters, and also remove unreachable code (try_an_object always returned an object!)

This commit is contained in:
Fábio Santos
2015-09-05 23:01:25 +01:00
parent af22b9c657
commit 2fac2bbfe4
2 changed files with 58 additions and 87 deletions

View File

@@ -672,7 +672,6 @@ function parse($TEXT, options) {
prev : null, prev : null,
peeked : null, peeked : null,
in_function : 0, in_function : 0,
in_parameters : false,
in_directives : true, in_directives : true,
in_loop : 0, in_loop : 0,
labels : [] labels : []
@@ -1044,7 +1043,6 @@ function parse($TEXT, options) {
expect("("); expect("(");
var first = true; var first = true;
var a = []; var a = [];
S.in_parameters = true;
while (!is("punc", ")")) { while (!is("punc", ")")) {
if (first) first = false; else expect(","); if (first) first = false; else expect(",");
if (is("expand", "...")) { if (is("expand", "...")) {
@@ -1058,7 +1056,6 @@ function parse($TEXT, options) {
a.push(expression(false)); a.push(expression(false));
} }
} }
S.in_parameters = false;
var end = S.token var end = S.token
next(); next();
return new AST_ArrowParametersOrSeq({ return new AST_ArrowParametersOrSeq({
@@ -1375,10 +1372,8 @@ function parse($TEXT, options) {
}); });
var object_or_object_destructuring_ = embed_tokens(function() { var object_or_object_destructuring_ = embed_tokens(function() {
var start = S.token; var start = S.token, first = true, a = [];
expect("{"); expect("{");
function try_an_object() {
var first = true, a = [];
while (!is("punc", "}")) { while (!is("punc", "}")) {
if (first) first = false; else expect(","); if (first) first = false; else expect(",");
if (!options.strict && is("punc", "}")) if (!options.strict && is("punc", "}"))
@@ -1420,9 +1415,6 @@ function parse($TEXT, options) {
}) })
})); }));
} else { } else {
if (S.in_parameters) {
croak("Cannot destructure", S.token.line, S.token.col);
}
expect(":"); expect(":");
a.push(new AST_ObjectKeyVal({ a.push(new AST_ObjectKeyVal({
start : start, start : start,
@@ -1434,38 +1426,6 @@ function parse($TEXT, options) {
} }
next(); next();
return new AST_Object({ properties: a }) return new AST_Object({ properties: a })
}
var obj = try_an_object();
if (obj instanceof AST_Object) { return obj; }
if (!S.in_parameters) {
croak("Cannot destructure", S.token.line, S.token.col);
}
var firstName = obj;
var namesInDestructuring = [];
namesInDestructuring.push( new AST_SymbolRef({
start : prev(),
end : prev(),
name : firstName
}));
while (!is("punc", "}")) {
expect(",");
namesInDestructuring.push(as_symbol(AST_SymbolRef))
}
expect('}');
return new AST_Destructuring({
start : start,
end : S.token,
names : namesInDestructuring,
is_array : false
})
}); });
function as_property_name() { function as_property_name() {

View File

@@ -122,3 +122,14 @@ number_literals: {
9; 9;
} }
} }
// Fabio: My patches accidentally caused a crash whenever
// there's an extraneous set of parens around an object.
regression_cannot_destructure: {
input: {
var x = ({ x : 3 });
x(({ x: 3 }));
}
expect_exact: "var x={x:3};x({x:3});";
}