File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed
Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 11import recast , { type AST } from 'ember-template-recast' ;
22import fs from 'node:fs' ;
3- import { fixFilename } from './utils.ts' ;
3+ import { fixFilename , combineRegexPatterns } from './utils.ts' ;
44import { Transformer } from 'content-tag-utils' ;
55
66let 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+
814function 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 ,
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 1+ <template >
2+ <Thing >
3+ <: block1 >
4+ </: block1 >
5+ </Thing >
6+ </template >
You can’t perform that action at this time.
0 commit comments