Skip to content

Commit 0732751

Browse files
authored
Optimize library_nodepath.js. NFC (#23086)
1 parent b95a669 commit 0732751

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/closure-externs/node-externs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ fs.Stats.prototype.mtimeMs;
119119
* @type {number}
120120
*/
121121
fs.Stats.prototype.ctimeMs;
122+
123+
/**
124+
* @param {string} p
125+
* @return {boolean}
126+
* @nosideeffects
127+
*/
128+
path.isAbsolute;
129+
130+
/**
131+
* @type {Object.<string,*>}
132+
*/
133+
path.posix;

src/library_nodepath.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
// operations. Hence, using `nodePath` should be safe here.
1313

1414
addToLibrary({
15-
$PATH: {
16-
isAbs: (path) => nodePath['isAbsolute'](path),
17-
normalize: (path) => nodePath['normalize'](path),
18-
dirname: (path) => nodePath['dirname'](path),
19-
basename: (path) => nodePath['basename'](path),
20-
join: (...args) => nodePath['join'](...args),
21-
join2: (l, r) => nodePath['join'](l, r),
22-
},
15+
$PATH: `{
16+
isAbs: nodePath.isAbsolute,
17+
normalize: nodePath.normalize,
18+
dirname: nodePath.dirname,
19+
basename: nodePath.basename,
20+
join: nodePath.join,
21+
join2: nodePath.join,
22+
}`,
2323
// The FS-using parts are split out into a separate object, so simple path
2424
// usage does not require the FS.
2525
$PATH_FS__deps: ['$FS'],
2626
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
2727
$PATH_FS: {
2828
resolve: (...paths) => {
2929
paths.unshift(FS.cwd());
30-
return nodePath['posix']['resolve'](...paths);
30+
return nodePath.posix.resolve(...paths);
3131
},
32-
relative: (from, to) => nodePath['posix']['relative'](from || FS.cwd(), to || FS.cwd()),
32+
relative: (from, to) => nodePath.posix.relative(from || FS.cwd(), to || FS.cwd()),
3333
}
3434
});

src/library_noderawfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ addToLibrary({
4040
},
4141
lookupPath(path, opts = {}) {
4242
if (opts.parent) {
43-
path = nodePath.dirname(path);
43+
path = PATH.dirname(path);
4444
}
4545
var st = fs.lstatSync(path);
4646
var mode = NODEFS.getMode(path);

0 commit comments

Comments
 (0)