webpack-sources
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -9,5 +9,4 @@ /* | ||
const streamChunksOfSourceMap = require("./streamChunksOfSourceMap"); | ||
const splitIntoLines = require("./splitIntoLines"); | ||
const SPLIT_LINES_REGEX = /[^\n]+\n?|\n/g; | ||
const streamChunksOfCombinedSourceMap = ( | ||
@@ -94,3 +93,3 @@ source, | ||
originalSourceLines = originalSource | ||
? originalSource.match(SPLIT_LINES_REGEX) | ||
? splitIntoLines(originalSource) | ||
: null; | ||
@@ -169,3 +168,3 @@ innerSourceContentLines[innerSourceIndex] = originalSourceLines; | ||
originalSourceLines = originalSource | ||
? originalSource.match(SPLIT_LINES_REGEX) | ||
? splitIntoLines(originalSource) | ||
: null; | ||
@@ -172,0 +171,0 @@ innerSourceContentLines[innerSourceIndex] = originalSourceLines; |
@@ -9,28 +9,21 @@ /* | ||
const getGeneratedSourceInfo = require("./getGeneratedSourceInfo"); | ||
const splitIntoLines = require("./splitIntoLines"); | ||
const MATCH_LINES_REGEX = /(?:[^\n]+\n?|\n)/g; | ||
const streamChunksOfRawSource = (source, onChunk, onSource, onName) => { | ||
let line = 1; | ||
const matches = source.match(MATCH_LINES_REGEX); | ||
if (matches !== null) { | ||
let match; | ||
for (match of matches) { | ||
onChunk(match, line, 0, -1, -1, -1, -1); | ||
line++; | ||
} | ||
return match.endsWith("\n") | ||
? { | ||
generatedLine: matches.length + 1, | ||
generatedColumn: 0 | ||
} | ||
: { | ||
generatedLine: matches.length, | ||
generatedColumn: match.length | ||
}; | ||
const matches = splitIntoLines(source); | ||
let match; | ||
for (match of matches) { | ||
onChunk(match, line, 0, -1, -1, -1, -1); | ||
line++; | ||
} | ||
return { | ||
generatedLine: 1, | ||
generatedColumn: 0 | ||
}; | ||
return matches.length === 0 || match.endsWith("\n") | ||
? { | ||
generatedLine: matches.length + 1, | ||
generatedColumn: 0 | ||
} | ||
: { | ||
generatedLine: matches.length, | ||
generatedColumn: match.length | ||
}; | ||
}; | ||
@@ -37,0 +30,0 @@ |
@@ -11,5 +11,4 @@ /* | ||
const readMappings = require("./readMappings"); | ||
const splitIntoLines = require("./splitIntoLines"); | ||
const SPLIT_LINES_REGEX = /[^\n]+\n?|\n/g; | ||
const streamChunksOfSourceMapFull = ( | ||
@@ -22,4 +21,4 @@ source, | ||
) => { | ||
const lines = source.match(SPLIT_LINES_REGEX); | ||
if (lines === null) { | ||
const lines = splitIntoLines(source); | ||
if (lines.length === 0) { | ||
return { | ||
@@ -169,4 +168,4 @@ generatedLine: 1, | ||
) => { | ||
const lines = source.match(SPLIT_LINES_REGEX); | ||
if (lines === null) { | ||
const lines = splitIntoLines(source); | ||
if (lines.length === 0) { | ||
return { | ||
@@ -173,0 +172,0 @@ generatedLine: 1, |
@@ -8,2 +8,3 @@ /* | ||
const { getMap, getSourceAndMap } = require("./helpers/getFromStreamChunks"); | ||
const splitIntoLines = require("./helpers/splitIntoLines"); | ||
const getGeneratedSourceInfo = require("./helpers/getGeneratedSourceInfo"); | ||
@@ -13,3 +14,2 @@ const Source = require("./Source"); | ||
const SPLIT_REGEX = /[^\n;{}]+[;{} \r\t]*\n?|[;{} \r\t]+\n?|\n/g; | ||
const SPLIT_LINES_REGEX = /[^\n]+\n?|\n/g; | ||
@@ -108,26 +108,19 @@ class OriginalSource extends Source { | ||
let line = 1; | ||
const matches = this._value.match(SPLIT_LINES_REGEX); | ||
if (matches !== null) { | ||
let match; | ||
for (match of matches) { | ||
onChunk(finalSource ? undefined : match, line, 0, 0, line, 0, -1); | ||
line++; | ||
} | ||
return match.endsWith("\n") | ||
? { | ||
generatedLine: matches.length + 1, | ||
generatedColumn: 0, | ||
source: finalSource ? this._value : undefined | ||
} | ||
: { | ||
generatedLine: matches.length, | ||
generatedColumn: match.length, | ||
source: finalSource ? this._value : undefined | ||
}; | ||
const matches = splitIntoLines(this._value); | ||
let match; | ||
for (match of matches) { | ||
onChunk(finalSource ? undefined : match, line, 0, 0, line, 0, -1); | ||
line++; | ||
} | ||
return { | ||
generatedLine: 1, | ||
generatedColumn: 0, | ||
source: finalSource ? this._value : undefined | ||
}; | ||
return matches.length === 0 || match.endsWith("\n") | ||
? { | ||
generatedLine: matches.length + 1, | ||
generatedColumn: 0, | ||
source: finalSource ? this._value : undefined | ||
} | ||
: { | ||
generatedLine: matches.length, | ||
generatedColumn: match.length, | ||
source: finalSource ? this._value : undefined | ||
}; | ||
} | ||
@@ -134,0 +127,0 @@ } |
@@ -21,2 +21,3 @@ /* | ||
this._valueAsBuffer = isBuffer ? value : undefined; | ||
this._valueAsString = isBuffer ? undefined : value; | ||
} | ||
@@ -55,6 +56,12 @@ | ||
if (this._value === undefined) { | ||
this._value = this._valueAsBuffer.toString("utf-8"); | ||
this._value = Buffer.from(this._valueAsBuffer, "utf-8"); | ||
} | ||
if (this._valueAsString === undefined) { | ||
this._valueAsString = | ||
typeof this._value === "string" | ||
? this._value | ||
: this._value.toString("utf-8"); | ||
} | ||
return streamChunksOfRawSource( | ||
this._value, | ||
this._valueAsString, | ||
onChunk, | ||
@@ -61,0 +68,0 @@ onSource, |
@@ -10,2 +10,3 @@ /* | ||
const Source = require("./Source"); | ||
const splitIntoLines = require("./helpers/splitIntoLines"); | ||
@@ -22,4 +23,2 @@ // since v8 7.0, Array.prototype.sort is stable | ||
const SPLIT_LINES_REGEX = /[^\n]+\n?|\n/g; | ||
class Replacement { | ||
@@ -168,3 +167,3 @@ constructor(start, end, content, name) { | ||
if (typeof content === "string") { | ||
content = content.match(SPLIT_LINES_REGEX) || []; | ||
content = splitIntoLines(content); | ||
sourceContents[sourceIndex] = content; | ||
@@ -171,0 +170,0 @@ } |
{ | ||
"name": "webpack-sources", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Source code handling classes for webpack", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
90596
26
3036