Skip to content

Commit 0ccbcff

Browse files
committed
Set "sourceType" to "unambiguous" by default in Babel's options
1 parent 6e1b371 commit 0ccbcff

File tree

10 files changed

+117
-33
lines changed

10 files changed

+117
-33
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040
}],
4141
"no-console": "off",
4242
"valid-jsdoc": ["error", {"requireParamDescription": false, "requireReturnDescription": false}],
43-
"node/no-unsupported-features": ["error", { version: 6 }],
43+
"node/no-unsupported-features": ["error", { version: 8 }],
4444
"node/no-deprecated-api": "error",
4545
"node/no-missing-import": "error",
4646
"node/no-missing-require": [

fixtures/js/array_flat_commonjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = [[1, 2], [3, 4]].flat();

fixtures/js/array_flat_ecmascript.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default [[1, 2], [3, 4]].flat();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const flattened = require('./array_flat_commonjs');
2+
3+
document.getElementById('app').innerHTML = JSON.stringify(flattened);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import flattened from './array_flat_ecmascript';
2+
3+
document.getElementById('app').innerHTML = JSON.stringify(flattened);

lib/loaders/babel.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ module.exports = {
2525
// by some Babel presets/plugins (for instance the ones
2626
// that use browserslist)
2727
// https://github.com/babel/babel-loader#options
28-
cacheDirectory: !webpackConfig.isProduction()
28+
cacheDirectory: !webpackConfig.isProduction(),
29+
30+
// let Babel guess which kind of import/export syntax
31+
// it should use based on the content of files
32+
sourceType: 'unambiguous',
2933
};
3034

3135
// configure babel (unless the user is specifying .babelrc)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@
6363
"babel-eslint": "^10.0.1",
6464
"chai": "^3.5.0",
6565
"chai-fs": "^1.0.0",
66+
"core-js": "^3.0.0",
6667
"eslint": "^5.15.2",
6768
"eslint-loader": "^2.1.2",
6869
"eslint-plugin-header": "^1.0.0",
6970
"eslint-plugin-import": "^2.8.0",
70-
"eslint-plugin-node": "^4.2.2",
71+
"eslint-plugin-node": "^8.0.1",
7172
"fork-ts-checker-webpack-plugin": "^0.4.1",
7273
"handlebars": "^4.0.11",
7374
"handlebars-loader": "^1.7.0",

test/functional.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,61 @@ module.exports = {
10931093
});
10941094
});
10951095

