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

fix(glimmer-wrapper): move debug normalize in .extend() block #313

Merged

Conversation

buschtoens
Copy link
Contributor

#300 (comment)

This seems to be broken. Resolver#normalize is null even though the following is included in the build:

  if (true) {
    Resolver.prototype.normalize = function (specifier) {
      // This method is called by `Registry#validateInjections` in dev mode.
      // https://github.com/ember-cli/ember-resolver/issues/299
      const [type, name] = specifier.split(':', 2);
      if (name && (type === 'service' || type === 'controller')) {
        return `${type}:${Ember.String.dasherize(name)}`;
      }
      return specifier;
    };
  }

I assume that this is because Ember manually collapses the prototype and normalize: null somehow takes precedence.

What is your suggested solution? Use .reopen({ ... }) or use a ternary in the original .extend({ ... }) block? I'm leaning towards a ternary like:

const Resolver = GlobalsResolver.extend({
  // ...

  normalize: !DEBUG ? null : function(specifier) {
    // This method is called by `Registry#validateInjections` in dev mode.
    // https://github.com/ember-cli/ember-resolver/issues/299
    const [type, name] = specifier.split(':', 2);
    if (name && (type === 'service' || type === 'controller')) {
      return `${type}:${dasherize(name)}`;
    }
    return specifier;
  },

  // ...
});

I assume constant ternaries are also optimized away by ember-cli-uglify / terser?

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing CI due to linting errors, I left an inline comment that might work but I'm also fine with disabling that lint rule inline...

@@ -82,7 +82,15 @@ const Resolver = GlobalsResolver.extend({
this._glimmerResolver = new GlimmerResolver(this.config, this.glimmerModuleRegistry);
},

normalize: null,
normalize: !DEBUG ? null : function(specifier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you hoist this above? Something like:

const normalize = !DEBUG ? null : function normalize(specifier) {
  // ...snip...
};

GlobalsResolver.extend({
  // ...snip...
  normalize,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@rwjblue rwjblue added the bug label Feb 15, 2019
@rwjblue rwjblue merged commit 86c1a9a into ember-cli:master Feb 15, 2019
@buschtoens buschtoens deleted the fix/actually-add-normalize-for-debug branch February 16, 2019 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants