webpack-sources
Advanced tools
Comparing version 3.0.4 to 3.1.0
@@ -195,3 +195,4 @@ /* | ||
onName, | ||
!!(options && options.finalSource) | ||
!!(options && options.finalSource), | ||
true | ||
); | ||
@@ -198,0 +199,0 @@ } else { |
@@ -145,27 +145,37 @@ /* | ||
const resultSourceIndex = | ||
sourceIndex < 0 ? -1 : sourceIndexMapping[sourceIndex]; | ||
sourceIndex < 0 || sourceIndex >= sourceIndexMapping.length | ||
? -1 | ||
: sourceIndexMapping[sourceIndex]; | ||
const resultNameIndex = | ||
nameIndex < 0 ? -1 : nameIndexMapping[nameIndex]; | ||
nameIndex < 0 || nameIndex >= nameIndexMapping.length | ||
? -1 | ||
: nameIndexMapping[nameIndex]; | ||
lastMappingLine = resultSourceIndex < 0 ? 0 : generatedLine; | ||
if (finalSource && chunk !== undefined) { | ||
code += chunk; | ||
onChunk( | ||
undefined, | ||
line, | ||
column, | ||
resultSourceIndex, | ||
originalLine, | ||
originalColumn, | ||
resultNameIndex | ||
); | ||
if (finalSource) { | ||
if (chunk !== undefined) code += chunk; | ||
if (resultSourceIndex >= 0) { | ||
onChunk( | ||
undefined, | ||
line, | ||
column, | ||
resultSourceIndex, | ||
originalLine, | ||
originalColumn, | ||
resultNameIndex | ||
); | ||
} | ||
} else { | ||
onChunk( | ||
chunk, | ||
line, | ||
column, | ||
resultSourceIndex, | ||
originalLine, | ||
originalColumn, | ||
resultNameIndex | ||
); | ||
if (resultSourceIndex < 0) { | ||
onChunk(chunk, line, column, -1, -1, -1, -1); | ||
} else { | ||
onChunk( | ||
chunk, | ||
line, | ||
column, | ||
resultSourceIndex, | ||
originalLine, | ||
originalColumn, | ||
resultNameIndex | ||
); | ||
} | ||
} | ||
@@ -172,0 +182,0 @@ }, |
@@ -23,3 +23,5 @@ /* | ||
let names = []; | ||
const addMapping = createMappingsSerializer(options); | ||
const addMapping = createMappingsSerializer( | ||
Object.assign({}, options, { columns: true }) | ||
); | ||
const finalSource = !!(options && options.finalSource); | ||
@@ -26,0 +28,0 @@ const { generatedLine, generatedColumn, source } = streamChunks( |
@@ -23,3 +23,4 @@ /* | ||
onName, | ||
!!(options && options.finalSource) | ||
!!(options && options.finalSource), | ||
!!(options && options.columns !== false) | ||
); | ||
@@ -26,0 +27,0 @@ } else { |
@@ -22,3 +22,4 @@ /* | ||
onName, | ||
finalSource | ||
finalSource, | ||
columns | ||
) => { | ||
@@ -87,3 +88,5 @@ let sourceMapping = new Map(); | ||
let originalSourceLines = | ||
innerSourceContentLines[innerSourceIndex]; | ||
innerSourceIndex < innerSourceContentLines.length | ||
? innerSourceContentLines[innerSourceIndex] | ||
: null; | ||
if (originalSourceLines === undefined) { | ||
@@ -114,7 +117,11 @@ const originalSource = innerSourceContents[innerSourceIndex]; | ||
// emit source when needed and compute global source index | ||
let sourceIndex = innerSourceIndexMapping[innerSourceIndex]; | ||
if (sourceIndex < 0) { | ||
const [source, sourceContent] = innerSourceIndexValueMapping[ | ||
innerSourceIndex | ||
]; | ||
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); | ||
@@ -133,11 +140,21 @@ if (globalIndex === undefined) { | ||
// when we have a inner name | ||
finalNameIndex = innerNameIndexMapping[innerNameIndex]; | ||
if (finalNameIndex < 0) { | ||
const name = innerNameIndexValueMapping[innerNameIndex]; | ||
let globalIndex = nameMapping.get(name); | ||
if (globalIndex === undefined) { | ||
nameMapping.set(name, (globalIndex = nameMapping.size)); | ||
onName(globalIndex, 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; | ||
} | ||
finalNameIndex = globalIndex; | ||
innerNameIndexMapping[innerNameIndex] = finalNameIndex; | ||
@@ -167,11 +184,18 @@ } | ||
if (name === originalName) { | ||
finalNameIndex = nameIndexMapping[nameIndex]; | ||
if (finalNameIndex < 0) { | ||
finalNameIndex = | ||
nameIndex < nameIndexMapping.length | ||
? nameIndexMapping[nameIndex] | ||
: -2; | ||
if (finalNameIndex === -2) { | ||
const name = nameIndexValueMapping[nameIndex]; | ||
let globalIndex = nameMapping.get(name); | ||
if (globalIndex === undefined) { | ||
nameMapping.set(name, (globalIndex = nameMapping.size)); | ||
onName(globalIndex, name); | ||
if (name) { | ||
let globalIndex = nameMapping.get(name); | ||
if (globalIndex === undefined) { | ||
nameMapping.set(name, (globalIndex = nameMapping.size)); | ||
onName(globalIndex, name); | ||
} | ||
finalNameIndex = globalIndex; | ||
} else { | ||
finalNameIndex = -1; | ||
} | ||
finalNameIndex = globalIndex; | ||
nameIndexMapping[nameIndex] = finalNameIndex; | ||
@@ -201,26 +225,35 @@ } | ||
// Pass through the chunk with mapping | ||
let finalNameIndex = -1; | ||
if (nameIndex >= 0) { | ||
finalNameIndex = nameIndexMapping[nameIndex]; | ||
if (finalNameIndex < 0) { | ||
const name = nameIndexValueMapping[nameIndex]; | ||
let globalIndex = nameMapping.get(name); | ||
if (globalIndex === undefined) { | ||
nameMapping.set(name, (globalIndex = nameMapping.size)); | ||
onName(globalIndex, name); | ||
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; | ||
} | ||
finalNameIndex = globalIndex; | ||
nameIndexMapping[nameIndex] = finalNameIndex; | ||
} | ||
onChunk( | ||
chunk, | ||
generatedLine, | ||
generatedColumn, | ||
finalSourceIndex, | ||
originalLine, | ||
originalColumn, | ||
finalNameIndex | ||
); | ||
} | ||
onChunk( | ||
chunk, | ||
generatedLine, | ||
generatedColumn, | ||
sourceIndex < 0 ? -1 : sourceIndexMapping[sourceIndex], | ||
originalLine, | ||
originalColumn, | ||
nameIndex < 0 ? -1 : nameIndexMapping[nameIndex] | ||
); | ||
}, | ||
@@ -262,9 +295,11 @@ (i, source, sourceContent) => { | ||
innerSourceContentLines[i] = undefined; | ||
innerSourceIndexMapping[i] = -1; | ||
innerSourceIndexMapping[i] = -2; | ||
innerSourceIndexValueMapping[i] = [source, sourceContent]; | ||
}, | ||
(i, name) => { | ||
innerNameIndexMapping[i] = -1; | ||
innerNameIndexMapping[i] = -2; | ||
innerNameIndexValueMapping[i] = name; | ||
} | ||
}, | ||
false, | ||
columns | ||
); | ||
@@ -281,6 +316,7 @@ if (removeInnerSource) return; | ||
(i, name) => { | ||
nameIndexMapping[i] = -1; | ||
nameIndexMapping[i] = -2; | ||
nameIndexValueMapping[i] = name; | ||
}, | ||
finalSource | ||
finalSource, | ||
columns | ||
); | ||
@@ -287,0 +323,0 @@ }; |
@@ -30,3 +30,7 @@ /* | ||
for (let i = 0; i < sources.length; i++) { | ||
onSource(i, getSource(sourceMap, i), sourcesContent && sourcesContent[i]); | ||
onSource( | ||
i, | ||
getSource(sourceMap, i), | ||
(sourcesContent && sourcesContent[i]) || undefined | ||
); | ||
} | ||
@@ -155,2 +159,88 @@ if (names) { | ||
const streamChunksOfSourceMapLinesFull = ( | ||
source, | ||
sourceMap, | ||
onChunk, | ||
onSource, | ||
_onName | ||
) => { | ||
const lines = source.match(SPLIT_LINES_REGEX); | ||
if (lines === null) { | ||
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) 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"); | ||
return lastNewLine | ||
? { | ||
generatedLine: lines.length + 1, | ||
generatedColumn: 0 | ||
} | ||
: { | ||
generatedLine: lines.length, | ||
generatedColumn: lastLine.length | ||
}; | ||
}; | ||
const streamChunksOfSourceMapFinal = ( | ||
@@ -165,3 +255,7 @@ source, | ||
for (let i = 0; i < sources.length; i++) { | ||
onSource(i, getSource(sourceMap, i), sourcesContent && sourcesContent[i]); | ||
onSource( | ||
i, | ||
getSource(sourceMap, i), | ||
(sourcesContent && sourcesContent[i]) || undefined | ||
); | ||
} | ||
@@ -204,2 +298,58 @@ if (names) { | ||
const streamChunksOfSourceMapLinesFinal = ( | ||
source, | ||
sourceMap, | ||
onChunk, | ||
onSource, | ||
_onName | ||
) => { | ||
const result = getGeneratedSourceInfo(source); | ||
const { generatedLine: numberOfLines, generatedColumn } = result; | ||
if (numberOfLines === 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 | ||
); | ||
} | ||
let currentGeneratedLine = 1; | ||
const onMapping = ( | ||
generatedLine, | ||
_generatedColumn, | ||
sourceIndex, | ||
originalLine, | ||
originalColumn, | ||
_nameIndex | ||
) => { | ||
if ( | ||
sourceIndex >= 0 && | ||
currentGeneratedLine <= generatedLine && | ||
generatedLine <= numberOfLines | ||
) { | ||
onChunk( | ||
undefined, | ||
generatedLine, | ||
0, | ||
sourceIndex, | ||
originalLine, | ||
originalColumn, | ||
-1 | ||
); | ||
currentGeneratedLine = generatedLine + 1; | ||
} | ||
}; | ||
readMappings(mappings, onMapping); | ||
return result; | ||
}; | ||
module.exports = ( | ||
@@ -211,7 +361,38 @@ source, | ||
onName, | ||
finalSource | ||
finalSource, | ||
columns | ||
) => { | ||
return finalSource | ||
? streamChunksOfSourceMapFinal(source, sourceMap, onChunk, onSource, onName) | ||
: streamChunksOfSourceMapFull(source, sourceMap, onChunk, onSource, onName); | ||
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 | ||
); | ||
} | ||
}; |
@@ -253,3 +253,5 @@ /* | ||
originalColumn, | ||
nameIndex < 0 ? -1 : nameIndexMapping[nameIndex] | ||
nameIndex < 0 || nameIndex >= nameIndexMapping.length | ||
? -1 | ||
: nameIndexMapping[nameIndex] | ||
); | ||
@@ -256,0 +258,0 @@ generatedColumn += offset; |
@@ -202,3 +202,4 @@ /* | ||
onName, | ||
!!(options && options.finalSource) | ||
!!(options && options.finalSource), | ||
!!(options && options.columns !== false) | ||
); | ||
@@ -212,3 +213,4 @@ } else { | ||
onName, | ||
!!(options && options.finalSource) | ||
!!(options && options.finalSource), | ||
!!(options && options.columns !== false) | ||
); | ||
@@ -215,0 +217,0 @@ } |
{ | ||
"name": "webpack-sources", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "Source code handling classes for webpack", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87899
2965