How to use the babel-types.jSXIdentifier function in babel-types

To help you get started, we’ve selected a few babel-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tencent / omi / packages / cax-omip / scripts / taro-transformer-wx / lib / src / render.js View on Github external
}
                            }
                        }
                        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')
github NervJS / taro / packages / taro-cli / src / h5 / index.ts View on Github external
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(
github Tencent / omi / packages / cax-omip / scripts / taro-transformer-wx / lib / src / jsx.js View on Github external
function buildBlockElement() {
    return t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('block'), []), t.jSXClosingElement(t.jSXIdentifier('block')), []);
}
exports.buildBlockElement = buildBlockElement;
github dwqs / vue-to-react / src / sfc / directives.js View on Github external
),
                [
                    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
                                )
                            )
                        ])
                    )
                ]
            )
        )
    );
};
github NervJS / taro / packages / taroize / src / wxml.ts View on Github external
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
github NervJS / taro / packages / taro-cli / src / h5 / index.ts View on Github external
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 {
github Tencent / omi / packages / omip / taro-transformer-wx / src / jsx.ts View on Github external
export function buildBlockElement () {
  return t.jSXElement(
    t.jSXOpeningElement(t.jSXIdentifier('block'), []),
    t.jSXClosingElement(t.jSXIdentifier('block')),
    []
  )
}
github trivago / melody / packages / melody-plugin-jsx / src / visitors / mount.js View on Github external
? 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,
                    [],
github NervJS / taro / packages / taro-transformer-wx / src / jsx.ts View on Github external
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)),
    []
  )
}
github zeit / styled-jsx / src / _utils.js View on Github external
)
    )
  ]

  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)]
  )
}