-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Create an API to "seed" the parser with an existing program #1442
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
would this allow a svelte preprocess to give the code to the typescript parser in eslint, |
@Zerowalker no, you misunderstand how eslint works. ESLint calls our parser to understand typescript code. This change is so that tools like |
Ah, don't understand it fully i think, but i think i somewhat get it. Then offtopic, but if i want to send typescript data from something that's been processed, |
When you lint a file, you call ESLint. Whether you lint a file via the CLI ( If you have typescript code, you configure ESLint to use our parser via the Now if you configure our parser to provide type information via the Now if you imagine a use case like FTSCWP; it has already done all of this expensive parsing using similar APIs. Right now, if you do a lint as part of a webpack build, then FTSCWP will do its parse, and our parser will do our parse. Probably one after the other, meaning you pay the time and memory cost of typechecking a TS project twice. So imagine if we could take the result from FTSCWP, and share it with our parser? That's the point of this issue; creating an API in our parser so that you can require it, and give it the result before calling the ESLint API. That way when you call ESLint, the parser is "seeded", and has to do no parsing. Onto your comment - the short answer is "not easily". For vue there is a custom parser, which parses vue code, and produces AST fragments. When it encounters a For svelte, there is an eslint-plugin, which uses a ESLint pre-processor to do a similar thing. The difference between the two solutions;
|
Just a heads up - @uniqueiniquity just added an API to do this as a v0. |
There are a number of tools (like
fork-ts-checker-webpack-plugin
) that already manage a TS program, and that would like to integrate with ESLint as well.Unfortunately, right now our parser is a black box - we create and manage the
Program
s we use, and our APIs only accept a file path, and file contents as input.This, brings a problem of wasted memory, because the tool and our parser both create separate
Program
s.We should look into creating an API which would "seed" the parser with a given program, using that program instead of creating its own.
I'd imagine something along the lines of:
cc @johnnyreilly - for
fork-ts-checker-webpack-plugin
.Slightly related: #774
The text was updated successfully, but these errors were encountered: