Skip to content

Commit

Permalink
Handle undefined paths, and factor better
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 11, 2024
1 parent 653ab87 commit bc7d79b
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 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: {
Block: {
Template: {
enter(node: any) {
if (node.blockParams.length > 0) {
scopeStack.push(node.blockParams);
Expand All @@ -89,9 +89,7 @@ export function makeFirstTransform(opts: FirstTransformParams) {
return;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return;
}

Expand Down Expand Up @@ -125,9 +123,7 @@ export function makeFirstTransform(opts: FirstTransformParams) {
return;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'macroGetOwnConfig') {
Expand Down Expand Up @@ -173,7 +169,7 @@ export function makeSecondTransform() {
name: '@embroider/macros/second',

visitor: {
Block: {
Template: {
enter(node: any) {
if (node.blockParams.length > 0) {
scopeStack.push(node.blockParams);
Expand All @@ -190,9 +186,7 @@ export function makeSecondTransform() {
return;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand All @@ -207,9 +201,7 @@ export function makeSecondTransform() {
return;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand Down Expand Up @@ -248,9 +240,7 @@ export function makeSecondTransform() {
return true;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return true;
}
if (modifier.path.original === 'macroMaybeAttrs') {
Expand All @@ -265,9 +255,7 @@ export function makeSecondTransform() {
return;
}

let head = 'head' in node.path ? node.path.head : node.path.parts[0];

if (inScope(scopeStack, head)) {
if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand Down Expand Up @@ -300,3 +288,9 @@ function inScope(scopeStack: string[][], name: string) {
}
return false;
}

function headOf(path: any) {
if (!path) return;

return 'head' in path ? path.head : path.parts[0];
}

0 comments on commit bc7d79b

Please sign in to comment.