Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,61 @@ export class DebuggerSuite extends RenderTest {
this.assertStableNodes();
}

@test({ kind: 'templateOnly' })
'debugger in template-only component logs template-only message'() {
let originalInfo = console.info;
let messages: string[] = [];

console.info = (...args: unknown[]) => {
messages.push(args.join(' '));
};

try {
resetDebuggerCallback();

this.registerComponent('TemplateOnly', 'DebugTest', '{{debugger}}');

this.render('<DebugTest @foo="bar" />', {});

this.assert.deepEqual(messages, [
"Use `get(<path>)` to debug this template. For named arguments, use `get('@argName')`.",
]);
} finally {
console.info = originalInfo;
resetDebuggerCallback();
}
}

@test
'debugger in class-backed component logs context message with named argument hint'() {
let originalInfo = console.info;
let messages: string[] = [];

console.info = (...args: unknown[]) => {
messages.push(args.join(' '));
};

try {
resetDebuggerCallback();

this.registerComponent(
'Glimmer',
'DebugTest',
'{{debugger}}',
class extends GlimmerishComponent {}
);

this.render('<DebugTest @foo="bar" />', {});

this.assert.deepEqual(messages, [
"Use `context`, and `get(<path>)` to debug this template. For named arguments, use `get('@argName')`.",
]);
} finally {
console.info = originalInfo;
resetDebuggerCallback();
}
}

@test
'can get locals'() {
let expectedContext = {
Expand Down
19 changes: 14 additions & 5 deletions packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ export type DebugGet = (path: string) => unknown;
export type DebugCallback = (context: unknown, get: DebugGet) => void;

function debugCallback(context: unknown, get: DebugGet): void {
// eslint-disable-next-line no-console
console.info('Use `context`, and `get(<path>)` to debug this template.');

// for example...
context === get('this');
if (context !== null && context !== undefined) {
// eslint-disable-next-line no-console
console.info(
"Use `context`, and `get(<path>)` to debug this template. For named arguments, use `get('@argName')`."
);

// for example...
context === get('this');
} else {
// eslint-disable-next-line no-console
console.info(
"Use `get(<path>)` to debug this template. For named arguments, use `get('@argName')`."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these instructions also valid for class-backed components?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - yes, get('@argName') is valid for class-backed components too.

The distinction here is only whether context is available. I updated the class-backed message to include the named-argument hint as well, and added test coverage for that case.

);
}

// eslint-disable-next-line no-debugger
debugger;
Expand Down
Loading