Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add declare to class properties type annotations #12257

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-generator/src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-helper-module-imports/src/import-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions packages/babel-helper-replace-supers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
22 changes: 11 additions & 11 deletions packages/babel-parser/src/parser/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions packages/babel-parser/src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/util/class-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/util/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions packages/babel-traverse/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
54 changes: 21 additions & 33 deletions packages/babel-traverse/src/path/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 8 additions & 15 deletions packages/babel-traverse/src/scope/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-traverse/src/scope/lib/renamer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down