Browse files

now we're making progress with tameRequire, which puts us in decent s…

…hape
  • Loading branch information...
1 parent 12def0e commit 6ba31cbe3abe88d4035b5ee3081ce794840b2f3e @maxtaco committed Dec 8, 2011
Showing with 222 additions and 192 deletions.
  1. +22 −4 lib/coffee-script/nodes.js
  2. +181 −178 lib/coffee-script/parser.js
  3. +19 −10 src/nodes.coffee
View
26 lib/coffee-script/nodes.js
@@ -2410,16 +2410,34 @@
function TameRequire(args) {
this.typ = null;
if (args && args.length > 2) {
- throw SyntaxError("Args to tameRequire are either 'inline' or 'ext'");
+ throw SyntaxError("args to tameRequire are either 'inline' or 'ext'");
}
if (args && args.length === 1) this.typ = args[0];
}
TameRequire.prototype.compileNode = function(o) {
- var call, file, ns, req, v;
+ var access, call, callv, file, ns, req, v;
v = this.typ ? this.typ.compile(o) : "inline";
- this.body = v === "inline" ? InlineDeferral.generate() : (file = v === "ext" ? new Literal(new Value("'coffee-script'")) : this.typ, req = new Value(new Literal("require")), call = new Call(req, [file]), call.add(new Access(new Literal(tame["const"].ns))), ns = new Access(new Literal(tame["const"].ns)), new Assign(ns, call));
- return this.body.compile(o);
+ this.body = null;
+ if (v === "inline") {
+ this.body = InlineDeferral.generate();
+ } else if (v === "ext") {
+ file = new Literal("'coffee-script'");
+ access = new Access(new Literal(tame["const"].ns));
+ req = new Value(new Literal("require"));
+ call = new Call(req, [file]);
+ callv = new Value(call);
+ callv.add(access);
+ ns = new Value(new Literal(tame["const"].ns));
+ this.body = new Assign(ns, callv);
+ } else if (v !== "skip") {
+ throw SyntaxError("tameRequire takes either 'inline', 'ext' or 'skip'");
+ }
+ if (this.body) {
+ return this.body.compile(o);
+ } else {
+ return '';
+ }
};
children = ['typ'];
View
359 lib/coffee-script/parser.js
181 additions, 178 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
29 src/nodes.coffee
@@ -1932,27 +1932,36 @@ exports.Await = class Await extends Base
#### tameRequire
-
+#
+# By default, the tame libraries are inlined. But if you preface your file
+# with 'tameRequire(ext)', you can have it require external libraries
+# of your choosing.
+#
exports.TameRequire = class TameRequire extends Base
constructor: (args) ->
@typ = null
if args and args.length > 2
- throw SyntaxError "Args to tameRequire are either 'inline' or 'ext'"
+ throw SyntaxError "args to tameRequire are either 'inline' or 'ext'"
if args and args.length == 1
@typ = args[0]
compileNode: (o) ->
v = if @typ then @typ.compile(o) else "inline"
- @body = if v == "inline"
- InlineDeferral.generate()
- else
- file = if v == "ext" then (new Literal new Value "'coffee-script'") else @typ
+ @body = null
+ if v == "inline"
+ @body = InlineDeferral.generate()
+ else if v == "ext"
+ file = new Literal "'coffee-script'"
+ access = new Access new Literal tame.const.ns
req = new Value new Literal "require"
call = new Call req, [ file ]
- call.add new Access new Literal tame.const.ns
- ns = new Access new Literal tame.const.ns
- new Assign ns, call
- @body.compile o
+ callv = new Value call
+ callv.add access
+ ns = new Value new Literal tame.const.ns
+ @body = new Assign ns, callv
+ else if v != "skip"
+ throw SyntaxError "tameRequire takes either 'inline', 'ext' or 'skip'"
+ if @body then @body.compile o else ''
children = [ 'typ']

0 comments on commit 6ba31cb

Please sign in to comment.