mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Tweaks to browser.coffee
This commit is contained in:
parent
481c3d536b
commit
269f4e8da8
3 changed files with 20 additions and 24 deletions
|
@ -465,5 +465,5 @@ E.prototype.ensureExpressions=function(a){return a instanceof C?a:new C([a])};E.
|
|||
bind:"function(func, context) {\n return function(){ return func.apply(context, arguments); };\n }",hasProp:"Object.prototype.hasOwnProperty",slice:"Array.prototype.slice"};la=" ";na=/[ \t]+$/gm;Y=/^[a-zA-Z\$_](\w|\$)*$/;N=/^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b$/i;Q=/^-?\d+$/;aa=/^['"]/;q=function(a){return new L(a)};ea=function(a){var b;b="__"+a;U.root.assign(b,oa[a]);return b}}).call(this)});T["./coffee-script"]=new (function(){var z=this;(function(){var x,
|
||||
c,j,h,e,r,d;d=T("path");c=T("./lexer");x=c.Lexer;c=T("./parser");r=c.parser;if(T.extensions){h=T("fs");T.extensions[".coffee"]=function(A,K){var P;P=j(h.readFileSync(K,"utf8"));A.filename=""+K+" (compiled)";return A._compile(P,A.filename)}}else T.registerExtension&&T.registerExtension(".coffee",function(A){return j(A)});z.VERSION="0.9.3";z.compile=j=function(A,K){K||(K={});try{return r.parse(e.tokenize(A)).compile(K)}catch(P){if(K.fileName)P.message="In "+K.fileName+", "+P.message;throw P;}};z.tokens=
|
||||
function(A){return e.tokenize(A)};z.nodes=function(A){return r.parse(e.tokenize(A))};z.run=function(A,K){var P;for(P=module;P.parent;)P=P.parent;P.filename=""+K.fileName+" (compiled)";if(P.moduleCache)P.moduleCache={};return P._compile(z.compile(A,K),P.filename)};z.eval=function(A,K){d.dirname(K.fileName);return eval(z.compile(A,K))};e=new x;r.lexer={lex:function(){var A;A=this.tokens[this.pos]||[""];this.pos+=1;this.yylineno=A[2];this.yytext=A[1];return A[0]},setInput:function(A){this.tokens=A;return this.pos=
|
||||
0},upcomingInput:function(){return""}};r.yy=T("./nodes")}).call(this)});T["./browser"]=new (function(){(function(){var z,x;z=T("./coffee-script");z.eval=function(c,j){return eval(z.compile(c,j))};if(!(typeof window!=="undefined"&&window!==null)){z.run=function(c,j){return Function(z.compile(c,j))()};return null}z.run=function(c,j){return setTimeout(z.compile(c,j))};z.load=function(c,j){var h;h=new (window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");h.open("GET",c,true);"overrideMimeType"in
|
||||
h&&h.overrideMimeType("text/plain");h.onreadystatechange=function(){if(h.readyState===4)return z.run(h.responseText,j)};return h.send(null)};x=function(){var c,j,h,e;h=document.getElementsByTagName("script");c=0;for(j=h.length;c<j;c++){e=h[c];if(e.type==="text/coffeescript")e.src?z.load(e.src):z.run(e.innerHTML)}return null};window.addEventListener?addEventListener("DOMContentLoaded",x,false):attachEvent("onload",x)}).call(this)});return T["./coffee-script"]}();
|
||||
0},upcomingInput:function(){return""}};r.yy=T("./nodes")}).call(this)});T["./browser"]=new (function(){(function(){var z,x;z=T("./coffee-script");z.eval=function(c,j){return eval(z.compile(c,j))};z.run=function(c,j){return Function(z.compile(c,j))()};if(!(typeof window!=="undefined"&&window!==null))return null;z.load=function(c,j){var h;h=new (window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");h.open("GET",c,true);"overrideMimeType"in h&&h.overrideMimeType("text/plain");h.onreadystatechange=
|
||||
function(){if(h.readyState===4)return z.run(h.responseText,j)};return h.send(null)};x=function(){var c,j,h;h=document.getElementsByTagName("script");c=0;for(j=h.length;c<j;c++)(function(){var e=h[c];return e.type==="text/coffeescript"?e.src?z.load(e.src):setTimeout(function(){return z.run(e.innerHTML)}):null})();return null};window.addEventListener?addEventListener("DOMContentLoaded",x,false):attachEvent("onload",x)}).call(this)});return T["./coffee-script"]}();
|
||||
|
|
|
@ -4,15 +4,12 @@
|
|||
CoffeeScript.eval = function(code, options) {
|
||||
return eval(CoffeeScript.compile(code, options));
|
||||
};
|
||||
CoffeeScript.run = function(code, options) {
|
||||
return (Function(CoffeeScript.compile(code, options)))();
|
||||
};
|
||||
if (!(typeof window !== "undefined" && window !== null)) {
|
||||
CoffeeScript.run = function(code, options) {
|
||||
return (Function(CoffeeScript.compile(code, options)))();
|
||||
};
|
||||
return null;
|
||||
}
|
||||
CoffeeScript.run = function(code, options) {
|
||||
return setTimeout(CoffeeScript.compile(code, options));
|
||||
};
|
||||
CoffeeScript.load = function(url, options) {
|
||||
var xhr;
|
||||
xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
|
||||
|
@ -28,17 +25,15 @@
|
|||
return xhr.send(null);
|
||||
};
|
||||
processScripts = function() {
|
||||
var _i, _len, _ref, script;
|
||||
var _i, _len, _ref;
|
||||
_ref = document.getElementsByTagName('script');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
script = _ref[_i];
|
||||
if (script.type === 'text/coffeescript') {
|
||||
if (script.src) {
|
||||
CoffeeScript.load(script.src);
|
||||
} else {
|
||||
CoffeeScript.run(script.innerHTML);
|
||||
}
|
||||
}
|
||||
(function() {
|
||||
var script = _ref[_i];
|
||||
return script.type === 'text/coffeescript' ? (script.src ? CoffeeScript.load(script.src) : setTimeout(function() {
|
||||
return CoffeeScript.run(script.innerHTML);
|
||||
})) : null;
|
||||
})();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
|
||||
CoffeeScript = require './coffee-script'
|
||||
|
||||
# Use standard JavaScript `eval` to eval code.
|
||||
CoffeeScript.eval = (code, options) ->
|
||||
eval CoffeeScript.compile code, options
|
||||
|
||||
unless window?
|
||||
CoffeeScript.run = (code, options) ->
|
||||
(Function CoffeeScript.compile code, options)()
|
||||
return
|
||||
# Running code does not provide access to this scope.
|
||||
CoffeeScript.run = (code, options) ->
|
||||
(Function CoffeeScript.compile code, options)()
|
||||
|
||||
CoffeeScript.run = (code, options) ->
|
||||
setTimeout CoffeeScript.compile code, options
|
||||
# If we're not in a browser environment, we're finished with the public API.
|
||||
return unless window?
|
||||
|
||||
# Load a remote script from the current domain via XHR.
|
||||
CoffeeScript.load = (url, options) ->
|
||||
xhr = new (window.ActiveXObject or XMLHttpRequest)('Microsoft.XMLHTTP')
|
||||
xhr.open 'GET', url, true
|
||||
|
@ -30,7 +31,7 @@ processScripts = ->
|
|||
if script.src
|
||||
CoffeeScript.load script.src
|
||||
else
|
||||
CoffeeScript.run script.innerHTML
|
||||
setTimeout -> CoffeeScript.run script.innerHTML
|
||||
null
|
||||
if window.addEventListener
|
||||
addEventListener 'DOMContentLoaded', processScripts, false
|
||||
|
|
Loading…
Add table
Reference in a new issue