Skip to content

Commit 391a3c8

Browse files
committed
Separate Tokens and Identifiers from other Nodes
With some further optimization to their properties, this shrinks the objects by quite a bit.
1 parent 72c0961 commit 391a3c8

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/compiler/utilities.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -3962,6 +3962,9 @@ namespace ts {
39623962
}
39633963

39643964
export function getModifierFlags(node: Node): ModifierFlags {
3965+
if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) {
3966+
return ModifierFlags.None;
3967+
}
39653968
if (node.modifierFlagsCache & ModifierFlags.HasComputedFlags) {
39663969
return node.modifierFlagsCache & ~ModifierFlags.HasComputedFlags;
39673970
}
@@ -7149,6 +7152,28 @@ namespace ts {
71497152
this.original = undefined;
71507153
}
71517154

7155+
function Token(this: Node, kind: SyntaxKind, pos: number, end: number) {
7156+
this.pos = pos;
7157+
this.end = end;
7158+
this.kind = kind;
7159+
this.id = 0;
7160+
this.flags = NodeFlags.None;
7161+
this.transformFlags = TransformFlags.None;
7162+
this.parent = undefined!;
7163+
}
7164+
7165+
function Identifier(this: Node, kind: SyntaxKind, pos: number, end: number) {
7166+
this.pos = pos;
7167+
this.end = end;
7168+
this.kind = kind;
7169+
this.id = 0;
7170+
this.flags = NodeFlags.None;
7171+
this.transformFlags = TransformFlags.None;
7172+
this.parent = undefined!;
7173+
this.original = undefined;
7174+
this.flowNode = undefined;
7175+
}
7176+
71527177
function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) {
71537178
this.fileName = fileName;
71547179
this.text = text;
@@ -7158,8 +7183,8 @@ namespace ts {
71587183
// eslint-disable-next-line prefer-const
71597184
export let objectAllocator: ObjectAllocator = {
71607185
getNodeConstructor: () => <any>Node,
7161-
getTokenConstructor: () => <any>Node,
7162-
getIdentifierConstructor: () => <any>Node,
7186+
getTokenConstructor: () => <any>Token,
7187+
getIdentifierConstructor: () => <any>Identifier,
71637188
getSourceFileConstructor: () => <any>Node,
71647189
getSymbolConstructor: () => <any>Symbol,
71657190
getTypeConstructor: () => <any>Type,

0 commit comments

Comments
 (0)