Skip to content

Commit 79ade62

Browse files
authored
fix(jsii-pacmak): incorrect casing for class namespaces in other module (#4852)
When resolving the .NET FQN for a type nested in a class from another module: ``` Module.Namespace.SomethingFANCY.SomeType ^^^^^ what is this? ``` The C# code generator incorrectly assumes that all parts leading up to the final type name are module names. Since module names are PascalCased, this means the name gets changed to `SomethingFancy`. However, in JSII classes can also hold types, but class names are not PascalCased (instead, they are capitalized). The upshot was that for L1 property types, which live inside L1 classes, the name of the class would be incorrectly rendered. This would only happen for references to types in other modules, because when processing inside the same module, the code generator was holding a lookup table that made it correctly realize that `SomethingFANCY` in this case is a class, making it take a different code path. In this change, try to distinguish between indicated components representing submodules and representing types, and mangle the names differently. Suffice to say this is all a bit of a mess, but barring a full redesign of how we trace generated this seems to be the best we can do for now. Fixes #4849. --- 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 06c9602 commit 79ade62

File tree

13 files changed

+1382
-26
lines changed

13 files changed

+1382
-26
lines changed

packages/@scope/jsii-calc-lib/lib/submodule/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-namespace */
12
export interface IReflectable {
23
readonly entries: ReflectableEntry[];
34
}
@@ -38,3 +39,14 @@ export namespace NestingClass {
3839
readonly name: string;
3940
}
4041
}
42+
43+
/**
44+
* Test for classes with shouting-cased names that serve as a namespace, consumed from a different assembly than the current one.
45+
*/
46+
export class ClassWithNONPASCALCASEDName {}
47+
48+
export namespace ClassWithNONPASCALCASEDName {
49+
export interface SomeType {
50+
readonly name: string;
51+
}
52+
}

