Skip to content

Commit ad29e30

Browse files
committed
perf(weapp-tailwindcss): 修正模块替换空输入快路径
1 parent a55a1ee commit ad29e30

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

packages/weapp-tailwindcss/src/js/sourceAnalysis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function collectModuleSpecifierReplacementTokens(
5656
analysis.importDeclarations.size === 0
5757
&& analysis.exportDeclarations.size === 0
5858
&& analysis.requireCallPaths.length === 0
59-
&& analysis.walker.imports.length === 0
59+
&& analysis.walker.imports.size === 0
6060
) {
6161
return []
6262
}

packages/weapp-tailwindcss/test/js/sourceAnalysis.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NodePath } from '@babel/traverse'
22
import type { ImportDeclaration, StringLiteral } from '@babel/types'
3+
import type { SourceAnalysis } from '@/js/babel'
34
import type { IJsHandlerOptions } from '@/types'
45
import MagicString from 'magic-string'
56
import { describe, expect, it } from 'vitest'
@@ -95,4 +96,28 @@ describe('sourceAnalysis helpers', () => {
9596
expect(analysis.walker.imports).toBe(originalImports)
9697
expect(analysis.walker.imports.size).toBe(originalImportCount)
9798
})
99+
100+
it('returns early when there are no module specifiers to rewrite', () => {
101+
const imports = {
102+
size: 0,
103+
[Symbol.iterator]() {
104+
throw new Error('should not iterate imports')
105+
},
106+
}
107+
108+
const analysis = {
109+
ast: {} as SourceAnalysis['ast'],
110+
walker: {
111+
imports,
112+
} as unknown as SourceAnalysis['walker'],
113+
jsTokenUpdater: new JsTokenUpdater(),
114+
targetPaths: [],
115+
importDeclarations: new Set(),
116+
exportDeclarations: new Set(),
117+
requireCallPaths: [],
118+
ignoredPaths: new WeakSet(),
119+
} satisfies SourceAnalysis
120+
121+
expect(collectModuleSpecifierReplacementTokens(analysis, { './foo': './bar' })).toEqual([])
122+
})
98123
})

0 commit comments

Comments
 (0)