From e3010b2f135729898c8e1d891767cde950bfb75e Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Wed, 30 Mar 2022 01:28:54 +0900 Subject: [PATCH] fix(plugin-legacy): polyfill latest features --- packages/playground/legacy/__tests__/legacy.spec.ts | 4 ++++ packages/playground/legacy/index.html | 1 + packages/playground/legacy/main.js | 6 ++++++ packages/plugin-legacy/index.js | 5 ++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/playground/legacy/__tests__/legacy.spec.ts b/packages/playground/legacy/__tests__/legacy.spec.ts index b8025694437502..65bd39ff32b1d1 100644 --- a/packages/playground/legacy/__tests__/legacy.spec.ts +++ b/packages/playground/legacy/__tests__/legacy.spec.ts @@ -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"') + }) } diff --git a/packages/playground/legacy/index.html b/packages/playground/legacy/index.html index bdc2feac6b4fbe..d481766463cd4f 100644 --- a/packages/playground/legacy/index.html +++ b/packages/playground/legacy/index.html @@ -1,6 +1,7 @@

+
diff --git a/packages/playground/legacy/main.js b/packages/playground/legacy/main.js index b05acf439bdff8..31579b4717810d 100644 --- a/packages/playground/legacy/main.js +++ b/packages/playground/legacy/main.js @@ -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. diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index 626b48f85ea955..41f7157ebfc533 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -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