@@ -9,7 +9,7 @@ const defaultOptions = {
9
9
10
10
const getAbsolutePolyfill = mod => {
11
11
// 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 } ]+` ) } ` )
13
13
}
14
14
15
15
beforeEach ( ( ) => {
@@ -29,7 +29,7 @@ test('polyfill detection', () => {
29
29
// default includes
30
30
expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
31
31
// usage-based detection
32
- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
32
+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
33
33
34
34
; ( { code } = babel . transformSync ( `
35
35
const a = new Map()
@@ -45,7 +45,7 @@ test('polyfill detection', () => {
45
45
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
46
46
expect ( code ) . toMatch ( getAbsolutePolyfill ( 'es.array.iterator' ) )
47
47
// usage-based detection
48
- expect ( code ) . toMatch ( 'import "core-js/modules/es.map"' )
48
+ expect ( code ) . toMatch ( '"core-js/modules/es.map"' )
49
49
} )
50
50
51
51
test ( 'modern mode always skips polyfills' , ( ) => {
@@ -63,7 +63,7 @@ test('modern mode always skips polyfills', () => {
63
63
// default includes
64
64
expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
65
65
// usage-based detection
66
- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
66
+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
67
67
68
68
; ( { code } = babel . transformSync ( `
69
69
const a = new Map()
@@ -78,7 +78,7 @@ test('modern mode always skips polyfills', () => {
78
78
// default includes
79
79
expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
80
80
// usage-based detection
81
- expect ( code ) . not . toMatch ( 'import "core-js/modules/es.map"' )
81
+ expect ( code ) . not . toMatch ( '"core-js/modules/es.map"' )
82
82
delete process . env . VUE_CLI_MODERN_BUILD
83
83
} )
84
84
@@ -105,9 +105,9 @@ test('async/await', () => {
105
105
` . trim ( ) , defaultOptions )
106
106
expect ( code ) . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
107
107
// should use regenerator runtime
108
- expect ( code ) . toMatch ( `import "regenerator-runtime/runtime"` )
108
+ expect ( code ) . toMatch ( `"regenerator-runtime/runtime"` )
109
109
// 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 \" / )
111
111
} )
112
112
113
113
test ( 'jsx' , ( ) => {
@@ -153,6 +153,47 @@ test('disable absoluteRuntime', () => {
153
153
filename : 'test-entry-file.js'
154
154
} )
155
155
156
- expect ( code ) . toMatch ( 'import _toConsumableArray from "@babel/runtime/helpers/esm /toConsumableArray"' )
156
+ expect ( code ) . toMatch ( '"@babel/runtime/helpers/toConsumableArray"' )
157
157
expect ( code ) . not . toMatch ( getAbsolutePolyfill ( 'es.promise' ) )
158
158
} )
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