Skip to content

Commit a2ff4ea

Browse files
committed
Identifier constructor
1 parent 4a77c97 commit a2ff4ea

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

src/compiler/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ namespace ts {
12321232
export interface ObjectAllocator {
12331233
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
12341234
getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
1235+
getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
12351236
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
12361237
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
12371238
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
@@ -1262,6 +1263,7 @@ namespace ts {
12621263
export let objectAllocator: ObjectAllocator = {
12631264
getNodeConstructor: () => <any>Node,
12641265
getTokenConstructor: () => <any>Node,
1266+
getIdentifierConstructor: () => <any>Node,
12651267
getSourceFileConstructor: () => <any>Node,
12661268
getSymbolConstructor: () => <any>Symbol,
12671269
getTypeConstructor: () => <any>Type,

src/compiler/parser.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ namespace ts {
66

77
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
88
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
9+
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
910
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
1011

1112
export function createNode(kind: SyntaxKind, pos?: number, end?: number): Node {
1213
if (kind === SyntaxKind.SourceFile) {
1314
return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, pos, end);
1415
}
16+
else if (kind === SyntaxKind.Identifier) {
17+
return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, pos, end);
18+
}
1519
else if (kind < SyntaxKind.FirstNode) {
1620
return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, pos, end);
1721
}
@@ -471,6 +475,7 @@ namespace ts {
471475
// capture constructors in 'initializeState' to avoid null checks
472476
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
473477
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
478+
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
474479
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
475480

476481
let sourceFile: SourceFile;
@@ -582,6 +587,7 @@ namespace ts {
582587
function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, scriptKind: ScriptKind) {
583588
NodeConstructor = objectAllocator.getNodeConstructor();
584589
TokenConstructor = objectAllocator.getTokenConstructor();
590+
IdentifierConstructor = objectAllocator.getIdentifierConstructor();
585591
SourceFileConstructor = objectAllocator.getSourceFileConstructor();
586592

587593
sourceText = _sourceText;
@@ -1030,9 +1036,9 @@ namespace ts {
10301036
pos = scanner.getStartPos();
10311037
}
10321038

1033-
return kind >= SyntaxKind.FirstNode ?
1034-
new NodeConstructor(kind, pos, pos) :
1035-
new TokenConstructor(kind, pos, pos);
1039+
return kind >= SyntaxKind.FirstNode ? new NodeConstructor(kind, pos, pos) :
1040+
kind === SyntaxKind.Identifier ? new IdentifierConstructor(kind, pos, pos) :
1041+
new TokenConstructor(kind, pos, pos);
10361042
}
10371043

10381044
function finishNode<T extends Node>(node: T, end?: number): T {

src/services/services.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ namespace ts {
180180
];
181181
let jsDocCompletionEntries: CompletionEntry[];
182182

183-
function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject {
184-
const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) : new TokenObject(kind, pos, end);
183+
function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject {
184+
const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) :
185+
kind === SyntaxKind.Identifier ? new IdentifierObject(kind, pos, end) :
186+
new TokenObject(kind, pos, end);
185187
node.parent = parent;
186188
return node;
187189
}
@@ -343,19 +345,17 @@ namespace ts {
343345
}
344346
}
345347

346-
class TokenObject implements Token {
348+
class TokenOrIdentifierObject implements Token {
347349
public kind: SyntaxKind;
348350
public pos: number;
349351
public end: number;
350352
public flags: NodeFlags;
351353
public parent: Node;
352354
public jsDocComments: JSDocComment[];
353355

354-
constructor(kind: SyntaxKind, pos: number, end: number) {
355-
this.kind = kind;
356+
constructor(pos: number, end: number) {
356357
this.pos = pos;
357358
this.end = end;
358-
this.flags = NodeFlags.None;
359359
this.parent = undefined;
360360
}
361361

@@ -416,6 +416,21 @@ namespace ts {
416416
}
417417
}
418418

419+
class TokenObject extends TokenOrIdentifierObject {
420+
constructor(kind: SyntaxKind, pos: number, end: number) {
421+
super(pos, end);
422+
this.kind = kind;
423+
this.flags = NodeFlags.None;
424+
}
425+
}
426+
427+
class IdentifierObject extends TokenOrIdentifierObject {
428+
constructor(kind: SyntaxKind, pos: number, end: number) {
429+
super(pos, end);
430+
}
431+
}
432+
IdentifierObject.prototype.kind = SyntaxKind.Identifier;
433+
419434
class SymbolObject implements Symbol {
420435
flags: SymbolFlags;
421436
name: string;
@@ -8768,6 +8783,7 @@ namespace ts {
87688783
objectAllocator = {
87698784
getNodeConstructor: () => NodeObject,
87708785
getTokenConstructor: () => TokenObject,
8786+
getIdentifierConstructor: () => IdentifierObject,
87718787
getSourceFileConstructor: () => SourceFileObject,
87728788
getSymbolConstructor: () => SymbolObject,
87738789
getTypeConstructor: () => TypeObject,

0 commit comments

Comments
 (0)