coffee-react 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/coffee-react-transform.js +198 -116
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 221be23805ca7f31a57e8e339c6cd14494d4b529
4
- data.tar.gz: 6ae3f47fc53183cbea885719a93a6abb179c7f90
3
+ metadata.gz: 3c37e9af38a88f4c1ea53a9e4f2a5595bd4c595a
4
+ data.tar.gz: 932baeb13b710547875569051f184165f55b47b6
5
5
  SHA512:
6
- metadata.gz: 6e57c3d5f022aff35daaf9ca8fb97aaf0e6c23a91c4716f8c9390b596ed71b96dcefd1defab29307ada2cbbecc945b8b5b1cf53249b1179ee7c43e318f3f1dab
7
- data.tar.gz: 7578aa1247a7c6424249a5f28de9dfc2cdab8e1c25e8a63a7d5092d6eadc6abd67ce5cd9927962a71a6dedbd8129db5a4e79b58830639d982ce4bb472cab3672
6
+ metadata.gz: d7350633763b4f967713a8975e993a60194634d409ec5a523172b9b154fe6f0f0ec76a2f059a9798f6556462530150b0d9ceee6765ad7aa28227510d4af35d68
7
+ data.tar.gz: a7739092b50a7737bceaeddff270913201be7bcb17fe7534b228345929f0745de8931533eeb98727f71db560f99803af12d8cca62f115f23bb61a2b5eba38108
@@ -286,7 +286,7 @@ module.exports = function decode(str) {
286
286
 
287
287
  },{}],3:[function(_dereq_,module,exports){
288
288
  // Generated by CoffeeScript 1.7.1
289
- var extend, flatten, last, repeat, syntaxErrorToString, _ref;
289
+ var extend, flatten, last, repeat, syntaxErrorToString, _ref, _ref1;
290
290
 
291
291
  exports.starts = function(string, literal, start) {
292
292
  return literal === string.substr(start, literal.length);
@@ -384,6 +384,16 @@ exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
384
384
  return false;
385
385
  };
386
386
 
387
+ exports.find = (_ref1 = Array.prototype.find) != null ? _ref1 : function(fn) {
388
+ var e, _i, _len;
389
+ for (_i = 0, _len = this.length; _i < _len; _i++) {
390
+ e = this[_i];
391
+ if (fn(e)) {
392
+ return e;
393
+ }
394
+ }
395
+ };
396
+
387
397
  exports.throwSyntaxError = function(message, location) {
388
398
  var error;
389
399
  error = new SyntaxError(message);
@@ -403,11 +413,11 @@ exports.updateSyntaxError = function(error, code, filename) {
403
413
  };
404
414
 
405
415
  syntaxErrorToString = function() {
406
- var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
416
+ var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref2, _ref3;
407
417
  if (!(this.code && this.location)) {
408
418
  return Error.prototype.toString.call(this);
409
419
  }
410
- _ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
420
+ _ref2 = this.location, first_line = _ref2.first_line, first_column = _ref2.first_column, last_line = _ref2.last_line, last_column = _ref2.last_column;
411
421
  if (last_line == null) {
412
422
  last_line = first_line;
413
423
  }
@@ -422,7 +432,7 @@ syntaxErrorToString = function() {
422
432
  if (typeof process !== "undefined" && process !== null) {
423
433
  colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
424
434
  }
425
- if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
435
+ if ((_ref3 = this.colorful) != null ? _ref3 : colorsEnabled) {
426
436
  colorize = function(str) {
427
437
  return "\x1B[1;31m" + str + "\x1B[0m";
428
438
  };
@@ -583,13 +593,13 @@ module.exports = {
583
593
  };
584
594
  },{}],5:[function(_dereq_,module,exports){
585
595
  // Generated by CoffeeScript 1.7.1
586
- var $, BOM, CLOSING_TAG, COMMENT, HEREDOC, HEREGEX, JSTOKEN, OPENING_TAG, PRAGMA, Parser, REGEX, SIMPLESTR, TAG_ATTRIBUTES, TRAILING_SPACES, WHITESPACE, compact, count, last, parseTreeBranchNode, parseTreeLeafNode, repeat, starts, throwSyntaxError, _ref;
596
+ var $, BOM, CLOSING_TAG, COMMENT, HEREDOC, HEREGEX, JSTOKEN, OPENING_TAG, PRAGMA, ParseTreeBranchNode, ParseTreeLeafNode, Parser, REGEX, SIMPLESTR, TAG_ATTRIBUTES, TRAILING_SPACES, WHITESPACE, compact, count, last, repeat, starts, throwSyntaxError, _ref;
587
597
 
588
598
  _ref = _dereq_('./helpers'), count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last, repeat = _ref.repeat, throwSyntaxError = _ref.throwSyntaxError;
589
599
 
590
600
  $ = _dereq_('./symbols');
591
601
 
592
- parseTreeLeafNode = function(type, value) {
602
+ ParseTreeLeafNode = function(type, value) {
593
603
  if (value == null) {
594
604
  value = null;
595
605
  }
@@ -599,7 +609,7 @@ parseTreeLeafNode = function(type, value) {
599
609
  };
600
610
  };
601
611
 
602
- parseTreeBranchNode = function(type, value, children) {
612
+ ParseTreeBranchNode = function(type, value, children) {
603
613
  if (value == null) {
604
614
  value = null;
605
615
  }
@@ -619,7 +629,7 @@ module.exports = Parser = (function() {
619
629
  Parser.prototype.parse = function(code, opts) {
620
630
  var consumed, i, message, _ref1, _ref2;
621
631
  this.opts = opts != null ? opts : {};
622
- this.parseTree = parseTreeBranchNode(this.opts.root || $.ROOT);
632
+ this.parseTree = ParseTreeBranchNode(this.opts.root || $.ROOT);
623
633
  this.activeStates = [this.parseTree];
624
634
  this.chunkLine = 0;
625
635
  this.chunkColumn = 0;
@@ -667,11 +677,11 @@ module.exports = Parser = (function() {
667
677
  } else {
668
678
  prefix = 'React.DOM';
669
679
  }
670
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CJSX_PRAGMA, prefix));
680
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CJSX_PRAGMA, prefix));
671
681
  return comment.length;
672
682
  }
673
683
  }
674
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS_COMMENT, comment));
684
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS_COMMENT, comment));
675
685
  return comment.length;
676
686
  };
677
687
 
@@ -681,7 +691,7 @@ module.exports = Parser = (function() {
681
691
  return 0;
682
692
  }
683
693
  heredoc = match[0];
684
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS_HEREDOC, heredoc));
694
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS_HEREDOC, heredoc));
685
695
  return heredoc.length;
