google / google/closure-compiler
`TypedArray` constructors are missing `@nosideeffects`
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Unused `TypedArray` global variables are not eliminated. Consider the example
```javascript
// a.js
/** @const {!Uint8Array} */
const Arr = Uint8Array.from([1, 2, 3]);
/** @const {string} */
const Str = "string";
console.log("a.js");
```
When compiled with Google Closure Compiler `20221102.0.1`
```shell
yarn google-closure-compiler -W VERBOSE -O ADVANCED \
--emit_use_strict \
--module_resolution NODE \
--assume_function_wrapper \
--dependency_mode PRUNE \
--entry_point a.js \
--js a.js
> 'use strict';Uint8Array.from([1,2,3]);console.log("a.js");
```
The compiler is able to eliminate the string constant `Str`, but not the typed array `Arr`. Indeed, the constructor definition [here](https://github.com/google/closure-compiler/blob/f9e7049f1ea798f113413e60bc5346b7d43b8b63/externs/es6.js#L778) does not have the `@nosideeffects` annotation.
Contributor guide
Assessment
This issue has not been assessed yet.