提交 d03d2a1e 编写于 作者: K kevinluohuan

运行组件和通用标签上绑定通用事件

上级 94923b16
#!/usr/bin/env node #!/usr/bin/env node
// --inspect-brk
const program = require('commander'); const program = require('commander');
const packageJson = require('../package.json'); const packageJson = require('../package.json');
const main = require('../index'); const main = require('../index');
......
const jsAstParser = require('./lib/js-ast-parser'); const jsAstParser = require('./lib/js-ast-parser');
const templateAstParser = require('./lib/template-ast-parser'); const templateAstParser = require('./lib/template-ast-parser');
const jsonAstParser = require('./lib/json-ast-parser'); const jsonAstParser = require('./lib/json-ast-parser');
const commonEvents = require('../../config/common-events.json');
class TemplateChecker { class TemplateChecker {
...@@ -49,10 +49,17 @@ class TemplateChecker { ...@@ -49,10 +49,17 @@ class TemplateChecker {
if (usingComponents[compName] && usingComponents[compName].isCml) { if (usingComponents[compName] && usingComponents[compName].isCml) {
let { props, events } = component[compName]; let { props, events } = component[compName];
let { props: usingProps, events: usingEvents } = usingComponents[compName]; let { props: usingProps, events: usingEvents } = usingComponents[compName];
usingProps = usingProps.map((prop) => prop.name).join('|'); usingProps = usingProps
usingEvents = usingEvents.map((event) => event.name).join('|'); .map((prop) => prop.name)
.join('|');
props.filter((prop) => usingProps.indexOf(prop.name) === -1).forEach((prop) => { usingEvents = usingEvents
.map((event) => event.name)
.concat(commonEvents.events)
.join('|');
usingProps = `|${usingProps}|`;
usingEvents = `|${usingEvents}|`;
debugger
props.filter((prop) => usingProps.indexOf('|' + prop.name + '|') === -1).forEach((prop) => {
issues.push({ issues.push({
line: prop.pos[0], line: prop.pos[0],
column: prop.pos[1], column: prop.pos[1],
...@@ -61,7 +68,7 @@ class TemplateChecker { ...@@ -61,7 +68,7 @@ class TemplateChecker {
}); });
}); });
events.filter((event) => usingEvents.indexOf(event.name) === -1).forEach((event) => { events.filter((event) => usingEvents.indexOf('|' + event.name + '|') === -1).forEach((event) => {
issues.push({ issues.push({
line: event.pos[0], line: event.pos[0],
column: event.pos[1], column: event.pos[1],
......
{
"events": ["tap", "click", "touchstart", "touchmove", "touchend"]
}
\ No newline at end of file
const commonEvents = ['tap', 'touchstart', 'touchmove', 'touchend']; const commonEvents = ['tap', 'click', 'touchstart', 'touchmove', 'touchend'];
module.exports.isCommonEvent = function(eventName) { module.exports.isCommonEvent = function(eventName) {
return ~commonEvents.indexOf(eventName); return ~commonEvents.indexOf(eventName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册