@@ -5,6 +5,7 @@ import { MappingChars2String } from '@weapp-core/escape'
55import { describe , expect , it , vi } from 'vitest'
66import { parse , traverse } from '@/babel'
77import * as babel from '@/js/babel'
8+ import * as nameMatcher from '@/utils/nameMatcher'
89
910function prepareEval ( code : string ) {
1011 const ast = parse ( code , { sourceType : 'module' } )
@@ -153,6 +154,32 @@ describe('babel helpers branch coverage', () => {
153154 expect ( analysis . targetPaths ) . toHaveLength ( 1 )
154155 } )
155156
157+ it ( 'does not build ignore matchers when tagged templates are absent' , ( ) => {
158+ const spy = vi . spyOn ( nameMatcher , 'createNameMatcher' )
159+ const ast = parse ( 'const cls = `w-[100px]`' , { sourceType : 'module' } )
160+
161+ const analysis = babel . analyzeSource ( ast , {
162+ ignoreTaggedTemplateExpressionIdentifiers : [ 'styled' ] ,
163+ } )
164+
165+ expect ( analysis . targetPaths ) . toHaveLength ( 1 )
166+ expect ( spy ) . not . toHaveBeenCalled ( )
167+ } )
168+
169+ it ( 'reuses ignored tag matchers for the same options object' , ( ) => {
170+ const spy = vi . spyOn ( nameMatcher , 'createNameMatcher' )
171+ const options = {
172+ ignoreTaggedTemplateExpressionIdentifiers : [ 'styled' ] ,
173+ }
174+
175+ const firstAst = parse ( 'styled`w-[100px]`' , { sourceType : 'module' } )
176+ const secondAst = parse ( 'styled`w-[200px]`' , { sourceType : 'module' } )
177+
178+ expect ( babel . analyzeSource ( firstAst , options ) . targetPaths ) . toHaveLength ( 0 )
179+ expect ( babel . analyzeSource ( secondAst , options ) . targetPaths ) . toHaveLength ( 0 )
180+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
181+ } )
182+
156183 it ( 'falls back to an empty original value for unexpected eval nodes' , ( ) => {
157184 const rawSource = 'eval(`__coverage__` )'
158185 const ast = parse ( rawSource , { sourceType : 'module' } )
0 commit comments