You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this tree-shaker, we may introduce some other annotations for a better tree-shake result. The following are some possible annotations to add:
#__FINITE_RECURSION__
Used before a function declaration/expression, indicating this function's recursed call can be analyzed in finite steps.
/* #__FINITE_RECURSION__ */functionrender(comp){if(comp.alwaysFalsy){// Treeshakable with the help of the annotation}constresult=renderSelf(comp)// A recursed call. Considered as an unknown call without the annotation.result.children=comp.children.map(render)}
#__ALWAYS_PLAIN__
Used before an object expression, indicating this object will always be used like a Map: no getters/setters, no special properties.
constsomeMap=/* #__ALWAYS_PLAIN__ */{}unknownFunction(someMap)someMap[key]// This property access is considered side-effectlesssomeMap.x=1// Can be removed if `someMap` is no longer used
#__FORGET__
Forget a property of an object, indicating it will no longer be used. If the property is not used before this annotation, it'll be removed.
constapp={mount(root,options){/* #__FORGET__ */app.mountif(options.ssr){// ... Really long code, now can be removed,// because the `mount` method has been forgotten before calling `unknownFunction`.// Otherwise, `unknownFunction` may pass any arguments to `app.mount`, which de-optimizes this branch.}},// ...}app.mount('#app',{ssr: false})unknownFunction(app)
#__SAFE_MANGLING__
The names of the properties of the object are meaningless. Currently, this tree-shaker doesn't have the ability to mangle object properties yet, but it will.
#__PURE__
and#__NO_SIDE_EFFECT__
have been widely supported. Their spec can be found at https://github.com/javascript-compiler-hints/compiler-notations-spec/.For this tree-shaker, we may introduce some other annotations for a better tree-shake result. The following are some possible annotations to add:
#__FINITE_RECURSION__
Used before a function declaration/expression, indicating this function's recursed call can be analyzed in finite steps.
#__ALWAYS_PLAIN__
Used before an object expression, indicating this object will always be used like a
Map
: no getters/setters, no special properties.#__FORGET__
Forget a property of an object, indicating it will no longer be used. If the property is not used before this annotation, it'll be removed.
#__SAFE_MANGLING__
The names of the properties of the object are meaningless. Currently, this tree-shaker doesn't have the ability to mangle object properties yet, but it will.
...
Please comment your ideas~
The text was updated successfully, but these errors were encountered: