Skip to content

Name mangling in ES modules #394

Closed
Closed

Description

@probins

As browsers are starting to implement module loaders, I've been looking at how well Babili can compress ES modules, and the short answer atm seems to be 'not very well'. AFAICS there's 2 main reasons for this.

  1. it's not mangling top-level names, which it should be able to do within modules, which have their own scope. I see a topLevel option was recently added to minify-mangle-names, but it looks like this was after the latest version was released. So, question: how do I install the latest master specifically for this plugin so I can try it out without waiting for the next release? It looks like it's not as simple as copying the current master source into node_modules.
  2. it's not mangling imported/exported names. Default imports and exports can surely be mangled without problem, so import importedName from ... can become import mm from ..., and export default exportedName export default mm. Similarly, for named imports, I'm thinking that import {importedName} from ... could become import {importedName as mm} ..., and named exports likewise. I've looked through issues/PRs and couldn't find any discussion of this, so I'm assuming this is not done atm because no-one's got around to it yet. Or is there some other issue?

Activity

  1. boopathi commented on Jan 30, 2017

    @boopathi
    Member
    1. There is https://github.com/babel/babili/blob/master/CONTRIBUTING.md on how to build babili. You can simply then npm link and use it.

    2. Yes. This still needs to be implemented.

  2. added
    bug
    on Jan 30, 2017
  3. probins commented on Feb 16, 2017

    @probins
    ContributorAuthor

    I've just got around to installing the latest version, which includes the topLevel option. This fixes item 1 as expected, but it looks like it also fixes the mangling of default import/export, which it presumably also treats as topLevel. So it looks like I have to revise my original comment to: 'it's doing a pretty good job of compressing ES modules if you set topLevel:true'. :-)

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions