google / google/closure-compiler

`String.prototype.repeat` and `String.prototype.at` can't be proved to have no side effect

Open
#4,018 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Consider the snippet
```javascript
/** @const {string} */
const Str1 = "a".repeat(10);

/** @const {string} */
const Str2 = "a".padEnd(10, "a");

/** @const {string} */
const Str3 = "a".at(0);

/** @const {string} */
const Str4 = "a".padStart(10, "a");
```
When compiled with `20221102.0.1` using
```shell
yarn google-closure-compiler -W VERBOSE -O ADVANCED \
--emit_use_strict \
--language_in ECMASCRIPT_NEXT \
--module_resolution NODE \
--assume_function_wrapper \
--dependency_mode PRUNE \
--entry_point a.js \
--js a.js
```
we get
```javascript
'use strict';"a".repeat(10);"a".at(0);
```
Namely, the `repeat` and `at` are not eliminated despite being marked as `@nosideeffects`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.