Skip to content

Commit 22b893e

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 e693396 commit 22b893e

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
@@ -840,14 +840,12 @@ The resolver can throw the following errors:
840840
> 1. Throw an _Invalid Module Specifier_ error.
841841
> 7. Let _packageSubpath_ be _"."_ concatenated with the substring of
842842
> _packageSpecifier_ from the position at the length of _packageName_.
843-
> 8. If _packageSubpath_ ends in _"/"_, then
844-
> 1. Throw an _Invalid Module Specifier_ error.
845-
> 9. Let _selfUrl_ be the result of
843+
> 8. Let _selfUrl_ be the result of
846844
> **PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
847-
> 10. If _selfUrl_ is not **undefined**, return _selfUrl_.
848-
> 11. While _parentURL_ is not the file system root,
845+
> 9. If _selfUrl_ is not **undefined**, return _selfUrl_.
846+
> 10. While _parentURL_ is not the file system root,
849847
> 1. Let _packageURL_ be the URL resolution of _"node\_modules/"_
850-
> concatenated with _packageSpecifier_, relative to _parentURL_.
848+
> concatenated with _packageName_, relative to _parentURL_.
851849
> 2. Set _parentURL_ to the parent folder URL of _parentURL_.
852850
> 3. If the folder at _packageURL_ does not exist, then
853851
> 1. Continue the next loop iteration.
@@ -861,7 +859,7 @@ The resolver can throw the following errors:
861859
> 1. Return the URL resolution of _main_ in _packageURL_.
862860
> 7. Otherwise,
863861
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
864-
> 12. Throw a _Module Not Found_ error.
862+
> 11. Throw a _Module Not Found_ error.
865863
866864
**PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_)
867865
@@ -879,6 +877,8 @@ The resolver can throw the following errors:
879877
880878
**PACKAGE\_EXPORTS\_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_)
881879
880+
Note: This function is directly invoked by the CommonJS resolution algorithm.
881+
882882
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
883883
> starting with _"."_, throw an _Invalid Package Configuration_ error.
884884
> 2. If _subpath_ is equal to _"."_, then
@@ -902,6 +902,8 @@ The resolver can throw the following errors:
902902
903903
**PACKAGE\_IMPORTS\_RESOLVE**(_specifier_, _parentURL_, _conditions_)
904904
905+
Note: This function is directly invoked by the CommonJS resolution algorithm.
906+
905907
> 1. Assert: _specifier_ begins with _"#"_.
906908
> 2. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
907909
> 1. Throw an _Invalid Module Specifier_ error.
@@ -918,14 +920,16 @@ The resolver can throw the following errors:
918920
**PACKAGE\_IMPORTS\_EXPORTS\_RESOLVE**(_matchKey_, _matchObj_, _packageURL_,
919921
_isImports_, _conditions_)
920922
921-
> 1. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
923+
> 1. If _matchKey_ ends in _"/"_, then
924+
> 1. Throw an _Invalid Module Specifier_ error.
925+
> 2. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then
922926
> 1. Let _target_ be the value of _matchObj_\[_matchKey_].
923927
> 2. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
924928
> _target_, **null**, _isImports_, _conditions_).
925-
> 2. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
929+
> 3. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
926930
> single _"\*"_, sorted by the sorting function **PATTERN\_KEY\_COMPARE**
927931
> which orders in descending order of specificity.
928-
> 3. For each key _expansionKey_ in _expansionKeys_, do
932+
> 4. For each key _expansionKey_ in _expansionKeys_, do
929933
> 1. Let _patternBase_ be the substring of _expansionKey_ up to but excluding
930934
> the first _"\*"_ character.
931935
> 2. If _matchKey_ starts with but is not equal to _patternBase_, then
@@ -940,7 +944,7 @@ _isImports_, _conditions_)
940944
> _matchKey_ minus the length of _patternTrailer_.
941945
> 3. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_,
942946
> _target_, _patternMatch_, _isImports_, _conditions_).
943-
> 4. Return **null**.
947+
> 5. Return **null**.
944948
945949
**PATTERN\_KEY\_COMPARE**(_keyA_, _keyB_)
946950

doc/api/modules.md

Lines changed: 1 addition & 1 deletion
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)