Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: add sourceURL magic comment hinting generated source #54402

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/internal/modules/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ function stripTypeScriptTypes(source, filename) {
const base64SourceMap = Buffer.from(map).toString('base64');
return `${code}\n\n//# sourceMappingURL=data:application/json;base64,${base64SourceMap}`;
}
return code;
// Source map is not necessary in strip-only mode. However, to map the source
// file in debuggers to the original TypeScript source, add a sourceURL magic
// comment to hint that it is a generated source.
return `${code}\n\n//# sourceURL=${filename}`;
}

function isUnderNodeModules(filename) {
Expand Down
8 changes: 8 additions & 0 deletions test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ class InspectorSession {
`break on ${url}:${line}`);
}

waitForPauseOnStart() {
return this
.waitForNotification(
(notification) =>
notification.method === 'Debugger.paused' && notification.params.reason === 'Break on start',
'break on start');
}

pausedDetails() {
return this._pausedDetails;
}
Expand Down
43 changes: 43 additions & 0 deletions test/parallel/test-inspector-strip-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
common.skipIfInspectorDisabled();
if (!process.config.variables.node_use_amaro) common.skip('Requires Amaro');

const { NodeInstance } = require('../common/inspector-helper.js');
const fixtures = require('../common/fixtures');
const assert = require('assert');

const scriptPath = fixtures.path('typescript/ts/test-typescript.ts');

async function runTest() {
const child = new NodeInstance(
['--inspect-brk=0', '--experimental-strip-types'],
undefined,
scriptPath);

const session = await child.connectInspectorSession();

const commands = [
{ 'method': 'Debugger.enable' },
{ 'method': 'Runtime.enable' },
{ 'method': 'Runtime.runIfWaitingForDebugger' },
];

await session.send(commands);

const scriptParsed = await session.waitForNotification((notification) => {
if (notification.method !== 'Debugger.scriptParsed') return false;

return notification.params.url === scriptPath;
});
// Verify that the script has a sourceURL, hinting that it is a generated source.
assert(scriptParsed.params.hasSourceURL);

await session.waitForPauseOnStart();
await session.runToCompletion();

assert.strictEqual((await child.expectShutdown()).exitCode, 0);
}

runTest().then(common.mustCall());
Loading