source: imaps-frontend/node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const createMappingsSerializer = require("./createMappingsSerializer");
9
10exports.getSourceAndMap = (inputSource, options) => {
11 let code = "";
12 let mappings = "";
13 let sources = [];
14 let sourcesContent = [];
15 let names = [];
16 const addMapping = createMappingsSerializer(options);
17 const { source } = inputSource.streamChunks(
18 Object.assign({}, options, { finalSource: true }),
19 (
20 chunk,
21 generatedLine,
22 generatedColumn,
23 sourceIndex,
24 originalLine,
25 originalColumn,
26 nameIndex
27 ) => {
28 if (chunk !== undefined) code += chunk;
29 mappings += addMapping(
30 generatedLine,
31 generatedColumn,
32 sourceIndex,
33 originalLine,
34 originalColumn,
35 nameIndex
36 );
37 },
38 (sourceIndex, source, sourceContent) => {
39 while (sources.length < sourceIndex) {
40 sources.push(null);
41 }
42 sources[sourceIndex] = source;
43 if (sourceContent !== undefined) {
44 while (sourcesContent.length < sourceIndex) {
45 sourcesContent.push(null);
46 }
47 sourcesContent[sourceIndex] = sourceContent;
48 }
49 },
50 (nameIndex, name) => {
51 while (names.length < nameIndex) {
52 names.push(null);
53 }
54 names[nameIndex] = name;
55 }
56 );
57 return {
58 source: source !== undefined ? source : code,
59 map:
60 mappings.length > 0
61 ? {
62 version: 3,
63 file: "x",
64 mappings,
65 sources,
66 sourcesContent:
67 sourcesContent.length > 0 ? sourcesContent : undefined,
68 names
69 }
70 : null
71 };
72};
73
74exports.getMap = (source, options) => {
75 let mappings = "";
76 let sources = [];
77 let sourcesContent = [];
78 let names = [];
79 const addMapping = createMappingsSerializer(options);
80 source.streamChunks(
81 Object.assign({}, options, { source: false, finalSource: true }),
82 (
83 chunk,
84 generatedLine,
85 generatedColumn,
86 sourceIndex,
87 originalLine,
88 originalColumn,
89 nameIndex
90 ) => {
91 mappings += addMapping(
92 generatedLine,
93 generatedColumn,
94 sourceIndex,
95 originalLine,
96 originalColumn,
97 nameIndex
98 );
99 },
100 (sourceIndex, source, sourceContent) => {
101 while (sources.length < sourceIndex) {
102 sources.push(null);
103 }
104 sources[sourceIndex] = source;
105 if (sourceContent !== undefined) {
106 while (sourcesContent.length < sourceIndex) {
107 sourcesContent.push(null);
108 }
109 sourcesContent[sourceIndex] = sourceContent;
110 }
111 },
112 (nameIndex, name) => {
113 while (names.length < nameIndex) {
114 names.push(null);
115 }
116 names[nameIndex] = name;
117 }
118 );
119 return mappings.length > 0
120 ? {
121 version: 3,
122 file: "x",
123 mappings,
124 sources,
125 sourcesContent: sourcesContent.length > 0 ? sourcesContent : undefined,
126 names
127 }
128 : null;
129};
Note: See TracBrowser for help on using the repository browser.