Revert "remove support for const (#1910)"
This reverts commit c391576d52.
This commit is contained in:
22
lib/parse.js
22
lib/parse.js
@@ -912,6 +912,9 @@ function parse($TEXT, options) {
|
||||
case "var":
|
||||
return tmp = var_(), semicolon(), tmp;
|
||||
|
||||
case "const":
|
||||
return tmp = const_(), semicolon(), tmp;
|
||||
|
||||
case "with":
|
||||
if (S.input.has_directive("use strict")) {
|
||||
croak("Strict mode may not include a with statement");
|
||||
@@ -1146,13 +1149,16 @@ function parse($TEXT, options) {
|
||||
});
|
||||
};
|
||||
|
||||
function vardefs(no_in) {
|
||||
function vardefs(no_in, in_const) {
|
||||
var a = [];
|
||||
for (;;) {
|
||||
a.push(new AST_VarDef({
|
||||
start : S.token,
|
||||
name : as_symbol(AST_SymbolVar),
|
||||
value : is("operator", "=") ? (next(), expression(false, no_in)) : null,
|
||||
name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar),
|
||||
value : is("operator", "=")
|
||||
? (next(), expression(false, no_in))
|
||||
: in_const && S.input.has_directive("use strict")
|
||||
? croak("Missing initializer in const declaration") : null,
|
||||
end : prev()
|
||||
}));
|
||||
if (!is("punc", ","))
|
||||
@@ -1165,7 +1171,15 @@ function parse($TEXT, options) {
|
||||
var var_ = function(no_in) {
|
||||
return new AST_Var({
|
||||
start : prev(),
|
||||
definitions : vardefs(no_in),
|
||||
definitions : vardefs(no_in, false),
|
||||
end : prev()
|
||||
});
|
||||
};
|
||||
|
||||
var const_ = function() {
|
||||
return new AST_Const({
|
||||
start : prev(),
|
||||
definitions : vardefs(false, true),
|
||||
end : prev()
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user