Skip to content

Commit

Permalink
fix: handle unclosed string literal for multiline vue component props (
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 29, 2024
1 parent d96d881 commit a39ba58
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/js-tokens.ts
Expand Up @@ -26,6 +26,11 @@ export function stripLiteralJsTokens(code: string, options?: StripLiteralOptions
}

if (token.type === 'StringLiteral') {
// js-token sees exotic vue prop value as an unclosed string literal
if (!token.closed) {
result += token.value
continue
}
const body = token.value.slice(1, -1)
if (filter(body)) {
result += token.value[0] + FILL.repeat(body.length) + token.value[token.value.length - 1]
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/vitest-5387.output.vue
@@ -0,0 +1,8 @@
<SomeOtherComponent
:some-prop="
testValue
? ' '
: ' '
"
>
</SomeOtherComponent>
8 changes: 8 additions & 0 deletions test/fixtures/vitest-5387.vue
@@ -0,0 +1,8 @@
<SomeOtherComponent
:some-prop="
testValue
? 'A long value to break handling of env variables'
: 'it needs to break into a new line'
"
>
</SomeOtherComponent>

0 comments on commit a39ba58

Please sign in to comment.