Skip to content

Commit b7ce6f0

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR comment
1 parent 51e4011 commit b7ce6f0

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/compiler/emitter.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,20 +2051,19 @@ namespace ts {
20512051

20522052
function emitSourceFile(node: SourceFile) {
20532053
writeLine();
2054-
// If the node is a sourceFile and it has prologueDirective (statmentOffSet is not zero) that is synthesize
2055-
// We will need to emit detached comment here because emitPrologueDirective will not emit comments of such prologue directive
20562054
const statements = node.statements;
2057-
// Emit detached comment if there iare no prologue directives or this is a synthesized prologue directives.
2058-
// The synthesized node will have no leading comment so some comments may be missed.
2059-
const shouldEmitDetachedComment = statements.length === 0 ||
2060-
!isPrologueDirective(statements[0]) ||
2061-
(isPrologueDirective(statements[0]) && nodeIsSynthesized(statements[0]));
2062-
if (emitBodyWithDetachedComments && shouldEmitDetachedComment) {
2063-
emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
2064-
}
2065-
else {
2066-
emitSourceFileWorker(node);
2055+
if (emitBodyWithDetachedComments) {
2056+
// Emit detached comment if there iare no prologue directives or this is a synthesized prologue directives.
2057+
// The synthesized node will have no leading comment so some comments may be missed.
2058+
const shouldEmitDetachedComment = statements.length === 0 ||
2059+
!isPrologueDirective(statements[0]) ||
2060+
nodeIsSynthesized(statements[0]);
2061+
if (shouldEmitDetachedComment) {
2062+
emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
2063+
return;
2064+
}
20672065
}
2066+
emitSourceFileWorker(node);
20682067
}
20692068

20702069
function emitSourceFileWorker(node: SourceFile) {
@@ -2111,7 +2110,7 @@ namespace ts {
21112110
}
21122111

21132112
function emitPrologueDirectivesIfNeeded(sourceFileOrBundle: Bundle | SourceFile) {
2114-
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) {
2113+
if (isSourceFile(sourceFileOrBundle)) {
21152114
setSourceFile(sourceFileOrBundle as SourceFile);
21162115
emitPrologueDirectives((sourceFileOrBundle as SourceFile).statements);
21172116
}
@@ -2125,7 +2124,7 @@ namespace ts {
21252124
}
21262125

21272126
function emitShebangIfNeeded(sourceFileOrBundle: Bundle | SourceFile) {
2128-
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) {
2127+
if (isSourceFile(sourceFileOrBundle)) {
21292128
const shebang = getShebang(sourceFileOrBundle.text);
21302129
if (shebang) {
21312130
write(shebang);

0 commit comments

Comments
 (0)