closure-compiler: Generates invalid output with certain properties
The React team encountered an issue with Closure Compiler when compiling the React DOM bundle. It’s quite specific, but it seems to somehow confuse the compiler into re-using a variable that is not safe to use given a given scenario.
https://github.com/facebook/react/pull/18670#issuecomment-623481140
Reproduction steps:
- Git clone React from https://github.com/facebook/react
- Checkout branch from https://github.com/facebook/react/pull/18670#issuecomment-623481140
- Run
yarn install - Run
yarn build --type=NODE_PROD - Run
yarn test-prod-build ReactDOMServerIntegrationTextarea. This will run the Jest test which shows the error.
This error should be seen:
TypeError: Cannot read property 'focusedElem' of null. It seems to be related to JSCompiler_inline_result. Which incorrectly gets re-used from a null value.
Specifically, the change that causes this is when we convert this logic:
function prepareForCommit(containerInfo) {
...
}
...
prepareForCommit(root.containerInfo);
to:
function prepareForCommit(containerInfo) {
...
return null;
}
...
prepareForCommit(root.containerInfo) || null;
These are the flags we use for this particular build:
compilation_level: 'SIMPLE'
language_in: 'ECMASCRIPT_2015'
language_out: 'ECMASCRIPT5_STRICT'
env: 'CUSTOM'
warning_level: 'QUIET'
apply_input_source_maps: false
use_types_for_optimization: false
process_common_js_modules: false
rewrite_polyfills: false
inject_libraries: false
assume_function_wrapper: true
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 29 (26 by maintainers)
Ok, great, thanks for catching that!
Then the actual repro steps are:
And that does give the expected error, namely (several) failed tests with: