google/closure-compiler

Array constructor with length is not eliminated

Open

#4,046 opened on 2023年1月22日

GitHub で見る
 (12 comments) (0 reactions) (0 assignees)Java (1,197 forks)batch import
P4featgood first issuehelp wanted

Repository metrics

Stars
 (7,176 stars)
PR merge metrics
 (平均マージ 3d 4h) (30d で 1 merged PR)

説明

Consider the code:

/** @const {!Array<number>} */
const a = [1];

/** @const {!Array<number>} */
const b = Array(10);
b[0] = 2;

/** @const {!Array<number>} */
const c = [];
c.push(3);

/** @const {!Array<number>} */
const d = Array(10);
d.push(4);

When compiled with

yarn google-closure-compiler -O ADVANCED --js a.js --rewrite_polyfills=false 

we get

Array(10)[0]=2;Array(10).push(4);

Arrays created with the Array(len) constructor are not eliminated.

google-closure-compiler version: v20230103

コントリビューターガイド