closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

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

Open KimlikDAO-bot opened this issue 3 years ago • 1 comments

Consider the snippet

/** @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

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

'use strict';"a".repeat(10);"a".at(0);

Namely, the repeat and at are not eliminated despite being marked as @nosideeffects.

KimlikDAO-bot avatar Dec 07 '22 23:12 KimlikDAO-bot

Looks like the polyfills are interfering with the analysis of the methods.

concavelenz avatar Dec 09 '22 19:12 concavelenz