coco a503190 ... made postfix invertible

This commit is contained in:
Jeremy Ashkenas 2010-11-08 22:47:13 -05:00
parent eb3a32e853
commit 919596aba4
3 changed files with 24 additions and 5 deletions

View File

@ -10,7 +10,7 @@
options.bare = true;
return Function(CoffeeScript.compile(code, options))();
};
if (!(typeof window !== "undefined" && window !== null)) {
if (typeof window == "undefined" || window === null) {
return;
}
CoffeeScript.load = function(url, options) {

View File

@ -1459,10 +1459,21 @@
})();
__extends(Existence, Base);
Existence.prototype.children = ['expression'];
Existence.prototype.invert = function() {
this.negated = !this.negated;
return this;
};
Existence.prototype.compileNode = function(o) {
var code;
var code, sym;
code = this.expression.compile(o);
code = IDENTIFIER.test(code) && !o.scope.check(code) ? "typeof " + code + " !== \"undefined\" && " + code + " !== null" : "" + code + " != null";
code = (function() {
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
return this.negated ? "typeof " + code + " == \"undefined\" || " + code + " === null" : "typeof " + code + " != \"undefined\" && " + code + " !== null";
} else {
sym = this.negated ? '==' : '!=';
return "" + code + " " + sym + " null";
}
}).call(this);
return o.level <= LEVEL_COND ? code : "(" + code + ")";
};
return Existence;

View File

@ -1214,12 +1214,20 @@ exports.Existence = class Existence extends Base
constructor: (@expression) ->
invert: ->
@negated = not @negated
this
compileNode: (o) ->
code = @expression.compile o
code = if IDENTIFIER.test(code) and not o.scope.check code
"typeof #{code} !== \"undefined\" && #{code} !== null"
if @negated
"typeof #{code} == \"undefined\" || #{code} === null"
else
"typeof #{code} != \"undefined\" && #{code} !== null"
else
"#{code} != null"
sym = if @negated then '==' else '!='
"#{code} #{sym} null"
if o.level <= LEVEL_COND then code else "(#{code})"
#### Parens