enable prefer const (#5113)
This commit is contained in:
@@ -29,16 +29,16 @@ export function run(code: string, opts: Object = {}): any {
|
||||
export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
const xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
|
||||
let status = xhr.status;
|
||||
const status = xhr.status;
|
||||
if (status === 0 || status === 200) {
|
||||
let param = [xhr.responseText, opts];
|
||||
const param = [xhr.responseText, opts];
|
||||
if (!hold) run(param);
|
||||
if (callback) callback(param);
|
||||
} else {
|
||||
@@ -50,8 +50,8 @@ export function load(url: string, callback: Function, opts: Object = {}, hold?:
|
||||
}
|
||||
|
||||
function runScripts() {
|
||||
let scripts: Array<Array<any> | Object> = [];
|
||||
let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
const scripts: Array<Array<any> | Object> = [];
|
||||
const types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
let index = 0;
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ function runScripts() {
|
||||
*/
|
||||
|
||||
function exec() {
|
||||
let param = scripts[index];
|
||||
const param = scripts[index];
|
||||
if (param instanceof Array) {
|
||||
run(param, index);
|
||||
index++;
|
||||
@@ -72,7 +72,7 @@ function runScripts() {
|
||||
*/
|
||||
|
||||
function run(script: Object, i: number) {
|
||||
let opts = {};
|
||||
const opts = {};
|
||||
|
||||
if (script.src) {
|
||||
load(script.src, function (param) {
|
||||
@@ -87,10 +87,10 @@ function runScripts() {
|
||||
|
||||
// Collect scripts with Babel `types`.
|
||||
|
||||
let _scripts = global.document.getElementsByTagName("script");
|
||||
const _scripts = global.document.getElementsByTagName("script");
|
||||
|
||||
for (let i = 0; i < _scripts.length; ++i) {
|
||||
let _script = _scripts[i];
|
||||
const _script = _scripts[i];
|
||||
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ export function Plugin(alias) {
|
||||
import Pipeline from "../transformation/pipeline";
|
||||
export { Pipeline };
|
||||
|
||||
let pipeline = new Pipeline;
|
||||
export let analyse = pipeline.analyse.bind(pipeline);
|
||||
export let transform = pipeline.transform.bind(pipeline);
|
||||
export let transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
const pipeline = new Pipeline;
|
||||
export const analyse = pipeline.analyse.bind(pipeline);
|
||||
export const transform = pipeline.transform.bind(pipeline);
|
||||
export const transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
|
||||
export function transformFile(filename: string, opts?: Object, callback: Function) {
|
||||
if (isFunction(opts)) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
export default function getPossiblePresetNames(presetName: string): Array<string> {
|
||||
let possibleNames = [`babel-preset-${presetName}`, presetName];
|
||||
const possibleNames = [`babel-preset-${presetName}`, presetName];
|
||||
|
||||
// trying to resolve @organization shortcat
|
||||
// @foo/es2015 -> @foo/babel-preset-es2015
|
||||
let matches = presetName.match(/^(@[^/]+)\/(.+)$/);
|
||||
const matches = presetName.match(/^(@[^/]+)\/(.+)$/);
|
||||
if (matches) {
|
||||
let [, orgName, presetPath] = matches;
|
||||
const [, orgName, presetPath] = matches;
|
||||
possibleNames.push(`${orgName}/babel-preset-${presetPath}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ export default function (dest?: Object, src?: Object): ?Object {
|
||||
|
||||
return mergeWith(dest, src, function (a, b) {
|
||||
if (b && Array.isArray(a)) {
|
||||
let newArray = b.slice(0);
|
||||
const newArray = b.slice(0);
|
||||
|
||||
for (let item of a) {
|
||||
for (const item of a) {
|
||||
if (newArray.indexOf(item) < 0) {
|
||||
newArray.push(item);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Module from "module";
|
||||
import path from "path";
|
||||
|
||||
let relativeModules = {};
|
||||
const relativeModules = {};
|
||||
|
||||
export default function (loc: string, relative: string = process.cwd()): ?string {
|
||||
// we're in the browser, probably
|
||||
@@ -18,7 +18,7 @@ export default function (loc: string, relative: string = process.cwd()): ?string
|
||||
// Node presumes "." is process.cwd(), not our relative path.
|
||||
// Since this fake module is never "loaded", we don't have to worry about mutating
|
||||
// any global Node module cache state here.
|
||||
let filename = path.join(relative, ".babelrc");
|
||||
const filename = path.join(relative, ".babelrc");
|
||||
relativeMod.id = filename;
|
||||
relativeMod.filename = filename;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class Store extends Map {
|
||||
return super.get(key);
|
||||
} else {
|
||||
if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) {
|
||||
let val = this.dynamicData[key]();
|
||||
const val = this.dynamicData[key]();
|
||||
this.set(key, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import template from "babel-template";
|
||||
import each from "lodash/each";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let buildUmdWrapper = template(`
|
||||
const buildUmdWrapper = template(`
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
@@ -22,9 +22,9 @@ let buildUmdWrapper = template(`
|
||||
`);
|
||||
|
||||
function buildGlobal(namespace, builder) {
|
||||
let body = [];
|
||||
let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
|
||||
const body = [];
|
||||
const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
const tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
@@ -39,7 +39,7 @@ function buildGlobal(namespace, builder) {
|
||||
}
|
||||
|
||||
function buildUmd(namespace, builder) {
|
||||
let body = [];
|
||||
const body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.identifier("global"))
|
||||
]));
|
||||
@@ -63,7 +63,7 @@ function buildUmd(namespace, builder) {
|
||||
}
|
||||
|
||||
function buildVar(namespace, builder) {
|
||||
let body = [];
|
||||
const body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.objectExpression([]))
|
||||
]));
|
||||
@@ -76,7 +76,7 @@ function buildHelpers(body, namespace, whitelist) {
|
||||
each(helpers.list, function (name) {
|
||||
if (whitelist && whitelist.indexOf(name) < 0) return;
|
||||
|
||||
let key = t.identifier(name);
|
||||
const key = t.identifier(name);
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))
|
||||
));
|
||||
@@ -86,15 +86,15 @@ export default function (
|
||||
whitelist?: Array<string>,
|
||||
outputType: "global" | "umd" | "var" = "global",
|
||||
) {
|
||||
let namespace = t.identifier("babelHelpers");
|
||||
const namespace = t.identifier("babelHelpers");
|
||||
|
||||
let builder = function (body) {
|
||||
const builder = function (body) {
|
||||
return buildHelpers(body, namespace, whitelist);
|
||||
};
|
||||
|
||||
let tree;
|
||||
|
||||
let build = {
|
||||
const build = {
|
||||
global: buildGlobal,
|
||||
umd: buildUmd,
|
||||
var: buildVar,
|
||||
|
||||
@@ -32,9 +32,9 @@ const INTERNAL_PLUGINS = [
|
||||
[shadowFunctionsPlugin]
|
||||
];
|
||||
|
||||
let errorVisitor = {
|
||||
const errorVisitor = {
|
||||
enter(path, state) {
|
||||
let loc = path.node.loc;
|
||||
const loc = path.node.loc;
|
||||
if (loc) {
|
||||
state.loc = loc;
|
||||
path.stop();
|
||||
@@ -69,7 +69,7 @@ export default class File extends Store {
|
||||
// All the "per preset" options are inherited from the main options.
|
||||
this.perPresetOpts = [];
|
||||
this.opts.presets.forEach((presetOpts) => {
|
||||
let perPresetOpts = Object.assign(Object.create(this.opts), presetOpts);
|
||||
const perPresetOpts = Object.assign(Object.create(this.opts), presetOpts);
|
||||
this.perPresetOpts.push(perPresetOpts);
|
||||
this.buildPluginsForOptions(perPresetOpts);
|
||||
});
|
||||
@@ -125,7 +125,7 @@ export default class File extends Store {
|
||||
|
||||
getMetadata() {
|
||||
let has = false;
|
||||
for (let node of (this.ast.program.body: Array<Object>)) {
|
||||
for (const node of (this.ast.program.body: Array<Object>)) {
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
has = true;
|
||||
break;
|
||||
@@ -165,7 +165,7 @@ export default class File extends Store {
|
||||
filenameRelative: opts.filename
|
||||
});
|
||||
|
||||
let basenameRelative = path.basename(opts.filenameRelative);
|
||||
const basenameRelative = path.basename(opts.filenameRelative);
|
||||
|
||||
defaults(opts, {
|
||||
sourceFileName: basenameRelative,
|
||||
@@ -180,13 +180,13 @@ export default class File extends Store {
|
||||
return;
|
||||
}
|
||||
|
||||
let plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS);
|
||||
let currentPluginVisitors = [];
|
||||
let currentPluginPasses = [];
|
||||
const plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS);
|
||||
const currentPluginVisitors = [];
|
||||
const currentPluginPasses = [];
|
||||
|
||||
// init plugins!
|
||||
for (let ref of plugins) {
|
||||
let [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug
|
||||
for (const ref of plugins) {
|
||||
const [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug
|
||||
|
||||
currentPluginVisitors.push(plugin.visitor);
|
||||
currentPluginPasses.push(new PluginPass(this, plugin, pluginOpts));
|
||||
@@ -201,7 +201,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
getModuleName(): ?string {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
if (!opts.moduleIds) {
|
||||
return null;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ export default class File extends Store {
|
||||
|
||||
if (opts.sourceRoot != null) {
|
||||
// remove sourceRoot from filename
|
||||
let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
const sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
@@ -245,20 +245,20 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
resolveModuleSource(source: string): string {
|
||||
let resolveModuleSource = this.opts.resolveModuleSource;
|
||||
const resolveModuleSource = this.opts.resolveModuleSource;
|
||||
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
|
||||
return source;
|
||||
}
|
||||
|
||||
addImport(source: string, imported: string, name?: string = imported): Object {
|
||||
let alias = `${source}:${imported}`;
|
||||
const alias = `${source}:${imported}`;
|
||||
let id = this.dynamicImportIds[alias];
|
||||
|
||||
if (!id) {
|
||||
source = this.resolveModuleSource(source);
|
||||
id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
let specifiers = [];
|
||||
const specifiers = [];
|
||||
|
||||
if (imported === "*") {
|
||||
specifiers.push(t.importNamespaceSpecifier(id));
|
||||
@@ -268,7 +268,7 @@ export default class File extends Store {
|
||||
specifiers.push(t.importSpecifier(id, t.identifier(imported)));
|
||||
}
|
||||
|
||||
let declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
||||
const declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.path.unshiftContainer("body", declar);
|
||||
@@ -278,7 +278,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
addHelper(name: string): Object {
|
||||
let declar = this.declarations[name];
|
||||
const declar = this.declarations[name];
|
||||
if (declar) return declar;
|
||||
|
||||
if (!this.usedHelpers[name]) {
|
||||
@@ -286,17 +286,17 @@ export default class File extends Store {
|
||||
this.usedHelpers[name] = true;
|
||||
}
|
||||
|
||||
let generator = this.get("helperGenerator");
|
||||
let runtime = this.get("helpersNamespace");
|
||||
const generator = this.get("helperGenerator");
|
||||
const runtime = this.get("helpersNamespace");
|
||||
if (generator) {
|
||||
let res = generator(name);
|
||||
const res = generator(name);
|
||||
if (res) return res;
|
||||
} else if (runtime) {
|
||||
return t.memberExpression(runtime, t.identifier(name));
|
||||
}
|
||||
|
||||
let ref = getHelper(name);
|
||||
let uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
const ref = getHelper(name);
|
||||
const uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = true;
|
||||
@@ -323,18 +323,18 @@ export default class File extends Store {
|
||||
): Object {
|
||||
// Generate a unique name based on the string literals so we dedupe
|
||||
// identical strings used in the program.
|
||||
let stringIds = raw.elements.map(function(string) {
|
||||
const stringIds = raw.elements.map(function(string) {
|
||||
return string.value;
|
||||
});
|
||||
let name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
||||
const name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
||||
|
||||
let declar = this.declarations[name];
|
||||
const declar = this.declarations[name];
|
||||
if (declar) return declar;
|
||||
|
||||
let uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
||||
const uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
||||
|
||||
let helperId = this.addHelper(helperName);
|
||||
let init = t.callExpression(helperId, [strings, raw]);
|
||||
const helperId = this.addHelper(helperName);
|
||||
const init = t.callExpression(helperId, [strings, raw]);
|
||||
init._compact = true;
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
@@ -345,9 +345,9 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
buildCodeFrameError(node: Object, msg: string, Error: typeof Error = SyntaxError): Error {
|
||||
let loc = node && (node.loc || node._loc);
|
||||
const loc = node && (node.loc || node._loc);
|
||||
|
||||
let err = new Error(msg);
|
||||
const err = new Error(msg);
|
||||
|
||||
if (loc) {
|
||||
err.loc = loc.start;
|
||||
@@ -367,13 +367,13 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
let inputMap = this.opts.inputSourceMap;
|
||||
const inputMap = this.opts.inputSourceMap;
|
||||
|
||||
if (inputMap) {
|
||||
let inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
let outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
const inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
const outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
|
||||
let mergedGenerator = new sourceMap.SourceMapGenerator({
|
||||
const mergedGenerator = new sourceMap.SourceMapGenerator({
|
||||
file: inputMapConsumer.file,
|
||||
sourceRoot: inputMapConsumer.sourceRoot
|
||||
});
|
||||
@@ -402,7 +402,7 @@ export default class File extends Store {
|
||||
}
|
||||
});
|
||||
|
||||
let mergedMap = mergedGenerator.toJSON();
|
||||
const mergedMap = mergedGenerator.toJSON();
|
||||
inputMap.mappings = mergedMap.mappings;
|
||||
return inputMap;
|
||||
} else {
|
||||
@@ -419,8 +419,8 @@ export default class File extends Store {
|
||||
|
||||
if (parserOpts.parser) {
|
||||
if (typeof parserOpts.parser === "string") {
|
||||
let dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
let parser = resolve(parserOpts.parser, dirname);
|
||||
const dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
const parser = resolve(parserOpts.parser, dirname);
|
||||
if (parser) {
|
||||
parseCode = require(parser).parse;
|
||||
} else {
|
||||
@@ -439,7 +439,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
this.log.debug("Parse start");
|
||||
let ast = parseCode(code, parserOpts || this.parserOpts);
|
||||
const ast = parseCode(code, parserOpts || this.parserOpts);
|
||||
this.log.debug("Parse stop");
|
||||
return ast;
|
||||
}
|
||||
@@ -472,7 +472,7 @@ export default class File extends Store {
|
||||
this.log.debug("Start transform traverse");
|
||||
|
||||
// merge all plugin visitors into a single visitor
|
||||
let visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
|
||||
const visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
|
||||
traverse(this.ast, visitor, this.scope);
|
||||
|
||||
this.log.debug("End transform traverse");
|
||||
@@ -500,7 +500,7 @@ export default class File extends Store {
|
||||
|
||||
let message = err.message = `${this.opts.filename}: ${err.message}`;
|
||||
|
||||
let loc = err.loc;
|
||||
const loc = err.loc;
|
||||
if (loc) {
|
||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
||||
message += "\n" + err.codeFrame;
|
||||
@@ -513,7 +513,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
if (err.stack) {
|
||||
let newStack = err.stack.replace(err.message, message);
|
||||
const newStack = err.stack.replace(err.message, message);
|
||||
err.stack = newStack;
|
||||
}
|
||||
|
||||
@@ -529,28 +529,28 @@ export default class File extends Store {
|
||||
|
||||
parseCode() {
|
||||
this.parseShebang();
|
||||
let ast = this.parse(this.code);
|
||||
const ast = this.parse(this.code);
|
||||
this.addAst(ast);
|
||||
}
|
||||
|
||||
shouldIgnore() {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||
}
|
||||
|
||||
call(key: "pre" | "post", pluginPasses: Array<PluginPass>) {
|
||||
for (let pass of pluginPasses) {
|
||||
let plugin = pass.plugin;
|
||||
let fn = plugin[key];
|
||||
for (const pass of pluginPasses) {
|
||||
const plugin = pass.plugin;
|
||||
const fn = plugin[key];
|
||||
if (fn) fn.call(pass, this);
|
||||
}
|
||||
}
|
||||
|
||||
parseInputSourceMap(code: string): string {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
|
||||
if (opts.inputSourceMap !== false) {
|
||||
let inputMap = convertSourceMap.fromSource(code);
|
||||
const inputMap = convertSourceMap.fromSource(code);
|
||||
if (inputMap) {
|
||||
opts.inputSourceMap = inputMap.toObject();
|
||||
code = convertSourceMap.removeComments(code);
|
||||
@@ -561,7 +561,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
parseShebang() {
|
||||
let shebangMatch = shebangRegex.exec(this.code);
|
||||
const shebangMatch = shebangRegex.exec(this.code);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
this.code = this.code.replace(shebangRegex, "");
|
||||
@@ -569,7 +569,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
makeResult({ code, map, ast, ignored }: BabelFileResult): BabelFileResult {
|
||||
let result = {
|
||||
const result = {
|
||||
metadata: null,
|
||||
options: this.opts,
|
||||
ignored: !!ignored,
|
||||
@@ -594,10 +594,10 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
generate(): BabelFileResult {
|
||||
let opts = this.opts;
|
||||
let ast = this.ast;
|
||||
const opts = this.opts;
|
||||
const ast = this.ast;
|
||||
|
||||
let result: BabelFileResult = { ast };
|
||||
const result: BabelFileResult = { ast };
|
||||
if (!opts.code) return this.makeResult(result);
|
||||
|
||||
let gen = generate;
|
||||
@@ -605,8 +605,8 @@ export default class File extends Store {
|
||||
gen = opts.generatorOpts.generator;
|
||||
|
||||
if (typeof gen === "string") {
|
||||
let dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
let generator = resolve(gen, dirname);
|
||||
const dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
const generator = resolve(gen, dirname);
|
||||
if (generator) {
|
||||
gen = require(generator).print;
|
||||
} else {
|
||||
@@ -617,7 +617,7 @@ export default class File extends Store {
|
||||
|
||||
this.log.debug("Generation start");
|
||||
|
||||
let _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code);
|
||||
const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code);
|
||||
result.code = _result.code;
|
||||
result.map = _result.map;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type File from "./index";
|
||||
import buildDebug from "debug/node";
|
||||
|
||||
let verboseDebug = buildDebug("babel:verbose");
|
||||
let generalDebug = buildDebug("babel");
|
||||
const verboseDebug = buildDebug("babel:verbose");
|
||||
const generalDebug = buildDebug("babel");
|
||||
|
||||
let seenDeprecatedMessages = [];
|
||||
const seenDeprecatedMessages = [];
|
||||
|
||||
export default class Logger {
|
||||
constructor(file: File, filename: string) {
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import * as t from "babel-types";
|
||||
|
||||
export let ModuleDeclaration = {
|
||||
export const ModuleDeclaration = {
|
||||
enter(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node.source) {
|
||||
node.source.value = file.resolveModuleSource(node.source.value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export let ImportDeclaration = {
|
||||
export const ImportDeclaration = {
|
||||
exit(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let specifiers = [];
|
||||
let imported = [];
|
||||
const specifiers = [];
|
||||
const imported = [];
|
||||
file.metadata.modules.imports.push({
|
||||
source: node.source.value,
|
||||
imported,
|
||||
specifiers
|
||||
});
|
||||
|
||||
for (let specifier of (path.get("specifiers"): Array<Object>)) {
|
||||
let local = specifier.node.local.name;
|
||||
for (const specifier of (path.get("specifiers"): Array<Object>)) {
|
||||
const local = specifier.node.local.name;
|
||||
|
||||
if (specifier.isImportDefaultSpecifier()) {
|
||||
imported.push("default");
|
||||
@@ -34,7 +34,7 @@ export let ImportDeclaration = {
|
||||
}
|
||||
|
||||
if (specifier.isImportSpecifier()) {
|
||||
let importedName = specifier.node.imported.name;
|
||||
const importedName = specifier.node.imported.name;
|
||||
imported.push(importedName);
|
||||
specifiers.push({
|
||||
kind: "named",
|
||||
@@ -55,18 +55,18 @@ export let ImportDeclaration = {
|
||||
};
|
||||
|
||||
export function ExportDeclaration(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let source = node.source ? node.source.value : null;
|
||||
let exports = file.metadata.modules.exports;
|
||||
const source = node.source ? node.source.value : null;
|
||||
const exports = file.metadata.modules.exports;
|
||||
|
||||
// export function foo() {}
|
||||
// export let foo = "bar";
|
||||
let declar = path.get("declaration");
|
||||
const declar = path.get("declaration");
|
||||
if (declar.isStatement()) {
|
||||
let bindings = declar.getBindingIdentifiers();
|
||||
const bindings = declar.getBindingIdentifiers();
|
||||
|
||||
for (let name in bindings) {
|
||||
for (const name in bindings) {
|
||||
exports.exported.push(name);
|
||||
exports.specifiers.push({
|
||||
kind: "local",
|
||||
@@ -77,8 +77,8 @@ export function ExportDeclaration(path, file) {
|
||||
}
|
||||
|
||||
if (path.isExportNamedDeclaration() && node.specifiers) {
|
||||
for (let specifier of (node.specifiers: Array<Object>)) {
|
||||
let exported = specifier.exported.name;
|
||||
for (const specifier of (node.specifiers: Array<Object>)) {
|
||||
const exported = specifier.exported.name;
|
||||
exports.exported.push(exported);
|
||||
|
||||
// export foo from "bar";
|
||||
@@ -100,7 +100,7 @@ export function ExportDeclaration(path, file) {
|
||||
});
|
||||
}
|
||||
|
||||
let local = specifier.local;
|
||||
const local = specifier.local;
|
||||
if (!local) continue;
|
||||
|
||||
// export { foo } from "bar";
|
||||
|
||||
@@ -6,15 +6,15 @@ import isAbsolute from "path-is-absolute";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
let existsCache = {};
|
||||
let jsonCache = {};
|
||||
const existsCache = {};
|
||||
const jsonCache = {};
|
||||
|
||||
const BABELIGNORE_FILENAME = ".babelignore";
|
||||
const BABELRC_FILENAME = ".babelrc";
|
||||
const PACKAGE_FILENAME = "package.json";
|
||||
|
||||
function exists(filename) {
|
||||
let cached = existsCache[filename];
|
||||
const cached = existsCache[filename];
|
||||
if (cached == null) {
|
||||
return existsCache[filename] = fs.existsSync(filename);
|
||||
} else {
|
||||
@@ -23,8 +23,8 @@ function exists(filename) {
|
||||
}
|
||||
|
||||
export default function buildConfigChain(opts: Object = {}, log?: Logger) {
|
||||
let filename = opts.filename;
|
||||
let builder = new ConfigChainBuilder(log);
|
||||
const filename = opts.filename;
|
||||
const builder = new ConfigChainBuilder(log);
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false) {
|
||||
@@ -59,20 +59,20 @@ class ConfigChainBuilder {
|
||||
|
||||
while (loc !== (loc = path.dirname(loc))) {
|
||||
if (!foundConfig) {
|
||||
let configLoc = path.join(loc, BABELRC_FILENAME);
|
||||
const configLoc = path.join(loc, BABELRC_FILENAME);
|
||||
if (exists(configLoc)) {
|
||||
this.addConfig(configLoc);
|
||||
foundConfig = true;
|
||||
}
|
||||
|
||||
let pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
||||
const pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
||||
if (!foundConfig && exists(pkgLoc)) {
|
||||
foundConfig = this.addConfig(pkgLoc, "babel", JSON);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundIgnore) {
|
||||
let ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||
const ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||
if (exists(ignoreLoc)) {
|
||||
this.addIgnoreConfig(ignoreLoc);
|
||||
foundIgnore = true;
|
||||
@@ -84,7 +84,7 @@ class ConfigChainBuilder {
|
||||
}
|
||||
|
||||
addIgnoreConfig(loc) {
|
||||
let file = fs.readFileSync(loc, "utf8");
|
||||
const file = fs.readFileSync(loc, "utf8");
|
||||
let lines = file.split("\n");
|
||||
|
||||
lines = lines
|
||||
@@ -107,7 +107,7 @@ class ConfigChainBuilder {
|
||||
|
||||
this.resolvedConfigs.push(loc);
|
||||
|
||||
let content = fs.readFileSync(loc, "utf8");
|
||||
const content = fs.readFileSync(loc, "utf8");
|
||||
let options;
|
||||
|
||||
try {
|
||||
@@ -144,7 +144,7 @@ class ConfigChainBuilder {
|
||||
|
||||
// add extends clause
|
||||
if (options.extends) {
|
||||
let extendsLoc = resolve(options.extends, dirname);
|
||||
const extendsLoc = resolve(options.extends, dirname);
|
||||
if (extendsLoc) {
|
||||
this.addConfig(extendsLoc);
|
||||
} else {
|
||||
@@ -162,7 +162,7 @@ class ConfigChainBuilder {
|
||||
|
||||
// env
|
||||
let envOpts;
|
||||
let envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
const envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
if (options.env) {
|
||||
envOpts = options.env[envKey];
|
||||
delete options.env;
|
||||
|
||||
@@ -4,7 +4,7 @@ import config from "./config";
|
||||
export { config };
|
||||
|
||||
export function normaliseOptions(options: Object = {}): Object {
|
||||
for (let key in options) {
|
||||
for (const key in options) {
|
||||
let val = options[key];
|
||||
if (val == null) continue;
|
||||
|
||||
@@ -12,7 +12,7 @@ export function normaliseOptions(options: Object = {}): Object {
|
||||
if (opt && opt.alias) opt = config[opt.alias];
|
||||
if (!opt) continue;
|
||||
|
||||
let parser = parsers[opt.type];
|
||||
const parser = parsers[opt.type];
|
||||
if (parser) val = parser(val);
|
||||
|
||||
options[key] = val;
|
||||
|
||||
@@ -53,7 +53,7 @@ export default class OptionManager {
|
||||
}>;
|
||||
|
||||
static memoisePluginContainer(fn, loc, i, alias) {
|
||||
for (let cache of (OptionManager.memoisedPlugins: Array<Object>)) {
|
||||
for (const cache of (OptionManager.memoisedPlugins: Array<Object>)) {
|
||||
if (cache.container === fn) return cache.plugin;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
if (typeof obj === "object") {
|
||||
let plugin = new Plugin(obj, alias);
|
||||
const plugin = new Plugin(obj, alias);
|
||||
OptionManager.memoisedPlugins.push({
|
||||
container: fn,
|
||||
plugin: plugin
|
||||
@@ -78,10 +78,10 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
static createBareOptions() {
|
||||
let opts = {};
|
||||
const opts = {};
|
||||
|
||||
for (let key in config) {
|
||||
let opt = config[key];
|
||||
for (const key in config) {
|
||||
const opt = config[key];
|
||||
opts[key] = clone(opt.default);
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ export default class OptionManager {
|
||||
plugin = val;
|
||||
}
|
||||
|
||||
let alias = typeof plugin === "string" ? plugin : `${loc}$${i}`;
|
||||
const alias = typeof plugin === "string" ? plugin : `${loc}$${i}`;
|
||||
|
||||
// allow plugins to be specified as strings
|
||||
if (typeof plugin === "string") {
|
||||
let pluginLoc = resolvePlugin(plugin, dirname);
|
||||
const pluginLoc = resolvePlugin(plugin, dirname);
|
||||
if (pluginLoc) {
|
||||
plugin = require(pluginLoc);
|
||||
} else {
|
||||
@@ -164,7 +164,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
//
|
||||
let opts = cloneDeepWith(rawOpts, (val) => {
|
||||
const opts = cloneDeepWith(rawOpts, (val) => {
|
||||
if (val instanceof Plugin) {
|
||||
return val;
|
||||
}
|
||||
@@ -174,16 +174,16 @@ export default class OptionManager {
|
||||
dirname = dirname || process.cwd();
|
||||
loc = loc || alias;
|
||||
|
||||
for (let key in opts) {
|
||||
let option = config[key];
|
||||
for (const key in opts) {
|
||||
const option = config[key];
|
||||
|
||||
// check for an unknown option
|
||||
if (!option && this.log) {
|
||||
if (removed[key]) {
|
||||
this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError);
|
||||
} else {
|
||||
let unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
let presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
|
||||
const unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
const presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
|
||||
|
||||
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
|
||||
}
|
||||
@@ -316,11 +316,11 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
normaliseOptions() {
|
||||
let opts = this.options;
|
||||
const opts = this.options;
|
||||
|
||||
for (let key in config) {
|
||||
let option = config[key];
|
||||
let val = opts[key];
|
||||
for (const key in config) {
|
||||
const option = config[key];
|
||||
const val = opts[key];
|
||||
|
||||
// optional
|
||||
if (!val && option.optional) continue;
|
||||
@@ -335,7 +335,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
init(opts: Object = {}): Object {
|
||||
for (let config of buildConfigChain(opts, this.log)) {
|
||||
for (const config of buildConfigChain(opts, this.log)) {
|
||||
this.mergeOptions(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import slash from "slash";
|
||||
import * as util from "../../../util";
|
||||
|
||||
export let filename = slash;
|
||||
export const filename = slash;
|
||||
|
||||
export function boolean(val: any): boolean {
|
||||
return !!val;
|
||||
|
||||
@@ -20,7 +20,7 @@ export default new Plugin({
|
||||
exit({ node }) {
|
||||
let hasChange = false;
|
||||
for (let i = 0; i < node.body.length; i++) {
|
||||
let bodyNode = node.body[i];
|
||||
const bodyNode = node.body[i];
|
||||
if (bodyNode && bodyNode._blockHoist != null) {
|
||||
hasChange = true;
|
||||
break;
|
||||
|
||||
@@ -41,10 +41,10 @@ function shouldShadow(path, shadowPath) {
|
||||
|
||||
function remap(path, key) {
|
||||
// ensure that we're shadowed
|
||||
let shadowPath = path.inShadow(key);
|
||||
const shadowPath = path.inShadow(key);
|
||||
if (!shouldShadow(path, shadowPath)) return;
|
||||
|
||||
let shadowFunction = path.node._shadowedFunctionLiteral;
|
||||
const shadowFunction = path.node._shadowedFunctionLiteral;
|
||||
|
||||
let currentFunction;
|
||||
let passedShadowFunction = false;
|
||||
@@ -91,15 +91,15 @@ function remap(path, key) {
|
||||
// binding since arrow function syntax already does that.
|
||||
if (!passedShadowFunction) return;
|
||||
|
||||
let cached = fnPath.getData(key);
|
||||
const cached = fnPath.getData(key);
|
||||
if (cached) return path.replaceWith(cached);
|
||||
|
||||
let id = path.scope.generateUidIdentifier(key);
|
||||
const id = path.scope.generateUidIdentifier(key);
|
||||
|
||||
fnPath.setData(key, id);
|
||||
|
||||
let classPath = fnPath.findParent((p) => p.isClass());
|
||||
let hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||
const classPath = fnPath.findParent((p) => p.isClass());
|
||||
const hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||
|
||||
if (key === "this" && fnPath.isMethod({kind: "constructor"}) && hasSuperClass) {
|
||||
fnPath.scope.push({ id });
|
||||
|
||||
@@ -11,7 +11,7 @@ export default class Pipeline {
|
||||
}
|
||||
|
||||
pretransform(code: string, opts?: Object): BabelFileResult {
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
@@ -20,7 +20,7 @@ export default class Pipeline {
|
||||
}
|
||||
|
||||
transform(code: string, opts?: Object): BabelFileResult {
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
@@ -40,7 +40,7 @@ export default class Pipeline {
|
||||
transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.addAst(ast);
|
||||
|
||||
@@ -31,7 +31,7 @@ export default class Plugin extends Store {
|
||||
visitor: Object;
|
||||
|
||||
take(key) {
|
||||
let val = this.raw[key];
|
||||
const val = this.raw[key];
|
||||
delete this.raw[key];
|
||||
return val;
|
||||
}
|
||||
@@ -40,13 +40,13 @@ export default class Plugin extends Store {
|
||||
if (!target[key]) return this[key];
|
||||
if (!this[key]) return target[key];
|
||||
|
||||
let fns: Array<?Function> = [target[key], this[key]];
|
||||
const fns: Array<?Function> = [target[key], this[key]];
|
||||
|
||||
return function (...args) {
|
||||
let val;
|
||||
for (let fn of fns) {
|
||||
for (const fn of fns) {
|
||||
if (fn) {
|
||||
let ret = fn.apply(this, args);
|
||||
const ret = fn.apply(this, args);
|
||||
if (ret != null) val = ret;
|
||||
}
|
||||
}
|
||||
@@ -77,13 +77,13 @@ export default class Plugin extends Store {
|
||||
|
||||
this.maybeInherit(loc);
|
||||
|
||||
for (let key in this.raw) {
|
||||
for (const key in this.raw) {
|
||||
throw new Error(messages.get("pluginInvalidProperty", loc, i, key));
|
||||
}
|
||||
}
|
||||
|
||||
normaliseVisitor(visitor: Object): Object {
|
||||
for (let key of GLOBAL_VISITOR_PROPS) {
|
||||
for (const key of GLOBAL_VISITOR_PROPS) {
|
||||
if (visitor[key]) {
|
||||
throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. Please target individual nodes.");
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ export { inherits, inspect } from "util";
|
||||
*/
|
||||
|
||||
export function canCompile(filename: string, altExts?: Array<string>): boolean {
|
||||
let exts = altExts || canCompile.EXTENSIONS;
|
||||
let ext = path.extname(filename);
|
||||
const exts = altExts || canCompile.EXTENSIONS;
|
||||
const ext = path.extname(filename);
|
||||
return includes(exts, ext);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export function regexify(val: any): RegExp {
|
||||
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
||||
if (startsWith(val, "**/")) val = val.slice(3);
|
||||
|
||||
let regex = minimatch.makeRe(val, { nocase: true });
|
||||
const regex = minimatch.makeRe(val, { nocase: true });
|
||||
return new RegExp(regex.source.slice(1, -1), "i");
|
||||
}
|
||||
|
||||
@@ -119,12 +119,12 @@ export function shouldIgnore(
|
||||
filename = filename.replace(/\\/g, "/");
|
||||
|
||||
if (only) {
|
||||
for (let pattern of only) {
|
||||
for (const pattern of only) {
|
||||
if (_shouldIgnore(pattern, filename)) return false;
|
||||
}
|
||||
return true;
|
||||
} else if (ignore.length) {
|
||||
for (let pattern of ignore) {
|
||||
for (const pattern of ignore) {
|
||||
if (_shouldIgnore(pattern, filename)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
let babel = require("../lib/api/node");
|
||||
let buildExternalHelpers = require("../lib/tools/build-external-helpers");
|
||||
let sourceMap = require("source-map");
|
||||
let assert = require("assert");
|
||||
let Plugin = require("../lib/transformation/plugin");
|
||||
let generator = require("babel-generator").default;
|
||||
const babel = require("../lib/api/node");
|
||||
const buildExternalHelpers = require("../lib/tools/build-external-helpers");
|
||||
const sourceMap = require("source-map");
|
||||
const assert = require("assert");
|
||||
const Plugin = require("../lib/transformation/plugin");
|
||||
const generator = require("babel-generator").default;
|
||||
|
||||
function assertIgnored(result) {
|
||||
assert.ok(result.ignored);
|
||||
@@ -23,7 +23,7 @@ function transformAsync(code, opts) {
|
||||
}
|
||||
|
||||
describe("parser and generator options", function() {
|
||||
let recast = {
|
||||
const recast = {
|
||||
parse: function(code, opts) {
|
||||
return opts.parser.parse(code);
|
||||
},
|
||||
@@ -46,13 +46,13 @@ describe("parser and generator options", function() {
|
||||
}
|
||||
|
||||
it("options", function() {
|
||||
let string = "original;";
|
||||
const string = "original;";
|
||||
assert.deepEqual(newTransform(string).ast, babel.transform(string).ast);
|
||||
assert.equal(newTransform(string).code, string);
|
||||
});
|
||||
|
||||
it("experimental syntax", function() {
|
||||
let experimental = "var a: number = 1;";
|
||||
const experimental = "var a: number = 1;";
|
||||
|
||||
assert.deepEqual(newTransform(experimental).ast, babel.transform(experimental, {
|
||||
parserOpts: {
|
||||
@@ -82,7 +82,7 @@ describe("parser and generator options", function() {
|
||||
});
|
||||
|
||||
it("other options", function() {
|
||||
let experimental = "if (true) {\n import a from 'a';\n}";
|
||||
const experimental = "if (true) {\n import a from 'a';\n}";
|
||||
|
||||
assert.notEqual(newTransform(experimental).ast, babel.transform(experimental, {
|
||||
parserOpts: {
|
||||
@@ -199,7 +199,7 @@ describe("api", function () {
|
||||
new Plugin({
|
||||
visitor: {
|
||||
Function: function(path) {
|
||||
let alias = path.scope.getProgramParent().path.get("body")[0].node;
|
||||
const alias = path.scope.getProgramParent().path.get("body")[0].node;
|
||||
if (!babel.types.isTypeAlias(alias)) return;
|
||||
|
||||
// In case of `passPerPreset` being `false`, the
|
||||
@@ -264,7 +264,7 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("source map merging", function () {
|
||||
let result = babel.transform([
|
||||
const result = babel.transform([
|
||||
"function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }",
|
||||
"",
|
||||
"let Foo = function Foo() {",
|
||||
@@ -288,7 +288,7 @@ describe("api", function () {
|
||||
"};"
|
||||
].join("\n"), result.code);
|
||||
|
||||
let consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
const consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
assert.deepEqual(consumer.originalPositionFor({
|
||||
line: 7,
|
||||
@@ -318,7 +318,7 @@ describe("api", function () {
|
||||
auxiliaryCommentBefore: "before",
|
||||
auxiliaryCommentAfter: "after",
|
||||
plugins: [function (babel) {
|
||||
let t = babel.types;
|
||||
const t = babel.types;
|
||||
return {
|
||||
visitor: {
|
||||
Program: function (path) {
|
||||
@@ -539,8 +539,8 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
describe("env option", function () {
|
||||
let oldBabelEnv = process.env.BABEL_ENV;
|
||||
let oldNodeEnv = process.env.NODE_ENV;
|
||||
const oldBabelEnv = process.env.BABEL_ENV;
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
setup(function () {
|
||||
// Tests need to run with the default and specific values for these. They
|
||||
@@ -555,7 +555,7 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("default", function () {
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
development: { code: false }
|
||||
}
|
||||
@@ -566,7 +566,7 @@ describe("api", function () {
|
||||
|
||||
it("BABEL_ENV", function () {
|
||||
process.env.BABEL_ENV = "foo";
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
foo: { code: false }
|
||||
}
|
||||
@@ -576,7 +576,7 @@ describe("api", function () {
|
||||
|
||||
it("NODE_ENV", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
foo: { code: false }
|
||||
}
|
||||
@@ -586,8 +586,8 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("resolveModuleSource option", function () {
|
||||
let actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";";
|
||||
let expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";";
|
||||
const actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";";
|
||||
const expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";";
|
||||
|
||||
return transformAsync(actual, {
|
||||
resolveModuleSource: function (originalSource) {
|
||||
@@ -600,25 +600,25 @@ describe("api", function () {
|
||||
|
||||
describe("buildExternalHelpers", function () {
|
||||
it("all", function () {
|
||||
let script = buildExternalHelpers();
|
||||
const script = buildExternalHelpers();
|
||||
assert.ok(script.indexOf("classCallCheck") >= -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
|
||||
it("whitelist", function () {
|
||||
let script = buildExternalHelpers(["inherits"]);
|
||||
const script = buildExternalHelpers(["inherits"]);
|
||||
assert.ok(script.indexOf("classCallCheck") === -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
|
||||
it("empty whitelist", function () {
|
||||
let script = buildExternalHelpers([]);
|
||||
const script = buildExternalHelpers([]);
|
||||
assert.ok(script.indexOf("classCallCheck") === -1);
|
||||
assert.ok(script.indexOf("inherits") === -1);
|
||||
});
|
||||
|
||||
it("underscored", function () {
|
||||
let script = buildExternalHelpers(["typeof"]);
|
||||
const script = buildExternalHelpers(["typeof"]);
|
||||
assert.ok(script.indexOf("typeof") >= 0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
let browserify = require("browserify");
|
||||
let assert = require("assert");
|
||||
let path = require("path");
|
||||
let vm = require("vm");
|
||||
const browserify = require("browserify");
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
describe("browserify", function() {
|
||||
it("babel/register may be used without breaking browserify", function(done) {
|
||||
let bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
const bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
|
||||
bundler.bundle(function(err, bundle) {
|
||||
if (err) return done(err);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
let assert = require("assert");
|
||||
let path = require("path");
|
||||
let buildConfigChain = require("../lib/transformation/file/options/build-config-chain");
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
const buildConfigChain = require("../lib/transformation/file/options/build-config-chain");
|
||||
|
||||
function fixture() {
|
||||
let args = [__dirname, "fixtures", "config"];
|
||||
const args = [__dirname, "fixtures", "config"];
|
||||
for (let i = 0; i < arguments.length; i ++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
@@ -28,11 +28,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("dir1", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("dir1", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -77,11 +77,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("dir2", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("dir2", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -116,11 +116,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("env - base", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -157,11 +157,11 @@ describe("buildConfigChain", function () {
|
||||
it("env - foo", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -209,11 +209,11 @@ describe("buildConfigChain", function () {
|
||||
process.env.NODE_ENV = "foo"; // overridden
|
||||
process.env.NODE_ENV = "bar";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -261,11 +261,11 @@ describe("buildConfigChain", function () {
|
||||
it("env - foo", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("pkg", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: ["pkg-plugin"]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
let traverse = require("babel-traverse").default;
|
||||
let assert = require("assert");
|
||||
let parse = require("babylon").parse;
|
||||
const traverse = require("babel-traverse").default;
|
||||
const assert = require("assert");
|
||||
const parse = require("babylon").parse;
|
||||
|
||||
describe("evaluation", function () {
|
||||
function addTest(code, type, value, notConfident) {
|
||||
it(type + ": " + code, function () {
|
||||
let visitor = {};
|
||||
const visitor = {};
|
||||
|
||||
visitor[type] = function (path) {
|
||||
let evaluate = path.evaluate();
|
||||
const evaluate = path.evaluate();
|
||||
assert.equal(evaluate.confident, !notConfident);
|
||||
assert.deepEqual(evaluate.value, value);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let assert = require("assert");
|
||||
let getPossiblePluginNames = require("../lib/helpers/get-possible-plugin-names");
|
||||
const assert = require("assert");
|
||||
const getPossiblePluginNames = require("../lib/helpers/get-possible-plugin-names");
|
||||
|
||||
describe("getPossiblePluginNames", function () {
|
||||
it("adds the babel-plugin prefix", function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let assert = require("assert");
|
||||
let getPossiblePresetNames = require("../lib/helpers/get-possible-preset-names");
|
||||
const assert = require("assert");
|
||||
const getPossiblePresetNames = require("../lib/helpers/get-possible-preset-names");
|
||||
|
||||
describe("getPossiblePresetNames", function () {
|
||||
it("adds the babel-preset prefix", function() {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"randomOption": true
|
||||
});
|
||||
@@ -29,7 +29,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"auxiliaryComment": true,
|
||||
"blacklist": true
|
||||
@@ -42,7 +42,7 @@ describe("option-manager", () => {
|
||||
it("throws for resolved but erroring preset", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")]
|
||||
});
|
||||
@@ -54,7 +54,7 @@ describe("option-manager", () => {
|
||||
it("throws for invalid preset configuration", function() {
|
||||
return assert.throws(
|
||||
function () {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"presets": [{ option: "value" }]
|
||||
});
|
||||
@@ -67,8 +67,8 @@ describe("option-manager", () => {
|
||||
describe("presets", function () {
|
||||
function presetTest(name) {
|
||||
it(name, function () {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
let options = opt.init({
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const options = opt.init({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/presets", name)]
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
let transform = require("../lib/api/node").transform;
|
||||
let Plugin = require("../lib/transformation/plugin");
|
||||
let chai = require("chai");
|
||||
const transform = require("../lib/api/node").transform;
|
||||
const Plugin = require("../lib/transformation/plugin");
|
||||
const chai = require("chai");
|
||||
|
||||
describe("traversal path", function () {
|
||||
it("replaceWithSourceString", function () {
|
||||
let expectCode = "function foo() {}";
|
||||
const expectCode = "function foo() {}";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
FunctionDeclaration: function (path) {
|
||||
@@ -20,9 +20,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (arrow expression body to block statement body)", function () {
|
||||
let expectCode = "var fn = () => true;";
|
||||
const expectCode = "var fn = () => true;";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ArrowFunctionExpression: function (path) {
|
||||
@@ -45,9 +45,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (arrow block statement body to expression body)", function () {
|
||||
let expectCode = "var fn = () => { return true; }";
|
||||
const expectCode = "var fn = () => { return true; }";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ArrowFunctionExpression: function (path) {
|
||||
@@ -64,9 +64,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-in left expression to variable declaration)", function () {
|
||||
let expectCode = "for (KEY in right);";
|
||||
const expectCode = "for (KEY in right);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForInStatement: function (path) {
|
||||
@@ -90,9 +90,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-in left variable declaration to expression)", function () {
|
||||
let expectCode = "for (var KEY in right);";
|
||||
const expectCode = "for (var KEY in right);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForInStatement: function (path) {
|
||||
@@ -109,9 +109,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-loop left expression to variable declaration)", function () {
|
||||
let expectCode = "for (KEY;;);";
|
||||
const expectCode = "for (KEY;;);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForStatement: function (path) {
|
||||
@@ -135,9 +135,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-loop left variable declaration to expression)", function () {
|
||||
let expectCode = "for (var KEY;;);";
|
||||
const expectCode = "for (var KEY;;);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForStatement: function (path) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
let assert = require("assert");
|
||||
let async = require("async");
|
||||
let babel = require("../lib/api/node");
|
||||
let fs = require("fs");
|
||||
let path = require("path");
|
||||
const assert = require("assert");
|
||||
const async = require("async");
|
||||
const babel = require("../lib/api/node");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Test that plugins & presets are resolved relative to `filename`.
|
||||
describe("addon resolution", function () {
|
||||
it("addon resolution", function (done) {
|
||||
let fixtures = {};
|
||||
let paths = {};
|
||||
const fixtures = {};
|
||||
const paths = {};
|
||||
|
||||
paths.fixtures = path.join(
|
||||
__dirname,
|
||||
@@ -33,7 +33,7 @@ describe("addon resolution", function () {
|
||||
function fixturesReady (err) {
|
||||
if (err) return done(err);
|
||||
|
||||
let actual = babel.transform(fixtures.actual, {
|
||||
const actual = babel.transform(fixtures.actual, {
|
||||
filename: paths.actual,
|
||||
plugins: ["addons/plugin"],
|
||||
presets: ["addons/preset"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
let assert = require("assert");
|
||||
let util = require("../lib/util");
|
||||
let t = require("babel-types");
|
||||
const assert = require("assert");
|
||||
const util = require("../lib/util");
|
||||
const t = require("babel-types");
|
||||
|
||||
describe("util", function () {
|
||||
it("canCompile", function () {
|
||||
@@ -36,7 +36,7 @@ describe("util", function () {
|
||||
assert.deepEqual(util.list(["foo", "bar"]), ["foo", "bar"]);
|
||||
assert.deepEqual(util.list(/foo/), [/foo/]);
|
||||
|
||||
let date = new Date;
|
||||
const date = new Date;
|
||||
assert.deepEqual(util.list(date), [date]);
|
||||
});
|
||||
|
||||
@@ -84,8 +84,8 @@ describe("util", function () {
|
||||
});
|
||||
|
||||
it("shouldIgnore", function () {
|
||||
let reIgnore = /\-reIgnore\.js/;
|
||||
let fnIgnore = function (src) {
|
||||
const reIgnore = /\-reIgnore\.js/;
|
||||
const fnIgnore = function (src) {
|
||||
if (src.indexOf("fnIgnore") > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user