686
696
  };
687
697
 
@@ -697,7 +707,7 @@ module.exports = Parser = (function() {
697
707
  if (!string) {
698
708
  return 0;
699
709
  }
700
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS_STRING, string));
710
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS_STRING, string));
701
711
  return string.length;
702
712
  };
703
713
 
@@ -719,7 +729,7 @@ module.exports = Parser = (function() {
719
729
  if (regex === '//') {
720
730
  return 0;
721
731
  }
722
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS_REGEX, match));
732
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS_REGEX, match));
723
733
  return match.length;
724
734
  };
725
735
 
@@ -729,7 +739,7 @@ module.exports = Parser = (function() {
729
739
  return 0;
730
740
  }
731
741
  heregex = match[0], body = match[1], flags = match[2];
732
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS_HEREGEX, heregex));
742
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS_HEREGEX, heregex));
733
743
  return heregex.length;
734
744
  };
735
745
 
@@ -739,7 +749,7 @@ module.exports = Parser = (function() {
739
749
  return 0;
740
750
  }
741
751
  script = match[0];
742
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.JS_ESC, script));
752
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.JS_ESC, script));
743
753
  return script.length;
744
754
  };
745
755
 
@@ -752,13 +762,13 @@ module.exports = Parser = (function() {
752
762
  if (!(selfClosing || this.chunk.indexOf("</" + tagName + ">", input.length) > -1)) {
753
763
  return 0;
754
764
  }
755
- this.pushActiveBranchNode(parseTreeBranchNode($.CJSX_EL, tagName));
756
- this.pushActiveBranchNode(parseTreeBranchNode($.CJSX_ATTRIBUTES));
765
+ this.pushActiveBranchNode(ParseTreeBranchNode($.CJSX_EL, tagName));
766
+ this.pushActiveBranchNode(ParseTreeBranchNode($.CJSX_ATTRIBUTES));
757
767
  return 1 + tagName.length;
758
768
  };
759
769
 
760
770
  Parser.prototype.cjsxAttribute = function() {
761
- var attrName, bareVal, cjsxEscVal, doubleQuotedVal, input, match, singleQuotedVal, whitespace;
771
+ var attrName, bareVal, cjsxEscVal, doubleQuotedVal, input, match, singleQuotedVal, spreadAttr, whitespace;
762
772
  if (this.currentState() !== $.CJSX_ATTRIBUTES) {
763
773
  return 0;
764
774
  }
@@ -781,27 +791,30 @@ module.exports = Parser = (function() {
781
791
  if (!(match = TAG_ATTRIBUTES.exec(this.chunk))) {
782
792
  return 0;
783
793
  }
784
- input = match[0], attrName = match[1], doubleQuotedVal = match[2], singleQuotedVal = match[3], cjsxEscVal = match[4], bareVal = match[5], whitespace = match[6];
794
+ input = match[0], attrName = match[1], doubleQuotedVal = match[2], singleQuotedVal = match[3], cjsxEscVal = match[4], bareVal = match[5], spreadAttr = match[6], whitespace = match[7];
785
795
  if (attrName) {
786
- if (doubleQuotedVal) {
787
- this.addLeafNodeToActiveBranch(parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [parseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), parseTreeLeafNode($.CJSX_ATTR_VAL, "\"" + doubleQuotedVal + "\"")]));
796
+ if (doubleQuotedVal != null) {
797
+ this.addLeafNodeToActiveBranch(ParseTreeBranchNode($.CJSX_ATTR_PAIR, null, [ParseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), ParseTreeLeafNode($.CJSX_ATTR_VAL, "\"" + doubleQuotedVal + "\"")]));
788
798
  return input.length;
789
- } else if (singleQuotedVal) {
790
- this.addLeafNodeToActiveBranch(parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [parseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), parseTreeLeafNode($.CJSX_ATTR_VAL, "'" + singleQuotedVal + "'")]));
799
+ } else if (singleQuotedVal != null) {
800
+ this.addLeafNodeToActiveBranch(ParseTreeBranchNode($.CJSX_ATTR_PAIR, null, [ParseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), ParseTreeLeafNode($.CJSX_ATTR_VAL, "'" + singleQuotedVal + "'")]));
791
801
  return input.length;
792
802
  } else if (cjsxEscVal) {
793
- this.pushActiveBranchNode(parseTreeBranchNode($.CJSX_ATTR_PAIR));
794
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""));
803
+ this.pushActiveBranchNode(ParseTreeBranchNode($.CJSX_ATTR_PAIR));
804
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""));
795
805
  return input.indexOf('{');
