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 alibaba / rax / packages / jsx-compiler / src / modules / components.js View on Github external
enableScopeSlot = true;
      }
    },
  });

  const dynamicValue = transformTemplate(jsxEl, slotName);
  // Remove dynamicValue that created by params.
  Object.keys(dynamicValue).forEach(key => {
    if (params.hasOwnProperty(key) || /^props\./.test(key))
      delete dynamicValue[key];
  });

  if (enableScopeSlot) {
    // Add scope slot
    jsxEl.openingElement.attributes.push(
      t.jsxAttribute(t.jsxIdentifier('slot-scope'), t.stringLiteral('props')),
    );
  }

  // Add slot attr
  jsxEl.openingElement.attributes.push(
    t.jsxAttribute(t.jsxIdentifier('slot'), t.stringLiteral(slotName)),
  );

  return { dynamicValue, node: jsxEl };
}
github alibaba / rax / packages / jsx-compiler / src / modules / components.js View on Github external
);
                // subComponent default style
                if (subComponent.attributes && subComponent.attributes.style) {
                  node.attributes.push(
                    t.jsxAttribute(
                      t.jsxIdentifier('style'),
                      t.stringLiteral(subComponent.attributes.style),
                    ),
                  );
                }
              } else if (isComponentLibrary) {
                let subComponent = pkg.miniappConfig.subPackages[alias.local].subComponents[property.name];
                const componentTag = subComponent.tagNameMap || `${alias.name}-${object.name}-${property.name}`.toLowerCase().replace(/@|\//g, '_');
                replaceComponentTagName(
                  path,
                  t.jsxIdentifier(componentTag)
                );
                componentsAlias[componentTag] = Object.assign({
                  isSubComponent: true,
                  subComponentName: property.name
                }, alias);
              }
            }
          }
        } else {
          throw new Error(
            `NOT_SUPPORTED: Unsupported type of sub components. ${genExpression(
              node,
            )}`,
          );
        }
      }
github didi / chameleon / packages / chameleon-template-parse / src / parser / parse-ref.js View on Github external
parseRef.tap('wx-vue', (args) => {
  let { path, type, options: { lang } } = args;
  if (lang === 'vue' && (['wx', 'qq', 'baidu', 'alipay'].includes(type))) {
    let parentPath = path.parentPath;
    let attributes = parentPath.node.attributes;
    let idNode = attributes.find((attr) => attr.name.name === 'id');
    let refNode = attributes.find((attr) => (attr.name.name === 'ref' || attr.name.name.name === 'ref'));
    let isDynamicRef = t.isJSXNamespacedName(refNode.name);
    let refNodeValue = isDynamicRef ? `{{${refNode.value.value}}}` : refNode.value.value
    let classNode = attributes.find((attr) => attr.name.name === 'class');
    if (idNode) {

      idNode.value.value = refNodeValue;
    } else {
      attributes.push(t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(refNodeValue)))
    }
    if (!classNode) { // 不存在class节点
      attributes.push(t.jsxAttribute(t.jsxIdentifier('class'), t.stringLiteral('_cml_ref_lmc_')))
    } else {
      classNode.value.value = `${classNode.value.value}  _cml_ref_lmc_`
    }


    path.remove();
  }

})
github alibaba / rax / packages / jsx-compiler / src / modules / jsx-plus.js View on Github external
const filterName = dynamicFilter.add({ expression: containerPath.node.expression });
            containerPath.node.expression.__listItemFilter = {
              item: args[0].name, // item
              filter: filterName // _f0
            };
            filters.push(containerPath.node.expression);
          }
        }
      }
    });
    if (args.length === 3) {
      args.splice(2);
    }
    attributes.push(
      t.jsxAttribute(
        t.jsxIdentifier(adapter.for),
        t.jsxExpressionContainer(iterValue)
      )
    );
    args.forEach((arg, index) => {
      attributes.push(
        t.jsxAttribute(
          t.jsxIdentifier([adapter.forItem, adapter.forIndex][index]),
          t.stringLiteral(arg.name)
        )
      );
      // Mark skip ids.
      const skipIds = node.skipIds = node.skipIds || new Map();
      skipIds.set(arg.name, true);
    });
    if (filters.length) {
      // return {
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / insertComponent.js View on Github external
function insertComponentToElement(element, identifier) {
  // why use upperCamelCase: a react component name must be upperCamelCase
  // https://babeljs.io/docs/en/babel-types#jsxelement
  const newElement = t.jsxElement(
    t.jsxOpeningElement(t.jsxIdentifier(upperCamelCase(identifier)), [], true),
    null,
    [],
    true,
  );
  element.children.push(newElement);
}
github gregberge / svgr / packages / hast-util-to-babel-ast / src / getAttributes.js View on Github external
function getKey(key, value, node) {
  const lowerCaseKey = key.toLowerCase()
  const mappedElementAttribute =
    ELEMENT_ATTRIBUTE_MAPPING[node.name] &&
    ELEMENT_ATTRIBUTE_MAPPING[node.name][lowerCaseKey]
  const mappedAttribute = ATTRIBUTE_MAPPING[lowerCaseKey]

  if (mappedElementAttribute || mappedAttribute) {
    return t.jsxIdentifier(mappedElementAttribute || mappedAttribute)
  }

  const kebabKey = kebabCase(key)

  if (kebabKey.startsWith('aria-')) {
    return t.jsxIdentifier(convertAriaAttribute(kebabKey))
  }

  if (kebabKey.startsWith('data-')) {
    return t.jsxIdentifier(kebabKey)
  }

  return t.jsxIdentifier(key)
}
github areslabs / alita / src / tran / addTempName.js View on Github external
&& (!isJSXChild(path) || isChildCompChild(path))
            ) {
                const jsxOp = path.node.openingElement

                const tempName = `${InnerTemplateNamePrefix}${go.next}`
                jsxOp.attributes.push(t.jsxAttribute(t.jsxIdentifier('tempName'), t.stringLiteral(tempName)))
            }


            if (path.type === 'JSXOpeningElement') {
                const jsxOp = path.node

                const key = `DIUU${go.next}`

                jsxOp.attributes.push(
                    t.jsxAttribute(t.jsxIdentifier('diuu'), t.stringLiteral(key))
                )
            }
        }
    })
