-
Notifications
You must be signed in to change notification settings - Fork 150
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
Better Typescript transpilation #392
Conversation
- inject vars from markup to typescript - do not use importTransform when markup is available - inject component script to context=module script - refactor modules/markup to reuse common functions - test injection behavior
- introduce two deps: magic-string, sorcery - produce a source map on each step of the process - store all source maps in a chain - refactor transformer to increase readability
…into typescript-imports
The failing tests seem unrelated, I guess they appear as a cause of the Svelte dev dependency bump. Edit: Yes, this PR sveltejs/svelte#5854 added support for inline source maps and notes that they are removed from the output while merging the source maps, so the way the tests test this no longer works. I also noticed that |
Inline source maps are stripped in recents Svelte preprocess versions, therefore we need to test the source map generation differently
Somewhat related. If the direction of adding a new option is accepted, then yes #342 can be closed. If we want to make this new transpilation the new default behavior, we first need to change the implementation and that could happen in #342 as well. For my arguments in favor of making this an option, see the comment above. |
Hi @dummdidumm, Thank you for taking some time on this PR. Your evolution is great. Here is my feedback:
So I have 3 questions:
|
They already have to for
I trief this, too, and didn't find any breaking things, so I'm also very confident that this works. The argument for making it an option is not related to this for me.
I think we shouldn't make these assumptions. Preprocessors could run in other contexts unrelated to Rollup or without removing unused imports as well. My arguments in favor of the option:
|
You're right, but it means that you now need to install 3 additionnal dependencies (typescript, magic-string, sorcery). Installing typescript is necessary when you use typescript in a project so it's normal to install it manually. However installing magic-string and sorcery is more obscure.
I'm in favor of adding them to dependencies. In this comment, I explain that both dependencies can be reused to improve the sourcemap handling of
I'm not totally sure that this will be an intermediate solution. Even if TypeScript provides a new import option to strictly separate types and values, this will generate additional code and will make imports less readable. Those who are using TypeScript for long time are used to combine types and values in the same import statement and IMHO, they will prefer staying like this. |
In the case of
I get that sentiment. We should rename the option to something that doesn't sound like it's superior to the current solution, like @kaisermann you asked about the TypeScript PR, it looks like it might land in 4.5: microsoft/TypeScript#44619 |
Agreed, seems too specific and obscure. Also, I've been wanting to use
Maybe
This wouldn't be the first time we did this: https://github.com/sveltejs/svelte-preprocess/blob/6346194254/src/autoProcess.js#L92. We can have it now as an opt-in feature and wait for a bit to see how it fairs in the wild and set it as the default behaviour on a future minor or possibly major version. |
I changed the option name to @SomaticIT could you give this one more try on your own project to see if that I didn't break anything? I think this is good to merge now if there are no objections to the option name. |
It seems good for me. |
only syntax errors are reported, not semantic errors
@SomaticIT were you able to have a look? Would love to get this merged. @kaisermann any change request for the PR or is this good to go for you? |
I will give the transformer a final look, format the file and we should be good. I should be able to do this in the following days 👍 |
Victory!!! 🎉 I finally found what was causing the comment issue, it was my fault 😥. This was making markup transform to handle comments as Now everything is working fine on my project, I have no regression and I can merge type and value imports 💪! @dummdidumm, you can find the fix in the last commit of the PR I submitted on your fork. |
Thank you for looking into this! I found one more edge case I fixed: It's valid to import something in the instance script but only use it in the module script. Therefore I append the module script below the instance script now. @kaisermann this is now good to go (the lintings should be fine now, too), please make sure that the "co-authored by"-message for @SomaticIT is part of the squash-merge-commit so he gets proper credit. |
I updated my local version and everything is working fine! I was happy to collaborate with you on this very exciting feature!! |
@dummdidumm, I found one more edge case: the codestores detection regex can detect reserved keywords. PatchYou can find the patch here: code-vars-filter-reserved-keywords.patch Exemple:const filter = { $in: ["test"] }; In the above code, the codestores regex will detect Edit 1:I updated the patch above because some reserved keywords were removed in ES5/6. FYI, the reserved keyword list comes from this page: https://www.w3schools.com/js/js_reserved.asp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added some minor comments. Other than that this looks great, good job @SomaticIT and @dummdidumm 🎉
It seems good for me, I'll continue to use this specific version on my largest project to see if I discover more edge cases. However it seems to work well for me. |
Released as v4.9.0 🎉 Awesome job 🙏 |
Are you referring to
on latest |
It's called |
@dummdidumm Looks like this change does not apply to imports from
Is this expected? See sveltejs/kit#2384 (comment) for details. |
This is expected. If your import consists of types only, you need to use |
I see. Prob should have read this thread more carefully. |
"ts-jest": "^25.1.0", | ||
"typescript": "^3.9.5" | ||
}, | ||
"dependencies": { | ||
"@types/pug": "^2.0.4", | ||
"@types/sass": "^1.16.0", | ||
"detect-indent": "^6.0.0", | ||
"magic-string": "^0.25.7", | ||
"sorcery": "^0.10.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorcery was not supported for a long time and adds a few unnecessary dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a good alternative to achieve source map concatenation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could bump sorcery to node 10 or 12 and get rid from "sander" package. Though I see svelte-preprocess still supports node 9. Do you plan major bump in near future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean you have write access to the repo? I only see Rich having contributed to that repository. Can't speak for how soon @kaisermann plans on bumping, but if a little cleanup can be done I have nothing against that. Not pressing for me since the solution seems to work so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't yet but I can ask Rich
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could bump sorcery to node 10 or 12 and get rid from "sander" package. Though I see svelte-preprocess still supports node 9. Do you plan major bump in near future?
Yeah, I've been wanting to remove the deprecated things and do a little cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're already here, I've started a discussion about one of the things on my mind for the next major: #424
Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
This PR builds upon the stellar work by @SomaticIT in #318 . See that PR for more info on the "why do this"?
This PR superseeds #318 and adds the following additions:
Closes #318