From 636b1b28e42c7cd3aa7fdfd9949ecd5bb9aef701 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Thu, 3 Jul 2014 08:38:55 -0700 Subject: [PATCH] version bump and build for npm, also test for SourceMap HTTP header --- .gitignore | 2 + browser-source-map-support.js | 166 +++++++++++++++++----------------- build.js | 24 +++-- header-test/index.html | 6 ++ header-test/script.coffee | 12 +++ header-test/server.js | 45 +++++++++ package.json | 2 +- source-map-support.js | 4 +- 8 files changed, 169 insertions(+), 92 deletions(-) create mode 100644 header-test/index.html create mode 100644 header-test/script.coffee create mode 100644 header-test/server.js diff --git a/.gitignore b/.gitignore index c56aeb8..19c622f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ amd-test/script.map browserify-test/compiled.js browserify-test/script.js browserify-test/script.map +header-test/script.js +header-test/script.map diff --git a/browser-source-map-support.js b/browser-source-map-support.js index 984543e..b75acbf 100644 --- a/browser-source-map-support.js +++ b/browser-source-map-support.js @@ -2,86 +2,86 @@ * Support for source maps in V8 stack traces * https://github.com/evanw/node-source-map-support */ -(this.define||function(H,N){this.sourceMapSupport=N()})("browser-source-map-support",function(H){(function k(s,p,e){function r(h,c){if(!p[h]){if(!s[h]){var g="function"==typeof require&&require;if(!c&&g)return g(h,!0);if(u)return u(h,!0);throw Error("Cannot find module '"+h+"'");}g=p[h]={exports:{}};s[h][0].call(g.exports,function(c){var a=s[h][1][c];return r(a?a:c)},g,g.exports,k,s,p,e)}return p[h].exports}for(var u="function"==typeof require&&require,A=0;A=a))return b?(b=f[n],n+1=a)){var d;b?(n+2>>0)): -(n+1>>0);return d}}function h(f,n,b,a){a||(q("boolean"===typeof b,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+1=f.length))return f=u(f,n,b,!0),f&32768?-1*(65535-f+1):f}function c(f,n,b,a){a||(q("boolean"===typeof b,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+3= -f.length))return f=A(f,n,b,!0),f&2147483648?-1*(4294967295-f+1):f}function g(f,n,b,a){a||(q("boolean"===typeof b,"missing or invalid endian"),q(n+3=l))for(d=0,l=Math.min(l-b,2);d>>8*(a?d:1-d)}function b(f,n,b,a,d){d||(q(void 0!==n&&null!==n,"missing value"),q("boolean"===typeof a,"missing or invalid endian"),q(void 0!==b&&null!==b,"missing offset"),q(b+3=l))for(d=0,l=Math.min(l-b,4);d>> -8*(a?d:3-d)&255}function d(f,n,b,d,l){l||(q(void 0!==n&&null!==n,"missing value"),q("boolean"===typeof d,"missing or invalid endian"),q(void 0!==b&&null!==b,"missing offset"),q(b+1=f.length||(0<=n?a(f,n,b,d,l):a(f,65535+n+1,b,d,l))}function y(f,n,a,d,l){l||(q(void 0!==n&&null!==n,"missing value"),q("boolean"===typeof d,"missing or invalid endian"),q(void 0!==a&&null!==a,"missing offset"),q(a+3=f.length||(0<=n?b(f,n,a,d,l):b(f,4294967295+n+1,a,d,l))}function C(f,b,a,d,l){l||(q(void 0!==b&&null!==b,"missing value"),q("boolean"===typeof d,"missing or invalid endian"),q(void 0!==a&&null!==a,"missing offset"),q(a+3=f.length||F.write(f,b,a,d,23,4)}function z(f,b,a,d,l){l||(q(void 0!==b&&null!==b,"missing value"),q("boolean"===typeof d,"missing or invalid endian"), -q(void 0!==a&&null!==a,"missing offset"),q(a+7=f.length||F.write(f,b,a,d,52,8)}function B(f,b,a){if("number"!==typeof f)return a;f=~~f;if(f>=b)return b;if(0<=f)return f;f+=b;return 0<=f?f:0}function v(f){f=~~Math.ceil(+f);return 0>f?0:f}function x(f){return(Array.isArray||function(f){return"[object Array]"===Object.prototype.toString.call(f)})(f)}function D(f){return 16>f?"0"+f.toString(16):f.toString(16)} -function l(f){for(var b=[],a=0;a=d)b.push(f.charCodeAt(a));else{var l=a;55296<=d&&57343>=d&&a++;d=encodeURIComponent(f.slice(l,a+1)).substr(1).split("%");for(l=0;l=b.length||l>=f.length);l++)b[l+a]=f[l];return l}function M(f){try{return decodeURIComponent(f)}catch(b){return String.fromCharCode(65533)}} -function I(f,b){q("number"===typeof f,"cannot write a non-number as a number");q(0<=f,"specified a negative value for writing an unsigned value");q(f<=b,"value is larger than maximum value for type");q(Math.floor(f)===f,"value has a fractional component")}function J(f,b,a){q("number"===typeof f,"cannot write a non-number as a number");q(f<=b,"value larger than maximum allowed value");q(f>=a,"value smaller than minimum allowed value");q(Math.floor(f)===f,"value has a fractional component")}function L(f, -b,a){q("number"===typeof f,"cannot write a non-number as a number");q(f<=b,"value larger than maximum allowed value");q(f>=a,"value smaller than minimum allowed value")}function q(f,b){if(!f)throw Error(b||"Failed assertion");}var G=k("base64-js"),F=k("ieee754");p.Buffer=e;p.SlowBuffer=e;p.INSPECT_MAX_BYTES=50;e.poolSize=8192;e._useTypedArrays=function(){try{var f=new ArrayBuffer(0),b=new Uint8Array(f);b.foo=function(){return 42};return 42===b.foo()&&"function"===typeof b.subarray}catch(a){return!1}}(); -e.isEncoding=function(f){switch(String(f).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "binary":case "base64":case "raw":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return!0;default:return!1}};e.isBuffer=function(f){return!(null===f||void 0===f||!f._isBuffer)};e.byteLength=function(f,b){var a;f+="";switch(b||"utf8"){case "hex":a=f.length/2;break;case "utf8":case "utf-8":a=l(f).length;break;case "ascii":case "binary":case "raw":a=f.length;break;case "base64":a=G.toByteArray(f).length; -break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":a=2*f.length;break;default:throw Error("Unknown encoding");}return a};e.concat=function(f,b){q(x(f),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array.");if(0===f.length)return new e(0);if(1===f.length)return f[0];var a;if("number"!==typeof b)for(a=b=0;ac&&(a=c)):a=c;d=String(d||"utf8").toLowerCase();switch(d){case "hex":b=Number(b)||0;d=this.length-b;a?(a=Number(a),a>d&&(a=d)):a=d;d=f.length;q(0===d%2,"Invalid hex string");a>d/2&&(a=d/2);for(d=0;d>8,g%=256,m.push(g),m.push(c);f=d._charsWritten=E(m,this,b,a);break;default:throw Error("Unknown encoding");}return f};e.prototype.toString=function(f,b,a){f=String(f||"utf8").toLowerCase();b=Number(b)||0;a=void 0!==a?Number(a):a=this.length;if(a=== -b)return"";switch(f){case "hex":f=b;b=this.length;if(!f||0>f)f=0;if(!a||0>a||a>b)a=b;for(b="";f=this[d]?(f+=M(b)+String.fromCharCode(this[d]),b=""):b+="%"+this[d].toString(16);a=f+M(b);break;case "ascii":a=r(this,b,a);break;case "binary":a=r(this,b,a);break;case "base64":f=b;a=0===f&&a===this.length?G.fromByteArray(this):G.fromByteArray(this.slice(f,a));break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":a= -this.slice(b,a);f="";for(b=0;b=d,"sourceEnd < sourceStart"),q(0<=b&&bthis.length&&(l=this.length),a.length-bl||!e._useTypedArrays)for(var c=0;c=this.length))return this[b]};e.prototype.readUInt16LE=function(b,a){return u(this,b,!0,a)};e.prototype.readUInt16BE=function(b,a){return u(this,b,!1,a)};e.prototype.readUInt32LE=function(b,a){return A(this, -b,!0,a)};e.prototype.readUInt32BE=function(b,a){return A(this,b,!1,a)};e.prototype.readInt8=function(b,a){a||(q(void 0!==b&&null!==b,"missing offset"),q(b=this.length))return this[b]&128?-1*(255-this[b]+1):this[b]};e.prototype.readInt16LE=function(b,a){return h(this,b,!0,a)};e.prototype.readInt16BE=function(b,a){return h(this,b,!1,a)};e.prototype.readInt32LE=function(b,a){return c(this,b,!0,a)};e.prototype.readInt32BE=function(b,a){return c(this, -b,!1,a)};e.prototype.readFloatLE=function(b,a){return g(this,b,!0,a)};e.prototype.readFloatBE=function(b,a){return g(this,b,!1,a)};e.prototype.readDoubleLE=function(b,a){return m(this,b,!0,a)};e.prototype.readDoubleBE=function(b,a){return m(this,b,!1,a)};e.prototype.writeUInt8=function(b,a,d){d||(q(void 0!==b&&null!==b,"missing value"),q(void 0!==a&&null!==a,"missing offset"),q(a=this.length||(this[a]=b)};e.prototype.writeUInt16LE=function(b, -d,l){a(this,b,d,!0,l)};e.prototype.writeUInt16BE=function(b,d,l){a(this,b,d,!1,l)};e.prototype.writeUInt32LE=function(a,d,l){b(this,a,d,!0,l)};e.prototype.writeUInt32BE=function(a,d,l){b(this,a,d,!1,l)};e.prototype.writeInt8=function(b,a,d){d||(q(void 0!==b&&null!==b,"missing value"),q(void 0!==a&&null!==a,"missing offset"),q(a=this.length||(0<=b?this.writeUInt8(b,a,d):this.writeUInt8(255+b+1,a,d))};e.prototype.writeInt16LE=function(b, -a,l){d(this,b,a,!0,l)};e.prototype.writeInt16BE=function(b,a,l){d(this,b,a,!1,l)};e.prototype.writeInt32LE=function(b,a,d){y(this,b,a,!0,d)};e.prototype.writeInt32BE=function(b,a,d){y(this,b,a,!1,d)};e.prototype.writeFloatLE=function(b,a,d){C(this,b,a,!0,d)};e.prototype.writeFloatBE=function(b,a,d){C(this,b,a,!1,d)};e.prototype.writeDoubleLE=function(b,a,d){z(this,b,a,!0,d)};e.prototype.writeDoubleBE=function(b,a,d){z(this,b,a,!1,d)};e.prototype.fill=function(b,a,d){b||(b=0);a||(a=0);d||(d=this.length); -"string"===typeof b&&(b=b.charCodeAt(0));q("number"===typeof b&&!isNaN(b),"value is not a number");q(d>=a,"end < start");if(d!==a&&0!==this.length)for(q(0<=a&&a"};e.prototype.toArrayBuffer=function(){if("undefined"!==typeof Uint8Array){if(e._useTypedArrays)return(new e(this)).buffer; -for(var b=new Uint8Array(this.length),a=0,d=b.length;a>16),b((g&65280)>>8),b(g&255);2===m?(g=r(a.charAt(d))<<2|r(a.charAt(d+1))>>4,b(g&255)): -1===m&&(g=r(a.charAt(d))<<10|r(a.charAt(d+1))<<4|r(a.charAt(d+2))>>2,b(g>>8&255),b(g&255));return h};s.exports.fromByteArray=function(a){var b,d=a.length%3,c="",g,m;b=0;for(m=a.length-d;b>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g& -63),c+=g;switch(d){case 1:g=a[a.length-1];c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>2);c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g<<4&63);c+="==";break;case 2:g=(a[a.length-2]<<8)+a[a.length-1],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>10),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g>>4&63),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(g<< -2&63),c+="="}return c}})()},{}],5:[function(k,s,p){p.read=function(e,r,u,k,h){var c;c=8*h-k-1;var g=(1<>1,a=-7;h=u?h-1:0;var b=u?-1:1,d=e[r+h];h+=b;u=d&(1<<-a)-1;d>>=-a;for(a+=c;0>=-a;for(a+=k;0>1,d=23===h?Math.pow(2,-24)-Math.pow(2,-77):0; -c=k?0:c-1;var y=k?1:-1,C=0>r||0===r&&0>1/r?1:0;r=Math.abs(r);isNaN(r)||Infinity===r?(r=isNaN(r)?1:0,k=a):(k=Math.floor(Math.log(r)/Math.LN2),1>r*(g=Math.pow(2,-k))&&(k--,g*=2),r=1<=k+b?r+d/g:r+d*Math.pow(2,1-b),2<=r*g&&(k++,g/=2),k+b>=a?(r=0,k=a):1<=k+b?(r=(r*g-1)*Math.pow(2,h),k+=b):(r=r*Math.pow(2,b-1)*Math.pow(2,h),k=0));for(;8<=h;e[u+c]=r&255,c+=y,r/=256,h-=8);k=k<d?[]:b.slice(a,d-a+1)}c=p.resolve(c).substr(1);g=p.resolve(g).substr(1); -for(var a=m(c.split("/")),b=m(g.split("/")),d=Math.min(a.length,b.length),e=d,h=0;hg&&(g=c.length+g);return c.substr(g,m)}}).call(this,k("node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6}],8:[function(k,s,p){p.SourceMapGenerator=k("./source-map/source-map-generator").SourceMapGenerator;p.SourceMapConsumer=k("./source-map/source-map-consumer").SourceMapConsumer; -p.SourceNode=k("./source-map/source-node").SourceNode},{"./source-map/source-map-consumer":13,"./source-map/source-map-generator":14,"./source-map/source-node":15}],9:[function(k,s,p){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,p){function h(){this._array=[];this._set={}}var c=e("./util");h.fromArray=function(c,m){for(var a=new h,b=0,d=c.length;bc?(-c<<1)+1:(c<<1)+0;do c=m&31,m>>>=5,0=m)throw Error("Expected more digits in base 64 VLQ value.");e=h.decode(c.charAt(g++));d=!!(e&32);e&=31;a+=e<>1;return{value:1===(a&1)?-m:m,rest:c.slice(g)}}})},{"./base64":11,amdefine:17}],11:[function(k,s,p){if("function"!==typeof e)var e=k("amdefine")(s, -k);e(function(e,k,p){var h={},c={};"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("").forEach(function(g,e){h[g]=e;c[e]=g});k.encode=function(g){if(g in c)return c[g];throw new TypeError("Must be between 0 and 63: "+g);};k.decode=function(c){if(c in h)return h[c];throw new TypeError("Not a valid base 64 digit: "+c);}})},{amdefine:17}],12:[function(k,s,p){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,p){function h(c,g,e,a,b){var d=Math.floor((g-c)/2)+c, -k=b(e,a[d],!0);return 0===k?a[d]:0c?null:a[c]}k.search=function(c,g,e){return 0=b[c])throw new TypeError("Line must be greater than or equal to 1, got "+b[c]);if(0>b[e])throw new TypeError("Column must be greater than or equal to 0, got "+b[e]);return g.search(b,a,h)};h.prototype.originalPositionFor=function(b){b={generatedLine:c.getArg(b,"line"),generatedColumn:c.getArg(b,"column")};if(b=this._findMapping(b,this._generatedMappings,"generatedLine","generatedColumn",c.compareByGeneratedPositions)){var a=c.getArg(b,"source",null); -a&&this.sourceRoot&&(a=c.join(this.sourceRoot,a));return{source:a,line:c.getArg(b,"originalLine",null),column:c.getArg(b,"originalColumn",null),name:c.getArg(b,"name",null)}}return{source:null,line:null,column:null,name:null}};h.prototype.sourceContentFor=function(b){if(!this.sourcesContent)return null;this.sourceRoot&&(b=c.relative(this.sourceRoot,b));if(this._sources.has(b))return this.sourcesContent[this._sources.indexOf(b)];var a;if(this.sourceRoot&&(a=c.urlParse(this.sourceRoot))){var e=b.replace(/^file:\/\//, -"");if("file"==a.scheme&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!a.path||"/"==a.path)&&this._sources.has("/"+b))return this.sourcesContent[this._sources.indexOf("/"+b)]}throw Error('"'+b+'" is not in the SourceMap.');};h.prototype.generatedPositionFor=function(b){b={source:c.getArg(b,"source"),originalLine:c.getArg(b,"line"),originalColumn:c.getArg(b,"column")};this.sourceRoot&&(b.source=c.relative(this.sourceRoot,b.source));return(b=this._findMapping(b,this._originalMappings, -"originalLine","originalColumn",c.compareByOriginalPositions))?{line:c.getArg(b,"generatedLine",null),column:c.getArg(b,"generatedColumn",null)}:{line:null,column:null}};h.GENERATED_ORDER=1;h.ORIGINAL_ORDER=2;h.prototype.eachMapping=function(b,a,e){a=a||null;switch(e||h.GENERATED_ORDER){case h.GENERATED_ORDER:e=this._generatedMappings;break;case h.ORIGINAL_ORDER:e=this._originalMappings;break;default:throw Error("Unknown order of iteration.");}var g=this.sourceRoot;e.map(function(b){var a=b.source; -a&&g&&(a=c.join(g,a));return{source:a,generatedLine:b.generatedLine,generatedColumn:b.generatedColumn,originalLine:b.originalLine,originalColumn:b.originalColumn,name:b.name}}).forEach(b,a)};k.SourceMapConsumer=h})},{"./array-set":9,"./base64-vlq":10,"./binary-search":12,"./util":16,amdefine:17}],14:[function(k,s,p){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,p){function h(a){this._file=g.getArg(a,"file");this._sourceRoot=g.getArg(a,"sourceRoot",null);this._sources=new m;this._names= -new m;this._mappings=[];this._sourcesContents=null}var c=e("./base64-vlq"),g=e("./util"),m=e("./array-set").ArraySet;h.prototype._version=3;h.fromSourceMap=function(a){var b=a.sourceRoot,d=new h({file:a.file,sourceRoot:b});a.eachMapping(function(a){var c={generated:{line:a.generatedLine,column:a.generatedColumn}};a.source&&(c.source=a.source,b&&(c.source=g.relative(b,c.source)),c.original={line:a.originalLine,column:a.originalColumn},a.name&&(c.name=a.name));d.addMapping(c)});a.sources.forEach(function(b){var c= -a.sourceContentFor(b);c&&d.setSourceContent(b,c)});return d};h.prototype.addMapping=function(a){var b=g.getArg(a,"generated"),d=g.getArg(a,"original",null),c=g.getArg(a,"source",null);a=g.getArg(a,"name",null);this._validateMapping(b,d,c,a);c&&!this._sources.has(c)&&this._sources.add(c);a&&!this._names.has(a)&&this._names.add(a);this._mappings.push({generatedLine:b.line,generatedColumn:b.column,originalLine:null!=d&&d.line,originalColumn:null!=d&&d.column,source:c,name:a})};h.prototype.setSourceContent= -function(a,b){var d=a;this._sourceRoot&&(d=g.relative(this._sourceRoot,d));null!==b?(this._sourcesContents||(this._sourcesContents={}),this._sourcesContents[g.toSetString(d)]=b):(delete this._sourcesContents[g.toSetString(d)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))};h.prototype.applySourceMap=function(a,b){b||(b=a.file);var d=this._sourceRoot;d&&(b=g.relative(d,b));var c=new m,e=new m;this._mappings.forEach(function(h){if(h.source===b&&h.originalLine){var m=a.originalPositionFor({line:h.originalLine, -column:h.originalColumn});null!==m.source&&(h.source=d?g.relative(d,m.source):m.source,h.originalLine=m.line,h.originalColumn=m.column,null!==m.name&&null!==h.name&&(h.name=m.name))}(m=h.source)&&!c.has(m)&&c.add(m);(h=h.name)&&!e.has(h)&&e.add(h)},this);this._sources=c;this._names=e;a.sources.forEach(function(b){var c=a.sourceContentFor(b);c&&(d&&(b=g.relative(d,b)),this.setSourceContent(b,c))},this)};h.prototype._validateMapping=function(a,b,d,c){if(!(a&&"line"in a&&"column"in a&&0e)-(c=a))return b?(b=h[n],n+1=a)){var d;b?(n+2>>0)): +(n+1>>0);return d}}function g(h,n,b,a){a||(p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==n&&null!==n,"missing offset"),p(n+1=h.length))return h=t(h,n,b,!0),h&32768?-1*(65535-h+1):h}function c(h,n,b,a){a||(p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==n&&null!==n,"missing offset"),p(n+3= +h.length))return h=E(h,n,b,!0),h&2147483648?-1*(4294967295-h+1):h}function f(h,n,b,a){a||(p("boolean"===typeof b,"missing or invalid endian"),p(n+3=c))for(d=0,c=Math.min(c-b,2);d>>8*(a?d:1-d)}function b(h,n,b,a,d){d||(p(void 0!==n&&null!==n,"missing value"),p("boolean"===typeof a,"missing or invalid endian"),p(void 0!==b&&null!==b,"missing offset"),p(b+3=c))for(d=0,c=Math.min(c-b,4);d>> +8*(a?d:3-d)&255}function d(h,n,b,d,c){c||(p(void 0!==n&&null!==n,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==b&&null!==b,"missing offset"),p(b+1=h.length||(0<=n?a(h,n,b,d,c):a(h,65535+n+1,b,d,c))}function z(h,n,a,d,c){c||(p(void 0!==n&&null!==n,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==a&&null!==a,"missing offset"),p(a+3=h.length||(0<=n?b(h,n,a,d,c):b(h,4294967295+n+1,a,d,c))}function D(h,b,a,d,c){c||(p(void 0!==b&&null!==b,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==a&&null!==a,"missing offset"),p(a+3=h.length||F.write(h,b,a,d,23,4)}function A(h,b,a,d,c){c||(p(void 0!==b&&null!==b,"missing value"),p("boolean"===typeof d,"missing or invalid endian"), +p(void 0!==a&&null!==a,"missing offset"),p(a+7=h.length||F.write(h,b,a,d,52,8)}function B(h,b,a){if("number"!==typeof h)return a;h=~~h;if(h>=b)return b;if(0<=h)return h;h+=b;return 0<=h?h:0}function v(h){h=~~Math.ceil(+h);return 0>h?0:h}function x(h){return(Array.isArray||function(h){return"[object Array]"===Object.prototype.toString.call(h)})(h)}function C(h){return 16>h?"0"+h.toString(16):h.toString(16)} +function r(h){for(var b=[],a=0;a=d)b.push(h.charCodeAt(a));else{var c=a;55296<=d&&57343>=d&&a++;d=encodeURIComponent(h.slice(c,a+1)).substr(1).split("%");for(c=0;c=b.length||c>=h.length);c++)b[c+a]=h[c];return c}function M(h){try{return decodeURIComponent(h)}catch(b){return String.fromCharCode(65533)}} +function I(h,b){p("number"===typeof h,"cannot write a non-number as a number");p(0<=h,"specified a negative value for writing an unsigned value");p(h<=b,"value is larger than maximum value for type");p(Math.floor(h)===h,"value has a fractional component")}function J(h,b,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=b,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value");p(Math.floor(h)===h,"value has a fractional component")}function L(h, +b,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=b,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value")}function p(h,b){if(!h)throw Error(b||"Failed assertion");}var G=k("base64-js"),F=k("ieee754");l.Buffer=e;l.SlowBuffer=e;l.INSPECT_MAX_BYTES=50;e.poolSize=8192;e._useTypedArrays=function(){try{var h=new ArrayBuffer(0),b=new Uint8Array(h);b.foo=function(){return 42};return 42===b.foo()&&"function"===typeof b.subarray}catch(a){return!1}}(); +e.isEncoding=function(h){switch(String(h).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "binary":case "base64":case "raw":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return!0;default:return!1}};e.isBuffer=function(h){return!(null===h||void 0===h||!h._isBuffer)};e.byteLength=function(h,b){var a;h+="";switch(b||"utf8"){case "hex":a=h.length/2;break;case "utf8":case "utf-8":a=r(h).length;break;case "ascii":case "binary":case "raw":a=h.length;break;case "base64":a=G.toByteArray(h).length; +break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":a=2*h.length;break;default:throw Error("Unknown encoding");}return a};e.concat=function(h,b){p(x(h),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array.");if(0===h.length)return new e(0);if(1===h.length)return h[0];var a;if("number"!==typeof b)for(a=b=0;ac&&(a=c)):a=c;d=String(d||"utf8").toLowerCase();switch(d){case "hex":b=Number(b)||0;d=this.length-b;a?(a=Number(a),a>d&&(a=d)):a=d;d=h.length;p(0===d%2,"Invalid hex string");a>d/2&&(a=d/2);for(d=0;d>8,f%=256,c.push(f),c.push(d);h=e._charsWritten=y(c,this,b,a);break;default:throw Error("Unknown encoding");}return h};e.prototype.toString=function(h,a,b){h=String(h||"utf8").toLowerCase();a=Number(a)||0;b=void 0!==b?Number(b):b=this.length;if(b===a)return""; +switch(h){case "hex":h=a;a=this.length;if(!h||0>h)h=0;if(!b||0>b||b>a)b=a;for(a="";h=this[d]?(h+=M(a)+String.fromCharCode(this[d]),a=""):a+="%"+this[d].toString(16);b=h+M(a);break;case "ascii":b=q(this,a,b);break;case "binary":b=q(this,a,b);break;case "base64":h=a;b=0===h&&b===this.length?G.fromByteArray(this):G.fromByteArray(this.slice(h,b));break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":b= +this.slice(a,b);h="";for(a=0;a=d,"sourceEnd < sourceStart"),p(0<=b&&bthis.length&&(c=this.length),a.length-bc||!e._useTypedArrays)for(var f=0;f=this.length))return this[b]};e.prototype.readUInt16LE=function(b,a){return t(this,b,!0,a)};e.prototype.readUInt16BE=function(b,a){return t(this,b,!1,a)};e.prototype.readUInt32LE=function(b,a){return E(this, +b,!0,a)};e.prototype.readUInt32BE=function(b,a){return E(this,b,!1,a)};e.prototype.readInt8=function(b,a){a||(p(void 0!==b&&null!==b,"missing offset"),p(b=this.length))return this[b]&128?-1*(255-this[b]+1):this[b]};e.prototype.readInt16LE=function(b,a){return g(this,b,!0,a)};e.prototype.readInt16BE=function(b,a){return g(this,b,!1,a)};e.prototype.readInt32LE=function(b,a){return c(this,b,!0,a)};e.prototype.readInt32BE=function(b,a){return c(this, +b,!1,a)};e.prototype.readFloatLE=function(b,a){return f(this,b,!0,a)};e.prototype.readFloatBE=function(b,a){return f(this,b,!1,a)};e.prototype.readDoubleLE=function(b,a){return m(this,b,!0,a)};e.prototype.readDoubleBE=function(b,a){return m(this,b,!1,a)};e.prototype.writeUInt8=function(b,a,d){d||(p(void 0!==b&&null!==b,"missing value"),p(void 0!==a&&null!==a,"missing offset"),p(a=this.length||(this[a]=b)};e.prototype.writeUInt16LE=function(b, +d,c){a(this,b,d,!0,c)};e.prototype.writeUInt16BE=function(b,d,c){a(this,b,d,!1,c)};e.prototype.writeUInt32LE=function(a,d,c){b(this,a,d,!0,c)};e.prototype.writeUInt32BE=function(a,d,c){b(this,a,d,!1,c)};e.prototype.writeInt8=function(b,a,d){d||(p(void 0!==b&&null!==b,"missing value"),p(void 0!==a&&null!==a,"missing offset"),p(a=this.length||(0<=b?this.writeUInt8(b,a,d):this.writeUInt8(255+b+1,a,d))};e.prototype.writeInt16LE=function(b, +a,c){d(this,b,a,!0,c)};e.prototype.writeInt16BE=function(b,a,c){d(this,b,a,!1,c)};e.prototype.writeInt32LE=function(b,a,d){z(this,b,a,!0,d)};e.prototype.writeInt32BE=function(b,a,d){z(this,b,a,!1,d)};e.prototype.writeFloatLE=function(b,a,d){D(this,b,a,!0,d)};e.prototype.writeFloatBE=function(b,a,d){D(this,b,a,!1,d)};e.prototype.writeDoubleLE=function(b,a,d){A(this,b,a,!0,d)};e.prototype.writeDoubleBE=function(b,a,d){A(this,b,a,!1,d)};e.prototype.fill=function(b,a,d){b||(b=0);a||(a=0);d||(d=this.length); +"string"===typeof b&&(b=b.charCodeAt(0));p("number"===typeof b&&!isNaN(b),"value is not a number");p(d>=a,"end < start");if(d!==a&&0!==this.length)for(p(0<=a&&a"};e.prototype.toArrayBuffer=function(){if("undefined"!==typeof Uint8Array){if(e._useTypedArrays)return(new e(this)).buffer; +for(var b=new Uint8Array(this.length),a=0,d=b.length;a>16),b((f&65280)>>8),b(f&255);2===m?(f=q(a.charAt(d))<<2|q(a.charAt(d+1))>>4,b(f&255)):1=== +m&&(f=q(a.charAt(d))<<10|q(a.charAt(d+1))<<4|q(a.charAt(d+2))>>2,b(f>>8&255),b(f&255));return g};e.fromByteArray=function(a){var b,d=a.length%3,c="",f,m;b=0;for(m=a.length-d;b>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f& +63),c+=f;switch(d){case 1:f=a[a.length-1];c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>2);c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f<<4&63);c+="==";break;case 2:f=(a[a.length-2]<<8)+a[a.length-1],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>10),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>4&63),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f<< +2&63),c+="="}return c}})("undefined"===typeof l?this.base64js={}:l)},{}],5:[function(k,s,l){l.read=function(e,q,t,k,g){var c;c=8*g-k-1;var f=(1<>1,a=-7;g=t?g-1:0;var b=t?-1:1,d=e[q+g];g+=b;t=d&(1<<-a)-1;d>>=-a;for(a+=c;0>=-a;for(a+=k;0>1,d= +23===g?Math.pow(2,-24)-Math.pow(2,-77):0;c=k?0:c-1;var z=k?1:-1,D=0>q||0===q&&0>1/q?1:0;q=Math.abs(q);isNaN(q)||Infinity===q?(q=isNaN(q)?1:0,k=a):(k=Math.floor(Math.log(q)/Math.LN2),1>q*(f=Math.pow(2,-k))&&(k--,f*=2),q=1<=k+b?q+d/f:q+d*Math.pow(2,1-b),2<=q*f&&(k++,f/=2),k+b>=a?(q=0,k=a):1<=k+b?(q=(q*f-1)*Math.pow(2,g),k+=b):(q=q*Math.pow(2,b-1)*Math.pow(2,g),k=0));for(;8<=g;e[t+c]=q&255,c+=z,q/=256,g-=8);k=k<d?[]:b.slice(a, +d-a+1)}c=l.resolve(c).substr(1);f=l.resolve(f).substr(1);for(var a=m(c.split("/")),b=m(f.split("/")),d=Math.min(a.length,b.length),e=d,g=0;gf&&(f=c.length+f);return c.substr(f,m)}}).call(this,k("node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6}],8:[function(k,s,l){l.SourceMapGenerator=k("./source-map/source-map-generator").SourceMapGenerator; +l.SourceMapConsumer=k("./source-map/source-map-consumer").SourceMapConsumer;l.SourceNode=k("./source-map/source-node").SourceNode},{"./source-map/source-map-consumer":13,"./source-map/source-map-generator":14,"./source-map/source-node":15}],9:[function(k,s,l){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,l){function g(){this._array=[];this._set={}}var c=e("./util");g.fromArray=function(c,m){for(var a=new g,b=0,d=c.length;bc?(-c<<1)+1:(c<<1)+0;do c=e&31,e>>>=5,0=e)throw Error("Expected more digits in base 64 VLQ value.");k=g.decode(c.charAt(f++));d=!!(k&32);k&=31;a+=k<>1;return{value:1===(a&1)?-e:e,rest:c.slice(f)}}})}, +{"./base64":11,amdefine:17}],11:[function(k,s,l){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,l){var g={},c={};"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("").forEach(function(f,e){g[f]=e;c[e]=f});k.encode=function(f){if(f in c)return c[f];throw new TypeError("Must be between 0 and 63: "+f);};k.decode=function(c){if(c in g)return g[c];throw new TypeError("Not a valid base 64 digit: "+c);}})},{amdefine:17}],12:[function(k,s,l){if("function"!==typeof e)var e= +k("amdefine")(s,k);e(function(e,k,l){function g(c,f,e,a,b){var d=Math.floor((f-c)/2)+c,k=b(e,a[d],!0);return 0===k?a[d]:0c?null:a[c]}k.search=function(c,f,e){return 0=b[c])throw new TypeError("Line must be greater than or equal to 1, got "+b[c]);if(0>b[e])throw new TypeError("Column must be greater than or equal to 0, got "+b[e]);return f.search(b,a,g)};g.prototype.originalPositionFor=function(b){b={generatedLine:c.getArg(b,"line"),generatedColumn:c.getArg(b,"column")};if(b=this._findMapping(b,this._generatedMappings,"generatedLine","generatedColumn", +c.compareByGeneratedPositions)){var a=c.getArg(b,"source",null);a&&this.sourceRoot&&(a=c.join(this.sourceRoot,a));return{source:a,line:c.getArg(b,"originalLine",null),column:c.getArg(b,"originalColumn",null),name:c.getArg(b,"name",null)}}return{source:null,line:null,column:null,name:null}};g.prototype.sourceContentFor=function(b){if(!this.sourcesContent)return null;this.sourceRoot&&(b=c.relative(this.sourceRoot,b));if(this._sources.has(b))return this.sourcesContent[this._sources.indexOf(b)];var a; +if(this.sourceRoot&&(a=c.urlParse(this.sourceRoot))){var f=b.replace(/^file:\/\//,"");if("file"==a.scheme&&this._sources.has(f))return this.sourcesContent[this._sources.indexOf(f)];if((!a.path||"/"==a.path)&&this._sources.has("/"+b))return this.sourcesContent[this._sources.indexOf("/"+b)]}throw Error('"'+b+'" is not in the SourceMap.');};g.prototype.generatedPositionFor=function(b){b={source:c.getArg(b,"source"),originalLine:c.getArg(b,"line"),originalColumn:c.getArg(b,"column")};this.sourceRoot&& +(b.source=c.relative(this.sourceRoot,b.source));return(b=this._findMapping(b,this._originalMappings,"originalLine","originalColumn",c.compareByOriginalPositions))?{line:c.getArg(b,"generatedLine",null),column:c.getArg(b,"generatedColumn",null)}:{line:null,column:null}};g.GENERATED_ORDER=1;g.ORIGINAL_ORDER=2;g.prototype.eachMapping=function(b,a,f){a=a||null;switch(f||g.GENERATED_ORDER){case g.GENERATED_ORDER:f=this._generatedMappings;break;case g.ORIGINAL_ORDER:f=this._originalMappings;break;default:throw Error("Unknown order of iteration."); +}var e=this.sourceRoot;f.map(function(b){var a=b.source;a&&e&&(a=c.join(e,a));return{source:a,generatedLine:b.generatedLine,generatedColumn:b.generatedColumn,originalLine:b.originalLine,originalColumn:b.originalColumn,name:b.name}}).forEach(b,a)};k.SourceMapConsumer=g})},{"./array-set":9,"./base64-vlq":10,"./binary-search":12,"./util":16,amdefine:17}],14:[function(k,s,l){if("function"!==typeof e)var e=k("amdefine")(s,k);e(function(e,k,l){function g(a){this._file=f.getArg(a,"file");this._sourceRoot= +f.getArg(a,"sourceRoot",null);this._sources=new m;this._names=new m;this._mappings=[];this._sourcesContents=null}var c=e("./base64-vlq"),f=e("./util"),m=e("./array-set").ArraySet;g.prototype._version=3;g.fromSourceMap=function(a){var b=a.sourceRoot,d=new g({file:a.file,sourceRoot:b});a.eachMapping(function(a){var c={generated:{line:a.generatedLine,column:a.generatedColumn}};a.source&&(c.source=a.source,b&&(c.source=f.relative(b,c.source)),c.original={line:a.originalLine,column:a.originalColumn},a.name&& +(c.name=a.name));d.addMapping(c)});a.sources.forEach(function(b){var c=a.sourceContentFor(b);c&&d.setSourceContent(b,c)});return d};g.prototype.addMapping=function(a){var b=f.getArg(a,"generated"),d=f.getArg(a,"original",null),c=f.getArg(a,"source",null);a=f.getArg(a,"name",null);this._validateMapping(b,d,c,a);c&&!this._sources.has(c)&&this._sources.add(c);a&&!this._names.has(a)&&this._names.add(a);this._mappings.push({generatedLine:b.line,generatedColumn:b.column,originalLine:null!=d&&d.line,originalColumn:null!= +d&&d.column,source:c,name:a})};g.prototype.setSourceContent=function(a,b){var d=a;this._sourceRoot&&(d=f.relative(this._sourceRoot,d));null!==b?(this._sourcesContents||(this._sourcesContents={}),this._sourcesContents[f.toSetString(d)]=b):(delete this._sourcesContents[f.toSetString(d)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))};g.prototype.applySourceMap=function(a,b){b||(b=a.file);var d=this._sourceRoot;d&&(b=f.relative(d,b));var c=new m,e=new m;this._mappings.forEach(function(g){if(g.source=== +b&&g.originalLine){var k=a.originalPositionFor({line:g.originalLine,column:g.originalColumn});null!==k.source&&(g.source=d?f.relative(d,k.source):k.source,g.originalLine=k.line,g.originalColumn=k.column,null!==k.name&&null!==g.name&&(g.name=k.name))}(k=g.source)&&!c.has(k)&&c.add(k);(g=g.name)&&!e.has(g)&&e.add(g)},this);this._sources=c;this._names=e;a.sources.forEach(function(b){var c=a.sourceContentFor(b);c&&(d&&(b=f.relative(d,b)),this.setSourceContent(b,c))},this)};g.prototype._validateMapping= +function(a,b,d,c){if(!(a&&"line"in a&&"column"in a&&0f)-(e module and as an AMD module @@ -29,7 +34,7 @@ child_process.exec('node_modules/browserify/bin/cmd.js .temp.js', function(error output_format: 'text', js_code: code })); - child_process.exec('curl -d @.temp.js "http://closure-compiler.appspot.com/compile"', function(error, stdout) { + run('curl -d @.temp.js "http://closure-compiler.appspot.com/compile"', function(error, stdout) { if (error) throw error; var code = header + '\n' + stdout; fs.unlinkSync('.temp.js'); @@ -39,19 +44,26 @@ child_process.exec('node_modules/browserify/bin/cmd.js .temp.js', function(error }); // Build the AMD test -child_process.exec('node_modules/coffee-script/bin/coffee --map --compile amd-test/script.coffee', function(error) { +run('node_modules/coffee-script/bin/coffee --map --compile amd-test/script.coffee', function(error) { if (error) throw error; }); // Build the browserify test -child_process.exec('node_modules/coffee-script/bin/coffee --map --compile browserify-test/script.coffee', function(error) { +run('node_modules/coffee-script/bin/coffee --map --compile browserify-test/script.coffee', function(error) { if (error) throw error; - child_process.exec('node_modules/browserify/bin/cmd.js --debug browserify-test/script.js > browserify-test/compiled.js', function(error) { + run('node_modules/browserify/bin/cmd.js --debug browserify-test/script.js > browserify-test/compiled.js', function(error) { if (error) throw error; }) }); // Build the browser test -child_process.exec('node_modules/coffee-script/bin/coffee --map --compile browser-test/script.coffee', function(error) { +run('node_modules/coffee-script/bin/coffee --map --compile browser-test/script.coffee', function(error) { + if (error) throw error; +}); + +// Build the header test +run('node_modules/coffee-script/bin/coffee --map --compile header-test/script.coffee', function(error) { if (error) throw error; + var contents = fs.readFileSync('header-test/script.js', 'utf8'); + fs.writeFileSync('header-test/script.js', contents.replace(/\/\/# sourceMappingURL=.*/g, '')) }); diff --git a/header-test/index.html b/header-test/index.html new file mode 100644 index 0000000..198054c --- /dev/null +++ b/header-test/index.html @@ -0,0 +1,6 @@ +

