Skip to content
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

fix: handle unclosed string literal for multiline vue component props #7

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>