Skip to content

Commit 989a42e

Browse files
authored
fix(legacy): don't use newer syntax when minifying legacy chunks (#23013)
1 parent 91f3257 commit 989a42e

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/plugin-legacy/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
538538
minify: resolveLegacyOutputMinify(
539539
config.build.minify,
540540
supportsLegacyOxcMinification,
541+
// Don't use newer syntax for legacy chunks
542+
'es2015',
541543
),
542544
}
543545
}

playground/legacy/__tests__/legacy.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ describe.runIf(isBuild)('build', () => {
123123
expect(findAssetFile(/polyfills-legacy/)).toMatch(terserPattern)
124124
})
125125

126+
test('should not use newer syntax when minifying legacy chunks', () => {
127+
// The playground targets IE 11, so babel lowers the legacy chunks to ES5.
128+
// The minifier must not reintroduce syntax newer than its `es2015` compress
129+
// target: `try {} catch (e) {}` must not be collapsed to `try {} catch {}`
130+
// (ES2019) and optional chaining (ES2020) must not appear.
131+
const mainLegacyChunk = findAssetFile(/chunk-main-legacy/)
132+
expect(mainLegacyChunk).toMatch(/catch\s*\(/)
133+
expect(mainLegacyChunk).not.toMatch(/catch\s*\{/)
134+
expect(mainLegacyChunk).not.toMatch(/\w\?\.\w/)
135+
})
136+
126137
test('should emit css file', async () => {
127138
expect(
128139
listAssets().some((filename) => filename.endsWith('.css')),

0 commit comments

Comments
 (0)