From 1e521ff50f90901e651c7ef106d3ba168e4423fb Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 10 Oct 2018 16:25:23 -0700 Subject: [PATCH] Pass through the implementation of more section operations. --- dist/source-map.js | 2 +- lib/source-map-consumer.js | 405 +++++++++---------------------- lib/util.js | 77 ------ test/test-source-map-consumer.js | 148 +++++++++++ test/util.js | 55 +++++ 5 files changed, 315 insertions(+), 372 deletions(-) diff --git a/dist/source-map.js b/dist/source-map.js index 16b740ce..c1c6f076 100644 --- a/dist/source-map.js +++ b/dist/source-map.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("path"),require("fs")):"function"==typeof define&&define.amd?define(["path","fs"],n):"object"==typeof exports?exports.sourceMap=n(require("path"),require("fs")):e.sourceMap=n(e.path,e.fs)}(window,function(e,n){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=13)}([function(e,n){n.getArg=function(e,n,t){if(n in e)return e[n];if(3===arguments.length)return t;throw new Error('"'+n+'" is a required argument.')};const t=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/,r=/^data:.+\,.+$/;function o(e){const n=e.match(t);return n?{scheme:n[1],auth:n[2],host:n[3],port:n[4],path:n[5]}:null}function i(e){let n="";return e.scheme&&(n+=e.scheme+":"),n+="//",e.auth&&(n+=e.auth+"@"),e.host&&(n+=e.host),e.port&&(n+=":"+e.port),e.path&&(n+=e.path),n}n.urlParse=o,n.urlGenerate=i;const s=32;const l=function(e){const n=[];return function(t){for(let e=0;es&&n.pop(),r}}(function(e){let t=e;const r=o(e);if(r){if(!r.path)return e;t=r.path}const s=n.isAbsolute(t),l=[];let a=0,u=0;for(;;){if(a=u,-1===(u=t.indexOf("/",a))){l.push(t.slice(a));break}for(l.push(t.slice(a,u));u=0;u--){const e=l[u];"."===e?l.splice(u,1):".."===e?c++:c>0&&(""===e?(l.splice(u+1,c),c=0):(l.splice(u,2),c--))}return""===(t=l.join("/"))&&(t=s?"/":"."),r?(r.path=t,i(r)):t});function a(e,n){""===e&&(e="."),""===n&&(n=".");const t=o(n),s=o(e);if(s&&(e=s.path||"/"),t&&!t.scheme)return s&&(t.scheme=s.scheme),i(t);if(t||n.match(r))return n;if(s&&!s.host&&!s.path)return s.host=n,i(s);const a="/"===n.charAt(0)?n:l(e.replace(/\/+$/,"")+"/"+n);return s?(s.path=a,i(s)):a}n.normalize=l,n.join=a,n.isAbsolute=function(e){return"/"===e.charAt(0)||t.test(e)},n.relative=function(e,n){""===e&&(e="."),e=e.replace(/\/$/,"");let t=0;for(;0!==n.indexOf(e+"/");){const r=e.lastIndexOf("/");if(r<0)return n;if((e=e.slice(0,r)).match(/^([^\/]+:\/)?\/*$/))return n;++t}return Array(t+1).join("../")+n.substr(e.length+1)};const u=!("__proto__"in Object.create(null));function c(e){return e}function g(e){if(!e)return!1;const n=e.length;if(n<9)return!1;if(95!==e.charCodeAt(n-1)||95!==e.charCodeAt(n-2)||111!==e.charCodeAt(n-3)||116!==e.charCodeAt(n-4)||111!==e.charCodeAt(n-5)||114!==e.charCodeAt(n-6)||112!==e.charCodeAt(n-7)||95!==e.charCodeAt(n-8)||95!==e.charCodeAt(n-9))return!1;for(let t=n-10;t>=0;t--)if(36!==e.charCodeAt(t))return!1;return!0}function p(e,n){return e===n?0:null===e?1:null===n?-1:e>n?1:-1}n.toSetString=u?c:function(e){return g(e)?"$"+e:e},n.fromSetString=u?c:function(e){return g(e)?e.slice(1):e},n.compareByOriginalPositions=function(e,n,t){let r=p(e.source,n.source);return 0!==r?r:0!=(r=e.originalLine-n.originalLine)?r:0!=(r=e.originalColumn-n.originalColumn)||t?r:0!=(r=e.generatedColumn-n.generatedColumn)?r:0!=(r=e.generatedLine-n.generatedLine)?r:p(e.name,n.name)},n.compareByGeneratedPositionsDeflated=function(e,n,t){let r=e.generatedLine-n.generatedLine;return 0!==r?r:0!=(r=e.generatedColumn-n.generatedColumn)||t?r:0!==(r=p(e.source,n.source))?r:0!=(r=e.originalLine-n.originalLine)?r:0!=(r=e.originalColumn-n.originalColumn)?r:p(e.name,n.name)},n.compareByGeneratedPositionsInflated=function(e,n){let t=e.generatedLine-n.generatedLine;return 0!==t?t:0!=(t=e.generatedColumn-n.generatedColumn)?t:0!==(t=p(e.source,n.source))?t:0!=(t=e.originalLine-n.originalLine)?t:0!=(t=e.originalColumn-n.originalColumn)?t:p(e.name,n.name)},n.parseSourceMapInput=function(e){return JSON.parse(e.replace(/^\)]}'[^\n]*\n/,""))},n.computeSourceURL=function(e,n,t){if(n=n||"",e&&("/"!==e[e.length-1]&&"/"!==n[0]&&(e+="/"),n=e+n),t){const e=o(t);if(!e)throw new Error("sourceMapURL could not be parsed");if(e.path){const n=e.path.lastIndexOf("/");n>=0&&(e.path=e.path.substring(0,n+1))}n=a(i(e),n)}return l(n)}},function(e,n,t){(function(n){if(function(){return"undefined"!=typeof window&&this===window}.call()){let n=null;e.exports=function(){if("string"==typeof n)return fetch(n).then(e=>e.arrayBuffer());if(n instanceof ArrayBuffer)return Promise.resolve(n);throw new Error("You must provide the string URL or ArrayBuffer contents of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer")},e.exports.initialize=(e=>n=e)}else{const r=t(8),o=t(7);e.exports=function(){return new Promise((e,t)=>{const i=o.join(n,"mappings.wasm");r.readFile(i,null,(n,r)=>{n?t(n):e(r.buffer)})})},e.exports.initialize=(e=>{console.debug("SourceMapConsumer.initialize is a no-op when running in node.js")})}}).call(this,"/")},function(e,n){class t{constructor(){this._array=[],this._set=new Map}static fromArray(e,n){const r=new t;for(let t=0,o=e.length;t=0)return n;throw new Error('"'+e+'" is not in the set.')}at(e){if(e>=0&&e>>=5)>0&&(n|=32),t+=r.encode(n)}while(o>0);return t}},function(e,n,t){const r=t(3),o=t(0),i=t(2).ArraySet,s=t(11).MappingList;class l{constructor(e){e||(e={}),this._file=o.getArg(e,"file",null),this._sourceRoot=o.getArg(e,"sourceRoot",null),this._skipValidation=o.getArg(e,"skipValidation",!1),this._sources=new i,this._names=new i,this._mappings=new s,this._sourcesContents=null}static fromSourceMap(e){const n=e.sourceRoot,t=new l({file:e.file,sourceRoot:n});return e.eachMapping(function(e){const r={generated:{line:e.generatedLine,column:e.generatedColumn}};null!=e.source&&(r.source=e.source,null!=n&&(r.source=o.relative(n,r.source)),r.original={line:e.originalLine,column:e.originalColumn},null!=e.name&&(r.name=e.name)),t.addMapping(r)}),e.sources.forEach(function(r){let i=r;null!==n&&(i=o.relative(n,r)),t._sources.has(i)||t._sources.add(i);const s=e.sourceContentFor(r);null!=s&&t.setSourceContent(r,s)}),t}addMapping(e){const n=o.getArg(e,"generated"),t=o.getArg(e,"original",null);let r=o.getArg(e,"source",null),i=o.getArg(e,"name",null);this._skipValidation||this._validateMapping(n,t,r,i),null!=r&&(r=String(r),this._sources.has(r)||this._sources.add(r)),null!=i&&(i=String(i),this._names.has(i)||this._names.add(i)),this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:null!=t&&t.line,originalColumn:null!=t&&t.column,source:r,name:i})}setSourceContent(e,n){let t=e;null!=this._sourceRoot&&(t=o.relative(this._sourceRoot,t)),null!=n?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[o.toSetString(t)]=n):this._sourcesContents&&(delete this._sourcesContents[o.toSetString(t)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))}applySourceMap(e,n,t){let r=n;if(null==n){if(null==e.file)throw new Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');r=e.file}const s=this._sourceRoot;null!=s&&(r=o.relative(s,r));const l=this._mappings.toArray().length>0?new i:this._sources,a=new i;this._mappings.unsortedForEach(function(n){if(n.source===r&&null!=n.originalLine){const r=e.originalPositionFor({line:n.originalLine,column:n.originalColumn});null!=r.source&&(n.source=r.source,null!=t&&(n.source=o.join(t,n.source)),null!=s&&(n.source=o.relative(s,n.source)),n.originalLine=r.line,n.originalColumn=r.column,null!=r.name&&(n.name=r.name))}const i=n.source;null==i||l.has(i)||l.add(i);const u=n.name;null==u||a.has(u)||a.add(u)},this),this._sources=l,this._names=a,e.sources.forEach(function(n){const r=e.sourceContentFor(n);null!=r&&(null!=t&&(n=o.join(t,n)),null!=s&&(n=o.relative(s,n)),this.setSourceContent(n,r))},this)}_validateMapping(e,n,t,r){if(n&&"number"!=typeof n.line&&"number"!=typeof n.column)throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0&&!n&&!t&&!r);else if(!(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&t))throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:t,original:n,name:r}))}_serializeMappings(){let e,n,t,i,s=0,l=1,a=0,u=0,c=0,g=0,p="";const h=this._mappings.toArray();for(let m=0,d=h.length;m0){if(!o.compareByGeneratedPositionsInflated(n,h[m-1]))continue;e+=","}e+=r.encode(n.generatedColumn-s),s=n.generatedColumn,null!=n.source&&(i=this._sources.indexOf(n.source),e+=r.encode(i-g),g=i,e+=r.encode(n.originalLine-1-u),u=n.originalLine-1,e+=r.encode(n.originalColumn-a),a=n.originalColumn,null!=n.name&&(t=this._names.indexOf(n.name),e+=r.encode(t-c),c=t)),p+=e}return p}_generateSourcesContent(e,n){return e.map(function(e){if(!this._sourcesContents)return null;null!=n&&(e=o.relative(n,e));const t=o.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,t)?this._sourcesContents[t]:null},this)}toJSON(){const e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(e.file=this._file),null!=this._sourceRoot&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e}toString(){return JSON.stringify(this.toJSON())}}l.prototype._version=3,n.SourceMapGenerator=l},function(e,n,t){const r=t(4).SourceMapGenerator,o=t(0),i=/(\r?\n)/,s=10,l="$$$isSourceNode$$$";class a{constructor(e,n,t,r,o){this.children=[],this.sourceContents={},this.line=null==e?null:e,this.column=null==n?null:n,this.source=null==t?null:t,this.name=null==o?null:o,this[l]=!0,null!=r&&this.add(r)}static fromStringWithSourceMap(e,n,t){const r=new a,s=e.split(i);let l=0;const u=function(){return e()+(e()||"");function e(){return l=0;n--)this.prepend(e[n]);else{if(!e[l]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);this.children.unshift(e)}return this}walk(e){let n;for(let t=0,r=this.children.length;t0){for(n=[],t=0;tWebAssembly.instantiate(n,{env:{mapping_callback(n,t,r,o,i,s,l,a,u,c){const g=new function(){this.generatedLine=0,this.generatedColumn=0,this.lastGeneratedColumn=null,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null};g.generatedLine=n+1,g.generatedColumn=t,r&&(g.lastGeneratedColumn=o-1),i&&(g.source=s,g.originalLine=l+1,g.originalColumn=a,u&&(g.name=c)),e[e.length-1](g)},start_all_generated_locations_for(){console.time("all_generated_locations_for")},end_all_generated_locations_for(){console.timeEnd("all_generated_locations_for")},start_compute_column_spans(){console.time("compute_column_spans")},end_compute_column_spans(){console.timeEnd("compute_column_spans")},start_generated_location_for(){console.time("generated_location_for")},end_generated_location_for(){console.timeEnd("generated_location_for")},start_original_location_for(){console.time("original_location_for")},end_original_location_for(){console.timeEnd("original_location_for")},start_parse_mappings(){console.time("parse_mappings")},end_parse_mappings(){console.timeEnd("parse_mappings")},start_sort_by_generated_location(){console.time("sort_by_generated_location")},end_sort_by_generated_location(){console.timeEnd("sort_by_generated_location")},start_sort_by_original_location(){console.time("sort_by_original_location")},end_sort_by_original_location(){console.timeEnd("sort_by_original_location")}}})).then(n=>({exports:n.instance.exports,withMappingCallback:(n,t)=>{e.push(n);try{t()}finally{e.pop()}}})).then(null,e=>{throw o=null,e})}},function(n,t){n.exports=e},function(e,t){e.exports=n},function(e,n){n.GREATEST_LOWER_BOUND=1,n.LEAST_UPPER_BOUND=2,n.search=function(e,t,r,o){if(0===t.length)return-1;let i=function e(t,r,o,i,s,l){const a=Math.floor((r-t)/2)+t,u=s(o,i[a],!0);return 0===u?a:u>0?r-a>1?e(a,r,o,i,s,l):l==n.LEAST_UPPER_BOUND?r1?e(t,a,o,i,s,l):l==n.LEAST_UPPER_BOUND?a:t<0?-1:t}(-1,t.length,e,t,r,o||n.GREATEST_LOWER_BOUND);if(i<0)return-1;for(;i-1>=0&&0===r(t[i],t[i-1],!0);)--i;return i}},function(e,n,t){const r=t(0),o=t(9),i=t(2).ArraySet,s=(t(3),t(1)),l=t(6),a=Symbol("smcInternal");class u{constructor(e,n){return e==a?Promise.resolve(this):function(e,n){let t=e;"string"==typeof e&&(t=r.parseSourceMapInput(e));const o=null!=t.sections?new g(t,n):new c(t,n);return Promise.resolve(o)}(e,n)}static initialize(e){s.initialize(e["lib/mappings.wasm"])}static fromSourceMap(e,n){return function(e,n){return c.fromSourceMap(e,n)}(e,n)}static async with(e,n,t){const r=await new u(e,n);try{return await t(r)}finally{r.destroy()}}_parseMappings(e,n){throw new Error("Subclasses must implement _parseMappings")}eachMapping(e,n,t){throw new Error("Subclasses must implement eachMapping")}allGeneratedPositionsFor(e){throw new Error("Subclasses must implement allGeneratedPositionsFor")}destroy(){throw new Error("Subclasses must implement destroy")}}u.prototype._version=3,u.GENERATED_ORDER=1,u.ORIGINAL_ORDER=2,u.GREATEST_LOWER_BOUND=1,u.LEAST_UPPER_BOUND=2,n.SourceMapConsumer=u;class c extends u{constructor(e,n){return super(a).then(t=>{let o=e;"string"==typeof e&&(o=r.parseSourceMapInput(e));const s=r.getArg(o,"version");let a=r.getArg(o,"sources");const u=r.getArg(o,"names",[]);let c=r.getArg(o,"sourceRoot",null);const g=r.getArg(o,"sourcesContent",null),p=r.getArg(o,"mappings"),h=r.getArg(o,"file",null);if(s!=t._version)throw new Error("Unsupported version: "+s);return c&&(c=r.normalize(c)),a=a.map(String).map(r.normalize).map(function(e){return c&&r.isAbsolute(c)&&r.isAbsolute(e)?r.relative(c,e):e}),t._names=i.fromArray(u.map(String),!0),t._sources=i.fromArray(a,!0),t._absoluteSources=t._sources.toArray().map(function(e){return r.computeSourceURL(c,e,n)}),t.sourceRoot=c,t.sourcesContent=g,t._mappings=p,t._sourceMapURL=n,t.file=h,t._computedColumnSpans=!1,t._mappingsPtr=0,t._wasm=null,l().then(e=>(t._wasm=e,t))})}_findSourceIndex(e){let n=e;if(null!=this.sourceRoot&&(n=r.relative(this.sourceRoot,n)),this._sources.has(n))return this._sources.indexOf(n);for(let n=0;n{null!==n.source&&(n.source=this._sources.at(n.source),n.source=r.computeSourceURL(s,n.source,this._sourceMapURL),null!==n.name&&(n.name=this._names.at(n.name))),e.call(o,n)},()=>{switch(i){case u.GENERATED_ORDER:this._wasm.exports.by_generated_location(this._getMappingsPtr());break;case u.ORIGINAL_ORDER:this._wasm.exports.by_original_location(this._getMappingsPtr());break;default:throw new Error("Unknown order of iteration.")}})}allGeneratedPositionsFor(e){let n=r.getArg(e,"source");const t=r.getArg(e,"line"),o=e.column||0;if((n=this._findSourceIndex(n))<0)return[];if(t<1)throw new Error("Line numbers must be >= 1");if(o<0)throw new Error("Column numbers must be >= 0");const i=[];return this._wasm.withMappingCallback(e=>{let n=e.lastGeneratedColumn;this._computedColumnSpans&&null===n&&(n=1/0),i.push({line:e.generatedLine,column:e.generatedColumn,lastColumn:n})},()=>{this._wasm.exports.all_generated_locations_for(this._getMappingsPtr(),n,t-1,"column"in e,o)}),i}destroy(){0!==this._mappingsPtr&&(this._wasm.exports.free_mappings(this._mappingsPtr),this._mappingsPtr=0)}computeColumnSpans(){this._computedColumnSpans||(this._wasm.exports.compute_column_spans(this._getMappingsPtr()),this._computedColumnSpans=!0)}originalPositionFor(e){const n={generatedLine:r.getArg(e,"line"),generatedColumn:r.getArg(e,"column")};if(n.generatedLine<1)throw new Error("Line numbers must be >= 1");if(n.generatedColumn<0)throw new Error("Column numbers must be >= 0");let t,o=r.getArg(e,"bias",u.GREATEST_LOWER_BOUND);if(null==o&&(o=u.GREATEST_LOWER_BOUND),this._wasm.withMappingCallback(e=>t=e,()=>{this._wasm.exports.original_location_for(this._getMappingsPtr(),n.generatedLine-1,n.generatedColumn,o)}),t&&t.generatedLine===n.generatedLine){let e=r.getArg(t,"source",null);null!==e&&(e=this._sources.at(e),e=r.computeSourceURL(this.sourceRoot,e,this._sourceMapURL));let n=r.getArg(t,"name",null);return null!==n&&(n=this._names.at(n)),{source:e,line:r.getArg(t,"originalLine",null),column:r.getArg(t,"originalColumn",null),name:n}}return{source:null,line:null,column:null,name:null}}hasContentsOfAllSources(){return!!this.sourcesContent&&(this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(e){return null==e}))}sourceContentFor(e,n){if(!this.sourcesContent)return null;const t=this._findSourceIndex(e);if(t>=0)return this.sourcesContent[t];let o,i=e;if(null!=this.sourceRoot&&(i=r.relative(this.sourceRoot,i)),null!=this.sourceRoot&&(o=r.urlParse(this.sourceRoot))){const e=i.replace(/^file:\/\//,"");if("file"==o.scheme&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!o.path||"/"==o.path)&&this._sources.has("/"+i))return this.sourcesContent[this._sources.indexOf("/"+i)]}if(n)return null;throw new Error('"'+i+'" is not in the SourceMap.')}generatedPositionFor(e){let n=r.getArg(e,"source");if((n=this._findSourceIndex(n))<0)return{line:null,column:null,lastColumn:null};const t={source:n,originalLine:r.getArg(e,"line"),originalColumn:r.getArg(e,"column")};if(t.originalLine<1)throw new Error("Line numbers must be >= 1");if(t.originalColumn<0)throw new Error("Column numbers must be >= 0");let o,i=r.getArg(e,"bias",u.GREATEST_LOWER_BOUND);if(null==i&&(i=u.GREATEST_LOWER_BOUND),this._wasm.withMappingCallback(e=>o=e,()=>{this._wasm.exports.generated_location_for(this._getMappingsPtr(),t.source,t.originalLine-1,t.originalColumn,i)}),o&&o.source===t.source){let e=o.lastGeneratedColumn;return this._computedColumnSpans&&null===e&&(e=1/0),{line:r.getArg(o,"generatedLine",null),column:r.getArg(o,"generatedColumn",null),lastColumn:e}}return{line:null,column:null,lastColumn:null}}}c.prototype.consumer=u,n.BasicSourceMapConsumer=c;class g extends u{constructor(e,n){return super(a).then(t=>{let o=e;"string"==typeof e&&(o=r.parseSourceMapInput(e));const s=r.getArg(o,"version"),l=r.getArg(o,"sections");if(s!=t._version)throw new Error("Unsupported version: "+s);t._sources=new i,t._names=new i,t.__generatedMappings=null,t.__originalMappings=null,t.__generatedMappingsUnsorted=null,t.__originalMappingsUnsorted=null;let a={line:-1,column:0};return Promise.all(l.map(e=>{if(e.url)throw new Error("Support for url field in sections not implemented.");const t=r.getArg(e,"offset"),o=r.getArg(t,"line"),i=r.getArg(t,"column");if(o({generatedOffset:{generatedLine:o+1,generatedColumn:i+1},consumer:e}))})).then(e=>(t._sections=e,t))})}get _generatedMappings(){return this.__generatedMappings||this._sortGeneratedMappings(),this.__generatedMappings}get _originalMappings(){return this.__originalMappings||this._sortOriginalMappings(),this.__originalMappings}get _generatedMappingsUnsorted(){return this.__generatedMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__generatedMappingsUnsorted}get _originalMappingsUnsorted(){return this.__originalMappingsUnsorted||this._parseMappings(this._mappings,this.sourceRoot),this.__originalMappingsUnsorted}_sortGeneratedMappings(){const e=this._generatedMappingsUnsorted;e.sort(r.compareByGeneratedPositionsDeflated),this.__generatedMappings=e}_sortOriginalMappings(){const e=this._originalMappingsUnsorted;e.sort(r.compareByOriginalPositions),this.__originalMappings=e}get sources(){const e=[];for(let n=0;ni.push(e));for(let e=0;e= 1");if(t.originalColumn<0)throw new Error("Column numbers must be >= 0");const i=[];let s=this._findMapping(t,this._originalMappings,"originalLine","originalColumn",r.compareByOriginalPositions,o.LEAST_UPPER_BOUND);if(s>=0){let t=this._originalMappings[s];if(void 0===e.column){const e=t.originalLine;for(;t&&t.originalLine===e;){let e=t.lastGeneratedColumn;this._computedColumnSpans&&null===e&&(e=1/0),i.push({line:r.getArg(t,"generatedLine",null),column:r.getArg(t,"generatedColumn",null),lastColumn:e}),t=this._originalMappings[++s]}}else{const e=t.originalColumn;for(;t&&t.originalLine===n&&t.originalColumn==e;){let e=t.lastGeneratedColumn;this._computedColumnSpans&&null===e&&(e=1/0),i.push({line:r.getArg(t,"generatedLine",null),column:r.getArg(t,"generatedColumn",null),lastColumn:e}),t=this._originalMappings[++s]}}}return i}destroy(){for(let e=0;et||o==t&&s>=i||r.compareByGeneratedPositionsInflated(e,n)<=0}(this._last,e)?(this._sorted=!1,this._array.push(e)):(this._last=e,this._array.push(e))}toArray(){return this._sorted||(this._array.sort(r.compareByGeneratedPositionsInflated),this._sorted=!0),this._array}}},function(e,n){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");n.encode=function(e){if(0<=e&&ei&&n.pop(),r}}(function(e){let t=e;const r=o(e);if(r){if(!r.path)return e;t=r.path}const i=n.isAbsolute(t),l=[];let u=0,a=0;for(;;){if(u=a,-1===(a=t.indexOf("/",u))){l.push(t.slice(u));break}for(l.push(t.slice(u,a));a=0;a--){const e=l[a];"."===e?l.splice(a,1):".."===e?c++:c>0&&(""===e?(l.splice(a+1,c),c=0):(l.splice(a,2),c--))}return""===(t=l.join("/"))&&(t=i?"/":"."),r?(r.path=t,s(r)):t});function u(e,n){""===e&&(e="."),""===n&&(n=".");const t=o(n),i=o(e);if(i&&(e=i.path||"/"),t&&!t.scheme)return i&&(t.scheme=i.scheme),s(t);if(t||n.match(r))return n;if(i&&!i.host&&!i.path)return i.host=n,s(i);const u="/"===n.charAt(0)?n:l(e.replace(/\/+$/,"")+"/"+n);return i?(i.path=u,s(i)):u}n.normalize=l,n.join=u,n.isAbsolute=function(e){return"/"===e.charAt(0)||t.test(e)},n.relative=function(e,n){""===e&&(e="."),e=e.replace(/\/$/,"");let t=0;for(;0!==n.indexOf(e+"/");){const r=e.lastIndexOf("/");if(r<0)return n;if((e=e.slice(0,r)).match(/^([^\/]+:\/)?\/*$/))return n;++t}return Array(t+1).join("../")+n.substr(e.length+1)};const a=!("__proto__"in Object.create(null));function c(e){return e}function h(e){if(!e)return!1;const n=e.length;if(n<9)return!1;if(95!==e.charCodeAt(n-1)||95!==e.charCodeAt(n-2)||111!==e.charCodeAt(n-3)||116!==e.charCodeAt(n-4)||111!==e.charCodeAt(n-5)||114!==e.charCodeAt(n-6)||112!==e.charCodeAt(n-7)||95!==e.charCodeAt(n-8)||95!==e.charCodeAt(n-9))return!1;for(let t=n-10;t>=0;t--)if(36!==e.charCodeAt(t))return!1;return!0}function g(e,n){return e===n?0:null===e?1:null===n?-1:e>n?1:-1}n.toSetString=a?c:function(e){return h(e)?"$"+e:e},n.fromSetString=a?c:function(e){return h(e)?e.slice(1):e},n.compareByGeneratedPositionsInflated=function(e,n){let t=e.generatedLine-n.generatedLine;return 0!==t?t:0!=(t=e.generatedColumn-n.generatedColumn)?t:0!==(t=g(e.source,n.source))?t:0!=(t=e.originalLine-n.originalLine)?t:0!=(t=e.originalColumn-n.originalColumn)?t:g(e.name,n.name)},n.parseSourceMapInput=function(e){return JSON.parse(e.replace(/^\)]}'[^\n]*\n/,""))},n.computeSourceURL=function(e,n,t){if(n=n||"",e&&("/"!==e[e.length-1]&&"/"!==n[0]&&(e+="/"),n=e+n),t){const e=o(t);if(!e)throw new Error("sourceMapURL could not be parsed");if(e.path){const n=e.path.lastIndexOf("/");n>=0&&(e.path=e.path.substring(0,n+1))}n=u(s(e),n)}return l(n)}},function(e,n,t){const r=t(2),o=t(0),s=t(3).ArraySet,i=t(7).MappingList;class l{constructor(e){e||(e={}),this._file=o.getArg(e,"file",null),this._sourceRoot=o.getArg(e,"sourceRoot",null),this._skipValidation=o.getArg(e,"skipValidation",!1),this._sources=new s,this._names=new s,this._mappings=new i,this._sourcesContents=null}static fromSourceMap(e){const n=e.sourceRoot,t=new l({file:e.file,sourceRoot:n});return e.eachMapping(function(e){const r={generated:{line:e.generatedLine,column:e.generatedColumn}};null!=e.source&&(r.source=e.source,null!=n&&(r.source=o.relative(n,r.source)),r.original={line:e.originalLine,column:e.originalColumn},null!=e.name&&(r.name=e.name)),t.addMapping(r)}),e.sources.forEach(function(r){let s=r;null!==n&&(s=o.relative(n,r)),t._sources.has(s)||t._sources.add(s);const i=e.sourceContentFor(r);null!=i&&t.setSourceContent(r,i)}),t}addMapping(e){const n=o.getArg(e,"generated"),t=o.getArg(e,"original",null);let r=o.getArg(e,"source",null),s=o.getArg(e,"name",null);this._skipValidation||this._validateMapping(n,t,r,s),null!=r&&(r=String(r),this._sources.has(r)||this._sources.add(r)),null!=s&&(s=String(s),this._names.has(s)||this._names.add(s)),this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:null!=t&&t.line,originalColumn:null!=t&&t.column,source:r,name:s})}setSourceContent(e,n){let t=e;null!=this._sourceRoot&&(t=o.relative(this._sourceRoot,t)),null!=n?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[o.toSetString(t)]=n):this._sourcesContents&&(delete this._sourcesContents[o.toSetString(t)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))}applySourceMap(e,n,t){let r=n;if(null==n){if(null==e.file)throw new Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');r=e.file}const i=this._sourceRoot;null!=i&&(r=o.relative(i,r));const l=this._mappings.toArray().length>0?new s:this._sources,u=new s;this._mappings.unsortedForEach(function(n){if(n.source===r&&null!=n.originalLine){const r=e.originalPositionFor({line:n.originalLine,column:n.originalColumn});null!=r.source&&(n.source=r.source,null!=t&&(n.source=o.join(t,n.source)),null!=i&&(n.source=o.relative(i,n.source)),n.originalLine=r.line,n.originalColumn=r.column,null!=r.name&&(n.name=r.name))}const s=n.source;null==s||l.has(s)||l.add(s);const a=n.name;null==a||u.has(a)||u.add(a)},this),this._sources=l,this._names=u,e.sources.forEach(function(n){const r=e.sourceContentFor(n);null!=r&&(null!=t&&(n=o.join(t,n)),null!=i&&(n=o.relative(i,n)),this.setSourceContent(n,r))},this)}_validateMapping(e,n,t,r){if(n&&"number"!=typeof n.line&&"number"!=typeof n.column)throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0&&!n&&!t&&!r);else if(!(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&t))throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:t,original:n,name:r}))}_serializeMappings(){let e,n,t,s,i=0,l=1,u=0,a=0,c=0,h=0,g="";const p=this._mappings.toArray();for(let m=0,d=p.length;m0){if(!o.compareByGeneratedPositionsInflated(n,p[m-1]))continue;e+=","}e+=r.encode(n.generatedColumn-i),i=n.generatedColumn,null!=n.source&&(s=this._sources.indexOf(n.source),e+=r.encode(s-h),h=s,e+=r.encode(n.originalLine-1-a),a=n.originalLine-1,e+=r.encode(n.originalColumn-u),u=n.originalColumn,null!=n.name&&(t=this._names.indexOf(n.name),e+=r.encode(t-c),c=t)),g+=e}return g}_generateSourcesContent(e,n){return e.map(function(e){if(!this._sourcesContents)return null;null!=n&&(e=o.relative(n,e));const t=o.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,t)?this._sourcesContents[t]:null},this)}toJSON(){const e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(e.file=this._file),null!=this._sourceRoot&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e}toString(){return JSON.stringify(this.toJSON())}}l.prototype._version=3,n.SourceMapGenerator=l},function(e,n,t){const r=t(6);n.encode=function(e){let n,t="",o=function(e){return e<0?1+(-e<<1):0+(e<<1)}(e);do{n=31&o,(o>>>=5)>0&&(n|=32),t+=r.encode(n)}while(o>0);return t}},function(e,n){class t{constructor(){this._array=[],this._set=new Map}static fromArray(e,n){const r=new t;for(let t=0,o=e.length;t=0)return n;throw new Error('"'+e+'" is not in the set.')}at(e){if(e>=0&&ee.arrayBuffer());if(n instanceof ArrayBuffer)return Promise.resolve(n);throw new Error("You must provide the string URL or ArrayBuffer contents of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer")},e.exports.initialize=(e=>n=e)}else{const r=t(10),o=t(11);e.exports=function(){return new Promise((e,t)=>{const s=o.join(n,"mappings.wasm");r.readFile(s,null,(n,r)=>{n?t(n):e(r.buffer)})})},e.exports.initialize=(e=>{console.debug("SourceMapConsumer.initialize is a no-op when running in node.js")})}}).call(this,"/")},function(e,n,t){n.SourceMapGenerator=t(1).SourceMapGenerator,n.SourceMapConsumer=t(8).SourceMapConsumer,n.SourceNode=t(13).SourceNode},function(e,n){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");n.encode=function(e){if(0<=e&&et||o==t&&i>=s||r.compareByGeneratedPositionsInflated(e,n)<=0}(this._last,e)?(this._sorted=!1,this._array.push(e)):(this._last=e,this._array.push(e))}toArray(){return this._sorted||(this._array.sort(r.compareByGeneratedPositionsInflated),this._sorted=!0),this._array}}},function(e,n,t){const r=t(0),o=t(9),s=t(3).ArraySet,i=(t(2),t(4)),l=t(12),u=Symbol("smcInternal");class a{constructor(e,n){return e==u?Promise.resolve(this):function(e,n){let t=e;"string"==typeof e&&(t=r.parseSourceMapInput(e));const o=null!=t.sections?new h(t,n):new c(t,n);return Promise.resolve(o)}(e,n)}static initialize(e){i.initialize(e["lib/mappings.wasm"])}static fromSourceMap(e,n){return function(e,n){return c.fromSourceMap(e,n)}(e,n)}static async with(e,n,t){const r=await new a(e,n);try{return await t(r)}finally{r.destroy()}}eachMapping(e,n,t){throw new Error("Subclasses must implement eachMapping")}allGeneratedPositionsFor(e){throw new Error("Subclasses must implement allGeneratedPositionsFor")}destroy(){throw new Error("Subclasses must implement destroy")}}a.prototype._version=3,a.GENERATED_ORDER=1,a.ORIGINAL_ORDER=2,a.GREATEST_LOWER_BOUND=1,a.LEAST_UPPER_BOUND=2,n.SourceMapConsumer=a;class c extends a{constructor(e,n){return super(u).then(t=>{let o=e;"string"==typeof e&&(o=r.parseSourceMapInput(e));const i=r.getArg(o,"version");let u=r.getArg(o,"sources");const a=r.getArg(o,"names",[]);let c=r.getArg(o,"sourceRoot",null);const h=r.getArg(o,"sourcesContent",null),g=r.getArg(o,"mappings"),p=r.getArg(o,"file",null);if(i!=t._version)throw new Error("Unsupported version: "+i);return c&&(c=r.normalize(c)),u=u.map(String).map(r.normalize).map(function(e){return c&&r.isAbsolute(c)&&r.isAbsolute(e)?r.relative(c,e):e}),t._names=s.fromArray(a.map(String),!0),t._sources=s.fromArray(u,!0),t._absoluteSources=t._sources.toArray().map(function(e){return r.computeSourceURL(c,e,n)}),t.sourceRoot=c,t.sourcesContent=h,t._mappings=g,t._sourceMapURL=n,t.file=p,t._computedColumnSpans=!1,t._mappingsPtr=0,t._wasm=null,l().then(e=>(t._wasm=e,t))})}_findSourceIndex(e){let n=e;if(null!=this.sourceRoot&&(n=r.relative(this.sourceRoot,n)),this._sources.has(n))return this._sources.indexOf(n);for(let n=0;n{null!==n.source&&(n.source=this._sources.at(n.source),n.source=r.computeSourceURL(i,n.source,this._sourceMapURL),null!==n.name&&(n.name=this._names.at(n.name))),this._computedColumnSpans&&null===n.lastGeneratedColumn&&(n.lastGeneratedColumn=1/0),e.call(o,n)},()=>{switch(s){case a.GENERATED_ORDER:this._wasm.exports.by_generated_location(this._getMappingsPtr());break;case a.ORIGINAL_ORDER:this._wasm.exports.by_original_location(this._getMappingsPtr());break;default:throw new Error("Unknown order of iteration.")}})}allGeneratedPositionsFor(e){let n=r.getArg(e,"source");const t=r.getArg(e,"line"),o=e.column||0;if((n=this._findSourceIndex(n))<0)return[];if(t<1)throw new Error("Line numbers must be >= 1");if(o<0)throw new Error("Column numbers must be >= 0");const s=[];return this._wasm.withMappingCallback(e=>{let n=e.lastGeneratedColumn;this._computedColumnSpans&&null===n&&(n=1/0),s.push({line:e.generatedLine,column:e.generatedColumn,lastColumn:n})},()=>{this._wasm.exports.all_generated_locations_for(this._getMappingsPtr(),n,t-1,"column"in e,o)}),s}destroy(){0!==this._mappingsPtr&&(this._wasm.exports.free_mappings(this._mappingsPtr),this._mappingsPtr=0)}computeColumnSpans(){this._computedColumnSpans||(this._wasm.exports.compute_column_spans(this._getMappingsPtr()),this._computedColumnSpans=!0)}originalPositionFor(e){const n={generatedLine:r.getArg(e,"line"),generatedColumn:r.getArg(e,"column")};if(n.generatedLine<1)throw new Error("Line numbers must be >= 1");if(n.generatedColumn<0)throw new Error("Column numbers must be >= 0");let t,o=r.getArg(e,"bias",a.GREATEST_LOWER_BOUND);if(null==o&&(o=a.GREATEST_LOWER_BOUND),this._wasm.withMappingCallback(e=>t=e,()=>{this._wasm.exports.original_location_for(this._getMappingsPtr(),n.generatedLine-1,n.generatedColumn,o)}),t&&t.generatedLine===n.generatedLine){let e=r.getArg(t,"source",null);null!==e&&(e=this._sources.at(e),e=r.computeSourceURL(this.sourceRoot,e,this._sourceMapURL));let n=r.getArg(t,"name",null);return null!==n&&(n=this._names.at(n)),{source:e,line:r.getArg(t,"originalLine",null),column:r.getArg(t,"originalColumn",null),name:n}}return{source:null,line:null,column:null,name:null}}hasContentsOfAllSources(){return!!this.sourcesContent&&(this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(e){return null==e}))}sourceContentFor(e,n){if(!this.sourcesContent)return null;const t=this._findSourceIndex(e);if(t>=0)return this.sourcesContent[t];let o,s=e;if(null!=this.sourceRoot&&(s=r.relative(this.sourceRoot,s)),null!=this.sourceRoot&&(o=r.urlParse(this.sourceRoot))){const e=s.replace(/^file:\/\//,"");if("file"==o.scheme&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!o.path||"/"==o.path)&&this._sources.has("/"+s))return this.sourcesContent[this._sources.indexOf("/"+s)]}if(n)return null;throw new Error('"'+s+'" is not in the SourceMap.')}generatedPositionFor(e){let n=r.getArg(e,"source");if((n=this._findSourceIndex(n))<0)return{line:null,column:null,lastColumn:null};const t={source:n,originalLine:r.getArg(e,"line"),originalColumn:r.getArg(e,"column")};if(t.originalLine<1)throw new Error("Line numbers must be >= 1");if(t.originalColumn<0)throw new Error("Column numbers must be >= 0");let o,s=r.getArg(e,"bias",a.GREATEST_LOWER_BOUND);if(null==s&&(s=a.GREATEST_LOWER_BOUND),this._wasm.withMappingCallback(e=>o=e,()=>{this._wasm.exports.generated_location_for(this._getMappingsPtr(),t.source,t.originalLine-1,t.originalColumn,s)}),o&&o.source===t.source){let e=o.lastGeneratedColumn;return this._computedColumnSpans&&null===e&&(e=1/0),{line:r.getArg(o,"generatedLine",null),column:r.getArg(o,"generatedColumn",null),lastColumn:e}}return{line:null,column:null,lastColumn:null}}}c.prototype.consumer=a,n.BasicSourceMapConsumer=c;class h extends a{constructor(e,n){return super(u).then(t=>{let o=e;"string"==typeof e&&(o=r.parseSourceMapInput(e));const s=r.getArg(o,"version"),i=r.getArg(o,"sections");if(s!=t._version)throw new Error("Unsupported version: "+s);let l={line:-1,column:0};return Promise.all(i.map(e=>{if(e.url)throw new Error("Support for url field in sections not implemented.");const t=r.getArg(e,"offset"),o=r.getArg(t,"line"),s=r.getArg(t,"column");if(o({generatedOffset:{generatedLine:o+1,generatedColumn:s+1},consumer:e}))})).then(e=>(t._sections=e,t))})}get sources(){const e=[];for(let n=0;n=0?this._sections[n]:null,o=n>=0&&n+1=0?this._sections[n]:null,o=n>=0&&n+1{const n=t.generatedOffset.generatedLine-1,r=t.generatedOffset.generatedColumn-1;return 1===e.line&&(e.column+=r,"number"==typeof e.lastColumn&&(e.lastColumn+=r)),e.lastColumn===1/0&&o&&e.line===o.generatedOffset.generatedLine&&(e.lastColumn=o.generatedOffset.generatedColumn-2),e.line+=n,e}):[]}eachMapping(e,n,t){this._sections.forEach((r,o)=>{const s=o+10?r-u>1?e(u,r,o,s,i,l):l==n.LEAST_UPPER_BOUND?r1?e(t,u,o,s,i,l):l==n.LEAST_UPPER_BOUND?u:t<0?-1:t}(-1,t.length,e,t,r,o||n.GREATEST_LOWER_BOUND);if(s<0)return-1;for(;s-1>=0&&0===r(t[s],t[s-1],!0);)--s;return s}},function(n,t){n.exports=e},function(e,t){e.exports=n},function(e,n,t){const r=t(4);let o=null;e.exports=function(){if(o)return o;const e=[];return o=r().then(n=>WebAssembly.instantiate(n,{env:{mapping_callback(n,t,r,o,s,i,l,u,a,c){const h=new function(){this.generatedLine=0,this.generatedColumn=0,this.lastGeneratedColumn=null,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null};h.generatedLine=n+1,h.generatedColumn=t,r&&(h.lastGeneratedColumn=o-1),s&&(h.source=i,h.originalLine=l+1,h.originalColumn=u,a&&(h.name=c)),e[e.length-1](h)},start_all_generated_locations_for(){console.time("all_generated_locations_for")},end_all_generated_locations_for(){console.timeEnd("all_generated_locations_for")},start_compute_column_spans(){console.time("compute_column_spans")},end_compute_column_spans(){console.timeEnd("compute_column_spans")},start_generated_location_for(){console.time("generated_location_for")},end_generated_location_for(){console.timeEnd("generated_location_for")},start_original_location_for(){console.time("original_location_for")},end_original_location_for(){console.timeEnd("original_location_for")},start_parse_mappings(){console.time("parse_mappings")},end_parse_mappings(){console.timeEnd("parse_mappings")},start_sort_by_generated_location(){console.time("sort_by_generated_location")},end_sort_by_generated_location(){console.timeEnd("sort_by_generated_location")},start_sort_by_original_location(){console.time("sort_by_original_location")},end_sort_by_original_location(){console.timeEnd("sort_by_original_location")}}})).then(n=>({exports:n.instance.exports,withMappingCallback:(n,t)=>{e.push(n);try{t()}finally{e.pop()}}})).then(null,e=>{throw o=null,e})}},function(e,n,t){const r=t(1).SourceMapGenerator,o=t(0),s=/(\r?\n)/,i=10,l="$$$isSourceNode$$$";class u{constructor(e,n,t,r,o){this.children=[],this.sourceContents={},this.line=null==e?null:e,this.column=null==n?null:n,this.source=null==t?null:t,this.name=null==o?null:o,this[l]=!0,null!=r&&this.add(r)}static fromStringWithSourceMap(e,n,t){const r=new u,i=e.split(s);let l=0;const a=function(){return e()+(e()||"");function e(){return l=0;n--)this.prepend(e[n]);else{if(!e[l]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);this.children.unshift(e)}return this}walk(e){let n;for(let t=0,r=this.children.length;t0){for(n=[],t=0;t= 0 ? this._sections[index] : null; + const nextSection = + index >= 0 && index + 1 < this._sections.length + ? this._sections[index + 1] + : null; + + const generatedPosition = + section && section.consumer.generatedPositionFor(aArgs); + if (generatedPosition && generatedPosition.line !== null) { + const lineShift = section.generatedOffset.generatedLine - 1; + const columnShift = section.generatedOffset.generatedColumn - 1; + + if (generatedPosition.line === 1) { + generatedPosition.column += columnShift; + if (typeof generatedPosition.lastColumn === "number") { + generatedPosition.lastColumn += columnShift; + } } - const generatedPosition = section.consumer.generatedPositionFor(aArgs); - if (generatedPosition) { - const ret = { - line: generatedPosition.line + - (section.generatedOffset.generatedLine - 1), - column: generatedPosition.column + - (section.generatedOffset.generatedLine === generatedPosition.line - ? section.generatedOffset.generatedColumn - 1 - : 0) - }; - return ret; + + if ( + generatedPosition.lastColumn === Infinity && + nextSection && + generatedPosition.line === nextSection.generatedOffset.generatedLine + ) { + generatedPosition.lastColumn = + nextSection.generatedOffset.generatedColumn - 2; } + generatedPosition.line += lineShift; + + return generatedPosition; } return { line: null, - column: null + column: null, + lastColumn: null }; } - /** - * Parse the mappings in a string in to a data structure which we can easily - * query (the ordered arrays in the `this.__generatedMappings` and - * `this.__originalMappings` properties). - */ - _parseMappings(aStr, aSourceRoot) { - const generatedMappings = this.__generatedMappingsUnsorted = []; - const originalMappings = this.__originalMappingsUnsorted = []; - for (let i = 0; i < this._sections.length; i++) { - const section = this._sections[i]; - - const sectionMappings = []; - section.consumer.eachMapping(m => sectionMappings.push(m)); - - for (let j = 0; j < sectionMappings.length; j++) { - const mapping = sectionMappings[j]; - - // TODO: test if null is correct here. The original code used - // `source`, which would actually have gotten used as null because - // var's get hoisted. - // See: https://github.com/mozilla/source-map/issues/333 - let source = util.computeSourceURL(section.consumer.sourceRoot, null, this._sourceMapURL); - this._sources.add(source); - source = this._sources.indexOf(source); - - let name = null; - if (mapping.name) { - this._names.add(mapping.name); - name = this._names.indexOf(mapping.name); + allGeneratedPositionsFor(aArgs) { + const index = this._findSectionIndex(util.getArg(aArgs, "source")); + const section = index >= 0 ? this._sections[index] : null; + const nextSection = + index >= 0 && index + 1 < this._sections.length + ? this._sections[index + 1] + : null; + + if (!section) return []; + + return section.consumer.allGeneratedPositionsFor(aArgs).map( + generatedPosition => { + const lineShift = section.generatedOffset.generatedLine - 1; + const columnShift = section.generatedOffset.generatedColumn - 1; + + if (generatedPosition.line === 1) { + generatedPosition.column += columnShift; + if (typeof generatedPosition.lastColumn === "number") { + generatedPosition.lastColumn += columnShift; + } } - // The mappings coming from the consumer for the section have - // generated positions relative to the start of the section, so we - // need to offset them to be relative to the start of the concatenated - // generated file. - const adjustedMapping = { - source, - generatedLine: mapping.generatedLine + - (section.generatedOffset.generatedLine - 1), - generatedColumn: mapping.generatedColumn + - (section.generatedOffset.generatedLine === mapping.generatedLine - ? section.generatedOffset.generatedColumn - 1 - : 0), - originalLine: mapping.originalLine, - originalColumn: mapping.originalColumn, - name - }; - - generatedMappings.push(adjustedMapping); - if (typeof adjustedMapping.originalLine === "number") { - originalMappings.push(adjustedMapping); + if ( + generatedPosition.lastColumn === Infinity && + nextSection && + generatedPosition.line === nextSection.generatedOffset.generatedLine + ) { + generatedPosition.lastColumn = + nextSection.generatedOffset.generatedColumn - 2; } - } - } - } - - eachMapping(aCallback, aContext, aOrder) { - const context = aContext || null; - const order = aOrder || SourceMapConsumer.GENERATED_ORDER; - - let mappings; - switch (order) { - case SourceMapConsumer.GENERATED_ORDER: - mappings = this._generatedMappings; - break; - case SourceMapConsumer.ORIGINAL_ORDER: - mappings = this._originalMappings; - break; - default: - throw new Error("Unknown order of iteration."); - } + generatedPosition.line += lineShift; - const sourceRoot = this.sourceRoot; - mappings.map(function(mapping) { - let source = null; - if (mapping.source !== null) { - source = this._sources.at(mapping.source); - source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL); + return generatedPosition; } - return { - source, - generatedLine: mapping.generatedLine, - generatedColumn: mapping.generatedColumn, - originalLine: mapping.originalLine, - originalColumn: mapping.originalColumn, - name: mapping.name === null ? null : this._names.at(mapping.name) - }; - }, this).forEach(aCallback, context); - } - - /** - * Find the mapping that best matches the hypothetical "needle" mapping that - * we are searching for in the given "haystack" of mappings. - */ - _findMapping(aNeedle, aMappings, aLineName, - aColumnName, aComparator, aBias) { - // To return the position we are searching for, we must first find the - // mapping for the given position and then return the opposite position it - // points to. Because the mappings are sorted, we can use binary search to - // find the best mapping. - - if (aNeedle[aLineName] <= 0) { - throw new TypeError("Line must be greater than or equal to 1, got " - + aNeedle[aLineName]); - } - if (aNeedle[aColumnName] < 0) { - throw new TypeError("Column must be greater than or equal to 0, got " - + aNeedle[aColumnName]); - } - - return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + ); } - allGeneratedPositionsFor(aArgs) { - const line = util.getArg(aArgs, "line"); - - // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping - // returns the index of the closest mapping less than the needle. By - // setting needle.originalColumn to 0, we thus find the last mapping for - // the given line, provided such a mapping exists. - const needle = { - source: util.getArg(aArgs, "source"), - originalLine: line, - originalColumn: util.getArg(aArgs, "column", 0) - }; - - needle.source = this._findSourceIndex(needle.source); - if (needle.source < 0) { - return []; - } - - if (needle.originalLine < 1) { - throw new Error("Line numbers must be >= 1"); - } - - if (needle.originalColumn < 0) { - throw new Error("Column numbers must be >= 0"); - } - - const mappings = []; - - let index = this._findMapping(needle, - this._originalMappings, - "originalLine", - "originalColumn", - util.compareByOriginalPositions, - binarySearch.LEAST_UPPER_BOUND); - if (index >= 0) { - let mapping = this._originalMappings[index]; - - if (aArgs.column === undefined) { - const originalLine = mapping.originalLine; - - // Iterate until either we run out of mappings, or we run into - // a mapping for a different line than the one we found. Since - // mappings are sorted, this is guaranteed to find all mappings for - // the line we found. - while (mapping && mapping.originalLine === originalLine) { - let lastColumn = mapping.lastGeneratedColumn; - if (this._computedColumnSpans && lastColumn === null) { - lastColumn = Infinity; + eachMapping(aCallback, aContext, aOrder) { + this._sections.forEach((section, index) => { + const nextSection = + index + 1 < this._sections.length + ? this._sections[index + 1] + : null; + const { generatedOffset } = section; + + const lineShift = generatedOffset.generatedLine - 1; + const columnShift = generatedOffset.generatedColumn - 1; + + section.consumer.eachMapping(function(mapping) { + if (mapping.generatedLine === 1) { + mapping.generatedColumn += columnShift; + + if (typeof mapping.lastGeneratedColumn === "number") { + mapping.lastGeneratedColumn += columnShift; } - mappings.push({ - line: util.getArg(mapping, "generatedLine", null), - column: util.getArg(mapping, "generatedColumn", null), - lastColumn, - }); - - mapping = this._originalMappings[++index]; } - } else { - const originalColumn = mapping.originalColumn; - - // Iterate until either we run out of mappings, or we run into - // a mapping for a different line than the one we were searching for. - // Since mappings are sorted, this is guaranteed to find all mappings for - // the line we are searching for. - while (mapping && - mapping.originalLine === line && - mapping.originalColumn == originalColumn) { - let lastColumn = mapping.lastGeneratedColumn; - if (this._computedColumnSpans && lastColumn === null) { - lastColumn = Infinity; - } - mappings.push({ - line: util.getArg(mapping, "generatedLine", null), - column: util.getArg(mapping, "generatedColumn", null), - lastColumn, - }); - mapping = this._originalMappings[++index]; + if ( + mapping.lastGeneratedColumn === Infinity && + nextSection && + mapping.generatedLine === nextSection.generatedOffset.generatedLine + ) { + mapping.lastGeneratedColumn = + nextSection.generatedOffset.generatedColumn - 2; } - } - } + mapping.generatedLine += lineShift; - return mappings; + aCallback.call(this, mapping); + }, aContext, aOrder); + }); + } + + computeColumnSpans() { + for (let i = 0; i < this._sections.length; i++) { + this._sections[i].consumer.computeColumnSpans(); + } } destroy() { diff --git a/lib/util.js b/lib/util.js index 35bd93d6..ae0897cd 100644 --- a/lib/util.js +++ b/lib/util.js @@ -351,83 +351,6 @@ function isProtoString(s) { return true; } -/** - * Comparator between two mappings where the original positions are compared. - * - * Optionally pass in `true` as `onlyCompareGenerated` to consider two - * mappings with the same original source/line/column, but different generated - * line and column the same. Useful when searching for a mapping with a - * stubbed out mapping. - */ -function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { - let cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0 || onlyCompareOriginal) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); -} -exports.compareByOriginalPositions = compareByOriginalPositions; - -/** - * Comparator between two mappings with deflated source and name indices where - * the generated positions are compared. - * - * Optionally pass in `true` as `onlyCompareGenerated` to consider two - * mappings with the same generated line and column, but different - * source/name/original line and column the same. Useful when searching for a - * mapping with a stubbed out mapping. - */ -function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { - let cmp = mappingA.generatedLine - mappingB.generatedLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.generatedColumn - mappingB.generatedColumn; - if (cmp !== 0 || onlyCompareGenerated) { - return cmp; - } - - cmp = strcmp(mappingA.source, mappingB.source); - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalLine - mappingB.originalLine; - if (cmp !== 0) { - return cmp; - } - - cmp = mappingA.originalColumn - mappingB.originalColumn; - if (cmp !== 0) { - return cmp; - } - - return strcmp(mappingA.name, mappingB.name); -} -exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; - function strcmp(aStr1, aStr2) { if (aStr1 === aStr2) { return 0; diff --git a/test/test-source-map-consumer.js b/test/test-source-map-consumer.js index 6d6d47d4..e715d641 100644 --- a/test/test-source-map-consumer.js +++ b/test/test-source-map-consumer.js @@ -304,8 +304,41 @@ exports["test eachMapping"] = async function(assert) { exports["test eachMapping for indexed source maps"] = async function(assert) { const map = await new SourceMapConsumer(util.indexedTestMap); + map.computeColumnSpans(); + let previousLine = -Infinity; + let previousColumn = -Infinity; + let previousLastColumn = -Infinity; + + map.eachMapping(function(mapping) { + assert.ok(mapping.generatedLine >= previousLine); + + if (mapping.source) { + assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0); + } + + if (mapping.generatedLine === previousLine) { + assert.ok(mapping.generatedColumn >= previousColumn); + if (typeof previousLastColumn === "number") { + assert.ok(mapping.generatedColumn > previousLastColumn); + } + previousColumn = mapping.generatedColumn; + previousLastColumn = mapping.lastGeneratedColumn; + } else { + previousLine = mapping.generatedLine; + previousColumn = -Infinity; + previousLastColumn = -Infinity; + } + }); + + map.destroy(); +}; + +exports["test eachMapping for indexed source maps with column offsets"] = async function(assert) { + const map = await new SourceMapConsumer(util.indexedTestMapColumnOffset); + map.computeColumnSpans(); let previousLine = -Infinity; let previousColumn = -Infinity; + let previousLastColumn = -Infinity; map.eachMapping(function(mapping) { assert.ok(mapping.generatedLine >= previousLine); @@ -316,10 +349,15 @@ exports["test eachMapping for indexed source maps"] = async function(assert) { if (mapping.generatedLine === previousLine) { assert.ok(mapping.generatedColumn >= previousColumn); + if (typeof previousLastColumn === "number") { + assert.ok(mapping.generatedColumn > previousLastColumn); + } previousColumn = mapping.generatedColumn; + previousLastColumn = mapping.lastGeneratedColumn; } else { previousLine = mapping.generatedLine; previousColumn = -Infinity; + previousLastColumn = -Infinity; } }); @@ -607,6 +645,53 @@ exports["test sourceRoot + generatedPositionFor for path above the root"] = asyn map.destroy(); }; +exports["test index map + generatedPositionFor"] = async function(assert) { + const map = await new SourceMapConsumer(util.indexedTestMapColumnOffset, "http://example.com/"); + map.computeColumnSpans(); + + let pos = map.generatedPositionFor({ + line: 1, + column: 11, + source: "one.js" + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 9); + assert.equal(pos.lastColumn, 17); + + pos = map.generatedPositionFor({ + line: 2, + column: 3, + source: "one.js" + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 21); + assert.equal(pos.lastColumn, 27); + + pos = map.generatedPositionFor({ + line: 1, + column: 11, + source: "two.js" + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 59); + assert.equal(pos.lastColumn, 67); + + pos = map.generatedPositionFor({ + line: 2, + column: 3, + source: "two.js" + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 71); + assert.equal(pos.lastColumn, 77); + + map.destroy(); +}; + exports["test allGeneratedPositionsFor for line"] = async function(assert) { let map = new SourceMapGenerator({ file: "generated.js" @@ -806,6 +891,69 @@ exports["test allGeneratedPositionsFor for column on different line fuzzy"] = as map.destroy(); }; +exports["test allGeneratedPositionsFor for index map"] = async function(assert) { + const map = await new SourceMapConsumer(util.indexedTestMapColumnOffset); + map.computeColumnSpans(); + + let mappings = map.allGeneratedPositionsFor({ + line: 2, + column: 3, + source: "one.js" + }); + + assert.deepEqual(mappings, [ + { + line: 1, + column: 21, + lastColumn: 27, + } + ]); + + mappings = map.allGeneratedPositionsFor({ + line: 2, + column: 14, + source: "one.js" + }); + + assert.deepEqual(mappings, [ + { + line: 1, + column: 32, + lastColumn: 49 + } + ]); + + mappings = map.allGeneratedPositionsFor({ + line: 2, + column: 3, + source: "two.js" + }); + + assert.deepEqual(mappings, [ + { + line: 1, + column: 71, + lastColumn: 77, + } + ]); + + mappings = map.allGeneratedPositionsFor({ + line: 2, + column: 10, + source: "two.js" + }); + + assert.deepEqual(mappings, [ + { + line: 1, + column: 78, + lastColumn: Infinity, + } + ]); + + map.destroy(); +}; + exports["test computeColumnSpans"] = async function(assert) { let map = new SourceMapGenerator({ file: "generated.js" diff --git a/test/util.js b/test/util.js index f0484320..3f2c25c9 100644 --- a/test/util.js +++ b/test/util.js @@ -210,6 +210,61 @@ exports.indexedTestMapDifferentSourceRoots = { } ] }; +exports.indexedTestMapColumnOffset = { + version: 3, + file: "min.js", + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + " ONE.foo = function (bar) {\n" + + " return baz(bar);\n" + + " };", + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 0, + // Previous section's last generated mapping is [32, Infinity), so + // we're placing this a bit after that. + column: 50 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + " TWO.inc = function (n) {\n" + + " return n + 1;\n" + + " };" + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/the/root" + } + } + ] +}; exports.testMapWithSourcesContent = { version: 3, file: "min.js",