From fd08c5ec8bf158de3673206adad716a3d732c51f Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:54:36 -0400 Subject: [PATCH] Use a dynamic visitor key --- packages/macros/src/glimmer/ast-transform.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/macros/src/glimmer/ast-transform.ts b/packages/macros/src/glimmer/ast-transform.ts index 27b6652b4..67086fa30 100644 --- a/packages/macros/src/glimmer/ast-transform.ts +++ b/packages/macros/src/glimmer/ast-transform.ts @@ -72,7 +72,7 @@ export function makeFirstTransform(opts: FirstTransformParams) { name: '@embroider/macros/first', visitor: { - Template: { + [rootVisitorKey(env)]: { enter(node: any) { if (node.blockParams.length > 0) { scopeStack.push(node.blockParams); @@ -169,7 +169,7 @@ export function makeSecondTransform() { name: '@embroider/macros/second', visitor: { - Template: { + [rootVisitorKey(env)]: { enter(node: any) { if (node.blockParams.length > 0) { scopeStack.push(node.blockParams); @@ -294,3 +294,14 @@ function headOf(path: any) { return 'head' in path ? path.head : path.parts[0]; } + +/** + * Template is available in ember-source 3.17+ + * Program is deprecated in ember-source 5.9+ + */ +function rootVisitorKey(env: any) { + let hasTemplate = 'template' in env.syntax.builders; + let rootKey = hasTemplate ? 'Template' : 'Program'; + + return rootKey; +}