emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.46k stars 4.21k forks source link

[Bug] class-based helpers throw weird error in strict mode (getDebugName) #19877

Closed NullVoxPopuli closed 2 years ago

NullVoxPopuli commented 2 years ago

🐞 Describe the Bug

Error wasn't expected, but I think phrasing of the error could be improved?

image

πŸ”¬ Minimal Reproduction

  1. define class based helper in my-app/helpers
  2. using ember-template-imports (or strict mode some other way), define this template:

    import MyHelper from 'my-app/helpers/my-helper';
    
    <template>
    {{#let (MyHelper 1 2) as |result|}}
      {{result}}
    {{/let}}
    </template>

πŸ˜• Actual Behavior

image

actual helper is:

import { getOwner } from '@ember/application';
import Helper from '@ember/component/helper';

export default class GetService extends Helper {
  compute([name]: [string]) {
    return getOwner(this).lookup(`service:${name}`);
  }
}

πŸ€” Expected Behavior

primarily, I expected this to work:

import service from 'limber/helpers/service';

<template>
  {{#let (service 'editor') as |context|}}

but a more helpful error would have been preferable, given the situation?

🌍 Environment

βž• Additional Context

Add any other context about the problem here.

NullVoxPopuli commented 2 years ago

Here is the code: https://github.com/emberjs/ember.js/blob/67d465f7603685b20a4dc27833164ceab7003559/packages/%40ember/-internals/glimmer/lib/helper.ts#L195

that matches what i'm seeing in my browser. I though I'd add .class property to my helper to make this getDebugName correct, but then the owner is not passed to the helper (goes down a different instantiation path: https://github.com/emberjs/ember.js/blob/67d465f7603685b20a4dc27833164ceab7003559/packages/%40ember/-internals/glimmer/lib/helper.ts#L165 )

NullVoxPopuli commented 2 years ago

successful reproduction here: https://github.com/ember-template-imports/ember-template-imports/runs/4567719281?check_suite_focus=true