Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
if (name.name.startsWith('on')) {
if (exprPath.isReferencedIdentifier()) {
const ids = [expr.name]
const fullPath = buildFullPathThisPropsRef(expr, ids, path)
if (fullPath) {
exprPath.replaceWith(fullPath)
}
}
if (exprPath.isReferencedMemberExpression()) {
const id = findFirstIdentifierFromMemberExpression(expr)
const ids = getIdsFromMemberProps(expr)
if (t.isIdentifier(id)) {
const fullPath = buildFullPathThisPropsRef(id, ids, path)
if (fullPath) {
exprPath.replaceWith(fullPath)
}
}
}
// @TODO: bind 的处理待定
}
},
ImportDeclaration (path) {
caller.getStatementParent().insertBefore(utils_1.buildConstVariableDeclaration(variableName, ary));
ary = t.identifier(variableName);
}
jsx_1.setJSXAttr(jsxElementPath.node, adapter_1.Adapter.for, t.jSXExpressionContainer(ary));
const [func] = caller.node.arguments;
if (t.isFunctionExpression(func) ||
t.isArrowFunctionExpression(func)) {
const [item, index] = func.params;
if (t.isIdentifier(item)) {
jsx_1.setJSXAttr(jsxElementPath.node, adapter_1.Adapter.forItem, t.stringLiteral(item.name));
loopScopes.add(item.name);
}
else {
jsx_1.setJSXAttr(jsxElementPath.node, adapter_1.Adapter.forItem, t.stringLiteral('__item'));
}
if (t.isIdentifier(index)) {
jsx_1.setJSXAttr(jsxElementPath.node, adapter_1.Adapter.forIndex, t.stringLiteral(index.name));
loopScopes.add(index.name);
}
caller.replaceWith(jsxElementPath.node);
if (statementParent) {
const name = utils_1.findIdentifierFromStatement(statementParent.node);
// setTemplate(name, path, templates)
name && templates.set(name, jsxElementPath.node);
}
}
}
}
}
else {
const ifStatement = parentPath.findParent(p => p.isIfStatement());
const blockStatement = parentPath.findParent(p => p.isBlockStatement());
utils_1.newJSXIfAttr(block, test);
jsx_1.setJSXAttr(block2, adapter_1.Adapter.else);
block2.children = [t.jSXExpressionContainer(alternate)];
const parentBlock = jsx_1.buildBlockElement();
parentBlock.children = [block, block2];
parentPath.replaceWith(parentBlock);
}
if (statementParent) {
const name = utils_1.findIdentifierFromStatement(statementParent.node);
utils_1.setTemplate(name, jsxElementPath, this.templates);
// name && templates.set(name, path.node)
}
}
else if (this.isLiteralOrUndefined(consequent) && t.isJSXElement(alternate)) {
const { value, confident } = parentPath.get('consequent').evaluate();
if (confident && !value || t.isIdentifier({ name: 'undefined' })) {
utils_1.newJSXIfAttr(block, utils_1.reverseBoolean(test));
block.children = [jsxElementPath.node];
// newJSXIfAttr(jsxElementPath.node, test)
parentPath.replaceWith(block);
}
else {
const block2 = jsx_1.buildBlockElement();
block.children = [t.jSXExpressionContainer(consequent)];
utils_1.newJSXIfAttr(block, test);
jsx_1.setJSXAttr(block2, adapter_1.Adapter.else);
block2.children = [alternate];
const parentBlock = jsx_1.buildBlockElement();
parentBlock.children = [block, block2];
parentPath.replaceWith(parentBlock);
}
if (statementParent) {
const serializeNode = (path, node, theme) => {
if (t.isIdentifier(node)) {
const refNode = resolveRef(path, node)
if (refNode.name !== 'undefined') return serializeNode(path, refNode, theme)
return null
}
if (t.isStringLiteral(node) || t.isNumericLiteral(node)) {
return node.value
}
// injectSheet({a: {}})
if (t.isObjectExpression(node)) {
return node.properties.reduce((serialized, property) => {
const value = serializeNode(path, property.value, theme)
if (value !== null) {
const key = getPropertyName(path, property)
serialized[key] = value
checkExportIdentifier(node) {
if (t.isIdentifier(node, { name: "__esModule" })) {
throw this.file.buildCodeFrameError(node, messages.get("modulesIllegalExportName", node.name));
}
}
function isUndefined(node) {
return t.isIdentifier(node) && node.name === 'undefined';
}
function isModuleDotExports(node) {
return (
t.isMemberExpression(node, {computed: false}) &&
t.isIdentifier(node.object, {name: 'module'}) &&
t.isIdentifier(node.property, {name: 'exports'})
);
}
function isRequire(node, filename) {
_getNodeName(node) {
if (types.isFunctionDeclaration(node) || types.isClassDeclaration(node)) {
return node.id && node.id.name;
}
if (types.isIdentifier(node)) {
return node.name;
}
if (types.isCallExpression(node)) {
return node.arguments[0];
}
if (types.isVariableDeclaration(node)) {
try {
return node.declarations[0].id.name;
} catch (e) {
return '';
}
}
return '';
hasStateId = id.node.properties.some(p => {
return (t.isObjectProperty(p) && t.isIdentifier(p.key, { name: word }))
|| (t.isRestProperty(p) && t.isIdentifier(p.argument, { name: word }));
});
}
}
});
const originalProp = t.objectProperty(t.identifier(constant_1.LOOP_ORIGINAL), t.memberExpression(t.identifier(item.name), t.identifier(constant_1.LOOP_ORIGINAL)));
properties.push(originalProp);
body.unshift(t.expressionStatement(t.assignmentExpression('=', t.identifier(item.name), t.objectExpression([
t.objectProperty(t.identifier(constant_1.LOOP_ORIGINAL), t.callExpression(t.identifier(constant_1.INTERNAL_GET_ORIGNAL), [t.identifier(item.name)]))
]))));
const returnStatement = t.returnStatement(properties.length ? t.objectExpression(properties) : item);
const parentCallee = callee.findParent(c => utils_1.isArrayMapCallExpression(c));
if (utils_1.isArrayMapCallExpression(parentCallee)) {
const [func] = parentCallee.node.arguments;
const { object } = callee.node.callee;
if (t.isFunctionExpression(func) || t.isArrowFunctionExpression(func)) {
const funcBody = func.body;
if (t.isBlockStatement(funcBody)) {
if (t.isIdentifier(object) || t.isMemberExpression(object)) {
const variableName = `${constant_1.LOOP_CALLEE}_${this.incrementCalleeId()}`;
funcBody.body.splice(funcBody.body.length - 1, 0, utils_1.buildConstVariableDeclaration(variableName, utils_1.setParentCondition(component, callee.node, true)));
const iterator = func.params[0];
component.node.openingElement.attributes.forEach(attr => {
if (attr.name.name === adapter_1.Adapter.for && t.isIdentifier(iterator)) {
attr.value = t.jSXExpressionContainer(t.memberExpression(iterator, t.identifier(variableName)));
}
});
}
else {
throw utils_1.codeFrameError(object.loc, '多层循环中循环的数组只能是一个变量或成员表达式');
}
}
}
body.push(returnStatement);
}