Skip to content

Commit de172a2

Browse files
committed
don't process yield blocks
1 parent 35b711b commit de172a2

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/babel/rewriteHbs.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import recast, { type AST } from 'ember-template-recast';
22
import fs from 'node:fs';
3-
import { fixFilename } from './utils.ts';
3+
import { fixFilename, combineRegexPatterns } from './utils.ts';
44
import { Transformer } from 'content-tag-utils';
55

66
let fileCache = new Map<string, string>();
77

8+
const invalidTagPatterns = [
9+
/^:/, // Don't process named blocks (:block-name)
10+
];
11+
12+
const isInvalidTag = combineRegexPatterns(invalidTagPatterns);
13+
814
function getFullFileContent(filename: string): string {
915
if (fileCache.has(filename)) {
1016
return fileCache.get(filename)!;
@@ -75,6 +81,10 @@ export function templatePlugin(env: { filename: string }) {
7581
return;
7682
}
7783

84+
if (isInvalidTag(node.tag)) {
85+
return;
86+
}
87+
7888
const innerCoordinates = {
7989
line: node.loc.startPosition.line,
8090
column: node.loc.startPosition.column,

src/babel/utils.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,38 @@ export function fixFilename(filename: string): string {
165165

166166
return fileName.replace(workspace, '');
167167
}
168+
169+
/**
170+
* Combines multiple regex patterns into a single regex that tests if ANY of them match.
171+
* Uses the OR operator (|) to join patterns.
172+
*
173+
* @param patterns - Array of RegExp objects to combine
174+
* @returns A function that tests if the input string matches any of the patterns
175+
*
176+
* @example
177+
* const isValid = combineRegexPatterns([
178+
* /^[a-zA-Z]/, // starts with letter
179+
* /^@/, // starts with @
180+
* ]);
181+
* isValid('Hello') // true
182+
* isValid('@component') // true
183+
* isValid('123') // false
184+
*/
185+
export function combineRegexPatterns(
186+
patterns: RegExp[],
187+
): (input: string) => boolean {
188+
if (patterns.length === 0) {
189+
return () => false;
190+
}
191+
192+
if (patterns.length === 1) {
193+
return (input: string) => patterns[0]!.test(input);
194+
}
195+
196+
// Extract source patterns and combine with OR
197+
const combinedPattern = patterns.map((regex) => regex.source).join('|');
198+
199+
const combinedRegex = new RegExp(combinedPattern);
200+
201+
return (input: string) => combinedRegex.test(input);
202+
}

tests/fixtures/yield-blocks.gjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<Thing>
3+
<:block1>
4+
</:block1>
5+
</Thing>
6+
</template>

0 commit comments

Comments
 (0)