Ensure compatibility with Terser pure_getters
optimization
#2770
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
This change makes Quill source compatible with Terser
pure_getters
optimization.This change is needed for Angular projects, because:
Angular CLI (the most popular tool for building Angular projects) internally uses Webpack with terser-webpack-plugin and unconditionally applies
pure_getters
optimization. You can see all of it in Angular CLI sources: webpack-configs/common.ts.At some point Angular CLI team disabled
pure_getters
optimization (see Production build optimization breaks code angular/angular-cli#11439, fix(@angular-devkit/build-angular): remove pure_getters angular/angular-cli#14187), but then they returned it back for their reasons (Revert "fix(@angular-devkit/build-angular): remove pure_getters" angular/angular-cli#14287).Angular CLI not only compiles project code, but also recompiles the code of external libraries located in
node_modules
, includingquill.min.js
if it happens to be thereHere is the problematic code from Quill:
With
pure_getters
optimization, Terser duly assumes thatdescendant.parentNode
statement is not doing anything and prunes the wholetry..catch
block. You can easily reproduce the problem locally:Of course, the resulting code will throw the Error described in #644 because the guards aren't there.