Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Recommending export {} maybe not so good? #7

Description

@ljharb

The text says "should specify an export {} to make their intentions clear and avoid accidental parse errors while removing import statements.". If you're simply saying "should specify any export" then I agree with that - but I'd think exporting a mutable object is a dangerous casual API to create, whereas export default null or export default undefined is safe.

Could we change the text to recommend export default undefined?

Activity

  1. jmm commented on Jun 17, 2016

    @jmm
    Contributor

    @ljharb That was my suggestion (originally in nodejs/node-eps#3 (comment)). It's not supposed to export an object (or anything). From what I've been able to tell, export {} (export ExportClause with no ExportsList) is a no-op syntax that's valid per the spec (though I'm not sure why it was included). If that's correct it's a way to include an export declaration that satisfies the requirement proposed here without actually exporting anything.

    See also #3.

  2. ljharb commented on Jun 17, 2016

    @ljharb
    MemberAuthor

    aha, good call. You're right that export {} is just zero named exports, so that's actually better than exporting a default of null/undefined.

  3. jmm commented on Jun 17, 2016

    @jmm
    Contributor

    Cool, thanks for confirming. Since it may not be clear to a lot of people what that syntax represents, maybe it'd make sense to include a quick note explaining it.

    On a side note, what kind of danger did you have in mind if an object had been exported? In general modules are often going to export mutable objects, right? E.g. export default function () {}.

  4. ljharb commented on Jun 17, 2016

    @ljharb
    MemberAuthor

    If an object was exported, people might rely on being able to set and get properties on it, and even if that's common, it's still an uninintended API contract.

  5. jmm commented on Jun 17, 2016

    @jmm
    Contributor

    Thanks. While it should never be advertised and people shouldn't rely on unadvertised stuff that just happens to be there, I see what you mean. That actually highlights what we all agree on -- that it's better to not export anything at all, as that could be similarly abused (just by importing it when it's never intended for external use and is therefore subject to change at any time).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions