Skip to content

Commit a39ba58

Browse files
authoredMar 29, 2024··
fix: handle unclosed string literal for multiline vue component props (#7)
1 parent d96d881 commit a39ba58

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
 

‎src/js-tokens.ts

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export function stripLiteralJsTokens(code: string, options?: StripLiteralOptions
2626
}
2727

2828
if (token.type === 'StringLiteral') {
29+
// js-token sees exotic vue prop value as an unclosed string literal
30+
if (!token.closed) {
31+
result += token.value
32+
continue
33+
}
2934
const body = token.value.slice(1, -1)
3035
if (filter(body)) {
3136
result += token.value[0] + FILL.repeat(body.length) + token.value[token.value.length - 1]

‎test/fixtures/vitest-5387.output.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<SomeOtherComponent
2+
:some-prop="
3+
testValue
4+
? ' '
5+
: ' '
6+
"
7+
>
8+
</SomeOtherComponent>

‎test/fixtures/vitest-5387.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<SomeOtherComponent
2+
:some-prop="
3+
testValue
4+
? 'A long value to break handling of env variables'
5+
: 'it needs to break into a new line'
6+
"
7+
>
8+
</SomeOtherComponent>

0 commit comments

Comments
 (0)
Please sign in to comment.