From 52163f88e22ad48ed4fcbfb2ff002c9f8bf6dc52 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 28 Feb 2023 17:49:58 +0100 Subject: [PATCH] fix(rosetta): go may incorrectly emit _ instead of . (#3985) The go transliteration uses a heuristic to determine if a property access expression is possibly a type name reference, however it failed to check whether the lead contains a call expression, which would make it impossible that the overall expression is a type reference. This fixes the regular expression to address this. Backports a fix from [4.9](https://github.com/aws/jsii-rosetta/pull/7). --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- packages/jsii-rosetta/lib/languages/go.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/jsii-rosetta/lib/languages/go.ts b/packages/jsii-rosetta/lib/languages/go.ts index a012bd85a6..1dbb2631ff 100644 --- a/packages/jsii-rosetta/lib/languages/go.ts +++ b/packages/jsii-rosetta/lib/languages/go.ts @@ -487,13 +487,14 @@ export class GoVisitor extends DefaultVisitor { const isClassStaticMethodAccess = isStaticMember && !isClassStaticPropertyAccess && ts.isMethodDeclaration(valueSymbol.valueDeclaration); - // When the expression has an unknown type (unresolved symbol), and has an upper-case first - // letter, we assume it's a type name... In such cases, what comes after can be considered a - // static member access. Note that the expression might be further qualified, so we check using - // a regex that checks for the last "."-delimited segment if there's dots in there... + // When the expression has an unknown type (unresolved symbol), has an upper-case first letter, + // and doesn't end in a call expression (as hinted by the presence of parentheses), we assume + // it's a type name... In such cases, what comes after can be considered a static member access. + // Note that the expression might be further qualified, so we check using a regex that checks + // for the last "." - delimited segment if there's dots in there... const expressionLooksLikeTypeReference = expressionType.symbol == null && - /(?:\.|^)[A-Z][^.]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null; + /(?:\.|^)[A-Z][^.)]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null; // Whether the node is an enum member reference. const isEnumMember =