Skip to content

Commit 3aed284

Browse files
laverdetRafaelGSS
authored andcommitted
doc: module resolution pseudocode corrections
PR-URL: #57080 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
1 parent b390cd5 commit 3aed284

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

doc/api/esm.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,12 @@ The resolver can throw the following errors:
899899
> 1. Throw an _Invalid Module Specifier_ error.
900900
> 7. Let _packageSubpath_ be _"."_ concatenated with the substring of
901901
> _packageSpecifier_ from the position at the length of _packageName_.
902-
> 8. If _packageSubpath_ ends in _"/"_, then
903-
> 1. Throw an _Invalid Module Specifier_ error.
904-
> 9. Let _selfUrl_ be the result of
902+
> 8. Let _selfUrl_ be the result of
905903
> **PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
906-
> 10. If _selfUrl_ is not **undefined**, return _selfUrl_.
907-
> 11. While _parentURL_ is not the file system root,
904+
> 9. If _selfUrl_ is not **undefined**, return _selfUrl_.
905+
> 10. While _parentURL_ is not the file system root,
908906
> 1. Let _packageURL_ be the URL resolution of _"node\_modules/"_
909-
> concatenated with _packageSpecifier_, relative to _parentURL_.
907+
> concatenated with _packageName_, relative to _parentURL_.
910908
> 2. Set _parentURL_ to the parent folder URL of _parentURL_.
911909
> 3. If the folder at _packageURL_ does not exist, then
912910
> 1. Continue the next loop iteration.
@@ -920,7 +918,7 @@ The resolver can throw the following errors:
920918
> 1. Return the URL resolution of _main_ in _packageURL_.
921919
> 7. Otherwise,
922920
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
923-
> 12. Throw a _Module Not Found_ error.
921+
> 11. Throw a _Module Not Found_ error.
924922
925923
**PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_)
926924
@@ -938,6 +936,8 @@ The resolver can throw the following errors:
938936
939937
**PACKAGE\_EXPORTS\_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_)
940938
939+
Note: This function is directly invoked by the CommonJS resolution algorithm.
940+
941941
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
942942
> starting with _"."_, throw an _Invalid Package Configuration_ error.
943943
> 2. If _subpath_ is equal to _"."_, then
@@ -961,6 +961,8 @@ The resolver can throw the following errors:
961961
962962
**PACKAGE\_IMPORTS\_RESOLVE**(_specifier_, _parentURL_, _conditions_)
963963
964+
Note: This function is directly invoked by the CommonJS resolution algorithm.
965+
964966
> 1. Assert: _specifier_ begins with _"#"_.
965967
> 2. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
966968
> 1. Throw an _Invalid Module Specifier_ error.
@@ -977,14 +979,16 @@ The resolver can throw the following errors:
977979
**PACKAGE\_IMPORTS\_EXPORTS\_RESOLVE**(_matchKey_, _matchObj_, _packageURL_,
978980
_isImports_, _conditions_)
979981
980-
> 1. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
982+
> 1. If _matchKey_ ends in _"/"_, then
983+
> 1. Throw an _Invalid Module Specifier_ error.
984+
> 2. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
981985
> 1. Let _target_ be the value of _matchObj_\[_matchKey_].
982986
> 2. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
983987
> _target_, **null**, _isImports_, _conditions_).
984-
> 2. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
988+
> 3. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
985989
> single _"\*"_, sorted by the sorting function **PATTERN\_KEY\_COMPARE**
986990
> which orders in descending order of specificity.
987-
> 3. For each key _expansionKey_ in _expansionKeys_, do
991+
> 4. For each key _expansionKey_ in _expansionKeys_, do
988992
> 1. Let _patternBase_ be the substring of _expansionKey_ up to but excluding
989993
> the first _"\*"_ character.
990994
> 2. If _matchKey_ starts with but is not equal to _patternBase_, then
@@ -999,7 +1003,7 @@ _isImports_, _conditions_)
9991003
> _matchKey_ minus the length of _patternTrailer_.
10001004
> 3. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
10011005
> _target_, _patternMatch_, _isImports_, _conditions_).
1002-
> 4. Return **null**.
1006+
> 5. Return **null**.
10031007
10041008
**PATTERN\_KEY\_COMPARE**(_keyA_, _keyB_)
10051009

doc/api/modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ require(X) from module at path Y
349349
b. STOP
350350
2. If X begins with '/'
351351
a. set Y to the file system root
352-
3. If X begins with './' or '/' or '../'
352+
3. If X is equal to '.', or X begins with './', '/' or '../'
353353
a. LOAD_AS_FILE(Y + X)
354354
b. LOAD_AS_DIRECTORY(Y + X)
355355
c. THROW "not found"

0 commit comments

Comments
 (0)