mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-06 04:35:21 -05:00
Merge pull request #21476 from Kingwl/concat-string-in-enum-member
allow string concat in enum member declaration
This commit is contained in:
@@ -5290,6 +5290,16 @@ namespace ts {
|
||||
return links.declaredType;
|
||||
}
|
||||
|
||||
function isStringConcatExpression(expr: Node): boolean {
|
||||
if (expr.kind === SyntaxKind.StringLiteral) {
|
||||
return true;
|
||||
}
|
||||
else if (expr.kind === SyntaxKind.BinaryExpression) {
|
||||
return isStringConcatExpression((<BinaryExpression>expr).left) && isStringConcatExpression((<BinaryExpression>expr).right);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLiteralEnumMember(member: EnumMember) {
|
||||
const expr = member.initializer;
|
||||
if (!expr) {
|
||||
@@ -5304,6 +5314,8 @@ namespace ts {
|
||||
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
|
||||
case SyntaxKind.Identifier:
|
||||
return nodeIsMissing(expr) || !!getSymbolOfNode(member.parent).exports.get((<Identifier>expr).escapedText);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return isStringConcatExpression(expr);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -24090,6 +24102,9 @@ namespace ts {
|
||||
case SyntaxKind.AsteriskAsteriskToken: return left ** right;
|
||||
}
|
||||
}
|
||||
else if (typeof left === "string" && typeof right === "string" && (<BinaryExpression>expr).operatorToken.kind === SyntaxKind.PlusToken) {
|
||||
return left + right;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.StringLiteral:
|
||||
return (<StringLiteral>expr).text;
|
||||
|
||||
Reference in New Issue
Block a user