Skip to content

Commit 2c4f894

Browse files
laverdetaduh95
authored andcommitted
doc: module resolution pseudocode corrections
PR-URL: #57080 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
1 parent e8d4a31 commit 2c4f894

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

doc/api/esm.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,12 @@ The resolver can throw the following errors:
861861
> 1. Throw an _Invalid Module Specifier_ error.
862862
> 7. Let _packageSubpath_ be _"."_ concatenated with the substring of
863863
> _packageSpecifier_ from the position at the length of _packageName_.
864-
> 8. If _packageSubpath_ ends in _"/"_, then
865-
> 1. Throw an _Invalid Module Specifier_ error.
866-
> 9. Let _selfUrl_ be the result of
864+
> 8. Let _selfUrl_ be the result of
867865
> **PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
868-
> 10. If _selfUrl_ is not **undefined**, return _selfUrl_.
869-
> 11. While _parentURL_ is not the file system root,
866+
> 9. If _selfUrl_ is not **undefined**, return _selfUrl_.
867+
> 10. While _parentURL_ is not the file system root,
870868
> 1. Let _packageURL_ be the URL resolution of _"node\_modules/"_
871-
> concatenated with _packageSpecifier_, relative to _parentURL_.
869+
> concatenated with _packageName_, relative to _parentURL_.
872870
> 2. Set _parentURL_ to the parent folder URL of _parentURL_.
873871
> 3. If the folder at _packageURL_ does not exist, then
874872
> 1. Continue the next loop iteration.
@@ -882,7 +880,7 @@ The resolver can throw the following errors:
882880
> 1. Return the URL resolution of _main_ in _packageURL_.
883881
> 7. Otherwise,
884882
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
885-
> 12. Throw a _Module Not Found_ error.
883+
> 11. Throw a _Module Not Found_ error.
886884
887885
**PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_)
888886
@@ -900,6 +898,8 @@ The resolver can throw the following errors:
900898
901899
**PACKAGE\_EXPORTS\_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_)
902900
901+
Note: This function is directly invoked by the CommonJS resolution algorithm.
902+
903903
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
904904
> starting with _"."_, throw an _Invalid Package Configuration_ error.
905905
> 2. If _subpath_ is equal to _"."_, then
@@ -923,6 +923,8 @@ The resolver can throw the following errors:
923923
924924
**PACKAGE\_IMPORTS\_RESOLVE**(_specifier_, _parentURL_, _conditions_)
925925
926+
Note: This function is directly invoked by the CommonJS resolution algorithm.
927+
926928
> 1. Assert: _specifier_ begins with _"#"_.
927929
> 2. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
928930
> 1. Throw an _Invalid Module Specifier_ error.
@@ -939,14 +941,16 @@ The resolver can throw the following errors:
939941
**PACKAGE\_IMPORTS\_EXPORTS\_RESOLVE**(_matchKey_, _matchObj_, _packageURL_,
940942
_isImports_, _conditions_)
941943
942-
> 1. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
944+
> 1. If _matchKey_ ends in _"/"_, then
945+
> 1. Throw an _Invalid Module Specifier_ error.
946+
> 2. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
943947
> 1. Let _target_ be the value of _matchObj_\[_matchKey_].
944948
> 2. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
945949
> _target_, **null**, _isImports_, _conditions_).
946-
> 2. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
950+
> 3. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
947951
> single _"\*"_, sorted by the sorting function **PATTERN\_KEY\_COMPARE**
948952
> which orders in descending order of specificity.
949-
> 3. For each key _expansionKey_ in _expansionKeys_, do
953+
> 4. For each key _expansionKey_ in _expansionKeys_, do
950954
> 1. Let _patternBase_ be the substring of _expansionKey_ up to but excluding
951955
> the first _"\*"_ character.
952956
> 2. If _matchKey_ starts with but is not equal to _patternBase_, then
@@ -961,7 +965,7 @@ _isImports_, _conditions_)
961965
> _matchKey_ minus the length of _patternTrailer_.
962966
> 3. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
963967
> _target_, _patternMatch_, _isImports_, _conditions_).
964-
> 4. Return **null**.
968+
> 5. Return **null**.
965969
966970
**PATTERN\_KEY\_COMPARE**(_keyA_, _keyB_)
967971

doc/api/modules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ require(X) from module at path Y
342342
b. STOP
343343
2. If X begins with '/'
344344
a. set Y to the file system root
345-
3. If X begins with './' or '/' or '../'
345+
3. If X is equal to '.', or X begins with './', '/' or '../'
346346
a. LOAD_AS_FILE(Y + X)
347347
b. LOAD_AS_DIRECTORY(Y + X)
348348
c. THROW "not found"

0 commit comments

Comments
 (0)