@@ -1033,6 +1033,86 @@ import('fs').then((esmFS) => {
1033
1033
});
1034
1034
` ` `
1035
1035
1036
+ ## Source Map V3 Support
1037
+ <!-- YAML
1038
+ added: REPLACEME
1039
+ -->
1040
+
1041
+ > Stability: 1 - Experimental
1042
+
1043
+ Helpers for for interacting with the source map cache. This cache is
1044
+ populated when source map parsing is enabled and
1045
+ [source map include directives][] are found in a modules' footer.
1046
+
1047
+ To enable source map parsing, Node.js must be run with the flag
1048
+ [` -- enable- source- maps` ][], or with code coverage enabled by setting
1049
+ [` NODE_V8_COVERAGE = dir` ][].
1050
+
1051
+ ` ` ` js
1052
+ const { findSourceMap , SourceMap } = require (' module' );
1053
+ ` ` `
1054
+
1055
+ ### ` module .findSourceMap (path[, error])`
1056
+ <!-- YAML
1057
+ added: REPLACEME
1058
+ -->
1059
+
1060
+ * ` path` {string}
1061
+ * ` error` {Error}
1062
+ * Returns: {module.SourceMap}
1063
+
1064
+ ` path` is the resolved path for the file for which a corresponding source map
1065
+ should be fetched.
1066
+
1067
+ The ` error` instance should be passed as the second parameter to ` findSourceMap`
1068
+ in exceptional flows, e.g., when an overridden
1069
+ [` Error .prepareStackTrace (error, trace)` ][] is invoked. Modules are not added to
1070
+ the module cache until they are successfully loaded, in these cases source maps
1071
+ will be associated with the ` error` instance along with the ` path` .
1072
+
1073
+ ### Class: ` module .SourceMap `
1074
+ <!-- YAML
1075
+ added: REPLACEME
1076
+ -->
1077
+
1078
+ #### ` new SourceMap (payload)`
1079
+
1080
+ * ` payload` {Object}
1081
+
1082
+ Creates a new ` sourceMap` instance.
1083
+
1084
+ ` payload` is an object with keys matching the [Source Map V3 format][]:
1085
+
1086
+ * ` file` : {string}
1087
+ * ` version` : {number}
1088
+ * ` sources` : {string[]}
1089
+ * ` sourcesContent` : {string[]}
1090
+ * ` names` : {string[]}
1091
+ * ` mappings` : {string}
1092
+ * ` sourceRoot` : {string}
1093
+
1094
+ #### ` sourceMap .payload `
1095
+
1096
+ * Returns: {Object}
1097
+
1098
+ Getter for the payload used to construct the [` SourceMap` ][] instance.
1099
+
1100
+ #### ` sourceMap .findEntry (lineNumber, columnNumber)`
1101
+
1102
+ * ` lineNumber` {number}
1103
+ * ` columnNumber` {number}
1104
+ * Returns: {Object}
1105
+
1106
+ Given a line number and column number in the generated source file, returns
1107
+ an object representing the position in the original file. The object returned
1108
+ consists of the following keys:
1109
+
1110
+ * generatedLine: {number}
1111
+ * generatedColumn: {number}
1112
+ * originalSource: {string}
1113
+ * originalLine: {number}
1114
+ * originalColumn: {number}
1115
+
1036
1116
[GLOBAL_FOLDERS]: #modules_loading_from_the_global_folders
1037
1117
[` Error ` ]: errors.html#errors_class_error
1038
1118
[` __dirname ` ]: #modules_dirname
@@ -1046,3 +1126,9 @@ import('fs').then((esmFS) => {
1046
1126
[module resolution]: #modules_all_together
1047
1127
[module wrapper]: #modules_the_module_wrapper
1048
1128
[native addons]: addons.html
1129
+ [source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
1130
+ [` -- enable- source- maps` ]: cli.html#cli_enable_source_maps
1131
+ [` NODE_V8_COVERAGE = dir` ]: cli.html#cli_node_v8_coverage_dir
1132
+ [` Error .prepareStackTrace (error, trace)` ]: https://v8.dev/docs/stack-trace-api#customizing-stack-traces
1133
+ [` SourceMap` ]: modules.html#modules_class_module_sourcemap
1134
+ [Source Map V3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej
0 commit comments