796
806
  } else if (bareVal) {
797
- this.addLeafNodeToActiveBranch(parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [parseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), parseTreeLeafNode($.CJSX_ATTR_VAL, bareVal)]));
807
+ this.addLeafNodeToActiveBranch(ParseTreeBranchNode($.CJSX_ATTR_PAIR, null, [ParseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), ParseTreeLeafNode($.CJSX_ATTR_VAL, bareVal)]));
798
808
  return input.length;
799
809
  } else {
800
- this.addLeafNodeToActiveBranch(parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [parseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), parseTreeLeafNode($.CJSX_ATTR_VAL, 'true')]));
810
+ this.addLeafNodeToActiveBranch(ParseTreeBranchNode($.CJSX_ATTR_PAIR, null, [ParseTreeLeafNode($.CJSX_ATTR_KEY, "\"" + attrName + "\""), ParseTreeLeafNode($.CJSX_ATTR_VAL, 'true')]));
801
811
  return input.length;
802
812
  }
803
- } else if (whitespace) {
804
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CJSX_WHITESPACE, whitespace));
813
+ } else if (spreadAttr) {
814
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CJSX_ATTR_SPREAD, spreadAttr));
815
+ return input.length;
816
+ } else if (whitespace != null) {
817
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CJSX_WHITESPACE, whitespace));
805
818
  return input.length;
806
819
  } else {
807
820
  return throwSyntaxError("Invalid attribute " + input + " in CJSX tag " + (this.peekActiveState(2).value), {
@@ -816,18 +829,19 @@ module.exports = Parser = (function() {
816
829
  if (!(this.chunk.charAt(0) === '{' && ((_ref1 = this.currentState()) === $.CJSX_EL || _ref1 === $.CJSX_ATTR_PAIR))) {
817
830
  return 0;
818
831
  }
819
- this.pushActiveBranchNode(parseTreeBranchNode($.CJSX_ESC));
832
+ this.pushActiveBranchNode(ParseTreeBranchNode($.CJSX_ESC));
820
833
  this.activeBranchNode().stack = 1;
821
834
  return 1;
822
835
  };
823
836
 
824
837
  Parser.prototype.cjsxUnescape = function() {
838
+ var _ref1;
825
839
  if (!(this.currentState() === $.CJSX_ESC && this.chunk.charAt(0) === '}')) {
826
840
  return 0;
827
841
  }
828
842
  if (this.activeBranchNode().stack === 0) {
829
843
  this.popActiveBranchNode();
830
- if (this.currentState() === $.CJSX_ATTR_PAIR) {
844
+ if ((_ref1 = this.currentState()) === $.CJSX_ATTR_PAIR) {
831
845
  this.popActiveBranchNode();
832
846
  }
833
847
  return 1;
@@ -860,7 +874,7 @@ module.exports = Parser = (function() {
860
874
  return 0;
861
875
  }
862
876
  if (this.newestNode().type !== $.CJSX_TEXT) {
863
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CJSX_TEXT, ''));
877
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CJSX_TEXT, ''));
864
878
  }
865
879
  this.newestNode().value += this.chunk.charAt(0);
866
880
  return 1;
@@ -878,7 +892,7 @@ module.exports = Parser = (function() {
878
892
  }
879
893
  }
880
894
  if (this.newestNode().type !== $.CS) {
881
- this.addLeafNodeToActiveBranch(parseTreeLeafNode($.CS, ''));
895
+ this.addLeafNodeToActiveBranch(ParseTreeLeafNode($.CS, ''));
882
896
  }
883
897
  this.newestNode().value += this.chunk.charAt(0);
884
898
  return 1;
@@ -984,11 +998,11 @@ module.exports = Parser = (function() {
984
998
 
985
999
  })();
986
1000
 
987
- OPENING_TAG = /^<([-A-Za-z0-9_\.]+)((?:\s+[\w-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:{[\s\S]*?})|[^>\s]+))?)*?\s*)(\/?)>/;
1001
+ OPENING_TAG = /^<([-A-Za-z0-9_\.]+)((?:(?:(?:\s+[\w-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:{[\s\S]*?})|[^>\s]+)))|\s+[\w-]+|\s+\{\.\.\.\s*?[^\s{}]+?\s*?\})?)*?\s*)(\/?)>/;
988
1002
 
989
1003
  CLOSING_TAG = /^<\/([-A-Za-z0-9_\.]+)[^>]*>/;
990
1004
 
