Parse and compress destructuring VarDefs
This commit is contained in:
committed by
Richard van Velzen
parent
824ecfb8a2
commit
c44c2d6c21
33
lib/parse.js
33
lib/parse.js
@@ -1180,13 +1180,24 @@ function parse($TEXT, options) {
|
||||
|
||||
function vardefs(no_in, in_const) {
|
||||
var a = [];
|
||||
var def;
|
||||
for (;;) {
|
||||
a.push(new AST_VarDef({
|
||||
start : S.token,
|
||||
name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar),
|
||||
value : is("operator", "=") ? (next(), expression(false, no_in)) : null,
|
||||
end : prev()
|
||||
}));
|
||||
if (is("punc", "{") || is("punc", "[")) {
|
||||
def = new AST_VarDef({
|
||||
start: S.token,
|
||||
name: destructuring_(),
|
||||
value: (expect_token("operator", "="), expression(false, no_in)),
|
||||
end: prev()
|
||||
});
|
||||
} else {
|
||||
def = new AST_VarDef({
|
||||
start : S.token,
|
||||
name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar),
|
||||
value : is("operator", "=") ? (next(), expression(false, no_in)) : null,
|
||||
end : prev()
|
||||
})
|
||||
}
|
||||
a.push(def);
|
||||
if (!is("punc", ","))
|
||||
break;
|
||||
next();
|
||||
@@ -1194,6 +1205,16 @@ function parse($TEXT, options) {
|
||||
return a;
|
||||
};
|
||||
|
||||
var destructuring_ = embed_tokens(function () {
|
||||
var is_array = is("punc", "[");
|
||||
var closing = is_array ? ']' : '}';
|
||||
next()
|
||||
return new AST_Destructuring({
|
||||
names: expr_list(closing),
|
||||
is_array: is_array
|
||||
})
|
||||
});
|
||||
|
||||
var var_ = function(no_in) {
|
||||
return new AST_Var({
|
||||
start : prev(),
|
||||
|
||||
Reference in New Issue
Block a user