-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dependency submodules may not be discovered (#3151)
When a dependency exposes submodules, and the entry point of that dependency is never imported by the program being compiled, symbols from the dependency were not correctly mapped to their submodule because the entry point was not part of the compiler input (and hence the `ts.Program` did not hold a `ts.SourceFile` for it, and the `ts.TypeChecker` did not have symbols for exports therein). In order to address this problem, this always explicitly references dependencies' entry point (the `.d.ts` file referenced by the `types` key) to the compiler input path. This guarantees the compiler binds symbols within those, and that the submodule mapper can appropriately discover those. ------------------------------------------------------------------------ An alternative approach was considered (but rejected because it introduced significant complexity): we could have created `ts.SourceFile` objects using `ts.createSourceFile`, which allows us to obtain a set of `ts.Statement` nodes, however those are not bound to symbols and we then have to process the AST without the assistance of the type checker (and would end up having to re-implement a sub-set of the binder/type-checker's features). --- 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
- Loading branch information
Romain Marcadier
committed
Nov 10, 2021
1 parent
ba4a20d
commit 5768bb9
Showing
14 changed files
with
140 additions
and
8 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
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,4 @@ | ||
/.jsii | ||
/tsconfig.json | ||
*.js | ||
*.d.ts |
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,6 @@ | ||
# @barrelimport/consumer | ||
|
||
This library re-exports a type imported from a barrel location within | ||
`@barrelimport/provider`, without actually importing `@barrelimport/provider` | ||
itself, so we validate the jsii compiler correctly identifies the submodule | ||
declarations. |
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,6 @@ | ||
// Directly importing NamespacedStruct, NEVER having imported @barrelimports/provider | ||
import { NamespacedStruct } from '@barrelimports/provider/lib/namespaced'; | ||
|
||
export class UsingBarrelImport { | ||
public constructor(public readonly props: NamespacedStruct) { } | ||
} |
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,30 @@ | ||
{ | ||
"name": "@barrelimports/consumer", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aws/jsii.git", | ||
"directory": "regression-tests/@barrelimports/provider" | ||
}, | ||
"scripts": { | ||
"build": "jsii" | ||
}, | ||
"peerDependencies": { | ||
"@barrelimports/provider": "0.0.0" | ||
}, | ||
"devDependencies": { | ||
"@barrelimports/provider": "0.0.0", | ||
"jsii": "^0.0.0" | ||
}, | ||
"jsii": { | ||
"targets": {} | ||
} | ||
} |
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,4 @@ | ||
/.jsii | ||
/tsconfig.json | ||
*.js | ||
*.d.ts |
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,5 @@ | ||
# @barrelimport/provider | ||
|
||
This library provides a single namespaced export struct, so that we can validate | ||
the jsii compiler is correctly able to identify submodule declarations when the | ||
package entry point is never imported by the consuming code. |
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 @@ | ||
export * as namespaced from './namespaced'; |
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,3 @@ | ||
export interface NamespacedStruct { | ||
readonly name: string; | ||
} |
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,26 @@ | ||
{ | ||
"name": "@barrelimports/provider", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aws/jsii.git", | ||
"directory": "regression-tests/@barrelimports/provider" | ||
}, | ||
"scripts": { | ||
"build": "jsii" | ||
}, | ||
"devDependencies": { | ||
"jsii": "^0.0.0" | ||
}, | ||
"jsii": { | ||
"targets": {} | ||
} | ||
} |
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,10 @@ | ||
# Regression Tests | ||
|
||
This directory contains packages that are supposed to cleanly compile using | ||
`jsii`. This validates the compiler is able to correctly interpret the source. | ||
|
||
When adding new tests, be sure to follow these guidelines: | ||
|
||
- Create a new namespace for each regression scenario | ||
- All packages should have `private: true` in their `package.json` | ||
- Provide a README.md with an explanation of what the package(s) validate |