for...of
This commit is contained in:
committed by
Richard van Velzen
parent
ad344c5be3
commit
9d7d365c2b
24
lib/parse.js
24
lib/parse.js
@@ -44,7 +44,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';
|
||||
var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in of instanceof new return switch throw try typeof var void while with';
|
||||
var KEYWORDS_ATOM = 'false null true';
|
||||
var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield'
|
||||
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||
@@ -921,11 +921,17 @@ function parse($TEXT, options) {
|
||||
init = is("keyword", "var")
|
||||
? (next(), var_(true))
|
||||
: expression(true, true);
|
||||
if (is("operator", "in")) {
|
||||
var is_in = is("operator", "in");
|
||||
var is_of = is("keyword", "of");
|
||||
if (is_in || is_of) {
|
||||
if (init instanceof AST_Var && init.definitions.length > 1)
|
||||
croak("Only one variable declaration allowed in for..in loop");
|
||||
next();
|
||||
return for_in(init);
|
||||
if (is_in) {
|
||||
return for_in(init);
|
||||
} else {
|
||||
return for_of(init);
|
||||
}
|
||||
}
|
||||
}
|
||||
return regular_for(init);
|
||||
@@ -945,6 +951,18 @@ function parse($TEXT, options) {
|
||||
});
|
||||
};
|
||||
|
||||
function for_of(init) {
|
||||
var lhs = init instanceof AST_Var ? init.definitions[0].name : null;
|
||||
var obj = expression(true);
|
||||
expect(")");
|
||||
return new AST_ForOf({
|
||||
init : init,
|
||||
name : lhs,
|
||||
object : obj,
|
||||
body : in_loop(statement)
|
||||
});
|
||||
};
|
||||
|
||||
function for_in(init) {
|
||||
var lhs = init instanceof AST_Var ? init.definitions[0].name : null;
|
||||
var obj = expression(true);
|
||||
|
||||
Reference in New Issue
Block a user