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,29 +1,36 @@
/* @flow */
import isFunction from "lodash/lang/isFunction";
import transform from "../transformation";
import * as babylon from "babylon";
import * as util from "../util";
import fs from "fs";
export { util, transform };
export { pipeline, lint } from "../transformation";
export { canCompile } from "../util";
export { default as File } from "../transformation/file";
export { default as options } from "../transformation/file/options/config";
export { default as Plugin } from "../transformation/plugin";
export { default as Pipeline } from "../transformation/pipeline";
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
export { default as template } from "babel-template";
export { version } from "../../package";
//
import * as util from "../util";
export { util };
import * as messages from "babel-messages";
export { messages };
import * as t from "babel-types";
export { t as types };
//
import Pipeline from "../transformation/pipeline";
export { Pipeline };
let pipeline = new Pipeline;
export let transform = pipeline.transform.bind(pipeline);
export let transformFromAst = pipeline.transformFromAst.bind(pipeline);
//
export function transformFile(filename: string, opts?: Object, callback: Function) {
if (isFunction(opts)) {

View File

@@ -1,3 +1,5 @@
/* @flow */
import path from "path";
import fs from "fs";
import homeOrTmp from "home-or-tmp";

View File

@@ -1,5 +1,6 @@
/* @flow */
import deepClone from "lodash/lang/cloneDeep";
import sourceMapSupport from "source-map-support";
import * as registerCache from "./cache";
import OptionManager from "../../transformation/file/options/option-manager";
@@ -10,10 +11,6 @@ import * as util from "../../util";
import fs from "fs";
import path from "path";
/**
* Install sourcemaps into node.
*/
sourceMapSupport.install({
handleUncaughtExceptions: false,
retrieveSourceMap(source) {
@@ -29,17 +26,9 @@ sourceMapSupport.install({
}
});
/**
* Load and setup cache.
*/
registerCache.load();
let cache = registerCache.get();
/**
* Store options.
*/
let transformOpts = {};
let ignore;
@@ -50,33 +39,21 @@ let maps = {};
let cwd = process.cwd();
/**
* Get path from `filename` relative to the current working directory.
*/
function getRelativePath(filename){
return path.relative(cwd, filename);
}
/**
* Get last modified time for a `filename`.
*/
function mtime(filename) {
return +fs.statSync(filename).mtime;
}
/**
* Compile a `filename` with optional `opts`.
*/
function compile(filename, opts = {}) {
let result;
opts.filename = filename;
let optsManager = new OptionManager;
optsManager.mergeOptions(transformOpts);
optsManager.mergeOptions(deepClone(transformOpts));
opts = optsManager.init(opts);
let cacheKey = `${JSON.stringify(opts)}:${babel.version}`;
@@ -108,10 +85,6 @@ function compile(filename, opts = {}) {
return result.code;
}
/**
* Test if a `filename` should be ignored by Babel.
*/
function shouldIgnore(filename) {
if (!ignore && !only) {
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
@@ -120,58 +93,13 @@ function shouldIgnore(filename) {
}
}
/**
* Monkey patch istanbul if it is running so that it works properly.
*/
let istanbulMonkey = {};
if (process.env.running_under_istanbul) {
// we need to monkey patch fs.readFileSync so we can hook into
// what istanbul gets, it's extremely dirty but it's the only way
let _readFileSync = fs.readFileSync;
fs.readFileSync = function (filename) {
if (istanbulMonkey[filename]) {
delete istanbulMonkey[filename];
let code = compile(filename, {
auxiliaryCommentBefore: "istanbul ignore next"
});
istanbulMonkey[filename] = true;
return code;
} else {
return _readFileSync.apply(this, arguments);
}
};
}
/**
* Replacement for the loader for istanbul.
*/
function istanbulLoader(m, filename, old) {
istanbulMonkey[filename] = true;
old(m, filename);
}
/**
* Default loader.
*/
function normalLoader(m, filename) {
function loader(m, filename) {
m._compile(compile(filename), filename);
}
/**
* Register a loader for an extension.
*/
function registerExtension(ext) {
let old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
let loader = normalLoader;
if (process.env.running_under_istanbul) loader = istanbulLoader;
require.extensions[ext] = function (m, filename) {
if (shouldIgnore(filename)) {
old(m, filename);
@@ -181,10 +109,6 @@ function registerExtension(ext) {
};
}
/**
* Register loader for given extensions.
*/
function hookExtensions(_exts) {
each(oldHandlers, function (old, ext) {
if (old === undefined) {
@@ -202,16 +126,8 @@ function hookExtensions(_exts) {
});
}
/**
* Register loader for default extensions.
*/
hookExtensions(util.canCompile.EXTENSIONS);
/**
* Update options at runtime.
*/
export default function (opts?: Object = {}) {
if (opts.only != null) only = util.arrayify(opts.only, util.regexify);
if (opts.ignore != null) ignore = util.arrayify(opts.ignore, util.regexify);