Re-enable the max-len ESLint rule. (#5265)
This commit is contained in:
parent
4d411ef83e
commit
b845f2b69d
@ -1,7 +1,6 @@
|
||||
{
|
||||
"extends": "babel",
|
||||
"rules": {
|
||||
"max-len": 0
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ node_modules
|
||||
test/tmp
|
||||
*.log
|
||||
*.cache
|
||||
/.eslintcache
|
||||
/templates.json
|
||||
/tests.json
|
||||
/browser.js
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"settings": {
|
||||
"rulers": [
|
||||
100
|
||||
110
|
||||
],
|
||||
|
||||
// Set to false to disable detection of tabs vs. spaces on load
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint indent: 0 */
|
||||
|
||||
/**
|
||||
* This tiny wrapper file checks for known node flags and appends them
|
||||
* when found, before invoking the "real" _babel-node(1) executable.
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
require("babel-core");
|
||||
|
||||
const fs = require("fs");
|
||||
const commander = require("commander");
|
||||
@ -38,6 +35,7 @@ Object.keys(options).forEach(function (key) {
|
||||
commander.option(arg, desc.join(" "));
|
||||
});
|
||||
|
||||
/* eslint-disable max-len */
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("--skip-initial-build", "Do not compile files before watching");
|
||||
@ -45,6 +43,7 @@ commander.option("-o, --out-file [out]", "Compile all input files into a single
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
/* eslint-enable max-len */
|
||||
|
||||
const pkg = require("../../package.json");
|
||||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
||||
|
||||
@ -46,7 +46,8 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stderr) {
|
||||
if (opts.stderrContains) {
|
||||
assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) +
|
||||
" didn't contain " + JSON.stringify(expectStderr));
|
||||
} else {
|
||||
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
|
||||
}
|
||||
@ -60,7 +61,8 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) +
|
||||
" didn't contain " + JSON.stringify(expectStdout));
|
||||
} else {
|
||||
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
||||
}
|
||||
|
||||
@ -197,10 +197,12 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
""
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }), chalk.reset([
|
||||
assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }),
|
||||
chalk.reset([
|
||||
" " + gutter(" 2 | "),
|
||||
marker(">") + gutter(" 3 | "),
|
||||
" " + gutter(" 4 | ")
|
||||
].join("\n")));
|
||||
].join("\n"))
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import * as helpers from "babel-helpers";
|
||||
import generator from "babel-generator";
|
||||
import * as messages from "babel-messages";
|
||||
@ -23,12 +21,14 @@ const buildUmdWrapper = template(`
|
||||
function buildGlobal(namespace, builder) {
|
||||
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")]))]);
|
||||
const tree = t.program([
|
||||
t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace),
|
||||
t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
/* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import getHelper from "babel-helpers";
|
||||
import * as metadataVisitor from "./metadata";
|
||||
@ -378,8 +377,8 @@ export default class File extends Store {
|
||||
sourceRoot: inputMapConsumer.sourceRoot
|
||||
});
|
||||
|
||||
// This assumes the output map always has a single source, since Babel always compiles a single source file to a
|
||||
// single output file.
|
||||
// This assumes the output map always has a single source, since Babel always compiles a
|
||||
// single source file to a single output file.
|
||||
const source = outputMapConsumer.sources[0];
|
||||
|
||||
inputMapConsumer.eachMapping(function (mapping) {
|
||||
@ -424,7 +423,8 @@ export default class File extends Store {
|
||||
if (parser) {
|
||||
parseCode = require(parser).parse;
|
||||
} else {
|
||||
throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method relative to directory ${dirname}`);
|
||||
throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method ` +
|
||||
`relative to directory ${dirname}`);
|
||||
}
|
||||
} else {
|
||||
parseCode = parserOpts.parser;
|
||||
@ -472,7 +472,8 @@ export default class File extends Store {
|
||||
this.log.debug("Start transform traverse");
|
||||
|
||||
// merge all plugin visitors into a single visitor
|
||||
const 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");
|
||||
@ -610,14 +611,16 @@ export default class File extends Store {
|
||||
if (generator) {
|
||||
gen = require(generator).print;
|
||||
} else {
|
||||
throw new Error(`Couldn't find generator ${gen} with "print" method relative to directory ${dirname}`);
|
||||
throw new Error(`Couldn't find generator ${gen} with "print" method relative ` +
|
||||
`to directory ${dirname}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.log.debug("Generation start");
|
||||
|
||||
const _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,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
module.exports = {
|
||||
filename: {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import * as context from "../../../api/node";
|
||||
import type Logger from "../logger";
|
||||
import Plugin from "../../plugin";
|
||||
@ -180,10 +178,13 @@ export default class OptionManager {
|
||||
// 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);
|
||||
this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`,
|
||||
ReferenceError);
|
||||
} else {
|
||||
/* eslint-disable max-len */
|
||||
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.";
|
||||
/* eslint-enable max-len */
|
||||
|
||||
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
module.exports = {
|
||||
"auxiliaryComment": {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import OptionManager from "./file/options/option-manager";
|
||||
import * as messages from "babel-messages";
|
||||
import Store from "../store";
|
||||
@ -85,7 +83,8 @@ export default class Plugin extends Store {
|
||||
normaliseVisitor(visitor: Object): Object {
|
||||
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.");
|
||||
throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. " +
|
||||
"Please target individual nodes.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -265,6 +265,7 @@ describe("api", function () {
|
||||
|
||||
it("source map merging", function () {
|
||||
const result = babel.transform([
|
||||
/* eslint-disable max-len */
|
||||
"function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }",
|
||||
"",
|
||||
"let Foo = function Foo() {",
|
||||
@ -272,6 +273,7 @@ describe("api", function () {
|
||||
"};",
|
||||
"",
|
||||
"//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0="
|
||||
/* eslint-enable max-len */
|
||||
].join("\n"), {
|
||||
sourceMap: true
|
||||
});
|
||||
@ -329,12 +331,14 @@ describe("api", function () {
|
||||
};
|
||||
}]
|
||||
}).then(function (result) {
|
||||
assert.equal(result.code, "/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/");
|
||||
assert.equal(result.code,
|
||||
"/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/");
|
||||
});
|
||||
});
|
||||
|
||||
it("modules metadata", function () {
|
||||
return Promise.all([
|
||||
// eslint-disable-next-line max-len
|
||||
transformAsync("import { externalName as localName } from \"external\";").then(function (result) {
|
||||
assert.deepEqual(result.metadata.modules.imports[0], {
|
||||
source: "external",
|
||||
@ -586,8 +590,10 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("resolveModuleSource option", function () {
|
||||
/* eslint-disable max-len */
|
||||
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\";";
|
||||
/* eslint-enable max-len */
|
||||
|
||||
return transformAsync(actual, {
|
||||
resolveModuleSource: function (originalSource) {
|
||||
|
||||
@ -35,6 +35,7 @@ describe("option-manager", () => {
|
||||
"blacklist": true
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line max-len
|
||||
/Using removed Babel 5 option: base.auxiliaryComment - Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`/
|
||||
);
|
||||
});
|
||||
@ -59,6 +60,7 @@ describe("option-manager", () => {
|
||||
"presets": [{ option: "value" }]
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line max-len
|
||||
/Unknown option: foreign.option\.(?:.|\n)+A common cause of this error is the presence of a configuration options object without the corresponding preset name/
|
||||
);
|
||||
});
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import * as t from "babel-types";
|
||||
import * as n from "../node";
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export function AnyTypeAnnotation() {
|
||||
this.word("any");
|
||||
}
|
||||
|
||||
@ -93,5 +93,6 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
}
|
||||
|
||||
function hasTypes(node, param) {
|
||||
return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments;
|
||||
return node.typeParameters || node.returnType || param.typeAnnotation || param.optional ||
|
||||
param.trailingComments;
|
||||
}
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint quotes: 0 */
|
||||
|
||||
import * as t from "babel-types";
|
||||
import jsesc from "jsesc";
|
||||
|
||||
@ -62,7 +59,8 @@ export function ObjectProperty(node: Object) {
|
||||
this.token("]");
|
||||
} else {
|
||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) &&
|
||||
node.key.name === node.value.left.name) {
|
||||
this.print(node.value, node);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import find from "lodash/find";
|
||||
import findLast from "lodash/findLast";
|
||||
import isInteger from "lodash/isInteger";
|
||||
@ -321,6 +319,7 @@ export default class Printer {
|
||||
|
||||
const printMethod = this[node.type];
|
||||
if (!printMethod) {
|
||||
// eslint-disable-next-line max-len
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
||||
}
|
||||
|
||||
|
||||
@ -312,7 +312,10 @@ suites.forEach(function (testSuite) {
|
||||
});
|
||||
const result = generate(actualAst, task.options, actualCode);
|
||||
|
||||
if (!expect.code && result.code && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) {
|
||||
if (
|
||||
!expect.code && result.code && fs.statSync(path.dirname(expect.loc)).isDirectory() &&
|
||||
!process.env.CI
|
||||
) {
|
||||
console.log(`New test file created: ${expect.loc}`);
|
||||
fs.writeFileSync(expect.loc, result.code);
|
||||
} else {
|
||||
|
||||
@ -128,7 +128,8 @@ export default function (opts) {
|
||||
|
||||
const useBuiltIns = file.opts.useBuiltIns || false;
|
||||
if (typeof useBuiltIns !== "boolean") {
|
||||
throw new Error("transform-react-jsx currently only accepts a boolean option for useBuiltIns (defaults to false)");
|
||||
throw new Error("transform-react-jsx currently only accepts a boolean option for " +
|
||||
"useBuiltIns (defaults to false)");
|
||||
}
|
||||
|
||||
function pushProps() {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import nameFunction from "babel-helper-function-name";
|
||||
import has from "lodash/has";
|
||||
import * as t from "babel-types";
|
||||
@ -36,7 +34,8 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
||||
|
||||
if (node.decorators) {
|
||||
const decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map((dec) => dec.expression).reverse());
|
||||
decorators.elements = decorators.elements.concat(
|
||||
node.decorators.map((dec) => dec.expression).reverse());
|
||||
}
|
||||
|
||||
if (map.value || map.initializer) {
|
||||
@ -63,7 +62,8 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
||||
}
|
||||
|
||||
// infer function name
|
||||
if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && t.isFunctionExpression(value)) {
|
||||
if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") &&
|
||||
t.isFunctionExpression(value)) {
|
||||
value = nameFunction({ id: key, node: value, scope });
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import getFunctionArity from "babel-helper-get-function-arity";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
@ -131,7 +129,8 @@ export default function ({ node, parent, scope, id }) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) && (!parent.computed || t.isLiteral(parent.key))) {
|
||||
if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) &&
|
||||
(!parent.computed || t.isLiteral(parent.key))) {
|
||||
// { foo() {} };
|
||||
id = parent.key;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function (callee, thisNode, args) {
|
||||
if (args.length === 1 && t.isSpreadElement(args[0]) && t.isIdentifier(args[0].argument, { name: "arguments" })) {
|
||||
if (args.length === 1 && t.isSpreadElement(args[0]) &&
|
||||
t.isIdentifier(args[0].argument, { name: "arguments" })) {
|
||||
// eg. super(...arguments);
|
||||
return t.callExpression(
|
||||
t.memberExpression(callee, t.identifier("apply")),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import type { NodePath, Scope } from "babel-traverse";
|
||||
import optimiseCall from "babel-helper-optimise-call-expression";
|
||||
import * as messages from "babel-messages";
|
||||
@ -144,7 +142,8 @@ export default class ReplaceSupers {
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* _set(CLASS.prototype.__proto__ || Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this)
|
||||
* _set(CLASS.prototype.__proto__ || Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE",
|
||||
* this)
|
||||
*
|
||||
*/
|
||||
|
||||
@ -227,9 +226,8 @@ export default class ReplaceSupers {
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ref, node.left)
|
||||
]),
|
||||
t.expressionStatement(
|
||||
t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right))
|
||||
)
|
||||
t.expressionStatement(t.assignmentExpression("=", node.left,
|
||||
t.binaryExpression(node.operator[0], ref, node.right)))
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -251,22 +249,30 @@ export default class ReplaceSupers {
|
||||
if (t.isSuper(callee)) {
|
||||
return;
|
||||
} else if (isMemberExpressionSuper(callee)) {
|
||||
// super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this);
|
||||
// super.test();
|
||||
// to
|
||||
// _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
}
|
||||
} else if (t.isMemberExpression(node) && t.isSuper(node.object)) {
|
||||
// super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||
// super.name;
|
||||
// to
|
||||
// _get(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
||||
const binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1));
|
||||
if (node.prefix) {
|
||||
// ++super.foo; -> super.foo += 1;
|
||||
// ++super.foo;
|
||||
// to
|
||||
// super.foo += 1;
|
||||
return this.specHandleAssignmentExpression(null, path, binary);
|
||||
} else {
|
||||
// super.foo++; -> let _ref = super.foo; super.foo = _ref + 1;
|
||||
// super.foo++;
|
||||
// to
|
||||
// let _ref = super.foo; super.foo = _ref + 1;
|
||||
const ref = path.scope.generateUidIdentifier("ref");
|
||||
return this.specHandleAssignmentExpression(ref, path, binary).concat(t.expressionStatement(ref));
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@ function wrapPackagesArray(type, names, optionsDir) {
|
||||
if (val[0][0] === ".") {
|
||||
|
||||
if (!optionsDir) {
|
||||
throw new Error("Please provide an options.json in test dir when using a relative plugin path.");
|
||||
throw new Error("Please provide an options.json in test dir when using a " +
|
||||
"relative plugin path.");
|
||||
}
|
||||
|
||||
val[0] = path.resolve(optionsDir, val[0]);
|
||||
@ -53,7 +54,8 @@ function run(task) {
|
||||
newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins, optionsDir);
|
||||
newOpts.presets = wrapPackagesArray("preset", newOpts.presets, optionsDir).map(function (val) {
|
||||
if (val.length > 2) {
|
||||
throw new Error(`Unexpected extra options ${JSON.stringify(val.slice(2))} passed to preset.`);
|
||||
throw new Error("Unexpected extra options " + JSON.stringify(val.slice(2)) +
|
||||
" passed to preset.");
|
||||
}
|
||||
|
||||
return val;
|
||||
@ -85,7 +87,10 @@ function run(task) {
|
||||
const expectCode = expect.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = babel.transform(actualCode, getOpts(actual));
|
||||
if (!expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) {
|
||||
if (
|
||||
!expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() &&
|
||||
!process.env.CI
|
||||
) {
|
||||
console.log(`New test file created: ${expect.loc}`);
|
||||
fs.writeFileSync(expect.loc, result.code);
|
||||
} else {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
import template from "babel-template";
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint no-confusing-arrow: 0 */
|
||||
|
||||
import helpers from "./helpers";
|
||||
|
||||
export function get(name) {
|
||||
@ -10,7 +8,7 @@ export function get(name) {
|
||||
}
|
||||
|
||||
export const list = Object.keys(helpers)
|
||||
.map((name) => name[0] === "_" ? name.slice(1) : name)
|
||||
.map((name) => name.replace(/^_/, ""))
|
||||
.filter((name) => name !== "__esModule");
|
||||
|
||||
export default get;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
import * as util from "util";
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
import nameFunction from "babel-helper-function-name";
|
||||
import template from "babel-template";
|
||||
|
||||
@ -44,7 +43,8 @@ export default function ({ types: t }) {
|
||||
|
||||
visitor: {
|
||||
Class(path, state) {
|
||||
const buildClassProperty = state.opts.spec ? buildClassPropertySpec : buildClassPropertyNonSpec;
|
||||
const buildClassProperty = state.opts.spec ? buildClassPropertySpec :
|
||||
buildClassPropertyNonSpec;
|
||||
const isDerived = !!path.node.superClass;
|
||||
let constructor;
|
||||
const props = [];
|
||||
@ -92,7 +92,8 @@ export default function ({ types: t }) {
|
||||
|
||||
if (instanceBody.length) {
|
||||
if (!constructor) {
|
||||
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([]));
|
||||
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [],
|
||||
t.blockStatement([]));
|
||||
if (isDerived) {
|
||||
newConstructor.params = [t.restElement(t.identifier("args"))];
|
||||
newConstructor.body.body.push(
|
||||
@ -129,7 +130,8 @@ export default function ({ types: t }) {
|
||||
|
||||
instanceBody = [
|
||||
t.expressionStatement(
|
||||
t.callExpression(t.memberExpression(initialisePropsRef, t.identifier("call")), [t.thisExpression()])
|
||||
t.callExpression(t.memberExpression(initialisePropsRef, t.identifier("call")), [
|
||||
t.thisExpression()])
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import type NodePath from "babel-traverse";
|
||||
import type Scope from "babel-traverse";
|
||||
import type File from "../../../file";
|
||||
@ -397,7 +395,8 @@ class BlockScoping {
|
||||
const isSwitch = this.blockPath.isSwitchStatement();
|
||||
|
||||
// build the closure that we're going to wrap the block with, possible wrapping switch(){}
|
||||
const fn = t.functionExpression(null, params, t.blockStatement(isSwitch ? [block] : block.body));
|
||||
const fn = t.functionExpression(null, params,
|
||||
t.blockStatement(isSwitch ? [block] : block.body));
|
||||
fn.shadow = true;
|
||||
|
||||
// continuation
|
||||
@ -654,7 +653,8 @@ class BlockScoping {
|
||||
for (let i = 0; i < cases.length; i++) {
|
||||
const caseConsequent = cases[i].consequent[0];
|
||||
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
|
||||
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
|
||||
caseConsequent.label = this.loopLabel = this.loopLabel ||
|
||||
this.scope.generateUidIdentifier("loop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import type { NodePath } from "babel-traverse";
|
||||
import { visitors } from "babel-traverse";
|
||||
import ReplaceSupers from "babel-helper-replace-supers";
|
||||
@ -28,7 +26,10 @@ const noMethodVisitor = {
|
||||
|
||||
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
||||
Super(path) {
|
||||
if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) {
|
||||
if (
|
||||
this.isDerived && !this.hasBareSuper &&
|
||||
!path.parentPath.isCallExpression({ callee: path.node })
|
||||
) {
|
||||
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
|
||||
}
|
||||
},
|
||||
@ -88,7 +89,8 @@ export default class ClassTransformer {
|
||||
this.classId = this.node.id;
|
||||
|
||||
// this is the name of the binding that will **always** reference the class we've constructed
|
||||
this.classRef = this.node.id ? t.identifier(this.node.id.name) : this.scope.generateUidIdentifier("class");
|
||||
this.classRef = this.node.id ? t.identifier(this.node.id.name) :
|
||||
this.scope.generateUidIdentifier("class");
|
||||
|
||||
this.superName = this.node.superClass || t.identifier("Function");
|
||||
this.isDerived = !!this.node.superClass;
|
||||
@ -123,10 +125,12 @@ export default class ClassTransformer {
|
||||
this.buildBody();
|
||||
|
||||
// make sure this class isn't directly called
|
||||
constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("classCallCheck"), [
|
||||
constructorBody.body.unshift(t.expressionStatement(t.callExpression(
|
||||
file.addHelper("classCallCheck"), [
|
||||
t.thisExpression(),
|
||||
this.classRef
|
||||
])));
|
||||
]
|
||||
)));
|
||||
|
||||
body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef)));
|
||||
|
||||
@ -227,7 +231,8 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
if (node.decorators) {
|
||||
throw path.buildCodeFrameError("Method has decorators, put the decorator plugin before the classes one.");
|
||||
throw path.buildCodeFrameError(
|
||||
"Method has decorators, put the decorator plugin before the classes one.");
|
||||
}
|
||||
|
||||
if (t.isClassMethod(node)) {
|
||||
@ -294,8 +299,13 @@ export default class ClassTransformer {
|
||||
|
||||
const nullNode = t.nullLiteral();
|
||||
|
||||
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers)
|
||||
let args = [this.classRef, nullNode, nullNode, nullNode, nullNode];
|
||||
let args = [
|
||||
this.classRef, // Constructor
|
||||
nullNode, // instanceDescriptors
|
||||
nullNode, // staticDescriptors
|
||||
nullNode, // instanceInitializers
|
||||
nullNode, // staticInitializers
|
||||
];
|
||||
|
||||
if (instanceProps) args[1] = instanceProps;
|
||||
if (staticProps) args[2] = staticProps;
|
||||
@ -336,7 +346,11 @@ export default class ClassTransformer {
|
||||
|
||||
if (this.isLoose) {
|
||||
bareSuperNode.arguments.unshift(t.thisExpression());
|
||||
if (bareSuperNode.arguments.length === 2 && t.isSpreadElement(bareSuperNode.arguments[1]) && t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" })) {
|
||||
if (
|
||||
bareSuperNode.arguments.length === 2 &&
|
||||
t.isSpreadElement(bareSuperNode.arguments[1]) &&
|
||||
t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" })
|
||||
) {
|
||||
// special case single arguments spread
|
||||
bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument;
|
||||
bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply"));
|
||||
@ -365,7 +379,11 @@ export default class ClassTransformer {
|
||||
|
||||
const bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef));
|
||||
|
||||
if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) {
|
||||
if (
|
||||
bareSuper.parentPath.isExpressionStatement() &&
|
||||
bareSuper.parentPath.container === body.node.body &&
|
||||
body.node.body.length - 1 === bareSuper.parentPath.key
|
||||
) {
|
||||
// this super call is the last statement in the body so we can just straight up
|
||||
// turn it into a return
|
||||
|
||||
@ -435,7 +453,8 @@ export default class ClassTransformer {
|
||||
// return
|
||||
const bodyPaths = body.get("body");
|
||||
if (bodyPaths.length && !bodyPaths.pop().isReturnStatement()) {
|
||||
body.pushContainer("body", t.returnStatement(guaranteedSuperBeforeFinish ? thisRef : wrapReturn()));
|
||||
body.pushContainer("body", t.returnStatement(
|
||||
guaranteedSuperBeforeFinish ? thisRef : wrapReturn()));
|
||||
}
|
||||
|
||||
for (const returnPath of this.superReturns) {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export default function ({ types: t }) {
|
||||
|
||||
/**
|
||||
@ -153,7 +151,8 @@ export default function ({ types: t }) {
|
||||
|
||||
//
|
||||
|
||||
const value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]);
|
||||
const value = t.callExpression(
|
||||
this.file.addHelper("objectWithoutProperties"), [objRef, keys]);
|
||||
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
|
||||
}
|
||||
|
||||
@ -294,7 +293,8 @@ export default function ({ types: t }) {
|
||||
|
||||
if (t.isRestElement(elem)) {
|
||||
elemRef = this.toArray(arrayRef);
|
||||
elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.numericLiteral(i)]);
|
||||
elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")),
|
||||
[t.numericLiteral(i)]);
|
||||
|
||||
// set the element to the rest element argument since we've dealt with it
|
||||
// being a rest already
|
||||
@ -485,14 +485,18 @@ export default function ({ types: t }) {
|
||||
t.inherits(nodes[nodes.length - 1], declar);
|
||||
}
|
||||
} else {
|
||||
nodes.push(t.inherits(destructuring.buildVariableAssignment(declar.id, declar.init), declar));
|
||||
nodes.push(t.inherits(
|
||||
destructuring.buildVariableAssignment(declar.id, declar.init), declar));
|
||||
}
|
||||
}
|
||||
|
||||
const nodesOut = [];
|
||||
for (const node of nodes) {
|
||||
const tail = nodesOut[nodesOut.length - 1];
|
||||
if (tail && t.isVariableDeclaration(tail) && t.isVariableDeclaration(node) && tail.kind === node.kind) {
|
||||
if (
|
||||
tail && t.isVariableDeclaration(tail) && t.isVariableDeclaration(node) &&
|
||||
tail.kind === node.kind
|
||||
) {
|
||||
// Create a single compound let/var rather than many.
|
||||
tail.declarations.push(...node.declarations);
|
||||
} else {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export default function ({ messages, template, types: t }) {
|
||||
const buildForOfArray = template(`
|
||||
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;
|
||||
@ -22,6 +20,7 @@ export default function ({ messages, template, types: t }) {
|
||||
}
|
||||
`);
|
||||
|
||||
/* eslint-disable max-len */
|
||||
const buildForOf = template(`
|
||||
var ITERATOR_COMPLETION = true;
|
||||
var ITERATOR_HAD_ERROR_KEY = false;
|
||||
@ -44,6 +43,7 @@ export default function ({ messages, template, types: t }) {
|
||||
}
|
||||
}
|
||||
`);
|
||||
/* eslint-enable max-len */
|
||||
|
||||
function _ForOfStatementArray(path) {
|
||||
const { node, scope } = path;
|
||||
@ -76,7 +76,8 @@ export default function ({ messages, template, types: t }) {
|
||||
left.declarations[0].init = iterationValue;
|
||||
loop.body.body.unshift(left);
|
||||
} else {
|
||||
loop.body.body.unshift(t.expressionStatement(t.assignmentExpression("=", left, iterationValue)));
|
||||
loop.body.body.unshift(t.expressionStatement(
|
||||
t.assignmentExpression("=", left, iterationValue)));
|
||||
}
|
||||
|
||||
if (path.parentPath.isLabeledStatement()) {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import { basename, extname } from "path";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
@ -43,7 +41,8 @@ const buildExportAll = template(`
|
||||
});
|
||||
`);
|
||||
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", "ClassMethod", "ObjectMethod"];
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty",
|
||||
"ClassMethod", "ObjectMethod"];
|
||||
|
||||
export default function () {
|
||||
const REASSIGN_REMAP_SKIP = Symbol();
|
||||
@ -61,7 +60,8 @@ export default function () {
|
||||
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), remap]));
|
||||
} else if (path.isJSXIdentifier() && t.isMemberExpression(remap)) {
|
||||
const { object, property } = remap;
|
||||
path.replaceWith(t.JSXMemberExpression(t.JSXIdentifier(object.name), t.JSXIdentifier(property.name)));
|
||||
path.replaceWith(t.JSXMemberExpression(t.JSXIdentifier(object.name),
|
||||
t.JSXIdentifier(property.name)));
|
||||
} else {
|
||||
path.replaceWith(remap);
|
||||
}
|
||||
@ -327,9 +327,15 @@ export default function () {
|
||||
// todo
|
||||
} else if (specifier.isExportSpecifier()) {
|
||||
if (specifier.node.local.name === "default") {
|
||||
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(t.callExpression(this.addHelper("interopRequireDefault"), [ref]), specifier.node.local)));
|
||||
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name),
|
||||
t.memberExpression(
|
||||
t.callExpression(this.addHelper("interopRequireDefault"), [ref]),
|
||||
specifier.node.local
|
||||
)
|
||||
));
|
||||
} else {
|
||||
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(ref, specifier.node.local)));
|
||||
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name),
|
||||
t.memberExpression(ref, specifier.node.local)));
|
||||
}
|
||||
nonHoistedExportNames[specifier.node.exported.name] = true;
|
||||
}
|
||||
@ -414,7 +420,8 @@ export default function () {
|
||||
topNodes.push(varDecl);
|
||||
}
|
||||
}
|
||||
remaps[specifier.local.name] = t.memberExpression(target, t.cloneWithoutLoc(specifier.imported));
|
||||
remaps[specifier.local.name] = t.memberExpression(target,
|
||||
t.cloneWithoutLoc(specifier.imported));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -431,13 +438,20 @@ export default function () {
|
||||
const maxHoistedExportsNodeAssignmentLength = 100;
|
||||
const nonHoistedExportNamesArr = Object.keys(nonHoistedExportNames);
|
||||
|
||||
for (let currentExportsNodeAssignmentLength = 0; currentExportsNodeAssignmentLength < nonHoistedExportNamesArr.length; currentExportsNodeAssignmentLength += maxHoistedExportsNodeAssignmentLength ) {
|
||||
const nonHoistedExportNamesChunk = nonHoistedExportNamesArr.slice(currentExportsNodeAssignmentLength, currentExportsNodeAssignmentLength + maxHoistedExportsNodeAssignmentLength);
|
||||
for (
|
||||
let currentExportsNodeAssignmentLength = 0;
|
||||
currentExportsNodeAssignmentLength < nonHoistedExportNamesArr.length;
|
||||
currentExportsNodeAssignmentLength += maxHoistedExportsNodeAssignmentLength
|
||||
) {
|
||||
const nonHoistedExportNamesChunk = nonHoistedExportNamesArr.slice(
|
||||
currentExportsNodeAssignmentLength,
|
||||
currentExportsNodeAssignmentLength + maxHoistedExportsNodeAssignmentLength);
|
||||
|
||||
let hoistedExportsNode = t.identifier("undefined");
|
||||
|
||||
nonHoistedExportNamesChunk.forEach(function (name) {
|
||||
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression;
|
||||
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode)
|
||||
.expression;
|
||||
});
|
||||
|
||||
const node = t.expressionStatement(hoistedExportsNode);
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import hoistVariables from "babel-helper-hoist-variables";
|
||||
import template from "babel-template";
|
||||
|
||||
@ -76,7 +74,8 @@ export default function ({ types: t }) {
|
||||
CallExpression(path, state) {
|
||||
if (path.node.callee.type === TYPE_IMPORT) {
|
||||
const contextIdent = state.contextIdent;
|
||||
path.replaceWith(t.callExpression(t.memberExpression(contextIdent, t.identifier("import")), path.node.arguments));
|
||||
path.replaceWith(t.callExpression(t.memberExpression(contextIdent, t.identifier("import")),
|
||||
path.node.arguments));
|
||||
}
|
||||
},
|
||||
|
||||
@ -236,7 +235,8 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
if (t.isImportSpecifier(specifier)) {
|
||||
setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, t.memberExpression(target, specifier.imported))));
|
||||
setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local,
|
||||
t.memberExpression(target, specifier.imported))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +256,8 @@ export default function ({ types: t }) {
|
||||
}));
|
||||
} else if (t.isExportSpecifier(node)) {
|
||||
setterBody.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(exportObjRef, node.exported), t.memberExpression(target, node.local))
|
||||
t.assignmentExpression("=", t.memberExpression(exportObjRef, node.exported),
|
||||
t.memberExpression(target, node.local))
|
||||
));
|
||||
} else {
|
||||
// todo
|
||||
@ -279,7 +280,8 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
if (variableIds.length) {
|
||||
beforeBody.unshift(t.variableDeclaration("var", variableIds.map((id) => t.variableDeclarator(id))));
|
||||
beforeBody.unshift(t.variableDeclaration("var",
|
||||
variableIds.map((id) => t.variableDeclarator(id))));
|
||||
}
|
||||
|
||||
path.traverse(reassignmentVisitor, {
|
||||
@ -294,7 +296,8 @@ export default function ({ types: t }) {
|
||||
|
||||
path.node.body = [
|
||||
buildTemplate({
|
||||
SYSTEM_REGISTER: t.memberExpression(t.identifier(state.opts.systemGlobal || "System"), t.identifier("register")),
|
||||
SYSTEM_REGISTER: t.memberExpression(
|
||||
t.identifier(state.opts.systemGlobal || "System"), t.identifier("register")),
|
||||
BEFORE_BODY: beforeBody,
|
||||
MODULE_NAME: moduleName,
|
||||
SETTERS: setters,
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import { basename, extname } from "path";
|
||||
import template from "babel-template";
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import getFunctionArity from "babel-helper-get-function-arity";
|
||||
import callDelegate from "babel-helper-call-delegate";
|
||||
import template from "babel-template";
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint indent: 0 */
|
||||
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export default function ({ types: t }) {
|
||||
const IGNORE = Symbol();
|
||||
|
||||
@ -18,10 +16,17 @@ export default function ({ types: t }) {
|
||||
if (node[IGNORE]) return;
|
||||
if (path.find((path) => path.node && !!path.node._generated)) return;
|
||||
|
||||
if (path.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) {
|
||||
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols
|
||||
if (
|
||||
path.parentPath.isBinaryExpression() &&
|
||||
t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0
|
||||
) {
|
||||
// optimise `typeof foo === "string"` since we can determine that they'll never
|
||||
// need to handle symbols
|
||||
const opposite = path.getOpposite();
|
||||
if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") {
|
||||
if (
|
||||
opposite.isLiteral() && opposite.node.value !== "symbol" &&
|
||||
opposite.node.value !== "object"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,11 +94,14 @@ export default function ({ types: t }) {
|
||||
// to avoid calling foo() twice, as a first step convert it to:
|
||||
// const _foo = foo(),
|
||||
// { a, ...b } = _foo;
|
||||
const initRef = path.scope.generateUidIdentifierBasedOnNode(this.originalPath.node.init, "ref");
|
||||
const initRef = path.scope.generateUidIdentifierBasedOnNode(
|
||||
this.originalPath.node.init, "ref");
|
||||
// insert _foo = foo()
|
||||
this.originalPath.insertBefore(t.variableDeclarator(initRef, this.originalPath.node.init));
|
||||
this.originalPath.insertBefore(t.variableDeclarator(initRef,
|
||||
this.originalPath.node.init));
|
||||
// replace foo() with _foo
|
||||
this.originalPath.replaceWith(t.variableDeclarator(this.originalPath.node.id, initRef));
|
||||
this.originalPath.replaceWith(t.variableDeclarator(
|
||||
this.originalPath.node.id, initRef));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -247,7 +250,8 @@ export default function ({ types: t }) {
|
||||
|
||||
const useBuiltIns = file.opts.useBuiltIns || false;
|
||||
if (typeof useBuiltIns !== "boolean") {
|
||||
throw new Error("transform-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)");
|
||||
throw new Error("transform-object-rest-spread currently only accepts a boolean " +
|
||||
"option for useBuiltIns (defaults to false)");
|
||||
}
|
||||
|
||||
const args = [];
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import pull from "lodash/pull";
|
||||
|
||||
export default function ({ types: t }) {
|
||||
@ -9,7 +7,8 @@ export default function ({ types: t }) {
|
||||
|
||||
function isProtoAssignmentExpression(node) {
|
||||
const left = node.left;
|
||||
return t.isMemberExpression(left) && t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" });
|
||||
return t.isMemberExpression(left) &&
|
||||
t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" });
|
||||
}
|
||||
|
||||
function buildDefaultsCallExpression(expr, ref, file) {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import jsx from "babel-plugin-syntax-jsx";
|
||||
import helper from "babel-helper-builder-react-jsx";
|
||||
|
||||
@ -31,7 +29,8 @@ export default function ({ types: t }) {
|
||||
if (matches) {
|
||||
id = matches[1];
|
||||
if (id === "React.DOM") {
|
||||
throw file.buildCodeFrameError(comment, "The @jsx React.DOM pragma has been deprecated as of React 0.12");
|
||||
throw file.buildCodeFrameError(comment,
|
||||
"The @jsx React.DOM pragma has been deprecated as of React 0.12");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
if (global._babelPolyfill) {
|
||||
throw new Error("only one instance of babel-polyfill is allowed");
|
||||
}
|
||||
@ -24,6 +22,7 @@ function define(O, key, value) {
|
||||
define(String.prototype, "padLeft", "".padStart);
|
||||
define(String.prototype, "padRight", "".padEnd);
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(key) {
|
||||
[][key] && define(Array, key, Function.call.bind([][key]));
|
||||
});
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import assign from "lodash/assign";
|
||||
import has from "lodash/has";
|
||||
@ -15,7 +13,8 @@ export default function (code: string, opts?: Object): Function {
|
||||
// original stack to append if it errors when parsing
|
||||
let stack;
|
||||
try {
|
||||
// error stack gets populated in IE only on throw (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx)
|
||||
// error stack gets populated in IE only on throw
|
||||
// (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx)
|
||||
throw new Error();
|
||||
} catch (error) {
|
||||
if (error.stack) {
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import TraversalContext from "./context";
|
||||
import * as visitors from "./visitors";
|
||||
import * as messages from "babel-messages";
|
||||
@ -45,7 +43,14 @@ traverse.cheap = function (node, enter) {
|
||||
return t.traverseFast(node, enter);
|
||||
};
|
||||
|
||||
traverse.node = function (node: Object, opts: Object, scope: Object, state: Object, parentPath: Object, skipKeys?) {
|
||||
traverse.node = function (
|
||||
node: Object,
|
||||
opts: Object,
|
||||
scope: Object,
|
||||
state: Object,
|
||||
parentPath: Object,
|
||||
skipKeys?
|
||||
) {
|
||||
const keys: Array = t.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
|
||||
@ -74,7 +79,12 @@ function hasBlacklistedType(path, state) {
|
||||
}
|
||||
}
|
||||
|
||||
traverse.hasType = function (tree: Object, scope: Object, type: Object, blacklistTypes: Array<string>): boolean {
|
||||
traverse.hasType = function (
|
||||
tree: Object,
|
||||
scope: Object,
|
||||
type: Object,
|
||||
blacklistTypes: Array<string>
|
||||
): boolean {
|
||||
// the node we're searching in is blacklisted
|
||||
if (includes(blacklistTypes, tree.type)) return false;
|
||||
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
/* eslint indent: 0 */
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import type NodePath from "./index";
|
||||
|
||||
// This file contains Babels metainterpreter that can evaluate static code.
|
||||
|
||||
/* eslint eqeqeq: 0 */
|
||||
|
||||
const VALID_CALLEES = ["String", "Number", "Math"];
|
||||
const INVALID_METHODS = ["random"];
|
||||
|
||||
@ -316,7 +311,7 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
case ">": return left > right;
|
||||
case "<=": return left <= right;
|
||||
case ">=": return left >= right;
|
||||
case "==": return left == right;
|
||||
case "==": return left == right; // eslint-disable-line eqeqeq
|
||||
case "!=": return left != right;
|
||||
case "===": return left === right;
|
||||
case "!==": return left !== right;
|
||||
@ -335,7 +330,10 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
let func;
|
||||
|
||||
// Number(1);
|
||||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
|
||||
if (
|
||||
callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) &&
|
||||
VALID_CALLEES.indexOf(callee.node.name) >= 0
|
||||
) {
|
||||
func = global[node.callee.name];
|
||||
}
|
||||
|
||||
@ -344,7 +342,11 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
const property = callee.get("property");
|
||||
|
||||
// Math.min(1, 2)
|
||||
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
|
||||
if (
|
||||
object.isIdentifier() && property.isIdentifier() &&
|
||||
VALID_CALLEES.indexOf(object.node.name) >= 0 &&
|
||||
INVALID_METHODS.indexOf(property.node.name) < 0
|
||||
) {
|
||||
context = global[object.node.name];
|
||||
func = context[property.node.name];
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import type Hub from "../hub";
|
||||
import type TraversalContext from "../context";
|
||||
import * as virtualTypes from "./lib/virtual-types";
|
||||
|
||||
@ -153,7 +153,8 @@ export default class PathHoister {
|
||||
const attachTo = this.getAttachmentPath();
|
||||
if (!attachTo) return;
|
||||
|
||||
// don't bother hoisting to the same function as this will cause multiple branches to be evaluated more than once leading to a bad optimisation
|
||||
// don't bother hoisting to the same function as this will cause multiple branches to be
|
||||
// evaluated more than once leading to a bad optimisation
|
||||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
||||
|
||||
// generate declaration and insert it to our point
|
||||
|
||||
@ -6,28 +6,29 @@
|
||||
|
||||
export const hooks = [
|
||||
function (self, parent) {
|
||||
let removeParent = false;
|
||||
|
||||
const removeParent =
|
||||
// while (NODE);
|
||||
// removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true`
|
||||
// unlikely that the latter will ever be what's wanted so we just remove the loop to avoid infinite recursion
|
||||
removeParent = removeParent || (self.key === "test" && (parent.isWhile() || parent.isSwitchCase()));
|
||||
// removing the test of a while/switch, we can either just remove it entirely *or* turn the
|
||||
// `test` into `true` unlikely that the latter will ever be what's wanted so we just remove
|
||||
// the loop to avoid infinite recursion
|
||||
(self.key === "test" && (parent.isWhile() || parent.isSwitchCase())) ||
|
||||
|
||||
// export NODE;
|
||||
// just remove a declaration for an export as this is no longer valid
|
||||
removeParent = removeParent || (self.key === "declaration" && parent.isExportDeclaration());
|
||||
(self.key === "declaration" && parent.isExportDeclaration()) ||
|
||||
|
||||
// label: NODE
|
||||
// stray labeled statement with no body
|
||||
removeParent = removeParent || (self.key === "body" && parent.isLabeledStatement());
|
||||
(self.key === "body" && parent.isLabeledStatement()) ||
|
||||
|
||||
// let NODE;
|
||||
// remove an entire declaration if there are no declarators left
|
||||
removeParent = removeParent || (self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1);
|
||||
(self.listKey === "declarations" && parent.isVariableDeclaration() &&
|
||||
parent.node.declarations.length === 1) ||
|
||||
|
||||
// NODE;
|
||||
// remove the entire expression statement if there's no expression
|
||||
removeParent = removeParent || (self.key === "expression" && parent.isExpressionStatement());
|
||||
(self.key === "expression" && parent.isExpressionStatement());
|
||||
|
||||
if (removeParent) {
|
||||
parent.remove();
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
// This file contains methods that modify the path/node in some ways.
|
||||
|
||||
import { path as pathCache } from "../cache";
|
||||
@ -17,7 +16,10 @@ export function insertBefore(nodes) {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertBefore(nodes);
|
||||
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
} else if (
|
||||
this.isNodeType("Expression") ||
|
||||
(this.parentPath.isForStatement() && this.key === "init")
|
||||
) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else {
|
||||
@ -28,7 +30,8 @@ export function insertBefore(nodes) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this._replaceWith(t.blockStatement(nodes));
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
throw new Error("We don't know what to do with this node type. " +
|
||||
"We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +91,8 @@ export function _containerInsertAfter(nodes) {
|
||||
|
||||
export function _maybePopFromStatements(nodes) {
|
||||
const last = nodes[nodes.length - 1];
|
||||
const isIdentifier = t.isIdentifier(last) || (t.isExpressionStatement(last) && t.isIdentifier(last.expression));
|
||||
const isIdentifier = t.isIdentifier(last) ||
|
||||
(t.isExpressionStatement(last) && t.isIdentifier(last.expression));
|
||||
|
||||
if (isIdentifier && !this.isCompletionRecord()) {
|
||||
nodes.pop();
|
||||
@ -107,7 +111,10 @@ export function insertAfter(nodes) {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertAfter(nodes);
|
||||
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
} else if (
|
||||
this.isNodeType("Expression") ||
|
||||
(this.parentPath.isForStatement() && this.key === "init")
|
||||
) {
|
||||
if (this.node) {
|
||||
const temp = this.scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||
@ -122,7 +129,8 @@ export function insertAfter(nodes) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this._replaceWith(t.blockStatement(nodes));
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
throw new Error("We don't know what to do with this node type. " +
|
||||
"We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
// This file contains methods responsible for replacing a node with another.
|
||||
|
||||
import codeFrame from "babel-code-frame";
|
||||
@ -114,22 +113,30 @@ export function replaceWith(replacement) {
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
||||
throw new Error(
|
||||
"Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
||||
}
|
||||
|
||||
if (typeof replacement === "string") {
|
||||
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
||||
throw new Error(
|
||||
"Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
||||
}
|
||||
|
||||
if (this.isNodeType("Statement") && t.isExpression(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
||||
if (
|
||||
!this.canHaveVariableDeclarationOrExpression() &&
|
||||
!this.canSwapBetweenExpressionAndStatement(replacement)
|
||||
) {
|
||||
// replacing a statement with an expression so wrap it in an expression statement
|
||||
replacement = t.expressionStatement(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isNodeType("Expression") && t.isStatement(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
||||
if (
|
||||
!this.canHaveVariableDeclarationOrExpression() &&
|
||||
!this.canSwapBetweenExpressionAndStatement(replacement)
|
||||
) {
|
||||
// replacing an expression with a statement so let's explode it
|
||||
return this.replaceExpressionWithStatements([replacement]);
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
import includes from "lodash/includes";
|
||||
import repeat from "lodash/repeat";
|
||||
import Renamer from "./lib/renamer";
|
||||
@ -341,13 +339,11 @@ export default class Scope {
|
||||
// ignore hoisted functions if there's also a local let
|
||||
if (kind === "hoisted" && local.kind === "let") return;
|
||||
|
||||
let duplicate = false;
|
||||
|
||||
const duplicate =
|
||||
// don't allow duplicate bindings to exist alongside
|
||||
if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module";
|
||||
|
||||
kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" ||
|
||||
// don't allow a local of param with a kind of let
|
||||
if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");
|
||||
local.kind === "param" && (kind === "let" || kind === "const");
|
||||
|
||||
if (duplicate) {
|
||||
throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
|
||||
|
||||
@ -33,7 +33,8 @@ describe("evaluation", function () {
|
||||
|
||||
it("should bail out on recursive evaluation", function () {
|
||||
assert.strictEqual(
|
||||
getPath("function fn(a) { var g = a ? 1 : 2, a = g * this.foo; }").get("body.0.body.body.0.declarations.1.init").evaluate().confident,
|
||||
getPath("function fn(a) { var g = a ? 1 : 2, a = g * this.foo; }")
|
||||
.get("body.0.body.body.0.declarations.1.init").evaluate().confident,
|
||||
false
|
||||
);
|
||||
});
|
||||
@ -54,7 +55,8 @@ describe("evaluation", function () {
|
||||
|
||||
it("should deopt when var is redeclared in the same scope", function () {
|
||||
assert.strictEqual(
|
||||
getPath("var x = 2; var y = x + 2; { var x = 3 }").get("body.1.declarations.0.init").evaluate().confident,
|
||||
getPath("var x = 2; var y = x + 2; { var x = 3 }")
|
||||
.get("body.1.declarations.0.init").evaluate().confident,
|
||||
false
|
||||
);
|
||||
});
|
||||
@ -73,7 +75,8 @@ describe("evaluation", function () {
|
||||
|
||||
it("it should not deopt let/const inside blocks", function () {
|
||||
assert.strictEqual(
|
||||
getPath("let x = 5; { let x = 1; } let y = x + 5").get("body.2.declarations.0.init").evaluate().value,
|
||||
getPath("let x = 5; { let x = 1; } let y = x + 5")
|
||||
.get("body.2.declarations.0.init").evaluate().value,
|
||||
10
|
||||
);
|
||||
const constExample = "const d = true; if (d && true || false) { const d = false; d && 5; }";
|
||||
|
||||
@ -36,7 +36,8 @@ describe("inference", function () {
|
||||
});
|
||||
|
||||
it("it should bail when type changes", function () {
|
||||
const path = getPath("var x = 1; if (foo) x = null;else x = 3; x === 2").get("body")[2].get("expression");
|
||||
const path = getPath("var x = 1; if (foo) x = null;else x = 3; x === 2")
|
||||
.get("body")[2].get("expression");
|
||||
const left = path.get("left");
|
||||
const right = path.get("right");
|
||||
|
||||
@ -144,7 +145,8 @@ describe("inference", function () {
|
||||
it("should infer call return type using async generator function", function () {
|
||||
const path = getPath("(async function * (): string {})()").get("body")[0].get("expression");
|
||||
const type = path.getTypeAnnotation();
|
||||
assert.ok(t.isGenericTypeAnnotation(type) && type.id.name === "AsyncIterator", "should be AsyncIterator");
|
||||
assert.ok(t.isGenericTypeAnnotation(type) && type.id.name === "AsyncIterator",
|
||||
"should be AsyncIterator");
|
||||
});
|
||||
it("should infer number from x/y", function () {
|
||||
const path = getPath("x/y").get("body")[0].get("expression");
|
||||
|
||||
@ -17,22 +17,29 @@ function getPath(code) {
|
||||
describe("scope", function () {
|
||||
describe("binding paths", function () {
|
||||
it("function declaration id", function () {
|
||||
assert.ok(getPath("function foo() {}").scope.getBinding("foo").path.type === "FunctionDeclaration");
|
||||
assert.ok(getPath("function foo() {}")
|
||||
.scope.getBinding("foo").path.type === "FunctionDeclaration");
|
||||
});
|
||||
|
||||
it("function expression id", function () {
|
||||
assert.ok(getPath("(function foo() {})").get("body")[0].get("expression").scope.getBinding("foo").path.type === "FunctionExpression");
|
||||
assert.ok(getPath("(function foo() {})").get("body")[0].get("expression")
|
||||
.scope.getBinding("foo").path.type === "FunctionExpression");
|
||||
});
|
||||
|
||||
it("function param", function () {
|
||||
assert.ok(getPath("(function (foo) {})").get("body")[0].get("expression").scope.getBinding("foo").path.type === "Identifier");
|
||||
assert.ok(getPath("(function (foo) {})").get("body")[0].get("expression")
|
||||
.scope.getBinding("foo").path.type === "Identifier");
|
||||
});
|
||||
|
||||
it("variable declaration", function () {
|
||||
assert.ok(getPath("var foo = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var { foo } = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var [ foo ] = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var { bar: [ foo ] } = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var foo = null;")
|
||||
.scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var { foo } = null;")
|
||||
.scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var [ foo ] = null;")
|
||||
.scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
assert.ok(getPath("var { bar: [ foo ] } = null;")
|
||||
.scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||
});
|
||||
|
||||
it("purity", function () {
|
||||
|
||||
@ -31,7 +31,8 @@ describe("traverse", function () {
|
||||
it("traverse", function () {
|
||||
const expect = [
|
||||
body[0], body[0].declarations[0], body[0].declarations[0].id, body[0].declarations[0].init,
|
||||
body[1], body[1].expression, body[1].expression.left, body[1].expression.left.object, body[1].expression.left.property, body[1].expression.right
|
||||
body[1], body[1].expression, body[1].expression.left, body[1].expression.left.object,
|
||||
body[1].expression.left.property, body[1].expression.right
|
||||
];
|
||||
|
||||
const actual = [];
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
export const STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
|
||||
export const FLATTENABLE_KEYS = ["body", "expressions"];
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
import * as t from "../index";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint max-len: "off" */
|
||||
|
||||
import defineType, {
|
||||
assertNodeType,
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint indent: 0 */
|
||||
|
||||
import { getBindingIdentifiers } from "./retrievers";
|
||||
import esutils from "esutils";
|
||||
import * as t from "./index";
|
||||
|
||||
@ -25,7 +25,8 @@ describe("converters", function () {
|
||||
assert.deepEqual(t.valueToNode(/abc.+/gm), t.regExpLiteral("abc.+", "gm"));
|
||||
});
|
||||
it("array", function () {
|
||||
assert.deepEqual(t.valueToNode([1, "a"]), t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]));
|
||||
assert.deepEqual(t.valueToNode([1, "a"]),
|
||||
t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]));
|
||||
});
|
||||
it("object", function () {
|
||||
assert.deepEqual(t.valueToNode({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user