Skip to content

Commit 3189d17

Browse files
authored
Handful more usages of emitIfPresent on optional nodes (#22274)
1 parent 09cfc0f commit 3189d17

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ namespace ts {
568568
writeSpace();
569569
writeKeyword("in");
570570
writeSpace();
571-
emit(node.constraint);
571+
emitIfPresent(node.constraint);
572572
}
573573

574574
function pipelineEmitUnspecified(node: Node): void {
@@ -1046,7 +1046,7 @@ namespace ts {
10461046
}
10471047
emitIfPresent(node.questionToken);
10481048
if (node.parent && node.parent.kind === SyntaxKind.JSDocFunctionType && !node.name) {
1049-
emit(node.type);
1049+
emitIfPresent(node.type);
10501050
}
10511051
else {
10521052
emitTypeAnnotation(node.type);
@@ -1174,14 +1174,14 @@ namespace ts {
11741174
writeSpace();
11751175
writePunctuation("=>");
11761176
writeSpace();
1177-
emit(node.type);
1177+
emitIfPresent(node.type);
11781178
}
11791179

11801180
function emitJSDocFunctionType(node: JSDocFunctionType) {
11811181
write("function");
11821182
emitParameters(node, node.parameters);
11831183
write(":");
1184-
emit(node.type);
1184+
emitIfPresent(node.type);
11851185
}
11861186

11871187

@@ -1208,7 +1208,7 @@ namespace ts {
12081208
writeSpace();
12091209
writePunctuation("=>");
12101210
writeSpace();
1211-
emit(node.type);
1211+
emitIfPresent(node.type);
12121212
}
12131213

12141214
function emitTypeQuery(node: TypeQueryNode) {
@@ -1322,7 +1322,7 @@ namespace ts {
13221322
}
13231323
writePunctuation(":");
13241324
writeSpace();
1325-
emit(node.type);
1325+
emitIfPresent(node.type);
13261326
writeSemicolon();
13271327
if (emitFlags & EmitFlags.SingleLine) {
13281328
writeSpace();
@@ -1593,7 +1593,7 @@ namespace ts {
15931593

15941594
function emitYieldExpression(node: YieldExpression) {
15951595
emitTokenWithComment(SyntaxKind.YieldKeyword, node.pos, writeKeyword, node);
1596-
emit(node.asteriskToken);
1596+
emitIfPresent(node.asteriskToken);
15971597
emitExpressionWithLeadingSpace(node.expression);
15981598
}
15991599

@@ -2156,12 +2156,12 @@ namespace ts {
21562156
}
21572157

21582158
function emitImportClause(node: ImportClause) {
2159-
emit(node.name);
2159+
emitIfPresent(node.name);
21602160
if (node.name && node.namedBindings) {
21612161
emitTokenWithComment(SyntaxKind.CommaToken, node.name.end, writePunctuation, node);
21622162
writeSpace();
21632163
}
2164-
emit(node.namedBindings);
2164+
emitIfPresent(node.namedBindings);
21652165
}
21662166

21672167
function emitNamespaceImport(node: NamespaceImport) {

src/harness/unittests/printer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace ts {
6363
// github #18071
6464
printsCorrectly("regularExpressionLiteral", {}, printer => printer.printFile(createSourceFile("source.ts", "let regex = /abc/;", ScriptTarget.ES2017)));
6565

66+
// github #22239
67+
printsCorrectly("importStatementRemoveComments", { removeComments: true }, printer => printer.printFile(createSourceFile("source.ts", "import {foo} from 'foo';", ScriptTarget.ESNext)));
6668
printsCorrectly("classHeritageClauses", {}, printer => printer.printFile(createSourceFile(
6769
"source.ts",
6870
`class A extends B implements C implements D {}`,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { foo } from "foo";

0 commit comments

Comments
 (0)