-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.spec.ts
127 lines (113 loc) · 3.22 KB
/
set.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { it, expect } from 'vitest';
import { transform, findManualMigrations } from 'vue-metamorph';
import { vueSetPlugin, vueSetManualPlugin } from './set';
it('should replace Vue.set and whatever.$set', () => {
const input = `
// with computed key
Vue.set(target, key, value);
// with regular key
Vue.set(target, 'key', value);
// with computed $set
something.$set(target, key, value);
// with regular $set
something.$set(target, 'key', value);
// edge case
Vue.set(a || b, 'c-d-e', d);
Vue.set(a || b, 'foo-bar-baz', value);
`;
expect(transform(input, 'file.js', [vueSetPlugin]).code).toMatchInlineSnapshot(`
"// with computed key
target[key] = value;
// with regular key
target.key = value;
// with computed $set
target[key] = value;
// with regular $set
target.key = value;
// edge case
(a || b)['c-d-e'] = d;
(a || b)['foo-bar-baz'] = value;
"
`);
});
it('should report when it cannot migrate', () => {
const input = `
// with computed key
Vue.set(target, key);
// with regular key
Vue.set(target, 'key');
// with computed $set
something.$set(target, key);
// with regular $set
something.$set(target, 'key');
`;
expect(findManualMigrations(input, 'file.js', [vueSetManualPlugin])).toMatchInlineSnapshot(`
[
{
"columnEnd": 20,
"columnStart": 1,
"file": "file.js",
"lineEnd": 3,
"lineStart": 3,
"message": "Cannot automatically migrate this code - the call expression must have 3 arguments",
"pluginName": "vue-set-manual",
"snippet": "1 |
2 | // with computed key
3 | Vue.set(target, key);
| ^^^^^^^^^^^^^^^^^^^^
4 |
5 | // with regular key
6 | Vue.set(target, 'key');",
},
{
"columnEnd": 22,
"columnStart": 1,
"file": "file.js",
"lineEnd": 6,
"lineStart": 6,
"message": "Cannot automatically migrate this code - the call expression must have 3 arguments",
"pluginName": "vue-set-manual",
"snippet": "3 | Vue.set(target, key);
4 |
5 | // with regular key
6 | Vue.set(target, 'key');
| ^^^^^^^^^^^^^^^^^^^^^^
7 |
8 | // with computed $set
9 | something.$set(target, key);",
},
{
"columnEnd": 27,
"columnStart": 1,
"file": "file.js",
"lineEnd": 9,
"lineStart": 9,
"message": "Cannot automatically migrate this code - the call expression must have 3 arguments",
"pluginName": "vue-set-manual",
"snippet": " 6 | Vue.set(target, 'key');
7 |
8 | // with computed $set
9 | something.$set(target, key);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 |
11 | // with regular $set
12 | something.$set(target, 'key');",
},
{
"columnEnd": 29,
"columnStart": 1,
"file": "file.js",
"lineEnd": 12,
"lineStart": 12,
"message": "Cannot automatically migrate this code - the call expression must have 3 arguments",
"pluginName": "vue-set-manual",
"snippet": " 9 | something.$set(target, key);
10 |
11 | // with regular $set
12 | something.$set(target, 'key');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 | ",
},
]
`);
});