How to use the @babel/types.expressionStatement 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 facebook / prepack / src / serializer / ResidualReactElementSerializer.js View on Github external
this._emitHoistedReactElement(
            value,
            id,
            reactElementAstNode,
            hoistedCreateElementIdentifier,
            originalCreateElementIdentifier
          );
        } else {
          // Note: it can be expected that we assign to the same variable multiple times
          // this is due to fact ReactElements are immutable objects and the fact that
          // when we inline/fold logic, the same ReactElements are referenced at different
          // points with different attributes. Given we can't mutate an immutable object,
          // we instead create new objects and assign to the same binding
          if (reactElement.declared) {
            this.residualHeapSerializer.emitter.emit(
              t.expressionStatement(t.assignmentExpression("=", id, reactElementAstNode))
            );
          } else {
            reactElement.declared = true;
            this.residualHeapSerializer.emitter.emit(
              t.variableDeclaration("var", [t.variableDeclarator(id, reactElementAstNode)])
            );
          }
        }
      },
      this.residualHeapSerializer.emitter.getBody()
github facebook / prepack / src / serializer / ResidualFunctionInitializers.js View on Github external
// First, let's see if one of the initialized values is guaranteed to not
    // be undefined after initialization. In that case, we can use that state-change
    // to figure out if initialization needs to run.
    let location;
    for (let value of initializedValues) {
      // function declarations get hoisted, so let's not use their initialization state as a marker
      if (!value.mightBeUndefined() && !(value instanceof FunctionValue)) {
        location = this.locationService.getLocation(value);
        if (location !== undefined) break;
      }
    }
    if (location === undefined) {
      // Second, if we didn't find a non-undefined value, let's make one up.
      // It will transition from `undefined` to `null`.
      location = this.locationService.createLocation(containingAdditionalFunction);
      initializationStatements.unshift(t.expressionStatement(t.assignmentExpression("=", location, nullExpression)));
    }
    return t.ifStatement(
      t.binaryExpression("===", location, voidExpression),
      t.blockStatement(initializationStatements)
    );
  }
github babel / babel / packages / babel-helper-remap-async-to-generator / src / for-await.js View on Github external
export default function(path, { getAsyncIterator, wrapAwait }) {
  const { node, scope, parent } = path;

  const stepKey = scope.generateUidIdentifier("step");
  const stepValue = scope.generateUidIdentifier("value");
  const left = node.left;
  let declar;

  if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
    // for await (i of test), for await ({ i } of test)
    declar = t.expressionStatement(
      t.assignmentExpression("=", left, stepValue),
    );
  } else if (t.isVariableDeclaration(left)) {
    // for await (let i of test)
    declar = t.variableDeclaration(left.kind, [
      t.variableDeclarator(left.declarations[0].id, stepValue),
    ]);
  }

  const build = wrapAwait ? buildForAwait : buildForAwaitWithoutWrapping;
  let template = build({
    ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
    ITERATOR_COMPLETION: scope.generateUidIdentifier(
      "iteratorNormalCompletion",
    ),
    ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
github parcel-bundler / parcel / packages / transformers / js / src / visitors / dependencies.js View on Github external
function evaluateExpression(node) {
  // Wrap the node in a standalone program so we can traverse it
  node = types.file(types.program([types.expressionStatement(node)]));

  // Find the first expression and evaluate it.
  let res = null;
  traverse(node, {
    Expression(path) {
      res = path.evaluate();
      path.stop();
    }
  });

  return res;
}
github alibaba / rax / packages / jsx-compiler / src / modules / code.js View on Github external
Object.keys(dynamicValue).forEach(name => {
    dataProperties.push(t.objectProperty(t.stringLiteral(name), dynamicValue[name]));
  });

  renderItemFunctions.map(renderItemFn => {
    dataProperties.push(t.objectProperty(t.stringLiteral(renderItemFn.name), renderItemFn.node));
  });

  const updateData = t.memberExpression(
    t.thisExpression(),
    t.identifier('_updateData')
  );

  const fnBody = renderFunctionPath.node.body.body;
  fnBody.push(t.expressionStatement(t.callExpression(updateData, [
    t.objectExpression(dataProperties)
  ])));
}
github babel / babel / packages / babel-helper-module-transforms / src / rewrite-live-references.js View on Github external
const exportedNames = exported.get(localName) || [];
          if (exportedNames.length > 0) {
            items.push(
              buildBindingExportAssignmentExpression(
                this.metadata,
                exportedNames,
                t.identifier(localName),
              ),
            );
          }
        });

        if (items.length > 0) {
          let node = t.sequenceExpression(items);
          if (path.parentPath.isExpressionStatement()) {
            node = t.expressionStatement(node);
            node._blockHoist = path.parentPath.node._blockHoist;
          }

          const statement = path.insertAfter(node)[0];
          requeueInParent(statement);
        }
      }
    },
  },
