MCPcopy
hub / github.com/less/less.js / add

Method add

packages/less/lib/less/source-map-output.js:48–108  ·  view source on GitHub ↗
(chunk, fileInfo, index, mapLines)

Source from the content-addressed store, hash-verified

46 }
47
48 add(chunk, fileInfo, index, mapLines) {
49
50 // ignore adding empty strings
51 if (!chunk) {
52 return;
53 }
54
55 let lines, sourceLines, columns, sourceColumns, i;
56
57 if (fileInfo && fileInfo.filename) {
58 let inputSource = this._contentsMap[fileInfo.filename];
59
60 // remove vars/banner added to the top of the file
61 if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
62 // adjust the index
63 index -= this._contentsIgnoredCharsMap[fileInfo.filename];
64 if (index < 0) { index = 0; }
65 // adjust the source
66 inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
67 }
68
69 /**
70 * ignore empty content, or failsafe
71 * if contents map is incorrect
72 */
73 if (inputSource === undefined) {
74 this._css.push(chunk);
75 return;
76 }
77
78 inputSource = inputSource.substring(0, index);
79 sourceLines = inputSource.split('\n');
80 sourceColumns = sourceLines[sourceLines.length - 1];
81 }
82
83 lines = chunk.split('\n');
84 columns = lines[lines.length - 1];
85
86 if (fileInfo && fileInfo.filename) {
87 if (!mapLines) {
88 this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
89 original: { line: sourceLines.length, column: sourceColumns.length},
90 source: this.normalizeFilename(fileInfo.filename)});
91 } else {
92 for (i = 0; i < lines.length; i++) {
93 this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0},
94 original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0},
95 source: this.normalizeFilename(fileInfo.filename)});
96 }
97 }
98 }
99
100 if (lines.length === 1) {
101 this._column += columns.length;
102 } else {
103 this._lineNumber += lines.length - 1;
104 this._column = columns.length;
105 }

Callers 15

loadStylesFunction · 0.80
initRunningModeFunction · 0.80
index.jsFile · 0.80
index.jsFile · 0.80
makeRegistryFunction · 0.80
genCSSMethod · 0.80
genCSSMethod · 0.80
genCSSMethod · 0.80
genCSSMethod · 0.80
genCSSMethod · 0.80
outputRulesetMethod · 0.80
genCSSMethod · 0.80

Calls 3

normalizeFilenameMethod · 0.95
pushMethod · 0.80
addMappingMethod · 0.80

Tested by

no test coverage detected