-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Better handling for manually created source files and compiler APIs #28413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is by design currently, but we should probably attempt to do something better than crash with a random js error (ideally we'd capture the difference between the trees in the API somehow) - maybe we can set a bit on synthetic source files that only gets unset when it becomes correctly bound and checked, and we use that bit to throw early on in the checker if it's set? I'm unsure. |
That probably won't work for SourceFiles from different Programs or Nodes that were previously part of a SourceFile but no longer are because of incremental parsing through |
We could set a random ID (random as in non-sequential, but the same ID for every node) on all nodes in a program and assert if the node the checker receives has an ID not equal to the hosting program's, perhaps? |
@weswigham I haven't come up with a better idea than that 😄. Would you accept a PR for the program-specific IDs? Clarifying questions:
Edit: oh, and should this be an opt-in feature, so that the CLI doesn't enable it, but external tools programmatically calling TS APIs would? |
I'd say so, yes.
Setting it at the same time we refresh and set
I'd be temped to tie it to the
We have some internal tools for informally measuring perf changes of some samples we have (and analyzing the resulting perf traces) - unfortunately we've never made them public. The closest thing we use in public is the aggregate timing data collected by the |
While i am not too familar with typescript internals, the fork-ts-checker-webpack-plugin, somehow managed to allow typechecking for .vue file: https://github.com/Realytics/fork-ts-checker-webpack-plugin/blob/master/src/VueProgram.ts |
Uh oh!
There was an error while loading. Please reload this page.
Search Terms
type checker source file cannot ready property 'members' of undefined
Suggestion
When a user of the compiler API manually creates a source file with
ts.createSourceFile
instead of retrieving it from theirprogram
, and then asks theprogram
for type inference on a contained node, this can crash. See #8136 / vuejs/vue-cli#2712 / angular/tsickle#151 / budgielang/ts-budgie#39.It seems like one of three interpretations might be best:
Use Cases
Auto-generated TypeScript files, such as
.vue
snippets, still want access to a type checker, such as for TSLint rules.Examples
palantir/tslint#4273
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: