From ff5f1ec141ec1120f4c75060e9dbec2efce07f9c Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Fri, 2 Jan 2015 01:22:07 +0700 Subject: [PATCH] client-server command are done --- README.md | 2 +- lib/parse.js | 2 +- lib/translate.js | 28 +++++++++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7ee1d5ef..d46fed88 100644 --- a/README.md +++ b/README.md @@ -547,7 +547,7 @@ Future plans console.log(name); }, this); - +- `@use client` and `@use server` commands - static typing - `@use` expressions diff --git a/lib/parse.js b/lib/parse.js index b70d07af..bfdf1298 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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, diff --git a/lib/translate.js b/lib/translate.js index 6ad136d5..92b1cd83 100644 --- a/lib/translate.js +++ b/lib/translate.js @@ -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" - }); - } + + _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] }); }