diff --git a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstIdentifier.java b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstIdentifier.java index c08be9afc..a7b631e4a 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstIdentifier.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstIdentifier.java @@ -1,10 +1,6 @@ package com.hubspot.jinjava.el.ext.eager; import com.hubspot.jinjava.el.ext.DeferredParsingException; -import com.hubspot.jinjava.el.ext.ExtendedParser; -import com.hubspot.jinjava.interpret.DeferredValueException; -import com.hubspot.jinjava.lib.filter.Filter; -import com.hubspot.jinjava.util.EagerExpressionResolver; import de.odysseus.el.tree.Bindings; import de.odysseus.el.tree.impl.ast.AstIdentifier; import javax.el.ELContext; @@ -20,21 +16,7 @@ public EagerAstIdentifier(String name, int index, boolean ignoreReturnType) { @Override public Object eval(Bindings bindings, ELContext context) { return EvalResultHolder.super.eval( - () -> { - Object result = super.eval(bindings, context); - if ( - !ExtendedParser.INTERPRETER.equals(getName()) && - !EagerExpressionResolver.isPrimitive(result) && - !(result instanceof Filter) && - EvalResultHolder - .getJinjavaInterpreter(context) - .getContext() - .isPreserveAllIdentifiers() - ) { - throw new DeferredValueException("Preserving all non-primitive identifiers"); - } - return result; - }, + () -> super.eval(bindings, context), bindings, context ); diff --git a/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java b/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java index 0298c5b43..30de67e77 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java @@ -44,7 +44,12 @@ default Object checkEvalResultSize(ELContext context) { if ( evalResult instanceof Collection && ((Collection) evalResult).size() > 100 && // TODO make size configurable - getJinjavaInterpreter(context).getContext().isDeferLargeObjects() + ( + (JinjavaInterpreter) context + .getELResolver() + .getValue(context, null, ExtendedParser.INTERPRETER) + ).getContext() + .isDeferLargeObjects() ) { throw new DeferredValueException("Collection too big"); } @@ -58,12 +63,6 @@ String getPartiallyResolved( boolean preserveIdentifier ); - static JinjavaInterpreter getJinjavaInterpreter(ELContext context) { - return (JinjavaInterpreter) context - .getELResolver() - .getValue(context, null, ExtendedParser.INTERPRETER); - } - static String reconstructNode( Bindings bindings, ELContext context, diff --git a/src/main/java/com/hubspot/jinjava/interpret/Context.java b/src/main/java/com/hubspot/jinjava/interpret/Context.java index bdbe61120..8e4d2d30d 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/Context.java +++ b/src/main/java/com/hubspot/jinjava/interpret/Context.java @@ -107,8 +107,6 @@ public enum Library { private boolean validationMode = false; private boolean deferredExecutionMode = false; private boolean deferLargeObjects = false; - - private boolean preserveAllIdentifiers = false; private boolean throwInterpreterErrors = false; private boolean partialMacroEvaluation = false; private boolean unwrapRawOverride = false; @@ -213,7 +211,6 @@ public Context( this.dynamicVariableResolver = parent.dynamicVariableResolver; this.deferredExecutionMode = parent.deferredExecutionMode; this.deferLargeObjects = parent.deferLargeObjects; - this.preserveAllIdentifiers = parent.preserveAllIdentifiers; this.throwInterpreterErrors = parent.throwInterpreterErrors; } } @@ -732,26 +729,6 @@ public TemporaryValueClosable withDeferLargeObjects( return temporaryValueClosable; } - public boolean isPreserveAllIdentifiers() { - return preserveAllIdentifiers; - } - - public Context setPreserveAllIdentifiers(boolean preserveAllIdentifiers) { - this.preserveAllIdentifiers = preserveAllIdentifiers; - return this; - } - - public TemporaryValueClosable withPreserveAllIdentifiers( - boolean preserveAllIdentifiers - ) { - TemporaryValueClosable temporaryValueClosable = new TemporaryValueClosable<>( - this.preserveAllIdentifiers, - this::setPreserveAllIdentifiers - ); - this.preserveAllIdentifiers = preserveAllIdentifiers; - return temporaryValueClosable; - } - public boolean getThrowInterpreterErrors() { return throwInterpreterErrors; } diff --git a/src/main/java/com/hubspot/jinjava/lib/fn/MacroFunction.java b/src/main/java/com/hubspot/jinjava/lib/fn/MacroFunction.java index b2efa44fd..c63f9453b 100644 --- a/src/main/java/com/hubspot/jinjava/lib/fn/MacroFunction.java +++ b/src/main/java/com/hubspot/jinjava/lib/fn/MacroFunction.java @@ -77,6 +77,7 @@ public Object doEvaluate( JinjavaInterpreter interpreter = JinjavaInterpreter.getCurrent(); Optional importFile = getImportFile(interpreter); try (InterpreterScopeClosable c = interpreter.enterScope()) { + interpreter.getContext().setDeferredExecutionMode(false); String result = getEvaluationResult(argMap, kwargMap, varArgs, interpreter); if ( diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java index 0b9ca7653..25337c4f2 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java @@ -55,16 +55,6 @@ protected EagerExecutionResult getEagerExecutionResult( return result; } - @Override - protected EagerExecutionResult getDeferredEagerExecutionResult( - TagNode tagNode, - String expression, - JinjavaInterpreter interpreter, - EagerExecutionResult firstResult - ) { - return firstResult; - } - @Override protected Optional resolveSet( TagNode tagNode, diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerExecutionResult.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerExecutionResult.java index bab3117bd..698543906 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerExecutionResult.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerExecutionResult.java @@ -55,6 +55,20 @@ public String getPrefixToPreserveState(boolean registerDeferredToken) { } JinjavaInterpreter interpreter = JinjavaInterpreter.getCurrent(); prefixToPreserveState = + speculativeBindings + .entrySet() + .stream() + .filter(entry -> entry.getValue() instanceof PyishBlockSetSerializable) + .map( + entry -> + buildBlockSetTag( + entry.getKey(), + ((PyishBlockSetSerializable) entry.getValue()).getBlockSetBody(), + interpreter, + registerDeferredToken + ) + ) + .collect(Collectors.joining()) + buildSetTag( speculativeBindings .entrySet() @@ -70,20 +84,6 @@ public String getPrefixToPreserveState(boolean registerDeferredToken) { interpreter, registerDeferredToken ) + - speculativeBindings - .entrySet() - .stream() - .filter(entry -> entry.getValue() instanceof PyishBlockSetSerializable) - .map( - entry -> - buildBlockSetTag( - entry.getKey(), - ((PyishBlockSetSerializable) entry.getValue()).getBlockSetBody(), - interpreter, - registerDeferredToken - ) - ) - .collect(Collectors.joining()) + speculativeBindings .entrySet() .stream() diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerForTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerForTag.java index 7d42cc242..13291b73a 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerForTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerForTag.java @@ -58,7 +58,7 @@ public String innerInterpret(TagNode tagNode, JinjavaInterpreter interpreter) { !result.getSpeculativeBindings().isEmpty() ) ) { - EagerReconstructionUtils.resetSpeculativeBindings(interpreter, result); + EagerIfTag.resetBindingsForNextBranch(interpreter, result); interpreter.getContext().removeDeferredTokens(addedTokens); throw new DeferredValueException( result.getResult().getResolutionState() == ResolutionState.NONE @@ -98,34 +98,28 @@ public String eagerInterpret( interpreter.getContext().isDeferLargeObjects() ) ) { - try ( - TemporaryValueClosable c1 = interpreter - .getContext() - .withPreserveAllIdentifiers(true) - ) { - // separate getEagerImage from renderChildren because the token gets evaluated once - // while the children are evaluated 0...n times. - result.append( - EagerContextWatcher - .executeInChildContext( - eagerInterpreter -> - EagerExpressionResult.fromString( - getEagerImage( - buildToken( - tagNode, - e, - interpreter.getLineNumber(), - interpreter.getPosition() - ), - eagerInterpreter - ) - ), - interpreter, - EagerContextWatcher.EagerChildContextConfig.newBuilder().build() - ) - .asTemplateString() - ); - } + // separate getEagerImage from renderChildren because the token gets evaluated once + // while the children are evaluated 0...n times. + result.append( + EagerContextWatcher + .executeInChildContext( + eagerInterpreter -> + EagerExpressionResult.fromString( + getEagerImage( + buildToken( + tagNode, + e, + interpreter.getLineNumber(), + interpreter.getPosition() + ), + eagerInterpreter + ) + ), + interpreter, + EagerContextWatcher.EagerChildContextConfig.newBuilder().build() + ) + .asTemplateString() + ); } EagerExecutionResult firstRunResult = runLoopOnce(tagNode, interpreter); diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java index 151676870..25d1e2484 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java @@ -121,9 +121,7 @@ public String eagerRenderBranches( .build() ); sb.append(result.getResult()); - bindingsToDefer.addAll( - EagerReconstructionUtils.resetSpeculativeBindings(interpreter, result) - ); + bindingsToDefer.addAll(resetBindingsForNextBranch(interpreter, result)); } if (branchEnd >= childrenSize || definitelyExecuted) { break; @@ -182,6 +180,16 @@ public String eagerRenderBranches( return sb.toString(); } + public static Set resetBindingsForNextBranch( + JinjavaInterpreter interpreter, + EagerExecutionResult result + ) { + result + .getSpeculativeBindings() + .forEach((k, v) -> interpreter.getContext().replace(k, v)); + return result.getSpeculativeBindings().keySet(); + } + private String evaluateBranch( TagNode tagNode, int startIdx, diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerInlineSetTagStrategy.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerInlineSetTagStrategy.java index d88a87232..9b786a84d 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerInlineSetTagStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerInlineSetTagStrategy.java @@ -1,6 +1,5 @@ package com.hubspot.jinjava.lib.tag.eager; -import com.hubspot.jinjava.interpret.Context.TemporaryValueClosable; import com.hubspot.jinjava.interpret.DeferredMacroValueImpl; import com.hubspot.jinjava.interpret.DeferredValueException; import com.hubspot.jinjava.interpret.JinjavaInterpreter; @@ -9,7 +8,6 @@ import com.hubspot.jinjava.tree.parse.TagToken; import com.hubspot.jinjava.util.EagerContextWatcher; import com.hubspot.jinjava.util.EagerExpressionResolver; -import com.hubspot.jinjava.util.EagerExpressionResolver.EagerExpressionResult; import com.hubspot.jinjava.util.EagerReconstructionUtils; import com.hubspot.jinjava.util.LengthLimitingStringJoiner; import com.hubspot.jinjava.util.WhitespaceUtils; @@ -34,7 +32,8 @@ public EagerExecutionResult getEagerExecutionResult( JinjavaInterpreter interpreter ) { return EagerContextWatcher.executeInChildContext( - eagerInterpreter -> getEagerExpressionResult(expression, interpreter), + eagerInterpreter -> + EagerExpressionResolver.resolveExpression('[' + expression + ']', interpreter), interpreter, EagerContextWatcher .EagerChildContextConfig.newBuilder() @@ -43,39 +42,6 @@ public EagerExecutionResult getEagerExecutionResult( ); } - @Override - protected EagerExecutionResult getDeferredEagerExecutionResult( - TagNode tagNode, - String expression, - JinjavaInterpreter interpreter, - EagerExecutionResult firstResult - ) { - EagerReconstructionUtils.resetSpeculativeBindings(interpreter, firstResult); - // Preserve identifiers when reconstructing to maintain proper object references - try ( - TemporaryValueClosable c = interpreter - .getContext() - .withPreserveAllIdentifiers(true) - ) { - return EagerContextWatcher.executeInChildContext( - eagerInterpreter -> getEagerExpressionResult(expression, interpreter), - interpreter, - EagerContextWatcher - .EagerChildContextConfig.newBuilder() - .withTakeNewValue(true) - .withForceDeferredExecutionMode(true) - .build() - ); - } - } - - private static EagerExpressionResult getEagerExpressionResult( - String expression, - JinjavaInterpreter interpreter - ) { - return EagerExpressionResolver.resolveExpression('[' + expression + ']', interpreter); - } - @Override public Optional resolveSet( TagNode tagNode, diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerSetTagStrategy.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerSetTagStrategy.java index e1ae274f5..191b8ecaf 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerSetTagStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerSetTagStrategy.java @@ -61,13 +61,6 @@ public String run(TagNode tagNode, JinjavaInterpreter interpreter) { return maybeResolved.get(); } } - eagerExecutionResult = - getDeferredEagerExecutionResult( - tagNode, - expression, - interpreter, - eagerExecutionResult - ); Triple triple = getPrefixTokenAndSuffix( tagNode, variables, @@ -89,13 +82,6 @@ protected abstract EagerExecutionResult getEagerExecutionResult( JinjavaInterpreter interpreter ); - protected abstract EagerExecutionResult getDeferredEagerExecutionResult( - TagNode tagNode, - String expression, - JinjavaInterpreter interpreter, - EagerExecutionResult firstResult - ); - protected abstract Optional resolveSet( TagNode tagNode, String[] variables, @@ -131,10 +117,7 @@ protected String getPrefixToPreserveState( JinjavaInterpreter interpreter ) { StringBuilder prefixToPreserveState = new StringBuilder(); - if ( - interpreter.getContext().isDeferredExecutionMode() || - !eagerExecutionResult.getResult().isFullyResolved() - ) { + if (interpreter.getContext().isDeferredExecutionMode()) { prefixToPreserveState.append(eagerExecutionResult.getPrefixToPreserveState()); } else { interpreter.getContext().putAll(eagerExecutionResult.getSpeculativeBindings()); diff --git a/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java b/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java index 6ad78e7d1..b364e61ba 100644 --- a/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java +++ b/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java @@ -653,14 +653,4 @@ public static String reconstructDeferredReferences( ) ); } - - public static Set resetSpeculativeBindings( - JinjavaInterpreter interpreter, - EagerExecutionResult result - ) { - result - .getSpeculativeBindings() - .forEach((k, v) -> interpreter.getContext().replace(k, v)); - return result.getSpeculativeBindings().keySet(); - } } diff --git a/src/test/java/com/hubspot/jinjava/EagerTest.java b/src/test/java/com/hubspot/jinjava/EagerTest.java index 65e71d0f7..37914d4e2 100644 --- a/src/test/java/com/hubspot/jinjava/EagerTest.java +++ b/src/test/java/com/hubspot/jinjava/EagerTest.java @@ -484,8 +484,9 @@ public void itMarksVariablesUsedAsMapKeysAsDeferred() { DeferredValueUtils.findAndMarkDeferredProperties(localContext); assertThat(deferredValue2).isInstanceOf(DeferredValue.class); assertThat(output) - .contains("{% set imported = {'map': {'key': 'value'} } %}") - .contains("{% set varSetInside = imported.map[deferredValue2.nonexistentprop] %}"); + .contains( + "{% set varSetInside = {'key': 'value'} [deferredValue2.nonexistentprop] %}" + ); } @Test @@ -1249,26 +1250,4 @@ public void itReconstructsWordsFromInsideNestedExpressionsSecondPass() { public void itDoesNotReconstructExtraTimes() { expectedTemplateInterpreter.assertExpectedOutput("does-not-reconstruct-extra-times"); } - - @Test - public void itCorrectlyPreservesIdentifiersInInlineSet() { - // This doesn't need to happen in block sets, because they only store string values - expectedTemplateInterpreter.assertExpectedOutput( - "correctly-preserves-identifiers-in-inline-set" - ); - } - - @Test - public void itCorrectlyPreservesIdentifiersInForLoop() { - expectedTemplateInterpreter.assertExpectedOutput( - "correctly-preserves-identifiers-in-for-loop" - ); - } - - @Test - public void itCorrectlyPreservesIdentifiersInMacroFunction() { - expectedTemplateInterpreter.assertExpectedOutputNonIdempotent( - "correctly-preserves-identifiers-in-macro-function" - ); - } } diff --git a/src/test/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategyTest.java b/src/test/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategyTest.java index 9eae2ff80..c3c457397 100644 --- a/src/test/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategyTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategyTest.java @@ -133,13 +133,13 @@ public void itGoesIntoDeferredExecutionMode() { } @Test - public void itGoesIntoDeferredExecutionModeWithMacro() { + public void itDoesNotGoIntoDeferredExecutionModeWithMacro() { assertExpectedOutput( "{% macro def() %}{{ is_deferred_execution_mode() }}{% endmacro %}" + "{{ def() }}" + "{% if deferred %}{{ def() }}{% endif %}" + "{{ def() }}", - "false{% if deferred %}true{% endif %}false" + "false{% if deferred %}false{% endif %}false" ); } diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerForTagTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerForTagTest.java index 5739426f7..956591f5c 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerForTagTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerForTagTest.java @@ -192,11 +192,7 @@ public void itAllowsChangesInDeferredForToken() { ); assertThat(output.trim()) .isEqualTo( - // now foo is being preserved because it may be used to fuel the collection we're looping through - "{% set foo = [0] %}{% set foo = [0] %}{% for i in range(foo.append(1) ? 0 : 1, deferred) %}\n" + - "{{ i }}\n" + - "{% endfor %}\n" + - "{{ foo }}" + "{% for i in range(0, deferred) %}\n" + "{{ i }}\n" + "{% endfor %}\n" + "[0, 1]" ); } diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.expected.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.expected.jinja deleted file mode 100644 index 83aa2c074..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.expected.jinja +++ /dev/null @@ -1,8 +0,0 @@ -{% set dict = {} %}{% set dict = {} %}{% for item in [dict] %} -{% if deferred %} -{% do item.update({'c': 'd'} ) %} -{% endif %} -{{ item }} -{% endfor %} - -{% do dict.update({'a': 'b'} ) %} diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.jinja deleted file mode 100644 index 061461d8b..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-for-loop.jinja +++ /dev/null @@ -1,10 +0,0 @@ -{% set dict = {} %} - -{% for item in [dict] %} -{% if deferred %} -{% do item.update({'c': 'd'}) %} -{% endif %} -{{ item }} -{% endfor %} - -{% do dict.update({'a': 'b'}) %} diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.expected.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.expected.jinja deleted file mode 100644 index 78328bf02..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.expected.jinja +++ /dev/null @@ -1,5 +0,0 @@ -{% set dict = {} %}{% set foo = (dict, deferred) %} - -{% do dict.update({'a': 'b'} ) %} - -{{ foo }} diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.jinja deleted file mode 100644 index 5e11bf14e..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-inline-set.jinja +++ /dev/null @@ -1,7 +0,0 @@ -{% set dict = {} %} - -{% set foo = (dict, deferred) %} - -{% do dict.update({'a': 'b'}) %} - -{{ foo }} diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.expected.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.expected.jinja deleted file mode 100644 index 9252a99ed..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.expected.jinja +++ /dev/null @@ -1,12 +0,0 @@ -{% set list = [{'a': 'A'} ] %}{% set __macro_bar_93535367_temp_variable_1__ %} -{% set map1 = {} %} -{% set map2 = {} %} -{% set map1 = {} %}{% do list.append(map1) %} -{% set map2 = {} %}{% if deferred %} -{% set map2 = {} %}{% do list.append(map2) %} -{% endif %} -{% do map1.update({'a': 'A'} ) %} -{% do map2.update({'b': 'B'} ) %} -{{ list }} -{% endset %}{% set foobar = __macro_bar_93535367_temp_variable_1__ %} -{{ list }} diff --git a/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.jinja b/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.jinja deleted file mode 100644 index 2d14eb5c1..000000000 --- a/src/test/resources/eager/correctly-preserves-identifiers-in-macro-function.jinja +++ /dev/null @@ -1,15 +0,0 @@ -{% set list = [] %} -{% macro bar() %} -{% set map1 = {} %} -{% set map2 = {} %} -{% do list.append(map1) %} -{% if deferred %} -{% do list.append(map2) %} -{% endif %} -{% do map1.update({'a': 'A'}) %} -{% do map2.update({'b': 'B'}) %} -{{ list }} -{% endmacro %} - -{% set foobar = bar() %} -{{ list }} diff --git a/src/test/resources/eager/handles-deferring-loop-variable.expected.jinja b/src/test/resources/eager/handles-deferring-loop-variable.expected.jinja index 1a1d7ec21..740c79b89 100644 --- a/src/test/resources/eager/handles-deferring-loop-variable.expected.jinja +++ b/src/test/resources/eager/handles-deferring-loop-variable.expected.jinja @@ -7,7 +7,7 @@ {% endif %} 2 {% endfor %} -{% set foo = [0, 1] %}{% set foo = [0, 1] %}{% for i in foo %} +{% for i in [0, 1] %} {% if deferred && loop.isLast() %}last time! {% endif %} {{ loop.index }} diff --git a/src/test/resources/eager/handles-duplicate-variable-reference-modification.expected.jinja b/src/test/resources/eager/handles-duplicate-variable-reference-modification.expected.jinja index 51c33fa58..b99253750 100644 --- a/src/test/resources/eager/handles-duplicate-variable-reference-modification.expected.jinja +++ b/src/test/resources/eager/handles-duplicate-variable-reference-modification.expected.jinja @@ -1,5 +1,5 @@ {% set the_list = [] %}{% if deferred %} -{% set the_list = [] %}{% set some_list = the_list %}{% do some_list.append(deferred) %} +{% set the_list = [] %}{% set some_list = [] %}{% set the_list = [] %}{% set some_list = the_list %}{% do some_list.append(deferred) %} {% endif %} {{ the_list }} diff --git a/src/test/resources/eager/handles-higher-scope-reference-modification.expected.jinja b/src/test/resources/eager/handles-higher-scope-reference-modification.expected.jinja index 5b7bf126f..95a282556 100644 --- a/src/test/resources/eager/handles-higher-scope-reference-modification.expected.jinja +++ b/src/test/resources/eager/handles-higher-scope-reference-modification.expected.jinja @@ -4,7 +4,7 @@ C: {{ c_list }}.{% endmacro %}{% set b_list = a_list %}{% set b_list = a_list %} B: {% set b_list = a_list %}{% set b_list = a_list %}{% set b_list = a_list %}{% set b_list = a_list %}{{ b_list }}.{% do a_list.append(deferred ? 'A' : '') %} A: {{ a_list }}. --- -{% set a_list = ['a'] %}{% for i in [0] %}{% set b_list = a_list %}{% set b_list = a_list %}{% do b_list.append('b') %}{% for __ignored__ in [0] %}{% set b_list = a_list %}{% set c_list = b_list %}{% do c_list.append(deferred ? 'c' : '') %} +{% set a_list = ['a'] %}{% set b_list = a_list %}{% for i in [0] %}{% set b_list = a_list %}{% set b_list = a_list %}{% do b_list.append('b') %}{% for __ignored__ in [0] %}{% set b_list = a_list %}{% set c_list = b_list %}{% do c_list.append(deferred ? 'c' : '') %} C: {{ c_list }}.{% endfor %}{% set b_list = a_list %}{% do b_list.append(deferred ? 'B' : '') %} B: {% set b_list = a_list %}{{ b_list }}.{% endfor %}{% do a_list.append(deferred ? 'A' : '') %} A: {{ a_list }}. diff --git a/src/test/resources/eager/uses-unique-macro-names.expected.jinja b/src/test/resources/eager/uses-unique-macro-names.expected.jinja index cccab7c13..713b24841 100644 --- a/src/test/resources/eager/uses-unique-macro-names.expected.jinja +++ b/src/test/resources/eager/uses-unique-macro-names.expected.jinja @@ -1,10 +1,10 @@ {% set myname = deferred %} -{% set __macro_foo_97643642_temp_variable_1__ %} +{% set __macro_foo_97643642_temp_variable_0__ %} Goodbye {{ myname }} -{% endset %}{% set a = filter:upper.filter(__macro_foo_97643642_temp_variable_1__, ____int3rpr3t3r____) %} +{% endset %}{% set a = filter:upper.filter(__macro_foo_97643642_temp_variable_0__, ____int3rpr3t3r____) %} {% set __ignored__ %}{% set current_path = 'macro-with-filter.jinja' %} -{% set __macro_foo_927217348_temp_variable_1__ %}Hello {{ myname }}{% endset %}{% set b = filter:upper.filter(__macro_foo_927217348_temp_variable_1__, ____int3rpr3t3r____) %} +{% set __macro_foo_927217348_temp_variable_0__ %}Hello {{ myname }}{% endset %}{% set b = filter:upper.filter(__macro_foo_927217348_temp_variable_0__, ____int3rpr3t3r____) %} {% set current_path = '' %}{% endset %} {{ a }} {{ b }}