Skip to content
This repository
Browse code

allow expressions for super classes: class X extends require(../lib).…

…expr
  • Loading branch information...
commit 0500bffb346c84a518d778d4ace0d278b4224148 1 parent a6b772e
weepy authored July 26, 2011
7  History.md
Source Rendered
... ...
@@ -1,3 +1,6 @@
1  
-Version 0.1.5
  1
+0.1.6
  2
+* class followed by : is converted to 'class'
  3
+* allow expressions for super classes: class X extends require("../lib").expr
2 4
 
3  
-* removed block scope plugin
  5
+Version 0.1.5
  6
+* removed block scope plugin
9  expectations/_TODO
... ...
@@ -1,5 +1,14 @@
  1
+compiles: 
  2
+
  3
+(1/2 + (1/2))
  4
+
  5
+to:
  6
+
  7
+(1/2 + (1/2))
  8
+
1 9
 compiles:
2 10
 
  11
+
3 12
 for i of 10|range
4 13
   100
5 14
   
21  expectations/_tmp
... ...
@@ -1,5 +1,16 @@
1  
-String::splice ||= (i, del, str) -> {
2  
-  chars = @split ""
3  
-  Array::splice.apply chars, arguments
4  
-  return chars.join ""
5  
-} 
  1
+compiles:
  2
+
  3
+
  4
+-> {
  5
+  $ {
  6
+    html: { class: "highlights"}
  7
+  }
  8
+}
  9
+
  10
+
  11
+
  12
+
  13
+
  14
+to:
  15
+
  16
+x
18  expectations/class
@@ -178,3 +178,21 @@ function __extends(child, parent) {
178 178
   return child;
179 179
 }
180 180
 
  181
+compiles:
  182
+
  183
+class Rook extends require("../piece").piece
  184
+
  185
+to:
  186
+
  187
+function Rook(){ Rook.__super__.constructor.apply(this, arguments);}; __extends(Rook, require("../piece").piece); 
  188
+
  189
+function __extends(child, parent) {
  190
+  var __hasProp = Object.prototype.hasOwnProperty;
  191
+  for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
  192
+  function ctor() { this.constructor = child; }
  193
+  ctor.prototype = parent.prototype;
  194
+  child.prototype = new ctor;
  195
+  child.__super__ = parent.prototype;
  196
+  return child;
  197
+}
  198
+
2  expectations/stacks
@@ -212,3 +212,5 @@ to:
212 212
 {
213 213
  xx
214 214
 }
  215
+
  216
+
2  lib/index.js
@@ -5,7 +5,7 @@ function Kaffeine(options) {
5 5
 }
6 6
 
7 7
 Kaffeine.fn = Kaffeine.prototype;
8  
-Kaffeine.VERSION = "0.0.6";
  8
+Kaffeine.VERSION = "0.1.6";
9 9
 Kaffeine.plugins = {};
10 10
 
11 11
 //unless brackets_for_keywords reverse_blocks indented_blocks
25  lib/plugins/class.js
@@ -7,12 +7,14 @@ var Token = require("../token");
7 7
 module.exports = function(stream) {
8 8
   var insert = false
9 9
 
10  
-//    console.log(stream.collectText())
11  
-
12 10
   stream.each(function() {
13 11
     Token.current_token = this
14 12
     
15 13
     if(this.text != "class") return 
  14
+    if(this.nextNW().text == ":") {
  15
+      this.text = "'class'"
  16
+      return
  17
+    }
16 18
     
17 19
     this.text = "function"
18 20
      
@@ -30,19 +32,22 @@ module.exports = function(stream) {
30 32
 
31 33
     var next = x.next.matching.nextNW()
32 34
 
33  
-
34  
-    // console.log(next.text, next.next.next.text)
35 35
     var super_class_name = null
36 36
 
37 37
     if(next.text == "extends") {
38 38
       insert = insert_extends = true
39 39
 
40 40
       var super_class = next.next.next
41  
-      super_class_name = super_class.text
42  
-      //console.log("super_class.text", super_class.text)
43  
-
44  
-      var after = super_class.nextNW()
45  
-      next.remove(super_class)
  41
+      var end = super_class.expressionEnd()
  42
+      
  43
+      var after = end.nextNW()
  44
+      super_class_name = super_class.collectText(end)
  45
+      // console.log(super_class.text, end.text, "XXXXXXXXXXXXXX")
  46
+      // console.log(super_class_name)
  47
+      var expr = super_class.remove(end)
  48
+      
  49
+      next.next.remove()
  50
+      next.remove()
46 51
       next = after
47 52
     }
48 53
     
@@ -57,7 +62,7 @@ module.exports = function(stream) {
57 62
 
58 63
     if(!curly.matching.next.semi) curly.matching.after(";")
59 64
     if(insert_extends)
60  
-      curly.matching.next.after(" __extends(" + class_name + ", "+ super_class.text + ");")
  65
+      curly.matching.next.after(" __extends(" + class_name + ", "+ super_class_name + ");")
61 66
 
62 67
     curly.updateBlock()
63 68
     curly.class_name = class_name;
2  lib/token.js
@@ -66,7 +66,7 @@ function postprocess(stream) {
66 66
   
67 67
   // match brackets
68 68
   var stack = []
69  
-  stream.each(function() { 
  69
+  stream.each(function() {  
70 70
     if(this.bracket)  
71 71
       if(this.lbracket) 
72 72
         stack.push(this)
2  package.json
... ...
@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "kaffeine",
3  
-  "version": "0.1.5",
  3
+  "version": "0.1.6",
4 4
   "description": "Enhanced Syntax for Javascript",
5 5
   "keywords": ["javascript", "language", "compiler", "coffeescript", "altjs"],
6 6
   "author": "weepy",

0 notes on commit 0500bff

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