diff --git a/babel.config.js b/babel.config.js index b55690d087..24dfc34ff2 100644 --- a/babel.config.js +++ b/babel.config.js @@ -102,14 +102,11 @@ module.exports = function (api) { ] .filter(Boolean) .map(normalize), - presets: [["@babel/env", envOpts]], + presets: [ + ["@babel/env", envOpts], + ["@babel/preset-flow", { allowDeclareFields: true }], + ], plugins: [ - // TODO: Use @babel/preset-flow when - // https://github.com/babel/babel/issues/7233 is fixed - [ - "@babel/plugin-transform-flow-strip-types", - { allowDeclareFields: true }, - ], [ "@babel/proposal-object-rest-spread", { useBuiltIns: true, loose: true }, diff --git a/package.json b/package.json index b3faa7e2e3..b094cec1dd 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "@babel/eslint-plugin-development-internal": "workspace:*", "@babel/plugin-proposal-dynamic-import": "^7.10.4", "@babel/plugin-proposal-object-rest-spread": "^7.11.0", - "@babel/plugin-transform-flow-strip-types": "^7.10.4", "@babel/plugin-transform-for-of": "^7.10.4", "@babel/plugin-transform-modules-commonjs": "^7.10.4", "@babel/plugin-transform-runtime": "^7.12.0", diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index ac9b6a9837..854119a2c3 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -33,10 +33,10 @@ export default class Printer { this._buf = new Buffer(map); } - format: Format; + declare format: Format; inForStatementInitCounter: number = 0; - _buf: Buffer; + declare _buf: Buffer; _printStack: Array = []; _indent: number = 0; _insideAux: boolean = false; diff --git a/packages/babel-helper-module-imports/src/import-injector.js b/packages/babel-helper-module-imports/src/import-injector.js index 1264dd4bc7..81acd472ae 100644 --- a/packages/babel-helper-module-imports/src/import-injector.js +++ b/packages/babel-helper-module-imports/src/import-injector.js @@ -98,17 +98,17 @@ export default class ImportInjector { /** * The path used for manipulation. */ - _programPath: NodePath; + declare _programPath: NodePath; /** * The scope used to generate unique variable names. */ - _programScope; + declare _programScope; /** * The file used to inject helpers and resolve paths. */ - _hub; + declare _hub; /** * The default options to use with this instance when imports are added. diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index cc0eec0cfe..240e5b5504 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -272,14 +272,14 @@ export default class ReplaceSupers { this.opts = opts; } - file: HubInterface; - isDerivedConstructor: boolean; - isLoose: boolean; - isPrivateMethod: boolean; - isStatic: boolean; - methodPath: NodePath; - opts: ReplaceSupersOptions; - superRef: Object; + declare file: HubInterface; + declare isDerivedConstructor: boolean; + declare isLoose: boolean; + declare isPrivateMethod: boolean; + declare isStatic: boolean; + declare methodPath: NodePath; + declare opts: ReplaceSupersOptions; + declare superRef: Object; getObjectRef() { return t.cloneNode(this.opts.objectRef || this.opts.getObjectRef()); diff --git a/packages/babel-parser/src/parser/base.js b/packages/babel-parser/src/parser/base.js index 770483e818..74c26a791b 100644 --- a/packages/babel-parser/src/parser/base.js +++ b/packages/babel-parser/src/parser/base.js @@ -10,23 +10,23 @@ import type ProductionParameterHandler from "../util/production-parameter"; export default class BaseParser { // Properties set by constructor in index.js - options: Options; - inModule: boolean; - scope: ScopeHandler<*>; - classScope: ClassScopeHandler; - prodParam: ProductionParameterHandler; - expressionScope: ExpressionScopeHandler; - plugins: PluginsMap; - filename: ?string; + declare options: Options; + declare inModule: boolean; + declare scope: ScopeHandler<*>; + declare classScope: ClassScopeHandler; + declare prodParam: ProductionParameterHandler; + declare expressionScope: ExpressionScopeHandler; + declare plugins: PluginsMap; + declare filename: ?string; sawUnambiguousESM: boolean = false; ambiguousScriptDifferentAst: boolean = false; // Initialized by Tokenizer - state: State; + declare state: State; // input and length are not in state as they are constant and we do // not want to ever copy them, which happens if state gets cloned - input: string; - length: number; + declare input: string; + declare length: number; hasPlugin(name: string): boolean { return this.plugins.has(name); diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 573db84a32..971226007c 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -101,11 +101,11 @@ export class Token { this.loc = new SourceLocation(state.startLoc, state.endLoc); } - type: TokenType; - value: any; - start: number; - end: number; - loc: SourceLocation; + declare type: TokenType; + declare value: any; + declare start: number; + declare end: number; + declare loc: SourceLocation; } // ## Tokenizer diff --git a/packages/babel-parser/src/util/class-scope.js b/packages/babel-parser/src/util/class-scope.js index 1ac00c995e..359af336e1 100644 --- a/packages/babel-parser/src/util/class-scope.js +++ b/packages/babel-parser/src/util/class-scope.js @@ -23,7 +23,7 @@ type raiseFunction = (number, string, ...any) => void; export default class ClassScopeHandler { stack: Array = []; - raise: raiseFunction; + declare raise: raiseFunction; undefinedPrivateNames: Map = new Map(); constructor(raise: raiseFunction) { diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 3d40c5fb87..b65cb7e0d9 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -39,8 +39,8 @@ type raiseFunction = (number, string, ...any) => void; // current scope in order to detect duplicate variable names. export default class ScopeHandler { scopeStack: Array = []; - raise: raiseFunction; - inModule: boolean; + declare raise: raiseFunction; + declare inModule: boolean; undefinedExports: Map = new Map(); undefinedPrivateNames: Map = new Map(); diff --git a/packages/babel-traverse/src/context.js b/packages/babel-traverse/src/context.js index 22b8bed959..5dd830f91d 100644 --- a/packages/babel-traverse/src/context.js +++ b/packages/babel-traverse/src/context.js @@ -11,10 +11,10 @@ export default class TraversalContext { this.opts = opts; } - parentPath: NodePath; - scope; - state; - opts; + declare parentPath: NodePath; + declare scope; + declare state; + declare opts; queue: ?Array = null; /** diff --git a/packages/babel-traverse/src/path/index.js b/packages/babel-traverse/src/path/index.js index a2eaf79f22..84f3664333 100644 --- a/packages/babel-traverse/src/path/index.js +++ b/packages/babel-traverse/src/path/index.js @@ -31,42 +31,30 @@ export default class NodePath { constructor(hub: HubInterface, parent: Object) { this.parent = parent; this.hub = hub; - this.contexts = []; this.data = null; - // this.shouldSkip = false; this.shouldStop = false; this.removed = false; - this._traverseFlags = 0; - this.state = null; - this.opts = null; - this.skipKeys = null; - this.parentPath = null; + this.context = null; - this.container = null; - this.listKey = null; - this.key = null; - this.node = null; this.scope = null; - this.type = null; } - parent: Object; - hub: HubInterface; - contexts: Array; - data: Object; - shouldSkip: boolean; - shouldStop: boolean; - removed: boolean; - state: any; - opts: ?Object; - _traverseFlags: number; - skipKeys: ?Object; - parentPath: ?NodePath; - context: TraversalContext; - container: ?Object | Array; - listKey: ?string; - key: ?string; - node: ?Object; - scope: Scope; - type: ?string; + declare parent: Object; + declare hub: HubInterface; + declare data: Object; + declare context: TraversalContext; + declare scope: Scope; + + contexts: Array = []; + state: any = null; + opts: ?Object = null; + // this.shouldSkip = false; this.shouldStop = false; this.removed = false; + _traverseFlags: number = 0; + skipKeys: ?Object = null; + parentPath: ?NodePath = null; + container: ?Object | Array = null; + listKey: ?string = null; + key: ?string = null; + node: ?Object = null; + type: ?string = null; static get({ hub, parentPath, parent, container, listKey, key }): NodePath { if (!hub && parentPath) { diff --git a/packages/babel-traverse/src/scope/binding.js b/packages/babel-traverse/src/scope/binding.js index 1f52201c51..341ecdfb6a 100644 --- a/packages/babel-traverse/src/scope/binding.js +++ b/packages/babel-traverse/src/scope/binding.js @@ -18,26 +18,19 @@ export default class Binding { this.path = path; this.kind = kind; - this.constantViolations = []; - this.constant = true; - - this.referencePaths = []; - this.referenced = false; - this.references = 0; - this.clearValue(); } - constantViolations: Array; - constant: boolean; + constantViolations: Array = []; + constant: boolean = true; - referencePaths: Array; - referenced: boolean; - references: number; + referencePaths: Array = []; + referenced: boolean = false; + references: number = 0; - hasDeoptedValue: boolean; - hasValue: boolean; - value: any; + declare hasDeoptedValue: boolean; + declare hasValue: boolean; + declare value: any; deoptValue() { this.clearValue(); diff --git a/packages/babel-traverse/src/scope/lib/renamer.js b/packages/babel-traverse/src/scope/lib/renamer.js index b15285e29c..528c43ef4d 100644 --- a/packages/babel-traverse/src/scope/lib/renamer.js +++ b/packages/babel-traverse/src/scope/lib/renamer.js @@ -37,9 +37,9 @@ export default class Renamer { this.binding = binding; } - oldName: string; - newName: string; - binding: Binding; + declare oldName: string; + declare newName: string; + declare binding: Binding; maybeConvertFromExportDeclaration(parentDeclar) { const maybeExportDeclar = parentDeclar.parentPath; diff --git a/yarn.lock b/yarn.lock index a816365276..5cb63b01e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4575,7 +4575,6 @@ __metadata: "@babel/eslint-plugin-development-internal": "workspace:*" "@babel/plugin-proposal-dynamic-import": ^7.10.4 "@babel/plugin-proposal-object-rest-spread": ^7.11.0 - "@babel/plugin-transform-flow-strip-types": ^7.10.4 "@babel/plugin-transform-for-of": ^7.10.4 "@babel/plugin-transform-modules-commonjs": ^7.10.4 "@babel/plugin-transform-runtime": ^7.12.0