MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / generateDecodedMap

Method generateDecodedMap

benchmark/data.js:894–955  ·  view source on GitHub ↗
(options = {})

Source from the content-addressed store, hash-verified

892 return bundle;
893 }
894 generateDecodedMap(options = {}) {
895 const names = [];
896 this.sources.forEach((source) => {
897 Object.keys(source.content.storedNames).forEach((name) => {
898 if (!~names.indexOf(name)) names.push(name);
899 });
900 });
901 const mappings = new Mappings(options.hires);
902 if (this.intro) {
903 mappings.advance(this.intro);
904 }
905 this.sources.forEach((source, i) => {
906 if (i > 0) {
907 mappings.advance(this.separator);
908 }
909 const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
910 const magicString = source.content;
911 const locate = getLocator(magicString.original);
912 if (magicString.intro) {
913 mappings.advance(magicString.intro);
914 }
915 magicString.firstChunk.eachNext((chunk) => {
916 const loc = locate(chunk.start);
917 if (chunk.intro.length) mappings.advance(chunk.intro);
918 if (source.filename) {
919 if (chunk.edited) {
920 mappings.addEdit(
921 sourceIndex,
922 chunk.content,
923 loc,
924 chunk.storeName ? names.indexOf(chunk.original) : -1,
925 );
926 } else {
927 mappings.addUneditedChunk(
928 sourceIndex,
929 chunk,
930 magicString.original,
931 loc,
932 magicString.sourcemapLocations,
933 );
934 }
935 } else {
936 mappings.advance(chunk.content);
937 }
938 if (chunk.outro.length) mappings.advance(chunk.outro);
939 });
940 if (magicString.outro) {
941 mappings.advance(magicString.outro);
942 }
943 });
944 return {
945 file: options.file ? options.file.split(/[/\\]/).pop() : null,
946 sources: this.uniqueSources.map((source) => {
947 return options.file ? getRelativePath(options.file, source.filename) : source.filename;
948 }),
949 sourcesContent: this.uniqueSources.map((source) => {
950 return options.includeContent ? source.content : null;
951 }),

Callers 1

generateMapMethod · 0.95

Calls 7

advanceMethod · 0.95
addEditMethod · 0.95
addUneditedChunkMethod · 0.95
getLocatorFunction · 0.70
getRelativePathFunction · 0.70
eachNextMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected