How to use the @babel/types.identifier 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 babel / babel / packages / babel-helper-module-transforms / src / rewrite-live-references.js View on Github external
return (exportNames || []).reduce((expr, exportName) => {
    // class Foo {} export { Foo, Foo as Bar };
    // as
    // class Foo {} exports.Foo = exports.Bar = Foo;
    return t.assignmentExpression(
      "=",
      t.memberExpression(
        t.identifier(metadata.exportName),
        t.identifier(exportName),
      ),
      expr,
    );
  }, localExpr);
};
github infernojs / babel-plugin-inferno / lib / index.js View on Github external
return t.callExpression(
        t.identifier(opts.pragmaFragmentVNode || 'createFragment'),
        createFragmentVNodeArgs(
          vChildren,
          childFlags,
          vProps.key,
          defineAll
        )
      );
    }

    // NormalizeProps will normalizeChildren too
    if (vProps.needsNormalization) {
      fileState.set('normalizeProps', true);
      createVNodeCall = t.callExpression(
        t.identifier(opts.pragmaNormalizeProps || 'normalizeProps'),
        [createVNodeCall]
      );
    }

    return createVNodeCall;
  case 'JSXText':
    text = handleWhiteSpace(astNode.value);

    if (text !== '') {
      return t.StringLiteral(text);
    }
    break;
  case 'JSXExpressionContainer':
    var expression = astNode.expression;

    if (expression && expression.type !== 'JSXEmptyExpression') {
github salesforce / lwc / packages / lwc-template-compiler / src / codegen / helpers.ts View on Github external
export function memorizeHandler(codeGen: CodeGen, element,
                                componentHandler: t.Expression, handler: t.Expression): t.Expression {
    // #439 - The handler can only be memorized if it is bound to component instance
    const id = getMemberExpressionRoot(componentHandler as t.MemberExpression);
    const shouldMemorizeHandler = isComponentProp(id, element);

    // Apply memorization if the handler is memorizable.
    //   $cmp.handlePress -> _m1 || ($ctx._m1 = b($cmp.handlePress))
    if (shouldMemorizeHandler) {
        const memorizedId = codeGen.getMemorizationId();
        const memorization = t.assignmentExpression(
            '=',
            t.memberExpression(
                t.identifier(TEMPLATE_PARAMS.CONTEXT),
                memorizedId,
            ),
            handler,
        );

        handler = t.logicalExpression(
            '||',
            memorizedId,
            memorization,
        );
    }
    return handler;
}
github ikatun / nnode / src / type-for-annotation.ts View on Github external
return t.unaryExpression('void', t.numericLiteral(0));
    case 'TSExpressionWithTypeArguments':
      if (annotation.typeParameters) {
        console.warn('Generic type is not supported');
      }
      return t.identifier('Object');
    case 'TSTypeReference':
      const typeName = annotation.typeName;
      const typeNameCopy = JSON.parse(JSON.stringify(typeName));
      const undefinedComparison = t.binaryExpression(
        '===',
        t.unaryExpression('typeof', typeName),
        t.identifier('"undefined"')
      );
      const args = [t.conditionalExpression(undefinedComparison, t.identifier('undefined'), typeNameCopy)];
      return t.callExpression(t.identifier('akessrfljlrgqgd_determineType'), args);
    case 'TSFunctionType':
      return t.identifier('Function');
    case 'TSUnionType':
      return typeForTSType(annotation.types[0]);
    case 'TSLiteralType':
      switch(annotation.literal.type) {
        case 'BooleanLiteral':
          return t.identifier('Boolean');
        case 'NumericLiteral':
          return t.identifier('Number');
        case 'StringLiteral':
          return t.identifier('String');
        default:
          return t.identifier('Object');
      }
    case 'TSArrayType':
github mcuking / vue2react / src / reactVisitor.ts View on Github external
} else if (this.app.script.methods[attr]) {
        methodProperties.push(
          t.objectProperty(t.identifier(attr), t.identifier(attr), false, true)
        );
      } else if (this.app.script.computed[attr]) {
        computed.push(attr);
      }
      return;
    });

    if (dataProperties.length > 0) {
      blocks.push(
        t.variableDeclaration('const', [
          t.variableDeclarator(
            t.objectPattern(dataProperties as any),
            t.memberExpression(t.thisExpression(), t.identifier('state'))
          )
        ])
      );
    }

    if (propProperties.length > 0) {
      blocks.push(
        t.variableDeclaration('const', [
          t.variableDeclarator(
            t.objectPattern(propProperties as any),
            t.memberExpression(t.thisExpression(), t.identifier('props'))
          )
        ])
      );
    }
github facebook / prepack / src / serializer / ResidualOperationSerializer.js View on Github external
_serializeDerivedOperationDescriptor(id: string, babelNode: BabelNodeExpression): BabelNodeStatement {
    return t.variableDeclaration("var", [t.variableDeclarator(t.identifier(id), babelNode)]);
  }
github brigand / babel-plugin-flow-react-proptypes / src / makePropTypesAst.js View on Github external
}
  else if (method === 'arrayOf') {
    node = t.callExpression(
      t.memberExpression(node, t.identifier('arrayOf')),
      [makePropType(data.of)]
    );
  }
  else if (method === 'objectOf') {
    node = t.callExpression(
      t.memberExpression(node, t.identifier('objectOf')),
      [makePropType(data.of)]
    );
  }
  else if (method === 'oneOf') {
    node = t.callExpression(
      t.memberExpression(node, t.identifier('oneOf')),
      [t.arrayExpression(data.options.map(makeLiteral))]
    );
  }
  else if (method === 'oneOfType') {
    node = t.callExpression(
      t.memberExpression(node, t.identifier('oneOfType')),
      [t.arrayExpression(data.options.map(item => makePropType(item)))]
    );
  }
  else if (method === 'reference') {
    const pp = data.propertyPath.slice();
    let valueNode = t.identifier(pp.shift());
    while (pp.length) {
      valueNode = t.memberExpression(valueNode, t.identifier(pp.shift()));
    }
    node = t.callExpression(
github ismail-codar / fidan / packages / babel-plugin-fidan-jsx / build / ast.js View on Github external
const isComputeFn = t.isCallExpression(value) &&
        t.isIdentifier(value.callee) &&
        value.callee.name === "compute";
    const valueExpression = isComputeFn ? value.arguments[0] : value;
    let valueExpressionValue = null;
    if (isComputeFn || isComputeIdentifier) {
        valueExpressionValue = t.callExpression(valueExpression, []);
    }
    else {
        valueExpressionValue = value;
    }
    if (isAttribute) {
        expression = t.callExpression(t.memberExpression(elem, t.identifier("setAttribute")), [t.stringLiteral(name), valueExpressionValue]);
    }
    else {
        expression = t.assignmentExpression("=", t.memberExpression(elem, t.identifier(name)), valueExpressionValue);
    }
    if (!isComputeFn && !isComputeIdentifier) {
        return expression;
    }
    else {
        const args = [
            t.functionExpression(t.identifier(""), [], t.blockStatement([t.expressionStatement(expression)]))
        ];
        if (t.isCallExpression(value) && value.arguments.length > 1) {
            args.push(value.arguments[1]);
        }
        return t.callExpression(t.identifier("compute"), args);
    }
}
exports.computeAttribute1 = computeAttribute1;
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / sdk / flagBabelPlugin / index.ts View on Github external
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),
          ...(content ? [t.stringLiteral(content)] : []),
        ],
      );
    }
  }