HubSpot / jinjava

Jinja template engine for Java
Apache License 2.0
700 stars 169 forks source link

Fix aliased macro function in set tag and duplicate DeferredTokens #1170

Closed jasmith-hs closed 7 months ago

jasmith-hs commented 7 months ago

Specifically in a set tag, we weren't properly removing deferred words from the eagerExecutionResult.getResult().getDeferredWords() because we were unioning those with the set tag's variable name.

Part of hydrateReconstructionFromContextBeforeDeferring will find the deferred macro functions which are marked as usedDeferredWords and hydrate their reconstruction within the prefixToPreserveState, and then they will get removed from eagerExecutionResult.getResult().getDeferredWords(), but since a new set was being created via:

 Stream
  .concat(
    eagerExecutionResult.getResult().getDeferredWords().stream(),
    Arrays.stream(variables).filter(var -> var.contains("."))
  )
  .collect(Collectors.toSet())

We weren't removing the macro functions, which was causing the import alias to be fully deferred unnecessarily.