1096+
it('Babel adds polyfills correctly', (done) => {
1097+
const cwd = process.cwd();
1098+
after(() => {
1099+
process.chdir(cwd);
1100+
});
1101+
1102+
const appDir = testSetup.createTestAppDir();
1103+
process.chdir(appDir);
1104+
1105+
fs.writeFileSync(
1106+
path.join(appDir, 'package.json'),
1107+
1108+
// The test case uses Array.flat which
1109+
// isn't supported by IE11
1110+
'{"browserslist": "IE 11"}'
1111+
);
1112+
1113+
const config = createWebpackConfig('www/build', 'dev');
1114+
config.setPublicPath('/build');
1115+
config.addEntry('commonjs', './js/import_polyfills_commonjs.js');
1116+
config.addEntry('ecmascript', './js/import_polyfills_ecmascript.js');
1117+
config.configureBabel(null, {
1118+
useBuiltIns: 'usage',
1119+
corejs: 3,
1120+
});
1121+
1122+
testSetup.runWebpack(config, async(webpackAssert) => {
1123+
for (const scriptName of ['commonjs.js', 'ecmascript.js']) {
1124+
// Check that the polyfills are included correctly
1125+
// in both files.
1126+
webpackAssert.assertOutputFileContains(
1127+
scriptName,
1128+
'Array.prototype.flat'
1129+
);
1130+
1131+
// Test that the generated scripts work fine
1132+
await new Promise(resolve => {
1133+
testSetup.requestTestPage(
1134+
path.join(config.getContext(), 'www'),
1135+
[
1136+
'build/runtime.js',
1137+
`build/${scriptName}`,
1138+
],
1139+
(browser) => {
1140+
browser.assert.text('body', '[1,2,3,4]');
1141+
resolve();
1142+
}
1143+
);
1144+
});
1145+
}
1146+
1147+
done();
1148+
});
1149+
});
1150+
10961151
it('When enabled, react JSX is transformed!', (done) => {
10971152
const config = createWebpackConfig('www/build', 'dev');
10981153
config.setPublicPath('/build');

test/loaders/babel.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('loaders/babel', () => {
4545
const actualLoaders = babelLoader.getLoaders(config);
4646
// we only add cacheDirectory
4747
expect(actualLoaders[0].options).to.deep.equal({
48-
cacheDirectory: true
48+
cacheDirectory: true,
49+
sourceType: 'unambiguous',
4950
});
5051
});
5152

@@ -57,7 +58,8 @@ describe('loaders/babel', () => {
5758
const actualLoaders = babelLoader.getLoaders(config);
5859
// cacheDirectory is disabled in production mode
5960
expect(actualLoaders[0].options).to.deep.equal({
60-
cacheDirectory: false
61+
cacheDirectory: false,
62+
sourceType: 'unambiguous',
6163
});
6264
});
6365

yarn.lock

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,11 @@ core-js@^2.4.0:
21962196
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895"
21972197
integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==
21982198

2199+
core-js@^3.0.0:
2200+
version "3.0.1"
2201+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.0.1.tgz#1343182634298f7f38622f95e73f54e48ddf4738"
2202+
integrity sha512-sco40rF+2KlE0ROMvydjkrVMMG1vYilP2ALoRXcYR4obqbYIuV3Bg+51GEDW+HF8n7NRA+iaA4qD0nD9lo9mew==
2203+
21992204
[email protected], core-util-is@~1.0.0:
22002205
version "1.0.2"
22012206
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -3042,6 +3047,14 @@ eslint-module-utils@^2.3.0:
30423047
debug "^2.6.8"
30433048
pkg-dir "^2.0.0"
30443049

3050+
eslint-plugin-es@^1.3.1:
3051+
version "1.4.0"
3052+
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-1.4.0.tgz#475f65bb20c993fc10e8c8fe77d1d60068072da6"
3053+
integrity sha512-XfFmgFdIUDgvaRAlaXUkxrRg5JSADoRC8IkKLc/cISeR3yHVMefFHQZpcyXXEUUPHfy5DwviBcrfqlyqEwlQVw==
3054+
dependencies:
3055+
eslint-utils "^1.3.0"
3056+
regexpp "^2.0.1"
3057+
30453058
eslint-plugin-header@^1.0.0:
30463059
version "1.2.0"
30473060
resolved "https://registry.yarnpkg.com/eslint-plugin-header/-/eslint-plugin-header-1.2.0.tgz#f704779c6fbc7c668f180d835de1f462b0467c37"
@@ -3063,16 +3076,17 @@ eslint-plugin-import@^2.8.0:
30633076
read-pkg-up "^2.0.0"
30643077
resolve "^1.9.0"
30653078

3066-
eslint-plugin-node@^4.2.2:
3067-
version "4.2.3"
3068-
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-4.2.3.tgz#c04390ab8dbcbb6887174023d6f3a72769e63b97"
3069-
integrity sha512-vIUQPuwbVYdz/CYnlTLsJrRy7iXHQjdEe5wz0XhhdTym3IInM/zZLlPf9nZ2mThsH0QcsieCOWs2vOeCy/22LQ==
3079+
eslint-plugin-node@^8.0.1:
3080+
version "8.0.1"
3081+
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-8.0.1.tgz#55ae3560022863d141fa7a11799532340a685964"
3082+
integrity sha512-ZjOjbjEi6jd82rIpFSgagv4CHWzG9xsQAVp1ZPlhRnnYxcTgENUVBvhYmkQ7GvT1QFijUSo69RaiOJKhMu6i8w==
30703083
dependencies:
3071-
ignore "^3.0.11"
3072-
minimatch "^3.0.2"
3073-
object-assign "^4.0.1"
3074-
resolve "^1.1.7"
3075-
semver "5.3.0"
3084+
eslint-plugin-es "^1.3.1"
3085+
eslint-utils "^1.3.1"
3086+
ignore "^5.0.2"
3087+
minimatch "^3.0.4"
3088+
resolve "^1.8.1"
3089+
semver "^5.5.0"
30763090

30773091
30783092
version "3.7.1"
@@ -3098,7 +3112,7 @@ eslint-scope@^4.0.3:
30983112
esrecurse "^4.1.0"
30993113
estraverse "^4.1.1"
31003114

3101-
eslint-utils@^1.3.1:
3115+
eslint-utils@^1.3.0, eslint-utils@^1.3.1:
31023116
version "1.3.1"
31033117
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.3.1.tgz#9a851ba89ee7c460346f97cf8939c7298827e512"
31043118
integrity sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==
@@ -4192,16 +4206,16 @@ ignore-walk@^3.0.1:
41924206
dependencies:
41934207
minimatch "^3.0.4"
41944208

4195-
ignore@^3.0.11:
4196-
version "3.3.10"
4197-
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043"
4198-
integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==
4199-
42004209
ignore@^4.0.6:
42014210
version "4.0.6"
42024211
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
42034212
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==
42044213

4214+
ignore@^5.0.2:
4215+
version "5.0.6"
4216+
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.0.6.tgz#562dacc7ec27d672dde433aa683c543b24c17694"
4217+
integrity sha512-/+hp3kUf/Csa32ktIaj0OlRqQxrgs30n62M90UBpNd9k+ENEch5S+hmbW3DtcJGz3sYFTh4F3A6fQ0q7KWsp4w==
4218+
42054219
image-size@~0.5.0:
42064220
version "0.5.5"
42074221
resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c"
@@ -7123,20 +7137,20 @@ resolve-url@^0.2.1:
71237137
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
71247138
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
71257139

7126-
resolve@^1.1.7, resolve@^1.3.2:
7127-
version "1.8.1"
7128-
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
7129-
integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==
7130-
dependencies:
7131-
path-parse "^1.0.5"
7132-
7133-
resolve@^1.10.0, resolve@^1.5.0, resolve@^1.9.0:
7140+
resolve@^1.10.0, resolve@^1.5.0, resolve@^1.8.1, resolve@^1.9.0:
71347141
version "1.10.0"
71357142
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba"
71367143
integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==
71377144
dependencies:
71387145
path-parse "^1.0.6"
71397146

7147+
resolve@^1.3.2:
7148+
version "1.8.1"
7149+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
7150+
integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==
7151+
dependencies:
7152+
path-parse "^1.0.5"
7153+
71407154
restore-cursor@^2.0.0:
71417155
version "2.0.0"
71427156
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
@@ -7318,11 +7332,6 @@ selfsigned@^1.9.1:
73187332
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
73197333
integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==
73207334

7321-
[email protected], semver@~5.3.0:
7322-
version "5.3.0"
7323-
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
7324-
integrity sha1-myzl094C0XxgEq0yaqa00M9U+U8=
7325-
73267335
semver@^5.0.1, semver@^5.5.0:
73277336
version "5.5.0"
73287337
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
@@ -7333,6 +7342,11 @@ semver@^5.4.1:
73337342
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"
73347343
integrity sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==
73357344

7345+
semver@~5.3.0:
7346+
version "5.3.0"
7347+
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
7348+
integrity sha1-myzl094C0XxgEq0yaqa00M9U+U8=
7349+
73367350
73377351
version "0.16.2"
73387352
resolved "https://registry.yarnpkg.com/send/-/send-0.16.2.tgz#6ecca1e0f8c156d141597559848df64730a6bbc1"

0 commit comments

Comments
 (0)