Skip to content

Commit b620c2b

Browse files
committed
fix: keep existing parent reference
1 parent 258f4f5 commit b620c2b

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,10 @@ function replaceChildNode (parent: VueAST.Node, oldChild: VueAST.Node, newChild:
257257
}
258258
return false
259259
}
260+
261+
type Builders = CodemodPluginContext['utils']['builders']
262+
export function setParents (node: AST.Node, builders: Builders) {
263+
const parent = node.parent
264+
builders.setParents(node)
265+
node.parent = parent
266+
}

src/plugins/v4/grid.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AST, CodemodPlugin, CodemodPluginContext } from 'vue-metamorph'
22
import { astHelpers } from 'vue-metamorph'
3-
import { classify } from '../../helpers'
3+
import { classify, setParents } from '../../helpers'
44

55
type Builders = CodemodPluginContext['utils']['builders']
66

@@ -30,7 +30,7 @@ export const v4GridPlugin: CodemodPlugin = {
3030
builders.vIdentifier('density'),
3131
builders.vLiteral('compact'),
3232
))
33-
builders.setParents(el.startTag)
33+
setParents(el.startTag, builders)
3434
count++
3535
}
3636

@@ -86,7 +86,7 @@ function appendStaticClass (el: AST.VElement, cls: string, builders: Builders) {
8686
builders.vLiteral(cls),
8787
),
8888
)
89-
builders.setParents(el.startTag)
89+
setParents(el.startTag, builders)
9090
}
9191
}
9292

src/plugins/v4/snackbar-multiline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CodemodPlugin } from 'vue-metamorph'
2-
import { camelize, classify } from '../../helpers'
2+
import { camelize, classify, setParents } from '../../helpers'
33

44
export const v4SnackbarMultilinePlugin: CodemodPlugin = {
55
type: 'codemod',
@@ -27,7 +27,7 @@ export const v4SnackbarMultilinePlugin: CodemodPlugin = {
2727
node.startTag.attributes.push(
2828
builders.vAttribute(builders.vIdentifier('min-height'), builders.vLiteral('68')),
2929
)
30-
builders.setParents(node.startTag)
30+
setParents(node.startTag, builders)
3131
}
3232

3333
count++

src/plugins/v4/snackbar-queue-slot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CodemodPlugin } from 'vue-metamorph'
2-
import { findSlotNodes } from '../../helpers'
2+
import { findSlotNodes, setParents } from '../../helpers'
33

44
export const v4SnackbarQueueSlotPlugin: CodemodPlugin = {
55
type: 'codemod',
@@ -13,7 +13,7 @@ export const v4SnackbarQueueSlotPlugin: CodemodPlugin = {
1313
if (!node.key.argument) {
1414
node.key.name.rawName = '#'
1515
node.key.argument = builders.vIdentifier('item')
16-
builders.setParents(node.key)
16+
setParents(node.key, builders)
1717
count++
1818
} else if (node.key.argument.type === 'VIdentifier') {
1919
node.key.argument.rawName = 'item'

0 commit comments

Comments
 (0)