Fix const enum comments (#47990)

* chore: add test case

* fix: const enum comment

* fix: replace all unsafe pattern

* chore: run regex only if element access
This commit is contained in:
magic-akari
2022-03-04 01:10:02 +08:00
committed by GitHub
parent f82d0cb329
commit 06d426c966
5 changed files with 352 additions and 155 deletions

View File

@@ -3355,6 +3355,10 @@ namespace ts {
return substituteConstantValue(node);
}
function safeMultiLineComment(value: string): string {
return value.replace(/\*\//g, "*_/");
}
function substituteConstantValue(node: PropertyAccessExpression | ElementAccessExpression): LeftHandSideExpression {
const constantValue = tryGetConstEnumValue(node);
if (constantValue !== undefined) {
@@ -3366,7 +3370,7 @@ namespace ts {
const originalNode = getOriginalNode(node, isAccessExpression);
const propertyName = isPropertyAccessExpression(originalNode)
? declarationNameToString(originalNode.name)
: getTextOfNode(originalNode.argumentExpression);
: safeMultiLineComment(getTextOfNode(originalNode.argumentExpression));
addSyntheticTrailingComment(substitute, SyntaxKind.MultiLineCommentTrivia, ` ${propertyName} `);
}