add declare to class properties type annotations (#12257)
* add declare to class properties type annotations * chore: use preset-flow
This commit is contained in:
parent
9eb661b285
commit
ea2892fefc
@ -102,14 +102,11 @@ module.exports = function (api) {
|
|||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map(normalize),
|
.map(normalize),
|
||||||
presets: [["@babel/env", envOpts]],
|
presets: [
|
||||||
|
["@babel/env", envOpts],
|
||||||
|
["@babel/preset-flow", { allowDeclareFields: true }],
|
||||||
|
],
|
||||||
plugins: [
|
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",
|
"@babel/proposal-object-rest-spread",
|
||||||
{ useBuiltIns: true, loose: true },
|
{ useBuiltIns: true, loose: true },
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
"@babel/eslint-plugin-development-internal": "workspace:*",
|
"@babel/eslint-plugin-development-internal": "workspace:*",
|
||||||
"@babel/plugin-proposal-dynamic-import": "^7.10.4",
|
"@babel/plugin-proposal-dynamic-import": "^7.10.4",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
"@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-for-of": "^7.10.4",
|
||||||
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
|
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
|
||||||
"@babel/plugin-transform-runtime": "^7.12.0",
|
"@babel/plugin-transform-runtime": "^7.12.0",
|
||||||
|
|||||||
@ -33,10 +33,10 @@ export default class Printer {
|
|||||||
this._buf = new Buffer(map);
|
this._buf = new Buffer(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
format: Format;
|
declare format: Format;
|
||||||
inForStatementInitCounter: number = 0;
|
inForStatementInitCounter: number = 0;
|
||||||
|
|
||||||
_buf: Buffer;
|
declare _buf: Buffer;
|
||||||
_printStack: Array<Node> = [];
|
_printStack: Array<Node> = [];
|
||||||
_indent: number = 0;
|
_indent: number = 0;
|
||||||
_insideAux: boolean = false;
|
_insideAux: boolean = false;
|
||||||
|
|||||||
@ -98,17 +98,17 @@ export default class ImportInjector {
|
|||||||
/**
|
/**
|
||||||
* The path used for manipulation.
|
* The path used for manipulation.
|
||||||
*/
|
*/
|
||||||
_programPath: NodePath;
|
declare _programPath: NodePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scope used to generate unique variable names.
|
* The scope used to generate unique variable names.
|
||||||
*/
|
*/
|
||||||
_programScope;
|
declare _programScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file used to inject helpers and resolve paths.
|
* The file used to inject helpers and resolve paths.
|
||||||
*/
|
*/
|
||||||
_hub;
|
declare _hub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default options to use with this instance when imports are added.
|
* The default options to use with this instance when imports are added.
|
||||||
|
|||||||
@ -272,14 +272,14 @@ export default class ReplaceSupers {
|
|||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
file: HubInterface;
|
declare file: HubInterface;
|
||||||
isDerivedConstructor: boolean;
|
declare isDerivedConstructor: boolean;
|
||||||
isLoose: boolean;
|
declare isLoose: boolean;
|
||||||
isPrivateMethod: boolean;
|
declare isPrivateMethod: boolean;
|
||||||
isStatic: boolean;
|
declare isStatic: boolean;
|
||||||
methodPath: NodePath;
|
declare methodPath: NodePath;
|
||||||
opts: ReplaceSupersOptions;
|
declare opts: ReplaceSupersOptions;
|
||||||
superRef: Object;
|
declare superRef: Object;
|
||||||
|
|
||||||
getObjectRef() {
|
getObjectRef() {
|
||||||
return t.cloneNode(this.opts.objectRef || this.opts.getObjectRef());
|
return t.cloneNode(this.opts.objectRef || this.opts.getObjectRef());
|
||||||
|
|||||||
@ -10,23 +10,23 @@ import type ProductionParameterHandler from "../util/production-parameter";
|
|||||||
|
|
||||||
export default class BaseParser {
|
export default class BaseParser {
|
||||||
// Properties set by constructor in index.js
|
// Properties set by constructor in index.js
|
||||||
options: Options;
|
declare options: Options;
|
||||||
inModule: boolean;
|
declare inModule: boolean;
|
||||||
scope: ScopeHandler<*>;
|
declare scope: ScopeHandler<*>;
|
||||||
classScope: ClassScopeHandler;
|
declare classScope: ClassScopeHandler;
|
||||||
prodParam: ProductionParameterHandler;
|
declare prodParam: ProductionParameterHandler;
|
||||||
expressionScope: ExpressionScopeHandler;
|
declare expressionScope: ExpressionScopeHandler;
|
||||||
plugins: PluginsMap;
|
declare plugins: PluginsMap;
|
||||||
filename: ?string;
|
declare filename: ?string;
|
||||||
sawUnambiguousESM: boolean = false;
|
sawUnambiguousESM: boolean = false;
|
||||||
ambiguousScriptDifferentAst: boolean = false;
|
ambiguousScriptDifferentAst: boolean = false;
|
||||||
|
|
||||||
// Initialized by Tokenizer
|
// Initialized by Tokenizer
|
||||||
state: State;
|
declare state: State;
|
||||||
// input and length are not in state as they are constant and we do
|
// 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
|
// not want to ever copy them, which happens if state gets cloned
|
||||||
input: string;
|
declare input: string;
|
||||||
length: number;
|
declare length: number;
|
||||||
|
|
||||||
hasPlugin(name: string): boolean {
|
hasPlugin(name: string): boolean {
|
||||||
return this.plugins.has(name);
|
return this.plugins.has(name);
|
||||||
|
|||||||
@ -101,11 +101,11 @@ export class Token {
|
|||||||
this.loc = new SourceLocation(state.startLoc, state.endLoc);
|
this.loc = new SourceLocation(state.startLoc, state.endLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
type: TokenType;
|
declare type: TokenType;
|
||||||
value: any;
|
declare value: any;
|
||||||
start: number;
|
declare start: number;
|
||||||
end: number;
|
declare end: number;
|
||||||
loc: SourceLocation;
|
declare loc: SourceLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ## Tokenizer
|
// ## Tokenizer
|
||||||
|
|||||||
@ -23,7 +23,7 @@ type raiseFunction = (number, string, ...any) => void;
|
|||||||
|
|
||||||
export default class ClassScopeHandler {
|
export default class ClassScopeHandler {
|
||||||
stack: Array<ClassScope> = [];
|
stack: Array<ClassScope> = [];
|
||||||
raise: raiseFunction;
|
declare raise: raiseFunction;
|
||||||
undefinedPrivateNames: Map<string, number> = new Map();
|
undefinedPrivateNames: Map<string, number> = new Map();
|
||||||
|
|
||||||
constructor(raise: raiseFunction) {
|
constructor(raise: raiseFunction) {
|
||||||
|
|||||||
@ -39,8 +39,8 @@ type raiseFunction = (number, string, ...any) => void;
|
|||||||
// current scope in order to detect duplicate variable names.
|
// current scope in order to detect duplicate variable names.
|
||||||
export default class ScopeHandler<IScope: Scope = Scope> {
|
export default class ScopeHandler<IScope: Scope = Scope> {
|
||||||
scopeStack: Array<IScope> = [];
|
scopeStack: Array<IScope> = [];
|
||||||
raise: raiseFunction;
|
declare raise: raiseFunction;
|
||||||
inModule: boolean;
|
declare inModule: boolean;
|
||||||
undefinedExports: Map<string, number> = new Map();
|
undefinedExports: Map<string, number> = new Map();
|
||||||
undefinedPrivateNames: Map<string, number> = new Map();
|
undefinedPrivateNames: Map<string, number> = new Map();
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,10 @@ export default class TraversalContext {
|
|||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
parentPath: NodePath;
|
declare parentPath: NodePath;
|
||||||
scope;
|
declare scope;
|
||||||
state;
|
declare state;
|
||||||
opts;
|
declare opts;
|
||||||
queue: ?Array<NodePath> = null;
|
queue: ?Array<NodePath> = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -31,42 +31,30 @@ export default class NodePath {
|
|||||||
constructor(hub: HubInterface, parent: Object) {
|
constructor(hub: HubInterface, parent: Object) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
this.contexts = [];
|
|
||||||
this.data = null;
|
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.context = null;
|
||||||
this.container = null;
|
|
||||||
this.listKey = null;
|
|
||||||
this.key = null;
|
|
||||||
this.node = null;
|
|
||||||
this.scope = null;
|
this.scope = null;
|
||||||
this.type = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parent: Object;
|
declare parent: Object;
|
||||||
hub: HubInterface;
|
declare hub: HubInterface;
|
||||||
contexts: Array<TraversalContext>;
|
declare data: Object;
|
||||||
data: Object;
|
declare context: TraversalContext;
|
||||||
shouldSkip: boolean;
|
declare scope: Scope;
|
||||||
shouldStop: boolean;
|
|
||||||
removed: boolean;
|
contexts: Array<TraversalContext> = [];
|
||||||
state: any;
|
state: any = null;
|
||||||
opts: ?Object;
|
opts: ?Object = null;
|
||||||
_traverseFlags: number;
|
// this.shouldSkip = false; this.shouldStop = false; this.removed = false;
|
||||||
skipKeys: ?Object;
|
_traverseFlags: number = 0;
|
||||||
parentPath: ?NodePath;
|
skipKeys: ?Object = null;
|
||||||
context: TraversalContext;
|
parentPath: ?NodePath = null;
|
||||||
container: ?Object | Array<Object>;
|
container: ?Object | Array<Object> = null;
|
||||||
listKey: ?string;
|
listKey: ?string = null;
|
||||||
key: ?string;
|
key: ?string = null;
|
||||||
node: ?Object;
|
node: ?Object = null;
|
||||||
scope: Scope;
|
type: ?string = null;
|
||||||
type: ?string;
|
|
||||||
|
|
||||||
static get({ hub, parentPath, parent, container, listKey, key }): NodePath {
|
static get({ hub, parentPath, parent, container, listKey, key }): NodePath {
|
||||||
if (!hub && parentPath) {
|
if (!hub && parentPath) {
|
||||||
|
|||||||
@ -18,26 +18,19 @@ export default class Binding {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
|
|
||||||
this.constantViolations = [];
|
|
||||||
this.constant = true;
|
|
||||||
|
|
||||||
this.referencePaths = [];
|
|
||||||
this.referenced = false;
|
|
||||||
this.references = 0;
|
|
||||||
|
|
||||||
this.clearValue();
|
this.clearValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
constantViolations: Array<NodePath>;
|
constantViolations: Array<NodePath> = [];
|
||||||
constant: boolean;
|
constant: boolean = true;
|
||||||
|
|
||||||
referencePaths: Array<NodePath>;
|
referencePaths: Array<NodePath> = [];
|
||||||
referenced: boolean;
|
referenced: boolean = false;
|
||||||
references: number;
|
references: number = 0;
|
||||||
|
|
||||||
hasDeoptedValue: boolean;
|
declare hasDeoptedValue: boolean;
|
||||||
hasValue: boolean;
|
declare hasValue: boolean;
|
||||||
value: any;
|
declare value: any;
|
||||||
|
|
||||||
deoptValue() {
|
deoptValue() {
|
||||||
this.clearValue();
|
this.clearValue();
|
||||||
|
|||||||
@ -37,9 +37,9 @@ export default class Renamer {
|
|||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldName: string;
|
declare oldName: string;
|
||||||
newName: string;
|
declare newName: string;
|
||||||
binding: Binding;
|
declare binding: Binding;
|
||||||
|
|
||||||
maybeConvertFromExportDeclaration(parentDeclar) {
|
maybeConvertFromExportDeclaration(parentDeclar) {
|
||||||
const maybeExportDeclar = parentDeclar.parentPath;
|
const maybeExportDeclar = parentDeclar.parentPath;
|
||||||
|
|||||||
@ -4575,7 +4575,6 @@ __metadata:
|
|||||||
"@babel/eslint-plugin-development-internal": "workspace:*"
|
"@babel/eslint-plugin-development-internal": "workspace:*"
|
||||||
"@babel/plugin-proposal-dynamic-import": ^7.10.4
|
"@babel/plugin-proposal-dynamic-import": ^7.10.4
|
||||||
"@babel/plugin-proposal-object-rest-spread": ^7.11.0
|
"@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-for-of": ^7.10.4
|
||||||
"@babel/plugin-transform-modules-commonjs": ^7.10.4
|
"@babel/plugin-transform-modules-commonjs": ^7.10.4
|
||||||
"@babel/plugin-transform-runtime": ^7.12.0
|
"@babel/plugin-transform-runtime": ^7.12.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user