Thanks to visit codestin.com
Credit goes to github.com

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

Commit 3ea321f

Browse files
committed
class and conditional postfix fix
1 parent a503901 commit 3ea321f

7 files changed

Lines changed: 139 additions & 12 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cola-script",
3-
"version": "0.8.17",
3+
"version": "0.8.18",
44
"homepage": "https://github.com/TrigenSoftware/ColaScript",
55
"authors": [
66
"Onoshko Dan"

lib/browser-cola.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
<label for="is_meteor">meteor</label>
223223
<input type="checkbox" id="compressed" onclick="changeClass()">
224224
<label for="compressed">compressed</label>
225-
<span id="version">v0.8.17</span>
225+
<span id="version">v0.8.18</span>
226226
<span id="lenstat"></span>
227227
</div>
228228
</body>

lib/parse.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,13 @@ Cola.Parser.prototype.semicolon = function () {
10101010
else if (!this.can_insert_semicolon()) this.unexpected();
10111011
};
10121012

1013+
Cola.Parser.prototype.next_is_semicolon = function () {
1014+
if (this.next_is("punc", ";")) return true;
1015+
return !this.options.strict && (
1016+
this.peek().nlb || this.next_is("eof") || this.next_is("punc", "}")
1017+
);
1018+
};
1019+
10131020
Cola.Parser.prototype.parenthesised = function (inline) {
10141021
var brackets = this.is("punc", "(");
10151022
if (this.is_js || brackets) this.expect("(");
@@ -2629,7 +2636,7 @@ Cola.Parser.prototype.maybe_unary = function(allow_calls) {
26292636

26302637
while (this.is("operator") && this.UNARY_POSTFIX(this.S.token.value) && !this.S.token.nlb) {
26312638
if(!this.is_js && this.is("operator", "?") &&
2632-
!(this.next_is("punc", ";") || this.next_is("punc", ",") || this.next_is("punc", ":") ||
2639+
!(this.next_is_semicolon() || this.next_is("punc", ",") || this.next_is("punc", ":") ||
26332640
this.next_is("punc", ")") || this.next_is("punc", "]") || this.next_is("punc", "}") ||
26342641
this.next_is("operator", "?") || this.next_is("operator") && this.PRECEDENCE[this.peek().value] ||
26352642
this.S.in_condition && this.next_is("punc", "{"))) break;

lib/transform.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
123123
self.body = self.body.transform(tw);
124124
});
125125

126+
// ColaScript
127+
_(Cola.AST_ForOf, function(self, tw){
128+
self.init = self.init.transform(tw);
129+
self.object = self.object.transform(tw);
130+
self.body = self.body.transform(tw);
131+
});
132+
126133
_(Cola.AST_With, function(self, tw){
127134
self.expression = self.expression.transform(tw);
128135
self.body = self.body.transform(tw);
@@ -197,6 +204,16 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
197204
self.property = self.property.transform(tw);
198205
});
199206

207+
// ColaScript
208+
_(Cola.AST_Proto, function(self, tw){
209+
self.expression = self.expression.transform(tw);
210+
});
211+
212+
// ColaScript
213+
_(Cola.AST_CondAccess, function(self, tw){
214+
self.expression = self.expression.transform(tw);
215+
});
216+
200217
_(Cola.AST_Unary, function(self, tw){
201218
self.expression = self.expression.transform(tw);
202219
});
@@ -216,6 +233,12 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
216233
self.elements = do_list(self.elements, tw);
217234
});
218235

236+
// ColaScript
237+
_(Cola.AST_ArrayRange, function(self, tw){
238+
self.from = self.from.transform(tw);
239+
self.to = self.to.transform(tw);
240+
});
241+
219242
_(Cola.AST_Object, function(self, tw){
220243
self.properties = do_list(self.properties, tw);
221244
});
@@ -224,4 +247,9 @@ Cola.TreeTransformer.prototype.__proto__ = new Cola.TreeWalker;
224247
self.value = self.value.transform(tw);
225248
});
226249

250+
// ColaScript
251+
_(Cola.AST_StringTemplate, function(self, tw){
252+
self.body = do_list(self.body, tw);
253+
});
254+
227255
})();

