How to use the babel-types.isIdentifier 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 / omip / taro-transformer-wx / src / index.ts View on Github external
}
      }

      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) {
github Tencent / omi / packages / mps-ts / _scripts / jsx2wxml / loop-component.js View on Github external
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());
github Tencent / omi / packages / cax-omip / scripts / taro-transformer-wx / lib / src / render.js View on Github external
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) {
github cssinjs / jss / packages / babel-plugin / src / utils / serializeNode.js View on Github external
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
github babel / babel / packages / babel-core / src / transformation / modules / _default.js View on Github external
checkExportIdentifier(node) {
    if (t.isIdentifier(node, { name: "__esModule" })) {
      throw this.file.buildCodeFrameError(node, messages.get("modulesIllegalExportName", node.name));
    }
  }
github vitalets / babel-plugin-runtyper / src / binary / equal.js View on Github external
function isUndefined(node) {
  return t.isIdentifier(node) && node.name === 'undefined';
}
github bfrgoncalves / Online-PhyloViZ / node_modules / l / node_modules / jsdom / node_modules / cssstyle / scripts / generate_properties.js View on Github external
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) {
github alibaba / ice / tools / props-schema-generator / lib / findDef.js View on Github external
_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 '';
github Tencent / omi / packages / omip / my-app / scripts / taro-transformer-wx / lib / src / render.js View on Github external
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 }));
                    });
                }
github Tencent / omi / packages / cax-omip / scripts / taro-transformer-wx / lib / src / render.js View on Github external
}
                        });
                        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);
                        }