@@ -9,7 +9,7 @@ const defaultOptions = {
99
1010const getAbsolutePolyfill = mod => {
1111 // expected to include a `node_modules` in the import path because we use absolute path for core-js
12- return new RegExp ( `import "${ [ '.*node_modules' , 'core-js' , 'modules' , mod ] . join ( `[\\${ path . sep } ]+` ) } ` )
12+ return new RegExp ( `"${ [ '.*node_modules' , 'core-js' , 'modules' , mod ] . join ( `[\\${ path . sep } ]+` ) } ` )
1313}
1414
1515beforeEach ( ( ) => {
@@ -29,7 +29,7 @@ test('polyfill detection', () => {
2929 // default includes
3030 expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
3131 // usage-based detection
32- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
32+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
3333
3434 ; ( { code } = babel . transformSync ( `
3535 const a = new Map()
@@ -45,7 +45,7 @@ test('polyfill detection', () => {
4545 // promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
4646 expect ( code ) . toMatch ( getAbsolutePolyfill ( 'es.array.iterator' ) )
4747 // usage-based detection
48- expect ( code ) . toMatch ( 'import "core-js/modules/es.map"' )
48+ expect ( code ) . toMatch ( '"core-js/modules/es.map"' )
4949} )
5050
5151test ( 'modern mode always skips polyfills' , ( ) => {
@@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
6363 // default includes
6464 expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
6565 // usage-based detection
66- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
66+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
6767
6868 ; ( { code } = babel . transformSync ( `
6969 const a = new Map()
@@ -78,7 +78,7 @@ test('modern mode always skips polyfills', () => {
7878 // default includes
7979 expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
8080 // usage-based detection
81- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
81+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
8282 delete process . env . VUE_CLI_MODERN_BUILD
8383} )
8484
@@ -105,9 +105,9 @@ test('async/await', () => {
105105 ` . trim ( ) , defaultOptions )
106106 expect ( code ) . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
107107 // should use regenerator runtime
108- expect ( code ) . toMatch ( `import "regenerator-runtime/runtime"` )
108+ expect ( code ) . toMatch ( `"regenerator-runtime/runtime"` )
109109 // should use required helper instead of inline
110- expect ( code ) . toMatch ( / i m p o r t _ a s y n c T o G e n e r a t o r f r o m " .* r u n t i m e \/ h e l p e r s \/ e s m \/ a s y n c T o G e n e r a t o r \" / )
110+ expect ( code ) . toMatch ( / " .* r u n t i m e \/ h e l p e r s \/ a s y n c T o G e n e r a t o r \" / )
111111} )
112112
113113test ( 'jsx' , ( ) => {
@@ -153,6 +153,47 @@ test('disable absoluteRuntime', () => {
153153 filename : 'test-entry-file.js'
154154 } )
155155
156- expect ( code ) . toMatch ( 'import _toConsumableArray from "@babel/runtime/helpers/esm /toConsumableArray"' )
156+ expect ( code ) . toMatch ( '"@babel/runtime/helpers/toConsumableArray"' )
157157 expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
158158} )
159+
160+ test ( 'should inject polyfills / helpers using "require" statements for a umd module' , ( ) => {
161+ // TODO:
162+ const { code } = babel . transformSync ( `
163+ (function (global, factory) {
164+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
165+ typeof define === 'function' && define.amd ? define(factory) :
166+ (global = global || self, global.Vue = factory());
167+ }(this, function () {
168+ const a = [...arr]
169+ new Promise()
170+ }))
171+ ` . trim ( ) , {
172+ babelrc : false ,
173+ presets : [ [ preset , {
174+ absoluteRuntime : false
175+ } ] ] ,
176+ filename : 'test-entry-file.js'
177+ } )
178+ expect ( code ) . toMatch ( 'require("@babel/runtime/helpers/toConsumableArray")' )
179+ expect ( code ) . toMatch ( 'require("core-js/modules/es.promise")' )
180+ expect ( code ) . not . toMatch ( 'import ' )
181+ } )
182+
183+ test ( 'should inject polyfills / helpers using "import" statements for an es module' , ( ) => {
184+ const { code } = babel . transformSync ( `
185+ import Vue from 'vue'
186+ const a = [...arr]
187+ new Promise()
188+ ` . trim ( ) , {
189+ babelrc : false ,
190+ presets : [ [ preset , {
191+ absoluteRuntime : false
192+ } ] ] ,
193+ filename : 'test-entry-file.js'
194+ } )
195+
196+ expect ( code ) . toMatch ( 'import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"' )
197+ expect ( code ) . toMatch ( 'import "core-js/modules/es.promise"' )
198+ expect ( code ) . not . toMatch ( 'require(' )
199+ } )
0 commit comments