github areslabs / alita / src / tran / geneWxml.ts View on Github external
for (let i = 0; i < outComp.length; i++) {
        const name = outComp[i];

        const wxmlFilepath = (name === "render"
                ? relativeJSPath.replace(".js", ".wxml")
                : relativeJSPath.replace(".js", `${name}.wxml`)
        );

        const wxmlAst = [];
        wxmlAst.push(t.jsxText(``))
        wxmlAst.push(t.jsxText("\n"));
        wxmlAst.push(t.jsxText(`<template is="">`))
        let tmpWxmlAst = t.jsxElement(
            t.jsxOpeningElement(
                t.jsxIdentifier("InnerTmpOpeningElement"),
                []
            ),
            t.jsxClosingElement(t.jsxIdentifier("InnerTmpOpeningElement")),
            wxmlAst,
            false
        );

        let WXMLCode = geneReactCode(tmpWxmlAst);
        WXMLCode = WXMLCode.replace("", "");
        WXMLCode = WXMLCode.replace("", "");


        webpackContext.emitFile(
            wxmlFilepath,
            WXMLCode,
        );</template>
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / sdk / flagBabelPlugin / index.ts View on Github external
function buildGUmiUIFlag(opts) {
    const { index, filename, jsx, inline, content } = opts;
    if (jsx) {
      const attrs = [
        t.jsxAttribute(t.jsxIdentifier('filename'), t.stringLiteral(`${filename}`)),
        t.jsxAttribute(t.jsxIdentifier('index'), t.stringLiteral(`${index}`)),
      ];
      if (inline) {
        attrs.push(t.jsxAttribute(t.jsxIdentifier('inline'), t.stringLiteral('true')));
      }
      return t.jsxElement(
        t.jsxOpeningElement(t.jsxIdentifier('GUmiUIFlag'), attrs),
        t.jsxClosingElement(t.jsxIdentifier('GUmiUIFlag')),
        content ? [t.jsxText(content)] : [],
        false,
      );
    } else {
      const attrs = [
        t.objectProperty(t.identifier('filename'), t.stringLiteral(`${filename}`)),
        t.objectProperty(t.identifier('index'), t.stringLiteral(`${index}`)),
      ];
      if (inline) {
        attrs.push(t.objectProperty(t.identifier('inline'), t.stringLiteral('true')));
      }
      return t.callExpression(
        t.memberExpression(t.identifier('React'), t.identifier('createElement')),
        [
          t.identifier('GUmiUIFlag'),
          t.objectExpression(attrs),