Skip to content

Commit 0e73be3

Browse files
authored
Merge pull request webpack#7051 from webpack/feature/type-utils-identifier
refactor(types): add type comments for util/identifier
2 parents ec6c9e8 + f7790f8 commit 0e73be3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/util/identifier.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
"use strict";
22
const path = require("path");
33

4+
/**
5+
* @typedef {Object} MakeRelativePathsCache
6+
* @property {Map<string, Map<string, string>>=} relativePaths
7+
*/
8+
9+
/**
10+
*
11+
* @param {string} maybeAbsolutePath path to check
12+
* @return {boolean} returns true if path is "Absolute Path"-like
13+
*/
414
const looksLikeAbsolutePath = maybeAbsolutePath => {
515
return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
616
};
717

18+
/**
19+
*
20+
* @param {string} p path to normalize
21+
* @return {string} normalized version of path
22+
*/
823
const normalizePathSeparator = p => p.replace(/\\/g, "/");
924

25+
/**
26+
*
27+
* @param {string} context context for relative path
28+
* @param {string} identifier identifier for path
29+
* @return {string} a converted relative path
30+
*/
1031
const _makePathsRelative = (context, identifier) => {
1132
return identifier
1233
.split(/([|! ])/)
@@ -19,6 +40,13 @@ const _makePathsRelative = (context, identifier) => {
1940
.join("");
2041
};
2142

43+
/**
44+
*
45+
* @param {string} context context used to create relative path
46+
* @param {string} identifier identifier used to create relative path
47+
* @param {MakeRelativePathsCache=} cache the cache object being set
48+
* @return {string} the returned relative path
49+
*/
2250
exports.makePathsRelative = (context, identifier, cache) => {
2351
if (!cache) return _makePathsRelative(context, identifier);
2452

0 commit comments

Comments
 (0)