packages/@scope/jsii-calc-lib/test/assembly.jsii

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,60 @@
882882
],
883883
"symbolId": "lib/deprecation-removal:VisibleBaseClass"
884884
},
885+
"@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName": {
886+
"assembly": "@scope/jsii-calc-lib",
887+
"docs": {
888+
"stability": "deprecated",
889+
"summary": "Test for classes with shouting-cased names that serve as a namespace, consumed from a different assembly than the current one."
890+
},
891+
"fqn": "@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName",
892+
"initializer": {
893+
"docs": {
894+
"stability": "deprecated"
895+
}
896+
},
897+
"kind": "class",
898+
"locationInModule": {
899+
"filename": "lib/submodule/index.ts",
900+
"line": 46
901+
},
902+
"name": "ClassWithNONPASCALCASEDName",
903+
"namespace": "submodule",
904+
"symbolId": "lib/submodule/index:ClassWithNONPASCALCASEDName"
905+
},
906+
"@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName.SomeType": {
907+
"assembly": "@scope/jsii-calc-lib",
908+
"datatype": true,
909+
"docs": {
910+
"stability": "deprecated"
911+
},
912+
"fqn": "@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName.SomeType",
913+
"kind": "interface",
914+
"locationInModule": {
915+
"filename": "lib/submodule/index.ts",
916+
"line": 49
917+
},
918+
"name": "SomeType",
919+
"namespace": "submodule.ClassWithNONPASCALCASEDName",
920+
"properties": [
921+
{
922+
"abstract": true,
923+
"docs": {
924+
"stability": "deprecated"
925+
},
926+
"immutable": true,
927+
"locationInModule": {
928+
"filename": "lib/submodule/index.ts",
929+
"line": 50
930+
},
931+
"name": "name",
932+
"type": {
933+
"primitive": "string"
934+
}
935+
}
936+
],
937+
"symbolId": "lib/submodule/index:ClassWithNONPASCALCASEDName.SomeType"
938+
},
885939
"@scope/jsii-calc-lib.submodule.IReflectable": {
886940
"assembly": "@scope/jsii-calc-lib",
887941
"docs": {
@@ -891,7 +945,7 @@
891945
"kind": "interface",
892946
"locationInModule": {
893947
"filename": "lib/submodule/index.ts",
894-
"line": 1
948+
"line": 2
895949
},
896950
"name": "IReflectable",
897951
"namespace": "submodule",
@@ -904,7 +958,7 @@
904958
"immutable": true,
905959
"locationInModule": {
906960
"filename": "lib/submodule/index.ts",
907-
"line": 2
961+
"line": 3
908962
},
909963
"name": "entries",
910964
"type": {
@@ -929,7 +983,7 @@
929983
"kind": "class",
930984
"locationInModule": {
931985
"filename": "lib/submodule/index.ts",
932-
"line": 22
986+
"line": 23
933987
},
934988
"name": "NestingClass",
935989
"namespace": "submodule",
@@ -950,7 +1004,7 @@
9501004
"kind": "class",
9511005
"locationInModule": {
9521006
"filename": "lib/submodule/index.ts",
953-
"line": 30
1007+
"line": 31
9541008
},
9551009
"name": "NestedClass",
9561010
"namespace": "submodule.NestingClass",
@@ -962,7 +1016,7 @@
9621016
"immutable": true,
9631017
"locationInModule": {
9641018
"filename": "lib/submodule/index.ts",
965-
"line": 31
1019+
"line": 32
9661020
},
9671021
"name": "property",
9681022
"type": {
@@ -984,7 +1038,7 @@
9841038
"kind": "interface",
9851039
"locationInModule": {
9861040
"filename": "lib/submodule/index.ts",
987-
"line": 37
1041+
"line": 38
9881042
},
9891043
"name": "NestedStruct",
9901044
"namespace": "submodule.NestingClass",
@@ -997,7 +1051,7 @@
9971051
"immutable": true,
9981052
"locationInModule": {
9991053
"filename": "lib/submodule/index.ts",
1000-
"line": 38
1054+
"line": 39
10011055
},
10021056
"name": "name",
10031057
"type": {
@@ -1017,7 +1071,7 @@
10171071
"kind": "interface",
10181072
"locationInModule": {
10191073
"filename": "lib/submodule/index.ts",
1020-
"line": 5
1074+
"line": 6
10211075
},
10221076
"name": "ReflectableEntry",
10231077
"namespace": "submodule",
@@ -1030,7 +1084,7 @@
10301084
"immutable": true,
10311085
"locationInModule": {
10321086
"filename": "lib/submodule/index.ts",
1033-
"line": 6
1087+
"line": 7
10341088
},
10351089
"name": "key",
10361090
"type": {
@@ -1045,7 +1099,7 @@
10451099
"immutable": true,
10461100
"locationInModule": {
10471101
"filename": "lib/submodule/index.ts",
1048-
"line": 7
1102+
"line": 8
10491103
},
10501104
"name": "value",
10511105
"type": {
@@ -1069,7 +1123,7 @@
10691123
"kind": "class",
10701124
"locationInModule": {
10711125
"filename": "lib/submodule/index.ts",
1072-
"line": 10
1126+
"line": 11
10731127
},
10741128
"methods": [
10751129
{
@@ -1078,7 +1132,7 @@
10781132
},
10791133
"locationInModule": {
10801134
"filename": "lib/submodule/index.ts",
1081-
"line": 11
1135+
"line": 12
10821136
},
10831137
"name": "asMap",
10841138
"parameters": [
@@ -1107,5 +1161,5 @@
11071161
}
11081162
},
11091163
"version": "0.0.0",
1110-
"fingerprint": "Cj0SprOiSFuu5uOdVNJtUfPpVZxEi7sfDe0BiGEM54M="
1164+
"fingerprint": "96UhBBs//vTawYDeg5dqr+eKokWgEG0LCb9P8eVfdF0="
11111165
}

packages/jsii-calc/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * as module2700 from './module2700';
2424
export * as cdk16625 from './cdk16625';
2525
export * as cdk22369 from './cdk22369';
2626
export * as jsii3656 from './jsii3656';
27+
export * as jsii4894 from './jsii4894';
2728

2829
export * as anonymous from './anonymous';
2930
export * as union from './union';

packages/jsii-calc/lib/jsii4894.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ClassWithNONPASCALCASEDName } from '@scope/jsii-calc-lib/build/submodule';
2+
3+
export interface NonPascalCaseTestProps {
4+
readonly someType: ClassWithNONPASCALCASEDName.SomeType;
5+
}
6+
7+
export class NonPascalCaseTest {
8+
public readonly someType: ClassWithNONPASCALCASEDName.SomeType;
9+
10+
public constructor(public readonly props: NonPascalCaseTestProps) {
11+
this.someType = props.someType;
12+
}
13+
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
"jsii-calc.anonymous": {
211211
"locationInModule": {
212212
"filename": "lib/index.ts",
213-
"line": 28
213+
"line": 29
214214
},
215215
"symbolId": "lib/anonymous/index:"
216216
},
@@ -245,7 +245,7 @@
245245
"jsii-calc.homonymousForwardReferences": {
246246
"locationInModule": {
247247
"filename": "lib/index.ts",
248-
"line": 30
248+
"line": 31
249249
},
250250
"readme": {
251251
"markdown": "Verifies homonymous forward references don't trip the Python type checker\n\nThis has been an issue when stub functions were introduced to create a reliable source for type checking\ninformation, which was reported in https://github.com/aws/jsii/issues/3818.\n"
@@ -273,6 +273,13 @@
273273
},
274274
"symbolId": "lib/jsii3656/index:"
275275
},
276+
"jsii-calc.jsii4894": {
277+
"locationInModule": {
278+
"filename": "lib/index.ts",
279+
"line": 27
280+
},
281+
"symbolId": "lib/jsii4894:"
282+
},
276283
"jsii-calc.module2530": {
277284
"locationInModule": {
278285
"filename": "lib/index.ts",
@@ -457,7 +464,7 @@
457464
"jsii-calc.union": {
458465
"locationInModule": {
459466
"filename": "lib/index.ts",
460-
"line": 29
467+
"line": 30
461468
},
462469
"symbolId": "lib/union:"
463470
}
@@ -17030,6 +17037,101 @@
1703017037
"namespace": "jsii3656",
1703117038
"symbolId": "lib/jsii3656/index:OverrideMe"
1703217039
},
17040+
"jsii-calc.jsii4894.NonPascalCaseTest": {
17041+
"assembly": "jsii-calc",
17042+
"docs": {
17043+
"stability": "stable"
17044+
},
17045+
"fqn": "jsii-calc.jsii4894.NonPascalCaseTest",
17046+
"initializer": {
17047+
"docs": {
17048+
"stability": "stable"
17049+
},
17050+
"locationInModule": {
17051+
"filename": "lib/jsii4894.ts",
17052+
"line": 10
17053+
},
17054+
"parameters": [
17055+
{
17056+
"name": "props",
17057+
"type": {
17058+
"fqn": "jsii-calc.jsii4894.NonPascalCaseTestProps"
17059+
}
17060+
}
17061+
]
17062+
},
17063+
"kind": "class",
17064+
"locationInModule": {
17065+
"filename": "lib/jsii4894.ts",
17066+
"line": 7
17067+
},
17068+
"name": "NonPascalCaseTest",
17069+
"namespace": "jsii4894",
17070+
"properties": [
17071+
{
17072+
"docs": {
17073+
"stability": "stable"
17074+
},
17075+
"immutable": true,
17076+
"locationInModule": {
17077+
"filename": "lib/jsii4894.ts",
17078+
"line": 10
17079+
},
17080+
"name": "props",
17081+
"type": {
17082+
"fqn": "jsii-calc.jsii4894.NonPascalCaseTestProps"
17083+
}
17084+
},
17085+
{
17086+
"docs": {
17087+
"stability": "stable"
17088+
},
17089+
"immutable": true,
17090+
"locationInModule": {
17091+
"filename": "lib/jsii4894.ts",
17092+
"line": 8
17093+
},
17094+
"name": "someType",
17095+
"type": {
17096+
"fqn": "@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName.SomeType"
17097+
}
17098+
}
17099+
],
17100+
"symbolId": "lib/jsii4894:NonPascalCaseTest"
17101+
},
17102+
"jsii-calc.jsii4894.NonPascalCaseTestProps": {
17103+
"assembly": "jsii-calc",
17104+
"datatype": true,
17105+
"docs": {
17106+
"stability": "stable"
17107+
},
17108+
"fqn": "jsii-calc.jsii4894.NonPascalCaseTestProps",
17109+
"kind": "interface",
17110+
"locationInModule": {
17111+
"filename": "lib/jsii4894.ts",
17112+
"line": 3
17113+
},
17114+
"name": "NonPascalCaseTestProps",
17115+
"namespace": "jsii4894",
17116+
"properties": [
17117+
{
17118+
"abstract": true,
17119+
"docs": {
17120+
"stability": "stable"
17121+
},
17122+
"immutable": true,
17123+
"locationInModule": {
17124+
"filename": "lib/jsii4894.ts",
17125+
"line": 4
17126+
},
17127+
"name": "someType",
17128+
"type": {
17129+
"fqn": "@scope/jsii-calc-lib.submodule.ClassWithNONPASCALCASEDName.SomeType"
17130+
}
17131+
}
17132+
],
17133+
"symbolId": "lib/jsii4894:NonPascalCaseTestProps"
17134+
},
1703317135
"jsii-calc.module2530.MyClass": {
1703417136
"assembly": "jsii-calc",
1703517137
"docs": {
@@ -19029,5 +19131,5 @@
1902919131
}
1903019132
},
1903119133
"version": "3.20.120",
19032-
"fingerprint": "diRJGYXL5dj+evWTyBy8BeUweyFmmVEcYDFNewFM1VQ="
19134+
"fingerprint": "O9HJsUWsfrb1HrOQ1znKEfsWfa9DuDhrkIFb7nHuB2g="
1903319135
}

0 commit comments

Comments
 (0)