-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsii): unable to use type from dependencies' submodules (#1557)
When referring to a type defined in a submodule of a dependency (but not using the "inline `namespace`" syntax style), the `jsii` compiler failed to account for the namespace segment and generated an incorrect `fqn`, leading to a type resolution error failing the compilation. This adds a pass in the compiler to gather submodule layout from dependencies and correctly register them in the compilation context, so correct `fqn` are emitted. New types have been introduced in `@scope/jsii-calc-lib` and `jsii-calc` to verify that the compiler produces reasonable output. Those will be leveraged in new compliance tests in a subsequent PR, as some outstanding code-generation issues come in the way of these tests.
- Loading branch information
1 parent
e016163
commit ba7fac2
Showing
38 changed files
with
1,357 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface IReflectable { | ||
readonly entries: ReflectableEntry[]; | ||
} | ||
|
||
export interface ReflectableEntry { | ||
readonly key: string; | ||
readonly value: unknown; | ||
} | ||
|
||
export class Reflector { | ||
public constructor() { } | ||
|
||
public asMap(reflectable: IReflectable): Record<string, unknown> { | ||
return reflectable.entries.reduce( | ||
(mapping, entry) => { | ||
mapping[entry.key] = entry.value; | ||
return mapping; | ||
}, | ||
{} as Record<string, unknown>, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { submodule } from '@scope/jsii-calc-lib'; | ||
|
||
/** | ||
* Ensures submodule-imported types from dependencies can be used correctly. | ||
*/ | ||
export class UpcasingReflectable implements submodule.IReflectable { | ||
public static readonly reflector = new submodule.Reflector(); | ||
|
||
public constructor(private readonly delegate: Record<string, unknown>) { } | ||
|
||
public get entries(): submodule.ReflectableEntry[] { | ||
return Object.entries(this.delegate) | ||
.map(([key, value]) => ({ key: key.toLocaleUpperCase(), value })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.