How to use the sequenceExpression function from @babel/types

Find comprehensive JavaScript @babel/types.sequenceExpression code examples handpicked from public code repositorys.

@babel/types.sequenceExpression is a function in the Babel compiler's API that creates an AST node representing a sequence of expressions.

247
248
249
250
251
252
253
254
255
256
  } = builder.done();

  this._insertStatements(statements, importPosition, blockHoist);

  if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") {
    return t.sequenceExpression([t.numericLiteral(0), resultName]);
  }

  return resultName;
}
fork icon0
star icon1
watch icon1

+ 2 other calls in file

165
166
167
168
169
170
171
172
173
174
  // We need to wrap the module in a function when a require
  // call happens inside a non top-level scope, e.g. in a
  // function, if statement, or conditional expression.
  if (mod.cacheData.shouldWrap) {
    let call = t.callExpression(getIdentifier(mod, 'init'), []);
    node = node ? t.sequenceExpression([call, node]) : call;
  }
} else {
  node = REQUIRE_TEMPLATE({ID: t.stringLiteral(mod.id)}).expression;
}
fork icon0
star icon1
watch icon1

How does @babel/types.sequenceExpression work?

@babel/types.sequenceExpression is a function in the Babel compiler's API that creates an abstract syntax tree (AST) node representing a sequence of expressions. When you call @babel/types.sequenceExpression, you provide an array of Babel AST nodes that represent the expressions in the sequence. The function then creates a new AST node that represents the entire sequence. Here's an implementation of @babel/types.sequenceExpression to illustrate how it works: javascript Copy code {{{{{{{ const t = require('@babel/types'); const expressions = [ t.identifier('x'), t.identifier('y'), t.identifier('z') ]; const sequenceExpr = t.sequenceExpression(expressions); In this implementation, we first import the Babel compiler's API using require('@babel/types'). We also define an array called expressions that contains three Identifier nodes. We then call t.sequenceExpression(expressions) to create a new AST node that represents the sequence of expressions in expressions. The resulting sequenceExpr object is a Babel AST node of type SequenceExpression that contains the expressions in the expressions array. Overall, @babel/types.sequenceExpression is a useful function in the Babel compiler's API that allows you to create an AST node representing a sequence of expressions.

286
287
288
289
290
291
292
293
294
295
 */
if (path.isMemberExpression() && path.node.computed) {
  let oldProperty = path.node.property;
  if (!(babelTypes.isStringLiteral(oldProperty) || babelTypes.isNumericLiteral(oldProperty))) {
    let tmpVar = 'nt_1';
    let newProperty = babelTypes.sequenceExpression([
      babelTypes.assignmentExpression(
        '=',
        babelTypes.identifier(tmpVar),
        oldProperty
fork icon0
star icon0
watch icon1

+ 10 other calls in file

79
80
81
82
83
84
85
86
87
88
    path.node,
    `Optimizing ${path.node.callee.name}`);
if (!babelTypes.isExpressionStatement(path.parent)) {
  nodes.push(path.node);
  thisMutator.replaceWithSkip(
      path, babelTypes.sequenceExpression(nodes));
} else {
  thisMutator.insertBeforeSkip(
      path, _liftExpressionsToStatements(path, nodes));
}
fork icon0
star icon0
watch icon0

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
const t = require("@babel/types");

const expressions = [t.identifier("x"), t.identifier("y"), t.identifier("z")];

const sequenceExpr = t.sequenceExpression(expressions);

console.log(JSON.stringify(sequenceExpr, null, 2));

In this example, we first import the Babel compiler's API using require('@babel/types'). We also define an array called expressions that contains three Identifier nodes. We then call t.sequenceExpression(expressions) to create a new AST node that represents the sequence of expressions in expressions. We then log the resulting sequenceExpr object to the console using console.log(JSON.stringify(sequenceExpr, null, 2)). This logs the AST node as a formatted JSON string to the console so that we can inspect its structure. The resulting JSON string looks like this: json Copy code

207
208
209
210
211
212
213
214
215
216
(0, _assert.default)(path.node.operator === "=", "Path was not simplified");
const assignment = path.node;

if (importData) {
  assignment.left = buildImportReference(importData, assignment.left);
  assignment.right = t.sequenceExpression([assignment.right, buildImportThrow(localName)]);
}

path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, assignment));
requeueInParent(path);
fork icon0
star icon0
watch icon0

+ 2 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)