How to use the newExpression function from @babel/types

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

171
172
173
174
175
176
177
178
179
180
'body',
t.expressionStatement(
  t.assignmentExpression(
    '=',
    t.memberExpression(t.identifier('client'), t.identifier(apiInstanceName)),
    t.newExpression(t.identifier(apiClassName), [
      t.memberExpression(t.thisExpression(), t.identifier('request')),
      t.memberExpression(t.thisExpression(), t.identifier('config')),
    ]),
  ),
fork icon24
star icon78
watch icon2

+ 5 other calls in file

40
41
42
43
44
45
46
47
48
49
  return upperFirst(camelCase(typeName));
}

function generateListReference(typeMap, apiType) {
  const ofType = typeMap.ref(apiType.items, true);
  return t.newExpression(typeMap.listTypeRef, [ofType]);
}

function generateListAST(typeMap, type) {
  const { graphqlName, apiType } = type;
fork icon3
star icon46
watch icon11

+ 5 other calls in file

21
22
23
24
25
26
27
28
29
30

module.exports = {
  serializeBoxedString(str, record) {
    const StringRecord = this.serializeValue(String),
      len = str.length;
    const node = t.newExpression(
      StringRecord.varNode,
      len > 0 ? [t.stringLiteral(stringToString.call(str))] : []
    );
    createDependency(record, StringRecord, node, 'callee');
fork icon0
star icon23
watch icon2

+ 5 other calls in file

29
30
31
32
33
34
35
36
37
},

serializeDate(date, record) {
  // `new Date(...)`
  const dateCtorRecord = this.serializeValue(Date);
  const node = t.newExpression(dateCtorRecord.varNode, [t.numericLiteral(dateGetTime.call(date))]);
  createDependency(record, dateCtorRecord, node, 'callee');
  return this.wrapWithProperties(date, record, node, Date.prototype);
},
fork icon0
star icon23
watch icon2

+ 5 other calls in file

81
82
83
84
85
86
87
88
89
90
91


function generateNewInstance(varName, className, args = []) {
  return t.variableDeclaration('const', [
    t.variableDeclarator(
      t.identifier(varName),
      t.newExpression(t.identifier(className), args)
    )
  ]);
}

fork icon1
star icon2
watch icon1

+ 57 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)