google / closure-compiler

A JavaScript checker and optimizer.

Home Page:https://developers.google.com/closure/compiler/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

KimlikDAO-bot opened this issue · 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.

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