mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 19:07:27 -06:00
Add missing questionToken in emitMethod/PropertyDeclaration (#16020)
This commit is contained in:
parent
1c3cdf11b5
commit
49638ab2eb
@ -860,6 +860,7 @@ namespace ts {
|
||||
emitDecorators(node, node.decorators);
|
||||
emitModifiers(node, node.modifiers);
|
||||
emit(node.name);
|
||||
writeIfPresent(node.questionToken, "?");
|
||||
emitWithPrefix(": ", node.type);
|
||||
emitExpressionWithPrefix(" = ", node.initializer);
|
||||
write(";");
|
||||
@ -881,6 +882,7 @@ namespace ts {
|
||||
emitModifiers(node, node.modifiers);
|
||||
writeIfPresent(node.asteriskToken, "*");
|
||||
emit(node.name);
|
||||
writeIfPresent(node.questionToken, "?");
|
||||
emitSignatureAndBody(node, emitSignatureHead);
|
||||
}
|
||||
|
||||
|
||||
@ -98,8 +98,40 @@ namespace ts {
|
||||
)
|
||||
])
|
||||
);
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/15971
|
||||
const classWithOptionalMethodAndProperty = createClassDeclaration(
|
||||
undefined,
|
||||
/* modifiers */ createNodeArray([createToken(SyntaxKind.DeclareKeyword)]),
|
||||
/* name */ createIdentifier("X"),
|
||||
undefined,
|
||||
undefined,
|
||||
createNodeArray([
|
||||
createMethod(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
/* name */ createIdentifier("method"),
|
||||
/* questionToken */ createToken(SyntaxKind.QuestionToken),
|
||||
undefined,
|
||||
undefined,
|
||||
/* type */ createKeywordTypeNode(SyntaxKind.VoidKeyword),
|
||||
undefined
|
||||
),
|
||||
createProperty(
|
||||
undefined,
|
||||
undefined,
|
||||
/* name */ createIdentifier("property"),
|
||||
/* questionToken */ createToken(SyntaxKind.QuestionToken),
|
||||
/* type */ createKeywordTypeNode(SyntaxKind.StringKeyword),
|
||||
undefined
|
||||
),
|
||||
])
|
||||
);
|
||||
|
||||
// tslint:enable boolean-trivia
|
||||
printsCorrectly("class", {}, printer => printer.printNode(EmitHint.Unspecified, syntheticNode, sourceFile));
|
||||
printsCorrectly("classWithOptionalMethodAndProperty", {}, printer => printer.printNode(EmitHint.Unspecified, classWithOptionalMethodAndProperty, sourceFile));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
declare class X {
|
||||
method?(): void;
|
||||
property?: string;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user