From df4e7df14258bc2b08e731a085813578d3d8b0b5 Mon Sep 17 00:00:00 2001 From: legendecas Date: Tue, 27 Sep 2022 00:55:59 +0800 Subject: [PATCH 1/3] src,lib: retrieve parsed source map url from v8 V8 already parses the source map magic comments. Currently, only scripts and functions expose the parsed source map URLs. It is unnecessary to parse the source map magic comments again when the parsed information is available. --- doc/api/vm.md | 23 ++++ lib/internal/modules/cjs/loader.js | 20 +++- lib/internal/source_map/source_map_cache.js | 31 ++++-- lib/internal/vm.js | 113 ++++++++++++++++++++ lib/vm.js | 92 +--------------- src/env_properties.h | 1 + src/node_contextify.cc | 28 +++-- test/parallel/test-bootstrap-modules.js | 1 + 8 files changed, 199 insertions(+), 110 deletions(-) create mode 100644 lib/internal/vm.js diff --git a/doc/api/vm.md b/doc/api/vm.md index f99f4966db82b6..c79f8bc104a579 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -344,6 +344,29 @@ console.log(globalVar); // 1000 ``` +### `script.sourceMapURL` + + + +* {string|undefined} + +When the script is compiled from a source that contains a source map magic +comment, this property will be set to the URL of the source map. + +```js +const vm = require('node:vm'); + +const script = new vm.Script(` +function myFunc() {} +//# sourceMappingURL=sourcemap.json +`); + +console.log(script.sourceMapURL); +// Prints: sourcemap.json +``` + ## Class: `vm.Module`