I'm extremely stupid and didn't commit as I go. To anyone reading this
I'm extremely sorry. A lot of these changes are very broad and I plan on
releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm
afraid I couldn't wait. If you're ever in London I'll buy you a beer
(or assorted beverage!) to make up for it, also I'll kiss your feet and
give you a back massage, maybe.
This commit is contained in:
Sebastian McKenzie
2015-10-29 17:51:24 +00:00
parent 3974dd762d
commit ae7d5367f1
1501 changed files with 16477 additions and 19786 deletions

View File

@@ -1 +1 @@
module.exports = require("babel-core");
throw new Error("Use the `babel-core` package not `babel`.");

View File

@@ -1,6 +1,6 @@
{
"name": "babel",
"version": "5.8.23",
"name": "babel-cli",
"version": "5.10.32",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -8,10 +8,10 @@
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.6.21",
"babel-polyfill": "^5.0.0",
"babel-core": "^5.10.32",
"babel-polyfill": "^5.10.32",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"commander": "^2.8.1",
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^0.1.0",
"glob": "^5.0.5",
@@ -20,13 +20,13 @@
"path-exists": "^1.0.0",
"path-is-absolute": "^1.0.0",
"slash": "^1.0.0",
"source-map": "^0.4.0",
"v8flags": "^2.0.10"
"source-map": "^0.5.0",
"v8flags": "^2.0.10",
"babel-runtime": "^5.10.32"
},
"bin": {
"babel": "./bin/babel.js",
"babel-node": "./bin/babel-node.js",
"babel-external-helpers": "./bin/babel-external-helpers.js",
"babel-plugin": "./bin/babel-plugin.js"
"babel-external-helpers": "./bin/babel-external-helpers.js"
}
}
}

View File

