智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/81/8176f09b64406bbea2547cd2b53...

47 lines
1.1 KiB

const t = require('@babel/types')
const babelTraverse = require('@babel/traverse').default
const {
INTERNAL_SET_MODEL
} = require('../../../constants')
module.exports = {
getModelEventFunctionExpr (funcExpr, propPath, modifiers = []) {
let targetExpr
let keyExpr
babelTraverse(funcExpr, {
noScope: true,
CallExpression (path) {
if (path.node.callee.name === '$set') {
targetExpr = path.node.arguments[0]
keyExpr = path.node.arguments[1]
}
}
})
if (!targetExpr || !keyExpr) {
targetExpr = t.stringLiteral('')
keyExpr = t.stringLiteral(propPath)
}
return t.functionExpression(
null,
[t.identifier('$event')],
t.blockStatement(
[
t.returnStatement(
t.callExpression(
t.identifier(INTERNAL_SET_MODEL),
[
targetExpr,
keyExpr,
t.identifier('$event'),
t.arrayExpression(modifiers)
]
)
)
]
)
)
}
}