Skip to content

Commit

Permalink
change NullCheckCallExpression consequent to ast.CallExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
alongubkin committed Nov 14, 2014
1 parent c724daa commit 8f68c49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/ast/expressions/CallExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ exports.CallExpression = function (callee, args) {
exports.CallExpression.prototype = Object.create(Node);

exports.CallExpression.prototype.codegen = function () {
if (!Node.prototype.codegen.call(this)) {
return;
}

var calleeType = this.callee.type;

this.callee = this.callee.codegen();
if (!this.callee.codeGenerated) {
this.callee = this.callee.codegen();
}

var args = this.arguments;
args.forEach(function (arg, i) {
Expand Down
22 changes: 13 additions & 9 deletions lib/ast/expressions/NullCheckCallExpression.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Node = require('../Node').Node;

var Node = require('../Node').Node,
CallExpression = require('./CallExpression').CallExpression;

exports.NullCheckCallExpression = function (callee, args) {
var self = this;
Node.call(self);
Expand All @@ -18,14 +19,19 @@ exports.NullCheckCallExpression = function (callee, args) {

exports.NullCheckCallExpression.prototype = Object.create(Node);

exports.NullCheckCallExpression.prototype.codegen = function () {
exports.NullCheckCallExpression.prototype.codegen = function () {
if (!Node.prototype.codegen.call(this)) {
return;
}

var calleeType = this.callee.type;

this.callee = this.callee.codegen();

var args = this.args;
args.forEach(function (arg, i) {
args[i] = arg.codegen();
args[i].codeGenerated = true;
});

// If the callee has a function call (e.g: a().b)
Expand All @@ -36,7 +42,8 @@ exports.NullCheckCallExpression.prototype.codegen = function () {

var id = {
"type": "Identifier",
"name": exports.NullCheckCallExpression.getNextVariableName()
"name": exports.NullCheckCallExpression.getNextVariableName(),
"codeGenerated": true
};

context.node.body.splice(context.position +
Expand Down Expand Up @@ -89,11 +96,8 @@ exports.NullCheckCallExpression.prototype.codegen = function () {
};
}

var consequent = {
"type": "CallExpression",
"callee": argument,
"arguments": args
};
argument.codeGenerated = true;
var consequent = new CallExpression(argument, args).codegen();

if (this.parent.type === 'ExpressionStatement') {
this.parent.type = 'IfStatement';
Expand Down

0 comments on commit 8f68c49

Please sign in to comment.