Skip to content

Commit 55bffba

Browse files
author
Andy
authored
Use getTextOfNode over getTextOfNodeFromSourceText(getSourceFileOfNode(node)) (#22387)
1 parent 0605424 commit 55bffba

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ namespace ts {
19961996

19971997
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
19981998
function isUseStrictPrologueDirective(node: ExpressionStatement): boolean {
1999-
const nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
1999+
const nodeText = getSourceTextOfNodeFromSourceFile(file, node.expression);
20002000

20012001
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
20022002
// string to contain unicode escapes (as per ES5).

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22851,8 +22851,7 @@ namespace ts {
2285122851
return "quit";
2285222852
}
2285322853
if (current.kind === SyntaxKind.LabeledStatement && (<LabeledStatement>current).label.escapedText === node.label.escapedText) {
22854-
const sourceFile = getSourceFileOfNode(node);
22855-
grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceFile.text, node.label));
22854+
grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNode(node.label));
2285622855
return true;
2285722856
}
2285822857
});

src/compiler/utilities.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,20 +314,15 @@ namespace ts {
314314
}
315315

316316
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia = false): string {
317-
if (nodeIsMissing(node)) {
318-
return "";
319-
}
320-
321-
const text = sourceFile.text;
322-
return text.substring(includeTrivia ? node.pos : skipTrivia(text, node.pos), node.end);
317+
return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia);
323318
}
324319

325-
export function getTextOfNodeFromSourceText(sourceText: string, node: Node): string {
320+
export function getTextOfNodeFromSourceText(sourceText: string, node: Node, includeTrivia = false): string {
326321
if (nodeIsMissing(node)) {
327322
return "";
328323
}
329324

330-
return sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
325+
return sourceText.substring(includeTrivia ? node.pos : skipTrivia(sourceText, node.pos), node.end);
331326
}
332327

333328
export function getTextOfNode(node: Node, includeTrivia = false): string {

src/harness/typeWriter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class TypeWriterWalker {
7272
private writeTypeOrSymbol(node: ts.Node, isSymbolWalk: boolean): TypeWriterResult {
7373
const actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
7474
const lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
75-
const sourceText = ts.getTextOfNodeFromSourceText(this.currentSourceFile.text, node);
76-
75+
const sourceText = ts.getSourceTextOfNodeFromSourceFile(this.currentSourceFile, node);
7776

7877
if (!isSymbolWalk) {
7978
// Workaround to ensure we output 'C' instead of 'typeof C' for base class expressions

0 commit comments

Comments
 (0)