Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit eff7c79

Browse files
fix(core): fix analyzer duplicate injection code (#268)
* fix(core): fix analyzer duplicate injection code * chore: playground add jsx
1 parent bfc59e6 commit eff7c79

File tree

6 files changed

+302
-1
lines changed

6 files changed

+302
-1
lines changed

packages/core/src/compiler/trace-rerender.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export function analyzeByTraceRerender(code: MS, locations: InsertLocation[]) {
2222
});\n`,
2323
}
2424

25+
// to avoid duplicate injection
26+
const currentCode = code.toString()
27+
const shouldInject = Object.entries(apiNames).map(([, alias]) => {
28+
return !currentCode.includes(alias)
29+
}).every(Boolean)
30+
31+
if (!shouldInject)
32+
return code
33+
2534
locations.forEach(({ start, end }, idx) => {
2635
if (idx === 0) {
2736
code = ensureImport(code, {
@@ -30,6 +39,7 @@ export function analyzeByTraceRerender(code: MS, locations: InsertLocation[]) {
3039
})),
3140
}, start)
3241
}
42+
3343
entries(injectedCodes).forEach(([, appendCode]) => {
3444
code.prependLeft(end, appendCode)
3545
})

packages/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"devDependencies": {
1717
"@vitejs/plugin-vue": "^4.4.0",
18+
"@vitejs/plugin-vue-jsx": "^3.1.0",
1819
"serve": "^14.2.1",
1920
"typescript": "^5.2.2",
2021
"vite": "^4.4.11",

packages/playground/src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { computed, reactive, ref } from 'vue'
33
import { useRouter } from 'vue-router'
44
import ReadCounter from './components/ReadCounter.vue'
5+
import TSX from './components/TSX.vue'
56
67
const count = ref(0)
78
const doubleCount = computed(() => {
@@ -43,6 +44,7 @@ const router = useRouter()
4344
{{ count }}
4445
{{ doubleCount }}
4546
<ReadCounter />
47+
TSX: <TSX />
4648
<RouterView />
4749
<!-- <HelloWorld msg="Vite + Vue" /> -->
4850
<button @click="router.push('/about')">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue'
3+
4+
export default defineComponent({
5+
setup() {
6+
return () => <div>TSX Component</div>
7+
},
8+
})
9+
</script>

packages/playground/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { resolve } from 'node:path'
22
import type { Plugin } from 'vite'
33
import { defineConfig } from 'vite'
44
import vue from '@vitejs/plugin-vue'
5+
import jsx from '@vitejs/plugin-vue-jsx'
56
import VueDevTools from 'vite-plugin-vue-devtools'
67

78
// https://vitejs.dev/config/
@@ -17,5 +18,6 @@ export default defineConfig({
1718
plugins: [
1819
VueDevTools() as Plugin[],
1920
vue(),
21+
jsx(),
2022
],
2123
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy