Skip to content

Commit

Permalink
Use a dynamic visitor key
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 8, 2024
1 parent 0cf436a commit 5acf119
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/macros/src/glimmer/ast-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

0 comments on commit 5acf119

Please sign in to comment.