@angular-devkit/build-optimizer purify marks PURE on namespace for packages built by cli #934
Description
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Area
- [x] devkit
- [ ] schematics
Versions
node 9.10.1
In @angular-devkit/build-optimizer
the Purify transformation marks a namespace as PURE when it's coming from a library built by the cli.
Consider the following file in a library built with the cli :
export function MyFunction() { }
export namespace MyFunction {
export function subFunction() { }
}
After publishing to NPM, the FESM5 bundle will look something like this:
function MyFunction() { }
(function (MyFunction) {
function subFunction() { }
MyFunction.subFunction = subFunction;
})(MyFunction || (MyFunctionn = {}));
export { MyFunction }
If we use this package in an angular application and build to prod the purify loader kicks in and the namespace implementation is treated as PURE:
```js
function MyFunction() { }
/*@__PURE__*/ (function (MyFunction) {
function subFunction() { }
MyFunction.subFunction = subFunction;
})(MyFunction || (MyFunctionn = {}));
export { MyFunction }
Even if MyFunction.subFunction
is used within the application it is removed by uglify the compilation result is that MyFunction
exists but MyFunction.subFunction
does not.
That PURE is added by the getPrefixFunctionsTransformer
transformer which thinks it's a function. I guess that there's not enough information as it deals with JS files and not TS.
If MyFunction
is used it will not get dropped, and since it is user in the next instruction as an input to the IIFE it probably means that the IIFE is used and should not be dropped.
Of course I can mark this file and other with the same structure as sideEffect
in package.json but because it's FESM bundle it will skip the entire package... not just parts of it.
I don't know maybe it's not even an issue, this is hard to grasp.