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

[CLEANUP beta] Inelegant throw for arg-less-paren-less helper #19843

Merged
merged 1 commit into from Nov 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Expand Up @@ -66,6 +66,15 @@ setGlobalContext({
if (DEBUG) {
let { id } = options;

if (id === 'argument-less-helper-paren-less-invocation') {
throw new Error(
`A resolved helper cannot be passed as a named argument as the syntax is ` +
`ambiguously a pass-by-reference or invocation. Use the ` +
`\`{{helper 'foo-helper}}\` helper to pass by reference or explicitly ` +
`invoke the helper with parens: \`{{(fooHelper)}}\`.`
);
}

let override = VM_DEPRECATION_OVERRIDES.filter((o) => o.id === id)[0];

if (!override) throw new Error(`deprecation override for ${id} not found`);
Expand Down Expand Up @@ -98,15 +107,6 @@ const VM_DEPRECATION_OVERRIDES: (DeprecationOptions & {
disabled?: boolean;
message?: string;
})[] = [
{
id: 'argument-less-helper-paren-less-invocation',
url: 'https://deprecations.emberjs.com/v3.x#toc_argument-less-helper-paren-less-invocation',
until: '4.0.0',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
},
{
id: 'setting-on-hash',
until: '4.4.0',
Expand Down
Expand Up @@ -870,25 +870,21 @@ if (DEBUG) {
this.registerHelper('is-string', ([value]) => typeof value === 'string');
}

['@test invoking an argument-less helper without parens in named argument position is deprecated']() {
['@test invoking an argument-less helper without parens in named argument position throws'](
assert
) {
this.registerHelper('foo', () => 'Hello, world!');

expectDeprecation(
assert.throws(
() => this.render('<Bar @content={{foo}} />', { foo: 'Not it!' }),
new RegExp(
/The `foo` helper was used in the `-top-level` template as /.source +
/`@content={{foo}}`\. This is ambigious between wanting the `@content` /.source +
/argument to be the `foo` helper itself, or the result of invoking the /.source +
/`foo` helper \(current behavior\)\. This implicit invocation behavior /.source +
/has been deprecated\./.source
)
`A resolved helper cannot be passed as a named argument as the syntax is ` +
`ambiguously a pass-by-reference or invocation. Use the ` +
`\`{{helper 'foo-helper}}\` helper to pass by reference or explicitly ` +
`invoke the helper with parens: \`{{(fooHelper)}}\`.`
);

this.assertText('[true][Hello, world!]');
this.assertStableRerender();
}

['@test invoking an argument-less helper with parens in named argument position is not deprecated']() {
['@test invoking an argument-less helper with parens in named argument position']() {
this.registerHelper('foo', () => 'Hello, world!');

expectNoDeprecation(() => this.render('<Bar @content={{(foo)}} />', { foo: 'Not it!' }));
Expand All @@ -897,7 +893,7 @@ if (DEBUG) {
this.assertStableRerender();
}

['@test invoking an argument-less helper with quotes in named argument position is not deprecated']() {
['@test invoking an argument-less helper with quotes in named argument position']() {
this.registerHelper('foo', () => 'Hello, world!');

expectNoDeprecation(() => this.render('<Bar @content="{{foo}}" />', { foo: 'Not it!' }));
Expand All @@ -906,7 +902,7 @@ if (DEBUG) {
this.assertStableRerender();
}

['@test passing a local helper in named argument position is not deprecated']() {
['@test passing a local helper in named argument position']() {
let foo = defineSimpleHelper(() => 'Hello, world!');

expectNoDeprecation(() =>
Expand All @@ -922,7 +918,7 @@ if (DEBUG) {
// is trying to call `block.compile()` but `block` is the reference for `this.foo`.
// So the execution stack is probably off-by-one or something.

['@test invoking a local helper with parens in named argument position is not deprecated']() {
['@test invoking a local helper with parens in named argument position']() {
let foo = defineSimpleHelper(() => 'Hello, world!');

expectNoDeprecation(() =>
Expand All @@ -933,9 +929,7 @@ if (DEBUG) {
this.assertStableRerender();
}

// TODO: this one doesn't work yet, and there is a failing test in glimmer-vm

['@skip invoking a helper with quotes in named argument position is not deprecated']() {
['@skip invoking a helper with quotes in named argument position']() {
let foo = defineSimpleHelper(() => 'Hello, world!');

expectNoDeprecation(() =>
Expand Down