summaryrefslogtreecommitdiff
path: root/node_modules/webpack-sources/lib/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webpack-sources/lib/helpers')
-rw-r--r--node_modules/webpack-sources/lib/helpers/createMappingsSerializer.js206
-rw-r--r--node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js129
-rw-r--r--node_modules/webpack-sources/lib/helpers/getGeneratedSourceInfo.js33
-rw-r--r--node_modules/webpack-sources/lib/helpers/getName.js14
-rw-r--r--node_modules/webpack-sources/lib/helpers/getSource.js17
-rw-r--r--node_modules/webpack-sources/lib/helpers/readMappings.js116
-rw-r--r--node_modules/webpack-sources/lib/helpers/splitIntoLines.js21
-rw-r--r--node_modules/webpack-sources/lib/helpers/splitIntoPotentialTokens.js41
-rw-r--r--node_modules/webpack-sources/lib/helpers/streamAndGetSourceAndMap.js102
-rw-r--r--node_modules/webpack-sources/lib/helpers/streamChunks.js36
-rw-r--r--node_modules/webpack-sources/lib/helpers/streamChunksOfCombinedSourceMap.js329
-rw-r--r--node_modules/webpack-sources/lib/helpers/streamChunksOfRawSource.js34
-rw-r--r--node_modules/webpack-sources/lib/helpers/streamChunksOfSourceMap.js412
13 files changed, 1490 insertions, 0 deletions
diff --git a/node_modules/webpack-sources/lib/helpers/createMappingsSerializer.js b/node_modules/webpack-sources/lib/helpers/createMappingsSerializer.js
new file mode 100644
index 00000000..8dafe438
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/createMappingsSerializer.js
@@ -0,0 +1,206 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(
+ ""
+);
+
+const CONTINUATION_BIT = 0x20;
+
+const createMappingsSerializer = options => {
+ const linesOnly = options && options.columns === false;
+ return linesOnly
+ ? createLinesOnlyMappingsSerializer()
+ : createFullMappingsSerializer();
+};
+
+const createFullMappingsSerializer = () => {
+ let currentLine = 1;
+ let currentColumn = 0;
+ let currentSourceIndex = 0;
+ let currentOriginalLine = 1;
+ let currentOriginalColumn = 0;
+ let currentNameIndex = 0;
+ let activeMapping = false;
+ let activeName = false;
+ let initial = true;
+ return (
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ if (activeMapping && currentLine === generatedLine) {
+ // A mapping is still active
+ if (
+ sourceIndex === currentSourceIndex &&
+ originalLine === currentOriginalLine &&
+ originalColumn === currentOriginalColumn &&
+ !activeName &&
+ nameIndex < 0
+ ) {
+ // avoid repeating the same original mapping
+ return "";
+ }
+ } else {
+ // No mapping is active
+ if (sourceIndex < 0) {
+ // avoid writing unneccessary generated mappings
+ return "";
+ }
+ }
+
+ let str;
+ if (currentLine < generatedLine) {
+ str = ";".repeat(generatedLine - currentLine);
+ currentLine = generatedLine;
+ currentColumn = 0;
+ initial = false;
+ } else if (initial) {
+ str = "";
+ initial = false;
+ } else {
+ str = ",";
+ }
+
+ const writeValue = value => {
+ const sign = (value >>> 31) & 1;
+ const mask = value >> 31;
+ const absValue = (value + mask) ^ mask;
+ let data = (absValue << 1) | sign;
+ for (;;) {
+ const sextet = data & 0x1f;
+ data >>= 5;
+ if (data === 0) {
+ str += ALPHABET[sextet];
+ break;
+ } else {
+ str += ALPHABET[sextet | CONTINUATION_BIT];
+ }
+ }
+ };
+ writeValue(generatedColumn - currentColumn);
+ currentColumn = generatedColumn;
+ if (sourceIndex >= 0) {
+ activeMapping = true;
+ if (sourceIndex === currentSourceIndex) {
+ str += "A";
+ } else {
+ writeValue(sourceIndex - currentSourceIndex);
+ currentSourceIndex = sourceIndex;
+ }
+ writeValue(originalLine - currentOriginalLine);
+ currentOriginalLine = originalLine;
+ if (originalColumn === currentOriginalColumn) {
+ str += "A";
+ } else {
+ writeValue(originalColumn - currentOriginalColumn);
+ currentOriginalColumn = originalColumn;
+ }
+ if (nameIndex >= 0) {
+ writeValue(nameIndex - currentNameIndex);
+ currentNameIndex = nameIndex;
+ activeName = true;
+ } else {
+ activeName = false;
+ }
+ } else {
+ activeMapping = false;
+ }
+ return str;
+ };
+};
+
+const createLinesOnlyMappingsSerializer = () => {
+ let lastWrittenLine = 0;
+ let currentLine = 1;
+ let currentSourceIndex = 0;
+ let currentOriginalLine = 1;
+ return (
+ generatedLine,
+ _generatedColumn,
+ sourceIndex,
+ originalLine,
+ _originalColumn,
+ _nameIndex
+ ) => {
+ if (sourceIndex < 0) {
+ // avoid writing generated mappings at all
+ return "";
+ }
+ if (lastWrittenLine === generatedLine) {
+ // avoid writing multiple original mappings per line
+ return "";
+ }
+ let str;
+ const writeValue = value => {
+ const sign = (value >>> 31) & 1;
+ const mask = value >> 31;
+ const absValue = (value + mask) ^ mask;
+ let data = (absValue << 1) | sign;
+ for (;;) {
+ const sextet = data & 0x1f;
+ data >>= 5;
+ if (data === 0) {
+ str += ALPHABET[sextet];
+ break;
+ } else {
+ str += ALPHABET[sextet | CONTINUATION_BIT];
+ }
+ }
+ };
+ lastWrittenLine = generatedLine;
+ if (generatedLine === currentLine + 1) {
+ currentLine = generatedLine;
+ if (sourceIndex === currentSourceIndex) {
+ currentSourceIndex = sourceIndex;
+ if (originalLine === currentOriginalLine + 1) {
+ currentOriginalLine = originalLine;
+ return ";AACA";
+ } else {
+ str = ";AA";
+ writeValue(originalLine - currentOriginalLine);
+ currentOriginalLine = originalLine;
+ return str + "A";
+ }
+ } else {
+ str = ";A";
+ writeValue(sourceIndex - currentSourceIndex);
+ currentSourceIndex = sourceIndex;
+ writeValue(originalLine - currentOriginalLine);
+ currentOriginalLine = originalLine;
+ return str + "A";
+ }
+ } else {
+ str = ";".repeat(generatedLine - currentLine);
+ currentLine = generatedLine;
+ if (sourceIndex === currentSourceIndex) {
+ currentSourceIndex = sourceIndex;
+ if (originalLine === currentOriginalLine + 1) {
+ currentOriginalLine = originalLine;
+ return str + "AACA";
+ } else {
+ str += "AA";
+ writeValue(originalLine - currentOriginalLine);
+ currentOriginalLine = originalLine;
+ return str + "A";
+ }
+ } else {
+ str += "A";
+ writeValue(sourceIndex - currentSourceIndex);
+ currentSourceIndex = sourceIndex;
+ writeValue(originalLine - currentOriginalLine);
+ currentOriginalLine = originalLine;
+ return str + "A";
+ }
+ }
+ };
+};
+
+module.exports = createMappingsSerializer;
diff --git a/node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js b/node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js
new file mode 100644
index 00000000..f45c639c
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js
@@ -0,0 +1,129 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const createMappingsSerializer = require("./createMappingsSerializer");
+
+exports.getSourceAndMap = (inputSource, options) => {
+ let code = "";
+ let mappings = "";
+ let sources = [];
+ let sourcesContent = [];
+ let names = [];
+ const addMapping = createMappingsSerializer(options);
+ const { source } = inputSource.streamChunks(
+ Object.assign({}, options, { finalSource: true }),
+ (
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ if (chunk !== undefined) code += chunk;
+ mappings += addMapping(
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ },
+ (sourceIndex, source, sourceContent) => {
+ while (sources.length < sourceIndex) {
+ sources.push(null);
+ }
+ sources[sourceIndex] = source;
+ if (sourceContent !== undefined) {
+ while (sourcesContent.length < sourceIndex) {
+ sourcesContent.push(null);
+ }
+ sourcesContent[sourceIndex] = sourceContent;
+ }
+ },
+ (nameIndex, name) => {
+ while (names.length < nameIndex) {
+ names.push(null);
+ }
+ names[nameIndex] = name;
+ }
+ );
+ return {
+ source: source !== undefined ? source : code,
+ map:
+ mappings.length > 0
+ ? {
+ version: 3,
+ file: "x",
+ mappings,
+ sources,
+ sourcesContent:
+ sourcesContent.length > 0 ? sourcesContent : undefined,
+ names
+ }
+ : null
+ };
+};
+
+exports.getMap = (source, options) => {
+ let mappings = "";
+ let sources = [];
+ let sourcesContent = [];
+ let names = [];
+ const addMapping = createMappingsSerializer(options);
+ source.streamChunks(
+ Object.assign({}, options, { source: false, finalSource: true }),
+ (
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ mappings += addMapping(
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ },
+ (sourceIndex, source, sourceContent) => {
+ while (sources.length < sourceIndex) {
+ sources.push(null);
+ }
+ sources[sourceIndex] = source;
+ if (sourceContent !== undefined) {
+ while (sourcesContent.length < sourceIndex) {
+ sourcesContent.push(null);
+ }
+ sourcesContent[sourceIndex] = sourceContent;
+ }
+ },
+ (nameIndex, name) => {
+ while (names.length < nameIndex) {
+ names.push(null);
+ }
+ names[nameIndex] = name;
+ }
+ );
+ return mappings.length > 0
+ ? {
+ version: 3,
+ file: "x",
+ mappings,
+ sources,
+ sourcesContent: sourcesContent.length > 0 ? sourcesContent : undefined,
+ names
+ }
+ : null;
+};
diff --git a/node_modules/webpack-sources/lib/helpers/getGeneratedSourceInfo.js b/node_modules/webpack-sources/lib/helpers/getGeneratedSourceInfo.js
new file mode 100644
index 00000000..2cc12fcd
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/getGeneratedSourceInfo.js
@@ -0,0 +1,33 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const CHAR_CODE_NEW_LINE = "\n".charCodeAt(0);
+
+const getGeneratedSourceInfo = source => {
+ if (source === undefined) {
+ return {};
+ }
+ const lastLineStart = source.lastIndexOf("\n");
+ if (lastLineStart === -1) {
+ return {
+ generatedLine: 1,
+ generatedColumn: source.length,
+ source
+ };
+ }
+ let generatedLine = 2;
+ for (let i = 0; i < lastLineStart; i++) {
+ if (source.charCodeAt(i) === CHAR_CODE_NEW_LINE) generatedLine++;
+ }
+ return {
+ generatedLine,
+ generatedColumn: source.length - lastLineStart - 1,
+ source
+ };
+};
+
+module.exports = getGeneratedSourceInfo;
diff --git a/node_modules/webpack-sources/lib/helpers/getName.js b/node_modules/webpack-sources/lib/helpers/getName.js
new file mode 100644
index 00000000..db6a863a
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/getName.js
@@ -0,0 +1,14 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const getName = (sourceMap, index) => {
+ if (index < 0) return null;
+ const { names } = sourceMap;
+ return names[index];
+};
+
+module.exports = getName;
diff --git a/node_modules/webpack-sources/lib/helpers/getSource.js b/node_modules/webpack-sources/lib/helpers/getSource.js
new file mode 100644
index 00000000..b236563d
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/getSource.js
@@ -0,0 +1,17 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const getSource = (sourceMap, index) => {
+ if (index < 0) return null;
+ const { sourceRoot, sources } = sourceMap;
+ const source = sources[index];
+ if (!sourceRoot) return source;
+ if (sourceRoot.endsWith("/")) return sourceRoot + source;
+ return sourceRoot + "/" + source;
+};
+
+module.exports = getSource;
diff --git a/node_modules/webpack-sources/lib/helpers/readMappings.js b/node_modules/webpack-sources/lib/helpers/readMappings.js
new file mode 100644
index 00000000..31cb48d2
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/readMappings.js
@@ -0,0 +1,116 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const ALPHABET =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+const CONTINUATION_BIT = 0x20;
+const END_SEGMENT_BIT = 0x40;
+const NEXT_LINE = END_SEGMENT_BIT | 0x01;
+const INVALID = END_SEGMENT_BIT | 0x02;
+const DATA_MASK = 0x1f;
+
+const ccToValue = new Uint8Array("z".charCodeAt(0) + 1);
+{
+ ccToValue.fill(INVALID);
+ for (let i = 0; i < ALPHABET.length; i++) {
+ ccToValue[ALPHABET.charCodeAt(i)] = i;
+ }
+ ccToValue[",".charCodeAt(0)] = END_SEGMENT_BIT;
+ ccToValue[";".charCodeAt(0)] = NEXT_LINE;
+}
+const ccMax = ccToValue.length - 1;
+
+/**
+ * @param {string} mappings the mappings string
+ * @param {function(number, number, number, number, number, number): void} onMapping called for each mapping
+ * @returns {void}
+ */
+const readMappings = (mappings, onMapping) => {
+ // generatedColumn, [sourceIndex, originalLine, orignalColumn, [nameIndex]]
+ const currentData = new Uint32Array([0, 0, 1, 0, 0]);
+ let currentDataPos = 0;
+ // currentValue will include a sign bit at bit 0
+ let currentValue = 0;
+ let currentValuePos = 0;
+ let generatedLine = 1;
+ let generatedColumn = -1;
+ for (let i = 0; i < mappings.length; i++) {
+ const cc = mappings.charCodeAt(i);
+ if (cc > ccMax) continue;
+ const value = ccToValue[cc];
+ if ((value & END_SEGMENT_BIT) !== 0) {
+ // End current segment
+ if (currentData[0] > generatedColumn) {
+ if (currentDataPos === 1) {
+ onMapping(generatedLine, currentData[0], -1, -1, -1, -1);
+ } else if (currentDataPos === 4) {
+ onMapping(
+ generatedLine,
+ currentData[0],
+ currentData[1],
+ currentData[2],
+ currentData[3],
+ -1
+ );
+ } else if (currentDataPos === 5) {
+ onMapping(
+ generatedLine,
+ currentData[0],
+ currentData[1],
+ currentData[2],
+ currentData[3],
+ currentData[4]
+ );
+ }
+ generatedColumn = currentData[0];
+ }
+ currentDataPos = 0;
+ if (value === NEXT_LINE) {
+ // Start new line
+ generatedLine++;
+ currentData[0] = 0;
+ generatedColumn = -1;
+ }
+ } else if ((value & CONTINUATION_BIT) === 0) {
+ // last sextet
+ currentValue |= value << currentValuePos;
+ const finalValue =
+ currentValue & 1 ? -(currentValue >> 1) : currentValue >> 1;
+ currentData[currentDataPos++] += finalValue;
+ currentValuePos = 0;
+ currentValue = 0;
+ } else {
+ currentValue |= (value & DATA_MASK) << currentValuePos;
+ currentValuePos += 5;
+ }
+ }
+ // End current segment
+ if (currentDataPos === 1) {
+ onMapping(generatedLine, currentData[0], -1, -1, -1, -1);
+ } else if (currentDataPos === 4) {
+ onMapping(
+ generatedLine,
+ currentData[0],
+ currentData[1],
+ currentData[2],
+ currentData[3],
+ -1
+ );
+ } else if (currentDataPos === 5) {
+ onMapping(
+ generatedLine,
+ currentData[0],
+ currentData[1],
+ currentData[2],
+ currentData[3],
+ currentData[4]
+ );
+ }
+};
+
+module.exports = readMappings;
diff --git a/node_modules/webpack-sources/lib/helpers/splitIntoLines.js b/node_modules/webpack-sources/lib/helpers/splitIntoLines.js
new file mode 100644
index 00000000..e9ccafdf
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/splitIntoLines.js
@@ -0,0 +1,21 @@
+const splitIntoLines = str => {
+ const results = [];
+ const len = str.length;
+ let i = 0;
+ for (; i < len; ) {
+ const cc = str.charCodeAt(i);
+ // 10 is "\n".charCodeAt(0)
+ if (cc === 10) {
+ results.push("\n");
+ i++;
+ } else {
+ let j = i + 1;
+ // 10 is "\n".charCodeAt(0)
+ while (j < len && str.charCodeAt(j) !== 10) j++;
+ results.push(str.slice(i, j + 1));
+ i = j + 1;
+ }
+ }
+ return results;
+};
+module.exports = splitIntoLines;
diff --git a/node_modules/webpack-sources/lib/helpers/splitIntoPotentialTokens.js b/node_modules/webpack-sources/lib/helpers/splitIntoPotentialTokens.js
new file mode 100644
index 00000000..0f0bc421
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/splitIntoPotentialTokens.js
@@ -0,0 +1,41 @@
+// \n = 10
+// ; = 59
+// { = 123
+// } = 125
+// <space> = 32
+// \r = 13
+// \t = 9
+
+const splitIntoPotentialTokens = str => {
+ const len = str.length;
+ if (len === 0) return null;
+ const results = [];
+ let i = 0;
+ for (; i < len; ) {
+ const s = i;
+ block: {
+ let cc = str.charCodeAt(i);
+ while (cc !== 10 && cc !== 59 && cc !== 123 && cc !== 125) {
+ if (++i >= len) break block;
+ cc = str.charCodeAt(i);
+ }
+ while (
+ cc === 59 ||
+ cc === 32 ||
+ cc === 123 ||
+ cc === 125 ||
+ cc === 13 ||
+ cc === 9
+ ) {
+ if (++i >= len) break block;
+ cc = str.charCodeAt(i);
+ }
+ if (cc === 10) {
+ i++;
+ }
+ }
+ results.push(str.slice(s, i));
+ }
+ return results;
+};
+module.exports = splitIntoPotentialTokens;
diff --git a/node_modules/webpack-sources/lib/helpers/streamAndGetSourceAndMap.js b/node_modules/webpack-sources/lib/helpers/streamAndGetSourceAndMap.js
new file mode 100644
index 00000000..529fd766
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/streamAndGetSourceAndMap.js
@@ -0,0 +1,102 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const createMappingsSerializer = require("./createMappingsSerializer");
+const streamChunks = require("./streamChunks");
+
+const streamAndGetSourceAndMap = (
+ inputSource,
+ options,
+ onChunk,
+ onSource,
+ onName
+) => {
+ let code = "";
+ let mappings = "";
+ let sources = [];
+ let sourcesContent = [];
+ let names = [];
+ const addMapping = createMappingsSerializer(
+ Object.assign({}, options, { columns: true })
+ );
+ const finalSource = !!(options && options.finalSource);
+ const { generatedLine, generatedColumn, source } = streamChunks(
+ inputSource,
+ options,
+ (
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ if (chunk !== undefined) code += chunk;
+ mappings += addMapping(
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ return onChunk(
+ finalSource ? undefined : chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ },
+ (sourceIndex, source, sourceContent) => {
+ while (sources.length < sourceIndex) {
+ sources.push(null);
+ }
+ sources[sourceIndex] = source;
+ if (sourceContent !== undefined) {
+ while (sourcesContent.length < sourceIndex) {
+ sourcesContent.push(null);
+ }
+ sourcesContent[sourceIndex] = sourceContent;
+ }
+ return onSource(sourceIndex, source, sourceContent);
+ },
+ (nameIndex, name) => {
+ while (names.length < nameIndex) {
+ names.push(null);
+ }
+ names[nameIndex] = name;
+ return onName(nameIndex, name);
+ }
+ );
+ const resultSource = source !== undefined ? source : code;
+ return {
+ result: {
+ generatedLine,
+ generatedColumn,
+ source: finalSource ? resultSource : undefined
+ },
+ source: resultSource,
+ map:
+ mappings.length > 0
+ ? {
+ version: 3,
+ file: "x",
+ mappings,
+ sources,
+ sourcesContent:
+ sourcesContent.length > 0 ? sourcesContent : undefined,
+ names
+ }
+ : null
+ };
+};
+
+module.exports = streamAndGetSourceAndMap;
diff --git a/node_modules/webpack-sources/lib/helpers/streamChunks.js b/node_modules/webpack-sources/lib/helpers/streamChunks.js
new file mode 100644
index 00000000..4bd3824a
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/streamChunks.js
@@ -0,0 +1,36 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const streamChunksOfRawSource = require("./streamChunksOfRawSource");
+const streamChunksOfSourceMap = require("./streamChunksOfSourceMap");
+
+module.exports = (source, options, onChunk, onSource, onName) => {
+ if (typeof source.streamChunks === "function") {
+ return source.streamChunks(options, onChunk, onSource, onName);
+ } else {
+ const sourceAndMap = source.sourceAndMap(options);
+ if (sourceAndMap.map) {
+ return streamChunksOfSourceMap(
+ sourceAndMap.source,
+ sourceAndMap.map,
+ onChunk,
+ onSource,
+ onName,
+ !!(options && options.finalSource),
+ !!(options && options.columns !== false)
+ );
+ } else {
+ return streamChunksOfRawSource(
+ sourceAndMap.source,
+ onChunk,
+ onSource,
+ onName,
+ !!(options && options.finalSource)
+ );
+ }
+ }
+};
diff --git a/node_modules/webpack-sources/lib/helpers/streamChunksOfCombinedSourceMap.js b/node_modules/webpack-sources/lib/helpers/streamChunksOfCombinedSourceMap.js
new file mode 100644
index 00000000..b40774d5
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/streamChunksOfCombinedSourceMap.js
@@ -0,0 +1,329 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const streamChunksOfSourceMap = require("./streamChunksOfSourceMap");
+const splitIntoLines = require("./splitIntoLines");
+
+const streamChunksOfCombinedSourceMap = (
+ source,
+ sourceMap,
+ innerSourceName,
+ innerSource,
+ innerSourceMap,
+ removeInnerSource,
+ onChunk,
+ onSource,
+ onName,
+ finalSource,
+ columns
+) => {
+ let sourceMapping = new Map();
+ let nameMapping = new Map();
+ const sourceIndexMapping = [];
+ const nameIndexMapping = [];
+ const nameIndexValueMapping = [];
+ let innerSourceIndex = -2;
+ const innerSourceIndexMapping = [];
+ const innerSourceIndexValueMapping = [];
+ const innerSourceContents = [];
+ const innerSourceContentLines = [];
+ const innerNameIndexMapping = [];
+ const innerNameIndexValueMapping = [];
+ const innerSourceMapLineData = [];
+ const findInnerMapping = (line, column) => {
+ if (line > innerSourceMapLineData.length) return -1;
+ const { mappingsData } = innerSourceMapLineData[line - 1];
+ let l = 0;
+ let r = mappingsData.length / 5;
+ while (l < r) {
+ let m = (l + r) >> 1;
+ if (mappingsData[m * 5] <= column) {
+ l = m + 1;
+ } else {
+ r = m;
+ }
+ }
+ if (l === 0) return -1;
+ return l - 1;
+ };
+ return streamChunksOfSourceMap(
+ source,
+ sourceMap,
+ (
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ // Check if this is a mapping to the inner source
+ if (sourceIndex === innerSourceIndex) {
+ // Check if there is a mapping in the inner source
+ const idx = findInnerMapping(originalLine, originalColumn);
+ if (idx !== -1) {
+ const { chunks, mappingsData } = innerSourceMapLineData[
+ originalLine - 1
+ ];
+ const mi = idx * 5;
+ const innerSourceIndex = mappingsData[mi + 1];
+ const innerOriginalLine = mappingsData[mi + 2];
+ let innerOriginalColumn = mappingsData[mi + 3];
+ let innerNameIndex = mappingsData[mi + 4];
+ if (innerSourceIndex >= 0) {
+ // Check for an identity mapping
+ // where we are allowed to adjust the original column
+ const innerChunk = chunks[idx];
+ const innerGeneratedColumn = mappingsData[mi];
+ const locationInChunk = originalColumn - innerGeneratedColumn;
+ if (locationInChunk > 0) {
+ let originalSourceLines =
+ innerSourceIndex < innerSourceContentLines.length
+ ? innerSourceContentLines[innerSourceIndex]
+ : null;
+ if (originalSourceLines === undefined) {
+ const originalSource = innerSourceContents[innerSourceIndex];
+ originalSourceLines = originalSource
+ ? splitIntoLines(originalSource)
+ : null;
+ innerSourceContentLines[innerSourceIndex] = originalSourceLines;
+ }
+ if (originalSourceLines !== null) {
+ const originalChunk =
+ innerOriginalLine <= originalSourceLines.length
+ ? originalSourceLines[innerOriginalLine - 1].slice(
+ innerOriginalColumn,
+ innerOriginalColumn + locationInChunk
+ )
+ : "";
+ if (innerChunk.slice(0, locationInChunk) === originalChunk) {
+ innerOriginalColumn += locationInChunk;
+ innerNameIndex = -1;
+ }
+ }
+ }
+
+ // We have a inner mapping to original source
+
+ // emit source when needed and compute global source index
+ let sourceIndex =
+ innerSourceIndex < innerSourceIndexMapping.length
+ ? innerSourceIndexMapping[innerSourceIndex]
+ : -2;
+ if (sourceIndex === -2) {
+ const [source, sourceContent] =
+ innerSourceIndex < innerSourceIndexValueMapping.length
+ ? innerSourceIndexValueMapping[innerSourceIndex]
+ : [null, undefined];
+ let globalIndex = sourceMapping.get(source);
+ if (globalIndex === undefined) {
+ sourceMapping.set(source, (globalIndex = sourceMapping.size));
+ onSource(globalIndex, source, sourceContent);
+ }
+ sourceIndex = globalIndex;
+ innerSourceIndexMapping[innerSourceIndex] = sourceIndex;
+ }
+
+ // emit name when needed and compute global name index
+ let finalNameIndex = -1;
+ if (innerNameIndex >= 0) {
+ // when we have a inner name
+ finalNameIndex =
+ innerNameIndex < innerNameIndexMapping.length
+ ? innerNameIndexMapping[innerNameIndex]
+ : -2;
+ if (finalNameIndex === -2) {
+ const name =
+ innerNameIndex < innerNameIndexValueMapping.length
+ ? innerNameIndexValueMapping[innerNameIndex]
+ : undefined;
+ if (name) {
+ let globalIndex = nameMapping.get(name);
+ if (globalIndex === undefined) {
+ nameMapping.set(name, (globalIndex = nameMapping.size));
+ onName(globalIndex, name);
+ }
+ finalNameIndex = globalIndex;
+ } else {
+ finalNameIndex = -1;
+ }
+ innerNameIndexMapping[innerNameIndex] = finalNameIndex;
+ }
+ } else if (nameIndex >= 0) {
+ // when we don't have an inner name,
+ // but we have an outer name
+ // it can be used when inner original code equals to the name
+ let originalSourceLines =
+ innerSourceContentLines[innerSourceIndex];
+ if (originalSourceLines === undefined) {
+ const originalSource = innerSourceContents[innerSourceIndex];
+ originalSourceLines = originalSource
+ ? splitIntoLines(originalSource)
+ : null;
+ innerSourceContentLines[innerSourceIndex] = originalSourceLines;
+ }
+ if (originalSourceLines !== null) {
+ const name = nameIndexValueMapping[nameIndex];
+ const originalName =
+ innerOriginalLine <= originalSourceLines.length
+ ? originalSourceLines[innerOriginalLine - 1].slice(
+ innerOriginalColumn,
+ innerOriginalColumn + name.length
+ )
+ : "";
+ if (name === originalName) {
+ finalNameIndex =
+ nameIndex < nameIndexMapping.length
+ ? nameIndexMapping[nameIndex]
+ : -2;
+ if (finalNameIndex === -2) {
+ const name = nameIndexValueMapping[nameIndex];
+ if (name) {
+ let globalIndex = nameMapping.get(name);
+ if (globalIndex === undefined) {
+ nameMapping.set(name, (globalIndex = nameMapping.size));
+ onName(globalIndex, name);
+ }
+ finalNameIndex = globalIndex;
+ } else {
+ finalNameIndex = -1;
+ }
+ nameIndexMapping[nameIndex] = finalNameIndex;
+ }
+ }
+ }
+ }
+ onChunk(
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ innerOriginalLine,
+ innerOriginalColumn,
+ finalNameIndex
+ );
+ return;
+ }
+ }
+
+ // We have a mapping to the inner source, but no inner mapping
+ if (removeInnerSource) {
+ onChunk(chunk, generatedLine, generatedColumn, -1, -1, -1, -1);
+ return;
+ } else {
+ if (sourceIndexMapping[sourceIndex] === -2) {
+ let globalIndex = sourceMapping.get(innerSourceName);
+ if (globalIndex === undefined) {
+ sourceMapping.set(source, (globalIndex = sourceMapping.size));
+ onSource(globalIndex, innerSourceName, innerSource);
+ }
+ sourceIndexMapping[sourceIndex] = globalIndex;
+ }
+ }
+ }
+
+ const finalSourceIndex =
+ sourceIndex < 0 || sourceIndex >= sourceIndexMapping.length
+ ? -1
+ : sourceIndexMapping[sourceIndex];
+ if (finalSourceIndex < 0) {
+ // no source, so we make it a generated chunk
+ onChunk(chunk, generatedLine, generatedColumn, -1, -1, -1, -1);
+ } else {
+ // Pass through the chunk with mapping
+ let finalNameIndex = -1;
+ if (nameIndex >= 0 && nameIndex < nameIndexMapping.length) {
+ finalNameIndex = nameIndexMapping[nameIndex];
+ if (finalNameIndex === -2) {
+ const name = nameIndexValueMapping[nameIndex];
+ let globalIndex = nameMapping.get(name);
+ if (globalIndex === undefined) {
+ nameMapping.set(name, (globalIndex = nameMapping.size));
+ onName(globalIndex, name);
+ }
+ finalNameIndex = globalIndex;
+ nameIndexMapping[nameIndex] = finalNameIndex;
+ }
+ }
+ onChunk(
+ chunk,
+ generatedLine,
+ generatedColumn,
+ finalSourceIndex,
+ originalLine,
+ originalColumn,
+ finalNameIndex
+ );
+ }
+ },
+ (i, source, sourceContent) => {
+ if (source === innerSourceName) {
+ innerSourceIndex = i;
+ if (innerSource !== undefined) sourceContent = innerSource;
+ else innerSource = sourceContent;
+ sourceIndexMapping[i] = -2;
+ streamChunksOfSourceMap(
+ sourceContent,
+ innerSourceMap,
+ (
+ chunk,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ while (innerSourceMapLineData.length < generatedLine) {
+ innerSourceMapLineData.push({
+ mappingsData: [],
+ chunks: []
+ });
+ }
+ const data = innerSourceMapLineData[generatedLine - 1];
+ data.mappingsData.push(
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ data.chunks.push(chunk);
+ },
+ (i, source, sourceContent) => {
+ innerSourceContents[i] = sourceContent;
+ innerSourceContentLines[i] = undefined;
+ innerSourceIndexMapping[i] = -2;
+ innerSourceIndexValueMapping[i] = [source, sourceContent];
+ },
+ (i, name) => {
+ innerNameIndexMapping[i] = -2;
+ innerNameIndexValueMapping[i] = name;
+ },
+ false,
+ columns
+ );
+ } else {
+ let globalIndex = sourceMapping.get(source);
+ if (globalIndex === undefined) {
+ sourceMapping.set(source, (globalIndex = sourceMapping.size));
+ onSource(globalIndex, source, sourceContent);
+ }
+ sourceIndexMapping[i] = globalIndex;
+ }
+ },
+ (i, name) => {
+ nameIndexMapping[i] = -2;
+ nameIndexValueMapping[i] = name;
+ },
+ finalSource,
+ columns
+ );
+};
+
+module.exports = streamChunksOfCombinedSourceMap;
diff --git a/node_modules/webpack-sources/lib/helpers/streamChunksOfRawSource.js b/node_modules/webpack-sources/lib/helpers/streamChunksOfRawSource.js
new file mode 100644
index 00000000..133022a9
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/streamChunksOfRawSource.js
@@ -0,0 +1,34 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const getGeneratedSourceInfo = require("./getGeneratedSourceInfo");
+const splitIntoLines = require("./splitIntoLines");
+
+const streamChunksOfRawSource = (source, onChunk, onSource, onName) => {
+ let line = 1;
+ const matches = splitIntoLines(source);
+ let match;
+ for (match of matches) {
+ onChunk(match, line, 0, -1, -1, -1, -1);
+ line++;
+ }
+ return matches.length === 0 || match.endsWith("\n")
+ ? {
+ generatedLine: matches.length + 1,
+ generatedColumn: 0
+ }
+ : {
+ generatedLine: matches.length,
+ generatedColumn: match.length
+ };
+};
+
+module.exports = (source, onChunk, onSource, onName, finalSource) => {
+ return finalSource
+ ? getGeneratedSourceInfo(source)
+ : streamChunksOfRawSource(source, onChunk, onSource, onName);
+};
diff --git a/node_modules/webpack-sources/lib/helpers/streamChunksOfSourceMap.js b/node_modules/webpack-sources/lib/helpers/streamChunksOfSourceMap.js
new file mode 100644
index 00000000..c57cb34b
--- /dev/null
+++ b/node_modules/webpack-sources/lib/helpers/streamChunksOfSourceMap.js
@@ -0,0 +1,412 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const getGeneratedSourceInfo = require("./getGeneratedSourceInfo");
+const getSource = require("./getSource");
+const readMappings = require("./readMappings");
+const splitIntoLines = require("./splitIntoLines");
+
+const streamChunksOfSourceMapFull = (
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+) => {
+ const lines = splitIntoLines(source);
+ if (lines.length === 0) {
+ return {
+ generatedLine: 1,
+ generatedColumn: 0
+ };
+ }
+ const { sources, sourcesContent, names, mappings } = sourceMap;
+ for (let i = 0; i < sources.length; i++) {
+ onSource(
+ i,
+ getSource(sourceMap, i),
+ (sourcesContent && sourcesContent[i]) || undefined
+ );
+ }
+ if (names) {
+ for (let i = 0; i < names.length; i++) {
+ onName(i, names[i]);
+ }
+ }
+
+ const lastLine = lines[lines.length - 1];
+ const lastNewLine = lastLine.endsWith("\n");
+ const finalLine = lastNewLine ? lines.length + 1 : lines.length;
+ const finalColumn = lastNewLine ? 0 : lastLine.length;
+
+ let currentGeneratedLine = 1;
+ let currentGeneratedColumn = 0;
+
+ let mappingActive = false;
+ let activeMappingSourceIndex = -1;
+ let activeMappingOriginalLine = -1;
+ let activeMappingOriginalColumn = -1;
+ let activeMappingNameIndex = -1;
+
+ const onMapping = (
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ if (mappingActive && currentGeneratedLine <= lines.length) {
+ let chunk;
+ const mappingLine = currentGeneratedLine;
+ const mappingColumn = currentGeneratedColumn;
+ const line = lines[currentGeneratedLine - 1];
+ if (generatedLine !== currentGeneratedLine) {
+ chunk = line.slice(currentGeneratedColumn);
+ currentGeneratedLine++;
+ currentGeneratedColumn = 0;
+ } else {
+ chunk = line.slice(currentGeneratedColumn, generatedColumn);
+ currentGeneratedColumn = generatedColumn;
+ }
+ if (chunk) {
+ onChunk(
+ chunk,
+ mappingLine,
+ mappingColumn,
+ activeMappingSourceIndex,
+ activeMappingOriginalLine,
+ activeMappingOriginalColumn,
+ activeMappingNameIndex
+ );
+ }
+ mappingActive = false;
+ }
+ if (generatedLine > currentGeneratedLine && currentGeneratedColumn > 0) {
+ if (currentGeneratedLine <= lines.length) {
+ const chunk = lines[currentGeneratedLine - 1].slice(
+ currentGeneratedColumn
+ );
+ onChunk(
+ chunk,
+ currentGeneratedLine,
+ currentGeneratedColumn,
+ -1,
+ -1,
+ -1,
+ -1
+ );
+ }
+ currentGeneratedLine++;
+ currentGeneratedColumn = 0;
+ }
+ while (generatedLine > currentGeneratedLine) {
+ if (currentGeneratedLine <= lines.length) {
+ onChunk(
+ lines[currentGeneratedLine - 1],
+ currentGeneratedLine,
+ 0,
+ -1,
+ -1,
+ -1,
+ -1
+ );
+ }
+ currentGeneratedLine++;
+ }
+ if (generatedColumn > currentGeneratedColumn) {
+ if (currentGeneratedLine <= lines.length) {
+ const chunk = lines[currentGeneratedLine - 1].slice(
+ currentGeneratedColumn,
+ generatedColumn
+ );
+ onChunk(
+ chunk,
+ currentGeneratedLine,
+ currentGeneratedColumn,
+ -1,
+ -1,
+ -1,
+ -1
+ );
+ }
+ currentGeneratedColumn = generatedColumn;
+ }
+ if (
+ sourceIndex >= 0 &&
+ (generatedLine < finalLine ||
+ (generatedLine === finalLine && generatedColumn < finalColumn))
+ ) {
+ mappingActive = true;
+ activeMappingSourceIndex = sourceIndex;
+ activeMappingOriginalLine = originalLine;
+ activeMappingOriginalColumn = originalColumn;
+ activeMappingNameIndex = nameIndex;
+ }
+ };
+ readMappings(mappings, onMapping);
+ onMapping(finalLine, finalColumn, -1, -1, -1, -1);
+ return {
+ generatedLine: finalLine,
+ generatedColumn: finalColumn
+ };
+};
+
+const streamChunksOfSourceMapLinesFull = (
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ _onName
+) => {
+ const lines = splitIntoLines(source);
+ if (lines.length === 0) {
+ return {
+ generatedLine: 1,
+ generatedColumn: 0
+ };
+ }
+ const { sources, sourcesContent, mappings } = sourceMap;
+ for (let i = 0; i < sources.length; i++) {
+ onSource(
+ i,
+ getSource(sourceMap, i),
+ (sourcesContent && sourcesContent[i]) || undefined
+ );
+ }
+
+ let currentGeneratedLine = 1;
+
+ const onMapping = (
+ generatedLine,
+ _generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ _nameIndex
+ ) => {
+ if (
+ sourceIndex < 0 ||
+ generatedLine < currentGeneratedLine ||
+ generatedLine > lines.length
+ ) {
+ return;
+ }
+ while (generatedLine > currentGeneratedLine) {
+ if (currentGeneratedLine <= lines.length) {
+ onChunk(
+ lines[currentGeneratedLine - 1],
+ currentGeneratedLine,
+ 0,
+ -1,
+ -1,
+ -1,
+ -1
+ );
+ }
+ currentGeneratedLine++;
+ }
+ if (generatedLine <= lines.length) {
+ onChunk(
+ lines[generatedLine - 1],
+ generatedLine,
+ 0,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ -1
+ );
+ currentGeneratedLine++;
+ }
+ };
+ readMappings(mappings, onMapping);
+ for (; currentGeneratedLine <= lines.length; currentGeneratedLine++) {
+ onChunk(
+ lines[currentGeneratedLine - 1],
+ currentGeneratedLine,
+ 0,
+ -1,
+ -1,
+ -1,
+ -1
+ );
+ }
+
+ const lastLine = lines[lines.length - 1];
+ const lastNewLine = lastLine.endsWith("\n");
+
+ const finalLine = lastNewLine ? lines.length + 1 : lines.length;
+ const finalColumn = lastNewLine ? 0 : lastLine.length;
+
+ return {
+ generatedLine: finalLine,
+ generatedColumn: finalColumn
+ };
+};
+
+const streamChunksOfSourceMapFinal = (
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+) => {
+ const result = getGeneratedSourceInfo(source);
+ const { generatedLine: finalLine, generatedColumn: finalColumn } = result;
+
+ if (finalLine === 1 && finalColumn === 0) return result;
+ const { sources, sourcesContent, names, mappings } = sourceMap;
+ for (let i = 0; i < sources.length; i++) {
+ onSource(
+ i,
+ getSource(sourceMap, i),
+ (sourcesContent && sourcesContent[i]) || undefined
+ );
+ }
+ if (names) {
+ for (let i = 0; i < names.length; i++) {
+ onName(i, names[i]);
+ }
+ }
+
+ let mappingActiveLine = 0;
+
+ const onMapping = (
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ ) => {
+ if (
+ generatedLine >= finalLine &&
+ (generatedColumn >= finalColumn || generatedLine > finalLine)
+ ) {
+ return;
+ }
+ if (sourceIndex >= 0) {
+ onChunk(
+ undefined,
+ generatedLine,
+ generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ nameIndex
+ );
+ mappingActiveLine = generatedLine;
+ } else if (mappingActiveLine === generatedLine) {
+ onChunk(undefined, generatedLine, generatedColumn, -1, -1, -1, -1);
+ mappingActiveLine = 0;
+ }
+ };
+ readMappings(mappings, onMapping);
+ return result;
+};
+
+const streamChunksOfSourceMapLinesFinal = (
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ _onName
+) => {
+ const result = getGeneratedSourceInfo(source);
+ const { generatedLine, generatedColumn } = result;
+ if (generatedLine === 1 && generatedColumn === 0) {
+ return {
+ generatedLine: 1,
+ generatedColumn: 0
+ };
+ }
+
+ const { sources, sourcesContent, mappings } = sourceMap;
+ for (let i = 0; i < sources.length; i++) {
+ onSource(
+ i,
+ getSource(sourceMap, i),
+ (sourcesContent && sourcesContent[i]) || undefined
+ );
+ }
+
+ const finalLine = generatedColumn === 0 ? generatedLine - 1 : generatedLine;
+
+ let currentGeneratedLine = 1;
+
+ const onMapping = (
+ generatedLine,
+ _generatedColumn,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ _nameIndex
+ ) => {
+ if (
+ sourceIndex >= 0 &&
+ currentGeneratedLine <= generatedLine &&
+ generatedLine <= finalLine
+ ) {
+ onChunk(
+ undefined,
+ generatedLine,
+ 0,
+ sourceIndex,
+ originalLine,
+ originalColumn,
+ -1
+ );
+ currentGeneratedLine = generatedLine + 1;
+ }
+ };
+ readMappings(mappings, onMapping);
+ return result;
+};
+
+module.exports = (
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName,
+ finalSource,
+ columns
+) => {
+ if (columns) {
+ return finalSource
+ ? streamChunksOfSourceMapFinal(
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+ )
+ : streamChunksOfSourceMapFull(
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+ );
+ } else {
+ return finalSource
+ ? streamChunksOfSourceMapLinesFinal(
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+ )
+ : streamChunksOfSourceMapLinesFull(
+ source,
+ sourceMap,
+ onChunk,
+ onSource,
+ onName
+ );
+ }
+};