client-server command are done

This commit is contained in:
Dan Onoshko 2015-01-02 01:22:07 +07:00
parent 6b7f7acd46
commit ff5f1ec141
3 changed files with 21 additions and 11 deletions

View File

@ -547,7 +547,7 @@ Future plans
console.log(name);
}, this);
- `@use client` and `@use server` commands
- static typing
- `@use` expressions

View File

@ -1253,7 +1253,7 @@ Cola.Parser.prototype.statement = Cola.Parser.embed_tokens(function() {
if (!this.is("name")) this.unexpected();
args.push(this.S.token.value);
if (this.S.token.value == 'closure') {
if (this.S.token.value == 'closure' || this.S.token.value == 'server' || this.S.token.value == 'client') {
this.next();
args.push(this.is("punc","{"), new Cola.AST_BlockStatement({
start : this.S.token,

View File

@ -3261,22 +3261,32 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
argnames : []
});
if (node.args[1]){
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
props = new Cola.AST_Dot({
expression : props,
property : "apply"
});
}
node = new Cola.AST_Call({
args : node.args[1] ? [new Cola.AST_SymbolRef({ name : "this" }), new Cola.AST_SymbolRef({ name : "arguments" })] : [],
args : [new Cola.AST_SymbolRef({ name : "this" }), new Cola.AST_SymbolRef({ name : "arguments" })],
expression : props
});
node = new Cola.AST_SimpleStatement({ body : node });
} else
if (node.args[0] == "client") {
if (options.is_node) return false;
node = new Cola.AST_BlockStatement({ body: node.args[2].body });
} else
if (node.args[0] == "server") {
if (!options.is_node) return false;
node = new Cola.AST_BlockStatement({ body: node.args[2].body });
} else
node = new Cola.AST_Directive({ value : "use " + node.args[0] });
}