fix(ivy): make defineComponent tree shakable by Closure Compiler (#26425)

PR Close #26425
This commit is contained in:
Miško Hevery
2018-10-12 15:49:42 -07:00
parent 398db3e9f0
commit 817821e553
8 changed files with 74 additions and 31 deletions

View File

@ -96,3 +96,16 @@ export function stringify(token: any): string {
const newLineIndex = res.indexOf('\n');
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
}
/**
* Convince closure compiler that the wrapped function has no side-effects.
*
* Closure compiler always assumes that `toString` has no side-effects. We use this quirk to
* allow us to execute a function but have closure compiler mark the call as no-side-effects.
* It is important that the return value for the `noSideEffects` function be assigned
* to something which is retained otherwise the call to `noSideEffects` will be removed by closure
* compiler.
*/
export function noSideEffects(fn: () => void): string {
return '' + {toString: fn};
}