Skip to content

Commit

Permalink
fix(plugin-legacy): polyfill latest features (#7514)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Mar 29, 2022
1 parent f05a813 commit cb388e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/playground/legacy/__tests__/legacy.spec.ts
Expand Up @@ -83,4 +83,8 @@ if (isBuild) {
test('should emit css file', async () => {
expect(listAssets().some((filename) => filename.endsWith('.css')))
})

test('includes structuredClone polyfill which is supported after core-js v3', () => {
expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"')
})
}
1 change: 1 addition & 0 deletions packages/playground/legacy/index.html
@@ -1,6 +1,7 @@
<h1 id="app"></h1>
<div id="env"></div>
<div id="iterators"></div>
<div id="features-after-corejs-3"></div>
<div id="babel-helpers"></div>
<div id="assets"></div>
<script type="module" src="./main.js"></script>
6 changes: 6 additions & 0 deletions packages/playground/legacy/main.js
Expand Up @@ -21,6 +21,12 @@ text('#env', `is legacy: ${isLegacy}`)
// Iterators
text('#iterators', [...new Set(['hello'])].join(''))

// structuredClone is supported core.js v3.20.0+
text(
'#features-after-corejs-3',
JSON.stringify(structuredClone({ foo: 'foo' }))
)

// babel-helpers
// Using `String.raw` to inject `@babel/plugin-transform-template-literals`
// helpers.
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-legacy/index.js
Expand Up @@ -330,7 +330,10 @@ function viteLegacyPlugin(options = {}) {
loose: false,
useBuiltIns: needPolyfills ? 'usage' : false,
corejs: needPolyfills
? { version: 3, proposals: false }
? {
version: require('core-js/package.json').version,
proposals: false
}
: undefined,
shippedProposals: true,
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig
Expand Down

0 comments on commit cb388e2

Please sign in to comment.