1087 final int varLine = line;
1088 final long varToken = token;
1089 // Get name of var.
1090 final IdentNode name = getIdent();
1091 verifyStrictIdent(name, "variable name");
1092
1093 // Assume no init.
1094 Expression init = null;
1095
1096 // Look for initializer assignment.
1097 if (type == ASSIGN) {
1098 next();
1099
1100 // Get initializer expression. Suppress IN if not statement.
1101 defaultNames.push(name);
1102 try {
1103 init = assignmentExpression(!isStatement);
1104 } finally {
1105 defaultNames.pop();
1106 }
1107 } else if (varType == CONST) {
1108 throw error(AbstractParser.message("missing.const.assignment", name.getName()));
1109 }
1110
1111 // Allocate var node.
1112 final VarNode var = new VarNode(varLine, varToken, sourceOrder, finish, name.setIsDeclaredHere(), init, varFlags);
1113 vars.add(var);
1114 appendStatement(var);
1115
1116 if (type != COMMARIGHT) {
1117 break;
1118 }
1119 next();
1120 }
1121
1122 // If is a statement then handle end of line.
1123 if (isStatement) {
1124 endOfLine();
1125 }
1126
1127 return vars;
1128 }
1129
1130 /**
1131 * EmptyStatement :
1132 * ;
1229 Block body = null;
1230 List<VarNode> vars = null;
1231 Expression init = null;
1232 JoinPredecessorExpression test = null;
1233 JoinPredecessorExpression modify = null;
1234
1235 int flags = 0;
1236
1237 try {
1238 // FOR tested in caller.
1239 next();
1240
1241 // Nashorn extension: for each expression.
1242 // iterate property values rather than property names.
1243 if (!env._no_syntax_extensions && type == IDENT && "each".equals(getValue())) {
1244 flags |= ForNode.IS_FOR_EACH;
1245 next();
1246 }
1247
1248 expect(LPAREN);
1249
1250
1251 switch (type) {
1252 case VAR:
1253 // Var declaration captured in for outer block.
1254 vars = variableStatement(type, false, forStart);
1255 break;
1256 case SEMICOLON:
1257 break;
1258 default:
1259 if (useBlockScope() && (type == LET || type == CONST)) {
1260 if (type == LET) {
1261 flags |= ForNode.PER_ITERATION_SCOPE;
1262 }
1263 // LET/CONST declaration captured in container block created above.
1264 vars = variableStatement(type, false, forStart);
1265 break;
1266 }
1267 if (env._const_as_var && type == CONST) {
1268 // Var declaration captured in for outer block.
1269 vars = variableStatement(TokenType.VAR, false, forStart);
|
1087 final int varLine = line;
1088 final long varToken = token;
1089 // Get name of var.
1090 final IdentNode name = getIdent();
1091 verifyStrictIdent(name, "variable name");
1092
1093 // Assume no init.
1094 Expression init = null;
1095
1096 // Look for initializer assignment.
1097 if (type == ASSIGN) {
1098 next();
1099
1100 // Get initializer expression. Suppress IN if not statement.
1101 defaultNames.push(name);
1102 try {
1103 init = assignmentExpression(!isStatement);
1104 } finally {
1105 defaultNames.pop();
1106 }
1107 } else if (varType == CONST && isStatement) {
1108 throw error(AbstractParser.message("missing.const.assignment", name.getName()));
1109 }
1110
1111 // Only set declaration flag on lexically scoped let/const as it adds runtime overhead.
1112 final IdentNode actualName = varType == LET || varType == CONST ? name.setIsDeclaredHere() : name;
1113 // Allocate var node.
1114 final VarNode var = new VarNode(varLine, varToken, sourceOrder, finish, actualName, init, varFlags);
1115 vars.add(var);
1116 appendStatement(var);
1117
1118 if (type != COMMARIGHT) {
1119 break;
1120 }
1121 next();
1122 }
1123
1124 // If is a statement then handle end of line.
1125 if (isStatement) {
1126 endOfLine();
1127 }
1128
1129 return vars;
1130 }
1131
1132 /**
1133 * EmptyStatement :
1134 * ;
1231 Block body = null;
1232 List<VarNode> vars = null;
1233 Expression init = null;
1234 JoinPredecessorExpression test = null;
1235 JoinPredecessorExpression modify = null;
1236
1237 int flags = 0;
1238
1239 try {
1240 // FOR tested in caller.
1241 next();
1242
1243 // Nashorn extension: for each expression.
1244 // iterate property values rather than property names.
1245 if (!env._no_syntax_extensions && type == IDENT && "each".equals(getValue())) {
1246 flags |= ForNode.IS_FOR_EACH;
1247 next();
1248 }
1249
1250 expect(LPAREN);
1251
1252 switch (type) {
1253 case VAR:
1254 // Var declaration captured in for outer block.
1255 vars = variableStatement(type, false, forStart);
1256 break;
1257 case SEMICOLON:
1258 break;
1259 default:
1260 if (useBlockScope() && (type == LET || type == CONST)) {
1261 if (type == LET) {
1262 flags |= ForNode.PER_ITERATION_SCOPE;
1263 }
1264 // LET/CONST declaration captured in container block created above.
1265 vars = variableStatement(type, false, forStart);
1266 break;
1267 }
1268 if (env._const_as_var && type == CONST) {
1269 // Var declaration captured in for outer block.
1270 vars = variableStatement(TokenType.VAR, false, forStart);
|