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); console.log(name);
}, this); }, this);
- `@use client` and `@use server` commands
- static typing - static typing
- `@use` expressions - `@use` expressions

View File

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

View File

@ -3261,22 +3261,32 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
argnames : [] argnames : []
}); });
if (node.args[1]){
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
props = new Cola.AST_Dot({ _ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
expression : props,
property : "apply" props = new Cola.AST_Dot({
}); expression : props,
} property : "apply"
});
node = new Cola.AST_Call({ 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 expression : props
}); });
node = new Cola.AST_SimpleStatement({ body : node }); node = new Cola.AST_SimpleStatement({ body : node });
} else } 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] }); node = new Cola.AST_Directive({ value : "use " + node.args[0] });
} }