991
- TAG_ATTRIBUTES = /(?:([-A-Za-z0-9_]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:{((?:\\.|[\s\S])*)})|([^>\s]+)))?)|([\s\n]+)/;
1005
+ TAG_ATTRIBUTES = /(?:([-A-Za-z0-9_]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:{((?:\\.|[\s\S])*)})|([^>\s]+)))?)|(?:\{\.\.\.(\s*?[^\s{}]+?\s*?)\})|([\s\n]+)/;
992
1006
 
993
1007
  PRAGMA = /^\s*#\s*@cjsx\s+(\S*)/i;
994
1008
 
@@ -1012,9 +1026,9 @@ HEREGEX = /^\/{3}((?:\\?[\s\S])+?)\/{3}([imgy]{0,4})(?!\w)/;
1012
1026
 
1013
1027
  },{"./helpers":3,"./symbols":8}],6:[function(_dereq_,module,exports){
1014
1028
  // Generated by CoffeeScript 1.7.1
1015
- var $, HTML_ELEMENTS, SPACES_ONLY, TEXT_LEADING_WHITESPACE, TEXT_TRAILING_WHITESPACE, WHITESPACE_ONLY, containsNewlines, entityDecode, genericBranchSerialiser, genericLeafSerialiser, last, serialise, serialiseNode, serialisers, stringEscape;
1029
+ var $, HTML_ELEMENTS, SPACES_ONLY, Serialiser, TEXT_LEADING_WHITESPACE, TEXT_TRAILING_WHITESPACE, WHITESPACE_ONLY, containsNewlines, entityDecode, exports, find, firstNonWhitespaceChild, genericBranchSerialiser, genericLeafSerialiser, last, nodeSerialisers, serialise, stringEscape, _ref;
1016
1030
 
1017
- last = _dereq_('./helpers').last;
1031
+ _ref = _dereq_('./helpers'), last = _ref.last, find = _ref.find;
1018
1032
 
1019
1033
  $ = _dereq_('./symbols');
1020
1034
 
@@ -1024,99 +1038,87 @@ stringEscape = _dereq_('./stringescape');
1024
1038
 
1025
1039
  entityDecode = _dereq_('./entitydecode');
1026
1040
 
1027
- module.exports = serialise = function(parseTree) {
1028
- var env;
1029
- env = {
1030
- serialiseNode: serialiseNode
1031
- };
1032
- if (parseTree.children && parseTree.children.length && parseTree.children[0].type === $.CJSX_PRAGMA) {
1033
- env.domObject = parseTree.children[0].value;
1034
- } else {
1035
- env.domObject = 'React.DOM';
1036
- }
1037
- return env.serialiseNode(parseTree);
1041
+ module.exports = exports = serialise = function(parseTree) {
1042
+ return new Serialiser().serialise(parseTree);
1038
1043
  };
1039
1044
 
1040
- serialiseNode = function(node) {
1041
- var serialised;
1042
- if (serialisers[node.type] == null) {
1043
- throw new Error("unknown parseTree node type " + node.type);
1044
- }
1045
- serialised = serialisers[node.type](node, this);
1046
- if (!(typeof serialised === 'string' || serialised === null)) {
1047
- throw new Error("serialiser " + node.type + " didn\'t return a string");
1048
- }
1049
- return serialised;
1050
- };
1045
+ Serialiser = (function() {
1046
+ function Serialiser() {}
1051
1047
 
1052
- genericBranchSerialiser = function(node, env) {
1053
- return node.children.map(function(child) {
1054
- return env.serialiseNode(child);
1055
- }).join('');
1056
- };
1048
+ Serialiser.prototype.serialise = function(parseTree) {
1049
+ if (parseTree.children && parseTree.children.length && parseTree.children[0].type === $.CJSX_PRAGMA) {
1050
+ this.domObject = parseTree.children[0].value;
1051
+ } else {
1052
+ this.domObject = 'React.DOM';
1053
+ }
1054
+ return this.serialiseNode(parseTree);
1055
+ };
1057
1056
 
1058
- genericLeafSerialiser = function(node, env) {
1059
- return node.value;
1060
- };
1057
+ Serialiser.prototype.serialiseNode = function(node) {
1058
+ var serialised;
1059
+ if (nodeSerialisers[node.type] == null) {
1060
+ throw new Error("unknown parseTree node type " + node.type);
1061
+ }
1062
+ serialised = nodeSerialisers[node.type].call(this, node);
1063
+ if (!(typeof serialised === 'string' || serialised === null)) {
1064
+ throw new Error("serialiser " + node.type + " didn\'t return a string");
1065
+ }
1066
+ return serialised;
1067
+ };
1061
1068
 
1062
- serialise.serialisers = serialisers = {
1063
- ROOT: genericBranchSerialiser,
1064
- CJSX_PRAGMA: function() {
1065
- return null;
1066
- },
1067
- CJSX_EL: function(node, env) {
1068
- var accumulatedWhitespace, child, prefix, serialisedChild, serialisedChildren, _i, _len, _ref;
1069
- serialisedChildren = [];
1070
- accumulatedWhitespace = '';
1071
- _ref = node.children;
1072
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1073
- child = _ref[_i];
1074
- serialisedChild = env.serialiseNode(child);
1075
- if (child != null) {
1076
- if (WHITESPACE_ONLY.test(serialisedChild)) {
1077
- accumulatedWhitespace += serialisedChild;
1078
- } else {
1079
- serialisedChildren.push(accumulatedWhitespace + serialisedChild);
1080
- accumulatedWhitespace = '';
1069
+ Serialiser.prototype.serialiseSpreadAndPairAttributes = function(children) {
1070
+ var assigns, child, childIndex, flushPairs, pairAttrsBuffer, _i, _len, _ref1;
1071
+ assigns = [];
1072
+ pairAttrsBuffer = [];
1073
+ flushPairs = (function(_this) {
1074
+ return function() {
1075
+ var serialisedChild;
1076
+ if (pairAttrsBuffer.length) {
1077
+ serialisedChild = _this.serialiseAttributePairs(pairAttrsBuffer);
1078
+ if (serialisedChild) {
1079
+ assigns.push(serialisedChild);
1080
+ }
1081
+ return pairAttrsBuffer = [];
1081
1082
  }
1082
- }
1083
+ };
1084
+ })(this);
1085
+ if (((_ref1 = firstNonWhitespaceChild(children)) != null ? _ref1.type : void 0) === $.CJSX_ATTR_SPREAD) {
1086
+ assigns.push('{}');
1083
1087
  }
1084
- if (serialisedChildren.length) {
1085
- serialisedChildren[serialisedChildren.length - 1] += accumulatedWhitespace;
1086
- accumulatedWhitespace = '';
1088
+ for (childIndex = _i = 0, _len = children.length; _i < _len; childIndex = ++_i) {
1089
+ child = children[childIndex];
1090
+ if (child.type === $.CJSX_ATTR_SPREAD) {
1091
+ flushPairs();
1092
+ assigns.push(child.value);
1093
+ } else {
1094
+ pairAttrsBuffer.push(child);
1095
+ }
1096
+ flushPairs();
1087
1097
  }
1088
- prefix = HTML_ELEMENTS[node.value] != null ? env.domObject + '.' : '';
1089
- return prefix + node.value + '(' + serialisedChildren.join(', ') + ')';
1090
- },
1091
- CJSX_ESC: function(node, env) {
1092
- var childrenSerialised;
1093
- childrenSerialised = node.children.map(function(child) {
1094
- return env.serialiseNode(child);
1095
- }).join('');
1096
- return '(' + childrenSerialised + ')';
1097
- },
1098
- CJSX_ATTRIBUTES: function(node, env) {
1099
- var child, childIndex, indexOfLastSemanticChild, isBeforeLastSemanticChild, semanticChildren, serialisedChild, serialisedChildren, whitespaceChildren, _ref;
1100
- _ref = node.children.reduce(function(partitionedChildren, child) {
1098
+ return "Object.assign(" + (assigns.join(', ')) + ")";
1099
+ };
1100
+
1101
+ Serialiser.prototype.serialiseAttributePairs = function(children) {
1102
+ var child, childIndex, indexOfLastSemanticChild, isBeforeLastSemanticChild, semanticChildren, serialisedChild, serialisedChildren, whitespaceChildren, _ref1;
1103
+ _ref1 = children.reduce(function(partitionedChildren, child) {
1101
1104
  if (child.type === $.CJSX_WHITESPACE) {
1102
1105
  partitionedChildren[0].push(child);
1103
1106
  } else {
1104
1107
  partitionedChildren[1].push(child);
1105
1108
  }
1106
1109
  return partitionedChildren;
1107
- }, [[], []]), whitespaceChildren = _ref[0], semanticChildren = _ref[1];
1108
- indexOfLastSemanticChild = node.children.lastIndexOf(last(semanticChildren));
1110
+ }, [[], []]), whitespaceChildren = _ref1[0], semanticChildren = _ref1[1];
1111
+ indexOfLastSemanticChild = children.lastIndexOf(last(semanticChildren));
1109
1112
  isBeforeLastSemanticChild = function(childIndex) {
1110
1113
  return childIndex < indexOfLastSemanticChild;
1111
1114
  };
1112
1115
  if (semanticChildren.length) {
1113
1116
  serialisedChildren = (function() {
1114
- var _i, _len, _ref1, _results;
1115
- _ref1 = node.children;
1117
+ var _i, _len, _results;
1116
1118
  _results = [];
1117
- for (childIndex = _i = 0, _len = _ref1.length; _i < _len; childIndex = ++_i) {
1118
- child = _ref1[childIndex];
1119
- serialisedChild = env.serialiseNode(child);
1119
+ for (childIndex = _i = 0, _len = children.length; _i < _len; childIndex = ++_i) {
1120
+ child = children[childIndex];
1121
+ serialisedChild = this.serialiseNode(child);
1120
1122
  if (child.type === $.CJSX_WHITESPACE) {
1121
1123
  if (containsNewlines(serialisedChild)) {
1122
1124
  if (isBeforeLastSemanticChild(childIndex)) {
@@ -1134,16 +1136,85 @@ serialise.serialisers = serialisers = {
1134
1136
  }
1135
1137
  }
1136
1138
  return _results;
1137
- })();
1139
+ }).call(this);
1138
1140
  return '{' + serialisedChildren.join('') + '}';
1139
1141
  } else {
1140
- return 'null';
1142
+ return null;
1143
+ }
1144
+ };
1145
+
1146
+ return Serialiser;
1147
+
1148
+ })();
1149
+
1150
+ genericBranchSerialiser = function(node) {
1151
+ return node.children.map((function(_this) {
1152
+ return function(child) {
1153
+ return _this.serialiseNode(child);
1154
+ };
1155
+ })(this)).join('');
1156
+ };
1157
+
1158
+ genericLeafSerialiser = function(node) {
1159
+ return node.value;
1160
+ };
1161
+
1162
+ nodeSerialisers = {
1163
+ ROOT: genericBranchSerialiser,
1164
+ CJSX_PRAGMA: function() {
1165
+ return null;
1166
+ },
1167
+ CJSX_EL: function(node) {
1168
+ var accumulatedWhitespace, child, prefix, serialisedChild, serialisedChildren, _i, _len, _ref1;
1169
+ serialisedChildren = [];
1170
+ accumulatedWhitespace = '';
1171
+ _ref1 = node.children;
1172
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1173
+ child = _ref1[_i];
1174
+ serialisedChild = this.serialiseNode(child);
1175
+ if (child != null) {
1176
+ if (WHITESPACE_ONLY.test(serialisedChild)) {
1177
+ accumulatedWhitespace += serialisedChild;
1178
+ } else {
1179
+ serialisedChildren.push(accumulatedWhitespace + serialisedChild);
1180
+ accumulatedWhitespace = '';
1181
+ }
1182
+ }
1183
+ }
1184
+ if (serialisedChildren.length) {
1185
+ serialisedChildren[serialisedChildren.length - 1] += accumulatedWhitespace;
1186
+ accumulatedWhitespace = '';
1187
+ }
1188
+ prefix = HTML_ELEMENTS[node.value] != null ? this.domObject + '.' : '';
1189
+ return prefix + node.value + '(' + serialisedChildren.join(', ') + ')';
1190
+ },
1191
+ CJSX_ESC: function(node) {
1192
+ var childrenSerialised;
1193
+ childrenSerialised = node.children.map((function(_this) {
1194
+ return function(child) {
1195
+ return _this.serialiseNode(child);
1196
+ };
1197
+ })(this)).join('');
1198
+ return '(' + childrenSerialised + ')';
1199
+ },
1200
+ CJSX_ATTRIBUTES: function(node) {
1201
+ if (node.children.some(function(child) {
1202
+ return child.type === $.CJSX_ATTR_SPREAD;
1203
+ })) {
1204
+ return this.serialiseSpreadAndPairAttributes(node.children);
1205
+ } else {
1206
+ return this.serialiseAttributePairs(node.children) || 'null';
1141
1207
  }
1142
1208
  },
1143
- CJSX_ATTR_PAIR: function(node, env) {
1144
- return node.children.map(function(child) {
1145
- return env.serialiseNode(child);
1146
- }).join(': ');
1209
+ CJSX_ATTR_PAIR: function(node) {
1210
+ return node.children.map((function(_this) {
1211
+ return function(child) {
1212
+ return _this.serialiseNode(child);
1213
+ };
1214
+ })(this)).join(': ');
1215
+ },
1216
+ CJSX_ATTR_SPREAD: function(node) {
1217
+ return node.value;
1147
1218
  },
1148
1219
  CS: genericLeafSerialiser,
1149
1220
  CS_COMMENT: genericLeafSerialiser,
@@ -1190,6 +1261,12 @@ serialise.serialisers = serialisers = {
1190
1261
  CJSX_ATTR_VAL: genericLeafSerialiser
1191
1262
  };
1192
1263
 
1264
+ firstNonWhitespaceChild = function(children) {
1265
+ return find.call(children, function(child) {
1266
+ return child.type !== $.CJSX_WHITESPACE;
1267
+ });
1268
+ };
1269
+
1193
1270
  containsNewlines = function(text) {
1194
1271
  return text.indexOf('\n') > -1;
1195
1272
  };
@@ -1202,6 +1279,10 @@ TEXT_LEADING_WHITESPACE = /^\s*?\n\s*/;
1202
1279
 
1203
1280
  TEXT_TRAILING_WHITESPACE = /\s*?\n\s*?$/;
1204
1281
 
1282
+ exports.Serialiser = Serialiser;
1283
+
1284
+ exports.nodeSerialisers = nodeSerialisers;
1285
+
1205
1286
  },{"./entitydecode":2,"./helpers":3,"./htmlelements":4,"./stringescape":7,"./symbols":8}],7:[function(_dereq_,module,exports){
1206
1287
 
1207
1288
  var hex = '0123456789abcdef'.split('');
@@ -1275,6 +1356,7 @@ module.exports = {
1275
1356
  CJSX_TEXT: 'CJSX_TEXT',
1276
1357
  CJSX_ATTR_KEY: 'CJSX_ATTR_KEY',
1277
1358
  CJSX_ATTR_VAL: 'CJSX_ATTR_VAL',
1359
+ CJSX_ATTR_SPREAD: 'CJSX_ATTR_SPREAD',
1278
1360
  CJSX_START: 'CJSX_START',
1279
1361
  CJSX_END: 'CJSX_END',
1280
1362
  CJSX_ESC_START: 'CJSX_ESC_START',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Friend
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs