question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better handling for manually created source files and compiler APIs

See original GitHub issue

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 their program, and then asks the program for type inference on a contained node, this can crash. See https://github.com/Microsoft/TypeScript/issues/8136 / https://github.com/vuejs/vue-cli/issues/2712 / https://github.com/angular/tsickle/issues/151 / https://github.com/general-language-syntax/TS-GLS/issues/39.

It seems like one of three interpretations might be best:

  • This is explicitly unsupported behavior, but for the sake of performance & simplicity, no checks should happen
  • This is explicitly unsupported behavior, and a more explicit error should be thrown
  • This should become supported behavior, and the program should dynamically create source files as requested

Use Cases

Auto-generated TypeScript files, such as .vue snippets, still want access to a type checker, such as for TSLint rules.

Examples

https://github.com/palantir/tslint/issues/4273

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript / JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. new expression-level syntax)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
backbone87commented, Mar 10, 2019

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

0reactions
weswighamcommented, Dec 13, 2018

Would each round of parsing (first the initial creation, then incremental parsing) use a new ID

I’d say so, yes.

Is the performance cost of updating all nodes something you’re concerned about?

Setting it at the same time we refresh and set .parent pointers in the parser/binder should be relatively cheap, since those need to be rewritten in the same way.

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 be temped to tie it to the diagnostics flag - but it’s probably best to only tie it to a flag if it has measurable perf impact.

Meaning: would you want a PR to include timing tests showing no real change, and if so, how do you TypeScript folks normally create those?

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 --extendedDiagnostics flag, but that’s only for tsc. For measuring, eg, the impact on LS operations and incremental parse, we don’t have anything anywhere (at least that I know of). We store execution time of tests when they’re run in parallel so we can more optimally schedule them on future runs, so that tracks, eg, fourslash test duration. You could maybe shoehorn that into measuring a fourslash test that edits and rechecks a file a bunch of times (or just enable and use the ts.performance timers on fourslash tests and add a new verifier/baseliner)… but yeah - we have no formal infra for measuring LS perf generally right now. When a perf issues is reported, we usually just get a repro and then open the build or LS in the chrome devtools and run a performance trace - that’s not great for trying to benchmark a LS change, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source Files and Compilation - Cython's Documentation
Compiling with the cython command¶. One way is to compile it manually with the Cython compiler, e.g.: $ cython primes.pyx.
Read more >
Documentation - tsc CLI Options - TypeScript
Flag Type Default ‑‑allowJs boolean false ‑‑allowUmdGlobalAccess boolean false ‑‑allowUnreachableCode boolean
Read more >
Closure Compiler - Google Developers
The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code,...
Read more >
Shrink, obfuscate, and optimize your app - Android Developers
Learn how to shrink code in your release build to remove unused code and resources.
Read more >
Essentials, Part 1, Lesson 1: Compiling & Running a Simple ...
Code comments are placed in source files to describe what is happening in the code to someone who might be reading the file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found