Skip to content

Commit f5502fd

Browse files
authored
feat: implements element-ui format attribute in the picker-option move to top-level (#87)
1 parent 5ced27c commit f5502fd

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-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+
'tine-picker-format-attribute',
5+
'time-picker-format-attribute',
6+
'time-picker-format-attribute',
7+
'vue',
8+
'vue'
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<el-time-picker
3+
:picker-options="{
4+
selectableRange: '18:30:00 - 20:30:00',
5+
format:'HH:mm:ss'
6+
}"
7+
placeholder='任意时间点'>
8+
</el-time-picker>
9+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<el-time-picker
3+
format='HH:mm:ss' :picker-options="{
4+
selectableRange: '18:30:00 - 20:30:00',
5+
format:'HH:mm:ss'
6+
}"
7+
placeholder='任意时间点'>
8+
</el-time-picker>
9+
</template>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Node, VAttribute } 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+
'time-picker-format-attribute'
13+
)
14+
export default wrap(transformAST)
15+
16+
function nodeFilter(node: Node): boolean {
17+
const pre = (item: VAttribute) =>
18+
// @ts-ignore
19+
item.key.name === 'bind' && item.key.argument?.name === 'format'
20+
return (
21+
node.type === 'VAttribute' &&
22+
node.key.type === 'VDirectiveKey' &&
23+
node.key.name.name === 'bind' &&
24+
// @ts-ignore
25+
node.key.argument.name === 'picker-options' &&
26+
node.value?.type === 'VExpressionContainer' &&
27+
node.value.expression?.type === 'ObjectExpression' &&
28+
// @ts-ignore
29+
node.value.expression.properties.filter(item => item.key.name === 'format')
30+
.length > 0 &&
31+
node.parent.parent.type === 'VElement' &&
32+
node.parent.parent.name === 'el-time-picker' &&
33+
node.parent.attributes.filter(pre).length === 0
34+
)
35+
}
36+
37+
function fix(node: VAttribute): Operation[] {
38+
let fixOperations: Operation[] = []
39+
// get format attribute in the time-picker
40+
// @ts-ignore
41+
let formatValue = node.value.expression.properties.filter(
42+
// @ts-ignore
43+
item => item.key.name === 'format'
44+
)[0].value.value
45+
// add format attribute to el-time-picker tag
46+
fixOperations.push(
47+
OperationUtil.insertTextBefore(node, `format='${formatValue}' `)
48+
)
49+
return fixOperations
50+
}

vue-transformations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const transformationMap: {
2121
'router-link-event-tag': require('./router-link-event-tag'),
2222
'router-link-exact': require('./router-link-exact'),
2323
'router-view-keep-alive-transition': require('./router-view-keep-alive-transition'),
24+
'time-picker-format-attribute':require('./element-ui/time-picker-format-attribute'),
2425

2526
// manual (must be used at the end of list)
2627
'manual-remove-keycode': require('./manual/manual-remove-keycode')

0 commit comments

Comments
 (0)