Re-enable the max-len ESLint rule. (#5265)
This commit is contained in:
parent
4d411ef83e
commit
b845f2b69d
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "babel",
|
"extends": "babel",
|
||||||
"rules": {
|
"rules": {
|
||||||
"max-len": 0
|
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ node_modules
|
|||||||
test/tmp
|
test/tmp
|
||||||
*.log
|
*.log
|
||||||
*.cache
|
*.cache
|
||||||
|
/.eslintcache
|
||||||
/templates.json
|
/templates.json
|
||||||
/tests.json
|
/tests.json
|
||||||
/browser.js
|
/browser.js
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"settings": {
|
"settings": {
|
||||||
"rulers": [
|
"rulers": [
|
||||||
100
|
110
|
||||||
],
|
],
|
||||||
|
|
||||||
// Set to false to disable detection of tabs vs. spaces on load
|
// 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
|
* This tiny wrapper file checks for known node flags and appends them
|
||||||
* when found, before invoking the "real" _babel-node(1) executable.
|
* when found, before invoking the "real" _babel-node(1) executable.
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
require("babel-core");
|
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const commander = require("commander");
|
const commander = require("commander");
|
||||||
@ -38,6 +35,7 @@ Object.keys(options).forEach(function (key) {
|
|||||||
commander.option(arg, desc.join(" "));
|
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("-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("-w, --watch", "Recompile files on changes");
|
||||||
commander.option("--skip-initial-build", "Do not compile files before watching");
|
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, --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("-D, --copy-files", "When compiling a directory copy over non-compilable files");
|
||||||
commander.option("-q, --quiet", "Don't log anything");
|
commander.option("-q, --quiet", "Don't log anything");
|
||||||
|
/* eslint-enable max-len */
|
||||||
|
|
||||||
const pkg = require("../../package.json");
|
const pkg = require("../../package.json");
|
||||||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
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.stderr) {
|
||||||
if (opts.stderrContains) {
|
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 {
|
} else {
|
||||||
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
|
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.stdout) {
|
||||||
if (opts.stdoutContains) {
|
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 {
|
} else {
|
||||||
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,10 +197,12 @@ describe("babel-code-frame", function () {
|
|||||||
"",
|
"",
|
||||||
""
|
""
|
||||||
].join("\n");
|
].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 | "),
|
" " + gutter(" 2 | "),
|
||||||
marker(">") + gutter(" 3 | "),
|
marker(">") + gutter(" 3 | "),
|
||||||
" " + gutter(" 4 | ")
|
" " + gutter(" 4 | ")
|
||||||
].join("\n")));
|
].join("\n"))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import * as helpers from "babel-helpers";
|
import * as helpers from "babel-helpers";
|
||||||
import generator from "babel-generator";
|
import generator from "babel-generator";
|
||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
@ -23,12 +21,14 @@ const buildUmdWrapper = template(`
|
|||||||
function buildGlobal(namespace, builder) {
|
function buildGlobal(namespace, builder) {
|
||||||
const body = [];
|
const body = [];
|
||||||
const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(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", [
|
body.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(
|
t.variableDeclarator(
|
||||||
namespace,
|
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 */
|
/* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
|
||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import getHelper from "babel-helpers";
|
import getHelper from "babel-helpers";
|
||||||
import * as metadataVisitor from "./metadata";
|
import * as metadataVisitor from "./metadata";
|
||||||
@ -378,8 +377,8 @@ export default class File extends Store {
|
|||||||
sourceRoot: inputMapConsumer.sourceRoot
|
sourceRoot: inputMapConsumer.sourceRoot
|
||||||
});
|
});
|
||||||
|
|
||||||
// This assumes the output map always has a single source, since Babel always compiles a single source file to a
|
// This assumes the output map always has a single source, since Babel always compiles a
|
||||||
// single output file.
|
// single source file to a single output file.
|
||||||
const source = outputMapConsumer.sources[0];
|
const source = outputMapConsumer.sources[0];
|
||||||
|
|
||||||
inputMapConsumer.eachMapping(function (mapping) {
|
inputMapConsumer.eachMapping(function (mapping) {
|
||||||
@ -424,7 +423,8 @@ export default class File extends Store {
|
|||||||
if (parser) {
|
if (parser) {
|
||||||
parseCode = require(parser).parse;
|
parseCode = require(parser).parse;
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
parseCode = parserOpts.parser;
|
parseCode = parserOpts.parser;
|
||||||
@ -472,7 +472,8 @@ export default class File extends Store {
|
|||||||
this.log.debug("Start transform traverse");
|
this.log.debug("Start transform traverse");
|
||||||
|
|
||||||
// merge all plugin visitors into a single visitor
|
// 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);
|
traverse(this.ast, visitor, this.scope);
|
||||||
|
|
||||||
this.log.debug("End transform traverse");
|
this.log.debug("End transform traverse");
|
||||||
@ -610,14 +611,16 @@ export default class File extends Store {
|
|||||||
if (generator) {
|
if (generator) {
|
||||||
gen = require(generator).print;
|
gen = require(generator).print;
|
||||||
} else {
|
} 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");
|
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.code = _result.code;
|
||||||
result.map = _result.map;
|
result.map = _result.map;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
filename: {
|
filename: {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import * as context from "../../../api/node";
|
import * as context from "../../../api/node";
|
||||||
import type Logger from "../logger";
|
import type Logger from "../logger";
|
||||||
import Plugin from "../../plugin";
|
import Plugin from "../../plugin";
|
||||||
@ -180,10 +178,13 @@ export default class OptionManager {
|
|||||||
// check for an unknown option
|
// check for an unknown option
|
||||||
if (!option && this.log) {
|
if (!option && this.log) {
|
||||||
if (removed[key]) {
|
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 {
|
} 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 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.";
|
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);
|
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"auxiliaryComment": {
|
"auxiliaryComment": {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import OptionManager from "./file/options/option-manager";
|
import OptionManager from "./file/options/option-manager";
|
||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
import Store from "../store";
|
import Store from "../store";
|
||||||
@ -85,7 +83,8 @@ export default class Plugin extends Store {
|
|||||||
normaliseVisitor(visitor: Object): Object {
|
normaliseVisitor(visitor: Object): Object {
|
||||||
for (const key of GLOBAL_VISITOR_PROPS) {
|
for (const key of GLOBAL_VISITOR_PROPS) {
|
||||||
if (visitor[key]) {
|
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 () {
|
it("source map merging", function () {
|
||||||
const result = babel.transform([
|
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\"); } }",
|
"function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }",
|
||||||
"",
|
"",
|
||||||
"let Foo = function Foo() {",
|
"let Foo = function Foo() {",
|
||||||
@ -272,6 +273,7 @@ describe("api", function () {
|
|||||||
"};",
|
"};",
|
||||||
"",
|
"",
|
||||||
"//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0="
|
"//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0="
|
||||||
|
/* eslint-enable max-len */
|
||||||
].join("\n"), {
|
].join("\n"), {
|
||||||
sourceMap: true
|
sourceMap: true
|
||||||
});
|
});
|
||||||
@ -329,12 +331,14 @@ describe("api", function () {
|
|||||||
};
|
};
|
||||||
}]
|
}]
|
||||||
}).then(function (result) {
|
}).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 () {
|
it("modules metadata", function () {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
transformAsync("import { externalName as localName } from \"external\";").then(function (result) {
|
transformAsync("import { externalName as localName } from \"external\";").then(function (result) {
|
||||||
assert.deepEqual(result.metadata.modules.imports[0], {
|
assert.deepEqual(result.metadata.modules.imports[0], {
|
||||||
source: "external",
|
source: "external",
|
||||||
@ -586,8 +590,10 @@ describe("api", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("resolveModuleSource option", 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 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\";";
|
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, {
|
return transformAsync(actual, {
|
||||||
resolveModuleSource: function (originalSource) {
|
resolveModuleSource: function (originalSource) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ describe("option-manager", () => {
|
|||||||
"blacklist": true
|
"blacklist": true
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
/Using removed Babel 5 option: base.auxiliaryComment - Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`/
|
/Using removed Babel 5 option: base.auxiliaryComment - Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -59,6 +60,7 @@ describe("option-manager", () => {
|
|||||||
"presets": [{ option: "value" }]
|
"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/
|
/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 t from "babel-types";
|
||||||
import * as n from "../node";
|
import * as n from "../node";
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
export function AnyTypeAnnotation() {
|
export function AnyTypeAnnotation() {
|
||||||
this.word("any");
|
this.word("any");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,5 +93,6 @@ export function ArrowFunctionExpression(node: Object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hasTypes(node, param) {
|
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 * as t from "babel-types";
|
||||||
import jsesc from "jsesc";
|
import jsesc from "jsesc";
|
||||||
|
|
||||||
@ -62,7 +59,8 @@ export function ObjectProperty(node: Object) {
|
|||||||
this.token("]");
|
this.token("]");
|
||||||
} else {
|
} else {
|
||||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
// 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);
|
this.print(node.value, node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import find from "lodash/find";
|
import find from "lodash/find";
|
||||||
import findLast from "lodash/findLast";
|
import findLast from "lodash/findLast";
|
||||||
import isInteger from "lodash/isInteger";
|
import isInteger from "lodash/isInteger";
|
||||||
@ -321,6 +319,7 @@ export default class Printer {
|
|||||||
|
|
||||||
const printMethod = this[node.type];
|
const printMethod = this[node.type];
|
||||||
if (!printMethod) {
|
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)}`);
|
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);
|
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}`);
|
console.log(`New test file created: ${expect.loc}`);
|
||||||
fs.writeFileSync(expect.loc, result.code);
|
fs.writeFileSync(expect.loc, result.code);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -128,7 +128,8 @@ export default function (opts) {
|
|||||||
|
|
||||||
const useBuiltIns = file.opts.useBuiltIns || false;
|
const useBuiltIns = file.opts.useBuiltIns || false;
|
||||||
if (typeof useBuiltIns !== "boolean") {
|
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() {
|
function pushProps() {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import nameFunction from "babel-helper-function-name";
|
import nameFunction from "babel-helper-function-name";
|
||||||
import has from "lodash/has";
|
import has from "lodash/has";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
@ -36,7 +34,8 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
|||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
const decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
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) {
|
if (map.value || map.initializer) {
|
||||||
@ -63,7 +62,8 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
|||||||
}
|
}
|
||||||
|
|
||||||
// infer function name
|
// 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 });
|
value = nameFunction({ id: key, node: value, scope });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import getFunctionArity from "babel-helper-get-function-arity";
|
import getFunctionArity from "babel-helper-get-function-arity";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
import * as t from "babel-types";
|
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
|
// has an `id` so we don't need to infer one
|
||||||
if (node.id) return;
|
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() {} };
|
// { foo() {} };
|
||||||
id = parent.key;
|
id = parent.key;
|
||||||
} else if (t.isVariableDeclarator(parent)) {
|
} else if (t.isVariableDeclarator(parent)) {
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (callee, thisNode, args) {
|
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);
|
// eg. super(...arguments);
|
||||||
return t.callExpression(
|
return t.callExpression(
|
||||||
t.memberExpression(callee, t.identifier("apply")),
|
t.memberExpression(callee, t.identifier("apply")),
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import type { NodePath, Scope } from "babel-traverse";
|
import type { NodePath, Scope } from "babel-traverse";
|
||||||
import optimiseCall from "babel-helper-optimise-call-expression";
|
import optimiseCall from "babel-helper-optimise-call-expression";
|
||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
@ -144,7 +142,8 @@ export default class ReplaceSupers {
|
|||||||
*
|
*
|
||||||
* @example
|
* @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.variableDeclaration("var", [
|
||||||
t.variableDeclarator(ref, node.left)
|
t.variableDeclarator(ref, node.left)
|
||||||
]),
|
]),
|
||||||
t.expressionStatement(
|
t.expressionStatement(t.assignmentExpression("=", node.left,
|
||||||
t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right))
|
t.binaryExpression(node.operator[0], ref, node.right)))
|
||||||
)
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,22 +249,30 @@ export default class ReplaceSupers {
|
|||||||
if (t.isSuper(callee)) {
|
if (t.isSuper(callee)) {
|
||||||
return;
|
return;
|
||||||
} else if (isMemberExpressionSuper(callee)) {
|
} 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;
|
property = callee.property;
|
||||||
computed = callee.computed;
|
computed = callee.computed;
|
||||||
args = node.arguments;
|
args = node.arguments;
|
||||||
}
|
}
|
||||||
} else if (t.isMemberExpression(node) && t.isSuper(node.object)) {
|
} 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;
|
property = node.property;
|
||||||
computed = node.computed;
|
computed = node.computed;
|
||||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
||||||
const binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1));
|
const binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1));
|
||||||
if (node.prefix) {
|
if (node.prefix) {
|
||||||
// ++super.foo; -> super.foo += 1;
|
// ++super.foo;
|
||||||
|
// to
|
||||||
|
// super.foo += 1;
|
||||||
return this.specHandleAssignmentExpression(null, path, binary);
|
return this.specHandleAssignmentExpression(null, path, binary);
|
||||||
} else {
|
} 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");
|
const ref = path.scope.generateUidIdentifier("ref");
|
||||||
return this.specHandleAssignmentExpression(ref, path, binary).concat(t.expressionStatement(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 (val[0][0] === ".") {
|
||||||
|
|
||||||
if (!optionsDir) {
|
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]);
|
val[0] = path.resolve(optionsDir, val[0]);
|
||||||
@ -53,7 +54,8 @@ function run(task) {
|
|||||||
newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins, optionsDir);
|
newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins, optionsDir);
|
||||||
newOpts.presets = wrapPackagesArray("preset", newOpts.presets, optionsDir).map(function (val) {
|
newOpts.presets = wrapPackagesArray("preset", newOpts.presets, optionsDir).map(function (val) {
|
||||||
if (val.length > 2) {
|
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;
|
return val;
|
||||||
@ -85,7 +87,10 @@ function run(task) {
|
|||||||
const expectCode = expect.code;
|
const expectCode = expect.code;
|
||||||
if (!execCode || actualCode) {
|
if (!execCode || actualCode) {
|
||||||
result = babel.transform(actualCode, getOpts(actual));
|
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}`);
|
console.log(`New test file created: ${expect.loc}`);
|
||||||
fs.writeFileSync(expect.loc, result.code);
|
fs.writeFileSync(expect.loc, result.code);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint no-confusing-arrow: 0 */
|
|
||||||
|
|
||||||
import helpers from "./helpers";
|
import helpers from "./helpers";
|
||||||
|
|
||||||
export function get(name) {
|
export function get(name) {
|
||||||
@ -10,7 +8,7 @@ export function get(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const list = Object.keys(helpers)
|
export const list = Object.keys(helpers)
|
||||||
.map((name) => name[0] === "_" ? name.slice(1) : name)
|
.map((name) => name.replace(/^_/, ""))
|
||||||
.filter((name) => name !== "__esModule");
|
.filter((name) => name !== "__esModule");
|
||||||
|
|
||||||
export default get;
|
export default get;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
import * as util from "util";
|
import * as util from "util";
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
import nameFunction from "babel-helper-function-name";
|
import nameFunction from "babel-helper-function-name";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
|
|
||||||
@ -44,7 +43,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
visitor: {
|
visitor: {
|
||||||
Class(path, state) {
|
Class(path, state) {
|
||||||
const buildClassProperty = state.opts.spec ? buildClassPropertySpec : buildClassPropertyNonSpec;
|
const buildClassProperty = state.opts.spec ? buildClassPropertySpec :
|
||||||
|
buildClassPropertyNonSpec;
|
||||||
const isDerived = !!path.node.superClass;
|
const isDerived = !!path.node.superClass;
|
||||||
let constructor;
|
let constructor;
|
||||||
const props = [];
|
const props = [];
|
||||||
@ -92,7 +92,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
if (instanceBody.length) {
|
if (instanceBody.length) {
|
||||||
if (!constructor) {
|
if (!constructor) {
|
||||||
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([]));
|
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [],
|
||||||
|
t.blockStatement([]));
|
||||||
if (isDerived) {
|
if (isDerived) {
|
||||||
newConstructor.params = [t.restElement(t.identifier("args"))];
|
newConstructor.params = [t.restElement(t.identifier("args"))];
|
||||||
newConstructor.body.body.push(
|
newConstructor.body.body.push(
|
||||||
@ -129,7 +130,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
instanceBody = [
|
instanceBody = [
|
||||||
t.expressionStatement(
|
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 NodePath from "babel-traverse";
|
||||||
import type Scope from "babel-traverse";
|
import type Scope from "babel-traverse";
|
||||||
import type File from "../../../file";
|
import type File from "../../../file";
|
||||||
@ -397,7 +395,8 @@ class BlockScoping {
|
|||||||
const isSwitch = this.blockPath.isSwitchStatement();
|
const isSwitch = this.blockPath.isSwitchStatement();
|
||||||
|
|
||||||
// build the closure that we're going to wrap the block with, possible wrapping switch(){}
|
// 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;
|
fn.shadow = true;
|
||||||
|
|
||||||
// continuation
|
// continuation
|
||||||
@ -654,7 +653,8 @@ class BlockScoping {
|
|||||||
for (let i = 0; i < cases.length; i++) {
|
for (let i = 0; i < cases.length; i++) {
|
||||||
const caseConsequent = cases[i].consequent[0];
|
const caseConsequent = cases[i].consequent[0];
|
||||||
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
|
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 type { NodePath } from "babel-traverse";
|
||||||
import { visitors } from "babel-traverse";
|
import { visitors } from "babel-traverse";
|
||||||
import ReplaceSupers from "babel-helper-replace-supers";
|
import ReplaceSupers from "babel-helper-replace-supers";
|
||||||
@ -28,7 +26,10 @@ const noMethodVisitor = {
|
|||||||
|
|
||||||
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
||||||
Super(path) {
|
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()");
|
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -88,7 +89,8 @@ export default class ClassTransformer {
|
|||||||
this.classId = this.node.id;
|
this.classId = this.node.id;
|
||||||
|
|
||||||
// this is the name of the binding that will **always** reference the class we've constructed
|
// 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.superName = this.node.superClass || t.identifier("Function");
|
||||||
this.isDerived = !!this.node.superClass;
|
this.isDerived = !!this.node.superClass;
|
||||||
@ -123,10 +125,12 @@ export default class ClassTransformer {
|
|||||||
this.buildBody();
|
this.buildBody();
|
||||||
|
|
||||||
// make sure this class isn't directly called
|
// 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(),
|
t.thisExpression(),
|
||||||
this.classRef
|
this.classRef
|
||||||
])));
|
]
|
||||||
|
)));
|
||||||
|
|
||||||
body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef)));
|
body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef)));
|
||||||
|
|
||||||
@ -227,7 +231,8 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.decorators) {
|
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)) {
|
if (t.isClassMethod(node)) {
|
||||||
@ -294,8 +299,13 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
const nullNode = t.nullLiteral();
|
const nullNode = t.nullLiteral();
|
||||||
|
|
||||||
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers)
|
let args = [
|
||||||
let args = [this.classRef, nullNode, nullNode, nullNode, nullNode];
|
this.classRef, // Constructor
|
||||||
|
nullNode, // instanceDescriptors
|
||||||
|
nullNode, // staticDescriptors
|
||||||
|
nullNode, // instanceInitializers
|
||||||
|
nullNode, // staticInitializers
|
||||||
|
];
|
||||||
|
|
||||||
if (instanceProps) args[1] = instanceProps;
|
if (instanceProps) args[1] = instanceProps;
|
||||||
if (staticProps) args[2] = staticProps;
|
if (staticProps) args[2] = staticProps;
|
||||||
@ -336,7 +346,11 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
if (this.isLoose) {
|
if (this.isLoose) {
|
||||||
bareSuperNode.arguments.unshift(t.thisExpression());
|
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
|
// special case single arguments spread
|
||||||
bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument;
|
bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument;
|
||||||
bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply"));
|
bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply"));
|
||||||
@ -365,7 +379,11 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
const bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef));
|
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
|
// this super call is the last statement in the body so we can just straight up
|
||||||
// turn it into a return
|
// turn it into a return
|
||||||
|
|
||||||
@ -435,7 +453,8 @@ export default class ClassTransformer {
|
|||||||
// return
|
// return
|
||||||
const bodyPaths = body.get("body");
|
const bodyPaths = body.get("body");
|
||||||
if (bodyPaths.length && !bodyPaths.pop().isReturnStatement()) {
|
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) {
|
for (const returnPath of this.superReturns) {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
export default function ({ types: t }) {
|
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));
|
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +293,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
if (t.isRestElement(elem)) {
|
if (t.isRestElement(elem)) {
|
||||||
elemRef = this.toArray(arrayRef);
|
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
|
// set the element to the rest element argument since we've dealt with it
|
||||||
// being a rest already
|
// being a rest already
|
||||||
@ -485,14 +485,18 @@ export default function ({ types: t }) {
|
|||||||
t.inherits(nodes[nodes.length - 1], declar);
|
t.inherits(nodes[nodes.length - 1], declar);
|
||||||
}
|
}
|
||||||
} else {
|
} 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 = [];
|
const nodesOut = [];
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
const tail = nodesOut[nodesOut.length - 1];
|
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.
|
// Create a single compound let/var rather than many.
|
||||||
tail.declarations.push(...node.declarations);
|
tail.declarations.push(...node.declarations);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
export default function ({ messages, template, types: t }) {
|
export default function ({ messages, template, types: t }) {
|
||||||
const buildForOfArray = template(`
|
const buildForOfArray = template(`
|
||||||
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;
|
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(`
|
const buildForOf = template(`
|
||||||
var ITERATOR_COMPLETION = true;
|
var ITERATOR_COMPLETION = true;
|
||||||
var ITERATOR_HAD_ERROR_KEY = false;
|
var ITERATOR_HAD_ERROR_KEY = false;
|
||||||
@ -44,6 +43,7 @@ export default function ({ messages, template, types: t }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
/* eslint-enable max-len */
|
||||||
|
|
||||||
function _ForOfStatementArray(path) {
|
function _ForOfStatementArray(path) {
|
||||||
const { node, scope } = path;
|
const { node, scope } = path;
|
||||||
@ -76,7 +76,8 @@ export default function ({ messages, template, types: t }) {
|
|||||||
left.declarations[0].init = iterationValue;
|
left.declarations[0].init = iterationValue;
|
||||||
loop.body.body.unshift(left);
|
loop.body.body.unshift(left);
|
||||||
} else {
|
} 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()) {
|
if (path.parentPath.isLabeledStatement()) {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import { basename, extname } from "path";
|
import { basename, extname } from "path";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
import * as t from "babel-types";
|
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 () {
|
export default function () {
|
||||||
const REASSIGN_REMAP_SKIP = Symbol();
|
const REASSIGN_REMAP_SKIP = Symbol();
|
||||||
@ -61,7 +60,8 @@ export default function () {
|
|||||||
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), remap]));
|
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), remap]));
|
||||||
} else if (path.isJSXIdentifier() && t.isMemberExpression(remap)) {
|
} else if (path.isJSXIdentifier() && t.isMemberExpression(remap)) {
|
||||||
const { object, property } = 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 {
|
} else {
|
||||||
path.replaceWith(remap);
|
path.replaceWith(remap);
|
||||||
}
|
}
|
||||||
@ -327,9 +327,15 @@ export default function () {
|
|||||||
// todo
|
// todo
|
||||||
} else if (specifier.isExportSpecifier()) {
|
} else if (specifier.isExportSpecifier()) {
|
||||||
if (specifier.node.local.name === "default") {
|
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 {
|
} 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;
|
nonHoistedExportNames[specifier.node.exported.name] = true;
|
||||||
}
|
}
|
||||||
@ -414,7 +420,8 @@ export default function () {
|
|||||||
topNodes.push(varDecl);
|
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 {
|
} else {
|
||||||
@ -431,13 +438,20 @@ export default function () {
|
|||||||
const maxHoistedExportsNodeAssignmentLength = 100;
|
const maxHoistedExportsNodeAssignmentLength = 100;
|
||||||
const nonHoistedExportNamesArr = Object.keys(nonHoistedExportNames);
|
const nonHoistedExportNamesArr = Object.keys(nonHoistedExportNames);
|
||||||
|
|
||||||
for (let currentExportsNodeAssignmentLength = 0; currentExportsNodeAssignmentLength < nonHoistedExportNamesArr.length; currentExportsNodeAssignmentLength += maxHoistedExportsNodeAssignmentLength ) {
|
for (
|
||||||
const nonHoistedExportNamesChunk = nonHoistedExportNamesArr.slice(currentExportsNodeAssignmentLength, currentExportsNodeAssignmentLength + maxHoistedExportsNodeAssignmentLength);
|
let currentExportsNodeAssignmentLength = 0;
|
||||||
|
currentExportsNodeAssignmentLength < nonHoistedExportNamesArr.length;
|
||||||
|
currentExportsNodeAssignmentLength += maxHoistedExportsNodeAssignmentLength
|
||||||
|
) {
|
||||||
|
const nonHoistedExportNamesChunk = nonHoistedExportNamesArr.slice(
|
||||||
|
currentExportsNodeAssignmentLength,
|
||||||
|
currentExportsNodeAssignmentLength + maxHoistedExportsNodeAssignmentLength);
|
||||||
|
|
||||||
let hoistedExportsNode = t.identifier("undefined");
|
let hoistedExportsNode = t.identifier("undefined");
|
||||||
|
|
||||||
nonHoistedExportNamesChunk.forEach(function (name) {
|
nonHoistedExportNamesChunk.forEach(function (name) {
|
||||||
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression;
|
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode)
|
||||||
|
.expression;
|
||||||
});
|
});
|
||||||
|
|
||||||
const node = t.expressionStatement(hoistedExportsNode);
|
const node = t.expressionStatement(hoistedExportsNode);
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import hoistVariables from "babel-helper-hoist-variables";
|
import hoistVariables from "babel-helper-hoist-variables";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
|
|
||||||
@ -76,7 +74,8 @@ export default function ({ types: t }) {
|
|||||||
CallExpression(path, state) {
|
CallExpression(path, state) {
|
||||||
if (path.node.callee.type === TYPE_IMPORT) {
|
if (path.node.callee.type === TYPE_IMPORT) {
|
||||||
const contextIdent = state.contextIdent;
|
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)) {
|
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)) {
|
} else if (t.isExportSpecifier(node)) {
|
||||||
setterBody.push(t.expressionStatement(
|
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 {
|
} else {
|
||||||
// todo
|
// todo
|
||||||
@ -279,7 +280,8 @@ export default function ({ types: t }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (variableIds.length) {
|
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, {
|
path.traverse(reassignmentVisitor, {
|
||||||
@ -294,7 +296,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
path.node.body = [
|
path.node.body = [
|
||||||
buildTemplate({
|
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,
|
BEFORE_BODY: beforeBody,
|
||||||
MODULE_NAME: moduleName,
|
MODULE_NAME: moduleName,
|
||||||
SETTERS: setters,
|
SETTERS: setters,
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import { basename, extname } from "path";
|
import { basename, extname } from "path";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import getFunctionArity from "babel-helper-get-function-arity";
|
import getFunctionArity from "babel-helper-get-function-arity";
|
||||||
import callDelegate from "babel-helper-call-delegate";
|
import callDelegate from "babel-helper-call-delegate";
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint indent: 0 */
|
|
||||||
|
|
||||||
import template from "babel-template";
|
import template from "babel-template";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
export default function ({ types: t }) {
|
export default function ({ types: t }) {
|
||||||
const IGNORE = Symbol();
|
const IGNORE = Symbol();
|
||||||
|
|
||||||
@ -18,10 +16,17 @@ export default function ({ types: t }) {
|
|||||||
if (node[IGNORE]) return;
|
if (node[IGNORE]) return;
|
||||||
if (path.find((path) => path.node && !!path.node._generated)) return;
|
if (path.find((path) => path.node && !!path.node._generated)) return;
|
||||||
|
|
||||||
if (path.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) {
|
if (
|
||||||
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols
|
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();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,11 +94,14 @@ export default function ({ types: t }) {
|
|||||||
// to avoid calling foo() twice, as a first step convert it to:
|
// to avoid calling foo() twice, as a first step convert it to:
|
||||||
// const _foo = foo(),
|
// const _foo = foo(),
|
||||||
// { a, ...b } = _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()
|
// 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
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
@ -247,7 +250,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
const useBuiltIns = file.opts.useBuiltIns || false;
|
const useBuiltIns = file.opts.useBuiltIns || false;
|
||||||
if (typeof useBuiltIns !== "boolean") {
|
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 = [];
|
const args = [];
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import pull from "lodash/pull";
|
import pull from "lodash/pull";
|
||||||
|
|
||||||
export default function ({ types: t }) {
|
export default function ({ types: t }) {
|
||||||
@ -9,7 +7,8 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
function isProtoAssignmentExpression(node) {
|
function isProtoAssignmentExpression(node) {
|
||||||
const left = node.left;
|
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) {
|
function buildDefaultsCallExpression(expr, ref, file) {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import jsx from "babel-plugin-syntax-jsx";
|
import jsx from "babel-plugin-syntax-jsx";
|
||||||
import helper from "babel-helper-builder-react-jsx";
|
import helper from "babel-helper-builder-react-jsx";
|
||||||
|
|
||||||
@ -31,7 +29,8 @@ export default function ({ types: t }) {
|
|||||||
if (matches) {
|
if (matches) {
|
||||||
id = matches[1];
|
id = matches[1];
|
||||||
if (id === "React.DOM") {
|
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 {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
if (global._babelPolyfill) {
|
if (global._babelPolyfill) {
|
||||||
throw new Error("only one instance of babel-polyfill is allowed");
|
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, "padLeft", "".padStart);
|
||||||
define(String.prototype, "padRight", "".padEnd);
|
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) {
|
"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]));
|
[][key] && define(Array, key, Function.call.bind([][key]));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import assign from "lodash/assign";
|
import assign from "lodash/assign";
|
||||||
import has from "lodash/has";
|
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
|
// original stack to append if it errors when parsing
|
||||||
let stack;
|
let stack;
|
||||||
try {
|
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();
|
throw new Error();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.stack) {
|
if (error.stack) {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import TraversalContext from "./context";
|
import TraversalContext from "./context";
|
||||||
import * as visitors from "./visitors";
|
import * as visitors from "./visitors";
|
||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
@ -45,7 +43,14 @@ traverse.cheap = function (node, enter) {
|
|||||||
return t.traverseFast(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];
|
const keys: Array = t.VISITOR_KEYS[node.type];
|
||||||
if (!keys) return;
|
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
|
// the node we're searching in is blacklisted
|
||||||
if (includes(blacklistTypes, tree.type)) return false;
|
if (includes(blacklistTypes, tree.type)) return false;
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,7 @@
|
|||||||
/* eslint indent: 0 */
|
|
||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import type NodePath from "./index";
|
import type NodePath from "./index";
|
||||||
|
|
||||||
// This file contains Babels metainterpreter that can evaluate static code.
|
// This file contains Babels metainterpreter that can evaluate static code.
|
||||||
|
|
||||||
/* eslint eqeqeq: 0 */
|
|
||||||
|
|
||||||
const VALID_CALLEES = ["String", "Number", "Math"];
|
const VALID_CALLEES = ["String", "Number", "Math"];
|
||||||
const INVALID_METHODS = ["random"];
|
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;
|
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;
|
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;
|
let func;
|
||||||
|
|
||||||
// Number(1);
|
// 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];
|
func = global[node.callee.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +342,11 @@ export function evaluate(): { confident: boolean; value: any } {
|
|||||||
const property = callee.get("property");
|
const property = callee.get("property");
|
||||||
|
|
||||||
// Math.min(1, 2)
|
// 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];
|
context = global[object.node.name];
|
||||||
func = context[property.node.name];
|
func = context[property.node.name];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import type Hub from "../hub";
|
import type Hub from "../hub";
|
||||||
import type TraversalContext from "../context";
|
import type TraversalContext from "../context";
|
||||||
import * as virtualTypes from "./lib/virtual-types";
|
import * as virtualTypes from "./lib/virtual-types";
|
||||||
|
|||||||
@ -153,7 +153,8 @@ export default class PathHoister {
|
|||||||
const attachTo = this.getAttachmentPath();
|
const attachTo = this.getAttachmentPath();
|
||||||
if (!attachTo) return;
|
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;
|
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
||||||
|
|
||||||
// generate declaration and insert it to our point
|
// generate declaration and insert it to our point
|
||||||
|
|||||||
@ -6,28 +6,29 @@
|
|||||||
|
|
||||||
export const hooks = [
|
export const hooks = [
|
||||||
function (self, parent) {
|
function (self, parent) {
|
||||||
let removeParent = false;
|
const removeParent =
|
||||||
|
|
||||||
// while (NODE);
|
// while (NODE);
|
||||||
// removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true`
|
// removing the test of a while/switch, we can either just remove it entirely *or* turn the
|
||||||
// unlikely that the latter will ever be what's wanted so we just remove the loop to avoid infinite recursion
|
// `test` into `true` unlikely that the latter will ever be what's wanted so we just remove
|
||||||
removeParent = removeParent || (self.key === "test" && (parent.isWhile() || parent.isSwitchCase()));
|
// the loop to avoid infinite recursion
|
||||||
|
(self.key === "test" && (parent.isWhile() || parent.isSwitchCase())) ||
|
||||||
|
|
||||||
// export NODE;
|
// export NODE;
|
||||||
// just remove a declaration for an export as this is no longer valid
|
// 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
|
// label: NODE
|
||||||
// stray labeled statement with no body
|
// stray labeled statement with no body
|
||||||
removeParent = removeParent || (self.key === "body" && parent.isLabeledStatement());
|
(self.key === "body" && parent.isLabeledStatement()) ||
|
||||||
|
|
||||||
// let NODE;
|
// let NODE;
|
||||||
// remove an entire declaration if there are no declarators left
|
// 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;
|
// NODE;
|
||||||
// remove the entire expression statement if there's no expression
|
// remove the entire expression statement if there's no expression
|
||||||
removeParent = removeParent || (self.key === "expression" && parent.isExpressionStatement());
|
(self.key === "expression" && parent.isExpressionStatement());
|
||||||
|
|
||||||
if (removeParent) {
|
if (removeParent) {
|
||||||
parent.remove();
|
parent.remove();
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
// This file contains methods that modify the path/node in some ways.
|
// This file contains methods that modify the path/node in some ways.
|
||||||
|
|
||||||
import { path as pathCache } from "../cache";
|
import { path as pathCache } from "../cache";
|
||||||
@ -17,7 +16,10 @@ export function insertBefore(nodes) {
|
|||||||
|
|
||||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||||
return this.parentPath.insertBefore(nodes);
|
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);
|
if (this.node) nodes.push(this.node);
|
||||||
this.replaceExpressionWithStatements(nodes);
|
this.replaceExpressionWithStatements(nodes);
|
||||||
} else {
|
} else {
|
||||||
@ -28,7 +30,8 @@ export function insertBefore(nodes) {
|
|||||||
if (this.node) nodes.push(this.node);
|
if (this.node) nodes.push(this.node);
|
||||||
this._replaceWith(t.blockStatement(nodes));
|
this._replaceWith(t.blockStatement(nodes));
|
||||||
} else {
|
} 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) {
|
export function _maybePopFromStatements(nodes) {
|
||||||
const last = nodes[nodes.length - 1];
|
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()) {
|
if (isIdentifier && !this.isCompletionRecord()) {
|
||||||
nodes.pop();
|
nodes.pop();
|
||||||
@ -107,7 +111,10 @@ export function insertAfter(nodes) {
|
|||||||
|
|
||||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||||
return this.parentPath.insertAfter(nodes);
|
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) {
|
if (this.node) {
|
||||||
const temp = this.scope.generateDeclaredUidIdentifier();
|
const temp = this.scope.generateDeclaredUidIdentifier();
|
||||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||||
@ -122,7 +129,8 @@ export function insertAfter(nodes) {
|
|||||||
if (this.node) nodes.unshift(this.node);
|
if (this.node) nodes.unshift(this.node);
|
||||||
this._replaceWith(t.blockStatement(nodes));
|
this._replaceWith(t.blockStatement(nodes));
|
||||||
} else {
|
} 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.
|
// This file contains methods responsible for replacing a node with another.
|
||||||
|
|
||||||
import codeFrame from "babel-code-frame";
|
import codeFrame from "babel-code-frame";
|
||||||
@ -114,22 +113,30 @@ export function replaceWith(replacement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(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") {
|
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.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
|
// replacing a statement with an expression so wrap it in an expression statement
|
||||||
replacement = t.expressionStatement(replacement);
|
replacement = t.expressionStatement(replacement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNodeType("Expression") && t.isStatement(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
|
// replacing an expression with a statement so let's explode it
|
||||||
return this.replaceExpressionWithStatements([replacement]);
|
return this.replaceExpressionWithStatements([replacement]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint max-len: 0 */
|
|
||||||
|
|
||||||
import includes from "lodash/includes";
|
import includes from "lodash/includes";
|
||||||
import repeat from "lodash/repeat";
|
import repeat from "lodash/repeat";
|
||||||
import Renamer from "./lib/renamer";
|
import Renamer from "./lib/renamer";
|
||||||
@ -341,13 +339,11 @@ export default class Scope {
|
|||||||
// ignore hoisted functions if there's also a local let
|
// ignore hoisted functions if there's also a local let
|
||||||
if (kind === "hoisted" && local.kind === "let") return;
|
if (kind === "hoisted" && local.kind === "let") return;
|
||||||
|
|
||||||
let duplicate = false;
|
const duplicate =
|
||||||
|
|
||||||
// don't allow duplicate bindings to exist alongside
|
// 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
|
// 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) {
|
if (duplicate) {
|
||||||
throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
|
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 () {
|
it("should bail out on recursive evaluation", function () {
|
||||||
assert.strictEqual(
|
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
|
false
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -54,7 +55,8 @@ describe("evaluation", function () {
|
|||||||
|
|
||||||
it("should deopt when var is redeclared in the same scope", function () {
|
it("should deopt when var is redeclared in the same scope", function () {
|
||||||
assert.strictEqual(
|
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
|
false
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -73,7 +75,8 @@ describe("evaluation", function () {
|
|||||||
|
|
||||||
it("it should not deopt let/const inside blocks", function () {
|
it("it should not deopt let/const inside blocks", function () {
|
||||||
assert.strictEqual(
|
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
|
10
|
||||||
);
|
);
|
||||||
const constExample = "const d = true; if (d && true || false) { const d = false; d && 5; }";
|
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 () {
|
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 left = path.get("left");
|
||||||
const right = path.get("right");
|
const right = path.get("right");
|
||||||
|
|
||||||
@ -144,7 +145,8 @@ describe("inference", function () {
|
|||||||
it("should infer call return type using async generator function", function () {
|
it("should infer call return type using async generator function", function () {
|
||||||
const path = getPath("(async function * (): string {})()").get("body")[0].get("expression");
|
const path = getPath("(async function * (): string {})()").get("body")[0].get("expression");
|
||||||
const type = path.getTypeAnnotation();
|
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 () {
|
it("should infer number from x/y", function () {
|
||||||
const path = getPath("x/y").get("body")[0].get("expression");
|
const path = getPath("x/y").get("body")[0].get("expression");
|
||||||
|
|||||||
@ -17,22 +17,29 @@ function getPath(code) {
|
|||||||
describe("scope", function () {
|
describe("scope", function () {
|
||||||
describe("binding paths", function () {
|
describe("binding paths", function () {
|
||||||
it("function declaration id", 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 () {
|
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 () {
|
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 () {
|
it("variable declaration", function () {
|
||||||
assert.ok(getPath("var foo = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
assert.ok(getPath("var foo = null;")
|
||||||
assert.ok(getPath("var { foo } = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
.scope.getBinding("foo").path.type === "VariableDeclarator");
|
||||||
assert.ok(getPath("var [ foo ] = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
assert.ok(getPath("var { foo } = null;")
|
||||||
assert.ok(getPath("var { bar: [ foo ] } = null;").scope.getBinding("foo").path.type === "VariableDeclarator");
|
.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 () {
|
it("purity", function () {
|
||||||
|
|||||||
@ -31,7 +31,8 @@ describe("traverse", function () {
|
|||||||
it("traverse", function () {
|
it("traverse", function () {
|
||||||
const expect = [
|
const expect = [
|
||||||
body[0], body[0].declarations[0], body[0].declarations[0].id, body[0].declarations[0].init,
|
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 = [];
|
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 STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
|
||||||
export const FLATTENABLE_KEYS = ["body", "expressions"];
|
export const FLATTENABLE_KEYS = ["body", "expressions"];
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
import * as t from "../index";
|
import * as t from "../index";
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/* eslint max-len: 0 */
|
/* eslint max-len: "off" */
|
||||||
|
|
||||||
import defineType, {
|
import defineType, {
|
||||||
assertNodeType,
|
assertNodeType,
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint indent: 0 */
|
|
||||||
|
|
||||||
import { getBindingIdentifiers } from "./retrievers";
|
import { getBindingIdentifiers } from "./retrievers";
|
||||||
import esutils from "esutils";
|
import esutils from "esutils";
|
||||||
import * as t from "./index";
|
import * as t from "./index";
|
||||||
|
|||||||
@ -25,7 +25,8 @@ describe("converters", function () {
|
|||||||
assert.deepEqual(t.valueToNode(/abc.+/gm), t.regExpLiteral("abc.+", "gm"));
|
assert.deepEqual(t.valueToNode(/abc.+/gm), t.regExpLiteral("abc.+", "gm"));
|
||||||
});
|
});
|
||||||
it("array", function () {
|
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 () {
|
it("object", function () {
|
||||||
assert.deepEqual(t.valueToNode({
|
assert.deepEqual(t.valueToNode({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user