add let support
This commit is contained in:
parent
f8a9649c2a
commit
906837dc90
|
|
@ -547,6 +547,10 @@ var AST_Const = DEFNODE("Const", null, {
|
||||||
$documentation: "A `const` statement"
|
$documentation: "A `const` statement"
|
||||||
}, AST_Definitions);
|
}, AST_Definitions);
|
||||||
|
|
||||||
|
var AST_Let = DEFNODE("Let", null, {
|
||||||
|
$documentation: "A `let` statement"
|
||||||
|
}, AST_Definitions);
|
||||||
|
|
||||||
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
||||||
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
|
|
|
||||||
|
|
@ -934,6 +934,9 @@ function OutputStream(options) {
|
||||||
DEFPRINT(AST_Const, function(self, output){
|
DEFPRINT(AST_Const, function(self, output){
|
||||||
self._do_print(output, "const");
|
self._do_print(output, "const");
|
||||||
});
|
});
|
||||||
|
DEFPRINT(AST_Let, function(self, output){
|
||||||
|
self._do_print(output, "let");
|
||||||
|
});
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
if (!noin) node.print(output);
|
if (!noin) node.print(output);
|
||||||
|
|
|
||||||
15
lib/parse.js
15
lib/parse.js
|
|
@ -844,6 +844,9 @@ function parse($TEXT, options) {
|
||||||
case "var":
|
case "var":
|
||||||
return tmp = var_(), semicolon(), tmp;
|
return tmp = var_(), semicolon(), tmp;
|
||||||
|
|
||||||
|
case "let":
|
||||||
|
return tmp = let_(), semicolon(), tmp;
|
||||||
|
|
||||||
case "const":
|
case "const":
|
||||||
return tmp = const_(), semicolon(), tmp;
|
return tmp = const_(), semicolon(), tmp;
|
||||||
|
|
||||||
|
|
@ -916,7 +919,9 @@ function parse($TEXT, options) {
|
||||||
if (!is("punc", ";")) {
|
if (!is("punc", ";")) {
|
||||||
init = is("keyword", "var")
|
init = is("keyword", "var")
|
||||||
? (next(), var_(true))
|
? (next(), var_(true))
|
||||||
: expression(true, true);
|
: is("keyword", "let")
|
||||||
|
? (next(), let_(true))
|
||||||
|
:expression(true, true);
|
||||||
if (is("operator", "in")) {
|
if (is("operator", "in")) {
|
||||||
if (init instanceof AST_Var && init.definitions.length > 1)
|
if (init instanceof AST_Var && init.definitions.length > 1)
|
||||||
croak("Only one variable declaration allowed in for..in loop");
|
croak("Only one variable declaration allowed in for..in loop");
|
||||||
|
|
@ -1111,6 +1116,14 @@ function parse($TEXT, options) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var let_ = function(no_in) {
|
||||||
|
return new AST_Let({
|
||||||
|
start : prev(),
|
||||||
|
definitions : vardefs(no_in, false),
|
||||||
|
end : prev()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var new_ = function() {
|
var new_ = function() {
|
||||||
var start = S.token;
|
var start = S.token;
|
||||||
expect_token("operator", "new");
|
expect_token("operator", "new");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user