Skip to content
This repository
Browse code

More work on expressions, got more things working like the tests incl…

…uded.
  • Loading branch information...
commit cc3c09f0bd1f421686d4f2591fcfba378d136fc2 1 parent 7dad16e
Maxwell Krohn authored
34 lib/coffee-script/nodes.js
@@ -916,6 +916,28 @@
916 916 return [base.add(name), new Value(bref || base.base, [nref || name])];
917 917 };
918 918
  919 + Value.prototype.tameWrapContinuation = YES;
  920 +
  921 + Value.prototype.tameCpsRotate = function() {
  922 + var nv, p, _i, _len, _ref2, _results;
  923 + if (!this.properties.length) {
  924 + Value.__super__.tameCpsRotate.call(this);
  925 + return;
  926 + }
  927 + if ((nv = this.tameCpsExprRotate(this.base))) this.base = nv;
  928 + _ref2 = this.properties;
  929 + _results = [];
  930 + for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  931 + p = _ref2[_i];
  932 + if ((p.index != null) && this.tameCpsExprRotate(p.index)) {
  933 + _results.push(p.index = v);
  934 + } else {
  935 + _results.push(void 0);
  936 + }
  937 + }
  938 + return _results;
  939 + };
  940 +
919 941 Value.prototype.compileNode = function(o) {
920 942 var code, prop, props, _i, _len;
921 943 this.base.front = this.front;
@@ -1034,6 +1056,18 @@
1034 1056 }
1035 1057 };
1036 1058
  1059 + Call.prototype.tameWrapContinuation = YES;
  1060 +
  1061 + Call.prototype.tameCpsRotate = function() {
  1062 + var a, i, v, _len, _ref2;
  1063 + _ref2 = this.args;
  1064 + for (i = 0, _len = _ref2.length; i < _len; i++) {
  1065 + a = _ref2[i];
  1066 + if ((v = this.tameCpsExprRotate(a))) this.args[i] = v;
  1067 + }
  1068 + if ((v = this.tameCpsExprRotate(this.variable))) return this.variable = v;
  1069 + };
  1070 +
1037 1071 Call.prototype.unfoldSoak = function(o) {
1038 1072 var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
1039 1073 if (this.soak) {
17 src/nodes.coffee
@@ -773,6 +773,16 @@ exports.Value = class Value extends Base
773 773 nref = new Index nref
774 774 [base.add(name), new Value(bref or base.base, [nref or name])]
775 775
  776 + tameWrapContinuation : YES
  777 + tameCpsRotate: ->
  778 + unless @properties.length
  779 + super()
  780 + return
  781 + @base = nv if (nv = @tameCpsExprRotate @base)
  782 + for p in @properties
  783 + if (p.index? and @tameCpsExprRotate p.index)
  784 + p.index = v
  785 +
776 786 # We compile a value to JavaScript by compiling and joining each property.
777 787 # Things get much more interesting if the chain of properties has *soak*
778 788 # operators `?.` interspersed. Then we have to take care not to accidentally
@@ -857,6 +867,13 @@ exports.Call = class Call extends Base
857 867 else
858 868 "#{name}.__super__.constructor"
859 869
  870 +
  871 + tameWrapContinuation: YES
  872 + tameCpsRotate: ->
  873 + for a,i in @args
  874 + @args[i] = v if (v = @tameCpsExprRotate a)
  875 + @variable = v if (v = @tameCpsExprRotate @variable)
  876 +
860 877 # Soaked chained invocations unfold into if/else ternary structures.
861 878 unfoldSoak: (o) ->
862 879 if @soak
22 test/tame.coffee
@@ -387,6 +387,16 @@ atest 'expressions -- addition (2)', (cb) ->
387 387 a+b
388 388 y = (await slowAdd 10, 20, defer _) + (await slowAdd 30, 40, defer _)
389 389 cb(y == 100, {})
  390 +
  391 +atest 'chaining', (cb) ->
  392 + id = "image data"
  393 + class Img
  394 + render : -> id
  395 + loadImage = (n, cb) ->
  396 + await delay defer()
  397 + cb new Img
  398 + x = (await loadImage "test.png", defer _).render()
  399 + cb(x is id, {})
390 400
391 401 #atest 'arrays and objects', (cb) ->
392 402 # id = "image data"
@@ -401,16 +411,8 @@ atest 'expressions -- addition (2)', (cb) ->
401 411 # v : "another value"
402 412 # cb(arr[0] is id and obj.i is id, {})
403 413 #
404   -#atest 'chaining', (cb) ->
405   -# id = "image data"
406   -# class Img
407   -# render : -> id
408   -# loadImage = (n, cb) ->
409   -# await delay defer()
410   -# cb new Img
411   -# x = (await loadImage "test.png", defer()).render()
412   -# cb(x is id, {})
413   -#
  414 +#
  415 +
414 416 #atest 'nesting', (cb) ->
415 417 # id = "image data"
416 418 # loadImage = (n, cb) ->

0 comments on commit cc3c09f

Please sign in to comment.
Something went wrong with that request. Please try again.