mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
coco a503190 ... made postfix invertible
This commit is contained in:
parent
eb3a32e853
commit
919596aba4
3 changed files with 24 additions and 5 deletions
|
@ -10,7 +10,7 @@
|
||||||
options.bare = true;
|
options.bare = true;
|
||||||
return Function(CoffeeScript.compile(code, options))();
|
return Function(CoffeeScript.compile(code, options))();
|
||||||
};
|
};
|
||||||
if (!(typeof window !== "undefined" && window !== null)) {
|
if (typeof window == "undefined" || window === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CoffeeScript.load = function(url, options) {
|
CoffeeScript.load = function(url, options) {
|
||||||
|
|
15
lib/nodes.js
15
lib/nodes.js
|
@ -1459,10 +1459,21 @@
|
||||||
})();
|
})();
|
||||||
__extends(Existence, Base);
|
__extends(Existence, Base);
|
||||||
Existence.prototype.children = ['expression'];
|
Existence.prototype.children = ['expression'];
|
||||||
|
Existence.prototype.invert = function() {
|
||||||
|
this.negated = !this.negated;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
Existence.prototype.compileNode = function(o) {
|
Existence.prototype.compileNode = function(o) {
|
||||||
var code;
|
var code, sym;
|
||||||
code = this.expression.compile(o);
|
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 o.level <= LEVEL_COND ? code : "(" + code + ")";
|
||||||
};
|
};
|
||||||
return Existence;
|
return Existence;
|
||||||
|
|
|
@ -1214,12 +1214,20 @@ exports.Existence = class Existence extends Base
|
||||||
|
|
||||||
constructor: (@expression) ->
|
constructor: (@expression) ->
|
||||||
|
|
||||||
|
invert: ->
|
||||||
|
@negated = not @negated
|
||||||
|
this
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
code = @expression.compile o
|
code = @expression.compile o
|
||||||
code = if IDENTIFIER.test(code) and not o.scope.check code
|
code = if IDENTIFIER.test(code) and not o.scope.check code
|
||||||
"typeof #{code} !== \"undefined\" && #{code} !== null"
|
if @negated
|
||||||
|
"typeof #{code} == \"undefined\" || #{code} === null"
|
||||||
else
|
else
|
||||||
"#{code} != null"
|
"typeof #{code} != \"undefined\" && #{code} !== null"
|
||||||
|
else
|
||||||
|
sym = if @negated then '==' else '!='
|
||||||
|
"#{code} #{sym} null"
|
||||||
if o.level <= LEVEL_COND then code else "(#{code})"
|
if o.level <= LEVEL_COND then code else "(#{code})"
|
||||||
|
|
||||||
#### Parens
|
#### Parens
|
||||||
|
|
Loading…
Reference in a new issue