@@ -15,10 +15,11 @@ let program = new commander.Command("babel-node");
program.option("-e, --eval [script]", "Evaluate script");
program.option("-p, --print [code]", "Evaluate script and print result");
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
program.option("-o, --only [globs]", "");
program.option("-i, --ignore [globs]", "");
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
program.option("-w, --plugins [string]", "TODO", util.list);
program.option("-b, --presets [string]", "TODO", util.list);
program.option("-w, --plugins [string]", "", util.list);
program.option("-b, --presets [string]", "", util.list);
let pkg = require("../package.json");
program.version(pkg.version);
@@ -28,24 +29,24 @@ program.parse(process.argv);
//
register({
extensions: program.extensions,
optional: program.optional,
ignore: program.ignore,
plugins: program.plugins,
presets: program.presets,
extensions: program.extensions,
ignore: program.ignore,
only: program.only,
plugins: program.plugins,
presets: program.presets,
});
//
let replPlugin = new babel.Plugin("repl", {
let replPlugin = () => ({
visitor: {
ModuleDeclaration() {
throw this.errorWithNode("Modules aren't supported in the REPL");
ModuleDeclaration(path) {
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
},
VariableDeclaration(node) {
if (node.kind !== "var") {
throw this.errorWithNode("Only `var` variables are supported in the REPL");
VariableDeclaration(path) {
if (path.node.kind !== "var") {
throw path.buildCodeFrameError("Only `var` variables are supported in the REPL");
}
}
}
@@ -59,11 +60,8 @@ let _eval = function (code, filename) {
code = babel.transform(code, {
filename: filename,
blacklist: program.blacklist,
whitelist: program.whitelist,
optional: program.optional,
stage: program.stage,
plugins: [replPlugin]
presets: program.presets,
plugins: (program.plugins || []).concat([replPlugin])
}).code;
return vm.runInThisContext(code, {

View File

@@ -18,7 +18,7 @@ if (argSeparator > -1) {
babelArgs = babelArgs.slice(0, argSeparator);
}
getV8Flags(function (v8Flags) {
getV8Flags(function (err, v8Flags) {
babelArgs.forEach(function(arg){
let flag = arg.split("=")[0];

View File

@@ -1,162 +0,0 @@
import pathExists from "path-exists";
import readline from "readline";
import child from "child_process";
import path from "path";
import fs from "fs";
function spawn(cmd, args, callback) {
console.log(">", cmd, args);
let spawn = child.spawn(cmd, args, { stdio: "inherit" });
spawn.on("exit", function (code) {
if (code === 0) {
callback();
} else {
console.log("Killing...");
process.exit(1);
}
});
}
function spawnMultiple(cmds) {
function next() {
let cmd = cmds.shift();
if (cmd) {
spawn(cmd.command, cmd.args, next);
} else {
process.exit();
}
}
next();
}
function template(name, data = {}) {
let source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8");
source = source.replace(/[A-Z_]+/g, function (key) {
return data[key] === undefined ? key : data[key];
});
return source;
}
function write(filename, content) {
console.log(filename);
fs.writeFileSync(filename, content);
}
function execMaybe(cmd) {
try {
return child.execSync(cmd).toString();
} catch (err) {
return "";
}
}
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let BABEL_PLUGIN_PREFIX = "babel-plugin-";
let cmds = {
init: function () {
let name = path.basename(process.cwd());
if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) {
name = name.slice(BABEL_PLUGIN_PREFIX.length);
}
rl.question("Description (optional): ", function (description) {
let remote = execMaybe("git config --get remote.origin.url").trim().match(/git@github.com:(.*?).git/);
if (remote) {
build(description, remote[1]);
} else {
rl.question("GitHub Repository (eg. sebmck/babel-plugin-foobar) (optional): ", function (repo) {
build(description, repo);
});
}
});
function build(description, repo) {
rl.close();
let templateData = {
DESCRIPTION: description,
FULL_NAME: BABEL_PLUGIN_PREFIX + name,
NAME: name
};
write("package.json", JSON.stringify({
name: templateData.FULL_NAME,
version: "1.0.0",
description: templateData.DESCRIPTION,
repository: repo || undefined,
license: "MIT",
main: "lib/index.js",
devDependencies: {
babel: "^5.6.0"
},
scripts: {
build: "babel-plugin build",
push: "babel-plugin publish",
test: "babel-plugin test"
},
keywords: ["babel-plugin"]
}, null, " ") + "\n");
write(".npmignore", "node_modules\n*.log\nsrc\n");
write(".gitignore", "node_modules\n*.log\nlib\n");
write("README.md", template("README.md", templateData));
write("LICENSE", template("LICENSE", {
AUTHOR_EMAIL: execMaybe("git config --get user.email").trim(),
AUTHOR_NAME: execMaybe("git config --get user.name").trim(),
YEAR: new Date().getFullYear()
}));
if (!pathExists.sync("src")) {
fs.mkdirSync("src");
write("src/index.js", template("index.js", templateData));
}
}
},
build: function () {
spawn("babel", ["src", "--out-dir", "lib", "--copy-files"], process.exit);
},
publish: function () {
let pkg = require(process.cwd() + "/package.json");
console.log("Current version:", pkg.version);
rl.question("New version (enter nothing for patch): ", function (newVersion) {
rl.close();
newVersion = newVersion || "patch";
spawnMultiple([
{ command: "git", args: ["pull"] },
{ command: "git", args: ["push"] },
{ command: "babel-plugin", args: ["build"] },
{ command: "npm", args: ["version", newVersion] },
{ command: "npm", args: ["publish"] },
{ command: "git", args: ["push", "--follow-tags"] }
]);
});
}
};
let cmd = cmds[process.argv[2]];
if (cmd) {
cmd();
} else {
console.error("Unknown command:", cmd);
process.exit(1);
}

View File

@@ -1,22 +0,0 @@
Copyright (c) YEAR AUTHOR_NAME <AUTHOR_EMAIL>
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,35 +0,0 @@
# FULL_NAME
DESCRIPTION
## Installation
```sh
$ npm install FULL_NAME
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["NAME"]
}
```
### Via CLI
```sh
$ babel --plugins NAME script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["NAME"]
});
```

View File

@@ -1,8 +0,0 @@
/* eslint no-unused-vars:0 */
export default function ({ Plugin, types: t }) {
return new Plugin("NAME", {
visitor: {
// your visitor methods go here
}
});
}

View File

@@ -20,6 +20,7 @@ module.exports = function (commander, filenames) {
});
if (!commander.copyFiles && data.ignored) return;
// we've requested explicit sourcemaps to be written to disk
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
let mapLoc = dest + ".map";
data.code = util.addSourceMappingUrl(data.code, mapLoc);
@@ -27,6 +28,7 @@ module.exports = function (commander, filenames) {
}
outputFileSync(dest, data.code);
util.chmod(src, dest);
util.log(src + " -> " + dest);
}
@@ -37,7 +39,9 @@ module.exports = function (commander, filenames) {
if (util.canCompile(filename, commander.extensions)) {
write(src, filename);
} else if (commander.copyFiles) {
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
let dest = path.join(commander.outDir, filename);
outputFileSync(dest, fs.readFileSync(src));
util.chmod(src, dest);
}
}

View File

@@ -54,6 +54,8 @@ module.exports = function (commander, filenames, opts) {
}
});
// add the inline sourcemap comment if we've either explicitly asked for inline source
// maps, or we've requested them without any output file
if (commander.sourceMaps === "inline" || (!commander.outFile && commander.sourceMaps)) {
code += "\n" + convertSourceMap.fromObject(map).toComment();
}
@@ -68,6 +70,7 @@ module.exports = function (commander, filenames, opts) {
let result = buildResult();
if (commander.outFile) {
// we've requested for a sorucemap to be written to disk
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
let mapLoc = commander.outFile + ".map";
result.code = util.addSourceMappingUrl(result.code, mapLoc);

View File

@@ -7,29 +7,33 @@ let path = require("path");
let fs = require("fs");
let _ = require("lodash");
exports.readdirFilter = function (filename) {
export function chmod(src, dest) {
fs.chmodSync(dest, fs.statSync(src).mode);
}
export function readdirFilter(filename) {
return readdir(filename).filter(function (filename) {
return util.canCompile(filename);
});
};
}
exports.readdir = readdir;
export { readdir };
exports.canCompile = util.canCompile;
export let canCompile = util.canCompile;
exports.shouldIgnore = function (loc) {
export function shouldIgnore(loc) {
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
};
}
exports.addSourceMappingUrl = function (code, loc) {
export function addSourceMappingUrl(code, loc) {
return code + "\n//# sourceMappingURL=" + path.basename(loc);
};
}
exports.log = function (msg) {
export function log(msg) {
if (!commander.quiet) console.log(msg);
};
}
exports.transform = function (filename, code, opts) {
export function transform(filename, code, opts) {
opts = _.defaults(opts || {}, index.opts);
opts.filename = filename;
opts.ignore = null;
@@ -39,12 +43,12 @@ exports.transform = function (filename, code, opts) {
result.filename = filename;
result.actual = code;
return result;
};
}
exports.compile = function (filename, opts) {
export function compile(filename, opts) {
try {
let code = fs.readFileSync(filename, "utf8");
return exports.transform(filename, code, opts);
return transform(filename, code, opts);
} catch (err) {
if (commander.watch) {
console.error(toErrorStack(err));
@@ -53,7 +57,7 @@ exports.compile = function (filename, opts) {
throw err;
}
}
};
}
function toErrorStack(err) {
if (err._babel && err instanceof SyntaxError) {

View File

@@ -1,3 +1 @@
{
"breakConfig": true
}
{}

View File

@@ -8,4 +8,4 @@
}
})(this, function (global) {
var babelHelpers = global;
})
});

View File

@@ -1,3 +1,3 @@
{
"args": ["--whitelist", "slice,has-own"]
"args": ["--whitelist", "createClass"]
}

View File

@@ -1,5 +1,21 @@
(function (global) {
var babelHelpers = global.babelHelpers = {};
babelHelpers.hasOwn = Object.prototype.hasOwnProperty;
babelHelpers.slice = Array.prototype.slice;
babelHelpers.createClass = (function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
})();
})(typeof global === "undefined" ? self : global);

View File

@@ -1,3 +0,0 @@
{
"args": ["--blacklist", "es6.arrowFunctions"]
}

View File

@@ -1 +0,0 @@
arr.map(x => x * MULTIPLIER);

View File

@@ -1,3 +0,0 @@
"use strict";
arr.map(x => x * MULTIPLIER);

View File

@@ -1,3 +0,0 @@
{
"args": ["--whitelist", "es6.arrowFunctions"]
}

View File

@@ -1,2 +0,0 @@
let MULTIPLER = 5;
arr.map(x => x * MULTIPLIER);

View File

@@ -1,4 +0,0 @@
let MULTIPLER = 5;
arr.map(function (x) {
return x * MULTIPLIER;
});

View File

@@ -15,6 +15,16 @@ var _ = require("lodash");
var fixtureLoc = __dirname + "/fixtures";
var tmpLoc = __dirname + "/tmp";
var presetLocs = [
__dirname + "/../../babel-preset-es2015",
__dirname + "/../../babel-preset-react"
].join(",");
var pluginLocs = [
__dirname + "/../../babel-plugin-transform-strict-mode",
__dirname + "/../../babel-plugin-transform-es2015-modules-commonjs",
].join(",");
var readDir = function (loc) {
var files = {};
if (pathExists.sync(loc)) {
@@ -43,7 +53,7 @@ var assertTest = function (stdout, stderr, opts) {
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
}
} else if (stderr) {
throw new Error("stderr: " + JSON.stringify(stderr));
throw new Error("stderr:\n" + stderr);
}
var expectStdout = opts.stdout.trim();
@@ -57,7 +67,7 @@ var assertTest = function (stdout, stderr, opts) {
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
}
} else if (stdout) {
throw new Error("stdout: " + JSON.stringify(stdout));
throw new Error("stdout:\n" + stdout);
}
_.each(opts.outFiles, function (expect, filename) {
@@ -74,7 +84,18 @@ var buildTest = function (binName, testName, opts) {
clear();
saveInFiles(opts.inFiles);
var args = [binLoc].concat(opts.args);
var args = [binLoc];
if (binName !== "babel-external-helpers") {
args.push("--presets", presetLocs, "--plugins", pluginLocs);
}
if (binName === "babel-node") {
args.push("--only", "packages/*/test");
}
args = args.concat(opts.args);
var spawn = child.spawn(process.execPath, args);
var stderr = "";