Skip to content

Commit a5e93c4

Browse files
author
Arthur Ozga
committed
remove souceFile checks
1 parent d5f34da commit a5e93c4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,9 +2289,9 @@ namespace ts {
22892289
const newLine = NewLineKind.None;
22902290
const options = { newLine, removeComments: true };
22912291
const writer = createTextWriter("");
2292-
// writer.writeLine = noop;
22932292
const printer = createPrinter(options, writer);
2294-
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ undefined, writer);
2293+
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
2294+
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ sourceFile, writer);
22952295
const result = writer.getText();
22962296

22972297
const maxLength = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation ? undefined : 100;

src/compiler/emitter.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace ts {
153153
for (let i = 0; i < numNodes; i++) {
154154
const currentNode = bundle ? bundle.sourceFiles[i] : node;
155155
const sourceFile = isSourceFile(currentNode) ? currentNode : currentSourceFile;
156-
const shouldSkip = compilerOptions.noEmitHelpers || (sourceFile && getExternalHelpersModuleName(sourceFile) !== undefined);
156+
const shouldSkip = compilerOptions.noEmitHelpers || getExternalHelpersModuleName(sourceFile) !== undefined;
157157
const shouldBundle = isSourceFile(currentNode) && !isOwnFileEmit;
158158
const helpers = getEmitHelpers(currentNode);
159159
if (helpers) {
@@ -234,6 +234,11 @@ namespace ts {
234234
writeBundle
235235
};
236236

237+
/**
238+
* If `sourceFile` is `undefined`, `node` must be a synthesized `TypeNode`.
239+
*/
240+
function printNode(hint: EmitHint, node: TypeNode, sourceFile: undefined): string;
241+
function printNode(hint: EmitHint, node: Node, sourceFile: SourceFile): string;
237242
function printNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined): string {
238243
switch (hint) {
239244
case EmitHint.SourceFile:
@@ -1112,7 +1117,7 @@ namespace ts {
11121117
function emitPropertyAccessExpression(node: PropertyAccessExpression) {
11131118
let indentBeforeDot = false;
11141119
let indentAfterDot = false;
1115-
if (currentSourceFile && !(getEmitFlags(node) & EmitFlags.NoIndentation)) {
1120+
if (!(getEmitFlags(node) & EmitFlags.NoIndentation)) {
11161121
const dotRangeStart = node.expression.end;
11171122
const dotRangeEnd = skipTrivia(currentSourceFile.text, node.expression.end) + 1;
11181123
const dotToken = <Node>{ kind: SyntaxKind.DotToken, pos: dotRangeStart, end: dotRangeEnd };
@@ -2520,7 +2525,7 @@ namespace ts {
25202525

25212526
const firstChild = children[0];
25222527
if (firstChild === undefined) {
2523-
return !(currentSourceFile && rangeIsOnSingleLine(parentNode, currentSourceFile));
2528+
return !(rangeIsOnSingleLine(parentNode, currentSourceFile));
25242529
}
25252530
else if (positionIsSynthesized(parentNode.pos) || nodeIsSynthesized(firstChild)) {
25262531
return synthesizedNodeStartsOnNewLine(firstChild, format);
@@ -2546,7 +2551,7 @@ namespace ts {
25462551
return synthesizedNodeStartsOnNewLine(previousNode, format) || synthesizedNodeStartsOnNewLine(nextNode, format);
25472552
}
25482553
else {
2549-
return !(currentSourceFile && rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile));
2554+
return !(rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile));
25502555
}
25512556
}
25522557
else {
@@ -2565,13 +2570,13 @@ namespace ts {
25652570

25662571
const lastChild = lastOrUndefined(children);
25672572
if (lastChild === undefined) {
2568-
return !(currentSourceFile && rangeIsOnSingleLine(parentNode, currentSourceFile));
2573+
return !(rangeIsOnSingleLine(parentNode, currentSourceFile));
25692574
}
25702575
else if (positionIsSynthesized(parentNode.pos) || nodeIsSynthesized(lastChild)) {
25712576
return synthesizedNodeStartsOnNewLine(lastChild, format);
25722577
}
25732578
else {
2574-
return !(currentSourceFile && rangeEndPositionsAreOnSameLine(parentNode, lastChild, currentSourceFile));
2579+
return !(rangeEndPositionsAreOnSameLine(parentNode, lastChild, currentSourceFile));
25752580
}
25762581
}
25772582
else {

0 commit comments

Comments
 (0)