Permalink
Browse files

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

…expr
  • Loading branch information...
1 parent a6b772e commit 0500bffb346c84a518d778d4ace0d278b4224148 @weepy committed Jul 26, 2011
Showing with 68 additions and 20 deletions.
  1. +5 −2 History.md
  2. +9 −0 expectations/_TODO
  3. +16 −5 expectations/_tmp
  4. +18 −0 expectations/class
  5. +2 −0 expectations/stacks
  6. +1 −1 lib/index.js
  7. +15 −10 lib/plugins/class.js
  8. +1 −1 lib/token.js
  9. +1 −1 package.json
View
7 History.md
@@ -1,3 +1,6 @@
-Version 0.1.5
+0.1.6
+* class followed by : is converted to 'class'
+* allow expressions for super classes: class X extends require("../lib").expr
-* removed block scope plugin
+Version 0.1.5
+* removed block scope plugin
View
9 expectations/_TODO
@@ -1,5 +1,14 @@
+compiles:
+
+(1/2 + (1/2))
+
+to:
+
+(1/2 + (1/2))
+
compiles:
+
for i of 10|range
100
View
21 expectations/_tmp
@@ -1,5 +1,16 @@
-String::splice ||= (i, del, str) -> {
- chars = @split ""
- Array::splice.apply chars, arguments
- return chars.join ""
-}
+compiles:
+
+
+-> {
+ $ {
+ html: { class: "highlights"}
+ }
+}
+
+
+
+
+
+to:
+
+x
View
18 expectations/class
@@ -178,3 +178,21 @@ function __extends(child, parent) {
return child;
}
+compiles:
+
+class Rook extends require("../piece").piece
+
+to:
+
+function Rook(){ Rook.__super__.constructor.apply(this, arguments);}; __extends(Rook, require("../piece").piece);
+
+function __extends(child, parent) {
+ var __hasProp = Object.prototype.hasOwnProperty;
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
+ function ctor() { this.constructor = child; }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor;
+ child.__super__ = parent.prototype;
+ return child;
+}
+
View
2 expectations/stacks
@@ -212,3 +212,5 @@ to:
{
xx
}
+
+
View
2 lib/index.js
@@ -5,7 +5,7 @@ function Kaffeine(options) {
}
Kaffeine.fn = Kaffeine.prototype;
-Kaffeine.VERSION = "0.0.6";
+Kaffeine.VERSION = "0.1.6";
Kaffeine.plugins = {};
//unless brackets_for_keywords reverse_blocks indented_blocks
View
25 lib/plugins/class.js
@@ -7,12 +7,14 @@ var Token = require("../token");
module.exports = function(stream) {
var insert = false
-// console.log(stream.collectText())
-
stream.each(function() {
Token.current_token = this
if(this.text != "class") return
+ if(this.nextNW().text == ":") {
+ this.text = "'class'"
+ return
+ }
this.text = "function"
@@ -30,19 +32,22 @@ module.exports = function(stream) {
var next = x.next.matching.nextNW()
-
- // console.log(next.text, next.next.next.text)
var super_class_name = null
if(next.text == "extends") {
insert = insert_extends = true
var super_class = next.next.next
- super_class_name = super_class.text
- //console.log("super_class.text", super_class.text)
-
- var after = super_class.nextNW()
- next.remove(super_class)
+ var end = super_class.expressionEnd()
+
+ var after = end.nextNW()
+ super_class_name = super_class.collectText(end)
+ // console.log(super_class.text, end.text, "XXXXXXXXXXXXXX")
+ // console.log(super_class_name)
+ var expr = super_class.remove(end)
+
+ next.next.remove()
+ next.remove()
next = after
}
@@ -57,7 +62,7 @@ module.exports = function(stream) {
if(!curly.matching.next.semi) curly.matching.after(";")
if(insert_extends)
- curly.matching.next.after(" __extends(" + class_name + ", "+ super_class.text + ");")
+ curly.matching.next.after(" __extends(" + class_name + ", "+ super_class_name + ");")
curly.updateBlock()
curly.class_name = class_name;
View
2 lib/token.js
@@ -66,7 +66,7 @@ function postprocess(stream) {
// match brackets
var stack = []
- stream.each(function() {
+ stream.each(function() {
if(this.bracket)
if(this.lbracket)
stack.push(this)
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "kaffeine",
- "version": "0.1.5",
+ "version": "0.1.6",
"description": "Enhanced Syntax for Javascript",
"keywords": ["javascript", "language", "compiler", "coffeescript", "altjs"],
"author": "weepy",

0 comments on commit 0500bff

Please sign in to comment.