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

Tree shaking of imports? #5

Open
mmis1000 opened this issue Nov 20, 2020 · 1 comment
Open

Tree shaking of imports? #5

mmis1000 opened this issue Nov 20, 2020 · 1 comment

Comments

@mmis1000
Copy link

The semantic of x::ext:name( seems incompatible with tree shaking after transpile if the the import and x::ext:name( got trasnpiled individually.

import * as ext from 'someOtherModule'
ExtInvoke(ext, 'name', x, args)

There is no way for any tool chain after it to realize that only ext.name is used instead of the whole ext.

Although the transpiler is still possible to do it if they are transformed at same time
(by just assume ext[SymbolExtension] do not exist because it is a module and emit different output)

@hax
Copy link
Member

hax commented Nov 20, 2020

Good question!

Actually tree shaking is one of the important use cases of this proposal.

First, ad-hoc extension methods and accessors are very friendly to tree shaking, it could solve size issue of many libraries (could be splitted into core and some extensions).

There could be a import ::{x, y, z} from 'module' syntax to import extension methods and declare x, y, z as ad-hoc extension methods/accessors in current module. This syntax is not included in the README just because it's not the core part of this proposal and could be separate to a follow-on proposal. I will improve the document to cover that soon.

Second, for x::ext:name, the behavior is delegated by ext. I would expect there will be three types in practice:

  • customized extension: by definition it can't and no need to apply tree shaking;
  • fine-grained static extension: the methods/accessors in it are highly related and sharing code, which means tree shaking can do little for it;
  • coarse-grained static extension: just a namespace, normally is re-exports of many fine-grained static extension. As u said, we need tools do static analysis and transform it to fine-grained static extensions. It would look like babel-plugin-lodash, but in a more general way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants