Skip to content

Commit

Permalink
Merge pull request #33 from benekastah/master
Browse files Browse the repository at this point in the history
for x from y
  • Loading branch information
weepy committed Jun 30, 2011
2 parents 761b5a6 + 87b4431 commit ca51bcc
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 24 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions bin/command.js
Expand Up @@ -9,7 +9,9 @@ var Kaffeine = require("./kaffeine"),


function loadPlugins(source) {
console.log(source)
fs.readdir(source, function(err, files) {
console.log(err)
for(var i =0; i< files.length;i++) {
var file = files[i]
if(!file.match(/\.js$/)) continue
Expand Down
2 changes: 1 addition & 1 deletion browser2/kaffeine-browser.js
Expand Up @@ -1233,7 +1233,7 @@ require.module('./plugins/implicit_brackets', function(module, exports, require)
var Token = require("../token");

module.exports = function(stream) {
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1, "from": 1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}

stream.tail().each(function() {
var ws = this.next
Expand Down
2 changes: 1 addition & 1 deletion browser2/lib/plugins/implicit_brackets.js
Expand Up @@ -4,7 +4,7 @@ require.module('./plugins/implicit_brackets', function(module, exports, require)
var Token = require("../token");

module.exports = function(stream) {
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1,"from":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}

stream.tail().each(function() {
var ws = this.next
Expand Down
49 changes: 47 additions & 2 deletions expectations/extend_for
Expand Up @@ -20,7 +20,7 @@ for(x of [1,2,3,4]) {
}

to:
var _a, x; for(_a = 0; _a < [1,2,3,4].length; _a++) { x = [1,2,3,4][_a];
var _a, x, _b; for(_a = 0, _b = [1,2,3,4].length; _a < _b; _a++) { x = [1,2,3,4][_a];
ok()
}

Expand All @@ -29,7 +29,7 @@ for(x of [1,2,3,4])
ok()

to:
var _a, x; for(_a = 0; _a < [1,2,3,4].length; _a++) { x = [1,2,3,4][_a];
var _a, x, _b; for(_a = 0, _b = [1,2,3,4].length; _a < _b; _a++) { x = [1,2,3,4][_a];
ok() }

compiles:
Expand Down Expand Up @@ -82,3 +82,48 @@ var i, x, j, y; for(i in a) { x = a[i];
for(j in a) { y = a[j];
x } }

compiles:
for (a from n)
fn()

to:
var a; for (a in n) {if (!n.hasOwnProperty(a)) continue;
fn() }

compiles:
for (a from n) {
fn()
}

to:
var a; for (a in n) {if (!n.hasOwnProperty(a)) continue;
fn()
}

compiles:
for (i, x from a)
fn()

to:
var i, x; for (i in a) {if (!a.hasOwnProperty(i)) continue; x = a[i];
fn() }

compiles:
for (i, x from a) {
fn()
}

to:
var i, x; for (i in a) {if (!a.hasOwnProperty(i)) continue; x = a[i];
fn()
}

compiles:
for (i, x from a()) {
fn()
}

to:
var _xpr, i, x; for (i in (_xpr=a())) {if (!_xpr.hasOwnProperty(i)) continue; x = _xpr[i];
fn()
}
2 changes: 1 addition & 1 deletion expectations/stacks
Expand Up @@ -112,7 +112,7 @@ compiles:
for x of row.split ""
log letter
to:
var _xpr, _a, x; for(_a = 0; _a < (_xpr=row.split("")).length; _a++) { x = _xpr[_a];
var _xpr, _a, x, _b; for(_a = 0, _b = (_xpr=row.split("")).length; _a < _b; _a++) { x = _xpr[_a];
log(letter) }


Expand Down
33 changes: 28 additions & 5 deletions lib/plugins/extend_for.js
Expand Up @@ -16,7 +16,7 @@ module.exports = function(stream) {
bracket.next.find(function() {
if(this.next == closingBracket) return true
if(this.semi) { skip = true; return true }
if(this.word && (this.text == "in" || this.text == "of") ) loopWord = this
if(this.word && (this.text == "in" || this.text == "of" || this.text == "from") ) loopWord = this
if(this.round) complex = true
toks.push(this)
})
Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = function(stream) {
closure.vars[iter] = true
closure.vars[val] = true

} else {
} else if (loopWord.text == "of") {
brace.implied = false
brace.matching.implied = false

Expand All @@ -92,12 +92,35 @@ module.exports = function(stream) {
closure.vars[iter] = true
closure.vars[val] = true

var string = iter + " = 0; " + iter + " < " + expressionText + ".length; " + iter + "++"
bracket.after(string)
var length;
closure.vars[length = closure.getUnusedVar()] = true

var string = iter + " = 0, " + length + " = " + expressionText + ".length; " + iter + " < " + length + "; " + iter + "++"
bracket.after(string)

} else {
brace.implied = false
brace.matching.implied = false

bracket.next.remove(closingBracket.prev)

if (var2)
var2.prev.remove(var2)
iter = var1.text
closure.vars[iter] = true

if (var2) {
val = var2.text
closure.vars[val] = true
}

var string = iter + " in " + expressionText
bracket.after(string)
}

var text = " "/* + this.indent()*/ + val + " = " + (complex ? "_xpr" : expressionText) + "[" + iter + "];"
var text = ''
text += loopWord.text == "from" ? "if (!" + (complex ? "_xpr" : expressionText) + ".hasOwnProperty(" + iter + ")) continue;" : ''
text += val ? " "/* + this.indent()*/ + val + " = " + (complex ? "_xpr" : expressionText) + "[" + iter + "];" : ''

this.block.after(text)

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/implicit_brackets.js
@@ -1,7 +1,7 @@
var Token = require("../token");

module.exports = function(stream) {
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1,"from":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}

stream.tail().each(function() {
Token.current_token = this
Expand Down
49 changes: 36 additions & 13 deletions web/try/kaffeine-browser.js
Expand Up @@ -976,7 +976,7 @@ module.exports = function(stream) {
bracket.next.find(function() {
if(this.next == closingBracket) return true
if(this.semi) { skip = true; return true }
if(this.word && (this.text == "in" || this.text == "of") ) loopWord = this
if(this.word && (this.text == "in" || this.text == "of" || this.text == "from") ) loopWord = this
if(this.round) complex = true
toks.push(this)
})
Expand Down Expand Up @@ -1041,7 +1041,7 @@ module.exports = function(stream) {
closure.vars[iter] = true
closure.vars[val] = true

} else {
} else if (loopWord.text == "of") {
brace.implied = false
brace.matching.implied = false

Expand All @@ -1052,12 +1052,35 @@ module.exports = function(stream) {
closure.vars[iter] = true
closure.vars[val] = true

var string = iter + " = 0; " + iter + " < " + expressionText + ".length; " + iter + "++"
bracket.after(string)
var length;
closure.vars[length = closure.getUnusedVar()] = true

var string = iter + " = 0, " + length + " = " + expressionText + ".length; " + iter + " < " + length + "; " + iter + "++"
bracket.after(string)

} else {
brace.implied = false
brace.matching.implied = false

bracket.next.remove(closingBracket.prev)

if (var2)
var2.prev.remove(var2)
iter = var1.text
closure.vars[iter] = true

if (var2) {
val = var2.text
closure.vars[val] = true
}

var string = iter + " in " + expressionText
bracket.after(string)
}

var text = " "/* + this.indent()*/ + val + " = " + (complex ? "_xpr" : expressionText) + "[" + iter + "];"
var text = ''
text += loopWord.text == "from" ? "if (!" + (complex ? "_xpr" : expressionText) + ".hasOwnProperty(" + iter + ")) continue;" : ''
text += val ? " "/* + this.indent()*/ + val + " = " + (complex ? "_xpr" : expressionText) + "[" + iter + "];" : ''

this.block.after(text)

Expand Down Expand Up @@ -1118,7 +1141,7 @@ require.register('kaffeine/plugins/implicit_brackets.js', function(module, expor
var Token = require("../token");

module.exports = function(stream) {
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}
var nobrackets_keywords = {"for":1, "if":1, "while": 1, "new":1,"return":1,"var":1,"throw":1, "in":1,"of":1,"from":1, "typeof":1, "instanceof":1, "else": 1, "try":1, "catch": 1, "class": 1}

stream.tail().each(function() {
Token.current_token = this
Expand Down Expand Up @@ -1681,14 +1704,14 @@ module.exports = function(stream) {

var curly = this

var super = curly.next.find(function() {
var _super = curly.next.find(function() {
if(this.text == "super") return true
if(this.matching == curly) return false
if(this.blockType == "function") return this.matching.next
})

if(super) {
var brack = super.nextNW()
if(_super) {
var brack = _super.nextNW()

if(brack.lbracket) {

Expand All @@ -1698,13 +1721,13 @@ module.exports = function(stream) {
brack.before(".call")
}
else {
super.after("(this, arguments)")
brack = super.nextNW()
_super.after("(this, arguments)")
brack = _super.nextNW()
brack.before(".apply")
}

if(this.class_name) {
super.replaceWith(this.class_name + ".__super__.constructor")
_super.replaceWith(this.class_name + ".__super__.constructor")
} else {

var eq = curly.blockTypeNode.prevNW()
Expand All @@ -1719,7 +1742,7 @@ module.exports = function(stream) {
} else {
caller = text + ".constructor" //replace(/\.$/,"")
}
super.replaceWith(caller + ".__super__." + method.text )
_super.replaceWith(caller + ".__super__." + method.text )
}
}
else {
Expand Down

0 comments on commit ca51bcc

Please sign in to comment.