Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Commit

Permalink
class and conditional postfix fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Jan 12, 2015
1 parent a503901 commit 3ea321f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cola-script",
"version": "0.8.17",
"version": "0.8.18",
"homepage": "https://github.com/TrigenSoftware/ColaScript",
"authors": [
"Onoshko Dan"
Expand Down
16 changes: 8 additions & 8 deletions lib/browser-cola.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<label for="is_meteor">meteor</label>
<input type="checkbox" id="compressed" onclick="changeClass()">
<label for="compressed">compressed</label>
<span id="version">v0.8.17</span>
<span id="version">v0.8.18</span>
<span id="lenstat"></span>
</div>
</body>
Expand Down
9 changes: 8 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,13 @@ Cola.Parser.prototype.semicolon = function () {
else if (!this.can_insert_semicolon()) this.unexpected();
};

Cola.Parser.prototype.next_is_semicolon = function () {
if (this.next_is("punc", ";")) return true;
return !this.options.strict && (
this.peek().nlb || this.next_is("eof") || this.next_is("punc", "}")
);
};

Cola.Parser.prototype.parenthesised = function (inline) {
var brackets = this.is("punc", "(");
if (this.is_js || brackets) this.expect("(");
Expand Down Expand Up @@ -2629,7 +2636,7 @@ Cola.Parser.prototype.maybe_unary = function(allow_calls) {

while (this.is("operator") && this.UNARY_POSTFIX(this.S.token.value) && !this.S.token.nlb) {
if(!this.is_js && this.is("operator", "?") &&
!(this.next_is("punc", ";") || this.next_is("punc", ",") || this.next_is("punc", ":") ||
!(this.next_is_semicolon() || this.next_is("punc", ",") || this.next_is("punc", ":") ||
this.next_is("punc", ")") || this.next_is("punc", "]") || this.next_is("punc", "}") ||
this.next_is("operator", "?") || this.next_is("operator") && this.PRECEDENCE[this.peek().value] ||
this.S.in_condition && this.next_is("punc", "{"))) break;
Expand Down
28 changes: 28 additions & 0 deletions lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
self.body = self.body.transform(tw);
});

// ColaScript
_(Cola.AST_ForOf, function(self, tw){
self.init = self.init.transform(tw);
self.object = self.object.transform(tw);
self.body = self.body.transform(tw);
});

_(Cola.AST_With, function(self, tw){
self.expression = self.expression.transform(tw);
self.body = self.body.transform(tw);
Expand Down Expand Up @@ -197,6 +204,16 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
self.property = self.property.transform(tw);
});

// ColaScript
_(Cola.AST_Proto, function(self, tw){
self.expression = self.expression.transform(tw);
});

// ColaScript
_(Cola.AST_CondAccess, function(self, tw){
self.expression = self.expression.transform(tw);
});

_(Cola.AST_Unary, function(self, tw){
self.expression = self.expression.transform(tw);
});
Expand All @@ -216,6 +233,12 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
self.elements = do_list(self.elements, tw);
});

// ColaScript
_(Cola.AST_ArrayRange, function(self, tw){
self.from = self.from.transform(tw);
self.to = self.to.transform(tw);
});

_(Cola.AST_Object, function(self, tw){
self.properties = do_list(self.properties, tw);
});
Expand All @@ -224,4 +247,9 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
self.value = self.value.transform(tw);
});

// ColaScript
_(Cola.AST_StringTemplate, function(self, tw){
self.body = do_list(self.body, tw);
});

})();
92 changes: 92 additions & 0 deletions lib/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,98 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
var tmembers, tscope, tlvl, tself_def;
member = member.clone();

// @todo("move to separated function")
if (member instanceof Cola.AST_Cascade) {
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;

var props = {
type : "dynamic",
body : [],
argnames : [new Cola.AST_ArgDef({
argtype : "positional",
type : "dynamic",
defval : new Cola.AST_Noop(),
name : new Cola.AST_SymbolFunarg({ name : "_ColaRuntime$$expr", start : member.expression.start, end : member.expression.end })
}), new Cola.AST_ArgDef({
argtype : "positional",
type : "dynamic",
defval : new Cola.AST_Noop(),
name : new Cola.AST_SymbolFunarg({ name : "arguments", start : new Cola.AST_Token(), end : new Cola.AST_Token() })
})]
};

var Expr, Parent = false;
member.subexpressions.forEach(function(expr){
Expr = expr, Parent = false;
while(true)
if( expr instanceof Cola.AST_Call || expr instanceof Cola.AST_PropAccess){
Parent = expr;
expr = expr.expression;
} else
if(expr instanceof Cola.AST_Binary){
Parent = expr;
expr = expr.left;
} else
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange || expr instanceof Cola.AST_SymbolRef) break;

if(!Parent){
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange) Expr = new Cola.AST_Sub({
start : Expr.start,
end : Expr.end,
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
}); else
if(expr instanceof Cola.AST_SymbolRef) Expr = new Cola.AST_Dot({
start : Expr.start,
end : Expr.end,
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : Expr.name
});
} else {
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange)
expr = new Cola.AST_Sub({
start : expr.start,
end : expr.end,
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
});
else
expr = new Cola.AST_Dot({
start : expr.start,
end : expr.end,
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr.name
});

if( Parent instanceof Cola.AST_Call || Parent instanceof Cola.AST_PropAccess) Parent.expression = expr;
else
if(Parent instanceof Cola.AST_Binary) Parent.left = expr;
}

props.body.push(new Cola.AST_SimpleStatement({
start : Expr.start,
end : Expr.end,
body : Expr
}));
});

props.body.push(new Cola.AST_Return({
value : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" })
}));

props = {
expression : new Cola.AST_Function(props),
property : "call"
};

member = new Cola.AST_Call({
start : member.start,
end : member.end,
args : [new Cola.AST_SymbolRef({ name : "this" }), member.expression, new Cola.AST_SymbolRef({ name : "arguments" })],
expression : new Cola.AST_Dot(props)
});
}

if (member instanceof Cola.AST_Lambda) {
member.argnames.forEach(function(argDef) {
if(argDef.name instanceof Cola.AST_Symbol && hmembers.indexOf(argDef.name.name) != -1)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"cola-script"
],
"main": "tools/node.js",
"version": "0.8.17",
"version": "0.8.18",
"engines": { "node" : ">=0.4.0" },
"maintainers": [{
"name": "Dan Onoshko (dangreen)",
Expand Down

0 comments on commit 3ea321f

Please sign in to comment.