Skip to content

Commit

Permalink
Merge pull request #1958 from parcel-bundler/jasper/remove-babel6
Browse files Browse the repository at this point in the history
Various updates to Babel 7 branch
  • Loading branch information
devongovett authored Sep 4, 2018
2 parents e0df562 + 367d5ec commit e89f06c
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 281 deletions.
24 changes: 8 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,11 @@
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"ansi-to-html": "^0.6.4",
"babel-code-frame": "^6.26.0",
"babel-core": "^6.25.0",
"babel-generator": "^6.25.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-template": "^6.26.0",
"babel-traverse": "^6.26.0",
"babel-types": "^6.26.0",
"babylon": "^6.17.4",
"babylon-walk": "^1.0.2",
"browserslist": "^3.2.6",
"chalk": "^2.1.0",
Expand Down Expand Up @@ -84,11 +73,14 @@
"ws": "^5.1.1"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/register": "^7.0.0",
"@vue/component-compiler-utils": "^2.0.0",
"babel-cli": "^6.26.0",
"babel-plugin-transform-async-super": "^1.0.0",
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babylon": "^6.18.0",
"bsb-js": "^1.0.1",
"codecov": "^3.0.0",
"coffeescript": "^2.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/.babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"presets": [["env", {
"presets": [["@babel/preset-env", {
"targets": {
"node": "6"
}
}]],
"plugins": ["transform-async-super"],
"plugins": ["@babel/plugin-transform-runtime"],
"ignore": ["builtins"]
}
36 changes: 28 additions & 8 deletions src/assets/JSAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const collectDependencies = require('../visitors/dependencies');
const walk = require('babylon-walk');
const Asset = require('../Asset');
// const babylon = require('@babel/parser');
const localRequire = require('../utils/localRequire');
const insertGlobals = require('../visitors/globals');
const fsVisitor = require('../visitors/fs');
const envVisitor = require('../visitors/env');
Expand Down Expand Up @@ -62,7 +63,7 @@ class JSAsset extends Asset {

async getParserOptions() {
// Babylon options. We enable a few plugins by default.
const options = {
let options = {
parserOpts: {
filename: this.name,
allowReturnOutsideFunction: true,
Expand All @@ -77,19 +78,38 @@ class JSAsset extends Asset {

// Check if there is a babel config file. If so, determine which parser plugins to enable
this.babelConfig = await babel.getConfig(this);
Object.assign(options, this.babelConfig);
// if (this.babelConfig) {
// const file = new BabelFile(this.babelConfig);
// options.plugins.push(...file.parserOpts.plugins);
// }
if (this.babelConfig) {
if (this.babelConfig.babelVersion === 6) {
options.parserOpts.tokens = true;
options = options.parserOpts;
}

Object.assign(options, this.babelConfig);

let babelVersion = this.babelConfig.babelVersion;
Object.defineProperty(options, 'babelVersion', {
value: babelVersion,
configurable: true
});

// if (this.babelConfig) {
// const file = new BabelFile(this.babelConfig);
// options.plugins.push(...file.parserOpts.plugins);
// }
}

return options;
}

async parse(code) {
const options = await this.getParserOptions();
// return babylon.parse(code, options);
return babelCore.parse(code, options);

if (options.babelVersion === 6) {
let babylon = await localRequire('babylon', this.name);
return babylon.parse(code, options);
} else {
return babelCore.parse(code, options);
}
}

traverse(visitor) {
Expand Down
5 changes: 3 additions & 2 deletions src/packagers/JSConcatPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ class JSConcatPackager extends Packager {
// Add source map url if a map bundle exists
let mapBundle = this.bundle.siblingBundlesMap.get('map');
if (mapBundle) {
output += `\n//# sourceMappingURL=${urlJoin(
let mapUrl = urlJoin(
this.options.publicURL,
path.basename(mapBundle.name)
)}`;
);
output += `\n//# sourceMappingURL=${mapUrl}`;
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/packagers/JSPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,11 @@ class JSPackager extends Packager {
// Add source map url if a map bundle exists
let mapBundle = this.bundle.siblingBundlesMap.get('map');
if (mapBundle) {
await this.write(
`\n//# sourceMappingURL=${urlJoin(
this.options.publicURL,
path.basename(mapBundle.name)
)}`
let mapUrl = urlJoin(
this.options.publicURL,
path.basename(mapBundle.name)
);
await this.write(`\n//# sourceMappingURL=${mapUrl}`);
}
}
await this.dest.end();
Expand Down
2 changes: 1 addition & 1 deletion src/scope-hoisting/concat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {relative} = require('path');
const template = require('babel-template');
const template = require('@babel/template').default;
const t = require('@babel/types');
const traverse = require('@babel/traverse').default;
const generate = require('@babel/generator').default;
Expand Down
13 changes: 6 additions & 7 deletions src/scope-hoisting/hoist.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const path = require('path');
const matchesPattern = require('../visitors/matches-pattern');
const mm = require('micromatch');
const t = require('@babel/types');
const template = require('babel-template');
const template = require('@babel/template').default;
const rename = require('./renamer');
const {getName, getIdentifier, getExportIdentifier} = require('./utils');

Expand Down Expand Up @@ -175,20 +174,20 @@ module.exports = {
return;
}

if (matchesPattern(path.node, 'module.exports')) {
if (t.matchesPattern(path.node, 'module.exports')) {
path.replaceWith(getExportsIdentifier(asset));
asset.cacheData.isCommonJS = true;
}

if (matchesPattern(path.node, 'module.id')) {
if (t.matchesPattern(path.node, 'module.id')) {
path.replaceWith(t.stringLiteral(asset.id));
}

if (matchesPattern(path.node, 'module.hot')) {
if (t.matchesPattern(path.node, 'module.hot')) {
path.replaceWith(t.identifier('null'));
}

if (matchesPattern(path.node, 'module.bundle')) {
if (t.matchesPattern(path.node, 'module.bundle')) {
path.replaceWith(t.identifier('require'));
}
},
Expand Down Expand Up @@ -332,7 +331,7 @@ module.exports = {
);
}

if (matchesPattern(callee, 'require.resolve')) {
if (t.matchesPattern(callee, 'require.resolve')) {
path.replaceWith(
REQUIRE_RESOLVE_CALL_TEMPLATE({
ID: t.stringLiteral(asset.id),
Expand Down
Loading

0 comments on commit e89f06c

Please sign in to comment.