Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b1e4272

Browse files
aduh95targos
authored andcommittedMay 30, 2021
lib: refactor source_map to use more primordials
PR-URL: #36733 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 16bb394 commit b1e4272

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed
 

‎lib/internal/source_map/source_map.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@
6767
'use strict';
6868

6969
const {
70-
ArrayIsArray
70+
ArrayIsArray,
71+
ArrayPrototypePush,
72+
ArrayPrototypeSlice,
73+
ArrayPrototypeSort,
74+
ObjectPrototypeHasOwnProperty,
75+
StringPrototypeCharAt,
7176
} = primordials;
7277

7378
const {
@@ -94,14 +99,14 @@ class StringCharIterator {
9499
* @return {string}
95100
*/
96101
next() {
97-
return this._string.charAt(this._position++);
102+
return StringPrototypeCharAt(this._string, this._position++);
98103
}
99104

100105
/**
101106
* @return {string}
102107
*/
103108
peek() {
104-
return this._string.charAt(this._position);
109+
return StringPrototypeCharAt(this._string, this._position);
105110
}
106111

107112
/**
@@ -158,7 +163,7 @@ class SourceMap {
158163
} else {
159164
this.#parseMap(this.#payload, 0, 0);
160165
}
161-
this.#mappings.sort(compareSourceMapEntry);
166+
ArrayPrototypeSort(this.#mappings, compareSourceMapEntry);
162167
}
163168

164169
/**
@@ -211,7 +216,7 @@ class SourceMap {
211216
/**
212217
* @override
213218
*/
214-
#parseMap = (map, lineNumber, columnNumber) => {
219+
#parseMap(map, lineNumber, columnNumber) {
215220
let sourceIndex = 0;
216221
let sourceLineNumber = 0;
217222
let sourceColumnNumber = 0;
@@ -222,7 +227,7 @@ class SourceMap {
222227
for (let i = 0; i < map.sources.length; ++i) {
223228
const url = map.sources[i];
224229
originalToCanonicalURLMap[url] = url;
225-
sources.push(url);
230+
ArrayPrototypePush(sources, url);
226231
this.#sources[url] = true;
227232

228233
if (map.sourcesContent && map.sourcesContent[i])
@@ -246,7 +251,7 @@ class SourceMap {
246251

247252
columnNumber += decodeVLQ(stringCharIterator);
248253
if (isSeparator(stringCharIterator.peek())) {
249-
this.#mappings.push([lineNumber, columnNumber]);
254+
ArrayPrototypePush(this.#mappings, [lineNumber, columnNumber]);
250255
continue;
251256
}
252257

@@ -264,8 +269,11 @@ class SourceMap {
264269
name = map.names?.[nameIndex];
265270
}
266271

267-
this.#mappings.push([lineNumber, columnNumber, sourceURL,
268-
sourceLineNumber, sourceColumnNumber, name]);
272+
ArrayPrototypePush(
273+
this.#mappings,
274+
[lineNumber, columnNumber, sourceURL, sourceLineNumber,
275+
sourceColumnNumber, name]
276+
);
269277
}
270278
};
271279
}
@@ -320,8 +328,9 @@ function cloneSourceMapV3(payload) {
320328
}
321329
payload = { ...payload };
322330
for (const key in payload) {
323-
if (payload.hasOwnProperty(key) && ArrayIsArray(payload[key])) {
324-
payload[key] = payload[key].slice(0);
331+
if (ObjectPrototypeHasOwnProperty(payload, key) &&
332+
ArrayIsArray(payload[key])) {
333+
payload[key] = ArrayPrototypeSlice(payload[key]);
325334
}
326335
}
327336
return payload;

0 commit comments

Comments
 (0)
Please sign in to comment.