Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expr.operator,
// Can't (and don't need to) break up the syntax of the argument.
// Think about delete a[b].
self.explodeExpression(path.get("argument")),
!!expr.prefix
));
case "BinaryExpression":
return finish(t.binaryExpression(
expr.operator,
explodeViaTempVar(null, path.get("left")),
explodeViaTempVar(null, path.get("right"))
));
case "AssignmentExpression":
return finish(t.assignmentExpression(
expr.operator,
self.explodeExpression(path.get("left")),
self.explodeExpression(path.get("right"))
));
case "UpdateExpression":
return finish(t.updateExpression(
expr.operator,
self.explodeExpression(path.get("argument")),
expr.prefix
));
case "YieldExpression":
after = loc();
let arg = expr.argument && self.explodeExpression(path.get("argument"));
UpdateExpression(node, parent, scope, { formatter }) {
let exported = formatter.getExport(node.argument, scope);
if (!exported) return;
this.skip();
// expand to long file assignment expression
let assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.numberLiteral(1));
// remap this assignment expression
let remapped = formatter.remapExportAssignment(assign, exported);
// we don't need to change the result
if (t.isExpressionStatement(parent) || node.prefix) {
return remapped;
}
let nodes = [];
nodes.push(remapped);
let operator;
if (node.operator === "--") {
operator = "+";
} else { // "++"
function toCJSModule(name, component, children, delimiter) {
var modules = [getCJSImportDeclaration("React", "react")].concat(
children.map(function(child) {
return getCJSImportDeclaration(
child,
"./" + toFileName(delimiter, child)
);
})
);
return t.program(
modules.concat([
component,
t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(t.identifier("module"), t.identifier("exports")),
t.identifier(name)
)
)
])
);
}
function fakeModule(path: NodePath) {
const isStop = t.identifier("$isStop");
const onStop = t.identifier("$onStop");
const onDone = t.identifier("$onDone");
const opts = t.identifier("$opts");
path.node.body.push(t.returnStatement(t.callExpression(onDone, [])));
path.node.body = [t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(t.identifier('module'), t.identifier('exports')),
t.functionExpression(
void 0,
[isStop, onStop, onDone, opts],
t.blockStatement(path.node.body))))];
}
const visitor: Visitor = {
}
classBody.push(t.classProperty(t.identifier(anonymousFuncName + 'Array'), t.arrayExpression([])));
const arrayFunc = t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Array')), t.identifier(index.name), true);
classBody.push(t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(index.name), t.identifier('e')], t.blockStatement([
isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(),
t.expressionStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')])))
])));
exprPath.replaceWith(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), t.identifier('bind')), [t.thisExpression(), t.identifier(index.name)]));
stemParent.insertBefore(t.expressionStatement(t.assignmentExpression('=', arrayFunc, expr)));
}
else {
classBody.push(t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier('e')], t.blockStatement([
isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement()
])));
exprPath.replaceWith(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)));
stemParent.insertBefore(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), expr)));
}
}
else {
throw utils_1.codeFrameError(path.node, '组件事件传参只能在使用匿名箭头函数,或使用类作用域下的确切引用(this.handleXX || this.props.handleXX),或使用 bind。');
}
}
const jsx = path.findParent(p => p.isJSXOpeningElement());
if (!jsx)
return;
const jsxName = jsx.node.name;
if (!t.isJSXIdentifier(jsxName))
return;
if (expression.isJSXElement())
return;
if (constant_1.DEFAULT_Component_SET.has(jsxName.name) || expression.isIdentifier() || expression.isMemberExpression() || expression.isLiteral() || expression.isLogicalExpression() || expression.isConditionalExpression() || key.name.startsWith('on') || expression.isCallExpression())
return;
const loopCallExpr = path.findParent(p => utils_1.isArrayMapCallExpression(p));
let index;
if (loopCallExpr) {
index = lodash_1.get(loopCallExpr, 'node.arguments[0].params[1]');
if (!t.isIdentifier(index)) {
index = t.identifier('__index' + counter);
lodash_1.set(loopCallExpr, 'node.arguments[0].params[1]', index);
}
classBody.push(t.classProperty(t.identifier(anonymousFuncName + 'Array'), t.arrayExpression([])));
const arrayFunc = t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Array')), t.identifier(index.name), true);
classBody.push(t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(index.name), t.identifier('e')], t.blockStatement([
isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(),
t.expressionStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')])))
])));
exprPath.replaceWith(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), t.identifier('bind')), [t.thisExpression(), t.identifier(index.name)]));
stemParent.insertBefore(t.expressionStatement(t.assignmentExpression('=', arrayFunc, expr)));
}
else {
classBody.push(t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier('e')], t.blockStatement([
isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement()
])));
exprPath.replaceWith(t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)));
stemParent.insertBefore(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)), expr)));
}
}
else {
throw utils_1.codeFrameError(path.node, '组件事件传参只能在使用匿名箭头函数,或使用类作用域下的确切引用(this.handleXX || this.props.handleXX),或使用 bind。');
}
}
const jsx = path.findParent(p => p.isJSXOpeningElement());
if (!jsx)
return;
let keyIterNextFn = self.makeTempVar();
self.emitAssign(
keyIterNextFn,
t.callExpression(
util.runtimeProperty("keys"),
[self.explodeExpression(path.get("right"))]
)
);
self.mark(head);
let keyInfoTmpVar = self.makeTempVar();
self.jumpIf(
t.memberExpression(
t.assignmentExpression(
"=",
keyInfoTmpVar,
t.callExpression(keyIterNextFn, [])
),
t.identifier("done"),
false
),
after
);
self.emitAssign(
stmt.left,
t.memberExpression(
keyInfoTmpVar,
t.identifier("value"),
false
const assignArgument = (identifier, argument, opts) => {
if (opts.blockDepth === 1) {
return t.variableDeclaration(
'let',
[
t.variableDeclarator(
t.identifier('_babel_temp_alias'),
argument
)
]
);
} else {
return t.expressionStatement(
t.assignmentExpression(
"=",
t.identifier('_babel_temp_alias'),
argument
)
);
}
}
ObjectExpression(node, parent, scope, file) {
var objectRef;
var getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj");
var propPaths = this.get("properties");
for (var i = 0; i < node.properties.length; i++) {
Property(propPaths[i], node.properties[i], scope, getObjectRef, file);
}
if (objectRef) {
scope.push({ id: objectRef });
return t.assignmentExpression("=", objectRef, node);
}
}
};