How to use the arrowFunctionExpression function from @babel/types

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

5
6
7
8
9
10
11
12
13
14

const fnToArrowPlugin = {
  visitor: {
    FunctionExpression(path) {
      const { params, body } = path.node
      const arrowFunctionExpression = t.arrowFunctionExpression(params, body)
      path.replaceWith(arrowFunctionExpression)
    }
  }
}
fork icon2
star icon12
watch icon1

+ 3 other calls in file

53
54
55
56
57
58
59
60
61
62
  t.callExpression(t.identifier('createIconComponent'), [
    // The name of the generated icon
    t.stringLiteral(name),
    // The className used on the underlying <svg> element
    t.stringLiteral(`octicon octicon-${key}`),
    t.arrowFunctionExpression([], t.blockStatement([t.returnStatement(svgData)]))
  ]),
  'leading',
  '#__PURE__'
)
fork icon915
star icon0
watch icon0

211
212
213
214
215
216
217
218
219
220
} else if (methodName === 'componentWillUnmount') {
  // 处理componentWillUnmount
  this.collectHooks('useEffect')
  const expression = t.expressionStatement(
    t.callExpression(t.identifier('useEffect'), [
      t.arrowFunctionExpression(
        [],
        t.blockStatement([t.returnStatement(this.createArrowFn(node))])
      ),
      t.arrayExpression([])
fork icon8
star icon53
watch icon1

+ 5 other calls in file

150
151
152
153
154
155
156
157
158
159
    t.objectExpression([
      t.objectProperty(t.identifier('name'), t.stringLiteral(graphqlName)),
      t.objectProperty(
        t.identifier('fields'),
        // arrow expression to deal with recursion
        t.arrowFunctionExpression([], t.objectExpression(fields))
      ),
    ]),
  ])
),
fork icon3
star icon46
watch icon11

+ 3 other calls in file

99
100
101
102
103
104
105
106
107
108
elseIfBindings.forEach((binding) => {
    const { node, index } = binding;
    removeAttrASTByIndex(node, index);
});

const callee = t.arrowFunctionExpression([], t.blockStatement([
    t.ifStatement(
        ifAttr.value.expression,
        t.returnStatement(ifNode),
        getAlternteAST(elseIfBindings, elseBinding)
fork icon3
star icon11
watch icon2

+ 2 other calls in file

78
79
80
81
82
83
84
85
86
87
  BlockStatement(p) {
    blockStatement = p.node
  },
})

const arrowFunctionExpression = t.arrowFunctionExpression(
  [],
  blockStatement,
)
const callExpression = t.callExpression(arrowFunctionExpression, [])
fork icon2
star icon16
watch icon1

53
54
55
56
57
58
59
60
61
    throw new Error(
      `createTemplate() must receive an object literal with all of the imported values for the template as its scope parameter, received: ${scopePath.type}`
    );
  }

  scope = t.arrowFunctionExpression([], scopePath.node);
} else {
  scope = t.arrowFunctionExpression([], t.objectExpression([]));
}
fork icon73
star icon0
watch icon1

+ 5 other calls in file

148
149
150
151
152
153
154
155
156
157
if (t.isNullLiteral(node) && key == '(') {
  this.updateCode({
    ast: produce(ast, ast => {
      getNodeFromPath(ast, path.slice(0, -1))[
        path[path.length - 1]
      ] = t.arrowFunctionExpression([], t.nullLiteral());
    })
  });
  this.moveCursor(null);
  event.preventDefault();
fork icon4
star icon0
watch icon1

+ 3 other calls in file

78
79
80
81
82
83
84
85
86
87
  });

  return [
    t.expressionStatement(
      t.callExpression(builder.buildMemberExpression(t.thisExpression(), t.identifier('setState')), [
        t.arrowFunctionExpression([prevStateVar], t.blockStatement([...statements, t.returnStatement(result)]))
      ])
    )
  ];
}
fork icon13
star icon10
watch icon0

+ 3 other calls in file

247
248
249
250
251
252
253
254
255
256
  let arrowFn;

  if (node.value && node.value.type === 'ArrowFunctionExpression') {
    arrowFn = node.value;
  } else {
    arrowFn = t.arrowFunctionExpression([], body);
  }

  return arrowFn;
});
fork icon8
star icon53
watch icon1

