Switch back to instance-only 'kind' fields

This commit is contained in:
Ron Buckton
2024-04-05 20:36:56 -04:00
parent 2b588610ec
commit 33d6204dcb

View File

@@ -90,11 +90,7 @@ import {
/** @internal */
export abstract class BaseSyntaxObject implements Node {
static {
this.prototype.kind = SyntaxKind.Unknown;
}
declare kind: SyntaxKind;
kind = SyntaxKind.Unknown;
pos = -1;
end = -1;
id = 0;
@@ -106,6 +102,10 @@ export abstract class BaseSyntaxObject implements Node {
abstract modifierFlagsCache: ModifierFlags; // TODO: move this off `Node`
abstract emitNode: EmitNode | undefined;
constructor(kind: SyntaxKind) {
this.kind = kind;
}
getSourceFile(): SourceFile {
return getSourceFileOfNode(this);
}
@@ -195,19 +195,14 @@ export abstract class BaseTokenObject extends BaseSyntaxObject {
/** @internal */
export class TokenObject<TKind extends SyntaxKind> extends BaseTokenObject implements Token<TKind> {
override kind: TKind;
declare kind: TKind;
constructor(kind: TKind) {
super();
this.kind = kind;
super(kind);
}
}
/** @internal */
export class IdentifierObject extends BaseTokenObject implements Identifier {
static {
this.prototype.kind = SyntaxKind.Identifier;
}
declare kind: SyntaxKind.Identifier;
declare _primaryExpressionBrand: any;
@@ -228,6 +223,10 @@ export class IdentifierObject extends BaseTokenObject implements Identifier {
jsDoc?: JSDoc[] = undefined; // initialized by parser (JsDocContainer)
flowNode?: FlowNode = undefined; // initialized by binder (FlowContainer)
constructor() {
super(SyntaxKind.Identifier);
}
get text(): string {
return idText(this);
}
@@ -235,9 +234,6 @@ export class IdentifierObject extends BaseTokenObject implements Identifier {
/** @internal */
export class PrivateIdentifierObject extends BaseTokenObject implements PrivateIdentifier {
static {
PrivateIdentifierObject.prototype.kind = SyntaxKind.PrivateIdentifier;
}
declare kind: SyntaxKind.PrivateIdentifier;
declare _primaryExpressionBrand: any;
@@ -252,6 +248,10 @@ export class PrivateIdentifierObject extends BaseTokenObject implements PrivateI
escapedText: __String = "" as __String;
constructor() {
super(SyntaxKind.PrivateIdentifier);
}
get text(): string {
return idText(this);
}
@@ -306,19 +306,15 @@ export abstract class BaseNodeObject extends BaseSyntaxObject {
/** @internal */
export class NodeObject<TKind extends SyntaxKind> extends BaseNodeObject implements Node {
override kind: TKind;
declare kind: TKind;
constructor(kind: TKind) {
super();
this.kind = kind;
super(kind);
}
}
/** @internal */
export class SourceFileObject extends BaseNodeObject implements SourceFile {
static {
this.prototype.kind = SyntaxKind.SourceFile;
}
declare kind: SyntaxKind.SourceFile;
declare _declarationBrand: any;
@@ -387,6 +383,10 @@ export class SourceFileObject extends BaseNodeObject implements SourceFile {
declare private namedDeclarations: Map<string, Declaration[]> | undefined;
constructor() {
super(SyntaxKind.SourceFile);
}
public update(newText: string, textChangeRange: TextChangeRange): SourceFile {
return updateSourceFile(this, newText, textChangeRange);
}