-
-
Notifications
You must be signed in to change notification settings - Fork 184
fix: ts expression should work well in the pug template #123
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
base: main
Are you sure you want to change the base?
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 |
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).