github teleporthq / teleport-code-generators / packages / teleport-vue-app-routing / src / index.ts View on Github external
const vueRouterComponentPlugin: ComponentPlugin = async (structure) => {
    const { chunks, uidl, dependencies } = structure

    dependencies.Vue = {
      type: 'library',
      path: 'vue',
    }
    dependencies.Router = {
      type: 'library',
      path: 'vue-router',
    }

    const declaration = t.expressionStatement(
      t.callExpression(t.identifier('Vue.use'), [t.identifier('Router')])
    )

    const routes = extractRoutes(uidl)
    const routeDefinitions = uidl.stateDefinitions.route

    const routesAST = routes.map((routeNode) => {
      const pageKey = routeNode.content.value.toString()
      const { fileName, componentName, path } = extractPageMetadata(routeDefinitions, pageKey)

      dependencies[componentName] = { type: 'local', path: `./views/${fileName}` }

      return t.objectExpression([
        t.objectProperty(t.identifier('name'), t.stringLiteral(pageKey)),
        t.objectProperty(t.identifier('path'), t.stringLiteral(path)),
        t.objectProperty(t.identifier('component'), t.identifier(componentName)),
github facebook / prepack / src / serializer / ResidualHeapVisitor.js View on Github external
depth: 0,
        lexicalDepth: 0,
        unbound: new Map(),
        requireCalls: new Map(),
        modified: new Set(),
        usesArguments: false,
        usesThis: false,
      };
      let state = {
        functionInfo,
        realm: this.realm,
        getModuleIdIfNodeIsRequireFunction: this.modules.getGetModuleIdIfNodeIsRequireFunction(formalParameters, [val]),
      };

      traverse(
        t.file(t.program([t.expressionStatement(t.functionExpression(null, formalParameters, code))])),
        ClosureRefVisitor,
        null,
        state
      );
      traverse.cache.clear();
      this.functionInfos.set(code, functionInfo);

      if (val.isResidual && functionInfo.unbound.size) {
        if (!val.isUnsafeResidual) {
          this.logger.logError(
            val,
            `residual function ${describeLocation(this.realm, val, undefined, code.loc) ||
              "(unknown)"} refers to the following identifiers defined outside of the local scope: ${Object.keys(
              functionInfo.unbound
            ).join(", ")}`
          );
github ismail-codar / fidan / packages / babel-plugin-fidan-jsx / src / util.ts View on Github external
export const setComponentPropsToDom = (path, result) => {
  const parentComponent = jsxParentComponent(path);
  if (parentComponent && parentComponent.params.length === 1) {
    //_el$.$props = props;
    result.exprs.push(
      t.expressionStatement(
        t.assignmentExpression(
          "=",
          t.memberExpression(result.id, t.identifier("$props")),
          parentComponent.params[0]
        )
      )
    );
  }
};
github parcel-bundler / parcel / packages / core / parcel-bundler / src / packagers / JSConcatPackager.js View on Github external
} else {
        body.push(node);
      }
    }

    let executed = getName(asset, 'executed');
    decls.push(
      t.variableDeclarator(t.identifier(executed), t.booleanLiteral(false)),
    );

    let init = t.functionDeclaration(
      getIdentifier(asset, 'init'),
      [],
      t.blockStatement([
        t.ifStatement(t.identifier(executed), t.returnStatement()),
        t.expressionStatement(
          t.assignmentExpression(
            '=',
            t.identifier(executed),
            t.booleanLiteral(true),
          ),
        ),
        ...body,
      ]),
    );

    return [t.variableDeclaration('var', decls), ...fns, init];
  }