Skip to content

Commit 0612a85

Browse files
authored
feat: add popconfirm-rename-event (#98)
1 parent 64cdb2e commit 0612a85

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runTest } from '../../src/testUtils'
2+
3+
runTest(
4+
'popconfirm-rename-event',
5+
'popconfirm-rename-event',
6+
'popconfirm-rename-event',
7+
'vue',
8+
'vue'
9+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<el-popconfirm @onConfirm="del()" @onCancel="del()" :onConfirm="tt" onCancel="tt"
3+
title="Are you sure to delete this?"
4+
>
5+
<template #reference>
6+
<el-button>Delete</el-button>
7+
</template>
8+
</el-popconfirm>
9+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<el-popconfirm @confirm="del()" @cancel="del()" :onConfirm="tt" onCancel="tt"
3+
title="Are you sure to delete this?"
4+
>
5+
<template #reference>
6+
<el-button>Delete</el-button>
7+
</template>
8+
</el-popconfirm>
9+
</template>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Node, VIdentifier } from 'vue-eslint-parser/ast/nodes'
2+
import * as OperationUtil from '../../src/operationUtils'
3+
import type { Operation } from '../../src/operationUtils'
4+
import {
5+
default as wrap,
6+
createTransformAST
7+
} from '../../src/wrapVueTransformation'
8+
9+
export const transformAST = createTransformAST(
10+
nodeFilter,
11+
fix,
12+
'popconfirm-rename-event'
13+
)
14+
export default wrap(transformAST)
15+
16+
const renameMap: Map<string, string> = new Map([
17+
['onconfirm', 'confirm'],
18+
['oncancel', 'cancel']
19+
])
20+
21+
function nodeFilter(node: Node): boolean {
22+
return (
23+
node.type === 'VIdentifier' &&
24+
node.parent?.type === 'VDirectiveKey' &&
25+
node.parent?.name?.type === 'VIdentifier' &&
26+
node.parent?.name?.name === 'on' &&
27+
renameMap.has(node.name) &&
28+
node.parent?.parent?.parent?.parent?.type === 'VElement' &&
29+
node.parent?.parent?.parent?.parent?.name === 'el-popconfirm'
30+
)
31+
}
32+
33+
function fix(node: VIdentifier): Operation[] {
34+
let fixOperations: Operation[] = []
35+
// @ts-ignore
36+
fixOperations.push(OperationUtil.replaceText(node, renameMap.get(node.name)))
37+
return fixOperations
38+
}

vue-transformations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const transformationMap: {
2626
'time-picker-format-attribute': require('./element-ui/time-picker-format-attribute'),
2727
'tooltip-rename-attribute': require('./element-ui/tooltip-rename-attribute'),
2828
'popover-rename-attribute': require('./element-ui/popover-rename-attribute'),
29+
'popconfirm-rename-event': require('./element-ui/popconfirm-rename-event'),
2930
'remove-row-type-flex': require('./element-ui/remove-row-type-flex'),
3031

3132
// manual (must be used at the end of list)

0 commit comments

Comments
 (0)