From 5700728bffff2b985f01d89f51e9bbe5ccffff14 Mon Sep 17 00:00:00 2001 From: dnalborczyk Date: Sun, 19 Sep 2021 00:56:33 -0400 Subject: [PATCH] prepare for useDefineForClassFields (#4224) * fix: use useDefineForClassFields in ts-config * fix class property types * Disable useDefineForClassFields for now Co-authored-by: Lukas Taegert-Atkinson Co-authored-by: Lukas Taegert-Atkinson --- src/ExternalModule.ts | 14 +++++--------- src/Graph.ts | 11 ++++------- src/Module.ts | 20 ++++++++++---------- src/ast/nodes/ArrayExpression.ts | 4 ++-- src/ast/nodes/ArrayPattern.ts | 4 ++-- src/ast/nodes/ArrowFunctionExpression.ts | 12 ++++++------ src/ast/nodes/AssignmentExpression.ts | 8 ++++---- src/ast/nodes/AssignmentPattern.ts | 6 +++--- src/ast/nodes/AwaitExpression.ts | 4 ++-- src/ast/nodes/BinaryExpression.ts | 8 ++++---- src/ast/nodes/BlockStatement.ts | 6 +++--- src/ast/nodes/BreakStatement.ts | 4 ++-- src/ast/nodes/CallExpression.ts | 10 +++++----- src/ast/nodes/CatchClause.ts | 10 +++++----- src/ast/nodes/ChainExpression.ts | 4 ++-- src/ast/nodes/ClassBody.ts | 6 +++--- src/ast/nodes/ClassDeclaration.ts | 4 ++-- src/ast/nodes/ClassExpression.ts | 2 +- src/ast/nodes/ConditionalExpression.ts | 8 ++++---- src/ast/nodes/ContinueStatement.ts | 4 ++-- src/ast/nodes/DoWhileStatement.ts | 6 +++--- src/ast/nodes/EmptyStatement.ts | 2 +- src/ast/nodes/ExportAllDeclaration.ts | 8 ++++---- src/ast/nodes/ExportDefaultDeclaration.ts | 12 ++++++------ src/ast/nodes/ExportNamedDeclaration.ts | 10 +++++----- src/ast/nodes/ExportSpecifier.ts | 6 +++--- src/ast/nodes/ExpressionStatement.ts | 4 ++-- src/ast/nodes/ForInStatement.ts | 8 ++++---- src/ast/nodes/ForOfStatement.ts | 10 +++++----- src/ast/nodes/ForStatement.ts | 10 +++++----- src/ast/nodes/FunctionDeclaration.ts | 2 +- src/ast/nodes/FunctionExpression.ts | 2 +- src/ast/nodes/Identifier.ts | 4 ++-- src/ast/nodes/IfStatement.ts | 12 ++++++------ src/ast/nodes/ImportDeclaration.ts | 8 ++++---- src/ast/nodes/ImportDefaultSpecifier.ts | 4 ++-- src/ast/nodes/ImportExpression.ts | 4 ++-- src/ast/nodes/ImportNamespaceSpecifier.ts | 4 ++-- src/ast/nodes/ImportSpecifier.ts | 6 +++--- src/ast/nodes/LabeledStatement.ts | 6 +++--- src/ast/nodes/Literal.ts | 8 ++++---- src/ast/nodes/LogicalExpression.ts | 8 ++++---- src/ast/nodes/MemberExpression.ts | 12 ++++++------ src/ast/nodes/MetaProperty.ts | 8 ++++---- src/ast/nodes/MethodDefinition.ts | 10 +++++----- src/ast/nodes/NewExpression.ts | 8 ++++---- src/ast/nodes/ObjectExpression.ts | 4 ++-- src/ast/nodes/ObjectPattern.ts | 4 ++-- src/ast/nodes/PrivateIdentifier.ts | 4 ++-- src/ast/nodes/Program.ts | 6 +++--- src/ast/nodes/Property.ts | 10 +++++----- src/ast/nodes/PropertyDefinition.ts | 10 +++++----- src/ast/nodes/RestElement.ts | 4 ++-- src/ast/nodes/ReturnStatement.ts | 4 ++-- src/ast/nodes/SequenceExpression.ts | 4 ++-- src/ast/nodes/SpreadElement.ts | 4 ++-- src/ast/nodes/Super.ts | 5 ++--- src/ast/nodes/SwitchCase.ts | 8 ++++---- src/ast/nodes/SwitchStatement.ts | 8 ++++---- src/ast/nodes/TaggedTemplateExpression.ts | 8 ++++---- src/ast/nodes/TemplateElement.ts | 6 +++--- src/ast/nodes/TemplateLiteral.ts | 6 +++--- src/ast/nodes/ThisExpression.ts | 7 +++---- src/ast/nodes/ThrowStatement.ts | 4 ++-- src/ast/nodes/TryStatement.ts | 8 ++++---- src/ast/nodes/UnaryExpression.ts | 8 ++++---- src/ast/nodes/UpdateExpression.ts | 8 ++++---- src/ast/nodes/VariableDeclaration.ts | 6 +++--- src/ast/nodes/VariableDeclarator.ts | 6 +++--- src/ast/nodes/WhileStatement.ts | 6 +++--- src/ast/nodes/YieldExpression.ts | 6 +++--- src/ast/nodes/shared/ClassNode.ts | 8 ++++---- src/ast/nodes/shared/FunctionNode.ts | 12 ++++++------ src/ast/nodes/shared/MethodBase.ts | 8 ++++---- src/ast/nodes/shared/Node.ts | 10 +++++----- src/ast/scopes/ChildScope.ts | 2 +- src/ast/scopes/GlobalScope.ts | 2 +- src/ast/scopes/ModuleScope.ts | 2 +- src/ast/scopes/TrackingScope.ts | 2 +- src/ast/variables/ExportShimVariable.ts | 2 ++ src/ast/variables/ExternalVariable.ts | 3 +-- src/ast/variables/NamespaceVariable.ts | 2 +- src/ast/variables/Variable.ts | 4 ++-- src/utils/collapseSourcemaps.ts | 3 +-- src/watch/watch.ts | 11 ++++------- tsconfig.json | 3 ++- 86 files changed, 274 insertions(+), 285 deletions(-) diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index d65456b07de..b950f45415f 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -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; + execIndex = Infinity; + exportedVariables = new Map(); 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; @@ -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 = { diff --git a/src/Graph.ts b/src/Graph.ts index 67b423bf724..9ed4bbdb4d9 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -45,26 +45,24 @@ function normalizeEntryModules( export default class Graph { acornParser: typeof acorn.Parser; - cachedModules: Map; - deoptimizationTracker: PathTracker; + cachedModules = new Map(); + deoptimizationTracker = new PathTracker(); entryModules: Module[] = []; moduleLoader: ModuleLoader; modulesById = new Map(); needsTreeshakingPass = false; phase: BuildPhase = BuildPhase.LOAD_AND_PARSE; pluginDriver: PluginDriver; - scope: GlobalScope; + scope = new GlobalScope(); watchFiles: Record = Object.create(null); watchMode = false; private externalModules: ExternalModule[] = []; private implicitEntryModules: Module[] = []; private modules: Module[] = []; - private pluginCache?: Record; + private declare pluginCache?: Record; 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); @@ -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); } diff --git a/src/Module.ts b/src/Module.ts index 6dda6782c22..0ac3b8f6622 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -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>(); - sourcemapChain!: DecodedSourceMapOrMissing[]; + declare sourcemapChain: DecodedSourceMapOrMissing[]; sources = new Set(); - transformFiles?: EmittedFile[]; + declare transformFiles?: EmittedFile[]; userChunkNames = new Set(); usesTopLevelAwait = false; private allExportNames: Set | 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 | null = null; private exportShimVariable: ExportShimVariable = new ExportShimVariable(this); - private magicString!: MagicString; + private declare magicString: MagicString; private namespaceReexportsByName: Record = Object.create(null); private relevantDependencies: Set | null = null; private syntheticExports = new Map(); diff --git a/src/ast/nodes/ArrayExpression.ts b/src/ast/nodes/ArrayExpression.ts index 89ab710f65e..5e466a10ed5 100644 --- a/src/ast/nodes/ArrayExpression.ts +++ b/src/ast/nodes/ArrayExpression.ts @@ -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 { diff --git a/src/ast/nodes/ArrayPattern.ts b/src/ast/nodes/ArrayPattern.ts index 8b737f6480c..19b1d623fa0 100644 --- a/src/ast/nodes/ArrayPattern.ts +++ b/src/ast/nodes/ArrayPattern.ts @@ -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[], diff --git a/src/ast/nodes/ArrowFunctionExpression.ts b/src/ast/nodes/ArrowFunctionExpression.ts index fd8ca028256..21b12f6a0d7 100644 --- a/src/ast/nodes/ArrowFunctionExpression.ts +++ b/src/ast/nodes/ArrowFunctionExpression.ts @@ -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 { diff --git a/src/ast/nodes/AssignmentExpression.ts b/src/ast/nodes/AssignmentExpression.ts index ffb86060b5b..827099493fe 100644 --- a/src/ast/nodes/AssignmentExpression.ts +++ b/src/ast/nodes/AssignmentExpression.ts @@ -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: | '=' | '+=' | '-=' @@ -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 { diff --git a/src/ast/nodes/AssignmentPattern.ts b/src/ast/nodes/AssignmentPattern.ts index 22b148f4880..2db30dcecd9 100644 --- a/src/ast/nodes/AssignmentPattern.ts +++ b/src/ast/nodes/AssignmentPattern.ts @@ -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( diff --git a/src/ast/nodes/AwaitExpression.ts b/src/ast/nodes/AwaitExpression.ts index 22ad50cdafe..9b7d8b127eb 100644 --- a/src/ast/nodes/AwaitExpression.ts +++ b/src/ast/nodes/AwaitExpression.ts @@ -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 { diff --git a/src/ast/nodes/BinaryExpression.ts b/src/ast/nodes/BinaryExpression.ts index 95121aed507..f216b78fa48 100644 --- a/src/ast/nodes/BinaryExpression.ts +++ b/src/ast/nodes/BinaryExpression.ts @@ -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 {} diff --git a/src/ast/nodes/BlockStatement.ts b/src/ast/nodes/BlockStatement.ts index be09138f43f..632795fb00f 100644 --- a/src/ast/nodes/BlockStatement.ts +++ b/src/ast/nodes/BlockStatement.ts @@ -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 { diff --git a/src/ast/nodes/BreakStatement.ts b/src/ast/nodes/BreakStatement.ts index 0d505a4c195..5da9497e242 100644 --- a/src/ast/nodes/BreakStatement.ts +++ b/src/ast/nodes/BreakStatement.ts @@ -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) { diff --git a/src/ast/nodes/CallExpression.ts b/src/ast/nodes/CallExpression.ts index ada77b9a749..88f81143d6c 100644 --- a/src/ast/nodes/CallExpression.ts +++ b/src/ast/nodes/CallExpression.ts @@ -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(); private returnExpression: ExpressionEntity | null = null; diff --git a/src/ast/nodes/CatchClause.ts b/src/ast/nodes/CatchClause.ts index 6d3f87c4a12..85a7246b94f 100644 --- a/src/ast/nodes/CatchClause.ts +++ b/src/ast/nodes/CatchClause.ts @@ -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); diff --git a/src/ast/nodes/ChainExpression.ts b/src/ast/nodes/ChainExpression.ts index 77c8a021819..88231ebedef 100644 --- a/src/ast/nodes/ChainExpression.ts +++ b/src/ast/nodes/ChainExpression.ts @@ -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; } diff --git a/src/ast/nodes/ClassBody.ts b/src/ast/nodes/ClassBody.ts index 2b15c9bff97..5e3f01f88ac 100644 --- a/src/ast/nodes/ClassBody.ts +++ b/src/ast/nodes/ClassBody.ts @@ -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); diff --git a/src/ast/nodes/ClassDeclaration.ts b/src/ast/nodes/ClassDeclaration.ts index 894eacf0a53..e5ba4e8b977 100644 --- a/src/ast/nodes/ClassDeclaration.ts +++ b/src/ast/nodes/ClassDeclaration.ts @@ -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(); diff --git a/src/ast/nodes/ClassExpression.ts b/src/ast/nodes/ClassExpression.ts index 24592c7b940..82fd208bd33 100644 --- a/src/ast/nodes/ClassExpression.ts +++ b/src/ast/nodes/ClassExpression.ts @@ -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, diff --git a/src/ast/nodes/ConditionalExpression.ts b/src/ast/nodes/ConditionalExpression.ts index 41f60ed5e22..26a2fca6508 100644 --- a/src/ast/nodes/ConditionalExpression.ts +++ b/src/ast/nodes/ConditionalExpression.ts @@ -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; diff --git a/src/ast/nodes/ContinueStatement.ts b/src/ast/nodes/ContinueStatement.ts index aaefb2caa6a..28f87168704 100644 --- a/src/ast/nodes/ContinueStatement.ts +++ b/src/ast/nodes/ContinueStatement.ts @@ -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) { diff --git a/src/ast/nodes/DoWhileStatement.ts b/src/ast/nodes/DoWhileStatement.ts index b15dfa026b3..ca30a4eaf60 100644 --- a/src/ast/nodes/DoWhileStatement.ts +++ b/src/ast/nodes/DoWhileStatement.ts @@ -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; diff --git a/src/ast/nodes/EmptyStatement.ts b/src/ast/nodes/EmptyStatement.ts index 7021b32d7ab..f34e3214b66 100644 --- a/src/ast/nodes/EmptyStatement.ts +++ b/src/ast/nodes/EmptyStatement.ts @@ -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; diff --git a/src/ast/nodes/ExportAllDeclaration.ts b/src/ast/nodes/ExportAllDeclaration.ts index 08aea6d59ef..850540c1094 100644 --- a/src/ast/nodes/ExportAllDeclaration.ts +++ b/src/ast/nodes/ExportAllDeclaration.ts @@ -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; - type!: NodeType.tExportAllDeclaration; + declare exported: Identifier | null; + declare needsBoundaries: true; + declare source: Literal; + declare type: NodeType.tExportAllDeclaration; hasEffects(): boolean { return false; diff --git a/src/ast/nodes/ExportDefaultDeclaration.ts b/src/ast/nodes/ExportDefaultDeclaration.ts index bb06a0884b1..5ce1950a026 100644 --- a/src/ast/nodes/ExportDefaultDeclaration.ts +++ b/src/ast/nodes/ExportDefaultDeclaration.ts @@ -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); diff --git a/src/ast/nodes/ExportNamedDeclaration.ts b/src/ast/nodes/ExportNamedDeclaration.ts index fdbbebda80e..d6c2fe89d06 100644 --- a/src/ast/nodes/ExportNamedDeclaration.ts +++ b/src/ast/nodes/ExportNamedDeclaration.ts @@ -10,11 +10,11 @@ import VariableDeclaration from './VariableDeclaration'; import { Node, NodeBase } from './shared/Node'; export default class ExportNamedDeclaration extends NodeBase { - declaration!: FunctionDeclaration | ClassDeclaration | VariableDeclaration | null; - needsBoundaries!: true; - source!: Literal | null; - specifiers!: ExportSpecifier[]; - type!: NodeType.tExportNamedDeclaration; + declare declaration: FunctionDeclaration | ClassDeclaration | VariableDeclaration | null; + declare needsBoundaries: true; + declare source: Literal | null; + declare specifiers: ExportSpecifier[]; + declare type: NodeType.tExportNamedDeclaration; bind(): void { // Do not bind specifiers diff --git a/src/ast/nodes/ExportSpecifier.ts b/src/ast/nodes/ExportSpecifier.ts index 1772b4da009..4ee18baeb39 100644 --- a/src/ast/nodes/ExportSpecifier.ts +++ b/src/ast/nodes/ExportSpecifier.ts @@ -3,7 +3,7 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ExportSpecifier extends NodeBase { - exported!: Identifier; - local!: Identifier; - type!: NodeType.tExportSpecifier; + declare exported: Identifier; + declare local: Identifier; + declare type: NodeType.tExportSpecifier; } diff --git a/src/ast/nodes/ExpressionStatement.ts b/src/ast/nodes/ExpressionStatement.ts index eb884b9c2bb..31954b8fbc8 100644 --- a/src/ast/nodes/ExpressionStatement.ts +++ b/src/ast/nodes/ExpressionStatement.ts @@ -5,8 +5,8 @@ import * as NodeType from './NodeType'; import { ExpressionNode, StatementBase } from './shared/Node'; export default class ExpressionStatement extends StatementBase { - directive?: string; - expression!: ExpressionNode; + declare directive?: string; + declare expression: ExpressionNode; initialise(): void { if ( diff --git a/src/ast/nodes/ForInStatement.ts b/src/ast/nodes/ForInStatement.ts index ac375c0c3ec..b010bea22d6 100644 --- a/src/ast/nodes/ForInStatement.ts +++ b/src/ast/nodes/ForInStatement.ts @@ -10,10 +10,10 @@ import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from '. import { PatternNode } from './shared/Pattern'; export default class ForInStatement extends StatementBase { - body!: StatementNode; - left!: VariableDeclaration | PatternNode; - right!: ExpressionNode; - type!: NodeType.tForInStatement; + declare body: StatementNode; + declare left: VariableDeclaration | PatternNode; + declare right: ExpressionNode; + declare type: NodeType.tForInStatement; protected deoptimized = false; createScope(parentScope: Scope): void { diff --git a/src/ast/nodes/ForOfStatement.ts b/src/ast/nodes/ForOfStatement.ts index fc7a54a46b7..4c7beed6c30 100644 --- a/src/ast/nodes/ForOfStatement.ts +++ b/src/ast/nodes/ForOfStatement.ts @@ -10,11 +10,11 @@ import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from '. import { PatternNode } from './shared/Pattern'; export default class ForOfStatement extends StatementBase { - await!: boolean; - body!: StatementNode; - left!: VariableDeclaration | PatternNode; - right!: ExpressionNode; - type!: NodeType.tForOfStatement; + declare await: boolean; + declare body: StatementNode; + declare left: VariableDeclaration | PatternNode; + declare right: ExpressionNode; + declare type: NodeType.tForOfStatement; protected deoptimized = false; createScope(parentScope: Scope): void { diff --git a/src/ast/nodes/ForStatement.ts b/src/ast/nodes/ForStatement.ts index 9267d550a46..9a67639e363 100644 --- a/src/ast/nodes/ForStatement.ts +++ b/src/ast/nodes/ForStatement.ts @@ -8,11 +8,11 @@ import VariableDeclaration from './VariableDeclaration'; import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from './shared/Node'; export default class ForStatement extends StatementBase { - body!: StatementNode; - init!: VariableDeclaration | ExpressionNode | null; - test!: ExpressionNode | null; - type!: NodeType.tForStatement; - update!: ExpressionNode | null; + declare body: StatementNode; + declare init: VariableDeclaration | ExpressionNode | null; + declare test: ExpressionNode | null; + declare type: NodeType.tForStatement; + declare update: ExpressionNode | null; createScope(parentScope: Scope): void { this.scope = new BlockScope(parentScope); diff --git a/src/ast/nodes/FunctionDeclaration.ts b/src/ast/nodes/FunctionDeclaration.ts index ad281ecfddd..b0c4ebc973d 100644 --- a/src/ast/nodes/FunctionDeclaration.ts +++ b/src/ast/nodes/FunctionDeclaration.ts @@ -5,7 +5,7 @@ import FunctionNode from './shared/FunctionNode'; import { GenericEsTreeNode } from './shared/Node'; export default class FunctionDeclaration extends FunctionNode { - type!: NodeType.tFunctionDeclaration; + declare type: NodeType.tFunctionDeclaration; initialise(): void { super.initialise(); diff --git a/src/ast/nodes/FunctionExpression.ts b/src/ast/nodes/FunctionExpression.ts index 8cce263c8eb..4783a0cddd0 100644 --- a/src/ast/nodes/FunctionExpression.ts +++ b/src/ast/nodes/FunctionExpression.ts @@ -5,7 +5,7 @@ import * as NodeType from './NodeType'; import FunctionNode from './shared/FunctionNode'; export default class FunctionExpression extends FunctionNode { - type!: NodeType.tFunctionExpression; + declare type: NodeType.tFunctionExpression; render( code: MagicString, diff --git a/src/ast/nodes/Identifier.ts b/src/ast/nodes/Identifier.ts index 7b5a1d3a11f..eb2cdaa177d 100644 --- a/src/ast/nodes/Identifier.ts +++ b/src/ast/nodes/Identifier.ts @@ -29,8 +29,8 @@ const tdzVariableKinds = { }; export default class Identifier extends NodeBase implements PatternNode { - name!: string; - type!: NodeType.tIdentifier; + declare name: string; + declare type: NodeType.tIdentifier; variable: Variable | null = null; protected deoptimized = false; private isTDZAccess: boolean | null = null; diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index 6276ea091e8..8fe01dee308 100644 --- a/src/ast/nodes/IfStatement.ts +++ b/src/ast/nodes/IfStatement.ts @@ -19,13 +19,13 @@ import { const unset = Symbol('unset'); export default class IfStatement extends StatementBase implements DeoptimizableEntity { - alternate!: StatementNode | null; - consequent!: StatementNode; - test!: ExpressionNode; - type!: NodeType.tIfStatement; + declare alternate: StatementNode | null; + declare consequent: StatementNode; + declare test: ExpressionNode; + declare type: NodeType.tIfStatement; - private alternateScope?: TrackingScope; - private consequentScope!: TrackingScope; + private declare alternateScope?: TrackingScope; + private declare consequentScope: TrackingScope; private testValue: LiteralValueOrUnknown | typeof unset = unset; deoptimizeCache(): void { diff --git a/src/ast/nodes/ImportDeclaration.ts b/src/ast/nodes/ImportDeclaration.ts index 6727addccea..c91c72aac65 100644 --- a/src/ast/nodes/ImportDeclaration.ts +++ b/src/ast/nodes/ImportDeclaration.ts @@ -8,10 +8,10 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ImportDeclaration extends NodeBase { - needsBoundaries!: true; - source!: Literal; - specifiers!: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[]; - type!: NodeType.tImportDeclaration; + declare needsBoundaries: true; + declare source: Literal; + declare specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[]; + declare type: NodeType.tImportDeclaration; // Do not bind specifiers bind(): void {} diff --git a/src/ast/nodes/ImportDefaultSpecifier.ts b/src/ast/nodes/ImportDefaultSpecifier.ts index f55eab1d4e2..25e3686e6a2 100644 --- a/src/ast/nodes/ImportDefaultSpecifier.ts +++ b/src/ast/nodes/ImportDefaultSpecifier.ts @@ -3,6 +3,6 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ImportDefaultSpecifier extends NodeBase { - local!: Identifier; - type!: NodeType.tImportDefaultSpecifier; + declare local: Identifier; + declare type: NodeType.tImportDefaultSpecifier; } diff --git a/src/ast/nodes/ImportExpression.ts b/src/ast/nodes/ImportExpression.ts index f5e67cdd6ac..0f33f75fc53 100644 --- a/src/ast/nodes/ImportExpression.ts +++ b/src/ast/nodes/ImportExpression.ts @@ -21,8 +21,8 @@ interface DynamicImportMechanism { export default class ImportExpression extends NodeBase { inlineNamespace: NamespaceVariable | null = null; - source!: ExpressionNode; - type!: NodeType.tImportExpression; + declare source: ExpressionNode; + declare type: NodeType.tImportExpression; private mechanism: DynamicImportMechanism | null = null; private resolution: Module | ExternalModule | string | null = null; diff --git a/src/ast/nodes/ImportNamespaceSpecifier.ts b/src/ast/nodes/ImportNamespaceSpecifier.ts index 4a4d7f17c18..9928f47114a 100644 --- a/src/ast/nodes/ImportNamespaceSpecifier.ts +++ b/src/ast/nodes/ImportNamespaceSpecifier.ts @@ -3,6 +3,6 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ImportNamespaceSpecifier extends NodeBase { - local!: Identifier; - type!: NodeType.tImportNamespaceSpecifier; + declare local: Identifier; + declare type: NodeType.tImportNamespaceSpecifier; } diff --git a/src/ast/nodes/ImportSpecifier.ts b/src/ast/nodes/ImportSpecifier.ts index 1852bcb4e97..c1c8cc15786 100644 --- a/src/ast/nodes/ImportSpecifier.ts +++ b/src/ast/nodes/ImportSpecifier.ts @@ -3,7 +3,7 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ImportSpecifier extends NodeBase { - imported!: Identifier; - local!: Identifier; - type!: NodeType.tImportSpecifier; + declare imported: Identifier; + declare local: Identifier; + declare type: NodeType.tImportSpecifier; } diff --git a/src/ast/nodes/LabeledStatement.ts b/src/ast/nodes/LabeledStatement.ts index 216529e446c..ed535ec1a88 100644 --- a/src/ast/nodes/LabeledStatement.ts +++ b/src/ast/nodes/LabeledStatement.ts @@ -10,9 +10,9 @@ import * as NodeType from './NodeType'; import { IncludeChildren, StatementBase, StatementNode } from './shared/Node'; export default class LabeledStatement extends StatementBase { - body!: StatementNode; - label!: Identifier; - type!: NodeType.tLabeledStatement; + declare body: StatementNode; + declare label: Identifier; + declare type: NodeType.tLabeledStatement; hasEffects(context: HasEffectsContext): boolean { const brokenFlow = context.brokenFlow; diff --git a/src/ast/nodes/Literal.ts b/src/ast/nodes/Literal.ts index 6a3229502fe..e6505f9a609 100644 --- a/src/ast/nodes/Literal.ts +++ b/src/ast/nodes/Literal.ts @@ -20,14 +20,14 @@ import { GenericEsTreeNode, NodeBase } from './shared/Node'; export type LiteralValue = string | boolean | null | number | RegExp | undefined; export default class Literal extends NodeBase { - regex?: { + declare regex?: { flags: string; pattern: string; }; - type!: NodeType.tLiteral; - value!: T; + declare type: NodeType.tLiteral; + declare value: T; - private members!: { [key: string]: MemberDescription }; + private declare members: { [key: string]: MemberDescription }; deoptimizeThisOnEventAtPath(): void {} diff --git a/src/ast/nodes/LogicalExpression.ts b/src/ast/nodes/LogicalExpression.ts index 7409ae30a30..363e2ba8069 100644 --- a/src/ast/nodes/LogicalExpression.ts +++ b/src/ast/nodes/LogicalExpression.ts @@ -27,10 +27,10 @@ import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node'; export type LogicalOperator = '||' | '&&' | '??'; export default class LogicalExpression extends NodeBase implements DeoptimizableEntity { - left!: ExpressionNode; - operator!: LogicalOperator; - right!: ExpressionNode; - type!: NodeType.tLogicalExpression; + declare left: ExpressionNode; + declare operator: LogicalOperator; + declare right: ExpressionNode; + declare type: NodeType.tLogicalExpression; // We collect deoptimization information if usedBranch !== null private expressionsToBeDeoptimized: DeoptimizableEntity[] = []; diff --git a/src/ast/nodes/MemberExpression.ts b/src/ast/nodes/MemberExpression.ts index f9d6b2b510d..6e92c255e8a 100644 --- a/src/ast/nodes/MemberExpression.ts +++ b/src/ast/nodes/MemberExpression.ts @@ -81,12 +81,12 @@ function getStringFromPath(path: PathWithPositions): string { } export default class MemberExpression extends NodeBase implements DeoptimizableEntity { - computed!: boolean; - object!: ExpressionNode | Super; - optional!: boolean; - property!: ExpressionNode | PrivateIdentifier; - propertyKey!: ObjectPathKey | null; - type!: NodeType.tMemberExpression; + declare computed: boolean; + declare object: ExpressionNode | Super; + declare optional: boolean; + declare property: ExpressionNode | PrivateIdentifier; + declare propertyKey: ObjectPathKey | null; + declare type: NodeType.tMemberExpression; variable: Variable | null = null; protected deoptimized = false; private bound = false; diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 38da8c66ca1..87709692647 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -15,11 +15,11 @@ const CHUNK_PREFIX = 'ROLLUP_CHUNK_URL_'; const FILE_PREFIX = 'ROLLUP_FILE_URL_'; export default class MetaProperty extends NodeBase { - meta!: Identifier; - property!: Identifier; - type!: NodeType.tMetaProperty; + declare meta: Identifier; + declare property: Identifier; + declare type: NodeType.tMetaProperty; - private metaProperty?: string | null; + private declare metaProperty?: string | null; addAccessedGlobals( format: InternalModuleFormat, diff --git a/src/ast/nodes/MethodDefinition.ts b/src/ast/nodes/MethodDefinition.ts index 07b0e88366a..e6b39cc9a21 100644 --- a/src/ast/nodes/MethodDefinition.ts +++ b/src/ast/nodes/MethodDefinition.ts @@ -5,9 +5,9 @@ import MethodBase from './shared/MethodBase'; import { ExpressionNode } from './shared/Node'; export default class MethodDefinition extends MethodBase { - key!: ExpressionNode | PrivateIdentifier; - kind!: 'constructor' | 'method' | 'get' | 'set'; - static!: boolean; - type!: NodeType.tMethodDefinition; - value!: FunctionExpression; + declare key: ExpressionNode | PrivateIdentifier; + declare kind: 'constructor' | 'method' | 'get' | 'set'; + declare static: boolean; + declare type: NodeType.tMethodDefinition; + declare value: FunctionExpression; } diff --git a/src/ast/nodes/NewExpression.ts b/src/ast/nodes/NewExpression.ts index 633ad8a124a..8bf4e270371 100644 --- a/src/ast/nodes/NewExpression.ts +++ b/src/ast/nodes/NewExpression.ts @@ -6,11 +6,11 @@ import * as NodeType from './NodeType'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class NewExpression extends NodeBase { - arguments!: ExpressionNode[]; - callee!: ExpressionNode; - type!: NodeType.tNewExpression; + declare arguments: ExpressionNode[]; + declare callee: ExpressionNode; + declare type: NodeType.tNewExpression; protected deoptimized = false; - private callOptions!: CallOptions; + private declare callOptions: CallOptions; hasEffects(context: HasEffectsContext): boolean { if (!this.deoptimized) this.applyDeoptimizations(); diff --git a/src/ast/nodes/ObjectExpression.ts b/src/ast/nodes/ObjectExpression.ts index 1fb9e703b7d..d2310cc0dec 100644 --- a/src/ast/nodes/ObjectExpression.ts +++ b/src/ast/nodes/ObjectExpression.ts @@ -23,8 +23,8 @@ import { ObjectEntity, ObjectProperty } from './shared/ObjectEntity'; import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype'; export default class ObjectExpression extends NodeBase implements DeoptimizableEntity { - properties!: (Property | SpreadElement)[]; - type!: NodeType.tObjectExpression; + declare properties: (Property | SpreadElement)[]; + declare type: NodeType.tObjectExpression; private objectEntity: ObjectEntity | null = null; deoptimizeCache(): void { diff --git a/src/ast/nodes/ObjectPattern.ts b/src/ast/nodes/ObjectPattern.ts index 57d1b1632ed..7d6d968c4ba 100644 --- a/src/ast/nodes/ObjectPattern.ts +++ b/src/ast/nodes/ObjectPattern.ts @@ -10,8 +10,8 @@ import { NodeBase } from './shared/Node'; import { PatternNode } from './shared/Pattern'; export default class ObjectPattern extends NodeBase implements PatternNode { - properties!: (Property | RestElement)[]; - type!: NodeType.tObjectPattern; + declare properties: (Property | RestElement)[]; + declare type: NodeType.tObjectPattern; addExportedVariables( variables: Variable[], diff --git a/src/ast/nodes/PrivateIdentifier.ts b/src/ast/nodes/PrivateIdentifier.ts index 1846762730f..355f7a4ceb7 100644 --- a/src/ast/nodes/PrivateIdentifier.ts +++ b/src/ast/nodes/PrivateIdentifier.ts @@ -2,6 +2,6 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class PrivateIdentifier extends NodeBase { - name!: string; - type!: NodeType.tPrivateIdentifier; + declare name: string; + declare type: NodeType.tPrivateIdentifier; } diff --git a/src/ast/nodes/Program.ts b/src/ast/nodes/Program.ts index cf5af219ea7..12e9723b0a9 100644 --- a/src/ast/nodes/Program.ts +++ b/src/ast/nodes/Program.ts @@ -5,9 +5,9 @@ import * as NodeType from './NodeType'; import { IncludeChildren, NodeBase, StatementNode } from './shared/Node'; export default class Program extends NodeBase { - body!: StatementNode[]; - sourceType!: 'module'; - type!: NodeType.tProgram; + declare body: StatementNode[]; + declare sourceType: 'module'; + declare type: NodeType.tProgram; private hasCachedEffect = false; diff --git a/src/ast/nodes/Property.ts b/src/ast/nodes/Property.ts index 6e2021512ec..9469900912d 100644 --- a/src/ast/nodes/Property.ts +++ b/src/ast/nodes/Property.ts @@ -11,11 +11,11 @@ import { ExpressionNode } from './shared/Node'; import { PatternNode } from './shared/Pattern'; export default class Property extends MethodBase implements PatternNode { - key!: ExpressionNode; - kind!: 'init' | 'get' | 'set'; - method!: boolean; - shorthand!: boolean; - type!: NodeType.tProperty; + declare key: ExpressionNode; + declare kind: 'init' | 'get' | 'set'; + declare method: boolean; + declare shorthand: boolean; + declare type: NodeType.tProperty; protected deoptimized = false; private declarationInit: ExpressionEntity | null = null; diff --git a/src/ast/nodes/PropertyDefinition.ts b/src/ast/nodes/PropertyDefinition.ts index 77dd5e58af1..cd6107288c7 100644 --- a/src/ast/nodes/PropertyDefinition.ts +++ b/src/ast/nodes/PropertyDefinition.ts @@ -14,11 +14,11 @@ import { import { ExpressionNode, NodeBase } from './shared/Node'; export default class PropertyDefinition extends NodeBase { - computed!: boolean; - key!: ExpressionNode | PrivateIdentifier; - static!: boolean; - type!: NodeType.tPropertyDefinition; - value!: ExpressionNode | null; + declare computed: boolean; + declare key: ExpressionNode | PrivateIdentifier; + declare static: boolean; + declare type: NodeType.tPropertyDefinition; + declare value: ExpressionNode | null; deoptimizePath(path: ObjectPath): void { this.value?.deoptimizePath(path); diff --git a/src/ast/nodes/RestElement.ts b/src/ast/nodes/RestElement.ts index 77653bde676..0a4f37cb532 100644 --- a/src/ast/nodes/RestElement.ts +++ b/src/ast/nodes/RestElement.ts @@ -8,8 +8,8 @@ import { NodeBase } from './shared/Node'; import { PatternNode } from './shared/Pattern'; export default class RestElement extends NodeBase implements PatternNode { - argument!: PatternNode; - type!: NodeType.tRestElement; + declare argument: PatternNode; + declare type: NodeType.tRestElement; protected deoptimized = false; private declarationInit: ExpressionEntity | null = null; diff --git a/src/ast/nodes/ReturnStatement.ts b/src/ast/nodes/ReturnStatement.ts index 6240ac591ce..4900f36367a 100644 --- a/src/ast/nodes/ReturnStatement.ts +++ b/src/ast/nodes/ReturnStatement.ts @@ -10,8 +10,8 @@ import { UNKNOWN_EXPRESSION } from './shared/Expression'; import { ExpressionNode, IncludeChildren, StatementBase } from './shared/Node'; export default class ReturnStatement extends StatementBase { - argument!: ExpressionNode | null; - type!: NodeType.tReturnStatement; + declare argument: ExpressionNode | null; + declare type: NodeType.tReturnStatement; hasEffects(context: HasEffectsContext): boolean { if ( diff --git a/src/ast/nodes/SequenceExpression.ts b/src/ast/nodes/SequenceExpression.ts index 9e05e0817f9..84f683bba88 100644 --- a/src/ast/nodes/SequenceExpression.ts +++ b/src/ast/nodes/SequenceExpression.ts @@ -18,8 +18,8 @@ import { ExpressionEntity, LiteralValueOrUnknown } from './shared/Expression'; import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node'; export default class SequenceExpression extends NodeBase { - expressions!: ExpressionNode[]; - type!: NodeType.tSequenceExpression; + declare expressions: ExpressionNode[]; + declare type: NodeType.tSequenceExpression; deoptimizePath(path: ObjectPath): void { this.expressions[this.expressions.length - 1].deoptimizePath(path); diff --git a/src/ast/nodes/SpreadElement.ts b/src/ast/nodes/SpreadElement.ts index 794436ee8a4..5d57efb0b88 100644 --- a/src/ast/nodes/SpreadElement.ts +++ b/src/ast/nodes/SpreadElement.ts @@ -7,8 +7,8 @@ import { ExpressionEntity } from './shared/Expression'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class SpreadElement extends NodeBase { - argument!: ExpressionNode; - type!: NodeType.tSpreadElement; + declare argument: ExpressionNode; + declare type: NodeType.tSpreadElement; protected deoptimized = false; deoptimizeThisOnEventAtPath( diff --git a/src/ast/nodes/Super.ts b/src/ast/nodes/Super.ts index 8d6660c25ee..f3d5695f679 100644 --- a/src/ast/nodes/Super.ts +++ b/src/ast/nodes/Super.ts @@ -4,9 +4,8 @@ import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class Super extends NodeBase { - type!: NodeType.tSuper; - - variable!: ThisVariable; + declare type: NodeType.tSuper; + declare variable: ThisVariable; bind(): void { this.variable = this.scope.findVariable('this') as ThisVariable; diff --git a/src/ast/nodes/SwitchCase.ts b/src/ast/nodes/SwitchCase.ts index a6958546fce..15648a0c276 100644 --- a/src/ast/nodes/SwitchCase.ts +++ b/src/ast/nodes/SwitchCase.ts @@ -10,10 +10,10 @@ import * as NodeType from './NodeType'; import { ExpressionNode, IncludeChildren, NodeBase, StatementNode } from './shared/Node'; export default class SwitchCase extends NodeBase { - consequent!: StatementNode[]; - needsBoundaries!: true; - test!: ExpressionNode | null; - type!: NodeType.tSwitchCase; + declare consequent: StatementNode[]; + declare needsBoundaries: true; + declare test: ExpressionNode | null; + declare type: NodeType.tSwitchCase; hasEffects(context: HasEffectsContext): boolean { if (this.test && this.test.hasEffects(context)) return true; diff --git a/src/ast/nodes/SwitchStatement.ts b/src/ast/nodes/SwitchStatement.ts index 91fbae52133..b338135bd45 100644 --- a/src/ast/nodes/SwitchStatement.ts +++ b/src/ast/nodes/SwitchStatement.ts @@ -13,11 +13,11 @@ import SwitchCase from './SwitchCase'; import { ExpressionNode, IncludeChildren, StatementBase } from './shared/Node'; export default class SwitchStatement extends StatementBase { - cases!: SwitchCase[]; - discriminant!: ExpressionNode; - type!: NodeType.tSwitchStatement; + declare cases: SwitchCase[]; + declare discriminant: ExpressionNode; + declare type: NodeType.tSwitchStatement; - private defaultCase!: number | null; + private declare defaultCase: number | null; createScope(parentScope: Scope): void { this.scope = new BlockScope(parentScope); diff --git a/src/ast/nodes/TaggedTemplateExpression.ts b/src/ast/nodes/TaggedTemplateExpression.ts index 012eceb05dd..660c1bd415f 100644 --- a/src/ast/nodes/TaggedTemplateExpression.ts +++ b/src/ast/nodes/TaggedTemplateExpression.ts @@ -9,11 +9,11 @@ import TemplateLiteral from './TemplateLiteral'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class TaggedTemplateExpression extends NodeBase { - quasi!: TemplateLiteral; - tag!: ExpressionNode; - type!: NodeType.tTaggedTemplateExpression; + declare quasi: TemplateLiteral; + declare tag: ExpressionNode; + declare type: NodeType.tTaggedTemplateExpression; - private callOptions!: CallOptions; + private declare callOptions: CallOptions; bind(): void { super.bind(); diff --git a/src/ast/nodes/TemplateElement.ts b/src/ast/nodes/TemplateElement.ts index af1d4106ff4..a1708182e1c 100644 --- a/src/ast/nodes/TemplateElement.ts +++ b/src/ast/nodes/TemplateElement.ts @@ -2,9 +2,9 @@ import * as NodeType from './NodeType'; import { GenericEsTreeNode, NodeBase } from './shared/Node'; export default class TemplateElement extends NodeBase { - tail!: boolean; - type!: NodeType.tTemplateElement; - value!: { + declare tail: boolean; + declare type: NodeType.tTemplateElement; + declare value: { cooked: string | null; raw: string; }; diff --git a/src/ast/nodes/TemplateLiteral.ts b/src/ast/nodes/TemplateLiteral.ts index 3bfca39f3d0..f24ce4c073f 100644 --- a/src/ast/nodes/TemplateLiteral.ts +++ b/src/ast/nodes/TemplateLiteral.ts @@ -7,9 +7,9 @@ import { LiteralValueOrUnknown, UnknownValue } from './shared/Expression'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class TemplateLiteral extends NodeBase { - expressions!: ExpressionNode[]; - quasis!: TemplateElement[]; - type!: NodeType.tTemplateLiteral; + declare expressions: ExpressionNode[]; + declare quasis: TemplateElement[]; + declare type: NodeType.tTemplateLiteral; getLiteralValueAtPath(path: ObjectPath): LiteralValueOrUnknown { if (path.length > 0 || this.quasis.length !== 1) { diff --git a/src/ast/nodes/ThisExpression.ts b/src/ast/nodes/ThisExpression.ts index 3fa8cdc58fa..f1361ab07a8 100644 --- a/src/ast/nodes/ThisExpression.ts +++ b/src/ast/nodes/ThisExpression.ts @@ -9,10 +9,9 @@ import { ExpressionEntity } from './shared/Expression'; import { NodeBase } from './shared/Node'; export default class ThisExpression extends NodeBase { - type!: NodeType.tThisExpression; - - variable!: Variable; - private alias!: string | null; + declare type: NodeType.tThisExpression; + declare variable: Variable; + private declare alias: string | null; bind(): void { this.variable = this.scope.findVariable('this'); diff --git a/src/ast/nodes/ThrowStatement.ts b/src/ast/nodes/ThrowStatement.ts index d3f87cde4f0..fd43434f7d4 100644 --- a/src/ast/nodes/ThrowStatement.ts +++ b/src/ast/nodes/ThrowStatement.ts @@ -5,8 +5,8 @@ import * as NodeType from './NodeType'; import { ExpressionNode, IncludeChildren, StatementBase } from './shared/Node'; export default class ThrowStatement extends StatementBase { - argument!: ExpressionNode; - type!: NodeType.tThrowStatement; + declare argument: ExpressionNode; + declare type: NodeType.tThrowStatement; hasEffects(): boolean { return true; diff --git a/src/ast/nodes/TryStatement.ts b/src/ast/nodes/TryStatement.ts index 62ddd849864..6a5642dace8 100644 --- a/src/ast/nodes/TryStatement.ts +++ b/src/ast/nodes/TryStatement.ts @@ -6,10 +6,10 @@ import * as NodeType from './NodeType'; import { INCLUDE_PARAMETERS, IncludeChildren, StatementBase } from './shared/Node'; export default class TryStatement extends StatementBase { - block!: BlockStatement; - finalizer!: BlockStatement | null; - handler!: CatchClause | null; - type!: NodeType.tTryStatement; + declare block: BlockStatement; + declare finalizer: BlockStatement | null; + declare handler: CatchClause | null; + declare type: NodeType.tTryStatement; private directlyIncluded = false; private includedLabelsAfterBlock: string[] | null = null; diff --git a/src/ast/nodes/UnaryExpression.ts b/src/ast/nodes/UnaryExpression.ts index 4b7f22c2bbf..213214efbe8 100644 --- a/src/ast/nodes/UnaryExpression.ts +++ b/src/ast/nodes/UnaryExpression.ts @@ -20,10 +20,10 @@ const unaryOperators: { }; export default class UnaryExpression extends NodeBase { - argument!: ExpressionNode; - operator!: '!' | '+' | '-' | 'delete' | 'typeof' | 'void' | '~'; - prefix!: boolean; - type!: NodeType.tUnaryExpression; + declare argument: ExpressionNode; + declare operator: '!' | '+' | '-' | 'delete' | 'typeof' | 'void' | '~'; + declare prefix: boolean; + declare type: NodeType.tUnaryExpression; protected deoptimized = false; getLiteralValueAtPath( diff --git a/src/ast/nodes/UpdateExpression.ts b/src/ast/nodes/UpdateExpression.ts index a6d7b0fdcd5..5db5259ccc2 100644 --- a/src/ast/nodes/UpdateExpression.ts +++ b/src/ast/nodes/UpdateExpression.ts @@ -12,10 +12,10 @@ import * as NodeType from './NodeType'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class UpdateExpression extends NodeBase { - argument!: ExpressionNode; - operator!: '++' | '--'; - prefix!: boolean; - type!: NodeType.tUpdateExpression; + declare argument: ExpressionNode; + declare operator: '++' | '--'; + declare prefix: boolean; + declare type: NodeType.tUpdateExpression; protected deoptimized = false; hasEffects(context: HasEffectsContext): boolean { diff --git a/src/ast/nodes/VariableDeclaration.ts b/src/ast/nodes/VariableDeclaration.ts index 2aa5e4eb923..ae576d643a7 100644 --- a/src/ast/nodes/VariableDeclaration.ts +++ b/src/ast/nodes/VariableDeclaration.ts @@ -38,9 +38,9 @@ function areAllDeclarationsIncludedAndNotExported( } export default class VariableDeclaration extends NodeBase { - declarations!: VariableDeclarator[]; - kind!: 'var' | 'let' | 'const'; - type!: NodeType.tVariableDeclaration; + declare declarations: VariableDeclarator[]; + declare kind: 'var' | 'let' | 'const'; + declare type: NodeType.tVariableDeclaration; deoptimizePath(): void { for (const declarator of this.declarations) { diff --git a/src/ast/nodes/VariableDeclarator.ts b/src/ast/nodes/VariableDeclarator.ts index a75fae32a1b..53082ba4332 100644 --- a/src/ast/nodes/VariableDeclarator.ts +++ b/src/ast/nodes/VariableDeclarator.ts @@ -15,9 +15,9 @@ import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node'; import { PatternNode } from './shared/Pattern'; export default class VariableDeclarator extends NodeBase { - id!: PatternNode; - init!: ExpressionNode | null; - type!: NodeType.tVariableDeclarator; + declare id: PatternNode; + declare init: ExpressionNode | null; + declare type: NodeType.tVariableDeclarator; declareDeclarator(kind: string): void { this.id.declare(kind, this.init || UNDEFINED_EXPRESSION); diff --git a/src/ast/nodes/WhileStatement.ts b/src/ast/nodes/WhileStatement.ts index acd88de451a..fd978451960 100644 --- a/src/ast/nodes/WhileStatement.ts +++ b/src/ast/nodes/WhileStatement.ts @@ -3,9 +3,9 @@ import * as NodeType from './NodeType'; import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from './shared/Node'; export default class WhileStatement extends StatementBase { - body!: StatementNode; - test!: ExpressionNode; - type!: NodeType.tWhileStatement; + declare body: StatementNode; + declare test: ExpressionNode; + declare type: NodeType.tWhileStatement; hasEffects(context: HasEffectsContext): boolean { if (this.test.hasEffects(context)) return true; diff --git a/src/ast/nodes/YieldExpression.ts b/src/ast/nodes/YieldExpression.ts index a313c736fd2..c5130e256b0 100644 --- a/src/ast/nodes/YieldExpression.ts +++ b/src/ast/nodes/YieldExpression.ts @@ -6,9 +6,9 @@ import * as NodeType from './NodeType'; import { ExpressionNode, NodeBase } from './shared/Node'; export default class YieldExpression extends NodeBase { - argument!: ExpressionNode | null; - delegate!: boolean; - type!: NodeType.tYieldExpression; + declare argument: ExpressionNode | null; + declare delegate: boolean; + declare type: NodeType.tYieldExpression; protected deoptimized = false; hasEffects(context: HasEffectsContext): boolean { diff --git a/src/ast/nodes/shared/ClassNode.ts b/src/ast/nodes/shared/ClassNode.ts index b7d0cc4e31c..0052e7b2b77 100644 --- a/src/ast/nodes/shared/ClassNode.ts +++ b/src/ast/nodes/shared/ClassNode.ts @@ -22,10 +22,10 @@ import { ObjectMember } from './ObjectMember'; import { OBJECT_PROTOTYPE } from './ObjectPrototype'; export default class ClassNode extends NodeBase implements DeoptimizableEntity { - body!: ClassBody; - id!: Identifier | null; - superClass!: ExpressionNode | null; - private classConstructor!: MethodDefinition | null; + declare body: ClassBody; + declare id: Identifier | null; + declare superClass: ExpressionNode | null; + private declare classConstructor: MethodDefinition | null; private objectEntity: ObjectEntity | null = null; createScope(parentScope: Scope): void { diff --git a/src/ast/nodes/shared/FunctionNode.ts b/src/ast/nodes/shared/FunctionNode.ts index 2d3de584c28..dda5e17a8ff 100644 --- a/src/ast/nodes/shared/FunctionNode.ts +++ b/src/ast/nodes/shared/FunctionNode.ts @@ -15,12 +15,12 @@ import { OBJECT_PROTOTYPE } from './ObjectPrototype'; import { PatternNode } from './Pattern'; export default class FunctionNode extends NodeBase { - async!: boolean; - body!: BlockStatement; - id!: IdentifierWithVariable | null; - params!: PatternNode[]; - preventChildBlockScope!: true; - scope!: FunctionScope; + declare async: boolean; + declare body: BlockStatement; + declare id: IdentifierWithVariable | null; + declare params: PatternNode[]; + declare preventChildBlockScope: true; + declare scope: FunctionScope; private deoptimizedReturn = false; private isPrototypeDeoptimized = false; diff --git a/src/ast/nodes/shared/MethodBase.ts b/src/ast/nodes/shared/MethodBase.ts index 02c2deae953..f810f22710c 100644 --- a/src/ast/nodes/shared/MethodBase.ts +++ b/src/ast/nodes/shared/MethodBase.ts @@ -14,10 +14,10 @@ import { ExpressionNode, NodeBase } from './Node'; import { PatternNode } from './Pattern'; export default class MethodBase extends NodeBase implements DeoptimizableEntity { - computed!: boolean; - key!: ExpressionNode | PrivateIdentifier; - kind!: 'constructor' | 'method' | 'init' | 'get' | 'set'; - value!: ExpressionNode | (ExpressionNode & PatternNode); + declare computed: boolean; + declare key: ExpressionNode | PrivateIdentifier; + declare kind: 'constructor' | 'method' | 'init' | 'get' | 'set'; + declare value: ExpressionNode | (ExpressionNode & PatternNode); private accessedValue: ExpressionEntity | null = null; private accessorCallOptions: CallOptions = { diff --git a/src/ast/nodes/shared/Node.ts b/src/ast/nodes/shared/Node.ts index c85df3be7f0..6c8f2bd99ec 100644 --- a/src/ast/nodes/shared/Node.ts +++ b/src/ast/nodes/shared/Node.ts @@ -84,15 +84,15 @@ export type StatementNode = Node; export interface ExpressionNode extends ExpressionEntity, Node {} export class NodeBase extends ExpressionEntity implements ExpressionNode { - annotations?: acorn.Comment[]; + declare annotations?: acorn.Comment[]; context: AstContext; - end!: number; + declare end: number; esTreeNode: acorn.Node; keys: string[]; parent: Node | { context: AstContext; type: string }; - scope!: ChildScope; - start!: number; - type!: keyof typeof NodeType; + declare scope: ChildScope; + declare start: number; + declare type: keyof typeof NodeType; // Nodes can apply custom deoptimizations once they become part of the // executed code. To do this, they must initialize this as false, implement // applyDeoptimizations and call this from include and hasEffects if they diff --git a/src/ast/scopes/ChildScope.ts b/src/ast/scopes/ChildScope.ts index 04940baaa8d..6b7acfbbf08 100644 --- a/src/ast/scopes/ChildScope.ts +++ b/src/ast/scopes/ChildScope.ts @@ -8,7 +8,7 @@ import Scope from './Scope'; export default class ChildScope extends Scope { accessedOutsideVariables = new Map(); parent: Scope; - private accessedDynamicImports?: Set; + private declare accessedDynamicImports?: Set; constructor(parent: Scope) { super(); diff --git a/src/ast/scopes/GlobalScope.ts b/src/ast/scopes/GlobalScope.ts index d5c96644d7f..c47d9026b9f 100644 --- a/src/ast/scopes/GlobalScope.ts +++ b/src/ast/scopes/GlobalScope.ts @@ -4,7 +4,7 @@ import Variable from '../variables/Variable'; import Scope from './Scope'; export default class GlobalScope extends Scope { - parent: null; + declare parent: null; constructor() { super(); diff --git a/src/ast/scopes/ModuleScope.ts b/src/ast/scopes/ModuleScope.ts index 885283d71ed..ab0c5696211 100644 --- a/src/ast/scopes/ModuleScope.ts +++ b/src/ast/scopes/ModuleScope.ts @@ -11,7 +11,7 @@ import GlobalScope from './GlobalScope'; export default class ModuleScope extends ChildScope { context: AstContext; - parent!: GlobalScope; + declare parent: GlobalScope; constructor(parent: GlobalScope, context: AstContext) { super(parent); diff --git a/src/ast/scopes/TrackingScope.ts b/src/ast/scopes/TrackingScope.ts index 53d3dbf272f..3f2b156b507 100644 --- a/src/ast/scopes/TrackingScope.ts +++ b/src/ast/scopes/TrackingScope.ts @@ -5,7 +5,7 @@ import LocalVariable from '../variables/LocalVariable'; import BlockScope from './BlockScope'; export default class TrackingScope extends BlockScope { - public hoistedDeclarations: Identifier[] = []; + hoistedDeclarations: Identifier[] = []; addDeclaration( identifier: Identifier, diff --git a/src/ast/variables/ExportShimVariable.ts b/src/ast/variables/ExportShimVariable.ts index f790182325a..664b1c0e462 100644 --- a/src/ast/variables/ExportShimVariable.ts +++ b/src/ast/variables/ExportShimVariable.ts @@ -3,6 +3,8 @@ import { MISSING_EXPORT_SHIM_VARIABLE } from '../../utils/variableNames'; import Variable from './Variable'; export default class ExportShimVariable extends Variable { + module: Module; + constructor(module: Module) { super(MISSING_EXPORT_SHIM_VARIABLE); this.module = module; diff --git a/src/ast/variables/ExternalVariable.ts b/src/ast/variables/ExternalVariable.ts index f9b7c9bef69..c4d42593a55 100644 --- a/src/ast/variables/ExternalVariable.ts +++ b/src/ast/variables/ExternalVariable.ts @@ -6,13 +6,12 @@ import Variable from './Variable'; export default class ExternalVariable extends Variable { isNamespace: boolean; module: ExternalModule; - referenced: boolean; + referenced = false; constructor(module: ExternalModule, name: string) { super(name); this.module = module; this.isNamespace = name === '*'; - this.referenced = false; } addReference(identifier: Identifier): void { diff --git a/src/ast/variables/NamespaceVariable.ts b/src/ast/variables/NamespaceVariable.ts index 331d0297cc0..a2d4fd67629 100644 --- a/src/ast/variables/NamespaceVariable.ts +++ b/src/ast/variables/NamespaceVariable.ts @@ -7,7 +7,7 @@ import Variable from './Variable'; export default class NamespaceVariable extends Variable { context: AstContext; - isNamespace!: true; + declare isNamespace: true; module: Module; private memberVariables: { [name: string]: Variable } | null = null; diff --git a/src/ast/variables/Variable.ts b/src/ast/variables/Variable.ts index 1ab08e8b5e6..9392827254f 100644 --- a/src/ast/variables/Variable.ts +++ b/src/ast/variables/Variable.ts @@ -11,10 +11,10 @@ export default class Variable extends ExpressionEntity { initReached = false; isId = false; // both NamespaceVariable and ExternalVariable can be namespaces - isNamespace?: boolean; + declare isNamespace?: boolean; isReassigned = false; kind: string | null = null; - module?: Module | ExternalModule; + declare module?: Module | ExternalModule; renderBaseName: string | null = null; renderName: string | null = null; diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index cffff82b267..784eadf6696 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -12,10 +12,9 @@ import { basename, dirname, relative, resolve } from './path'; class Source { content: string; filename: string; - isOriginal: boolean; + isOriginal = true; constructor(filename: string, content: string) { - this.isOriginal = true; this.filename = filename; this.content = content; } diff --git a/src/watch/watch.ts b/src/watch/watch.ts index 1ab78ac0a37..d1c30413332 100644 --- a/src/watch/watch.ts +++ b/src/watch/watch.ts @@ -37,9 +37,9 @@ export class Watcher { private buildDelay = 0; private buildTimeout: NodeJS.Timer | null = null; - private invalidatedIds: Map = new Map(); + private invalidatedIds = new Map(); private rerun = false; - private running: boolean; + private running = true; private tasks: Task[]; constructor(configs: GenericConfigObject[], emitter: RollupWatcher) { @@ -53,7 +53,6 @@ export class Watcher { : buildDelay, this.buildDelay ); - this.running = true; process.nextTick(() => this.run()); } @@ -123,7 +122,7 @@ export class Task { cache: RollupCache = { modules: [] }; watchFiles: string[] = []; - private closed: boolean; + private closed = false; private fileWatcher: FileWatcher; private filter: (id: string) => boolean; private invalidated = true; @@ -131,13 +130,11 @@ export class Task { private outputFiles: string[]; private outputs: OutputOptions[]; private skipWrite: boolean; - private watched: Set; + private watched = new Set(); private watcher: Watcher; constructor(watcher: Watcher, config: GenericConfigObject) { this.watcher = watcher; - this.closed = false; - this.watched = new Set(); this.skipWrite = Boolean(config.watch && (config.watch as GenericConfigObject).skipWrite); this.options = mergeOptions(config); diff --git a/tsconfig.json b/tsconfig.json index 8f07d049dc1..a9b3c3819ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,8 @@ "resolveJsonModule": true, "skipLibCheck": true, "strict": true, - "target": "ES2018" + "target": "ES2018", + "useDefineForClassFields": false }, "include": ["typings/**/*.d.ts", "src", "cli", "browser", "rollup.config.ts"], "exclude": ["dist", "node_modules", "test/typescript"]