-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): Generate maps to allow improved "go to definition" behavi…
…our (#9269) **Problem** Navigating to the definition of pages, layouts, components, cells etc. would lead you to the .d.ts file. This can be really frustrating if you're used to flying around between definitions this way. **Changes** 1. Generates basic definition/source mappings for: 1. directory mapped modules 2. cell mirrors 3. router pages 4. route links **Linked issues** Fixes #5862 Fixes #2867 **Performance** This adds additional AST parsing work to the `yarn rw g types` so it has the potential to slow that command down. I have tested that command on the test project and the results are: Benchmark: `hyperfine --runs 32 --warmup 3 'yarn rw g types'` Main: ``` Benchmark 1: yarn rw g types Time (mean ± σ): 4.006 s ± 0.048 s [User: 5.244 s, System: 0.737 s] Range (min … max): 3.926 s … 4.171 s 32 runs ``` PR: ``` Benchmark 1: yarn rw g types Time (mean ± σ): 4.629 s ± 0.049 s [User: 6.066 s, System: 0.828 s] Range (min … max): 4.544 s … 4.723 s 32 runs ``` An approximate +15% change in duration on this basic test. There are areas where caching results could improve performance. For example we are likely finding the location of page components twice when we could cache the first result. I have not added this here so we do not prematurely optimise and introduce subtle bugs that would be more difficult to track down. If users with large projects report problems with this performance change then we can work to address it. **Notes** This is not an area I'm particularly knowledgeable about so there could be unknown consequences to this that I don't know about. For pages and other web components it's easy to direct the map to the definition of the specific component that is the default export. This is not the case for cells as they have no default export and instead have a number of other non-default exports. In this case I currently direct the map to the head of the source file - happy to improve on this based on feedback. For future reference I found the following useful: * https://www.murzwin.com/base64vlq.html * https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.1ce2c87bpj24
- Loading branch information
1 parent
b0964a9
commit 452ec49
Showing
12 changed files
with
302 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
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
2 changes: 2 additions & 0 deletions
2
packages/internal/src/generate/templates/mirror-directoryNamedModule.d.ts.template
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { default as DEFAULT } from './${name}' | ||
export default DEFAULT | ||
export * from './${name}' | ||
|
||
//# sourceMappingURL=index.d.ts.map |
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ ${routes.map( | |
} | ||
} | ||
|
||
//# sourceMappingURL=web-routerRoutes.d.ts.map |
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.