UNPKG

792 BJavaScriptView Raw
1var traverse = require('../traverse');
2var helpers = require('../helpers');
3var Identifier = require('./Identifier');
4var VariableDeclaration = require('./VariableDeclaration');
5var VariableDeclarator = require('./VariableDeclarator');
6
7var FunctionExpression = module.exports = function(id, params, body) {
8 this.type = 'FunctionExpression';
9 this.id = id;
10 this.params = params;
11 this.body = body;
12};
13
14FunctionExpression.prototype.normalize = function (place) {
15 this.body.normalize();
16 var dec = helpers.extractVariableDeclarations(this.body);
17 if (dec.declarations.length > 0) {
18 this.body.body.unshift(dec);
19 }
20};
21
22FunctionExpression.prototype.transform = function (place) {
23 this.body.transform(place);
24 if (this.body.async) {
25 this.async = true;
26 }
27 return place;
28};