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

add debug alias for let #1631

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions bin/run-tests.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

// @ts-check

import child from 'child_process';
import { resolve } from 'path';
import PCR from 'puppeteer-chromium-resolver';
import { fileURLToPath } from 'url';


const { puppeteer, executablePath } = await PCR({});

const __root = fileURLToPath(new URL('..', import.meta.url));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,20 @@ class DynamicStrictModeTest extends RenderTest {
}, /Expected a dynamic component definition, but received an object or function that did not have a component manager associated with it. The dynamic invocation was `<this.Foo>` or `\{\{this.Foo\}\}`, and the incorrect definition is the value at the path `this.Foo`, which was:/u);
}

@test
'Throws an error with correct debug label if a non-component is used as a component'() {
const Foo = defineSimpleHelper(() => 'Hello, world!');
const Bar = defineComponent({}, '{{#let this.Foo as |foo|}}<foo/>{{/let}}', {
definition: class extends GlimmerishComponent {
Foo = Foo;
},
});

this.assert.throws(() => {
this.renderComponent(Bar);
}, /Expected a dynamic component definition, but received an object or function that did not have a component manager associated with it. The dynamic invocation was `<foo>` or `\{\{foo\}\}`, and the incorrect definition is the value at the path `foo`, which was:/u);
}

@test
'Can pass helper as argument and invoke dynamically'() {
const plusOne = defineSimpleHelper(() => 'Hello, world!');
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/reference/lib/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function createConstRef<T>(value: T, debugLabel: false | string): Referen
ref.tag = CONSTANT_TAG;

if (import.meta.env.DEV) {
ref.debugLabel = debugLabel as string;
ref.debugLabel = (debugLabel as string) || String(value);
}

return ref;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import { getInternalHelperManager } from '@glimmer/manager';
import {
childRefFor,
createComputeRef,
createDebugAliasRef,
FALSE_REFERENCE,
TRUE_REFERENCE,
UNDEFINED_REFERENCE,
valueForRef,
} from '@glimmer/reference';
import { assert, assign, debugToString, decodeHandle, isObject } from '@glimmer/util';
import { $v0, CurriedTypes, Op } from '@glimmer/vm';
import { $s0, $v0, CurriedTypes, Op } from '@glimmer/vm';

import { isCurriedType, resolveCurriedValue } from '../../curried-value';
import { APPEND_OPCODES } from '../../opcodes';
Expand Down Expand Up @@ -170,6 +171,12 @@ APPEND_OPCODES.add(Op.GetVariable, (vm, { op1: symbol }) => {

APPEND_OPCODES.add(Op.SetVariable, (vm, { op1: symbol }) => {
let expr = check(vm.stack.pop(), CheckReference);
if (import.meta.env.DEV) {
let state = vm.fetchValue($s0);
let symbols = (state as any)?.table?.symbols;
let sym = symbol === 0 ? 'this' : symbols?.[symbol - 1];
expr = createDebugAliasRef!(sym, expr);
}
vm.scope().bindSymbol(symbol, expr);
});

Expand Down
6 changes: 5 additions & 1 deletion packages/@glimmer/syntax/test/plugin-node-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ test('deprecated program visitor', (assert) => {
return {
name: 'plugin',
visitor: {
Program(node: AST.Program) {
Template(node: AST.Template) {
assert.step(node.type);
},

BlockStatement(node: AST.BlockStatement) {
assert.step(node.type);
},

Block(node: AST.Block) {
assert.step(node.type);
},
},
};
};
Expand Down
Loading