Skip to content

Commit

Permalink
closes #121; implemented export
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Apr 11, 2012
1 parent e2b3eee commit 7194d43
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 98 deletions.
2 changes: 1 addition & 1 deletion doc/doc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/lang-co.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extras/coco.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extras/mode-coco.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,21 @@ exports.Util = Util = (function(superclass){
exports.L = function(yylineno, node){
return node.line = yylineno + 1, node;
};
exports.Export = function(lines){
var i, out, node, that, __ref;
i = -1;
out = Util('out');
while (node = lines[++i]) {
if (that = node instanceof Fun && node.name) {
lines.splice(i++, 0, Assign(Chain(out, [Index(Key(that))]), Var(that)));
continue;
}
lines[i] = (that = node.varName() || node instanceof Assign && node.left.varName() || node instanceof Class && ((__ref = node.title) != null ? __ref.varName() : void 8))
? Assign(Chain(out, [Index(Key(that))]), node)
: Import(out, node);
}
return __ref = __clone(Block.prototype), __ref.lines = lines, __ref;
};
function Scope(parent, shared){
this.parent = parent;
this.shared = shared;
Expand Down Expand Up @@ -3150,6 +3165,7 @@ UTILITIES = {
repeatString: 'function(str, n){\n for (var r = \'\'; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;\n return r;\n}',
repeatArray: 'function(arr, n){\n for (var r = []; n > 0; (n >>= 1) && (arr = arr.concat(arr)))\n if (n & 1) r.push.apply(r, arr);\n return r;\n}',
of: 'function(x, arr){\n var i = 0, l = arr.length >>> 0;\n while (i < l) if (x === arr[i++]) return true;\n return false;\n}',
out: 'typeof exports != \'undefined\' && exports || this',
split: "''.split",
replace: "''.replace",
toString: '{}.toString',
Expand Down
4 changes: 4 additions & 0 deletions lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ bnf = {
Line: [
o('Expression'), o('PARAM( ArgList OptComma )PARAM <- Expression', function(){
return Call.back($2, $6, $5 === '<~');
}), o('EXPORT Exprs', function(){
return Export($2);
}), o('EXPORT INDENT ArgList OptComma DEDENT', function(){
return Export($3);
}), o('COMMENT', function(){
return L(JS($1, true, true));
}), o('...', function(){
Expand Down
4 changes: 2 additions & 2 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,8 @@ function indexOfPair(tokens, i){
}
return -1;
}
KEYWORDS_SHARED = ['true', 'false', 'null', 'this', 'void', 'super', 'return', 'throw', 'break', 'continue', 'if', 'else', 'for', 'while', 'switch', 'case', 'default', 'try', 'catch', 'finally', 'class', 'extends', 'new', 'do', 'delete', 'typeof', 'in', 'instanceof', 'import', 'function', 'let', 'with', 'debugger'];
KEYWORDS_UNUSED = ['var', 'const', 'enum', 'export', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
KEYWORDS_SHARED = ['true', 'false', 'null', 'this', 'void', 'super', 'return', 'throw', 'break', 'continue', 'if', 'else', 'for', 'while', 'switch', 'case', 'default', 'try', 'catch', 'finally', 'class', 'extends', 'new', 'do', 'delete', 'typeof', 'in', 'instanceof', 'import', 'function', 'let', 'with', 'debugger', 'export'];
KEYWORDS_UNUSED = ['var', 'const', 'enum', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield'];
KEYWORDS = KEYWORDS_SHARED.concat(KEYWORDS_UNUSED);
ID = (function(){
var start, part;
Expand Down
Loading

0 comments on commit 7194d43

Please sign in to comment.