@@ -16,6 +16,7 @@ import { createTaggedTemplateIgnore } from './taggedTemplateIgnore'
1616
1717const EXPRESSION_WRAPPER_PREFIX = '(\n'
1818const EXPRESSION_WRAPPER_SUFFIX = '\n)'
19+ const EMPTY_IGNORED_PATHS = new WeakSet < NodePath < StringLiteral | TemplateElement > > ( )
1920const ignoredTaggedTemplateMatcherCache = new WeakMap < IJsHandlerOptions , ReturnType < typeof createNameMatcher > > ( )
2021
2122function getIgnoredTaggedTemplateMatcher ( options : IJsHandlerOptions ) {
@@ -35,17 +36,19 @@ export function analyzeSource(
3536 handler ?: EvalHandler ,
3637) : SourceAnalysis {
3738 const jsTokenUpdater = new JsTokenUpdater ( )
38- const ignoredPaths = new WeakSet < NodePath < StringLiteral | TemplateElement > > ( )
39- const walker = new NodePathWalker (
40- {
41- ignoreCallExpressionIdentifiers : options . ignoreCallExpressionIdentifiers ,
42- callback ( path ) {
43- if ( path . isStringLiteral ( ) || path . isTemplateElement ( ) ) {
39+ // 仅在需要忽略特定调用参数时记录路径,默认路径复用共享空集合。
40+ const needScope = Boolean ( options . ignoreCallExpressionIdentifiers && options . ignoreCallExpressionIdentifiers . length > 0 )
41+ const ignoredPaths = needScope
42+ ? new WeakSet < NodePath < StringLiteral | TemplateElement > > ( )
43+ : EMPTY_IGNORED_PATHS
44+ const walker = needScope
45+ ? new NodePathWalker ( {
46+ ignoreCallExpressionIdentifiers : options . ignoreCallExpressionIdentifiers ,
47+ callback ( path ) {
4448 ignoredPaths . add ( path )
45- }
46- } ,
47- } ,
48- )
49+ } ,
50+ } )
51+ : new NodePathWalker ( )
4952
5053 let taggedTemplateIgnore : ReturnType < typeof createTaggedTemplateIgnore > | undefined
5154
@@ -59,9 +62,6 @@ export function analyzeSource(
5962 return taggedTemplateIgnore
6063 }
6164
62- // 仅在需要时才构建作用域信息(例如需要遍历调用表达式的实参)。
63- const needScope = Boolean ( options . ignoreCallExpressionIdentifiers && options . ignoreCallExpressionIdentifiers . length > 0 )
64-
6565 const targetPaths : NodePath < StringLiteral | TemplateElement > [ ] = [ ]
6666 const importDeclarations = new Set < NodePath < ImportDeclaration > > ( )
6767 const exportDeclarations = new Set < NodePath < ExportDeclaration > > ( )
0 commit comments