+Make sure to run build.js, then run server.js and visit http://localhost:1337/. +This test should say either "Test failed" or "Test passed": +

+ + diff --git a/header-test/script.coffee b/header-test/script.coffee new file mode 100644 index 0000000..5721068 --- /dev/null +++ b/header-test/script.coffee @@ -0,0 +1,12 @@ +sourceMapSupport.install() + +foo = -> throw new Error 'foo' + +try + foo() +catch e + if /\bscript\.coffee\b/.test e.stack + document.body.appendChild document.createTextNode 'Test passed' + else + document.body.appendChild document.createTextNode 'Test failed' + console.log e.stack diff --git a/header-test/server.js b/header-test/server.js new file mode 100644 index 0000000..ecc0cdf --- /dev/null +++ b/header-test/server.js @@ -0,0 +1,45 @@ +var fs = require('fs'); +var http = require('http'); + +http.createServer(function(req, res) { + switch (req.url) { + case '/': + case '/index.html': { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(fs.readFileSync('index.html', 'utf8')); + break; + } + + case '/browser-source-map-support.js': { + res.writeHead(200, { 'Content-Type': 'text/javascript' }); + res.end(fs.readFileSync('../browser-source-map-support.js', 'utf8')); + break; + } + + case '/script.js': { + res.writeHead(200, { 'Content-Type': 'text/javascript', 'SourceMap': 'script-source-map.map' }); + res.end(fs.readFileSync('script.js', 'utf8')); + break; + } + + case '/script-source-map.map': { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(fs.readFileSync('script.map', 'utf8')); + break; + } + + case '/header-test/script.coffee': { + res.writeHead(200, { 'Content-Type': 'text/x-coffeescript' }); + res.end(fs.readFileSync('script.coffee', 'utf8')); + break; + } + + default: { + res.writeHead(404, { 'Content-Type': 'text/html' }); + res.end('404 not found'); + break; + } + } +}).listen(1337, '127.0.0.1'); + +console.log('Server running at http://127.0.0.1:1337/'); diff --git a/package.json b/package.json index 323e4e8..24bc57e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "source-map-support", "description": "Fixes stack traces for files with source maps", - "version": "0.2.6", + "version": "0.2.7", "main": "./source-map-support.js", "scripts": { "test": "node_modules/mocha/bin/mocha" diff --git a/source-map-support.js b/source-map-support.js index a51d50c..d855aaf 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -68,10 +68,10 @@ function retrieveSourceMapURL(source) { if (sourceMapHeader) { return sourceMapHeader; } - } else { - fileData = retrieveFile(source); } + // Get the URL of the source map + fileData = retrieveFile(source); var match = /\/\/[#@]\s*sourceMappingURL=(.*)\s*$/m.exec(fileData); if (!match) return null; return match[1];