[79a0317] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
| 4 |
|
---|
| 5 | var traceMapping = require('@jridgewell/trace-mapping');
|
---|
| 6 | var genMapping = require('@jridgewell/gen-mapping');
|
---|
| 7 |
|
---|
| 8 | class SourceMapConsumer {
|
---|
| 9 | constructor(map, mapUrl) {
|
---|
| 10 | const trace = (this._map = new traceMapping.AnyMap(map, mapUrl));
|
---|
| 11 | this.file = trace.file;
|
---|
| 12 | this.names = trace.names;
|
---|
| 13 | this.sourceRoot = trace.sourceRoot;
|
---|
| 14 | this.sources = trace.resolvedSources;
|
---|
| 15 | this.sourcesContent = trace.sourcesContent;
|
---|
| 16 | this.version = trace.version;
|
---|
| 17 | }
|
---|
| 18 | static fromSourceMap(map, mapUrl) {
|
---|
| 19 | // This is more performant if we receive
|
---|
| 20 | // a @jridgewell/source-map SourceMapGenerator
|
---|
| 21 | if (map.toDecodedMap) {
|
---|
| 22 | return new SourceMapConsumer(map.toDecodedMap(), mapUrl);
|
---|
| 23 | }
|
---|
| 24 | // This is a fallback for `source-map` and `source-map-js`
|
---|
| 25 | return new SourceMapConsumer(map.toJSON(), mapUrl);
|
---|
| 26 | }
|
---|
| 27 | get mappings() {
|
---|
| 28 | return traceMapping.encodedMappings(this._map);
|
---|
| 29 | }
|
---|
| 30 | originalPositionFor(needle) {
|
---|
| 31 | return traceMapping.originalPositionFor(this._map, needle);
|
---|
| 32 | }
|
---|
| 33 | generatedPositionFor(originalPosition) {
|
---|
| 34 | return traceMapping.generatedPositionFor(this._map, originalPosition);
|
---|
| 35 | }
|
---|
| 36 | allGeneratedPositionsFor(originalPosition) {
|
---|
| 37 | return traceMapping.allGeneratedPositionsFor(this._map, originalPosition);
|
---|
| 38 | }
|
---|
| 39 | hasContentsOfAllSources() {
|
---|
| 40 | if (!this.sourcesContent || this.sourcesContent.length !== this.sources.length) {
|
---|
| 41 | return false;
|
---|
| 42 | }
|
---|
| 43 | for (const content of this.sourcesContent) {
|
---|
| 44 | if (content == null) {
|
---|
| 45 | return false;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | return true;
|
---|
| 49 | }
|
---|
| 50 | sourceContentFor(source, nullOnMissing) {
|
---|
| 51 | const sourceContent = traceMapping.sourceContentFor(this._map, source);
|
---|
| 52 | if (sourceContent != null) {
|
---|
| 53 | return sourceContent;
|
---|
| 54 | }
|
---|
| 55 | if (nullOnMissing) {
|
---|
| 56 | return null;
|
---|
| 57 | }
|
---|
| 58 | throw new Error(`"${source}" is not in the SourceMap.`);
|
---|
| 59 | }
|
---|
| 60 | eachMapping(callback, context /*, order?: number*/) {
|
---|
| 61 | // order is ignored as @jridgewell/trace-map doesn't implement it
|
---|
| 62 | traceMapping.eachMapping(this._map, context ? callback.bind(context) : callback);
|
---|
| 63 | }
|
---|
| 64 | destroy() {
|
---|
| 65 | // noop.
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | class SourceMapGenerator {
|
---|
| 69 | constructor(opts) {
|
---|
| 70 | // TODO :: should this be duck-typed ?
|
---|
| 71 | this._map = opts instanceof genMapping.GenMapping ? opts : new genMapping.GenMapping(opts);
|
---|
| 72 | }
|
---|
| 73 | static fromSourceMap(consumer) {
|
---|
| 74 | return new SourceMapGenerator(genMapping.fromMap(consumer));
|
---|
| 75 | }
|
---|
| 76 | addMapping(mapping) {
|
---|
| 77 | genMapping.maybeAddMapping(this._map, mapping);
|
---|
| 78 | }
|
---|
| 79 | setSourceContent(source, content) {
|
---|
| 80 | genMapping.setSourceContent(this._map, source, content);
|
---|
| 81 | }
|
---|
| 82 | toJSON() {
|
---|
| 83 | return genMapping.toEncodedMap(this._map);
|
---|
| 84 | }
|
---|
| 85 | toString() {
|
---|
| 86 | return JSON.stringify(this.toJSON());
|
---|
| 87 | }
|
---|
| 88 | toDecodedMap() {
|
---|
| 89 | return genMapping.toDecodedMap(this._map);
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | exports.SourceMapConsumer = SourceMapConsumer;
|
---|
| 94 | exports.SourceMapGenerator = SourceMapGenerator;
|
---|
| 95 | //# sourceMappingURL=source-map.cjs.map
|
---|