Remove unused state variable in_parameters, and also remove unreachable code (try_an_object always returned an object!)
This commit is contained in:
42
lib/parse.js
42
lib/parse.js
@@ -672,7 +672,6 @@ function parse($TEXT, options) {
|
||||
prev : null,
|
||||
peeked : null,
|
||||
in_function : 0,
|
||||
in_parameters : false,
|
||||
in_directives : true,
|
||||
in_loop : 0,
|
||||
labels : []
|
||||
@@ -1044,7 +1043,6 @@ function parse($TEXT, options) {
|
||||
expect("(");
|
||||
var first = true;
|
||||
var a = [];
|
||||
S.in_parameters = true;
|
||||
while (!is("punc", ")")) {
|
||||
if (first) first = false; else expect(",");
|
||||
if (is("expand", "...")) {
|
||||
@@ -1058,7 +1056,6 @@ function parse($TEXT, options) {
|
||||
a.push(expression(false));
|
||||
}
|
||||
}
|
||||
S.in_parameters = false;
|
||||
var end = S.token
|
||||
next();
|
||||
return new AST_ArrowParametersOrSeq({
|
||||
@@ -1375,10 +1372,8 @@ function parse($TEXT, options) {
|
||||
});
|
||||
|
||||
var object_or_object_destructuring_ = embed_tokens(function() {
|
||||
var start = S.token;
|
||||
var start = S.token, first = true, a = [];
|
||||
expect("{");
|
||||
function try_an_object() {
|
||||
var first = true, a = [];
|
||||
while (!is("punc", "}")) {
|
||||
if (first) first = false; else expect(",");
|
||||
if (!options.strict && is("punc", "}"))
|
||||
@@ -1420,9 +1415,6 @@ function parse($TEXT, options) {
|
||||
})
|
||||
}));
|
||||
} else {
|
||||
if (S.in_parameters) {
|
||||
croak("Cannot destructure", S.token.line, S.token.col);
|
||||
}
|
||||
expect(":");
|
||||
a.push(new AST_ObjectKeyVal({
|
||||
start : start,
|
||||
@@ -1434,38 +1426,6 @@ function parse($TEXT, options) {
|
||||
}
|
||||
next();
|
||||
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() {
|
||||
|
||||
@@ -122,3 +122,14 @@ number_literals: {
|
||||
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});";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user