Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
}
if (t.isJSXIdentifier(jsxElementPath.node.openingElement.name)) {
const componentName = jsxElementPath.node.openingElement.name.name;
if (adapter_1.Adapter.type === "alipay" /* alipay */) {
let transformName = name.name;
if (constant_1.DEFAULT_Component_SET.has(componentName) && constant_1.ALIPAY_BUBBLE_EVENTS.has(name.name)) {
if (name.name === 'onClick') {
transformName = eventShouldBeCatched ? 'catchTap' : 'onTap';
}
else {
transformName = `${eventShouldBeCatched ? 'catch' : 'on'}${name.name.slice(2)}`;
}
}
path.node.name = t.jSXIdentifier(transformName);
}
else if (constant_1.DEFAULT_Component_SET.has(componentName)) {
let transformName = `${eventShouldBeCatched ? 'catch' : 'bind'}`
+ name.name.slice(2).toLowerCase();
if (name.name === 'onClick') {
transformName = eventShouldBeCatched ? 'catchtap' : 'bindtap';
}
path.node.name = t.jSXIdentifier(transformName);
}
else if (constant_1.THIRD_PARTY_COMPONENTS.has(componentName)) {
path.node.name = t.jSXIdentifier('bind' + name.name[2].toLowerCase() + name.name.slice(3));
}
else {
//@fix
let n = name.name.toLowerCase();
if (n === 'onclick')
exit (astPath: NodePath) {
const node = astPath.node
const tagName = toVar(node.name)
const componentName = componentnameMap.get(tagName)
const componentId = getComponentId(componentName, node)
const componentRef = getComponentRef(node)
if (tagName === BLOCK_TAG_NAME) {
node.name = t.jSXMemberExpression(
t.jSXIdentifier('Nerv'),
t.jSXIdentifier('Fragment')
)
}
if (!componentId) return
const refFunc = createRefFunc(componentId)
if (componentRef) {
const expression = (componentRef.value as t.JSXExpressionContainer).expression;
(refFunc.body as t.BlockStatement).body.unshift(
t.expressionStatement(
t.callExpression(expression, [t.identifier('ref')])
)
);
(componentRef.value as t.JSXExpressionContainer).expression = refFunc
} else {
node.attributes.push(
function buildBlockElement() {
return t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('block'), []), t.jSXClosingElement(t.jSXIdentifier('block')), []);
}
exports.buildBlockElement = buildBlockElement;
),
[
t.arrowFunctionExpression(
newParams,
t.blockStatement([
t.returnStatement(
t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(element), [
t.jSXAttribute(
t.jSXIdentifier('key'),
t.jSXExpressionContainer(
t.identifier('index')
)
)
]),
t.jSXClosingElement(t.jSXIdentifier(element)),
childs
)
)
])
)
]
)
)
);
};
const slotAttr = attrs.find(a => a.node.name.name === 'slot')
if (slotAttr) {
const slotValue = slotAttr.node.value
if (slotValue && t.isStringLiteral(slotValue)) {
const slotName = slotValue.value
const parentComponent = path.findParent(p => p.isJSXElement() && t.isJSXIdentifier(p.node.openingElement.name) && !DEFAULT_Component_SET.has(p.node.openingElement.name.name))
if (parentComponent && parentComponent.isJSXElement()) {
slotAttr.remove()
path.traverse({
JSXAttribute: jsxAttrVisitor
})
const block = buildBlockElement()
block.children = [cloneDeep(path.node)]
parentComponent.node.openingElement.attributes.push(
t.jSXAttribute(
t.jSXIdentifier(buildSlotName(slotName)),
t.jSXExpressionContainer(block)
)
)
path.remove()
}
} else {
throw codeFrameError(slotValue, 'slot 的值必须是一个字符串')
}
}
const tagName = jsxName.node.name
if (tagName === 'Slot') {
const nameAttr = attrs.find(a => a.node.name.name === 'name')
let slotName = ''
if (nameAttr) {
if (nameAttr.node.value && t.isStringLiteral(nameAttr.node.value)) {
slotName = nameAttr.node.value.value
exit (astPath: NodePath) {
const node = astPath.node
const tagName = toVar(node.name)
const componentName = componentnameMap.get(tagName)
const componentId = getComponentId(componentName, node)
const componentRef = getComponentRef(node)
if (tagName === BLOCK_TAG_NAME) {
node.name = t.jSXMemberExpression(
t.jSXIdentifier('Nerv'),
t.jSXIdentifier('Fragment')
)
}
if (!componentId) return
const refFunc = createRefFunc(componentId)
if (componentRef) {
const expression = (componentRef.value as t.JSXExpressionContainer).expression;
(refFunc.body as t.BlockStatement).body.unshift(
t.expressionStatement(
t.callExpression(expression, [t.identifier('ref')])
)
);
(componentRef.value as t.JSXExpressionContainer).expression = refFunc
} else {
export function buildBlockElement () {
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('block'), []),
t.jSXClosingElement(t.jSXIdentifier('block')),
[]
)
}
? key.name
: key.value
),
t.jSXExpressionContainer(value)
);
}
);
} else {
properties = [t.jSXSpreadAttribute(attributes)];
}
}
if (path.node.key) {
properties.push(
t.jSXAttribute(
t.jSXIdentifier('key'),
t.jSXExpressionContainer(path.node.key)
)
);
}
let identifier = componentName;
if (is(identifier, 'MemberExpression')) {
identifier = toJSXMemberExpression(identifier);
} else {
identifier = t.jSXIdentifier(identifier.name);
}
const jsxElement = t.jSXElement(
t.jSXOpeningElement(identifier, properties, true),
null,
[],
export function buildBlockElement (attrs: t.JSXAttribute[] = [], isView = false) {
let blockName = Adapter.type === Adapters.quickapp ? 'div' : 'block'
if (isView) {
blockName = 'View'
}
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(blockName), attrs),
t.jSXClosingElement(t.jSXIdentifier(blockName)),
[]
)
}
)
)
]
if (expressions.length > 0) {
attributes.push(
t.jSXAttribute(
t.jSXIdentifier(STYLE_COMPONENT_DYNAMIC),
t.jSXExpressionContainer(t.arrayExpression(expressions))
)
)
}
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(STYLE_COMPONENT), attributes),
t.jSXClosingElement(t.jSXIdentifier(STYLE_COMPONENT)),
[t.jSXExpressionContainer(css)]
)
}