1945 default: 1946 if (useBlockScope() && (type == LET && lookaheadIsLetDeclaration(true) || type == CONST)) { 1947 flags |= ForNode.PER_ITERATION_SCOPE; 1948 // LET/CONST declaration captured in container block created above. 1949 varDeclList = variableDeclarationList(varType = type, false, forStart); 1950 break; 1951 } 1952 if (env._const_as_var && type == CONST) { 1953 // Var declaration captured in for outer block. 1954 varDeclList = variableDeclarationList(varType = TokenType.VAR, false, forStart); 1955 break; 1956 } 1957 1958 init = expression(unaryExpression(), COMMARIGHT.getPrecedence(), true); 1959 break; 1960 } 1961 1962 switch (type) { 1963 case SEMICOLON: 1964 // for (init; test; modify) 1965 1966 // for each (init; test; modify) is invalid 1967 if ((flags & ForNode.IS_FOR_EACH) != 0) { 1968 throw error(AbstractParser.message("for.each.without.in"), token); 1969 } 1970 1971 expect(SEMICOLON); 1972 if (type != SEMICOLON) { 1973 test = joinPredecessorExpression(); 1974 } 1975 expect(SEMICOLON); 1976 if (type != RPAREN) { 1977 modify = joinPredecessorExpression(); 1978 } 1979 break; 1980 1981 case IDENT: 1982 if (env._es6 && "of".equals(getValue())) { 1983 isForOf = true; 1984 // fall through | 1945 default: 1946 if (useBlockScope() && (type == LET && lookaheadIsLetDeclaration(true) || type == CONST)) { 1947 flags |= ForNode.PER_ITERATION_SCOPE; 1948 // LET/CONST declaration captured in container block created above. 1949 varDeclList = variableDeclarationList(varType = type, false, forStart); 1950 break; 1951 } 1952 if (env._const_as_var && type == CONST) { 1953 // Var declaration captured in for outer block. 1954 varDeclList = variableDeclarationList(varType = TokenType.VAR, false, forStart); 1955 break; 1956 } 1957 1958 init = expression(unaryExpression(), COMMARIGHT.getPrecedence(), true); 1959 break; 1960 } 1961 1962 switch (type) { 1963 case SEMICOLON: 1964 // for (init; test; modify) 1965 if (varDeclList != null) { 1966 assert init == null; 1967 init = varDeclList.init; 1968 // late check for missing assignment, now we know it's a for (init; test; modify) loop 1969 if (varDeclList.missingAssignment != null) { 1970 if (varDeclList.missingAssignment instanceof IdentNode) { 1971 throw error(AbstractParser.message("missing.const.assignment", ((IdentNode)varDeclList.missingAssignment).getName())); 1972 } else { 1973 throw error(AbstractParser.message("missing.destructuring.assignment"), varDeclList.missingAssignment.getToken()); 1974 } 1975 } 1976 } 1977 1978 // for each (init; test; modify) is invalid 1979 if ((flags & ForNode.IS_FOR_EACH) != 0) { 1980 throw error(AbstractParser.message("for.each.without.in"), token); 1981 } 1982 1983 expect(SEMICOLON); 1984 if (type != SEMICOLON) { 1985 test = joinPredecessorExpression(); 1986 } 1987 expect(SEMICOLON); 1988 if (type != RPAREN) { 1989 modify = joinPredecessorExpression(); 1990 } 1991 break; 1992 1993 case IDENT: 1994 if (env._es6 && "of".equals(getValue())) { 1995 isForOf = true; 1996 // fall through |