lib/translate.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,98 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
17781778
var tmembers, tscope, tlvl, tself_def;
17791779
member = member.clone();
17801780

1781+
// @todo("move to separated function")
1782+
if (member instanceof Cola.AST_Cascade) {
1783+
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
1784+
1785+
var props = {
1786+
type : "dynamic",
1787+
body : [],
1788+
argnames : [new Cola.AST_ArgDef({
1789+
argtype : "positional",
1790+
type : "dynamic",
1791+
defval : new Cola.AST_Noop(),
1792+
name : new Cola.AST_SymbolFunarg({ name : "_ColaRuntime$$expr", start : member.expression.start, end : member.expression.end })
1793+
}), new Cola.AST_ArgDef({
1794+
argtype : "positional",
1795+
type : "dynamic",
1796+
defval : new Cola.AST_Noop(),
1797+
name : new Cola.AST_SymbolFunarg({ name : "arguments", start : new Cola.AST_Token(), end : new Cola.AST_Token() })
1798+
})]
1799+
};
1800+
1801+
var Expr, Parent = false;
1802+
member.subexpressions.forEach(function(expr){
1803+
Expr = expr, Parent = false;
1804+
while(true)
1805+
if( expr instanceof Cola.AST_Call || expr instanceof Cola.AST_PropAccess){
1806+
Parent = expr;
1807+
expr = expr.expression;
1808+
} else
1809+
if(expr instanceof Cola.AST_Binary){
1810+
Parent = expr;
1811+
expr = expr.left;
1812+
} else
1813+
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange || expr instanceof Cola.AST_SymbolRef) break;
1814+
1815+
if(!Parent){
1816+
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange) Expr = new Cola.AST_Sub({
1817+
start : Expr.start,
1818+
end : Expr.end,
1819+
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
1820+
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
1821+
}); else
1822+
if(expr instanceof Cola.AST_SymbolRef) Expr = new Cola.AST_Dot({
1823+
start : Expr.start,
1824+
end : Expr.end,
1825+
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
1826+
property : Expr.name
1827+
});
1828+
} else {
1829+
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange)
1830+
expr = new Cola.AST_Sub({
1831+
start : expr.start,
1832+
end : expr.end,
1833+
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
1834+
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
1835+
});
1836+
else
1837+
expr = new Cola.AST_Dot({
1838+
start : expr.start,
1839+
end : expr.end,
1840+
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
1841+
property : expr.name
1842+
});
1843+
1844+
if( Parent instanceof Cola.AST_Call || Parent instanceof Cola.AST_PropAccess) Parent.expression = expr;
1845+
else
1846+
if(Parent instanceof Cola.AST_Binary) Parent.left = expr;
1847+
}
1848+
1849+
props.body.push(new Cola.AST_SimpleStatement({
1850+
start : Expr.start,
1851+
end : Expr.end,
1852+
body : Expr
1853+
}));
1854+
});
1855+
1856+
props.body.push(new Cola.AST_Return({
1857+
value : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" })
1858+
}));
1859+
1860+
props = {
1861+
expression : new Cola.AST_Function(props),
1862+
property : "call"
1863+
};
1864+
1865+
member = new Cola.AST_Call({
1866+
start : member.start,
1867+
end : member.end,
1868+
args : [new Cola.AST_SymbolRef({ name : "this" }), member.expression, new Cola.AST_SymbolRef({ name : "arguments" })],
1869+
expression : new Cola.AST_Dot(props)
1870+
});
1871+
}
1872+
17811873
if (member instanceof Cola.AST_Lambda) {
17821874
member.argnames.forEach(function(argDef) {
17831875
if(argDef.name instanceof Cola.AST_Symbol && hmembers.indexOf(argDef.name.name) != -1)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"cola-script"
99
],
1010
"main": "tools/node.js",
11-
"version": "0.8.17",
11+
"version": "0.8.18",
1212
"engines": { "node" : ">=0.4.0" },
1313
"maintainers": [{
1414
"name": "Dan Onoshko (dangreen)",

0 commit comments

Comments
 (0)