node/test/parallel/test-vm-source-map-url.js
legendecas 6bdc101c63
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.

PR-URL: https://github.com/nodejs/node/pull/44798
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2022-10-23 22:37:21 +08:00

28 lines
586 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
function checkSourceMapUrl(source, expectedSourceMapURL) {
const script = new vm.Script(source);
assert.strictEqual(script.sourceMapURL, expectedSourceMapURL);
}
// No magic comment
checkSourceMapUrl(`
function myFunc() {}
`, undefined);
// Malformed magic comment
checkSourceMapUrl(`
function myFunc() {}
// sourceMappingURL=sourcemap.json
`, undefined);
// Expected magic comment
checkSourceMapUrl(`
function myFunc() {}
//# sourceMappingURL=sourcemap.json
`, 'sourcemap.json');