-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstring-actions.js
53 lines (50 loc) · 1.6 KB
/
string-actions.js
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
const stringActions = require('../string-actions');
const { parse, transform } = require('ember-template-recast');
function codeshift(input, plugin) {
return plugin(
{
path: 'filename.hbs',
source: input,
},
{
parse,
visit(ast, callback) {
const results = transform(ast, callback);
return results && results.code;
},
}
);
}
const TESTS = [
[
'action "foo"',
`<button {{on "click" (prevent-default (action "foo"))}}>button</button>`,
`<button {{on "click" (prevent-default this.foo)}}>button</button>`
],
[
'value=',
`<button {{on "click" (prevent-default (action "bar" value="target.value"))}}>button</button>`,
`<button {{on "click" (prevent-default (action this.bar value="target.value"))}}>button</button>`
],
[
'target=',
`<button {{on "click" (prevent-default (action "foo" target=something))}}>button</button>`,
`<button {{on "click" (prevent-default (action this.foo target=something))}}>button</button>`
],
[
'allowedKeys=',
`<button {{on "click" (prevent-default (action "foo" allowedKeys="alt"))}}>button</button>`,
`<button {{on "click" (prevent-default (action this.foo allowedKeys="alt"))}}>button</button>`
],
[
'no-op on actions with multiple params',
`<button {{on "click" (action "foo" bar)}}>button</button>`,
`<button {{on "click" (action "foo" bar)}}>button</button>`
]
];
TESTS.forEach(([name, input, expectedOutput]) => {
it(name, () => {
const output = codeshift(input, stringActions);
expect((output || '').trim()).toEqual(expectedOutput.trim());
});
});