From 2827ff6b01dcce69e9d3c0402e96b52b3a2a47ee Mon Sep 17 00:00:00 2001 From: Sam Goldman Date: Tue, 1 Mar 2016 21:02:55 -0800 Subject: [PATCH] Remove flow --- packages/babel-cli/src/babel-doctor/index.js | 2 +- packages/babel-core/src/api/browser.js | 8 +- packages/babel-core/src/api/node.js | 4 +- packages/babel-core/src/helpers/resolve.js | 2 +- packages/babel-core/src/store.js | 4 +- .../src/tools/build-external-helpers.js | 5 +- .../src/transformation/file/logger.js | 20 ++-- .../src/transformation/file/metadata.js | 4 +- .../file/options/option-manager.js | 47 ++------ .../src/transformation/plugin-pass.js | 8 +- packages/babel-generator/src/index.js | 29 +---- packages/babel-generator/src/printer.js | 4 +- packages/babel-generator/src/whitespace.js | 4 +- .../src/index.js | 3 +- .../src/index.js | 10 +- .../babel-helper-call-delegate/src/index.js | 3 +- packages/babel-helper-define-map/src/index.js | 12 +- .../src/index.js | 12 +- .../babel-helper-explode-class/src/index.js | 5 +- packages/babel-helper-fixtures/src/index.js | 28 +---- .../src/index.js | 4 +- .../babel-helper-hoist-variables/src/index.js | 4 +- .../babel-helper-replace-supers/src/index.js | 34 +----- .../src/index.js | 8 +- .../src/index.js | 4 +- .../src/index.js | 4 +- .../src/index.js | 4 +- .../src/index.js | 2 +- .../src/index.js | 13 +-- .../src/vanilla.js | 13 +-- .../src/index.js | 2 +- .../src/index.js | 8 +- .../src/index.js | 2 +- .../src/index.js | 2 +- .../src/index.js | 2 +- .../src/default.js | 2 +- .../src/destructuring.js | 2 +- .../src/index.js | 3 +- .../src/rest.js | 2 +- .../src/index.js | 2 +- .../src/index.js | 6 +- .../src/index.js | 2 +- .../src/index.js | 2 +- .../src/index.js | 4 +- .../src/index.js | 2 +- .../src/index.js | 2 +- .../src/index.js | 2 +- .../src/index.js | 2 +- packages/babel-template/src/index.js | 4 +- packages/babel-traverse/src/context.js | 18 +-- packages/babel-traverse/src/index.js | 18 +-- packages/babel-traverse/src/path/ancestry.js | 13 +-- packages/babel-traverse/src/path/comments.js | 4 +- packages/babel-traverse/src/path/context.js | 8 +- .../babel-traverse/src/path/conversion.js | 2 +- .../babel-traverse/src/path/evaluation.js | 12 +- packages/babel-traverse/src/path/family.js | 15 ++- packages/babel-traverse/src/path/index.js | 48 ++------ .../src/path/inference/index.js | 17 ++- .../src/path/inference/inferer-reference.js | 5 +- .../babel-traverse/src/path/introspection.js | 19 ++- packages/babel-traverse/src/path/removal.js | 2 +- .../babel-traverse/src/path/replacement.js | 10 +- packages/babel-traverse/src/scope/binding.js | 19 +-- packages/babel-traverse/src/scope/index.js | 101 ++++++++-------- packages/babel-traverse/src/visitors.js | 10 +- packages/babel-types/src/definitions/core.js | 1 - packages/babel-types/src/index.js | 2 +- packages/babel-types/src/validators.js | 2 +- packages/babylon/src/parser/expression.js | 4 +- packages/babylon/src/parser/lval.js | 6 +- packages/babylon/src/parser/node.js | 9 +- packages/babylon/src/parser/statement.js | 6 +- packages/babylon/src/plugins/flow.js | 2 +- packages/babylon/src/tokenizer/state.js | 110 +++++------------- 75 files changed, 278 insertions(+), 542 deletions(-) diff --git a/packages/babel-cli/src/babel-doctor/index.js b/packages/babel-cli/src/babel-doctor/index.js index 3bf118d240..3e171e04c3 100644 --- a/packages/babel-cli/src/babel-doctor/index.js +++ b/packages/babel-cli/src/babel-doctor/index.js @@ -36,7 +36,7 @@ while (nodeModulesDirectories.length) { let loc = nodeModulesDirectories.shift(); if (!fs.existsSync(loc)) continue; - let packagesNames: Array = fs.readdirSync(loc); + let packagesNames = fs.readdirSync(loc); for (let packageName of packagesNames) { if (packageName[0] === ".") continue; diff --git a/packages/babel-core/src/api/browser.js b/packages/babel-core/src/api/browser.js index 31731b6335..cd78e66d64 100644 --- a/packages/babel-core/src/api/browser.js +++ b/packages/babel-core/src/api/browser.js @@ -4,11 +4,11 @@ import { transform } from "./node"; export * from "./node"; -export function run(code: string, opts: Object = {}): any { +export function run(code, opts = {}) { return new Function(transform(code, opts).code)(); } -export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) { +export function load(url, callback, opts = {}, hold) { opts.filename = opts.filename || url; let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest(); @@ -32,7 +32,7 @@ export function load(url: string, callback: Function, opts: Object = {}, hold?: } function runScripts() { - let scripts: Array | Object> = []; + let scripts = []; let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"]; let index = 0; @@ -53,7 +53,7 @@ function runScripts() { * Load, transform, and execute all scripts. */ - function run(script: Object, i: number) { + function run(script, i) { let opts = {}; if (script.src) { diff --git a/packages/babel-core/src/api/node.js b/packages/babel-core/src/api/node.js index 4cd086ea0b..294621c909 100644 --- a/packages/babel-core/src/api/node.js +++ b/packages/babel-core/src/api/node.js @@ -42,7 +42,7 @@ export let transformFromAst = pipeline.transformFromAst.bind(pipeline); // -export function transformFile(filename: string, opts?: Object, callback: Function) { +export function transformFile(filename, opts, callback) { if (isFunction(opts)) { callback = opts; opts = {}; @@ -69,7 +69,7 @@ export function transformFile(filename: string, opts?: Object, callback: Functio }); } -export function transformFileSync(filename: string, opts?: Object = {}): string { +export function transformFileSync(filename, opts = {}) { opts.filename = filename; return transform(fs.readFileSync(filename, "utf8"), opts); } diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/helpers/resolve.js index 623a910cbf..183901fcf1 100644 --- a/packages/babel-core/src/helpers/resolve.js +++ b/packages/babel-core/src/helpers/resolve.js @@ -3,7 +3,7 @@ import path from "path"; let relativeModules = {}; -export default function (loc: string, relative: string = process.cwd()): ?string { +export default function (loc, relative = process.cwd()) { // we're in the browser, probably if (typeof Module === "object") return null; diff --git a/packages/babel-core/src/store.js b/packages/babel-core/src/store.js index fab3d10f34..ee4dc3669a 100644 --- a/packages/babel-core/src/store.js +++ b/packages/babel-core/src/store.js @@ -4,13 +4,11 @@ export default class Store extends Map { this.dynamicData = {}; } - dynamicData: Object; - setDynamic(key, fn) { this.dynamicData[key] = fn; } - get(key: string): any { + get(key) { if (this.has(key)) { return super.get(key); } else { diff --git a/packages/babel-core/src/tools/build-external-helpers.js b/packages/babel-core/src/tools/build-external-helpers.js index ebc98b6ecd..615f4b0bf8 100644 --- a/packages/babel-core/src/tools/build-external-helpers.js +++ b/packages/babel-core/src/tools/build-external-helpers.js @@ -82,10 +82,7 @@ function buildHelpers(body, namespace, whitelist) { )); }); } -export default function ( - whitelist?: Array, - outputType: "global" | "umd" | "var" = "global", -) { +export default function (whitelist, outputType = "global") { let namespace = t.identifier("babelHelpers"); let builder = function (body) { diff --git a/packages/babel-core/src/transformation/file/logger.js b/packages/babel-core/src/transformation/file/logger.js index 3573c968e4..f1c4a6078a 100644 --- a/packages/babel-core/src/transformation/file/logger.js +++ b/packages/babel-core/src/transformation/file/logger.js @@ -1,4 +1,3 @@ -import type File from "./index"; import buildDebug from "debug/node"; let verboseDebug = buildDebug("babel:verbose"); @@ -7,29 +6,26 @@ let generalDebug = buildDebug("babel"); let seenDeprecatedMessages = []; export default class Logger { - constructor(file: File, filename: string) { + constructor(file, filename) { this.filename = filename; this.file = file; } - filename: string; - file: File; - - _buildMessage(msg: string): string { + _buildMessage(msg) { let parts = `[BABEL] ${this.filename}`; if (msg) parts += `: ${msg}`; return parts; } - warn(msg: string) { + warn(msg) { console.warn(this._buildMessage(msg)); } - error(msg: string, Constructor: typeof Error = Error): Error { + error(msg, Constructor = Error) { throw new Constructor(this._buildMessage(msg)); } - deprecate(msg: string) { + deprecate(msg) { if (this.file.opts && this.file.opts.suppressDeprecationMessages) return; msg = this._buildMessage(msg); @@ -43,15 +39,15 @@ export default class Logger { console.error(msg); } - verbose(msg: string) { + verbose(msg) { if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg)); } - debug(msg: string) { + debug(msg) { if (generalDebug.enabled) generalDebug(this._buildMessage(msg)); } - deopt(node: Object, msg: string) { + deopt(node, msg) { this.debug(msg); } } diff --git a/packages/babel-core/src/transformation/file/metadata.js b/packages/babel-core/src/transformation/file/metadata.js index 0183006ffb..b76b218396 100644 --- a/packages/babel-core/src/transformation/file/metadata.js +++ b/packages/babel-core/src/transformation/file/metadata.js @@ -21,7 +21,7 @@ export let ImportDeclaration = { specifiers }); - for (let specifier of (path.get("specifiers"): Array)) { + for (let specifier of path.get("specifiers")) { let local = specifier.node.local.name; if (specifier.isImportDefaultSpecifier()) { @@ -77,7 +77,7 @@ export function ExportDeclaration(path, file) { } if (path.isExportNamedDeclaration() && node.specifiers) { - for (let specifier of (node.specifiers: Array)) { + for (let specifier of node.specifiers) { let exported = specifier.exported.name; exports.exported.push(exported); diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index 3739fa6aa7..0e4b42840a 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -1,7 +1,6 @@ /* eslint max-len: 0 */ import * as context from "../../../api/node"; -import type Logger from "../logger"; import Plugin from "../../plugin"; import * as messages from "babel-messages"; import { normaliseOptions } from "./index"; @@ -33,49 +32,19 @@ function exists(filename) { } } -type PluginObject = { - pre?: Function; - post?: Function; - manipulateOptions?: Function; - - visitor: ?{ - [key: string]: Function | { - enter?: Function | Array; - exit?: Function | Array; - } - }; -}; - -type MergeOptions = { - options?: Object, - extending?: Object, - alias: string, - loc?: string, - dirname?: string -}; - export default class OptionManager { - constructor(log?: Logger) { + constructor(log) { this.resolvedConfigs = []; this.options = OptionManager.createBareOptions(); this.log = log; } - resolvedConfigs: Array; - options: Object; - log: ?Logger; - - static memoisedPlugins: Array<{ - container: Function; - plugin: Plugin; - }>; - static memoisePluginContainer(fn, loc, i, alias) { - for (let cache of (OptionManager.memoisedPlugins: Array)) { + for (let cache of OptionManager.memoisedPlugins) { if (cache.container === fn) return cache.plugin; } - let obj: ?PluginObject; + let obj; if (typeof fn === "function") { obj = fn(context); @@ -156,7 +125,7 @@ export default class OptionManager { }); } - addConfig(loc: string, key?: string, json = json5): boolean { + addConfig(loc, key, json = json5) { if (this.resolvedConfigs.indexOf(loc) >= 0) { return false; } @@ -198,7 +167,7 @@ export default class OptionManager { alias, loc, dirname - }: MergeOptions) { + }) { alias = alias || "foreign"; if (!rawOpts) return; @@ -303,7 +272,7 @@ export default class OptionManager { * Merges all presets into the main options in case we are not in the * "pass per preset" mode. Otherwise, options are calculated per preset. */ - mergePresets(presets: Array, dirname: string) { + mergePresets(presets, dirname) { this.resolvePresets(presets, dirname, (presetOpts, presetLoc) => { this.mergeOptions({ options: presetOpts, @@ -318,7 +287,7 @@ export default class OptionManager { * Resolves presets options which can be either direct object data, * or a module name to require. */ - resolvePresets(presets: Array, dirname: string, onResolve?) { + resolvePresets(presets, dirname, onResolve) { return presets.map((val) => { if (typeof val === "string") { let presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname); @@ -407,7 +376,7 @@ export default class OptionManager { } } - init(opts: Object = {}): Object { + init(opts = {}) { let filename = opts.filename; // resolve all .babelrc files diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 10b7d9381b..73fa00bab8 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -1,20 +1,14 @@ -import type Plugin from "./plugin"; import Store from "../store"; import traverse from "babel-traverse"; -import File from "./file"; export default class PluginPass extends Store { - constructor(file: File, plugin: Plugin, options: Object = {}) { + constructor(file, plugin, options = {}) { super(); this.plugin = plugin; this.file = file; this.opts = options; } - plugin: Plugin; - file: File; - opts: Object; - transform() { let file = this.file; file.log.debug(`Start transformer ${this.key}`); diff --git a/packages/babel-generator/src/index.js b/packages/babel-generator/src/index.js index f65d065520..bef9d3cfcd 100644 --- a/packages/babel-generator/src/index.js +++ b/packages/babel-generator/src/index.js @@ -34,33 +34,6 @@ export class CodeGenerator extends Printer { this.map = new SourceMap(position, opts, code); } - format: { - shouldPrintComment: (comment: string) => boolean; - retainLines: boolean; - comments: boolean; - auxiliaryCommentBefore: string; - auxiliaryCommentAfter: string; - compact: boolean | "auto"; - minified: boolean; - quotes: "single" | "double"; - concise: boolean; - indent: { - adjustMultilineComment: boolean; - style: string; - base: number; - } - }; - - auxiliaryCommentBefore: string; - auxiliaryCommentAfter: string; - whitespace: Whitespace; - position: Position; - map: SourceMap; - comments: Array; - tokens: Array; - opts: Object; - ast: Object; - /** * Normalize generator options, setting defaults. * @@ -161,7 +134,7 @@ export class CodeGenerator extends Printer { } } -export default function (ast: Object, opts: Object, code: string): Object { +export default function (ast, opts, code) { let gen = new CodeGenerator(ast, opts, code); return gen.generate(); } diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index a8c843d82c..89d1c1d1f4 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -120,7 +120,7 @@ export default class Printer extends Buffer { printMethod.call(this, node, parent); } - printJoin(nodes: ?Array, parent: Object, opts = {}) { + printJoin(nodes, parent, opts = {}) { if (!nodes || !nodes.length) return; let len = nodes.length; @@ -310,7 +310,7 @@ export default class Printer extends Buffer { this.newline(this.whitespace.getNewlinesAfter(comment)); } - printComments(comments?: Array) { + printComments(comments) { if (!comments || !comments.length) return; for (let comment of comments) { diff --git a/packages/babel-generator/src/whitespace.js b/packages/babel-generator/src/whitespace.js index 035f5bb272..f2440b2ce3 100644 --- a/packages/babel-generator/src/whitespace.js +++ b/packages/babel-generator/src/whitespace.js @@ -82,10 +82,10 @@ export default class Whitespace { * Find a token between start and end. */ - _findToken(test: Function, start: number, end: number): number { + _findToken(test, start, end) { if (start >= end) return -1; const middle = (start + end) >>> 1; - const match: number = test(this.tokens[middle]); + const match = test(this.tokens[middle]); if (match < 0) { return this._findToken(test, middle + 1, end); } else if (match > 0) { diff --git a/packages/babel-helper-bindify-decorators/src/index.js b/packages/babel-helper-bindify-decorators/src/index.js index 750c00f56f..b1e4e9d646 100644 --- a/packages/babel-helper-bindify-decorators/src/index.js +++ b/packages/babel-helper-bindify-decorators/src/index.js @@ -1,7 +1,6 @@ -import type { NodePath } from "babel-traverse"; import * as t from "babel-types"; -export default function bindifyDecorators(decorators: Array): Array { +export default function bindifyDecorators(decorators) { for (let decoratorPath of decorators) { let decorator = decoratorPath.node; let expression = decorator.expression; diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js index 3e6094c490..f0da00b55e 100644 --- a/packages/babel-helper-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -1,14 +1,6 @@ import esutils from "esutils"; import * as t from "babel-types"; -type ElementState = { - tagExpr: Object; // tag node - tagName: string; // raw string tag name - args: Array; // array of call arguments - call?: Object; // optional call property that can be set to override the call expression returned - pre?: Function; // function called with (state: ElementState) before building attribs - post?: Function; // function called with (state: ElementState) after building attribs -}; export default function (opts) { let visitor = {}; @@ -89,7 +81,7 @@ export default function (opts) { tagName = tagExpr.value; } - let state: ElementState = { + let state = { tagExpr: tagExpr, tagName: tagName, args: args diff --git a/packages/babel-helper-call-delegate/src/index.js b/packages/babel-helper-call-delegate/src/index.js index 1319a662fc..5ebb1379a2 100644 --- a/packages/babel-helper-call-delegate/src/index.js +++ b/packages/babel-helper-call-delegate/src/index.js @@ -1,5 +1,4 @@ import hoistVariables from "babel-helper-hoist-variables"; -import type { NodePath } from "babel-traverse"; import * as t from "babel-types"; let visitor = { @@ -18,7 +17,7 @@ let visitor = { } }; -export default function (path: NodePath, scope = path.scope) { +export default function (path, scope = path.scope) { let { node } = path; let container = t.functionExpression(null, [], node.body, node.generator, node.async); diff --git a/packages/babel-helper-define-map/src/index.js b/packages/babel-helper-define-map/src/index.js index aa0e2af5a7..09023cb079 100644 --- a/packages/babel-helper-define-map/src/index.js +++ b/packages/babel-helper-define-map/src/index.js @@ -5,7 +5,7 @@ import each from "lodash/collection/each"; import has from "lodash/object/has"; import * as t from "babel-types"; -function toKind(node: Object) { +function toKind(node) { if (t.isClassMethod(node) || t.isObjectMethod(node)) { if (node.kind === "get" || node.kind === "set") { return node.kind; @@ -15,7 +15,7 @@ function toKind(node: Object) { return "value"; } -export function push(mutatorMap: Object, node: Object, kind: string, file, scope?): Object { +export function push(mutatorMap, node, kind, file, scope) { let alias = t.toKeyAlias(node); // @@ -75,7 +75,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope return map; } -export function hasComputed(mutatorMap: Object): boolean { +export function hasComputed(mutatorMap) { for (let key in mutatorMap) { if (mutatorMap[key]._computed) { return true; @@ -84,7 +84,7 @@ export function hasComputed(mutatorMap: Object): boolean { return false; } -export function toComputedObjectFromClass(obj: Object): Object { +export function toComputedObjectFromClass(obj) { let objExpr = t.arrayExpression([]); for (let i = 0; i < obj.properties.length; i++) { @@ -97,7 +97,7 @@ export function toComputedObjectFromClass(obj: Object): Object { return objExpr; } -export function toClassObject(mutatorMap: Object): Object { +export function toClassObject(mutatorMap) { let objExpr = t.objectExpression([]); each(mutatorMap, function (map) { @@ -124,7 +124,7 @@ export function toClassObject(mutatorMap: Object): Object { return objExpr; } -export function toDefineObject(mutatorMap: Object): Object { +export function toDefineObject(mutatorMap) { each(mutatorMap, function (map) { if (map.value) map.writable = t.booleanLiteral(true); map.configurable = t.booleanLiteral(true); diff --git a/packages/babel-helper-explode-assignable-expression/src/index.js b/packages/babel-helper-explode-assignable-expression/src/index.js index fb8024d8af..c8c3a60daf 100644 --- a/packages/babel-helper-explode-assignable-expression/src/index.js +++ b/packages/babel-helper-explode-assignable-expression/src/index.js @@ -1,4 +1,3 @@ -import type { Scope } from "babel-traverse"; import * as t from "babel-types"; function getObjRef(node, nodes, file, scope) { @@ -46,16 +45,7 @@ function getPropRef(node, nodes, file, scope) { return temp; } -export default function ( - node: Object, - nodes: Array, - file, - scope: Scope, - allowedSingleIdent?: boolean, -): { - uid: Object; - ref: Object; -} { +export default function (node, nodes, file, scope, allowedSingleIdent) { let obj; if (t.isIdentifier(node) && allowedSingleIdent) { obj = node; diff --git a/packages/babel-helper-explode-class/src/index.js b/packages/babel-helper-explode-class/src/index.js index 1091e1ba06..5be9817d61 100644 --- a/packages/babel-helper-explode-class/src/index.js +++ b/packages/babel-helper-explode-class/src/index.js @@ -1,5 +1,4 @@ import bindifyDecorators from "babel-helper-bindify-decorators"; -import type { NodePath } from "babel-traverse"; import * as t from "babel-types"; export default function (classPath) { @@ -15,7 +14,7 @@ export default function (classPath) { path.replaceWith(uid); } - function memoiseDecorators(paths: Array) { + function memoiseDecorators(paths) { if (!Array.isArray(paths) || !paths.length) return; // ensure correct evaluation order of decorators @@ -32,7 +31,7 @@ export default function (classPath) { maybeMemoise(classPath.get("superClass")); memoiseDecorators(classPath.get("decorators"), true); - let methods: Array = classPath.get("body.body"); + let methods = classPath.get("body.body"); for (let methodPath of methods) { if (methodPath.is("computed")) { maybeMemoise(methodPath.get("key")); diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.js index 7e1bfcb24f..4a648d2fdf 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.js @@ -10,35 +10,13 @@ function humanize(val, noext) { return val.replace(/-/g, " "); } -type TestFile = { - loc: string; - code: string; - filename: string; -}; - -type Test = { - title: string; - disabled: boolean; - options: Object; - exec: TestFile; - actual: TestFile; - expected: TestFile; -}; - -type Suite = { - options: Object; - tests: Array; - title: string; - filename: string; -}; - function assertDirectory(loc) { if (!fs.statSync(loc).isDirectory()) { throw new Error(`Expected ${loc} to be a directory.`); } } -function shouldIgnore(name, blacklist?: Array) { +function shouldIgnore(name, blacklist) { if (blacklist && blacklist.indexOf(name) >= 0) { return true; } @@ -49,7 +27,7 @@ function shouldIgnore(name, blacklist?: Array) { return name[0] === "." || ext === ".md" || base === "LICENSE" || base === "options"; } -export default function get(entryLoc): Array { +export default function get(entryLoc) { let suites = []; let rootOpts = {}; @@ -147,7 +125,7 @@ export default function get(entryLoc): Array { return suites; } -export function multiple(entryLoc, ignore?: Array) { +export function multiple(entryLoc, ignore) { let categories = {}; for (let name of fs.readdirSync(entryLoc)) { diff --git a/packages/babel-helper-get-function-arity/src/index.js b/packages/babel-helper-get-function-arity/src/index.js index a3c60a5a61..c9d48401c4 100644 --- a/packages/babel-helper-get-function-arity/src/index.js +++ b/packages/babel-helper-get-function-arity/src/index.js @@ -1,7 +1,7 @@ import * as t from "babel-types"; -export default function (node): number { - let params: Array = node.params; +export default function (node) { + let params = node.params; for (let i = 0; i < params.length; i++) { let param = params[i]; if (t.isAssignmentPattern(param) || t.isRestElement(param)) { diff --git a/packages/babel-helper-hoist-variables/src/index.js b/packages/babel-helper-hoist-variables/src/index.js index de36a3f591..a41b3963e6 100644 --- a/packages/babel-helper-hoist-variables/src/index.js +++ b/packages/babel-helper-hoist-variables/src/index.js @@ -14,7 +14,7 @@ let visitor = { let nodes = []; - let declarations: Array = path.get("declarations"); + let declarations = path.get("declarations"); let firstId; for (let declar of declarations) { @@ -40,6 +40,6 @@ let visitor = { } }; -export default function (path, emit: Function, kind: "var" | "let" = "var") { +export default function (path, emit, kind = "var") { path.traverse(visitor, { kind, emit }); } diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index 76b05d7ad4..42aa5d23be 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -1,6 +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"; import * as t from "babel-types"; @@ -73,7 +72,7 @@ let visitor = { }; export default class ReplaceSupers { - constructor(opts: Object, inClass?: boolean = false) { + constructor(opts, inClass = false) { this.forceSuperMemoisation = opts.forceSuperMemoisation; this.methodPath = opts.methodPath; this.methodNode = opts.methodNode; @@ -91,27 +90,6 @@ export default class ReplaceSupers { this.thises = []; } - forceSuperMemoisation: boolean; - methodPath: NodePath; - methodNode: Object; - superRef: Object; - isStatic: boolean; - hasSuper: boolean; - inClass: boolean; - isLoose: boolean; - scope: Scope; - file; - opts: { - forceSuperMemoisation: boolean; - getObjetRef: Function; - methodPath: NodePath; - methodNode: Object; - superRef: Object; - isStatic: boolean; - isLoose: boolean; - file: any; - }; - getObjectRef() { return this.opts.objectRef || this.opts.getObjectRef(); } @@ -125,7 +103,7 @@ export default class ReplaceSupers { * */ - setSuperProperty(property: Object, value: Object, isComputed: boolean): Object { + setSuperProperty(property, value, isComputed) { return t.callExpression( this.file.addHelper("set"), [ @@ -151,7 +129,7 @@ export default class ReplaceSupers { * */ - getSuperProperty(property: Object, isComputed: boolean): Object { + getSuperProperty(property, isComputed) { return t.callExpression( this.file.addHelper("get"), [ @@ -171,7 +149,7 @@ export default class ReplaceSupers { this.methodPath.traverse(visitor, this); } - getLooseSuperProperty(id: Object, parent: Object) { + getLooseSuperProperty(id, parent) { let methodNode = this.methodNode; let superRef = this.superRef || t.identifier("Function"); @@ -187,7 +165,7 @@ export default class ReplaceSupers { } } - looseHandle(path: NodePath) { + looseHandle(path) { let node = path.node; if (path.isSuper()) { return this.getLooseSuperProperty(node, path.parent); @@ -221,7 +199,7 @@ export default class ReplaceSupers { } } - specHandle(path: NodePath) { + specHandle(path) { let property; let computed; let args; diff --git a/packages/babel-helper-transform-fixture-test-runner/src/index.js b/packages/babel-helper-transform-fixture-test-runner/src/index.js index 5dbf3db89e..b1660a14f5 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.js @@ -111,13 +111,7 @@ function runExec(opts, execCode) { return fn.apply(null, Object.values(sandbox)); } -export default function ( - fixturesLoc: string, - name: string, - suiteOpts = {}, - taskOpts = {}, - dynamicOpts?: Function, -) { +export default function (fixturesLoc, name, suiteOpts = {}, taskOpts = {}, dynamicOpts) { let suites = getFixtures(fixturesLoc); for (let testSuite of suites) { diff --git a/packages/babel-plugin-check-es2015-constants/src/index.js b/packages/babel-plugin-check-es2015-constants/src/index.js index 4269b0385c..307c8d610d 100644 --- a/packages/babel-plugin-check-es2015-constants/src/index.js +++ b/packages/babel-plugin-check-es2015-constants/src/index.js @@ -6,11 +6,11 @@ export default function ({ messages }) { let binding = scope.bindings[name]; if (binding.kind !== "const" && binding.kind !== "module") continue; - for (let violation of (binding.constantViolations: Array)) { + for (let violation of binding.constantViolations) { throw violation.buildCodeFrameError(messages.get("readOnly", name)); } } - }, + } } }; } diff --git a/packages/babel-plugin-transform-class-constructor-call/src/index.js b/packages/babel-plugin-transform-class-constructor-call/src/index.js index 5d2e80f90f..880be0c16b 100644 --- a/packages/babel-plugin-transform-class-constructor-call/src/index.js +++ b/packages/babel-plugin-transform-class-constructor-call/src/index.js @@ -17,8 +17,8 @@ let buildWrapper = template(` export default function ({ types: t }) { let ALREADY_VISITED = Symbol(); - function findConstructorCall(path): ?Object { - let methods: Array = path.get("body.body"); + function findConstructorCall(path) { + let methods = path.get("body.body"); for (let method of methods) { if (method.node.kind === "constructorCall") { diff --git a/packages/babel-plugin-transform-decorators/src/index.js b/packages/babel-plugin-transform-decorators/src/index.js index ae3b5469cf..9ecee53b94 100644 --- a/packages/babel-plugin-transform-decorators/src/index.js +++ b/packages/babel-plugin-transform-decorators/src/index.js @@ -54,13 +54,13 @@ export default function ({ types: t }) { if (path.isClass()) { if (path.node.decorators) return true; - for (let method of (path.node.body.body: Array)) { + for (let method of path.node.body.body) { if (method.decorators) { return true; } } } else if (path.isObjectExpression()) { - for (let prop of (path.node.properties: Array)) { + for (let prop of path.node.properties) { if (prop.decorators) { return true; } diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js index a1aac15dc3..1cb3d0e44f 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js @@ -1,6 +1,6 @@ export default function ({ types: t }) { function statementList(key, path) { - let paths: Array = path.get(key); + let paths = path.get(key); for (let path of paths) { let func = path.node; diff --git a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js index 3ab7b74cfd..825b665f2a 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js @@ -1,8 +1,5 @@ /* eslint max-len: 0 */ -import type NodePath from "babel-traverse"; -import type Scope from "babel-traverse"; -import type File from "../../../file"; import traverse from "babel-traverse"; import { visitor as tdzVisitor } from "./tdz"; import * as t from "babel-types"; @@ -276,7 +273,7 @@ let loopVisitor = { }; class BlockScoping { - constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) { + constructor(loopPath, blockPath, parent, scope, file) { this.parent = parent; this.scope = scope; this.file = file; @@ -445,7 +442,7 @@ class BlockScoping { * Push the closure to the body. */ - buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { + buildClosure(ret, call) { let has = this.has; if (has.hasReturn || has.hasBreakContinue) { this.buildHas(ret, call); @@ -539,7 +536,7 @@ class BlockScoping { * later on. */ - checkLoop(): Object { + checkLoop() { let state = { hasBreakContinue: false, ignoreLabeless: false, @@ -571,7 +568,7 @@ class BlockScoping { * their declarations hoisted to before the closure wrapper. */ - pushDeclar(node: { type: "VariableDeclaration" }): Array { + pushDeclar(node) { let declars = []; let names = t.getBindingIdentifiers(node); for (let name in names) { @@ -593,7 +590,7 @@ class BlockScoping { return replace; } - buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { + buildHas(ret, call) { let body = this.body; body.push(t.variableDeclaration("var", [ diff --git a/packages/babel-plugin-transform-es2015-classes/src/vanilla.js b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js index 83cf2176d9..292bdb49ac 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/vanilla.js +++ b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js @@ -1,6 +1,5 @@ /* eslint max-len: 0 */ -import type { NodePath } from "babel-traverse"; import { visitors } from "babel-traverse"; import ReplaceSupers from "babel-helper-replace-supers"; import optimiseCall from "babel-helper-optimise-call-expression"; @@ -61,7 +60,7 @@ let findThisesVisitor = visitors.merge([noMethodVisitor, { }]); export default class ClassTransformer { - constructor(path: NodePath, file) { + constructor(path, file) { this.parent = path.parent; this.scope = path.scope; this.node = path.node; @@ -149,7 +148,7 @@ export default class ClassTransformer { return func; } - pushToMap(node, enumerable, kind = "value", scope?) { + pushToMap(node, enumerable, kind = "value", scope) { let mutatorMap; if (node.static) { this.hasStaticDescriptors = true; @@ -176,7 +175,7 @@ export default class ClassTransformer { constructorMeMaybe() { let hasConstructor = false; let paths = this.path.get("body.body"); - for (let path of (paths: Array)) { + for (let path of paths) { hasConstructor = path.equals("kind", "constructor"); if (hasConstructor) break; } @@ -217,7 +216,7 @@ export default class ClassTransformer { } pushBody() { - let classBodyPaths: Array = this.path.get("body.body"); + let classBodyPaths = this.path.get("body.body"); for (let path of classBodyPaths) { let node = path.node; @@ -451,7 +450,7 @@ export default class ClassTransformer { * Push a method to its respective mutatorMap. */ - pushMethod(node: { type: "ClassMethod" }, path?: NodePath) { + pushMethod(node, path) { let scope = path ? path.scope : this.scope; if (node.kind === "method") { @@ -469,7 +468,7 @@ export default class ClassTransformer { * Replace the constructor body of our class. */ - pushConstructor(replaceSupers, method: { type: "ClassMethod" }, path: NodePath) { + pushConstructor(replaceSupers, method, path) { this.bareSupers = replaceSupers.bareSupers; this.superReturns = replaceSupers.returns; diff --git a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js index 4583c1de3c..bc157c15a4 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js @@ -89,7 +89,7 @@ export default function ({ types: t, template }) { exit(path, state) { let { node, parent, scope } = path; let hasComputed = false; - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { hasComputed = prop.computed === true; if (hasComputed) break; } diff --git a/packages/babel-plugin-transform-es2015-destructuring/src/index.js b/packages/babel-plugin-transform-es2015-destructuring/src/index.js index 0c2a651e81..acd254a2f1 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/src/index.js +++ b/packages/babel-plugin-transform-es2015-destructuring/src/index.js @@ -7,7 +7,7 @@ export default function ({ types: t }) { */ function variableDeclarationHasPattern(node) { - for (let declar of (node.declarations: Array)) { + for (let declar of node.declarations) { if (t.isPattern(declar.id)) { return true; } @@ -20,7 +20,7 @@ export default function ({ types: t }) { */ function hasRest(pattern) { - for (let elem of (pattern.elements: Array)) { + for (let elem of pattern.elements) { if (t.isRestElement(elem)) { return true; } @@ -210,7 +210,7 @@ export default function ({ types: t }) { if (pattern.elements.length > arr.elements.length) return; if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false; - for (let elem of (pattern.elements: Array)) { + for (let elem of pattern.elements) { // deopt on holes if (!elem) return false; @@ -218,7 +218,7 @@ export default function ({ types: t }) { if (t.isMemberExpression(elem)) return false; } - for (let elem of (arr.elements: Array)) { + for (let elem of arr.elements) { // deopt on spread elements if (t.isSpreadElement(elem)) return false; } diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index 2f39be67bf..64fc027506 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -160,7 +160,7 @@ export default function () { let hasExports = false; let hasImports = false; - let body: Array = path.get("body"); + let body = path.get("body"); let imports = Object.create(null); let exports = Object.create(null); diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js index 467a12391d..470518f050 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js @@ -92,7 +92,7 @@ export default function ({ types: t }) { ); } - let body: Array = path.get("body"); + let body = path.get("body"); let canHoist = true; for (let path of body) { diff --git a/packages/babel-plugin-transform-es2015-object-super/src/index.js b/packages/babel-plugin-transform-es2015-object-super/src/index.js index 95098fda8a..32c1c67eff 100644 --- a/packages/babel-plugin-transform-es2015-object-super/src/index.js +++ b/packages/babel-plugin-transform-es2015-object-super/src/index.js @@ -30,7 +30,7 @@ export default function ({ types: t }) { let objectRef; let getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj"); - let propPaths: Array = path.get("properties"); + let propPaths = path.get("properties"); for (let propPath of propPaths) { if (propPath.isObjectProperty()) propPath = propPath.get("value"); Property(propPath, propPath.node, path.scope, getObjectRef, file); diff --git a/packages/babel-plugin-transform-es2015-parameters/src/default.js b/packages/babel-plugin-transform-es2015-parameters/src/default.js index 05f1f328e1..24214af486 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/default.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/default.js @@ -22,7 +22,7 @@ let buildCutOff = template(` `); function hasDefaults(node) { - for (let param of (node.params: Array)) { + for (let param of node.params) { if (!t.isIdentifier(param)) return true; } return false; diff --git a/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js index e3a7e10494..7365614476 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js @@ -2,7 +2,7 @@ import * as t from "babel-types"; export let visitor = { Function(path) { - let params: Array = path.get("params"); + let params = path.get("params"); // If there's a rest param, no need to loop through it. Also, we need to // hoist one more level to get `declar` at the right spot. diff --git a/packages/babel-plugin-transform-es2015-parameters/src/index.js b/packages/babel-plugin-transform-es2015-parameters/src/index.js index 6279147062..822febd872 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/index.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/index.js @@ -1,4 +1,3 @@ -import type { NodePath } from "babel-traverse"; import { visitors } from "babel-traverse"; import * as destructuring from "./destructuring"; @@ -10,7 +9,7 @@ export default function () { visitor: visitors.merge([{ ArrowFunctionExpression(path) { // default/rest visitors require access to `arguments` - let params: Array = path.get("params"); + let params = path.get("params"); for (let param of params) { if (param.isRestElement() || param.isAssignmentPattern()) { path.arrowFunctionToShadowed(); diff --git a/packages/babel-plugin-transform-es2015-parameters/src/rest.js b/packages/babel-plugin-transform-es2015-parameters/src/rest.js index bda2cb0557..1143f901de 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/rest.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/rest.js @@ -198,7 +198,7 @@ export let visitor = { // There are only "shorthand" references if (!state.deopted && !state.references.length) { - for (let {path, cause} of (state.candidates: Array)) { + for (let {path, cause} of state.candidates) { switch (cause) { case "indexGetter": optimiseIndexGetter(path, argsId, state.offset); diff --git a/packages/babel-plugin-transform-es2015-spread/src/index.js b/packages/babel-plugin-transform-es2015-spread/src/index.js index d7768cb161..439054c4c2 100644 --- a/packages/babel-plugin-transform-es2015-spread/src/index.js +++ b/packages/babel-plugin-transform-es2015-spread/src/index.js @@ -16,7 +16,7 @@ export default function ({ types: t }) { return false; } - function build(props: Array, scope, state) { + function build(props, scope, state) { let nodes = []; let _props = []; diff --git a/packages/babel-plugin-transform-es2015-template-literals/src/index.js b/packages/babel-plugin-transform-es2015-template-literals/src/index.js index 7359598f99..faf3c13093 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/src/index.js +++ b/packages/babel-plugin-transform-es2015-template-literals/src/index.js @@ -17,7 +17,7 @@ export default function ({ types: t }) { let strings = []; let raw = []; - for (let elem of (quasi.quasis: Array)) { + for (let elem of quasi.quasis) { strings.push(t.stringLiteral(elem.value.cooked)); raw.push(t.stringLiteral(elem.value.raw)); } @@ -37,11 +37,11 @@ export default function ({ types: t }) { }, TemplateLiteral(path, state) { - let nodes: Array = []; + let nodes = []; let expressions = path.get("expressions"); - for (let elem of (path.node.quasis: Array)) { + for (let elem of path.node.quasis) { nodes.push(t.stringLiteral(elem.value.cooked)); let expr = expressions.shift(); diff --git a/packages/babel-plugin-transform-es5-property-mutators/src/index.js b/packages/babel-plugin-transform-es5-property-mutators/src/index.js index 46d810f6f5..fbcacfe335 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/src/index.js +++ b/packages/babel-plugin-transform-es5-property-mutators/src/index.js @@ -6,7 +6,7 @@ export default function ({ types: t }) { ObjectExpression(path, file) { let { node } = path; let hasAny = false; - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { if (prop.kind === "get" || prop.kind === "set") { hasAny = true; break; diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index 11933b0ff8..4594e8b141 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -6,7 +6,7 @@ export default function ({ types: t }) { visitor: { Program(path, { file: { ast: { comments } } }) { - for (let comment of (comments: Array)) { + for (let comment of comments) { if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) { // remove flow directive comment.value = comment.value.replace(FLOW_DIRECTIVE, ""); diff --git a/packages/babel-plugin-transform-object-rest-spread/src/index.js b/packages/babel-plugin-transform-object-rest-spread/src/index.js index ace0dbab89..1a39000ddb 100644 --- a/packages/babel-plugin-transform-object-rest-spread/src/index.js +++ b/packages/babel-plugin-transform-object-rest-spread/src/index.js @@ -1,6 +1,6 @@ export default function ({ types: t }) { function hasSpread(node) { - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { if (t.isSpreadProperty(prop)) { return true; } @@ -24,7 +24,7 @@ export default function ({ types: t }) { props = []; } - for (let prop of (path.node.properties: Array)) { + for (let prop of path.node.properties) { if (t.isSpreadProperty(prop)) { push(); args.push(prop.argument); diff --git a/packages/babel-plugin-transform-proto-to-assign/src/index.js b/packages/babel-plugin-transform-proto-to-assign/src/index.js index 648ee983b3..6cb320abfd 100644 --- a/packages/babel-plugin-transform-proto-to-assign/src/index.js +++ b/packages/babel-plugin-transform-proto-to-assign/src/index.js @@ -45,7 +45,7 @@ export default function ({ types: t }) { let proto; let { node } = path; - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { if (isProtoKey(prop)) { proto = prop.value; pull(node.properties, prop); diff --git a/packages/babel-plugin-transform-react-inline-elements/src/index.js b/packages/babel-plugin-transform-react-inline-elements/src/index.js index 5f394fc3f8..2024996b2e 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -42,7 +42,7 @@ export default function ({ types: t }) { } // props - for (let attr of (open.attributes: Array)) { + for (let attr of open.attributes) { if (isJSXAttributeOfName(attr, "key")) { key = getAttributeValue(attr); } else { diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 32e97505f8..fe3b329d64 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -23,7 +23,7 @@ export default function ({ types: t }) { let { file } = state; let id = state.opts.pragma || "React.createElement"; - for (let comment of (file.ast.comments: Array)) { + for (let comment of file.ast.comments) { let matches = JSX_ANNOTATION_REGEX.exec(comment.value); if (matches) { id = matches[1]; diff --git a/packages/babel-plugin-transform-strict-mode/src/index.js b/packages/babel-plugin-transform-strict-mode/src/index.js index 452f5c9a6b..eb186621ea 100644 --- a/packages/babel-plugin-transform-strict-mode/src/index.js +++ b/packages/babel-plugin-transform-strict-mode/src/index.js @@ -8,7 +8,7 @@ export default function () { let { node } = path; - for (let directive of (node.directives: Array)) { + for (let directive of node.directives) { if (directive.value.value === "use strict") return; } diff --git a/packages/babel-template/src/index.js b/packages/babel-template/src/index.js index ef3cc93190..76e8c9d268 100644 --- a/packages/babel-template/src/index.js +++ b/packages/babel-template/src/index.js @@ -10,7 +10,7 @@ import * as t from "babel-types"; let FROM_TEMPLATE = "_fromTemplate"; //Symbol(); // todo: probably wont get copied over let TEMPLATE_SKIP = Symbol(); -export default function (code: string, opts?: Object): Function { +export default function (code, opts) { // since we lazy parse the template, we get the current stack so we have the // original stack to append if it errors when parsing let stack; @@ -52,7 +52,7 @@ export default function (code: string, opts?: Object): Function { }; } -function useTemplate(ast, nodes?: Array) { +function useTemplate(ast, nodes) { ast = cloneDeep(ast); let { program } = ast; diff --git a/packages/babel-traverse/src/context.js b/packages/babel-traverse/src/context.js index edad4ea598..b5580d28c0 100644 --- a/packages/babel-traverse/src/context.js +++ b/packages/babel-traverse/src/context.js @@ -11,18 +11,12 @@ export default class TraversalContext { this.opts = opts; } - parentPath: NodePath; - scope; - state; - opts; - queue: ?Array = null; - /** * This method does a simple check to determine whether or not we really need to attempt * visit a node. This will prevent us from constructing a NodePath. */ - shouldVisit(node): boolean { + shouldVisit(node) { let opts = this.opts; if (opts.enter || opts.exit) return true; @@ -30,7 +24,7 @@ export default class TraversalContext { if (opts[node.type]) return true; // check if we're going to traverse into this node - let keys: ?Array = t.VISITOR_KEYS[node.type]; + let keys = t.VISITOR_KEYS[node.type]; if (!keys || !keys.length) return false; // we need to traverse into this node so ensure that it has children to traverse into! @@ -41,7 +35,7 @@ export default class TraversalContext { return false; } - create(node, obj, key, listKey): NodePath { + create(node, obj, key, listKey) { return NodePath.get({ parentPath: this.parentPath, parent: node, @@ -51,7 +45,7 @@ export default class TraversalContext { }); } - maybeQueue(path, notPriority?: boolean) { + maybeQueue(path, notPriority) { if (this.trap) { throw new Error("Infinite cycle detected"); } @@ -82,7 +76,7 @@ export default class TraversalContext { return this.visitQueue(queue); } - visitSingle(node, key): boolean { + visitSingle(node, key) { if (this.shouldVisit(node[key])) { return this.visitQueue([ this.create(node, node, key) @@ -92,7 +86,7 @@ export default class TraversalContext { } } - visitQueue(queue: Array) { + visitQueue(queue) { // set queue this.queue = queue; this.priorityQueue = []; diff --git a/packages/babel-traverse/src/index.js b/packages/babel-traverse/src/index.js index 01a48112c4..53ded855d8 100644 --- a/packages/babel-traverse/src/index.js +++ b/packages/babel-traverse/src/index.js @@ -11,13 +11,7 @@ export { default as Scope } from "./scope"; export { default as Hub } from "./hub"; export { visitors }; -export default function traverse( - parent: Object | Array, - opts?: Object, - scope?: Object, - state: Object, - parentPath: Object, -) { +export default function traverse(parent, opts, scope, state, parentPath) { if (!parent) return; if (!opts) opts = {}; @@ -61,8 +55,8 @@ traverse.cheap = function (node, enter) { } }; -traverse.node = function (node: Object, opts: Object, scope: Object, state: Object, parentPath: Object, skipKeys?) { - let keys: Array = t.VISITOR_KEYS[node.type]; +traverse.node = function (node, opts, scope, state, parentPath, skipKeys) { + let keys = t.VISITOR_KEYS[node.type]; if (!keys) return; let context = new TraversalContext(scope, opts, state, parentPath); @@ -72,7 +66,7 @@ traverse.node = function (node: Object, opts: Object, scope: Object, state: Obje } }; -const CLEAR_KEYS: Array = t.COMMENT_KEYS.concat([ +const CLEAR_KEYS = t.COMMENT_KEYS.concat([ "tokens", "comments", "start", "end", "loc", "raw", "rawValue" @@ -87,7 +81,7 @@ traverse.clearNode = function (node) { if (key[0] === "_" && node[key] != null) node[key] = undefined; } - let syms: Array = Object.getOwnPropertySymbols(node); + let syms = Object.getOwnPropertySymbols(node); for (let sym of syms) { node[sym] = null; } @@ -105,7 +99,7 @@ function hasBlacklistedType(path, state) { } } -traverse.hasType = function (tree: Object, scope: Object, type: Object, blacklistTypes: Array): boolean { +traverse.hasType = function (tree, scope, type, blacklistTypes) { // the node we're searching in is blacklisted if (includes(blacklistTypes, tree.type)) return false; diff --git a/packages/babel-traverse/src/path/ancestry.js b/packages/babel-traverse/src/path/ancestry.js index 7e52857056..a9347896a8 100644 --- a/packages/babel-traverse/src/path/ancestry.js +++ b/packages/babel-traverse/src/path/ancestry.js @@ -1,7 +1,6 @@ // This file contains that retrieve or validate anything related to the current paths ancestry. import * as t from "babel-types"; -import NodePath from "./index"; /** * Call the provided `callback` with the `NodePath`s of all the parents. @@ -57,12 +56,12 @@ export function getStatementParent() { * position and visiting key. */ -export function getEarliestCommonAncestorFrom(paths: Array): NodePath { +export function getEarliestCommonAncestorFrom(paths) { return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) { let earliest; let keys = t.VISITOR_KEYS[deepest.type]; - for (let ancestry of (ancestries: Array)) { + for (let ancestry of ancestries) { let path = ancestry[i + 1]; // first path @@ -99,7 +98,7 @@ export function getEarliestCommonAncestorFrom(paths: Array): NodePath * TODO: Possible optimisation target. */ -export function getDeepestCommonAncestorFrom(paths: Array, filter?: Function): NodePath { +export function getDeepestCommonAncestorFrom(paths, filter) { if (!paths.length) { return this; } @@ -137,7 +136,7 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu depthLoop: for (let i = 0; i < minDepth; i++) { let shouldMatch = first[i]; - for (let ancestry of (ancestries: Array)) { + for (let ancestry of ancestries) { if (ancestry[i] !== shouldMatch) { // we've hit a snag break depthLoop; @@ -178,7 +177,7 @@ export function getAncestry() { export function inType() { let path = this; while (path) { - for (let type of (arguments: Array)) { + for (let type of arguments) { if (path.node.type === type) return true; } path = path.parentPath; @@ -191,7 +190,7 @@ export function inType() { * Check if we're inside a shadowed function. */ -export function inShadow(key?) { +export function inShadow(key) { let path = this; do { if (path.isFunction()) { diff --git a/packages/babel-traverse/src/path/comments.js b/packages/babel-traverse/src/path/comments.js index 2a1b06f64a..b036114bc8 100644 --- a/packages/babel-traverse/src/path/comments.js +++ b/packages/babel-traverse/src/path/comments.js @@ -22,7 +22,7 @@ export function shareCommentsWithSiblings() { next.addComments("leading", trailing); } -export function addComment(type, content, line?) { +export function addComment(type, content, line) { this.addComments(type, [{ type: line ? "CommentLine" : "CommentBlock", value: content @@ -33,7 +33,7 @@ export function addComment(type, content, line?) { * Give node `comments` of the specified `type`. */ -export function addComments(type: string, comments: Array) { +export function addComments(type, comments) { if (!comments) return; let node = this.node; diff --git a/packages/babel-traverse/src/path/context.js b/packages/babel-traverse/src/path/context.js index ce1f6f5361..473532c722 100644 --- a/packages/babel-traverse/src/path/context.js +++ b/packages/babel-traverse/src/path/context.js @@ -2,7 +2,7 @@ import traverse from "../index"; -export function call(key): boolean { +export function call(key) { let opts = this.opts; this.debug(() => key); @@ -18,7 +18,7 @@ export function call(key): boolean { return false; } -export function _call(fns?: Array): boolean { +export function _call(fns) { if (!fns) return false; for (let fn of fns) { @@ -39,12 +39,12 @@ export function _call(fns?: Array): boolean { return false; } -export function isBlacklisted(): boolean { +export function isBlacklisted() { let blacklist = this.opts.blacklist; return blacklist && blacklist.indexOf(this.node.type) > -1; } -export function visit(): boolean { +export function visit() { if (!this.node) { return false; } diff --git a/packages/babel-traverse/src/path/conversion.js b/packages/babel-traverse/src/path/conversion.js index 27079529d7..0451d4a740 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -2,7 +2,7 @@ import * as t from "babel-types"; -export function toComputedKey(): Object { +export function toComputedKey() { let node = this.node; let key; diff --git a/packages/babel-traverse/src/path/evaluation.js b/packages/babel-traverse/src/path/evaluation.js index 904fc6f720..736c0301d7 100644 --- a/packages/babel-traverse/src/path/evaluation.js +++ b/packages/babel-traverse/src/path/evaluation.js @@ -1,8 +1,6 @@ /* eslint indent: 0 */ /* eslint max-len: 0 */ -import type NodePath from "./index"; - // This file contains Babels metainterpreter that can evaluate static code. /* eslint eqeqeq: 0 */ @@ -28,7 +26,7 @@ const INVALID_METHODS = ["random"]; * */ -export function evaluateTruthy(): boolean { +export function evaluateTruthy() { let res = this.evaluate(); if (res.confident) return !!res.value; } @@ -48,9 +46,9 @@ export function evaluateTruthy(): boolean { * */ -export function evaluate(): { confident: boolean; value: any } { +export function evaluate() { let confident = true; - let deoptPath: ?NodePath; + let deoptPath; function deopt(path) { if (!confident) return; @@ -90,7 +88,7 @@ export function evaluate(): { confident: boolean; value: any } { let i = 0; let exprs = path.get("expressions"); - for (let elem of (node.quasis: Array)) { + for (let elem of node.quasis) { // not confident, evaluated an expression we don't like if (!confident) break; @@ -180,7 +178,7 @@ export function evaluate(): { confident: boolean; value: any } { if (path.isArrayExpression()) { let arr = []; - let elems: Array = path.get("elements"); + let elems = path.get("elements"); for (let elem of elems) { elem = elem.evaluate(); diff --git a/packages/babel-traverse/src/path/family.js b/packages/babel-traverse/src/path/family.js index b27538edaf..323ce4eb56 100644 --- a/packages/babel-traverse/src/path/family.js +++ b/packages/babel-traverse/src/path/family.js @@ -1,10 +1,9 @@ // This file contains methods responsible for dealing with/retrieving children or siblings. -import type TraversalContext from "../index"; import NodePath from "./index"; import * as t from "babel-types"; -export function getStatementParent(): ?NodePath { +export function getStatementParent() { let path = this; do { @@ -30,7 +29,7 @@ export function getOpposite() { } } -export function getCompletionRecords(): Array { +export function getCompletionRecords() { let paths = []; let add = function (path) { @@ -67,7 +66,7 @@ export function getSibling(key) { }); } -export function get(key: string, context?: boolean | TraversalContext): NodePath { +export function get(key, context) { if (context === true) context = this.context; let parts = key.split("."); if (parts.length === 1) { // "foo" @@ -77,7 +76,7 @@ export function get(key: string, context?: boolean | TraversalContext): NodePath } } -export function _getKey(key, context?) { +export function _getKey(key, context) { let node = this.node; let container = node[key]; @@ -104,7 +103,7 @@ export function _getKey(key, context?) { export function _getPattern(parts, context) { let path = this; - for (let part of (parts: Array)) { + for (let part of parts) { if (part === ".") { path = path.parentPath; } else { @@ -118,10 +117,10 @@ export function _getPattern(parts, context) { return path; } -export function getBindingIdentifiers(duplicates?) { +export function getBindingIdentifiers(duplicates) { return t.getBindingIdentifiers(this.node, duplicates); } -export function getOuterBindingIdentifiers(duplicates?) { +export function getOuterBindingIdentifiers(duplicates) { return t.getOuterBindingIdentifiers(this.node, duplicates); } diff --git a/packages/babel-traverse/src/path/index.js b/packages/babel-traverse/src/path/index.js index 4fa06c9b30..8353d1d6db 100644 --- a/packages/babel-traverse/src/path/index.js +++ b/packages/babel-traverse/src/path/index.js @@ -1,7 +1,5 @@ /* eslint max-len: 0 */ -import type Hub from "../hub"; -import type TraversalContext from "../context"; import * as virtualTypes from "./lib/virtual-types"; import buildDebug from "debug"; import { PATH_CACHE_KEY } from "./constants"; @@ -14,7 +12,7 @@ import * as t from "babel-types"; let debug = buildDebug("babel"); export default class NodePath { - constructor(hub: Hub, parent: Object) { + constructor(hub, parent) { this.parent = parent; this.hub = hub; this.contexts = []; @@ -38,29 +36,7 @@ export default class NodePath { this.typeAnnotation = null; } - parent: Object; - hub: Hub; - contexts: Array; - data: Object; - shouldSkip: boolean; - shouldStop: boolean; - removed: boolean; - state: any; - opts: ?Object; - skipKeys: ?Object; - parentPath: ?NodePath; - context: TraversalContext; - container: ?Object | Array; - listKey: ?string; - inList: boolean; - parentKey: ?string; - key: ?string; - node: ?Object; - scope: Scope; - type: ?string; - typeAnnotation: ?Object; - - static get({ hub, parentPath, parent, container, listKey, key }): NodePath { + static get({ hub, parentPath, parent, container, listKey, key }) { if (!hub && parentPath) { hub = parentPath.hub; } @@ -102,7 +78,7 @@ export default class NodePath { return path; } - getScope(scope: Scope) { + getScope(scope) { let ourScope = scope; // we're entering a new scope so let's construct it! @@ -113,25 +89,25 @@ export default class NodePath { return ourScope; } - setData(key: string, val: any): any { + setData(key, val) { return this.data[key] = val; } - getData(key: string, def?: any): any { + getData(key, def) { let val = this.data[key]; if (!val && def) val = this.data[key] = def; return val; } - buildCodeFrameError(msg: string, Error: typeof Error = SyntaxError): Error { + buildCodeFrameError(msg, Error = SyntaxError) { return this.hub.file.buildCodeFrameError(this.node, msg, Error); } - traverse(visitor: Object, state?: any) { + traverse(visitor, state) { traverse(this.node, visitor, this.scope, state, this); } - mark(type: string, message: string) { + mark(type, message) { this.hub.file.metadata.marked.push({ type, message, @@ -139,12 +115,12 @@ export default class NodePath { }); } - set(key: string, node: Object) { + set(key, node) { t.validate(this.node, key, node); this.node[key] = node; } - getPathLocation(): string { + getPathLocation() { let parts = []; let path = this; do { @@ -155,7 +131,7 @@ export default class NodePath { return parts.join("."); } - debug(buildMessage: Function) { + debug(buildMessage) { if (!debug.enabled) return; debug(`${this.getPathLocation()} ${this.type}: ${buildMessage()}`); } @@ -173,7 +149,7 @@ assign(NodePath.prototype, require("./modification")); assign(NodePath.prototype, require("./family")); assign(NodePath.prototype, require("./comments")); -for (let type of (t.TYPES: Array)) { +for (let type of t.TYPES) { let typeKey = `is${type}`; NodePath.prototype[typeKey] = function (opts) { return t[typeKey](this.node, opts); diff --git a/packages/babel-traverse/src/path/inference/index.js b/packages/babel-traverse/src/path/inference/index.js index d6b9c878f3..9d57951a83 100644 --- a/packages/babel-traverse/src/path/inference/index.js +++ b/packages/babel-traverse/src/path/inference/index.js @@ -1,4 +1,3 @@ -import type NodePath from "./index"; import * as inferers from "./inferers"; import * as t from "babel-types"; @@ -6,7 +5,7 @@ import * as t from "babel-types"; * Infer the type of the current `NodePath`. */ -export function getTypeAnnotation(): Object { +export function getTypeAnnotation() { if (this.typeAnnotation) return this.typeAnnotation; let type = this._getTypeAnnotation() || t.anyTypeAnnotation(); @@ -18,7 +17,7 @@ export function getTypeAnnotation(): Object { * todo: split up this method */ -export function _getTypeAnnotation(): ?Object { +export function _getTypeAnnotation() { let node = this.node; if (!node) { @@ -58,11 +57,11 @@ export function _getTypeAnnotation(): ?Object { } } -export function isBaseType(baseName: string, soft?: boolean): boolean { +export function isBaseType(baseName, soft) { return _isBaseType(baseName, this.getTypeAnnotation(), soft); } -function _isBaseType(baseName: string, type?, soft?): boolean { +function _isBaseType(baseName, type, soft) { if (baseName === "string") { return t.isStringTypeAnnotation(type); } else if (baseName === "number") { @@ -84,12 +83,12 @@ function _isBaseType(baseName: string, type?, soft?): boolean { } } -export function couldBeBaseType(name: string): boolean { +export function couldBeBaseType(name) { let type = this.getTypeAnnotation(); if (t.isAnyTypeAnnotation(type)) return true; if (t.isUnionTypeAnnotation(type)) { - for (let type2 of (type.types: Array)) { + for (let type2 of type.types) { if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { return true; } @@ -100,7 +99,7 @@ export function couldBeBaseType(name: string): boolean { } } -export function baseTypeStrictlyMatches(right: NodePath) { +export function baseTypeStrictlyMatches(right) { let left = this.getTypeAnnotation(); right = right.getTypeAnnotation(); @@ -109,7 +108,7 @@ export function baseTypeStrictlyMatches(right: NodePath) { } } -export function isGenericType(genericName: string): boolean { +export function isGenericType(genericName) { let type = this.getTypeAnnotation(); return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { name: genericName }); } diff --git a/packages/babel-traverse/src/path/inference/inferer-reference.js b/packages/babel-traverse/src/path/inference/inferer-reference.js index 4b1d8e58a9..a3e9d96705 100644 --- a/packages/babel-traverse/src/path/inference/inferer-reference.js +++ b/packages/babel-traverse/src/path/inference/inferer-reference.js @@ -1,7 +1,6 @@ -import type NodePath from "../index"; import * as t from "babel-types"; -export default function (node: Object) { +export default function (node) { if (!this.isReferenced()) return; // check if a binding exists of this value and if so then return a union type of all @@ -76,7 +75,7 @@ function getTypeAnnotationBindingConstantViolations(path, name) { constantViolations = constantViolations.concat(functionConstantViolations); // push on inferred types of violated paths - for (let violation of (constantViolations: Array)) { + for (let violation of constantViolations) { types.push(violation.getTypeAnnotation()); } } diff --git a/packages/babel-traverse/src/path/introspection.js b/packages/babel-traverse/src/path/introspection.js index 278efc0713..e1cc67d777 100644 --- a/packages/babel-traverse/src/path/introspection.js +++ b/packages/babel-traverse/src/path/introspection.js @@ -1,6 +1,5 @@ // This file contains methods responsible for introspecting the current path for certain values. -import type NodePath from "./index"; import includes from "lodash/collection/includes"; import * as t from "babel-types"; @@ -11,7 +10,7 @@ import * as t from "babel-types"; * parsed nodes of `React.createClass` and `React["createClass"]`. */ -export function matchesPattern(pattern: string, allowPartial?: boolean): boolean { +export function matchesPattern(pattern, allowPartial) { // not a member expression if (!this.isMemberExpression()) return false; @@ -67,7 +66,7 @@ export function matchesPattern(pattern: string, allowPartial?: boolean): boolean * if the array has any items, otherwise we just check if it's falsy. */ -export function has(key): boolean { +export function has(key) { let val = this.node && this.node[key]; if (val && Array.isArray(val)) { return !!val.length; @@ -94,7 +93,7 @@ export let is = has; * Opposite of `has`. */ -export function isnt(key): boolean { +export function isnt(key) { return !this.has(key); } @@ -102,7 +101,7 @@ export function isnt(key): boolean { * Check whether the path node `key` strict equals `value`. */ -export function equals(key, value): boolean { +export function equals(key, value) { return this.node[key] === value; } @@ -111,7 +110,7 @@ export function equals(key, value): boolean { * been removed yet we still internally know the type and need it to calculate node replacement. */ -export function isNodeType(type: string): boolean { +export function isNodeType(type) { return t.isType(this.type, type); } @@ -155,7 +154,7 @@ export function canSwapBetweenExpressionAndStatement(replacement) { * Check whether the current path references a completion record */ -export function isCompletionRecord(allowInsideFunction?) { +export function isCompletionRecord(allowInsideFunction) { let path = this; let first = true; @@ -320,7 +319,7 @@ export function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncPare // no references! if (!binding.references) return "before"; - let referencePaths: Array = binding.referencePaths; + let referencePaths = binding.referencePaths; // verify that all of the references are calls for (let path of referencePaths) { @@ -358,7 +357,7 @@ export function resolve(dangerous, resolved) { return this._resolve(dangerous, resolved) || this; } -export function _resolve(dangerous?, resolved?): ?NodePath { +export function _resolve(dangerous, resolved) { // detect infinite recursion // todo: possibly have a max length on this just to be safe if (resolved && resolved.indexOf(this) >= 0) return; @@ -404,7 +403,7 @@ export function _resolve(dangerous?, resolved?): ?NodePath { if (target.isObjectExpression()) { let props = target.get("properties"); - for (let prop of (props: Array)) { + for (let prop of props) { if (!prop.isProperty()) continue; let key = prop.get("key"); diff --git a/packages/babel-traverse/src/path/removal.js b/packages/babel-traverse/src/path/removal.js index f7686fce6b..4292e90ddc 100644 --- a/packages/babel-traverse/src/path/removal.js +++ b/packages/babel-traverse/src/path/removal.js @@ -18,7 +18,7 @@ export function remove() { } export function _callRemovalHooks() { - for (let fn of (hooks: Array)) { + for (let fn of hooks) { if (fn(this, this.parentPath)) return true; } } diff --git a/packages/babel-traverse/src/path/replacement.js b/packages/babel-traverse/src/path/replacement.js index 8ca15a4c09..b0961de965 100644 --- a/packages/babel-traverse/src/path/replacement.js +++ b/packages/babel-traverse/src/path/replacement.js @@ -22,7 +22,7 @@ let hoistVariablesVisitor = { let exprs = []; - for (let declar of (path.node.declarations: Array)) { + for (let declar of path.node.declarations) { if (declar.init) { exprs.push(t.expressionStatement( t.assignmentExpression("=", declar.id, declar.init) @@ -42,7 +42,7 @@ let hoistVariablesVisitor = { * - Remove the current node. */ -export function replaceWithMultiple(nodes: Array) { +export function replaceWithMultiple(nodes) { this.resync(); nodes = this._verifyNodeList(nodes); @@ -178,7 +178,7 @@ export function _replaceWith(node) { * extremely important to retain original semantics. */ -export function replaceExpressionWithStatements(nodes: Array) { +export function replaceExpressionWithStatements(nodes) { this.resync(); let toSequenceExpression = t.toSequenceExpression(nodes, this.scope); @@ -206,7 +206,7 @@ export function replaceExpressionWithStatements(nodes: Array) { this.traverse(hoistVariablesVisitor); // add implicit returns to all ending expression statements - let completionRecords: Array = this.get("callee").getCompletionRecords(); + let completionRecords = this.get("callee").getCompletionRecords(); for (let path of completionRecords) { if (!path.isExpressionStatement()) continue; @@ -229,7 +229,7 @@ export function replaceExpressionWithStatements(nodes: Array) { } } -export function replaceInline(nodes: Object | Array) { +export function replaceInline(nodes) { this.resync(); if (Array.isArray(nodes)) { diff --git a/packages/babel-traverse/src/scope/binding.js b/packages/babel-traverse/src/scope/binding.js index 57decb22a9..b19c310712 100644 --- a/packages/babel-traverse/src/scope/binding.js +++ b/packages/babel-traverse/src/scope/binding.js @@ -1,4 +1,3 @@ -import type NodePath from "../path"; /** * This class is responsible for a binding inside of a scope. @@ -36,24 +35,12 @@ export default class Binding { } } - - constantViolations: Array; - constant: boolean; - - referencePaths: Array; - referenced: boolean; - references: number; - - hasDeoptedValue: boolean; - hasValue: boolean; - value: any; - deoptValue() { this.clearValue(); this.hasDeoptedValue = true; } - setValue(value: any) { + setValue(value) { if (this.hasDeoptedValue) return; this.hasValue = true; this.value = value; @@ -69,7 +56,7 @@ export default class Binding { * Register a constant violation with the provided `path`. */ - reassign(path: Object) { + reassign(path) { this.constant = false; this.constantViolations.push(path); } @@ -78,7 +65,7 @@ export default class Binding { * Increment the amount of references to this binding. */ - reference(path: NodePath) { + reference(path) { this.referenced = true; this.references++; this.referencePaths.push(path); diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index 05c492f2d4..1718f97972 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -3,7 +3,6 @@ import includes from "lodash/collection/includes"; import repeating from "repeating"; import Renamer from "./lib/renamer"; -import type NodePath from "../path"; import traverse from "../index"; import defaults from "lodash/object/defaults"; import * as messages from "babel-messages"; @@ -49,7 +48,7 @@ function matchesParent(scope, parentScope) { } function getCacheMultiple(node, parentScope, self, singleCache) { - let scopes: Array = node[CACHE_MULTIPLE_KEY] = node[CACHE_MULTIPLE_KEY] || []; + let scopes = node[CACHE_MULTIPLE_KEY] = node[CACHE_MULTIPLE_KEY] || []; if (singleCache) { // we have a scope assocation miss so push it onto our scopes @@ -69,7 +68,7 @@ function getCacheMultiple(node, parentScope, self, singleCache) { let collectorVisitor = { For(path) { - for (let key of (t.FOR_INIT_KEYS: Array)) { + for (let key of t.FOR_INIT_KEYS) { let declar = path.get(key); if (declar.isVar()) path.scope.getFunctionParent().registerBinding("var", declar); } @@ -107,7 +106,7 @@ let collectorVisitor = { let binding = scope.getBinding(id.name); if (binding) binding.reference(); } else if (t.isVariableDeclaration(declar)) { - for (let decl of (declar.declarations: Array)) { + for (let decl of declar.declarations) { let ids = t.getBindingIdentifiers(decl); for (let name in ids) { let binding = scope.getBinding(name); @@ -153,7 +152,7 @@ let collectorVisitor = { Block(path) { let paths = path.get("body"); - for (let bodyPath of (paths: Array)) { + for (let bodyPath of paths) { if (bodyPath.isFunctionDeclaration()) { path.scope.getBlockParent().registerDeclaration(bodyPath); } @@ -170,7 +169,7 @@ export default class Scope { * within. */ - constructor(path: NodePath, parentScope?: Scope) { + constructor(path, parentScope) { if (parentScope && parentScope.block === path.node) { return parentScope; } @@ -208,7 +207,7 @@ export default class Scope { * Traverse node with current scope and path. */ - traverse(node: Object, opts: Object, state?) { + traverse(node, opts, state) { traverse(node, opts, this, state, this.path); } @@ -216,7 +215,7 @@ export default class Scope { * Generate a unique identifier and add it to the current scope. */ - generateDeclaredUidIdentifier(name: string = "temp") { + generateDeclaredUidIdentifier(name = "temp") { let id = this.generateUidIdentifier(name); this.push({ id }); return id; @@ -226,7 +225,7 @@ export default class Scope { * Generate a unique identifier. */ - generateUidIdentifier(name: string = "temp") { + generateUidIdentifier(name = "temp") { return t.identifier(this.generateUid(name)); } @@ -234,7 +233,7 @@ export default class Scope { * Generate a unique `_id1` binding. */ - generateUid(name: string = "temp") { + generateUid(name = "temp") { name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); let uid; @@ -265,7 +264,7 @@ export default class Scope { * Generate a unique identifier based on a node. */ - generateUidIdentifierBasedOnNode(parent: Object, defaultName?: String): Object { + generateUidIdentifierBasedOnNode(parent, defaultName) { let node = parent; if (t.isAssignmentExpression(parent)) { @@ -283,7 +282,7 @@ export default class Scope { if (node.source) { add(node.source); } else if (node.specifiers && node.specifiers.length) { - for (let specifier of (node.specifiers: Array)) { + for (let specifier of node.specifiers) { add(specifier); } } else if (node.declaration) { @@ -301,7 +300,7 @@ export default class Scope { } else if (t.isCallExpression(node)) { add(node.callee); } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { add(prop.key || prop.argument); } } @@ -325,7 +324,7 @@ export default class Scope { * - Bound identifiers */ - isStatic(node: Object): boolean { + isStatic(node) { if (t.isThisExpression(node) || t.isSuper(node)) { return true; } @@ -346,7 +345,7 @@ export default class Scope { * Possibly generate a memoised identifier if it is not static and has consequences. */ - maybeGenerateMemoised(node: Object, dontPush?: boolean): ?Object { + maybeGenerateMemoised(node, dontPush) { if (this.isStatic(node)) { return null; } else { @@ -356,7 +355,7 @@ export default class Scope { } } - checkBlockScopedCollisions(local, kind: string, name: string, id: Object) { + checkBlockScopedCollisions(local, kind, name, id) { // ignore parameters if (kind === "param") return; @@ -376,7 +375,7 @@ export default class Scope { } } - rename(oldName: string, newName: string, block?) { + rename(oldName, newName, block) { let binding = this.getBinding(oldName); if (binding) { newName = newName || this.generateUidIdentifier(oldName).name; @@ -410,7 +409,7 @@ export default class Scope { console.log(sep); } - toArray(node: Object, i?: number) { + toArray(node, i) { let file = this.hub.file; if (t.isIdentifier(node)) { @@ -450,21 +449,21 @@ export default class Scope { return t.callExpression(file.addHelper(helperName), args); } - registerDeclaration(path: NodePath) { + registerDeclaration(path) { if (path.isLabeledStatement()) { this.registerBinding("label", path); } else if (path.isFunctionDeclaration()) { this.registerBinding("hoisted", path.get("id"), path); } else if (path.isVariableDeclaration()) { let declarations = path.get("declarations"); - for (let declar of (declarations: Array)) { + for (let declar of declarations) { this.registerBinding(path.node.kind, declar); } } else if (path.isClassDeclaration()) { this.registerBinding("let", path); } else if (path.isImportDeclaration()) { let specifiers = path.get("specifiers"); - for (let specifier of (specifiers: Array)) { + for (let specifier of specifiers) { this.registerBinding("module", specifier); } } else if (path.isExportDeclaration()) { @@ -485,7 +484,7 @@ export default class Scope { } } - registerConstantViolation(path: NodePath) { + registerConstantViolation(path) { let ids = path.getBindingIdentifiers(); for (let name in ids) { let binding = this.getBinding(name); @@ -493,11 +492,11 @@ export default class Scope { } } - registerBinding(kind: string, path: NodePath, bindingPath = path) { + registerBinding(kind, path, bindingPath = path) { if (!kind) throw new ReferenceError("no `kind`"); if (path.isVariableDeclaration()) { - let declarators: Array = path.get("declarations"); + let declarators = path.get("declarations"); for (let declar of declarators) { this.registerBinding(kind, declar); } @@ -508,7 +507,7 @@ export default class Scope { let ids = path.getBindingIdentifiers(true); for (let name in ids) { - for (let id of (ids[name]: Array)) { + for (let id of ids[name]) { let local = this.getOwnBinding(name); if (local) { // same identifier so continue safely as we're likely trying to register it @@ -531,11 +530,11 @@ export default class Scope { } } - addGlobal(node: Object) { + addGlobal(node) { this.globals[node.name] = node; } - hasUid(name): boolean { + hasUid(name) { let scope = this; do { @@ -545,7 +544,7 @@ export default class Scope { return false; } - hasGlobal(name: string): boolean { + hasGlobal(name) { let scope = this; do { @@ -555,7 +554,7 @@ export default class Scope { return false; } - hasReference(name: string): boolean { + hasReference(name) { let scope = this; do { @@ -565,7 +564,7 @@ export default class Scope { return false; } - isPure(node, constantsOnly?: boolean) { + isPure(node, constantsOnly) { if (t.isIdentifier(node)) { let binding = this.getBinding(node.name); if (!binding) return false; @@ -582,12 +581,12 @@ export default class Scope { } else if (t.isBinary(node)) { return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); } else if (t.isArrayExpression(node)) { - for (let elem of (node.elements: Array)) { + for (let elem of node.elements) { if (!this.isPure(elem, constantsOnly)) return false; } return true; } else if (t.isObjectExpression(node)) { - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { if (!this.isPure(prop, constantsOnly)) return false; } return true; @@ -656,7 +655,7 @@ export default class Scope { // ForStatement - left, init if (path.isLoop()) { - for (let key of (t.FOR_INIT_KEYS: Array)) { + for (let key of t.FOR_INIT_KEYS) { let node = path.get(key); if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); } @@ -681,7 +680,7 @@ export default class Scope { // Function - params, rest if (path.isFunction()) { - let params: Array = path.get("params"); + let params = path.get("params"); for (let param of params) { this.registerBinding("param", param); } @@ -740,13 +739,7 @@ export default class Scope { } } - push(opts: { - id: Object; - init: ?Object; - unique: ?boolean; - _blockHoist: ?number; - kind: "var" | "let"; - }) { + push(opts) { let path = this.path; if (!path.isBlockStatement() && !path.isProgram()) { @@ -831,7 +824,7 @@ export default class Scope { * Walks the scope tree and gathers **all** bindings. */ - getAllBindings(): Object { + getAllBindings() { let ids = Object.create(null); let scope = this; @@ -847,10 +840,10 @@ export default class Scope { * Walks the scope tree and gathers all declarations of `kind`. */ - getAllBindingsOfKind(): Object { + getAllBindingsOfKind() { let ids = Object.create(null); - for (let kind of (arguments: Array)) { + for (let kind of arguments) { let scope = this; do { for (let name in scope.bindings) { @@ -864,11 +857,11 @@ export default class Scope { return ids; } - bindingIdentifierEquals(name: string, node: Object): boolean { + bindingIdentifierEquals(name, node) { return this.getBindingIdentifier(name) === node; } - getBinding(name: string) { + getBinding(name) { let scope = this; do { @@ -877,25 +870,25 @@ export default class Scope { } while (scope = scope.parent); } - getOwnBinding(name: string) { + getOwnBinding(name) { return this.bindings[name]; } - getBindingIdentifier(name: string) { + getBindingIdentifier(name) { let info = this.getBinding(name); return info && info.identifier; } - getOwnBindingIdentifier(name: string) { + getOwnBindingIdentifier(name) { let binding = this.bindings[name]; return binding && binding.identifier; } - hasOwnBinding(name: string) { + hasOwnBinding(name) { return !!this.getOwnBinding(name); } - hasBinding(name: string, noGlobals?) { + hasBinding(name, noGlobals) { if (!name) return false; if (this.hasOwnBinding(name)) return true; if (this.parentHasBinding(name, noGlobals)) return true; @@ -905,7 +898,7 @@ export default class Scope { return false; } - parentHasBinding(name: string, noGlobals?) { + parentHasBinding(name, noGlobals) { return this.parent && this.parent.hasBinding(name, noGlobals); } @@ -922,11 +915,11 @@ export default class Scope { } } - removeOwnBinding(name: string) { + removeOwnBinding(name) { delete this.bindings[name]; } - removeBinding(name: string) { + removeBinding(name) { // clear literal binding let info = this.getBinding(name); if (info) { diff --git a/packages/babel-traverse/src/visitors.js b/packages/babel-traverse/src/visitors.js index 36f762ae46..70ae3ed6ea 100644 --- a/packages/babel-traverse/src/visitors.js +++ b/packages/babel-traverse/src/visitors.js @@ -27,7 +27,7 @@ export function explode(visitor) { for (let nodeType in visitor) { if (shouldIgnoreKey(nodeType)) continue; - let parts: Array = nodeType.split("|"); + let parts = nodeType.split("|"); if (parts.length === 1) continue; let fns = visitor[nodeType]; @@ -52,7 +52,7 @@ export function explode(visitor) { ensureCallbackArrays(visitor); // add type wrappers - for (let nodeType of (Object.keys(visitor): Array)) { + for (let nodeType of Object.keys(visitor)) { if (shouldIgnoreKey(nodeType)) continue; let wrapper = virtualTypes[nodeType]; @@ -68,7 +68,7 @@ export function explode(visitor) { delete visitor[nodeType]; if (wrapper.types) { - for (let type of (wrapper.types: Array)) { + for (let type of wrapper.types) { // merge the visitor if necessary or just put it back in if (visitor[type]) { mergePair(visitor[type], fns); @@ -87,7 +87,7 @@ export function explode(visitor) { let fns = visitor[nodeType]; - let aliases: ?Array = t.FLIPPED_ALIAS_KEYS[nodeType]; + let aliases = t.FLIPPED_ALIAS_KEYS[nodeType]; let deprecratedKey = t.DEPRECATED_KEYS[nodeType]; if (deprecratedKey) { @@ -162,7 +162,7 @@ function validateVisitorMethods(path, val) { } } -export function merge(visitors: Array, states: Array = []) { +export function merge(visitors, states = []) { let rootVisitor = {}; for (let i = 0; i < visitors.length; i++) { diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index 9eb9d7df43..74c29b7cfc 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -1,4 +1,3 @@ -/* @flow */ /* eslint max-len: 0 */ import * as t from "../index"; diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index 03cac174eb..5bcda71daf 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -97,7 +97,7 @@ export function is(type, node, opts) { export function isType(nodeType, targetType) { if (nodeType === targetType) return true; - let aliases: ?Array = t.FLIPPED_ALIAS_KEYS[targetType]; + let aliases = t.FLIPPED_ALIAS_KEYS[targetType]; if (aliases) { if (aliases[0] === nodeType) return true; diff --git a/packages/babel-types/src/validators.js b/packages/babel-types/src/validators.js index 9b9c03c20b..1f5ae15b32 100644 --- a/packages/babel-types/src/validators.js +++ b/packages/babel-types/src/validators.js @@ -197,7 +197,7 @@ export function isVar(node) { * Check if the input `specifier` is a `default` import or export. */ -export function isSpecifierDefault(specifier: Object): boolean { +export function isSpecifierDefault(specifier) { return t.isImportDefaultSpecifier(specifier) || t.isIdentifier(specifier.imported || specifier.exported, { name: "default" }); } diff --git a/packages/babylon/src/parser/expression.js b/packages/babylon/src/parser/expression.js index bc89b4bdf5..78dc6e97ac 100644 --- a/packages/babylon/src/parser/expression.js +++ b/packages/babylon/src/parser/expression.js @@ -873,7 +873,7 @@ pp.parseFunctionBody = function (node, allowExpression) { // normal function if (!isExpression && node.body.directives.length) { - for (let directive of (node.body.directives: Array)) { + for (let directive of node.body.directives) { if (directive.value.value === "use strict") { isStrict = true; checkLVal = true; @@ -895,7 +895,7 @@ pp.parseFunctionBody = function (node, allowExpression) { if (node.id) { this.checkLVal(node.id, true); } - for (let param of (node.params: Array)) { + for (let param of node.params) { this.checkLVal(param, true, nameHash); } this.state.strict = oldStrict; diff --git a/packages/babylon/src/parser/lval.js b/packages/babylon/src/parser/lval.js index fe3e6bb34e..96811030d8 100644 --- a/packages/babylon/src/parser/lval.js +++ b/packages/babylon/src/parser/lval.js @@ -20,7 +20,7 @@ pp.toAssignable = function (node, isBinding) { case "ObjectExpression": node.type = "ObjectPattern"; - for (let prop of (node.properties: Array)) { + for (let prop of node.properties) { if (prop.type === "ObjectMethod") { if (prop.kind === "get" || prop.kind === "set") { this.raise(prop.key.start, "Object pattern can't contain getter or setter"); @@ -225,14 +225,14 @@ pp.checkLVal = function (expr, isBinding, checkClashes) { break; case "ObjectPattern": - for (let prop of (expr.properties: Array)) { + for (let prop of expr.properties) { if (prop.type === "ObjectProperty") prop = prop.value; this.checkLVal(prop, isBinding, checkClashes); } break; case "ArrayPattern": - for (let elem of (expr.elements: Array)) { + for (let elem of expr.elements) { if (elem) this.checkLVal(elem, isBinding, checkClashes); } break; diff --git a/packages/babylon/src/parser/node.js b/packages/babylon/src/parser/node.js index d9e07ae329..3d219278e8 100644 --- a/packages/babylon/src/parser/node.js +++ b/packages/babylon/src/parser/node.js @@ -6,19 +6,14 @@ import { SourceLocation } from "../util/location"; const pp = Parser.prototype; class Node { - constructor(pos?: number, loc?: SourceLocation) { + constructor(pos, loc) { this.type = ""; this.start = pos; this.end = 0; this.loc = new SourceLocation(loc); } - type: string; - start: ?number; - end: number; - loc: SourceLocation; - - __clone(): Node { + __clone() { let node2 = new Node; for (let key in this) node2[key] = this[key]; return node2; diff --git a/packages/babylon/src/parser/statement.js b/packages/babylon/src/parser/statement.js index 5a9c2ae9df..16c4cb5a70 100644 --- a/packages/babylon/src/parser/statement.js +++ b/packages/babylon/src/parser/statement.js @@ -404,7 +404,7 @@ pp.parseEmptyStatement = function (node) { }; pp.parseLabeledStatement = function (node, maybeName, expr) { - for (let label of (this.state.labels: Array)){ + for (let label of this.state.labels) { if (label.name === maybeName) { this.raise(expr.start, `Label '${maybeName}' is already declared`); } @@ -438,7 +438,7 @@ pp.parseExpressionStatement = function (node, expr) { // strict"` declarations when `allowStrict` is true (used for // function bodies). -pp.parseBlock = function (allowDirectives?) { +pp.parseBlock = function (allowDirectives) { let node = this.startNode(); this.expect(tt.braceL); this.parseBlockBody(node, allowDirectives, false, tt.braceR); @@ -860,7 +860,7 @@ pp.parseExportSpecifiersMaybe = function (node) { } }; -pp.parseExportFrom = function (node, expect?) { +pp.parseExportFrom = function (node, expect) { if (this.eatContextual("from")) { node.source = this.match(tt.string) ? this.parseExprAtom() : this.unexpected(); this.checkExport(node); diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index f856955176..a12487e660 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -704,7 +704,7 @@ export default function (instance) { }); instance.extend("parseParenItem", function () { - return function (node, startLoc, startPos, forceArrow?) { + return function (node, startLoc, startPos, forceArrow) { let canBeArrow = this.state.potentialArrowAt = startPos; if (this.match(tt.colon)) { let typeCastNode = this.startNodeAt(startLoc, startPos); diff --git a/packages/babylon/src/tokenizer/state.js b/packages/babylon/src/tokenizer/state.js index 68104ae947..a932b1618a 100644 --- a/packages/babylon/src/tokenizer/state.js +++ b/packages/babylon/src/tokenizer/state.js @@ -1,129 +1,83 @@ -import type { TokContext } from "./context"; -import type { Token } from "./index"; import { Position } from "../util/location"; import { types as ct } from "./context"; import { types as tt } from "./types"; export default class State { - init(options: Object, input: string) { + init(options, input) { + // TODO this.strict = options.strictMode === false ? false : options.sourceType === "module"; + // TODO this.input = input; + // Used to signify the start of a potential arrow function this.potentialArrowAt = -1; + // Flags to track whether we are in a function, a generator. this.inMethod = this.inFunction = this.inGenerator = this.inAsync = false; + // Labels in scope. this.labels = []; + // Leading decorators. this.decorators = []; + // Token store. this.tokens = []; + // Comment store. this.comments = []; + // Comment attachment store this.trailingComments = []; this.leadingComments = []; this.commentStack = []; + // The current position of the tokenizer in the input. this.pos = this.lineStart = 0; this.curLine = 1; + // Properties of the current token: + // Its type this.type = tt.eof; + + // For tokens that include more information than their type, the value this.value = null; + + // Its start and end offset this.start = this.end = this.pos; + + // And, if locations are used, the {line, column} object + // corresponding to those offsets this.startLoc = this.endLoc = this.curPosition(); + // Position information for the previous token this.lastTokEndLoc = this.lastTokStartLoc = null; this.lastTokStart = this.lastTokEnd = this.pos; + // The context stack is used to superficially track syntactic + // context to predict whether a regular expression is allowed in a + // given position. this.context = [ct.b_stat]; this.exprAllowed = true; - this.containsEsc = this.containsOctal = false; + // Used to signal to callers of `readWord1` whether the word + // contained any escape sequences. This is needed because words with + // escape sequences must not be interpreted as keywords. + this.containsEsc = false; + + // TODO + this.containsOctal = false; this.octalPosition = null; return this; } - // TODO - strict: boolean; - - // TODO - input: string; - - // Used to signify the start of a potential arrow function - potentialArrowAt: number; - - // Flags to track whether we are in a function, a generator. - inFunction: boolean; - inGenerator: boolean; - inMethod: boolean; - - // Labels in scope. - labels: Array; - - // Leading decorators. - decorators: Array; - - // Token store. - tokens: Array; - - // Comment store. - comments: Array; - - // Comment attachment store - trailingComments: Array; - leadingComments: Array; - commentStack: Array; - - // The current position of the tokenizer in the input. - pos: number; - lineStart: number; - curLine: number; - - // Properties of the current token: - // Its type - type: Token; - - // For tokens that include more information than their type, the value - value: any; - - // Its start and end offset - start: number; - end: number; - - // And, if locations are used, the {line, column} object - // corresponding to those offsets - startLoc: Position; - endLoc: Position; - - // Position information for the previous token - lastTokEndLoc: ?Position; - lastTokStartLoc: ?Position; - lastTokStart: number; - lastTokEnd: number; - - // The context stack is used to superficially track syntactic - // context to predict whether a regular expression is allowed in a - // given position. - context: Array; - exprAllowed: boolean; - - // Used to signal to callers of `readWord1` whether the word - // contained any escape sequences. This is needed because words with - // escape sequences must not be interpreted as keywords. - containsEsc: boolean; - - // TODO - containsOctal: boolean; - octalPosition: ?number; - curPosition() { return new Position(this.curLine, this.pos - this.lineStart); } - clone(skipArrays?) { + clone(skipArrays) { let state = new State; for (let key in this) { let val = this[key];