Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ConcatSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ConcatSource extends Source {
if (Buffer.isBuffer(bufferOrString)) {
buffers.push(bufferOrString);
} else {
// This will not happen
buffers.push(Buffer.from(bufferOrString, "utf-8"));
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/OriginalSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const { getMap, getSourceAndMap } = require("./helpers/getFromStreamChunks");
const splitIntoLines = require("./helpers/splitIntoLines");
const getGeneratedSourceInfo = require("./helpers/getGeneratedSourceInfo");
const Source = require("./Source");

const SPLIT_REGEX = /[^\n;{}]+[;{} \r\t]*\n?|[;{} \r\t]+\n?|\n/g;
const splitIntoPotentialTokens = require("./helpers/splitIntoPotentialTokens");

class OriginalSource extends Source {
constructor(value, name) {
Expand Down Expand Up @@ -61,7 +60,7 @@ class OriginalSource extends Source {
const finalSource = !!(options && options.finalSource);
if (!options || options.columns !== false) {
// With column info we need to read all lines and split them
const matches = this._value.match(SPLIT_REGEX);
const matches = splitIntoPotentialTokens(this._value);
let line = 1;
let column = 0;
if (matches !== null) {
Expand Down
41 changes: 41 additions & 0 deletions lib/helpers/splitIntoPotentialTokens.js
Original file line number Diff line number Diff line change
@@ -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;