Bump eslint-config-babel and fix lint (#5129)
This commit is contained in:
parent
2457c8ee14
commit
8c35b320d3
@ -26,7 +26,7 @@
|
|||||||
"codecov": "^1.0.1",
|
"codecov": "^1.0.1",
|
||||||
"derequire": "^2.0.2",
|
"derequire": "^2.0.2",
|
||||||
"eslint": "^3.9.0",
|
"eslint": "^3.9.0",
|
||||||
"eslint-config-babel": "^5.0.0",
|
"eslint-config-babel": "^6.0.0",
|
||||||
"eslint-plugin-flowtype": "^2.20.0",
|
"eslint-plugin-flowtype": "^2.20.0",
|
||||||
"flow-bin": "^0.34.0",
|
"flow-bin": "^0.34.0",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import jsTokens, {matchToToken} from "js-tokens";
|
import jsTokens, { matchToToken } from "js-tokens";
|
||||||
import esutils from "esutils";
|
import esutils from "esutils";
|
||||||
import Chalk from "chalk";
|
import Chalk from "chalk";
|
||||||
|
|
||||||
|
|||||||
@ -109,7 +109,7 @@ describe("babel-code-frame", function () {
|
|||||||
|
|
||||||
it("opts.highlightCode", function () {
|
it("opts.highlightCode", function () {
|
||||||
const rawLines = "console.log('babel')";
|
const rawLines = "console.log('babel')";
|
||||||
const result = codeFrame(rawLines, 1, 9, {highlightCode: true});
|
const result = codeFrame(rawLines, 1, 9, { highlightCode: true });
|
||||||
const stripped = chalk.stripColor(result);
|
const stripped = chalk.stripColor(result);
|
||||||
assert.ok(result.length > stripped.length);
|
assert.ok(result.length > stripped.length);
|
||||||
assert.equal(stripped, [
|
assert.equal(stripped, [
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const superVisitor = {
|
|||||||
CallExpression(path) {
|
CallExpression(path) {
|
||||||
if (!path.get("callee").isSuper()) return;
|
if (!path.get("callee").isSuper()) return;
|
||||||
|
|
||||||
const {node} = path;
|
const { node } = path;
|
||||||
if (node[SUPER_THIS_BOUND]) return;
|
if (node[SUPER_THIS_BOUND]) return;
|
||||||
node[SUPER_THIS_BOUND] = true;
|
node[SUPER_THIS_BOUND] = true;
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ function remap(path, key) {
|
|||||||
const classPath = fnPath.findParent((p) => p.isClass());
|
const classPath = fnPath.findParent((p) => p.isClass());
|
||||||
const hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
const hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||||
|
|
||||||
if (key === "this" && fnPath.isMethod({kind: "constructor"}) && hasSuperClass) {
|
if (key === "this" && fnPath.isMethod({ kind: "constructor" }) && hasSuperClass) {
|
||||||
fnPath.scope.push({ id });
|
fnPath.scope.push({ id });
|
||||||
|
|
||||||
fnPath.traverse(superVisitor, { id });
|
fnPath.traverse(superVisitor, { id });
|
||||||
|
|||||||
@ -64,6 +64,6 @@ describe("evaluation", function () {
|
|||||||
addTest("'abc' === 'xyz' || (1 === 1 && 'four' === 'four')", "LogicalExpression", true);
|
addTest("'abc' === 'xyz' || (1 === 1 && 'four' === 'four')", "LogicalExpression", true);
|
||||||
addTest("'abc' === 'abc' && (1 === 1 && 'four' === 'four')", "LogicalExpression", true);
|
addTest("'abc' === 'abc' && (1 === 1 && 'four' === 'four')", "LogicalExpression", true);
|
||||||
addTest("({})", "ObjectExpression", {});
|
addTest("({})", "ObjectExpression", {});
|
||||||
addTest("({a: '1'})", "ObjectExpression", {a: "1"});
|
addTest("({a: '1'})", "ObjectExpression", { a: "1" });
|
||||||
addTest("({['a' + 'b']: 10 * 20, 'z': [1, 2, 3]})", "ObjectExpression", {ab: 200, z: [1, 2, 3]});
|
addTest("({['a' + 'b']: 10 * 20, 'z': [1, 2, 3]})", "ObjectExpression", { ab: 200, z: [1, 2, 3] });
|
||||||
});
|
});
|
||||||
|
|||||||
@ -55,7 +55,7 @@ export default class Buffer {
|
|||||||
return this.map = map.get();
|
return this.map = map.get();
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
Object.defineProperty(this, "map", {value, writable: true});
|
Object.defineProperty(this, "map", { value, writable: true });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import detectIndent from "detect-indent";
|
|||||||
import SourceMap from "./source-map";
|
import SourceMap from "./source-map";
|
||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
import Printer from "./printer";
|
import Printer from "./printer";
|
||||||
import type {Format} from "./printer";
|
import type { Format } from "./printer";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Babel's code generator, turns an ast into code, maintaining sourcemaps,
|
* Babel's code generator, turns an ast into code, maintaining sourcemaps,
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export function UpdateExpression(node: Object, parent: Object): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ObjectExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
export function ObjectExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
||||||
return isFirstInStatement(printStack, {considerArrow: true});
|
return isFirstInStatement(printStack, { considerArrow: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Binary(node: Object, parent: Object): boolean {
|
export function Binary(node: Object, parent: Object): boolean {
|
||||||
@ -150,7 +150,7 @@ export function YieldExpression(node: Object, parent: Object): boolean {
|
|||||||
export { YieldExpression as AwaitExpression };
|
export { YieldExpression as AwaitExpression };
|
||||||
|
|
||||||
export function ClassExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
export function ClassExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
||||||
return isFirstInStatement(printStack, {considerDefaultExports: true});
|
return isFirstInStatement(printStack, { considerDefaultExports: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UnaryLike(node: Object, parent: Object): boolean {
|
export function UnaryLike(node: Object, parent: Object): boolean {
|
||||||
@ -166,7 +166,7 @@ export function UnaryLike(node: Object, parent: Object): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FunctionExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
export function FunctionExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
|
||||||
return isFirstInStatement(printStack, {considerDefaultExports: true});
|
return isFirstInStatement(printStack, { considerDefaultExports: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ArrowFunctionExpression(node: Object, parent: Object): boolean {
|
export function ArrowFunctionExpression(node: Object, parent: Object): boolean {
|
||||||
|
|||||||
@ -29,13 +29,13 @@ export default function ({ types: t }) {
|
|||||||
});
|
});
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const buildClassPropertySpec = (ref, {key, value, computed}) => buildObjectDefineProperty({
|
const buildClassPropertySpec = (ref, { key, value, computed }) => buildObjectDefineProperty({
|
||||||
REF: ref,
|
REF: ref,
|
||||||
KEY: (t.isIdentifier(key) && !computed) ? t.stringLiteral(key.name) : key,
|
KEY: (t.isIdentifier(key) && !computed) ? t.stringLiteral(key.name) : key,
|
||||||
VALUE: value ? value : t.identifier("undefined")
|
VALUE: value ? value : t.identifier("undefined")
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildClassPropertyNonSpec = (ref, {key, value, computed}) => t.expressionStatement(
|
const buildClassPropertyNonSpec = (ref, { key, value, computed }) => t.expressionStatement(
|
||||||
t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value)
|
t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -506,7 +506,7 @@ export default function ({ types: t }) {
|
|||||||
for (const nodeOut of nodesOut) {
|
for (const nodeOut of nodesOut) {
|
||||||
if (!nodeOut.declarations) continue;
|
if (!nodeOut.declarations) continue;
|
||||||
for (const declaration of nodeOut.declarations) {
|
for (const declaration of nodeOut.declarations) {
|
||||||
const {name} = declaration.id;
|
const { name } = declaration.id;
|
||||||
if (scope.bindings[name]) {
|
if (scope.bindings[name]) {
|
||||||
scope.bindings[name].kind = nodeOut.kind;
|
scope.bindings[name].kind = nodeOut.kind;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -355,7 +355,7 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const source in imports) {
|
for (const source in imports) {
|
||||||
const {specifiers, maxBlockHoist} = imports[source];
|
const { specifiers, maxBlockHoist } = imports[source];
|
||||||
if (specifiers.length) {
|
if (specifiers.length) {
|
||||||
const uid = addRequire(source, maxBlockHoist);
|
const uid = addRequire(source, maxBlockHoist);
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ test("Re-export doesn't overwrite __esModule flag", function () {
|
|||||||
|
|
||||||
code = babel.transform(code, {
|
code = babel.transform(code, {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
[require("../"), {loose: true}],
|
[require("../"), { loose: true }],
|
||||||
],
|
],
|
||||||
"ast": false,
|
"ast": false,
|
||||||
}).code;
|
}).code;
|
||||||
|
|||||||
@ -67,7 +67,7 @@ const memberExpressionOptimisationVisitor = {
|
|||||||
if (state.noOptimise) {
|
if (state.noOptimise) {
|
||||||
state.deopted = true;
|
state.deopted = true;
|
||||||
} else {
|
} else {
|
||||||
const {parentPath} = path;
|
const { parentPath } = path;
|
||||||
|
|
||||||
// Is this identifier the right hand side of a default parameter?
|
// Is this identifier the right hand side of a default parameter?
|
||||||
if (parentPath.listKey === "params" && parentPath.key < state.offset) {
|
if (parentPath.listKey === "params" && parentPath.key < state.offset) {
|
||||||
@ -117,13 +117,13 @@ const memberExpressionOptimisationVisitor = {
|
|||||||
// if we know that this member expression is referencing a number then
|
// if we know that this member expression is referencing a number then
|
||||||
// we can safely optimise it
|
// we can safely optimise it
|
||||||
if (parentPath.get("property").isBaseType("number")) {
|
if (parentPath.get("property").isBaseType("number")) {
|
||||||
state.candidates.push({cause: "indexGetter", path});
|
state.candidates.push({ cause: "indexGetter", path });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// args.length
|
// args.length
|
||||||
else if (parentPath.node.property.name === "length") {
|
else if (parentPath.node.property.name === "length") {
|
||||||
state.candidates.push({cause: "lengthGetter", path});
|
state.candidates.push({ cause: "lengthGetter", path });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ const memberExpressionOptimisationVisitor = {
|
|||||||
if (state.offset === 0 && parentPath.isSpreadElement()) {
|
if (state.offset === 0 && parentPath.isSpreadElement()) {
|
||||||
const call = parentPath.parentPath;
|
const call = parentPath.parentPath;
|
||||||
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
||||||
state.candidates.push({cause: "argSpread", path});
|
state.candidates.push({ cause: "argSpread", path });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ function optimiseIndexGetter(path, argsId, offset) {
|
|||||||
const { scope } = path;
|
const { scope } = path;
|
||||||
if (!scope.isPure(index)) {
|
if (!scope.isPure(index)) {
|
||||||
const temp = scope.generateUidIdentifierBasedOnNode(index);
|
const temp = scope.generateUidIdentifierBasedOnNode(index);
|
||||||
scope.push({id: temp, kind: "var"});
|
scope.push({ id: temp, kind: "var" });
|
||||||
path.parentPath.replaceWith(restIndexImpure({
|
path.parentPath.replaceWith(restIndexImpure({
|
||||||
ARGUMENTS: argsId,
|
ARGUMENTS: argsId,
|
||||||
INDEX: index,
|
INDEX: index,
|
||||||
@ -246,7 +246,7 @@ export const visitor = {
|
|||||||
|
|
||||||
// There are only "shorthand" references
|
// There are only "shorthand" references
|
||||||
if (!state.deopted && !state.references.length) {
|
if (!state.deopted && !state.references.length) {
|
||||||
for (const {path, cause} of (state.candidates: Array)) {
|
for (const { path, cause } of (state.candidates: Array)) {
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case "indexGetter":
|
case "indexGetter":
|
||||||
optimiseIndexGetter(path, argsId, state.offset);
|
optimiseIndexGetter(path, argsId, state.offset);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ export default function ({ types: t }) {
|
|||||||
return {
|
return {
|
||||||
visitor: {
|
visitor: {
|
||||||
ObjectProperty: {
|
ObjectProperty: {
|
||||||
exit({node}) {
|
exit({ node }) {
|
||||||
const key = node.key;
|
const key = node.key;
|
||||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||||
// default: "bar" -> "default": "bar"
|
// default: "bar" -> "default": "bar"
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export default function ({ types: t }) {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
const fileNameIdentifier = path.scope.generateUidIdentifier(FILE_NAME_VAR);
|
const fileNameIdentifier = path.scope.generateUidIdentifier(FILE_NAME_VAR);
|
||||||
path.hub.file.scope.push({id: fileNameIdentifier, init: t.stringLiteral(fileName)});
|
path.hub.file.scope.push({ id: fileNameIdentifier, init: t.stringLiteral(fileName) });
|
||||||
state.fileNameIdentifier = fileNameIdentifier;
|
state.fileNameIdentifier = fileNameIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ describe("es2015 preset", function () {
|
|||||||
describe("loose", function () {
|
describe("loose", function () {
|
||||||
it("throws on non-boolean value", function () {
|
it("throws on non-boolean value", function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
es2015.buildPreset(null, { loose: 1});
|
es2015.buildPreset(null, { loose: 1 });
|
||||||
}).to.throw(/must be a boolean/);
|
}).to.throw(/must be a boolean/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export default function (code: string, opts?: Object): Function {
|
|||||||
try {
|
try {
|
||||||
ast = babylon.parse(code, opts);
|
ast = babylon.parse(code, opts);
|
||||||
|
|
||||||
ast = traverse.removeProperties(ast, {preserveComments: opts.preserveComments});
|
ast = traverse.removeProperties(ast, { preserveComments: opts.preserveComments });
|
||||||
|
|
||||||
traverse.cheap(ast, function (node) {
|
traverse.cheap(ast, function (node) {
|
||||||
node[FROM_TEMPLATE] = true;
|
node[FROM_TEMPLATE] = true;
|
||||||
|
|||||||
@ -13,7 +13,7 @@ describe("templating", function () {
|
|||||||
|
|
||||||
it("import statements are allowed with sourceType: module", function () {
|
it("import statements are allowed with sourceType: module", function () {
|
||||||
chai.expect(function () {
|
chai.expect(function () {
|
||||||
template("import foo from 'foo'", {sourceType: "module"})({});
|
template("import foo from 'foo'", { sourceType: "module" })({});
|
||||||
}).not.to.throw();
|
}).not.to.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ describe("templating", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should preserve comments with a flag", function () {
|
it("should preserve comments with a flag", function () {
|
||||||
const output = template(comments, {preserveComments: true})();
|
const output = template(comments, { preserveComments: true })();
|
||||||
chai.expect(generator(output).code).to.be.equal(comments);
|
chai.expect(generator(output).code).to.be.equal(comments);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { parse } from "babylon";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
function getPath(code) {
|
function getPath(code) {
|
||||||
const ast = parse(code, {plugins: ["flow", "asyncGenerators"]});
|
const ast = parse(code, { plugins: ["flow", "asyncGenerators"] });
|
||||||
let path;
|
let path;
|
||||||
traverse(ast, {
|
traverse(ast, {
|
||||||
Program: function (_path) {
|
Program: function (_path) {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import assert from "assert";
|
|||||||
import { parse } from "babylon";
|
import { parse } from "babylon";
|
||||||
|
|
||||||
function getBody(program) {
|
function getBody(program) {
|
||||||
return parse(program, {sourceType: "module"}).program.body;
|
return parse(program, { sourceType: "module" }).program.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("retrievers", function () {
|
describe("retrievers", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user