fix: ts expression should work well in the pug template#123
Open
Jevon617 wants to merge 1 commit intovitejs:mainfrom
Open
fix: ts expression should work well in the pug template#123Jevon617 wants to merge 1 commit intovitejs:mainfrom
Jevon617 wants to merge 1 commit intovitejs:mainfrom
Conversation
|
Any chance we can get this merged? This bug is affecting me quite a bit. |
|
bump |
|
+1 |
|
Almost always it is possible to extract Typescript to the |
|
2024 bump! |
|
This issue makes can't use Pug with Typescript. |
|
Applying these changes to version 6.0.0 works without any edits beside resolving the simple conflicts, it would be great to have it merged in! |
|
I'm using the following pnpm patch to cherry pick these changes into the latest Vite 8.0.0-beta.0: diff --git a/dist/index.mjs b/dist/index.mjs
index 83717e6565c721494c24b34c2e2c056ec9a1bea1..da29046c72b65f452524a5b8161dc8016a794cd0 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -169,15 +169,35 @@ function createRollupError(id, error) {
//#endregion
//#region src/template.ts
async function transformTemplateAsModule(code, filename, descriptor, options, pluginContext, ssr, customElement) {
- const result = compile(code, filename, descriptor, options, pluginContext, ssr, customElement);
- let returnCode = result.code;
+ let { code: returnCode, map: returnMap } = compile(code, filename, descriptor, options, pluginContext, ssr, customElement);
if (options.devServer && options.devServer.config.server.hmr !== false && !ssr && !options.isProduction) returnCode += `\nimport.meta.hot.accept(({ render }) => {
__VUE_HMR_RUNTIME__.rerender(${JSON.stringify(descriptor.id)}, render)
})`;
- return {
- code: returnCode,
- map: result.map
- };
+ const lang = descriptor.scriptSetup?.lang || descriptor.script?.lang
+
+ if (
+ lang &&
+ /tsx?$/.test(lang) &&
+ !descriptor.script?.src // only normal script can have src
+ ) {
+ const { transformWithOxc } = await import("vite");
+ const { code, map } = await transformWithOxc(
+ returnCode,
+ descriptor.filename,
+ {
+ lang: 'ts',
+ sourcemap: options.sourceMap,
+ },
+ returnMap,
+ )
+ returnCode = code
+ returnMap = returnMap ? map : returnMap
+ }
+
+ return {
+ code: returnCode,
+ map: returnMap
+ };
}
/**
* transform the template directly in the main SFC module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix #18
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).