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)
|
||||
.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 },
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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<Node> = [];
|
||||
_indent: number = 0;
|
||||
_insideAux: boolean = false;
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,7 +23,7 @@ type raiseFunction = (number, string, ...any) => void;
|
||||
|
||||
export default class ClassScopeHandler {
|
||||
stack: Array<ClassScope> = [];
|
||||
raise: raiseFunction;
|
||||
declare raise: raiseFunction;
|
||||
undefinedPrivateNames: Map<string, number> = new Map();
|
||||
|
||||
constructor(raise: raiseFunction) {
|
||||
|
||||
@ -39,8 +39,8 @@ type raiseFunction = (number, string, ...any) => void;
|
||||
// current scope in order to detect duplicate variable names.
|
||||
export default class ScopeHandler<IScope: Scope = Scope> {
|
||||
scopeStack: Array<IScope> = [];
|
||||
raise: raiseFunction;
|
||||
inModule: boolean;
|
||||
declare raise: raiseFunction;
|
||||
declare inModule: boolean;
|
||||
undefinedExports: Map<string, number> = new Map();
|
||||
undefinedPrivateNames: Map<string, number> = new Map();
|
||||
|
||||
|
||||
@ -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<NodePath> = null;
|
||||
|
||||
/**
|
||||
|
||||
@ -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<TraversalContext>;
|
||||
data: Object;
|
||||
shouldSkip: boolean;
|
||||
shouldStop: boolean;
|
||||
removed: boolean;
|
||||
state: any;
|
||||
opts: ?Object;
|
||||
_traverseFlags: number;
|
||||
skipKeys: ?Object;
|
||||
parentPath: ?NodePath;
|
||||
context: TraversalContext;
|
||||
container: ?Object | Array<Object>;
|
||||
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<TraversalContext> = [];
|
||||
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<Object> = 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) {
|
||||
|
||||
@ -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<NodePath>;
|
||||
constant: boolean;
|
||||
constantViolations: Array<NodePath> = [];
|
||||
constant: boolean = true;
|
||||
|
||||
referencePaths: Array<NodePath>;
|
||||
referenced: boolean;
|
||||
references: number;
|
||||
referencePaths: Array<NodePath> = [];
|
||||
referenced: boolean = false;
|
||||
references: number = 0;
|
||||
|
||||
hasDeoptedValue: boolean;
|
||||
hasValue: boolean;
|
||||
value: any;
|
||||
declare hasDeoptedValue: boolean;
|
||||
declare hasValue: boolean;
|
||||
declare value: any;
|
||||
|
||||
deoptValue() {
|
||||
this.clearValue();
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user