Skip to content

Commit a4b82d2

Browse files
committed
fix: template literal, close unplugin#82
1 parent 041f971 commit a4b82d2

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/core/transform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const excludeRE = [
1010
/\b(?:const|let|var)\s+?(\[[\s\S]*?\]|\{[\s\S]*?\}|[\s\S]+?)\s*?[=;\n]/g,
1111
]
1212

13-
const matchRE = /(?<![\w_$]\.)([\w_$]+?)[^\w_$]/g
13+
const matchRE = /(?<![\w_$]\.)([\w_$]+?)[^\w_${]/g
1414
const importAsRE = /^.*\sas\s+/
1515
const seperatorRE = /[,[\]{}\n]/g
1616
const multilineCommentsRE = /\/\*\s(.|[\r\n])*?\*\//gm
@@ -25,6 +25,7 @@ function stripeCommentsAndStrings(code: string) {
2525
.replace(multilineCommentsRE, '')
2626
.replace(singlelineCommentsRE, '')
2727
.replace(quotesRE[0], '""')
28+
.replace(/\$\{(.*)\}/g, '` + $1 + `')
2829
.replace(quotesRE[1], '``')
2930
}
3031

test/__snapshots__/transform.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ onMount(() => {})
159159
"
160160
`;
161161
162+
exports[`transform fixtures template-literal.ts 1`] = `
163+
"import { ref } from 'vue';const z = \`bar-\${ref()}\`
164+
"
165+
`;
166+
162167
exports[`transform fixtures vue.js 1`] = `
163168
"import { useQuasar, useMeta } from 'quasar';import { ref } from 'vue';import { defineStore, mapState } from 'pinia';const q = useQuasar()
164169
const meta = useMeta()

test/fixtures/template-literal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const z = `bar-${ref()}`

0 commit comments

Comments
 (0)