< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java
Print this page
@@ -95,10 +95,11 @@
*/
@Logger(name="lower")
final class Lower extends NodeOperatorVisitor<BlockLexicalContext> implements Loggable {
private final DebugLogger log;
+ private final boolean es6;
// Conservative pattern to test if element names consist of characters valid for identifiers.
// This matches any non-zero length alphanumeric string including _ and $ and not starting with a digit.
private static final Pattern SAFE_PROPERTY_NAME = Pattern.compile("[a-zA-Z_$][\\w$]*");
@@ -142,10 +143,11 @@
return block.setIsTerminal(this, false);
}
});
this.log = initLogger(compiler.getContext());
+ this.es6 = compiler.getScriptEnvironment()._es6;
}
@Override
public DebugLogger getLogger() {
return log;
@@ -255,12 +257,13 @@
if (!forNode.isForIn() && isAlwaysTrue(test)) {
newForNode = forNode.setTest(lc, null);
}
newForNode = checkEscape(newForNode);
- if(newForNode.isForIn()) {
- // Wrap it in a block so its internally created iterator is restricted in scope
+ if(!es6 && newForNode.isForIn()) {
+ // Wrap it in a block so its internally created iterator is restricted in scope, unless we are running
+ // in ES6 mode, in which case the parser already created a block to capture let/const declarations.
addStatementEnclosedInBlock(newForNode);
} else {
addStatement(newForNode);
}
return newForNode;
< prev index next >