Skip to content

Commit

Permalink
lib: refactor source_map to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: #36733
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 committed Jan 13, 2021
1 parent 251a0ff commit e2b954b
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/internal/source_map/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@
'use strict';

const {
ArrayIsArray
ArrayIsArray,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSort,
ObjectPrototypeHasOwnProperty,
StringPrototypeCharAt,
} = primordials;

const {
Expand All @@ -94,14 +99,14 @@ class StringCharIterator {
* @return {string}
*/
next() {
return this._string.charAt(this._position++);
return StringPrototypeCharAt(this._string, this._position++);
}

/**
* @return {string}
*/
peek() {
return this._string.charAt(this._position);
return StringPrototypeCharAt(this._string, this._position);
}

/**
Expand Down Expand Up @@ -158,7 +163,7 @@ class SourceMap {
} else {
this.#parseMap(this.#payload, 0, 0);
}
this.#mappings.sort(compareSourceMapEntry);
ArrayPrototypeSort(this.#mappings, compareSourceMapEntry);
}

/**
Expand Down Expand Up @@ -211,7 +216,7 @@ class SourceMap {
/**
* @override
*/
#parseMap = (map, lineNumber, columnNumber) => {
#parseMap(map, lineNumber, columnNumber) {
let sourceIndex = 0;
let sourceLineNumber = 0;
let sourceColumnNumber = 0;
Expand All @@ -222,7 +227,7 @@ class SourceMap {
for (let i = 0; i < map.sources.length; ++i) {
const url = map.sources[i];
originalToCanonicalURLMap[url] = url;
sources.push(url);
ArrayPrototypePush(sources, url);
this.#sources[url] = true;

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

columnNumber += decodeVLQ(stringCharIterator);
if (isSeparator(stringCharIterator.peek())) {
this.#mappings.push([lineNumber, columnNumber]);
ArrayPrototypePush(this.#mappings, [lineNumber, columnNumber]);
continue;
}

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

this.#mappings.push([lineNumber, columnNumber, sourceURL,
sourceLineNumber, sourceColumnNumber, name]);
ArrayPrototypePush(
this.#mappings,
[lineNumber, columnNumber, sourceURL, sourceLineNumber,
sourceColumnNumber, name]
);
}
};
}
Expand Down Expand Up @@ -320,8 +328,9 @@ function cloneSourceMapV3(payload) {
}
payload = { ...payload };
for (const key in payload) {
if (payload.hasOwnProperty(key) && ArrayIsArray(payload[key])) {
payload[key] = payload[key].slice(0);
if (ObjectPrototypeHasOwnProperty(payload, key) &&
ArrayIsArray(payload[key])) {
payload[key] = ArrayPrototypeSlice(payload[key]);
}
}
return payload;
Expand Down

0 comments on commit e2b954b

Please sign in to comment.