Add undefined and null literal support

This adds the UndefinedLiteral and NullLiteral to AST.

Fixes #990
This commit is contained in:
kpdecker
2015-04-07 23:37:38 -05:00
parent 81a4d50955
commit 2d149e7797
12 changed files with 65 additions and 2 deletions
+12
View File
@@ -101,6 +101,18 @@ var AST = {
this.value = bool === 'true';
},
UndefinedLiteral: function(locInfo) {
this.loc = locInfo;
this.type = 'UndefinedLiteral';
this.original = this.value = undefined;
},
NullLiteral: function(locInfo) {
this.loc = locInfo;
this.type = 'NullLiteral';
this.original = this.value = null;
},
Hash: function(pairs, locInfo) {
this.loc = locInfo;
this.type = 'Hash';
+8
View File
@@ -273,6 +273,14 @@ Compiler.prototype = {
this.opcode('pushLiteral', bool.value);
},
UndefinedLiteral: function() {
this.opcode('pushLiteral', 'undefined');
},
NullLiteral: function() {
this.opcode('pushLiteral', 'null');
},
Hash: function(hash) {
var pairs = hash.pairs, i, l;
+8
View File
@@ -124,6 +124,14 @@ PrintVisitor.prototype.BooleanLiteral = function(bool) {
return "BOOLEAN{" + bool.value + "}";
};
PrintVisitor.prototype.UndefinedLiteral = function() {
return 'UNDEFINED';
};
PrintVisitor.prototype.NullLiteral = function() {
return 'NULL';
};
PrintVisitor.prototype.Hash = function(hash) {
var pairs = hash.pairs;
var joinedPairs = [];
+2
View File
@@ -110,6 +110,8 @@ Visitor.prototype = {
StringLiteral: function(/* string */) {},
NumberLiteral: function(/* number */) {},
BooleanLiteral: function(/* bool */) {},
UndefinedLiteral: function(/* literal */) {},
NullLiteral: function(/* literal */) {},
Hash: function(hash) {
this.acceptArray(hash.pairs);