Skip to content

Commit

Permalink
fix class property types
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Sep 8, 2021
1 parent 6adf46e commit f6c5f12
Show file tree
Hide file tree
Showing 85 changed files with 272 additions and 284 deletions.
14 changes: 5 additions & 9 deletions src/ExternalModule.ts
Expand Up @@ -12,16 +12,16 @@ import { printQuotedStringList } from './utils/printStringList';
import relativeId from './utils/relativeId';

export default class ExternalModule {
chunk: void;
declarations: { [name: string]: ExternalVariable };
declare chunk: void;
declarations: { [name: string]: ExternalVariable } = Object.create(null);
defaultVariableName = '';
dynamicImporters: string[] = [];
execIndex: number;
exportedVariables: Map<ExternalVariable, string>;
execIndex = Infinity;
exportedVariables = new Map<ExternalVariable, string>();
importers: string[] = [];
info: ModuleInfo;
mostCommonSuggestion = 0;
nameSuggestions: { [name: string]: number };
nameSuggestions: { [name: string]: number } = Object.create(null);
namespaceVariableName = '';
reexported = false;
renderPath: string = undefined as never;
Expand All @@ -36,11 +36,7 @@ export default class ExternalModule {
meta: CustomPluginOptions,
public renormalizeRenderPath: boolean
) {
this.execIndex = Infinity;
this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop()!);
this.nameSuggestions = Object.create(null);
this.declarations = Object.create(null);
this.exportedVariables = new Map();

const { importers, dynamicImporters } = this;
this.info = {
Expand Down
11 changes: 4 additions & 7 deletions src/Graph.ts
Expand Up @@ -45,26 +45,24 @@ function normalizeEntryModules(

export default class Graph {
acornParser: typeof acorn.Parser;
cachedModules: Map<string, ModuleJSON>;
deoptimizationTracker: PathTracker;
cachedModules = new Map<string, ModuleJSON>();
deoptimizationTracker = new PathTracker();
entryModules: Module[] = [];
moduleLoader: ModuleLoader;
modulesById = new Map<string, Module | ExternalModule>();
needsTreeshakingPass = false;
phase: BuildPhase = BuildPhase.LOAD_AND_PARSE;
pluginDriver: PluginDriver;
scope: GlobalScope;
scope = new GlobalScope();
watchFiles: Record<string, true> = Object.create(null);
watchMode = false;

private externalModules: ExternalModule[] = [];
private implicitEntryModules: Module[] = [];
private modules: Module[] = [];
private pluginCache?: Record<string, SerializablePluginCache>;
private declare pluginCache?: Record<string, SerializablePluginCache>;

constructor(private readonly options: NormalizedInputOptions, watcher: RollupWatcher | null) {
this.deoptimizationTracker = new PathTracker();
this.cachedModules = new Map();
if (options.cache !== false) {
if (options.cache?.modules) {
for (const module of options.cache.modules) this.cachedModules.set(module.id, module);
Expand All @@ -91,7 +89,6 @@ export default class Graph {
});
}
this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
this.scope = new GlobalScope();
this.acornParser = acorn.Parser.extend(...(options.acornInjectPlugins as any));
this.moduleLoader = new ModuleLoader(this, this.modulesById, this.options, this.pluginDriver);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Module.ts
Expand Up @@ -211,28 +211,28 @@ export default class Module {
info: ModuleInfo;
isExecuted = false;
isUserDefinedEntryPoint = false;
namespace!: NamespaceVariable;
originalCode!: string;
originalSourcemap!: ExistingDecodedSourceMap | null;
declare namespace: NamespaceVariable;
declare originalCode: string;
declare originalSourcemap: ExistingDecodedSourceMap | null;
preserveSignature: PreserveEntrySignaturesOption = this.options.preserveEntrySignatures;
reexportDescriptions: { [name: string]: ReexportDescription } = Object.create(null);
resolvedIds!: ResolvedIdMap;
scope!: ModuleScope;
declare resolvedIds: ResolvedIdMap;
declare scope: ModuleScope;
sideEffectDependenciesByVariable = new Map<Variable, Set<Module>>();
sourcemapChain!: DecodedSourceMapOrMissing[];
declare sourcemapChain: DecodedSourceMapOrMissing[];
sources = new Set<string>();
transformFiles?: EmittedFile[];
declare transformFiles?: EmittedFile[];
userChunkNames = new Set<string>();
usesTopLevelAwait = false;

private allExportNames: Set<string> | null = null;
private astContext!: AstContext;
private declare astContext: AstContext;
private readonly context: string;
private customTransformCache!: boolean;
private declare customTransformCache: boolean;
private exportAllModules: (Module | ExternalModule)[] = [];
private exportNamesByVariable: Map<Variable, string[]> | null = null;
private exportShimVariable: ExportShimVariable = new ExportShimVariable(this);
private magicString!: MagicString;
private declare magicString: MagicString;
private namespaceReexportsByName: Record<string, Variable | null> = Object.create(null);
private relevantDependencies: Set<Module | ExternalModule> | null = null;
private syntheticExports = new Map<string, SyntheticNamedExportVariable>();
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ArrayExpression.ts
Expand Up @@ -12,8 +12,8 @@ import { ExpressionNode, NodeBase } from './shared/Node';
import { ObjectEntity, ObjectProperty } from './shared/ObjectEntity';

export default class ArrayExpression extends NodeBase {
elements!: (ExpressionNode | SpreadElement | null)[];
type!: NodeType.tArrayExpression;
declare elements: (ExpressionNode | SpreadElement | null)[];
declare type: NodeType.tArrayExpression;
private objectEntity: ObjectEntity | null = null;

deoptimizePath(path: ObjectPath): void {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ArrayPattern.ts
Expand Up @@ -8,8 +8,8 @@ import { NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';

export default class ArrayPattern extends NodeBase implements PatternNode {
elements!: (PatternNode | null)[];
type!: NodeType.tArrayPattern;
declare elements: (PatternNode | null)[];
declare type: NodeType.tArrayPattern;

addExportedVariables(
variables: Variable[],
Expand Down
12 changes: 6 additions & 6 deletions src/ast/nodes/ArrowFunctionExpression.ts
Expand Up @@ -14,12 +14,12 @@ import { ExpressionNode, GenericEsTreeNode, IncludeChildren, NodeBase } from './
import { PatternNode } from './shared/Pattern';

export default class ArrowFunctionExpression extends NodeBase {
async!: boolean;
body!: BlockStatement | ExpressionNode;
params!: PatternNode[];
preventChildBlockScope!: true;
scope!: ReturnValueScope;
type!: NodeType.tArrowFunctionExpression;
declare async: boolean;
declare body: BlockStatement | ExpressionNode;
declare params: PatternNode[];
declare preventChildBlockScope: true;
declare scope: ReturnValueScope;
declare type: NodeType.tArrowFunctionExpression;
private deoptimizedReturn = false;

createScope(parentScope: Scope): void {
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/AssignmentExpression.ts
Expand Up @@ -22,8 +22,8 @@ import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';

export default class AssignmentExpression extends NodeBase {
left!: ExpressionNode | PatternNode;
operator!:
declare left: ExpressionNode | PatternNode;
declare operator:
| '='
| '+='
| '-='
Expand All @@ -37,8 +37,8 @@ export default class AssignmentExpression extends NodeBase {
| '^='
| '&='
| '**=';
right!: ExpressionNode;
type!: NodeType.tAssignmentExpression;
declare right: ExpressionNode;
declare type: NodeType.tAssignmentExpression;
protected deoptimized = false;

hasEffects(context: HasEffectsContext): boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/AssignmentPattern.ts
Expand Up @@ -11,9 +11,9 @@ import { ExpressionNode, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';

export default class AssignmentPattern extends NodeBase implements PatternNode {
left!: PatternNode;
right!: ExpressionNode;
type!: NodeType.tAssignmentPattern;
declare left: PatternNode;
declare right: ExpressionNode;
declare type: NodeType.tAssignmentPattern;
protected deoptimized = false;

addExportedVariables(
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/AwaitExpression.ts
Expand Up @@ -6,8 +6,8 @@ import FunctionNode from './shared/FunctionNode';
import { ExpressionNode, IncludeChildren, Node, NodeBase } from './shared/Node';

export default class AwaitExpression extends NodeBase {
argument!: ExpressionNode;
type!: NodeType.tAwaitExpression;
declare argument: ExpressionNode;
declare type: NodeType.tAwaitExpression;
protected deoptimized = false;

hasEffects(): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/BinaryExpression.ts
Expand Up @@ -46,10 +46,10 @@ const binaryOperators: {
};

export default class BinaryExpression extends NodeBase implements DeoptimizableEntity {
left!: ExpressionNode;
operator!: keyof typeof binaryOperators;
right!: ExpressionNode;
type!: NodeType.tBinaryExpression;
declare left: ExpressionNode;
declare operator: keyof typeof binaryOperators;
declare right: ExpressionNode;
declare type: NodeType.tBinaryExpression;

deoptimizeCache(): void {}

Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/BlockStatement.ts
Expand Up @@ -10,10 +10,10 @@ import { UNKNOWN_EXPRESSION } from './shared/Expression';
import { IncludeChildren, Node, StatementBase, StatementNode } from './shared/Node';

export default class BlockStatement extends StatementBase {
body!: StatementNode[];
type!: NodeType.tBlockStatement;
declare body: StatementNode[];
declare type: NodeType.tBlockStatement;

private deoptimizeBody!: boolean;
private declare deoptimizeBody: boolean;
private directlyIncluded = false;

addImplicitReturnExpressionToScope(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/BreakStatement.ts
Expand Up @@ -9,8 +9,8 @@ import * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';

export default class BreakStatement extends StatementBase {
label!: Identifier | null;
type!: NodeType.tBreakStatement;
declare label: Identifier | null;
declare type: NodeType.tBreakStatement;

hasEffects(context: HasEffectsContext): boolean {
if (this.label) {
Expand Down
10 changes: 5 additions & 5 deletions src/ast/nodes/CallExpression.ts
Expand Up @@ -31,12 +31,12 @@ import {
import { ExpressionNode, INCLUDE_PARAMETERS, IncludeChildren, NodeBase } from './shared/Node';

export default class CallExpression extends NodeBase implements DeoptimizableEntity {
arguments!: (ExpressionNode | SpreadElement)[];
callee!: ExpressionNode | Super;
optional!: boolean;
type!: NodeType.tCallExpression;
declare arguments: (ExpressionNode | SpreadElement)[];
declare callee: ExpressionNode | Super;
declare optional: boolean;
declare type: NodeType.tCallExpression;
protected deoptimized = false;
private callOptions!: CallOptions;
private declare callOptions: CallOptions;
private deoptimizableDependentExpressions: DeoptimizableEntity[] = [];
private expressionsToBeDeoptimized = new Set<ExpressionEntity>();
private returnExpression: ExpressionEntity | null = null;
Expand Down
10 changes: 5 additions & 5 deletions src/ast/nodes/CatchClause.ts
Expand Up @@ -7,11 +7,11 @@ import { GenericEsTreeNode, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';

export default class CatchClause extends NodeBase {
body!: BlockStatement;
param!: PatternNode | null;
preventChildBlockScope!: true;
scope!: CatchScope;
type!: NodeType.tCatchClause;
declare body: BlockStatement;
declare param: PatternNode | null;
declare preventChildBlockScope: true;
declare scope: CatchScope;
declare type: NodeType.tCatchClause;

createScope(parentScope: Scope): void {
this.scope = new CatchScope(parentScope, this.context);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ChainExpression.ts
Expand Up @@ -4,6 +4,6 @@ import * as NodeType from './NodeType';
import { NodeBase } from './shared/Node';

export default class ChainExpression extends NodeBase {
expression!: CallExpression | MemberExpression;
type!: NodeType.tChainExpression;
declare expression: CallExpression | MemberExpression;
declare type: NodeType.tChainExpression;
}
6 changes: 3 additions & 3 deletions src/ast/nodes/ClassBody.ts
Expand Up @@ -8,9 +8,9 @@ import ClassNode from './shared/ClassNode';
import { GenericEsTreeNode, IncludeChildren, NodeBase } from './shared/Node';

export default class ClassBody extends NodeBase {
body!: (MethodDefinition | PropertyDefinition)[];
scope!: ClassBodyScope;
type!: NodeType.tClassBody;
declare body: (MethodDefinition | PropertyDefinition)[];
declare scope: ClassBodyScope;
declare type: NodeType.tClassBody;

createScope(parentScope: Scope): void {
this.scope = new ClassBodyScope(parentScope, this.parent as ClassNode, this.context);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ClassDeclaration.ts
Expand Up @@ -8,8 +8,8 @@ import ClassNode from './shared/ClassNode';
import { GenericEsTreeNode } from './shared/Node';

export default class ClassDeclaration extends ClassNode {
id!: IdentifierWithVariable | null;
type!: NodeType.tClassDeclaration;
declare id: IdentifierWithVariable | null;
declare type: NodeType.tClassDeclaration;

initialise(): void {
super.initialise();
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ClassExpression.ts
Expand Up @@ -5,7 +5,7 @@ import * as NodeType from './NodeType';
import ClassNode from './shared/ClassNode';

export default class ClassExpression extends ClassNode {
type!: NodeType.tClassExpression;
declare type: NodeType.tClassExpression;

render(
code: MagicString,
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/ConditionalExpression.ts
Expand Up @@ -26,10 +26,10 @@ import { MultiExpression } from './shared/MultiExpression';
import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';

export default class ConditionalExpression extends NodeBase implements DeoptimizableEntity {
alternate!: ExpressionNode;
consequent!: ExpressionNode;
test!: ExpressionNode;
type!: NodeType.tConditionalExpression;
declare alternate: ExpressionNode;
declare consequent: ExpressionNode;
declare test: ExpressionNode;
declare type: NodeType.tConditionalExpression;

private expressionsToBeDeoptimized: DeoptimizableEntity[] = [];
private isBranchResolutionAnalysed = false;
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ContinueStatement.ts
Expand Up @@ -9,8 +9,8 @@ import * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';

export default class ContinueStatement extends StatementBase {
label!: Identifier | null;
type!: NodeType.tContinueStatement;
declare label: Identifier | null;
declare type: NodeType.tContinueStatement;

hasEffects(context: HasEffectsContext): boolean {
if (this.label) {
Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/DoWhileStatement.ts
Expand Up @@ -3,9 +3,9 @@ import * as NodeType from './NodeType';
import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from './shared/Node';

export default class DoWhileStatement extends StatementBase {
body!: StatementNode;
test!: ExpressionNode;
type!: NodeType.tDoWhileStatement;
declare body: StatementNode;
declare test: ExpressionNode;
declare type: NodeType.tDoWhileStatement;

hasEffects(context: HasEffectsContext): boolean {
if (this.test.hasEffects(context)) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/EmptyStatement.ts
Expand Up @@ -2,7 +2,7 @@ import * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';

export default class EmptyStatement extends StatementBase {
type!: NodeType.tEmptyStatement;
declare type: NodeType.tEmptyStatement;

hasEffects(): boolean {
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/ExportAllDeclaration.ts
Expand Up @@ -6,10 +6,10 @@ import * as NodeType from './NodeType';
import { NodeBase } from './shared/Node';

export default class ExportAllDeclaration extends NodeBase {
exported!: Identifier | null;
needsBoundaries!: true;
source!: Literal<string>;
type!: NodeType.tExportAllDeclaration;
declare exported: Identifier | null;
declare needsBoundaries: true;
declare source: Literal<string>;
declare type: NodeType.tExportAllDeclaration;

hasEffects(): boolean {
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/ast/nodes/ExportDefaultDeclaration.ts
Expand Up @@ -41,13 +41,13 @@ function getIdInsertPosition(
}

export default class ExportDefaultDeclaration extends NodeBase {
declaration!: FunctionDeclaration | ClassDeclaration | ExpressionNode;
needsBoundaries!: true;
scope!: ModuleScope;
type!: NodeType.tExportDefaultDeclaration;
variable!: ExportDefaultVariable;
declare declaration: FunctionDeclaration | ClassDeclaration | ExpressionNode;
declare needsBoundaries: true;
declare scope: ModuleScope;
declare type: NodeType.tExportDefaultDeclaration;
declare variable: ExportDefaultVariable;

private declarationName: string | undefined;
private declare declarationName: string | undefined;

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
super.include(context, includeChildrenRecursively);
Expand Down

0 comments on commit f6c5f12

Please sign in to comment.