Switch to klint, fix some lint rules

This commit is contained in:
Sebastian McKenzie 2016-02-14 23:25:14 +00:00
parent 456d24630a
commit 5b89849f43
75 changed files with 226 additions and 138 deletions

View File

@ -1,2 +1,11 @@
packages/babel-core/src/transformation/templates
scripts
lib
packages/babel-runtime
packages/babel-regenerator-runtime
packages/*/node_modules
packages/*/test
packages/*/dist
vendor
_babel.github.io
Gulpfile.js

View File

@ -4,7 +4,6 @@
"devDependencies": {
"async": "^1.5.0",
"babel": "5.8.21",
"babel-eslint": "^4.1.8",
"babel-plugin-flow-comments": "^1.0.9",
"browserify": "^11.2.0",
"bundle-collapser": "^1.2.1",
@ -13,7 +12,7 @@
"codecov.io": "^0.1.6",
"derequire": "^2.0.2",
"es5-shim": "^4.1.7",
"eslint": "~1.10.3",
"klint": "^1.0.0",
"flow-bin": "^0.21.0",
"fs-readdir-recursive": "^0.1.2",
"gulp": "^3.9.0",
@ -63,44 +62,5 @@
"auxiliaryCommentBefore": "istanbul ignore next"
}
}
},
"eslintConfig": {
"parser": "babel-eslint",
"extends": "eslint:recommended",
"rules": {
"quotes": [
2,
"double",
"avoid-escape"
],
"no-var": 2,
"space-after-keywords": 2,
"strict": 0,
"no-underscore-dangle": 0,
"curly": 0,
"no-multi-spaces": 0,
"key-spacing": 0,
"no-return-assign": 0,
"consistent-return": 0,
"no-shadow": 0,
"comma-dangle": 0,
"no-use-before-define": 0,
"no-empty": 0,
"new-parens": 0,
"no-cond-assign": 0,
"no-fallthrough": 0,
"new-cap": 0,
"no-loop-func": 0,
"no-unreachable": 0,
"no-labels": 0,
"no-process-exit": 0,
"camelcase": 0,
"no-console": 0,
"no-constant-condition": 0,
"no-inner-declarations": 0
},
"env": {
"node": true
}
}
}

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import binVersionCheck from "bin-version-check";
import chalk from "chalk";

View File

@ -1,3 +1,5 @@
/* eslint indent: 0 */
/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _babel-node(1) executable.
@ -37,7 +39,7 @@ getV8Flags(function (err, v8Flags) {
case "--expose-gc":
args.unshift("--expose-gc");
break;
case "--nolazy":
args.unshift("--nolazy");
break;

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
/* eslint max-len: 0 */
require("babel-core");

View File

@ -76,7 +76,10 @@ export function requireChokidar() {
try {
return require("chokidar");
} catch (err) {
console.error("The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.")
console.error(
"The optional dependency chokidar failed to install and is required for " +
"--watch. Chokidar is likely not supported on your platform."
);
throw err;
}
}

View File

@ -1,4 +1,6 @@
/* @flow */
/* eslint indent: 0 */
/* eslint max-len: 0 */
import lineNumbers from "line-numbers";
import repeating from "repeating";
@ -65,7 +67,7 @@ function highlight(text: string) {
let type = getTokenType(args);
let colorize = defs[type];
if (colorize) {
return args[0].split(NEWLINE).map(str => colorize(str)).join("\n");
return args[0].split(NEWLINE).map((str) => colorize(str)).join("\n");
} else {
return args[0];
}

View File

@ -1,2 +1,3 @@
/* eslint max-len: 0 */
// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`");
module.exports = require("babel-register");

View File

@ -1,3 +1,4 @@
/* eslint max-len: 0 */
/* eslint no-new-func: 0 */
import { transform } from "./node";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import * as helpers from "babel-helpers";
import generator from "babel-generator";
import * as messages from "babel-messages";

View File

@ -2,6 +2,7 @@
/* global BabelParserOptions */
/* global BabelFileMetadata */
/* global BabelFileResult */
/* eslint max-len: 0 */
import getHelper from "babel-helpers";
import * as metadataVisitor from "./metadata";
@ -69,7 +70,7 @@ export default class File extends Store {
if (this.opts.passPerPreset) {
// All the "per preset" options are inherited from the main options.
this.perPresetOpts = [];
this.opts.presets.forEach(presetOpts => {
this.opts.presets.forEach((presetOpts) => {
let perPresetOpts = Object.assign(Object.create(this.opts), presetOpts);
this.perPresetOpts.push(perPresetOpts);
this.buildPluginsForOptions(perPresetOpts);
@ -364,7 +365,7 @@ export default class File extends Store {
err.message += ")";
}
return err
return err;
}
mergeSourceMap(map: Object) {
@ -442,9 +443,9 @@ export default class File extends Store {
// Otherwise, there is only one plain pluginPasses array.
this.pluginPasses.forEach((pluginPasses, index) => {
this.call("pre", pluginPasses);
this.log.debug(`Start transform traverse`);
this.log.debug("Start transform traverse");
traverse(this.ast, traverse.visitors.merge(this.pluginVisitors[index], pluginPasses), this.scope);
this.log.debug(`End transform traverse`);
this.log.debug("End transform traverse");
this.call("post", pluginPasses);
});

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
module.exports = {
filename: {
type: "filename",

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import * as context from "../../../api/node";
import type Logger from "../logger";
import Plugin from "../../plugin";
@ -205,7 +207,7 @@ export default class OptionManager {
}
//
let opts = cloneDeep(rawOpts, val => {
let opts = cloneDeep(rawOpts, (val) => {
if (val instanceof Plugin) {
return val;
}
@ -310,7 +312,7 @@ export default class OptionManager {
* or a module name to require.
*/
resolvePresets(presets: Array<string | Object>, dirname: string, onResolve?) {
return presets.map(val => {
return presets.map((val) => {
if (typeof val === "string") {
let presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname);
if (presetLoc) {

View File

@ -1,6 +1,7 @@
/* @noflow */
/* 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 Store from "../store";
import traverse from "babel-traverse";

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
import isInteger from "is-integer";
import isNumber from "lodash/lang/isNumber";

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
import * as t from "babel-types";

View File

@ -6,7 +6,7 @@ export function _params(node: Object) {
this.print(node.typeParameters, node);
this.push("(");
this.printList(node.params, node, {
iterator: (node) =>{
iterator: (node) => {
if (node.optional) this.push("?");
this.print(node.typeAnnotation, node);
}

View File

@ -1,5 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
/* eslint quotes: 0 */
import * as t from "babel-types";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import repeating from "repeating";
import Buffer from "./buffer";
import * as n from "./node";

View File

@ -17,7 +17,7 @@ export default class Whitespace {
let endToken;
let tokens = this.tokens;
let index = this._findToken(token => token.start - node.start, 0, tokens.length);
let index = this._findToken((token) => token.start - node.start, 0, tokens.length);
if (index >= 0) {
while (index && node.start === tokens[index - 1].start) --index;
startToken = tokens[index - 1];
@ -36,7 +36,7 @@ export default class Whitespace {
let endToken;
let tokens = this.tokens;
let index = this._findToken(token => token.end - node.end, 0, tokens.length);
let index = this._findToken((token) => token.end - node.end, 0, tokens.length);
if (index >= 0) {
while (index && node.end === tokens[index - 1].end) --index;
startToken = tokens[index];

View File

@ -1,4 +1,4 @@
import type { NodePath } from "babel-traverse"
import type { NodePath } from "babel-traverse";
import * as t from "babel-types";
export default function bindifyDecorators(decorators: Array<NodePath>): Array<NodePath> {

View File

@ -26,7 +26,7 @@ export default function (path: NodePath, scope = path.scope) {
let args = [];
// todo: only hoist if necessary
hoistVariables(path, id => scope.push({ id }));
hoistVariables(path, (id) => scope.push({ id }));
let state = {
foundThis: false,

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import nameFunction from "babel-helper-function-name";
import each from "lodash/collection/each";
import has from "lodash/object/has";
@ -35,7 +37,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
if (node.decorators) {
let 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) {

View File

@ -1,5 +1,5 @@
import bindifyDecorators from "babel-helper-bindify-decorators";
import type { NodePath } from "babel-traverse"
import type { NodePath } from "babel-traverse";
import * as t from "babel-types";
export default function (classPath) {

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import getFunctionArity from "babel-helper-get-function-arity";
import template from "babel-template";
import * as t from "babel-types";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import * as t from "babel-types";
export default function (callee, thisNode, args) {

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import type { NodePath, Scope } from "babel-traverse";
import optimiseCall from "babel-helper-optimise-call-expression";
import * as messages from "babel-messages";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import template from "babel-template";
let helpers = {};

View File

@ -1,3 +1,5 @@
/* eslint no-confusing-arrow: 0 */
import helpers from "./helpers";
export function get(name) {
@ -8,7 +10,7 @@ export function get(name) {
}
export let list = Object.keys(helpers)
.map(name => name[0] === "_" ? name.slice(1) : name)
.filter(name => name !== "__esModule");
.map((name) => name[0] === "_" ? name.slice(1) : name)
.filter((name) => name !== "__esModule");
export default get;

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
import * as util from "util";

View File

@ -1,3 +1,4 @@
/* eslint max-len: 0 */
// todo: define instead of assign
export default function ({ types: t }) {
@ -114,7 +115,7 @@ export default function ({ types: t }) {
//
if (isDerived) {
let bareSupers = []
let bareSupers = [];
constructor.traverse(findBareSupers, bareSupers);
for (let bareSuper of bareSupers) {
bareSuper.insertAfter(instanceBody);

View File

@ -7,7 +7,7 @@ let buildClassDecorator = template(`
export default function ({ types: t }) {
function cleanDecorators(decorators) {
return decorators.reverse().map(dec => dec.expression);
return decorators.reverse().map((dec) => dec.expression);
}
function transformClass(path, ref, state) {
@ -104,7 +104,7 @@ export default function ({ types: t }) {
let ref = path.node.id;
let nodes = [];
nodes = nodes.concat(transformClass(path, ref, this).map(expr => t.expressionStatement(expr)));
nodes = nodes.concat(transformClass(path, ref, this).map((expr) => t.expressionStatement(expr)));
nodes.push(t.expressionStatement(ref));
path.insertAfter(nodes);

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import type NodePath from "babel-traverse";
import type Scope from "babel-traverse";
import type File from "../../../file";
@ -171,7 +173,7 @@ let hoistVarDeclarationsVisitor = {
node.left = node.left.declarations[0].id;
}
} else if (isVar(node, parent)) {
path.replaceWithMultiple(self.pushDeclar(node).map(expr => t.expressionStatement(expr)));
path.replaceWithMultiple(self.pushDeclar(node).map((expr) => t.expressionStatement(expr)));
} else if (path.isFunction()) {
return path.skip();
}

View File

@ -6,7 +6,7 @@ function getTDZStatus(refPath, bindingPath) {
if (executionStatus === "before") {
return "inside";
} else if (executionStatus === "after") {
return "outside"
return "outside";
} else {
return "maybe";
}

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import type { NodePath } from "babel-traverse";
import { visitors } from "babel-traverse";
import ReplaceSupers from "babel-helper-replace-supers";
@ -357,7 +359,7 @@ export default class ClassTransformer {
[t.thisExpression(), bareSuperNode]
);
let bareSuperAfter = this.bareSuperAfter.map(fn => fn(thisRef));
let 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) {
// this super call is the last statement in the body so we can just straight up
@ -420,7 +422,7 @@ export default class ClassTransformer {
thisPath.replaceWith(thisRef);
}
let wrapReturn = returnArg => t.callExpression(
let wrapReturn = (returnArg) => t.callExpression(
this.file.addHelper("possibleConstructorReturn"),
[thisRef].concat(returnArg || [])
);
@ -440,7 +442,7 @@ export default class ClassTransformer {
wrapReturn(ref)
]);
} else {
returnPath.get("argument").replaceWith(wrapReturn())
returnPath.get("argument").replaceWith(wrapReturn());
}
}
}

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
export default function ({ types: t }) {
/**

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
export default function ({ messages, template, types: t }) {
let buildForOfArray = template(`
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;

View File

@ -80,8 +80,8 @@ export default function ({ types: t }) {
path.traverse(amdVisitor, this);
let params = this.sources.map(source => source[0]);
let sources = this.sources.map(source => source[1]);
let params = this.sources.map((source) => source[0]);
let sources = this.sources.map((source) => source[1]);
sources = sources.concat(this.bareSources.filter((str) => {
return !this.sourceNames[str.value];

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import { basename, extname } from "path";
import template from "babel-template";
import * as t from "babel-types";
@ -191,7 +193,7 @@ export default function () {
for (let specifier of specifiers) {
let ids = specifier.getBindingIdentifiers();
if (ids.__esModule) {
throw specifier.buildCodeFrameError(`Illegal export "__esModule"`);
throw specifier.buildCodeFrameError("Illegal export \"__esModule\"");
}
}
}
@ -285,7 +287,7 @@ export default function () {
let specifiers = path.get("specifiers");
if (specifiers.length) {
let nodes = [];
let source = path.node.source
let source = path.node.source;
if (source) {
let ref = addRequire(source.value, path.node._blockHoist);

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import hoistVariables from "babel-helper-hoist-variables";
import template from "babel-template";
@ -231,11 +233,11 @@ export default function ({ types: t }) {
if (moduleName) moduleName = t.stringLiteral(moduleName);
if (canHoist) {
hoistVariables(path, id => variableIds.push(id));
hoistVariables(path, (id) => variableIds.push(id));
}
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, {

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import { basename, extname } from "path";
import template from "babel-template";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import getFunctionArity from "babel-helper-get-function-arity";
import callDelegate from "babel-helper-call-delegate";
import template from "babel-template";

View File

@ -1,3 +1,5 @@
/* eslint indent: 0 */
import template from "babel-template";
import * as t from "babel-types";
@ -203,7 +205,7 @@ export let visitor = {
}
state.references = state.references.concat(
state.candidates.map(({path}) => path)
state.candidates.map(({ path }) => path)
);
// deopt shadowed functions as transforms like regenerator may try touch the allocation loop
@ -254,7 +256,7 @@ export let visitor = {
let target = path.getEarliestCommonAncestorFrom(state.references).getStatementParent();
// don't perform the allocation inside a loop
target.findParent(path => {
target.findParent((path) => {
if (path.isLoop()) {
target = path;
} else {

View File

@ -55,7 +55,7 @@ export default function ({ types: t }) {
}
// filter out empty string literals
nodes = nodes.filter(n => !t.isLiteral(n, { value: "" }));
nodes = nodes.filter((n) => !t.isLiteral(n, { value: "" }));
// since `+` is left-to-right associative
// ensure the first node is a string if first/second isn't

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
export default function ({ types: t }) {
let IGNORE = Symbol();
@ -14,7 +16,7 @@ export default function ({ types: t }) {
UnaryExpression(path) {
let { node, parent } = path;
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) {
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols

View File

@ -3,33 +3,33 @@ import * as defineMap from "babel-helper-define-map";
export default function ({ types: t }) {
return {
visitor: {
ObjectExpression(path, file) {
let{ node } = path;
let hasAny = false;
for (let prop of (node.properties: Array)) {
if (prop.kind === "get" || prop.kind === "set") {
hasAny = true;
break;
}
ObjectExpression(path, file) {
let { node } = path;
let hasAny = false;
for (let prop of (node.properties: Array)) {
if (prop.kind === "get" || prop.kind === "set") {
hasAny = true;
break;
}
if (!hasAny) return;
let mutatorMap = {};
node.properties = node.properties.filter(function (prop) {
if (!prop.computed && (prop.kind === "get" || prop.kind === "set")) {
defineMap.push(mutatorMap, prop, null, file);
return false;
} else {
return true;
}
});
path.replaceWith(t.callExpression(
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
[node, defineMap.toDefineObject(mutatorMap)]
));
}
if (!hasAny) return;
let mutatorMap = {};
node.properties = node.properties.filter(function (prop) {
if (!prop.computed && (prop.kind === "get" || prop.kind === "set")) {
defineMap.push(mutatorMap, prop, null, file);
return false;
} else {
return true;
}
});
path.replaceWith(t.callExpression(
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
[node, defineMap.toDefineObject(mutatorMap)]
));
}
}
};
}

View File

@ -33,7 +33,7 @@ export default function ({ types: t }) {
// strip optional property from function params - facebook/fbjs#17
Function: {
exit({ node }) {
node.params.forEach(param => param.optional = false);
node.params.forEach((param) => param.optional = false);
}
},

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import pull from "lodash/array/pull";
export default function ({ types: t }) {

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
export default function ({ types: t }) {
let JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import cloneDeep from "lodash/lang/cloneDeep";
import assign from "lodash/object/assign";
import has from "lodash/object/has";
@ -16,7 +18,7 @@ export default function (code: string, opts?: Object): Function {
// error stack gets populated in IE only on throw (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx)
throw new Error();
} catch (error) {
stack = error.stack.split("\n").slice(1).join("\n")
stack = error.stack.split("\n").slice(1).join("\n");
}
let getAst = function () {

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import TraversalContext from "./context";
import * as visitors from "./visitors";
import * as messages from "babel-messages";

View File

@ -1,3 +1,6 @@
/* eslint indent: 0 */
/* eslint max-len: 0 */
import type NodePath from "./index";
// This file contains Babels metainterpreter that can evaluate static code.

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import type Hub from "../hub";
import type TraversalContext from "../context";
import * as virtualTypes from "./lib/virtual-types";

View File

@ -125,9 +125,9 @@ export function isNodeType(type: string): boolean {
* to tell the path replacement that it's ok to replace this with an expression.
*/
export function canHaveVariableDeclarationOrExpression() {
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
}
export function canHaveVariableDeclarationOrExpression() {
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
}
/**
* Check whether the current path references a completion record
@ -313,7 +313,7 @@ export function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncPare
for (let path of referencePaths) {
// if a reference is a child of the function we're checking against then we can
// safelty ignore it
let childOfFunction = !!path.find(path => path.node === targetFuncPath.node);
let childOfFunction = !!path.find((path) => path.node === targetFuncPath.node);
if (childOfFunction) continue;
let status = this._guessExecutionStatusRelativeTo(path);
@ -364,7 +364,7 @@ export function _resolve(dangerous?, resolved?): ?NodePath {
if (binding.path !== this) {
let ret = binding.path.resolve(dangerous, resolved);
// If the identifier resolves to parent node then we can't really resolve it.
if (this.find(parent => parent.node === ret.node)) return;
if (this.find((parent) => parent.node === ret.node)) return;
return ret;
}
} else if (this.isTypeCastExpression()) {

View File

@ -1,3 +1,4 @@
/* eslint max-len: 0 */
// This file contains methods that modify the path/node in some ways.
import { PATH_CACHE_KEY } from "./constants";

View File

@ -1,3 +1,4 @@
/* eslint max-len: 0 */
// This file contains methods responsible for replacing a node with another.
import codeFrame from "babel-code-frame";

View File

@ -81,7 +81,7 @@ export default class Binding {
reference(path: NodePath) {
this.referenced = true;
this.references++;
this.referencePaths.push(path)
this.referencePaths.push(path);
}
/**

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
import includes from "lodash/collection/includes";
import repeating from "repeating";
import Renamer from "./lib/renamer";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
export const STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
export const FLATTENABLE_KEYS = ["body", "expressions"];
export const FOR_INIT_KEYS = ["left", "init"];

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
import * as t from "../index";
@ -21,7 +22,10 @@ import defineType, {
defineType("ArrayExpression", {
fields: {
elements: {
validate: chain(assertValueType("array"), assertEach(assertNodeOrValueType("null", "Expression", "SpreadElement"))),
validate: chain(
assertValueType("array"),
assertEach(assertNodeOrValueType("null", "Expression", "SpreadElement"))
),
default: [],
}
},
@ -462,7 +466,10 @@ defineType("ObjectExpression", {
aliases: ["Expression"],
fields: {
properties: {
validate: chain(assertValueType("array"), assertEach(assertNodeType("ObjectMethod", "ObjectProperty", "SpreadProperty")))
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("ObjectMethod", "ObjectProperty", "SpreadProperty"))
)
}
}
});

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
import defineType, {
assertNodeType,
@ -181,7 +182,10 @@ defineType("ImportDeclaration", {
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
fields: {
specifiers: {
validate: chain(assertValueType("array"), assertEach(assertNodeType("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier")))
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier"))
)
},
source: {
validate: assertNodeType("StringLiteral")

View File

@ -34,7 +34,9 @@ export function assertEach(callback: Function): Function {
export function assertOneOf(...vals): Function {
function validate(node, key, val) {
if (vals.indexOf(val) < 0) {
throw new TypeError(`Property ${key} expected value to be one of ${JSON.stringify(vals)} but got ${JSON.stringify(val)}`);
throw new TypeError(
`Property ${key} expected value to be one of ${JSON.stringify(vals)} but got ${JSON.stringify(val)}`
);
}
}
@ -55,7 +57,10 @@ export function assertNodeType(...types: Array<string>): Function {
}
if (!valid) {
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val && val.type)}`);
throw new TypeError(
`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} ` +
`but instead got ${JSON.stringify(val && val.type)}`
);
}
}
@ -76,7 +81,10 @@ export function assertNodeOrValueType(...types: Array<string>): Function {
}
if (!valid) {
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val && val.type)}`);
throw new TypeError(
`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} ` +
`but instead got ${JSON.stringify(val && val.type)}`
);
}
}

View File

@ -117,7 +117,10 @@ export function isType(nodeType: string, targetType: string): boolean {
each(t.BUILDER_KEYS, function (keys, type) {
function builder() {
if (arguments.length > keys.length) {
throw new Error(`t.${type}: Too many arguments passed. Received ${arguments.length} but can receive no more than ${keys.length}`);
throw new Error(
`t.${type}: Too many arguments passed. Received ${arguments.length} but can receive ` +
`no more than ${keys.length}`
);
}
let node = {};
@ -149,20 +152,20 @@ each(t.BUILDER_KEYS, function (keys, type) {
* Description
*/
for (let type in t.DEPRECATED_KEYS) {
let newType = t.DEPRECATED_KEYS[type];
for (let type in t.DEPRECATED_KEYS) {
let newType = t.DEPRECATED_KEYS[type];
function proxy(fn) {
return function () {
console.trace(`The node type ${type} has been renamed to ${newType}`);
return fn.apply(this, arguments);
};
}
function proxy(fn) {
return function () {
console.trace(`The node type ${type} has been renamed to ${newType}`);
return fn.apply(this, arguments);
};
}
t[type] = t[type[0].toLowerCase() + type.slice(1)] = proxy(t[newType]);
t[`is${type}`] = proxy(t[`is${newType}`]);
t[`assert${type}`] = proxy(t[`assert${newType}`]);
}
t[type] = t[type[0].toLowerCase() + type.slice(1)] = proxy(t[newType]);
t[`is${type}`] = proxy(t[`is${newType}`]);
t[`assert${type}`] = proxy(t[`assert${newType}`]);
}
/**
* Description

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint indent: 0 */
import { getBindingIdentifiers } from "./retrievers";
import esutils from "esutils";

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
/* eslint no-var: 0 */
var babylon = require("..");
var fs = require("fs");

View File

@ -1,4 +1,5 @@
/* @flow */
/* eslint max-len: 0 */
/**
* Based on the comment attachment algorithm used in espree and estraverse.

View File

@ -1,3 +1,6 @@
/* eslint indent: 0 */
/* eslint max-len: 0 */
// A recursive descent parser operates by defining functions for all
// syntactic elements, and recursively calling those, each function
// advancing the input stream and returning an AST node. Precedence
@ -969,7 +972,7 @@ pp.parseAwait = function (node) {
this.unexpected();
}
if (this.match(tt.star)) {
this.raise(node.start, "await* has been removed from the async functions proposal. Use Promise.all() instead.")
this.raise(node.start, "await* has been removed from the async functions proposal. Use Promise.all() instead.");
}
node.argument = this.parseMaybeUnary();
return this.finishNode(node, "AwaitExpression");

View File

@ -36,7 +36,7 @@ export default class Parser extends Tokenizer {
if (plugins.indexOf("flow") >= 0) {
// ensure flow plugin loads last
plugins = plugins.filter(plugin => plugin !== "flow");
plugins = plugins.filter((plugin) => plugin !== "flow");
plugins.push("flow");
}

View File

@ -1,3 +1,5 @@
/* eslint indent: 0 */
import { types as tt } from "../tokenizer/types";
import Parser from "./index";
import { reservedWords } from "../util/identifier";

View File

@ -1,3 +1,6 @@
/* eslint indent: 0 */
/* eslint max-len: 0 */
import { types as tt } from "../tokenizer/types";
import Parser from "./index";
import { lineBreak } from "../util/whitespace";

View File

@ -1,3 +1,6 @@
/* eslint indent: 0 */
/* eslint max-len: 0 */
import { types as tt } from "../tokenizer/types";
import Parser from "../parser";
@ -115,8 +118,7 @@ pp.flowParseDeclareInterface = function (node) {
this.next();
this.flowParseInterfaceish(node);
return this.finishNode(node, "DeclareInterface");
}
};
// Interfaces
@ -920,7 +922,7 @@ export default function (instance) {
node.typeParameters = null;
}
implemented.push(this.finishNode(node, "ClassImplements"));
} while (this.eat(tt.comma))
} while (this.eat(tt.comma));
}
};
});

View File

@ -1,3 +1,5 @@
/* eslint indent: 0 */
import XHTMLEntities from "./xhtml";
import { TokenType, types as tt } from "../../tokenizer/types";
import { TokContext, types as tc } from "../../tokenizer/context";

View File

@ -34,7 +34,7 @@ export const types: {
b_tmpl: new TokContext("${", true),
p_stat: new TokContext("(", false),
p_expr: new TokContext("(", true),
q_tmpl: new TokContext("`", true, true, p => p.readTmplToken()),
q_tmpl: new TokContext("`", true, true, (p) => p.readTmplToken()),
f_expr: new TokContext("function", true)
};
@ -78,7 +78,8 @@ tt.dollarBraceL.updateContext = function () {
};
tt.parenL.updateContext = function (prevType) {
let statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while;
let statementParens = prevType === tt._if || prevType === tt._for ||
prevType === tt._with || prevType === tt._while;
this.state.context.push(statementParens ? types.p_stat : types.p_expr);
this.state.exprAllowed = true;
};

View File

@ -1,4 +1,6 @@
/* @noflow */
/* eslint max-len: 0 */
/* eslint indent: 0 */
import type { TokenType } from "./types";
import { isIdentifierStart, isIdentifierChar, isKeyword } from "../util/identifier";

View File

@ -1,3 +1,5 @@
/* eslint max-len: 0 */
// This is a trick taken from Esprima. It turns out that, on
// non-Chrome browsers, to check whether a string is in a set, a
// predicate containing a big ugly `switch` statement is faster than