Skip to content

Commit 52163f8

Browse files
authored
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](aws/jsii-rosetta#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
1 parent 7e53ab2 commit 52163f8

File tree

1 file changed

+6
-5
lines changed
  • packages/jsii-rosetta/lib/languages

1 file changed

+6
-5
lines changed

packages/jsii-rosetta/lib/languages/go.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,14 @@ export class GoVisitor extends DefaultVisitor<GoLanguageContext> {
487487
const isClassStaticMethodAccess =
488488
isStaticMember && !isClassStaticPropertyAccess && ts.isMethodDeclaration(valueSymbol.valueDeclaration);
489489

490-
// When the expression has an unknown type (unresolved symbol), and has an upper-case first
491-
// letter, we assume it's a type name... In such cases, what comes after can be considered a
492-
// static member access. Note that the expression might be further qualified, so we check using
493-
// a regex that checks for the last "."-delimited segment if there's dots in there...
490+
// When the expression has an unknown type (unresolved symbol), has an upper-case first letter,
491+
// and doesn't end in a call expression (as hinted by the presence of parentheses), we assume
492+
// it's a type name... In such cases, what comes after can be considered a static member access.
493+
// Note that the expression might be further qualified, so we check using a regex that checks
494+
// for the last "." - delimited segment if there's dots in there...
494495
const expressionLooksLikeTypeReference =
495496
expressionType.symbol == null &&
496-
/(?:\.|^)[A-Z][^.]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null;
497+
/(?:\.|^)[A-Z][^.)]*$/.exec(node.expression.getText(node.expression.getSourceFile())) != null;
497498

498499
// Whether the node is an enum member reference.
499500
const isEnumMember =

0 commit comments

Comments
 (0)