Upgrade Babel to self-host with beta.46 (#7784)

This commit is contained in:
Logan Smyth 2018-04-27 15:04:37 -07:00 committed by GitHub
parent 4f312f5739
commit acf509bab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 656 additions and 589 deletions

View File

@ -1,5 +0,0 @@
# Ensure babel-register won't compile fixtures, or try to recompile compiled code.
packages/*/test/fixtures
packages/*/lib
packages/babel-standalone/babel.js
packages/babel-preset-env-standalone/babel-preset-env.js

View File

@ -99,8 +99,6 @@ function buildRollup(packages) {
plugins: [
rollupBabel({
envName: "babylon",
babelrc: false,
extends: "./.babelrc.js",
}),
rollupNodeResolve(),
],

View File

@ -12,12 +12,14 @@ module.exports = function(api) {
};
let convertESM = true;
let ignoreLib = true;
switch (env) {
// Configs used during bundling builds.
case "babylon":
case "standalone":
convertESM = false;
ignoreLib = false;
break;
case "production":
// Config during builds before publish.
@ -40,6 +42,15 @@ module.exports = function(api) {
const config = {
comments: false,
ignore: [
// These may not be strictly necessary with the newly-limited scope of
// babelrc searching, but including them for now because we had them
// in our .babelignore before.
"packages/*/test/fixtures",
ignoreLib ? "packages/*/lib" : null,
"packages/babel-standalone/babel.js",
"packages/babel-preset-env-standalone/babel-preset-env.js",
].filter(Boolean),
presets: [["@babel/env", envOpts]],
plugins: [
// TODO: Use @babel/preset-flow when

View File

@ -10,19 +10,19 @@
"test": "make test"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.44",
"@babel/core": "7.0.0-beta.44",
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.44",
"@babel/preset-env": "7.0.0-beta.44",
"@babel/preset-flow": "7.0.0-beta.44",
"@babel/preset-stage-0": "7.0.0-beta.44",
"@babel/register": "7.0.0-beta.44",
"@babel/cli": "7.0.0-beta.46",
"@babel/core": "7.0.0-beta.46",
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.46",
"@babel/preset-env": "7.0.0-beta.46",
"@babel/preset-flow": "7.0.0-beta.46",
"@babel/preset-stage-0": "7.0.0-beta.46",
"@babel/register": "7.0.0-beta.46",
"babel-core": "^7.0.0-0",
"babel-eslint": "^8.0.1",
"babel-jest": "^22.4.1",
"babel-loader": "8.0.0-beta.0",
"babel-plugin-transform-charcodes": "^0.1.0",
"babylon": "7.0.0-beta.44",
"babylon": "7.0.0-beta.46",
"browserify": "^13.1.1",
"bundle-collapser": "^1.2.1",
"chalk": "^2.3.2",

View File

@ -12,11 +12,35 @@ function assertNotIgnored(result) {
expect(result.ignored).toBeFalsy();
}
function transform(code, opts) {
return babel.transform(code, {
cwd: __dirname,
...opts,
});
}
function transformFile(filename, opts, cb) {
return babel.transformFile(
filename,
{
cwd: __dirname,
...opts,
},
cb,
);
}
function transformFileSync(filename, opts) {
return babel.transformFileSync(filename, {
cwd: __dirname,
...opts,
});
}
// shim
function transformAsync(code, opts) {
return {
then: function(resolve) {
resolve(babel.transform(code, opts));
resolve(transform(code, opts));
},
};
}
@ -32,7 +56,7 @@ describe("parser and generator options", function() {
};
function newTransform(string) {
return babel.transform(string, {
return transform(string, {
ast: true,
parserOpts: {
parser: recast.parse,
@ -48,7 +72,7 @@ describe("parser and generator options", function() {
it("options", function() {
const string = "original;";
expect(newTransform(string).ast).toEqual(
babel.transform(string, { ast: true }).ast,
transform(string, { ast: true }).ast,
);
expect(newTransform(string).code).toBe(string);
});
@ -57,7 +81,7 @@ describe("parser and generator options", function() {
const experimental = "var a: number = 1;";
expect(newTransform(experimental).ast).toEqual(
babel.transform(experimental, {
transform(experimental, {
ast: true,
parserOpts: {
plugins: ["flow"],
@ -67,7 +91,7 @@ describe("parser and generator options", function() {
expect(newTransform(experimental).code).toBe(experimental);
function newTransformWithPlugins(string) {
return babel.transform(string, {
return transform(string, {
ast: true,
plugins: [__dirname + "/../../babel-plugin-syntax-flow"],
parserOpts: {
@ -80,7 +104,7 @@ describe("parser and generator options", function() {
}
expect(newTransformWithPlugins(experimental).ast).toEqual(
babel.transform(experimental, {
transform(experimental, {
ast: true,
parserOpts: {
plugins: ["flow"],
@ -94,7 +118,7 @@ describe("parser and generator options", function() {
const experimental = "if (true) {\n import a from 'a';\n}";
expect(newTransform(experimental).ast).not.toBe(
babel.transform(experimental, {
transform(experimental, {
ast: true,
parserOpts: {
allowImportExportEverywhere: true,
@ -123,7 +147,7 @@ describe("api", function() {
babelrc: false,
};
Object.freeze(options);
babel.transformFile(__dirname + "/fixtures/api/file.js", options, function(
transformFile(__dirname + "/fixtures/api/file.js", options, function(
err,
res,
) {
@ -141,15 +165,14 @@ describe("api", function() {
};
Object.freeze(options);
expect(
babel.transformFileSync(__dirname + "/fixtures/api/file.js", options)
.code,
transformFileSync(__dirname + "/fixtures/api/file.js", options).code,
).toBe("foo();");
expect(options).toEqual({ babelrc: false });
});
it("options throw on falsy true", function() {
return expect(function() {
babel.transform("", {
transform("", {
plugins: [__dirname + "/../../babel-plugin-syntax-jsx", false],
});
}).toThrow(/.plugins\[1\] must be a string, object, function/);
@ -170,7 +193,7 @@ describe("api", function() {
let calledRaw = 0;
let calledIntercept = 0;
babel.transform("function foo() { bar(foobar); }", {
transform("function foo() { bar(foobar); }", {
wrapPluginVisitorMethod: function(pluginAlias, visitorType, callback) {
if (pluginAlias !== "foobar") {
return callback;
@ -204,7 +227,7 @@ describe("api", function() {
let aliasBaseType = null;
function execTest(passPerPreset) {
return babel.transform("type Foo = number; let x = (y): Foo => y;", {
return transform("type Foo = number; let x = (y): Foo => y;", {
sourceType: "script",
passPerPreset: passPerPreset,
presets: [
@ -293,7 +316,7 @@ describe("api", function() {
const oldEnv = process.env.BABEL_ENV;
process.env.BABEL_ENV = "development";
const result = babel.transform("", {
const result = transform("", {
cwd: path.join(__dirname, "fixtures", "config", "complex-plugin-config"),
filename: path.join(
__dirname,
@ -348,7 +371,7 @@ describe("api", function() {
});
it("source map merging", function() {
const result = babel.transform(
const result = transform(
[
/* eslint-disable max-len */
'function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }',
@ -555,7 +578,7 @@ describe("api", function() {
});
it("default", function() {
const result = babel.transform("foo;", {
const result = transform("foo;", {
env: {
development: { comments: false },
},
@ -566,7 +589,7 @@ describe("api", function() {
it("BABEL_ENV", function() {
process.env.BABEL_ENV = "foo";
const result = babel.transform("foo;", {
const result = transform("foo;", {
env: {
foo: { comments: false },
},
@ -576,7 +599,7 @@ describe("api", function() {
it("NODE_ENV", function() {
process.env.NODE_ENV = "foo";
const result = babel.transform("foo;", {
const result = transform("foo;", {
env: {
foo: { comments: false },
},
@ -634,7 +657,7 @@ describe("api", function() {
};
it("only syntax plugin available", function(done) {
babel.transformFile(
transformFile(
__dirname + "/fixtures/api/parsing-errors/only-syntax/file.js",
options,
function(err) {
@ -651,7 +674,7 @@ describe("api", function() {
});
it("both syntax and transform plugin available", function(done) {
babel.transformFile(
transformFile(
__dirname + "/fixtures/api/parsing-errors/syntax-and-transform/file.js",
options,
function(err) {

View File

@ -1,11 +1,18 @@
import fs from "fs";
import path from "path";
import { loadOptions } from "../lib";
import { loadOptions as loadOptionsOrig } from "../lib";
function fixture(...args) {
return path.join(__dirname, "fixtures", "config", ...args);
}
function loadOptions(opts) {
return loadOptionsOrig({
cwd: __dirname,
...opts,
});
}
describe("buildConfigChain", function() {
describe("test", () => {
describe("single", () => {

View File

@ -1,6 +1,13 @@
import { loadOptions } from "../lib";
import { loadOptions as loadOptionsOrig } from "../lib";
import path from "path";
function loadOptions(opts) {
return loadOptionsOrig({
cwd: __dirname,
...opts,
});
}
describe("option-manager", () => {
it("throws for babel 5 plugin", () => {
return expect(() => {

View File

@ -22,7 +22,10 @@ describe("parse", function() {
const input = fs.readFileSync(fixture("input.js"), "utf8");
const output = require(fixture("output.json"));
const result = parse(input, { parserOpts: { plugins: ["decorators"] } });
const result = parse(input, {
parserOpts: { plugins: ["decorators"] },
cwd: fixture(),
});
expect(JSON.parse(JSON.stringify(result))).toEqual(output);
});
});

View File

@ -6,6 +6,7 @@ describe("traversal path", function() {
const expectCode = "function foo() {}";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -24,6 +25,7 @@ describe("traversal path", function() {
const expectCode = "var fn = () => true;";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -53,6 +55,7 @@ describe("traversal path", function() {
const expectCode = "var fn = () => { return true; }";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -74,6 +77,7 @@ describe("traversal path", function() {
const expectCode = "for (KEY in right);";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -104,6 +108,7 @@ describe("traversal path", function() {
const expectCode = "for (var KEY in right);";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -125,6 +130,7 @@ describe("traversal path", function() {
const expectCode = "for (KEY;;);";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {
@ -155,6 +161,7 @@ describe("traversal path", function() {
const expectCode = "for (var KEY;;);";
const actualCode = transform(expectCode, {
cwd: __dirname,
plugins: [
new Plugin({
visitor: {

View File

@ -10,6 +10,7 @@ function test(sourceType, opts, initializer, expectedCode) {
}
const result = babel.transform("", {
cwd: __dirname,
sourceType,
filename: "example" + (sourceType === "module" ? ".mjs" : ".js"),
babelrc: false,

View File

@ -88,14 +88,21 @@ export function runCodeInTestContext(
exports: {},
};
// Expose the test options as "opts", but otherwise run the test in a CommonJS-like environment.
// Note: This isn't doing .call(module.exports, ...) because some of our tests currently
// rely on 'this === global'.
const src = `(function(exports, require, module, __filename, __dirname, opts) {${code}\n});`;
return vm.runInContext(src, testContext, {
filename,
displayErrors: true,
})(module.exports, req, module, filename, dirname, opts);
const oldCwd = process.cwd();
try {
if (opts.filename) process.chdir(path.dirname(opts.filename));
// Expose the test options as "opts", but otherwise run the test in a CommonJS-like environment.
// Note: This isn't doing .call(module.exports, ...) because some of our tests currently
// rely on 'this === global'.
const src = `(function(exports, require, module, __filename, __dirname, opts) {${code}\n});`;
return vm.runInContext(src, testContext, {
filename,
displayErrors: true,
})(module.exports, req, module, filename, dirname, opts);
} finally {
process.chdir(oldCwd);
}
}
function wrapPackagesArray(type, names, optionsDir) {
@ -320,6 +327,7 @@ function run(task) {
function getOpts(self) {
const newOpts = merge(
{
cwd: path.dirname(self.filename),
filename: self.loc,
filenameRelative: self.filename,
sourceFileName: self.filename,

View File

@ -4,6 +4,7 @@ test("Doesn't use the same object for two different nodes in the AST", function(
const code = 'import Foo from "bar"; Foo; Foo;';
const ast = babel.transform(code, {
cwd: __dirname,
ast: true,
plugins: [[require("../"), { loose: true }]],
}).ast;

View File

@ -19,6 +19,7 @@ test("Re-export doesn't overwrite __esModule flag", function() {
context.exports = context.module.exports;
code = babel.transform(code, {
cwd: __dirname,
plugins: [[require("../"), { loose: true }]],
ast: false,
}).code;

View File

@ -1,6 +1,13 @@
import * as babel from "@babel/core";
import es2015 from "../lib";
function transform(code, opts) {
return babel.transform(code, {
cwd: __dirname,
...opts,
});
}
describe("es2015 preset", function() {
it("does throw clear error when no options passed for Babel 6", () => {
expect(function() {
@ -12,7 +19,7 @@ describe("es2015 preset", function() {
describe("loose", function() {
it("throws on non-boolean value", function() {
expect(function() {
babel.transform("", { presets: [[es2015, { loose: 1 }]] });
transform("", { presets: [[es2015, { loose: 1 }]] });
}).toThrow(/must be a boolean/);
});
});
@ -20,7 +27,7 @@ describe("es2015 preset", function() {
describe("spec", function() {
it("throws on non-boolean value", function() {
expect(function() {
babel.transform("", { presets: [[es2015, { spec: 1 }]] });
transform("", { presets: [[es2015, { spec: 1 }]] });
}).toThrow(/must be a boolean/);
});
});
@ -28,31 +35,31 @@ describe("es2015 preset", function() {
describe("modules", function() {
it("doesn't throw when passing one false", function() {
expect(function() {
babel.transform("", { presets: [[es2015, { modules: false }]] });
transform("", { presets: [[es2015, { modules: false }]] });
}).not.toThrow();
});
it("doesn't throw when passing one of: 'commonjs', 'amd', 'umd', 'systemjs", function() {
expect(function() {
babel.transform("", { presets: [[es2015, { modules: "commonjs" }]] });
transform("", { presets: [[es2015, { modules: "commonjs" }]] });
}).not.toThrow();
expect(function() {
babel.transform("", { presets: [[es2015, { modules: "amd" }]] });
transform("", { presets: [[es2015, { modules: "amd" }]] });
}).not.toThrow();
expect(function() {
babel.transform("", { presets: [[es2015, { modules: "umd" }]] });
transform("", { presets: [[es2015, { modules: "umd" }]] });
}).not.toThrow();
expect(function() {
babel.transform("", { presets: [[es2015, { modules: "systemjs" }]] });
transform("", { presets: [[es2015, { modules: "systemjs" }]] });
}).not.toThrow();
});
it("throws when passing neither false nor one of: 'commonjs', 'amd', 'umd', 'systemjs'", function() {
expect(function() {
babel.transform("", { presets: [[es2015, { modules: 1 }]] });
transform("", { presets: [[es2015, { modules: 1 }]] });
}).toThrow();
});
});

View File

@ -42,15 +42,6 @@ function webpackBuild(opts) {
// Use the bundled config so that module syntax is passed through
// for Webpack.
envName: "standalone",
// Some of the node_modules may have their own "babel" section in
// their project.json (or a ".babelrc" file). We need to ignore
// those as we're using our own Babel options.
babelrc: false,
// We explicitly load the `.babelrc.js` file since searching is
// turned off, but we still want to use the main config.
extends: "./.babelrc.js",
},
},
],

1059
yarn.lock

File diff suppressed because it is too large Load Diff