Skip to content

Commit

Permalink
feat: compat for Vue 3.4 (#567)
Browse files Browse the repository at this point in the history
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
  • Loading branch information
yyx990803 and sxzz committed Nov 25, 2023
1 parent 033ff02 commit 2d4a32d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-buckets-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/setup-block': patch
---

compat for Vue 3.4
12 changes: 8 additions & 4 deletions packages/setup-block/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
import { MagicString, generateTransform } from '@vue-macros/common'
import { type NodeTypes, type TextModes, parse } from '@vue/compiler-dom'
import { type ElementNode, type NodeTypes, parse } from '@vue/compiler-dom'

export function transformSetupBlock(code: string, id: string, lang?: string) {
const s = new MagicString(code)

const node = parse(code, {
// @ts-ignore TODO remove ignore in 3.4
parseMode: 'sfc',
// there are no components at SFC parsing level
isNativeTag: () => true,
// preserve all whitespaces
isPreTag: () => true,
getTextMode: ({ tag, props }, parent) => {
// @ts-ignore (this has been removed in Vue 3.4)
getTextMode: ({ tag, props }: ElementNode, parent) => {
// all top level elements except <template> are parsed as raw text
// containers
if (
Expand All @@ -25,9 +29,9 @@ export function transformSetupBlock(code: string, id: string, lang?: string) {
p.value.content !== 'html',
))
) {
return 2 satisfies TextModes.RAWTEXT
return 2
} else {
return 0 satisfies TextModes.DATA
return 0
}
},
})
Expand Down

0 comments on commit 2d4a32d

Please sign in to comment.