Skip to content

Commit 46c019b

Browse files
aduh95targos
authored andcommitted
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 459fe68 commit 46c019b

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

‎lib/internal/source_map/source_map.js‎

Lines changed: 20 additions & 11 deletions
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-
returnthis._string.charAt(this._position++);
102+
returnStringPrototypeCharAt(this._string,this._position++);
98103
}
99104

100105
/**
101106
* @return {string}
102107
*/
103108
peek(){
104-
returnthis._string.charAt(this._position);
109+
returnStringPrototypeCharAt(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
letsourceIndex=0;
216221
letsourceLineNumber=0;
217222
letsourceColumnNumber=0;
@@ -222,7 +227,7 @@ class SourceMap {
222227
for(leti=0;i<map.sources.length;++i){
223228
consturl=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(constkeyinpayload){
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
returnpayload;

0 commit comments

Comments
 (0)