Skip to content

Commit

Permalink
conditional expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
alongubkin committed Nov 14, 2014
1 parent 86cc7fb commit 4d218a4
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 350 deletions.
1 change: 1 addition & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
ThisExpression: require('./ast/expressions/ThisExpression').ThisExpression,
SuperExpression: require('./ast/expressions/SuperExpression').SuperExpression,
SplatExpression: require('./ast/expressions/SplatExpression').SplatExpression,
ConditionalExpression: require('./ast/expressions/ConditionalExpression').ConditionalExpression,
BlockStatement: require('./ast/statements/BlockStatement').BlockStatement,
ExpressionStatement: require('./ast/statements/ExpressionStatement').ExpressionStatement,
IfStatement: require('./ast/statements/IfStatement').IfStatement,
Expand Down
34 changes: 34 additions & 0 deletions lib/ast/expressions/ConditionalExpression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Node = require('../Node').Node;

exports.ConditionalExpression = function (test, consequent, alternate) {
Node.call(this);

this.type = 'ConditionalExpression';

this.test = test;
this.test.parent = this;

this.consequent = consequent;
this.consequent.parent = this;

this.alternate = alternate;
this.alternate.parent = this;
};

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

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

this.test = this.test.codegen();
this.consequent = this.consequent.codegen();
this.alternate = this.alternate.codegen();

return this;
};

exports.ConditionalExpression.prototype.hasCallExpression = function () {
return true;
};
Loading

0 comments on commit 4d218a4

Please sign in to comment.