Skip to content

Commit cb388e2

Browse files
authored
fix(plugin-legacy): polyfill latest features (#7514)
1 parent f05a813 commit cb388e2

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

packages/playground/legacy/__tests__/legacy.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,8 @@ if (isBuild) {
8383
test('should emit css file', async () => {
8484
expect(listAssets().some((filename) => filename.endsWith('.css')))
8585
})
86+
87+
test('includes structuredClone polyfill which is supported after core-js v3', () => {
88+
expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"')
89+
})
8690
}

packages/playground/legacy/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h1 id="app"></h1>
22
<div id="env"></div>
33
<div id="iterators"></div>
4+
<div id="features-after-corejs-3"></div>
45
<div id="babel-helpers"></div>
56
<div id="assets"></div>
67
<script type="module" src="./main.js"></script>

packages/playground/legacy/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ text('#env', `is legacy: ${isLegacy}`)
2121
// Iterators
2222
text('#iterators', [...new Set(['hello'])].join(''))
2323

24+
// structuredClone is supported core.js v3.20.0+
25+
text(
26+
'#features-after-corejs-3',
27+
JSON.stringify(structuredClone({ foo: 'foo' }))
28+
)
29+
2430
// babel-helpers
2531
// Using `String.raw` to inject `@babel/plugin-transform-template-literals`
2632
// helpers.

packages/plugin-legacy/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ function viteLegacyPlugin(options = {}) {
330330
loose: false,
331331
useBuiltIns: needPolyfills ? 'usage' : false,
332332
corejs: needPolyfills
333-
? { version: 3, proposals: false }
333+
? {
334+
version: require('core-js/package.json').version,
335+
proposals: false
336+
}
334337
: undefined,
335338
shippedProposals: true,
336339
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig

0 commit comments

Comments
 (0)