Skip to content
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

Add TypeScript support #83

Merged
merged 13 commits into from
Feb 15, 2021
Merged

Add TypeScript support #83

merged 13 commits into from
Feb 15, 2021

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Feb 9, 2021

Closes #68

This does not introduce a generic preprocessor-option. Instead it provides a TypeScript-specific implementation. The advantage is that we don't need hacks like deasync because transpilation and mapping can happen synchronously. It also makes post-processing and interaction with ESLint easier.

How it works:

  1. transpile script contents from TS to JS
  2. compile result to get Svelte compiler warnings
  3. map those warnings back to its original positions
  4. blank script contents
  5. compile again to get the AST with original positions in the markdown part
  6. use AST of step 5, vars of step 2 and blanked script content to produce the text which is handed to ESLint
  7. Let the ESLint TypeScript plugin handle the TS code
  8. adjust mappings

TODO:

  • test/support for named blocks
  • check type-aware rules support
  • map suggestions (this could be a independent PR)

Question: Update package-lock.json? There are new (dev) dependencies and it would be good to have them in there. Why is it ignored in the first place?

Closes sveltejs#68

This does not introduce a generic preprocessor-option. Instead it provides a TypeScript-specific implementation. The advantage is that we don't need hacks like deasync because transpilation and mapping can happen synchronously. It also makes post-processing and interaction with ESLint easier.

How it works:
1. transpile script contents from TS to JS
2. compile result to get Svelte compiler warnings
3. map those warnings back to its original positions
4. blank script contents
5. compile again to get the AST with original positions in the markdown part
6. use AST of step 5, vars of step 2 and blanked script content to produce the text which is handed to ESLint
7. Let the ESLint TypeScript plugin handle the TS code
8. adjust mappings
@dummdidumm dummdidumm marked this pull request as draft February 9, 2021 10:43
@dummdidumm dummdidumm marked this pull request as ready for review February 9, 2021 15:01
src/mapping.js Outdated Show resolved Hide resolved
@dummdidumm
Copy link
Member Author

Sorry about these code style issues, I'm no longer able to format myself since using Prettier 😄

@winfr34k
Copy link

Yeah!
Thanks to this getting merged, we can finally lint out TS/Svelte project 👍

@dummdidumm dummdidumm deleted the typescript branch February 16, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript?
4 participants