Skip to content

Commit

Permalink
fix: keep unclosed string literal to handle exotic vue input
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 29, 2024
1 parent 641b7a1 commit af08636
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 99 deletions.
5 changes: 5 additions & 0 deletions src/js-tokens.ts
Original file line number Diff line number Diff line change
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
46 changes: 0 additions & 46 deletions src/regex.ts

This file was deleted.

17 changes: 0 additions & 17 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { describe, expect, it } from 'vitest'
import { stripLiteralDetailed } from '../src'
import { stripLiteralRegex } from '../src/regex'
import { executeWithVerify } from './utils'

describe('fixtures', () => {
Expand All @@ -16,18 +14,3 @@ describe('fixtures', () => {
})
}
})

describe('counter examples', () => {
const cases = import.meta.glob('./fixtures/counter/*.*', { as: 'raw' })
for (const [path, input] of Object.entries(cases)) {
if (path.includes('.output.'))
continue
it(path, async () => {
const raw = await input()
await expect(stripLiteralDetailed(raw).result)
.toMatchFileSnapshot(path.replace(/\.(\w+)$/, '.output.js-token.$1'))
await expect(stripLiteralRegex(raw))
.toMatchFileSnapshot(path.replace(/\.(\w+)$/, '.output.regex.$1'))
})
}
})
12 changes: 0 additions & 12 deletions test/fixtures/counter/vitest-5387.output.js-token.vue

This file was deleted.

12 changes: 0 additions & 12 deletions test/fixtures/counter/vitest-5387.output.regex.vue

This file was deleted.

12 changes: 0 additions & 12 deletions test/fixtures/counter/vitest-5387.vue

This file was deleted.

8 changes: 8 additions & 0 deletions test/fixtures/vitest-5387.output.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<SomeOtherComponent
:some-prop="
testValue
? ' '
: ' '
"
>
</SomeOtherComponent>
8 changes: 8 additions & 0 deletions test/fixtures/vitest-5387.vue
Original file line number Diff line number Diff line change
@@ -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 af08636

Please sign in to comment.