145
146
147
148
149
150
151
152
153
154
  false,
  false
),
[
  node,
  types.arrowFunctionExpression(
    [],
    useGestureHandlerExpression(
      !!config.useGestureHandler,
      types.identifier(component)
fork icon2
star icon7
watch icon2

105
106
107
108
109
110
111
112
113
114
        true
      )
    )
  }
})
exArray.push(t.objectProperty(t.identifier('render'), t.arrowFunctionExpression([
  t.identifier('_'),
  t.identifier('record'),
], t.BlockStatement([
  t.returnStatement(
fork icon1
star icon25
watch icon0

141
142
143
144
145
146
147
148
149
150
         *    value: () => {},
         * }
         */

        var body = valueNode.value
        let afx = t.arrowFunctionExpression([], body)

        valueNode.value = afx
    }
}
fork icon221
star icon0
watch icon0

116
117
118
119
120
121
122
123
124
125
  t.callExpression(t.identifier('createIconComponent'), [
    // The name of the generated icon
    t.stringLiteral(name),
    // The className used on the underlying <svg> element
    t.stringLiteral(`oxygen-icon oxygen-icon-${key}`),
    t.arrowFunctionExpression([], t.blockStatement([t.returnStatement(svgData)])),
  ]),
  'leading',
  '#__PURE__',
),
fork icon10
star icon4
watch icon0

330
331
332
333
334
335
336
337
338
339
340
341
      )
    )
  ])


const makeAsyncT = body =>
  btypes.arrowFunctionExpression([btypes.identifier('t')], body, true)


const makeTPass = () =>
  btypes.callExpression(
    btypes.memberExpression(btypes.identifier('t'), btypes.identifier('pass')),
fork icon0
star icon15
watch icon1

338
339
340
341
342
343
344
345
346
347
348
349
      const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
      argsList.push(valueIdent);
      fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
    }


    return t.arrowFunctionExpression(argsList, fnBody);
  });
}


function getBinding(thisEnvFn, key, init) {
fork icon0
star icon1
watch icon1

+ 81 other calls in file

408
409
410
411
412
413
414
415
416
417
        body = this.visitChildren(child);
      }
    }
  });

  return t.arrowFunctionExpression(args, body[0]);
}

isTerminalNode(node) {
  return node.constructor.name === "TerminalNodeImpl";
fork icon0
star icon1
watch icon0

160
161
162
163
164
165
166
167
168
169
    // 去掉类型
    params[0] = t.identifier(p0.name);
}
const isArrow = t.isArrowFunctionExpression(fn);
const fnExp = isArrow
    ? t.arrowFunctionExpression(params, fn.body, fn.async)
    : t.functionExpression(undefined, params, fn.body, fn.generator, fn.async);
// fnExp.end = fn.end;
fnExp.extra = fn.extra;
fnExp.generator = fn.generator;
fork icon0
star icon0
watch icon1

+ 25 other calls in file

143
144
145
146
147
148
149
150
151
152
    consequent.expression.isNewCallExp = true;
    var ifCheckStmt = babel.ifStatement(test, consequent);
    var retCallExp = babel.callExpression(callExpNode.callee /*tempVarID*/, callExpNode.arguments);
    retCallExp.isNewCallExp = true;
    var returnStmt = babel.returnStatement(retCallExp);
    var arrowFunc = babel.arrowFunctionExpression([], // params
    babel.blockStatement(tempVarDecls.concat([ifCheckStmt, returnStmt])), inAsyncFct); // whether or not it should be async
    return babel.callExpression(arrowFunc, []);
}
exports.buildEvalCheck = buildEvalCheck;
fork icon0
star icon0
watch icon14

+ 256 other calls in file

179
180
181
182
183
184
185
186
187
188
189
    NODE_EQUIV: [clonedStateExp(), types.expressionStatement(equivNodeRight)],
    ARGS: DUMMY_NAME
  });
  var declare3 = types.returnStatement(tempNode);
  var block = types.blockStatement([declare1, declare2, declare3]);
  var arrowFunc = types.arrowFunctionExpression([], block);
  return types.callExpression(arrowFunc, []);
};


var transformer = function transformer(node, type) {
fork icon0
star icon0
watch icon1

Other functions in @babel/types

Sorted by popularity

function icon

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