From f8ce3f3f28b7c79333768c7d2c4ef21bf142e1e3 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 15 Oct 2024 14:27:28 +0200 Subject: [PATCH] add debug alias for let --- bin/run-tests.mjs | 2 -- .../integration-tests/test/strict-mode-test.ts | 14 ++++++++++++++ packages/@glimmer/reference/lib/reference.ts | 2 +- .../runtime/lib/compiled/opcodes/expressions.ts | 9 ++++++++- packages/@glimmer/syntax/test/plugin-node-test.ts | 6 +++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bin/run-tests.mjs b/bin/run-tests.mjs index e207ad8a0..e079aa83e 100644 --- a/bin/run-tests.mjs +++ b/bin/run-tests.mjs @@ -1,4 +1,3 @@ - // @ts-check import child from 'child_process'; @@ -6,7 +5,6 @@ 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)); diff --git a/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts b/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts index 940428bbd..8ea8a0178 100644 --- a/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/strict-mode-test.ts @@ -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 `` 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|}}{{/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 `` 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!'); diff --git a/packages/@glimmer/reference/lib/reference.ts b/packages/@glimmer/reference/lib/reference.ts index 42c56b269..b006a37ae 100644 --- a/packages/@glimmer/reference/lib/reference.ts +++ b/packages/@glimmer/reference/lib/reference.ts @@ -82,7 +82,7 @@ export function createConstRef(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; diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts index 2fa7af747..36ab6cabf 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts @@ -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'; @@ -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); }); diff --git a/packages/@glimmer/syntax/test/plugin-node-test.ts b/packages/@glimmer/syntax/test/plugin-node-test.ts index e4cf8f7fc..19d238b0e 100644 --- a/packages/@glimmer/syntax/test/plugin-node-test.ts +++ b/packages/@glimmer/syntax/test/plugin-node-test.ts @@ -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); + }, }, }; };