Skip to content

Commit 7cc5f38

Browse files
committed
Implement event handler method skipping
1 parent c177ad9 commit 7cc5f38

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

lib/index.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,44 @@ const globby = require('globby');
55
const j = require('jscodeshift').withParser('ts');
66
const debug = require('debug')('tagless-ember-components-codemod');
77

8+
const EVENT_HANDLER_METHODS = [
9+
// Touch events
10+
'touchStart',
11+
'touchMove',
12+
'touchEnd',
13+
'touchCancel',
14+
15+
// Keyboard events
16+
'keyDown',
17+
'keyUp',
18+
'keyPress',
19+
20+
// Mouse events
21+
'mouseDown',
22+
'mouseUp',
23+
'contextMenu',
24+
'click',
25+
'doubleClick',
26+
'focusIn',
27+
'focusOut',
28+
29+
// Form events
30+
'submit',
31+
'change',
32+
'focusIn',
33+
'focusOut',
34+
'input',
35+
36+
// Drag and drop events
37+
'dragStart',
38+
'drag',
39+
'dragEnter',
40+
'dragLeave',
41+
'dragOver',
42+
'dragEnd',
43+
'drop',
44+
];
45+
846
async function run() {
947
let path = await pkgDir();
1048
await runForPath(path);
@@ -107,7 +145,23 @@ async function runForPath(path, options = {}) {
107145
continue;
108146
}
109147

110-
// TODO skip components that use `click()` etc. (warn)
148+
// skip components that use `click()` etc.
149+
for (let methodName of EVENT_HANDLER_METHODS) {
150+
let handlerMethod = properties.filter(
151+
({ value: node }) =>
152+
node.type === 'ObjectMethod' &&
153+
node.key.type === 'Identifier' &&
154+
node.key.name === methodName
155+
)[0];
156+
if (handlerMethod) {
157+
console.log(
158+
chalk.yellow(
159+
`${dimPath}: Using \`${methodName}()\` is not supported in tagless components`
160+
)
161+
);
162+
continue;
163+
}
164+
}
111165

112166
// TODO analyze `tagName`, `attributeBindings`, `classNames`, ...
113167
// TODO skip on error (warn incl. please report)

0 commit comments

Comments
 (0)