Skip to content

Commit

Permalink
add debug alias for let
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Oct 18, 2024
1 parent cc46230 commit 8730a06
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
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

0 comments on commit 8730a06

Please sign in to comment.