Skip to content

Conflict between JS module API and Module Unification #16361

Closed

Description

@tomdale

I discovered an issue while pairing with @wycats that I wanted to write down for future discussion.

We were upgrading an Ember app to use Module Unification that had already adopted the JS module API. The migrator produced invalid code for helpers due to the following conflict:

  1. Helper functions must be wrapped with the helper function exported by @ember/component/helper.
  2. In Module Unification, helpers must be a named export called helper.

The migrator produces code that looks like this:

import { helper } from '@ember/components/helper';
function myHelper() { /* ... */ }
// Error: cannot redeclare `helper`
export const helper = helper(myHelper);

One way to fix this is for the migrator to detect this conflict and rename the import (since the export name cannot be changed), e.g. import { helper as emberHelper } from '@ember/components/helper'. But this is something that everyone will have to type, so we may want to think about this conflict and if there are design changes we want to consider.

Activity

  1. cursedquail commented on Mar 12, 2018

    @cursedquail

    One solution would be to rename helper to createHelper

    So the above example would become:

    import { createHelper } from '@ember/components/helper';
    function myHelper() {}
    export const helper = createHelper(myHelper);

    This can be done in a backwards compatible way by exporting both helper and createHelper from @ember/components/helper, and by mapping both to Ember.Helper.helper in the mappings.

  2. mixonic commented on Mar 13, 2018

    @mixonic
    SponsorMember

    @NLincoln yeah that is a fine approach. We will probably do it in the migrator though:

    import { helper as buildHelper } from '@ember/components/helper';
    function myHelper() {}
    export const helper = buildHelper(myHelper);

    This work should be done in https://github.com/rwjblue/ember-module-migrator

    /cc @rwjblue @bantic

  3. bantic commented on Mar 13, 2018

    @bantic
    Member

    A fix for this is released in the module migrator in v0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions