format: prettify entire project
This commit is contained in:
262
node_modules/source-map-js/lib/source-node.js
generated
vendored
262
node_modules/source-map-js/lib/source-node.js
generated
vendored
@ -18,7 +18,7 @@ var NEWLINE_CODE = 10;
|
||||
// Private symbol for identifying `SourceNode`s when multiple versions of
|
||||
// the source-map library are loaded. This MUST NOT CHANGE across
|
||||
// versions!
|
||||
var isSourceNode = "$$$isSourceNode$$$";
|
||||
var isSourceNode = '$$$isSourceNode$$$';
|
||||
|
||||
/**
|
||||
* SourceNodes provide a way to abstract over interpolating/concatenating
|
||||
@ -52,7 +52,11 @@ function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
||||
* SourceMapConsumer should be relative to.
|
||||
*/
|
||||
SourceNode.fromStringWithSourceMap =
|
||||
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
|
||||
function SourceNode_fromStringWithSourceMap(
|
||||
aGeneratedCode,
|
||||
aSourceMapConsumer,
|
||||
aRelativePath
|
||||
) {
|
||||
// The SourceNode we want to fill with the generated code
|
||||
// and the SourceMap
|
||||
var node = new SourceNode();
|
||||
@ -63,20 +67,22 @@ SourceNode.fromStringWithSourceMap =
|
||||
// Processed fragments are accessed by calling `shiftNextLine`.
|
||||
var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
|
||||
var remainingLinesIndex = 0;
|
||||
var shiftNextLine = function() {
|
||||
var shiftNextLine = function () {
|
||||
var lineContents = getNextLine();
|
||||
// The last line of a file might not have a newline.
|
||||
var newLine = getNextLine() || "";
|
||||
var newLine = getNextLine() || '';
|
||||
return lineContents + newLine;
|
||||
|
||||
function getNextLine() {
|
||||
return remainingLinesIndex < remainingLines.length ?
|
||||
remainingLines[remainingLinesIndex++] : undefined;
|
||||
remainingLines[remainingLinesIndex++]
|
||||
: undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// We need to remember the position of "remainingLines"
|
||||
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
|
||||
var lastGeneratedLine = 1,
|
||||
lastGeneratedColumn = 0;
|
||||
|
||||
// The generate SourceNodes we need a code range.
|
||||
// To extract it current and last mapping is used.
|
||||
@ -98,10 +104,13 @@ SourceNode.fromStringWithSourceMap =
|
||||
// Associate the code between "lastGeneratedColumn" and
|
||||
// "mapping.generatedColumn" with "lastMapping"
|
||||
var nextLine = remainingLines[remainingLinesIndex] || '';
|
||||
var code = nextLine.substr(0, mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
var code = nextLine.substr(
|
||||
0,
|
||||
mapping.generatedColumn - lastGeneratedColumn
|
||||
);
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(
|
||||
mapping.generatedColumn - lastGeneratedColumn
|
||||
);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
addMappingWithCode(lastMapping, code);
|
||||
// No more remaining code, continue
|
||||
@ -119,7 +128,9 @@ SourceNode.fromStringWithSourceMap =
|
||||
if (lastGeneratedColumn < mapping.generatedColumn) {
|
||||
var nextLine = remainingLines[remainingLinesIndex] || '';
|
||||
node.add(nextLine.substr(0, mapping.generatedColumn));
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(
|
||||
mapping.generatedColumn
|
||||
);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
}
|
||||
lastMapping = mapping;
|
||||
@ -131,7 +142,7 @@ SourceNode.fromStringWithSourceMap =
|
||||
addMappingWithCode(lastMapping, shiftNextLine());
|
||||
}
|
||||
// and add the remaining lines without any mapping
|
||||
node.add(remainingLines.splice(remainingLinesIndex).join(""));
|
||||
node.add(remainingLines.splice(remainingLinesIndex).join(''));
|
||||
}
|
||||
|
||||
// Copy sourcesContent into SourceNode
|
||||
@ -151,14 +162,19 @@ SourceNode.fromStringWithSourceMap =
|
||||
if (mapping === null || mapping.source === undefined) {
|
||||
node.add(code);
|
||||
} else {
|
||||
var source = aRelativePath
|
||||
? util.join(aRelativePath, mapping.source)
|
||||
var source =
|
||||
aRelativePath ?
|
||||
util.join(aRelativePath, mapping.source)
|
||||
: mapping.source;
|
||||
node.add(new SourceNode(mapping.originalLine,
|
||||
mapping.originalColumn,
|
||||
source,
|
||||
code,
|
||||
mapping.name));
|
||||
node.add(
|
||||
new SourceNode(
|
||||
mapping.originalLine,
|
||||
mapping.originalColumn,
|
||||
source,
|
||||
code,
|
||||
mapping.name
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -174,15 +190,14 @@ SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
||||
aChunk.forEach(function (chunk) {
|
||||
this.add(chunk);
|
||||
}, this);
|
||||
}
|
||||
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
|
||||
} else if (aChunk[isSourceNode] || typeof aChunk === 'string') {
|
||||
if (aChunk) {
|
||||
this.children.push(aChunk);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
'Expected a SourceNode, string, or an array of SourceNodes and strings. Got ' +
|
||||
aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
@ -196,16 +211,15 @@ SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
||||
*/
|
||||
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
||||
if (Array.isArray(aChunk)) {
|
||||
for (var i = aChunk.length-1; i >= 0; i--) {
|
||||
for (var i = aChunk.length - 1; i >= 0; i--) {
|
||||
this.prepend(aChunk[i]);
|
||||
}
|
||||
}
|
||||
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
|
||||
} else if (aChunk[isSourceNode] || typeof aChunk === 'string') {
|
||||
this.children.unshift(aChunk);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
'Expected a SourceNode, string, or an array of SourceNodes and strings. Got ' +
|
||||
aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
@ -224,13 +238,14 @@ SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
||||
chunk = this.children[i];
|
||||
if (chunk[isSourceNode]) {
|
||||
chunk.walk(aFn);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (chunk !== '') {
|
||||
aFn(chunk, { source: this.source,
|
||||
line: this.line,
|
||||
column: this.column,
|
||||
name: this.name });
|
||||
aFn(chunk, {
|
||||
source: this.source,
|
||||
line: this.line,
|
||||
column: this.column,
|
||||
name: this.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -248,7 +263,7 @@ SourceNode.prototype.join = function SourceNode_join(aSep) {
|
||||
var len = this.children.length;
|
||||
if (len > 0) {
|
||||
newChildren = [];
|
||||
for (i = 0; i < len-1; i++) {
|
||||
for (i = 0; i < len - 1; i++) {
|
||||
newChildren.push(this.children[i]);
|
||||
newChildren.push(aSep);
|
||||
}
|
||||
@ -265,15 +280,19 @@ SourceNode.prototype.join = function SourceNode_join(aSep) {
|
||||
* @param aPattern The pattern to replace.
|
||||
* @param aReplacement The thing to replace the pattern with.
|
||||
*/
|
||||
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
||||
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(
|
||||
aPattern,
|
||||
aReplacement
|
||||
) {
|
||||
var lastChild = this.children[this.children.length - 1];
|
||||
if (lastChild[isSourceNode]) {
|
||||
lastChild.replaceRight(aPattern, aReplacement);
|
||||
}
|
||||
else if (typeof lastChild === 'string') {
|
||||
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
||||
}
|
||||
else {
|
||||
} else if (typeof lastChild === 'string') {
|
||||
this.children[this.children.length - 1] = lastChild.replace(
|
||||
aPattern,
|
||||
aReplacement
|
||||
);
|
||||
} else {
|
||||
this.children.push(''.replace(aPattern, aReplacement));
|
||||
}
|
||||
return this;
|
||||
@ -286,10 +305,12 @@ SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, a
|
||||
* @param aSourceFile The filename of the source file
|
||||
* @param aSourceContent The content of the source file
|
||||
*/
|
||||
SourceNode.prototype.setSourceContent =
|
||||
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
|
||||
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
||||
};
|
||||
SourceNode.prototype.setSourceContent = function SourceNode_setSourceContent(
|
||||
aSourceFile,
|
||||
aSourceContent
|
||||
) {
|
||||
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk over the tree of SourceNodes. The walking function is called for each
|
||||
@ -316,7 +337,7 @@ SourceNode.prototype.walkSourceContents =
|
||||
* and concatenates all the various snippets together to one string.
|
||||
*/
|
||||
SourceNode.prototype.toString = function SourceNode_toString() {
|
||||
var str = "";
|
||||
var str = '';
|
||||
this.walk(function (chunk) {
|
||||
str += chunk;
|
||||
});
|
||||
@ -327,87 +348,92 @@ SourceNode.prototype.toString = function SourceNode_toString() {
|
||||
* Returns the string representation of this source node along with a source
|
||||
* map.
|
||||
*/
|
||||
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
||||
var generated = {
|
||||
code: "",
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
var map = new SourceMapGenerator(aArgs);
|
||||
var sourceMappingActive = false;
|
||||
var lastOriginalSource = null;
|
||||
var lastOriginalLine = null;
|
||||
var lastOriginalColumn = null;
|
||||
var lastOriginalName = null;
|
||||
this.walk(function (chunk, original) {
|
||||
generated.code += chunk;
|
||||
if (original.source !== null
|
||||
&& original.line !== null
|
||||
&& original.column !== null) {
|
||||
if(lastOriginalSource !== original.source
|
||||
|| lastOriginalLine !== original.line
|
||||
|| lastOriginalColumn !== original.column
|
||||
|| lastOriginalName !== original.name) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
}
|
||||
lastOriginalSource = original.source;
|
||||
lastOriginalLine = original.line;
|
||||
lastOriginalColumn = original.column;
|
||||
lastOriginalName = original.name;
|
||||
sourceMappingActive = true;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
}
|
||||
});
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
}
|
||||
for (var idx = 0, length = chunk.length; idx < length; idx++) {
|
||||
if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
|
||||
generated.line++;
|
||||
generated.column = 0;
|
||||
// Mappings end at eol
|
||||
if (idx + 1 === length) {
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
} else if (sourceMappingActive) {
|
||||
SourceNode.prototype.toStringWithSourceMap =
|
||||
function SourceNode_toStringWithSourceMap(aArgs) {
|
||||
var generated = {
|
||||
code: '',
|
||||
line: 1,
|
||||
column: 0,
|
||||
};
|
||||
var map = new SourceMapGenerator(aArgs);
|
||||
var sourceMappingActive = false;
|
||||
var lastOriginalSource = null;
|
||||
var lastOriginalLine = null;
|
||||
var lastOriginalColumn = null;
|
||||
var lastOriginalName = null;
|
||||
this.walk(function (chunk, original) {
|
||||
generated.code += chunk;
|
||||
if (
|
||||
original.source !== null &&
|
||||
original.line !== null &&
|
||||
original.column !== null
|
||||
) {
|
||||
if (
|
||||
lastOriginalSource !== original.source ||
|
||||
lastOriginalLine !== original.line ||
|
||||
lastOriginalColumn !== original.column ||
|
||||
lastOriginalName !== original.name
|
||||
) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
column: original.column,
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
column: generated.column,
|
||||
},
|
||||
name: original.name
|
||||
name: original.name,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
generated.column++;
|
||||
lastOriginalSource = original.source;
|
||||
lastOriginalLine = original.line;
|
||||
lastOriginalColumn = original.column;
|
||||
lastOriginalName = original.name;
|
||||
sourceMappingActive = true;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column,
|
||||
},
|
||||
});
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
map.setSourceContent(sourceFile, sourceContent);
|
||||
});
|
||||
for (var idx = 0, length = chunk.length; idx < length; idx++) {
|
||||
if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
|
||||
generated.line++;
|
||||
generated.column = 0;
|
||||
// Mappings end at eol
|
||||
if (idx + 1 === length) {
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column,
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column,
|
||||
},
|
||||
name: original.name,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
generated.column++;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
map.setSourceContent(sourceFile, sourceContent);
|
||||
});
|
||||
|
||||
return { code: generated.code, map: map };
|
||||
};
|
||||
return { code: generated.code, map: map };
|
||||
};
|
||||
|
||||
exports.SourceNode = SourceNode;
|
||||
|
Reference in New Issue
Block a user