google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.42k stars 1.16k forks source link

String array access to const index not simplified #1920

Closed krk closed 8 years ago

krk commented 8 years ago

Input:

alert("falseundefined"["10"]);

Output:

alert("falseundefined"["10"]);

Expected:

alert("i");
mashedcode commented 8 years ago

@krk this is unsafe anyway, you should use "falseundefined".charAt(10) for guaranteed browser support IE5-7.

krk commented 8 years ago

It is generated code by http://www.jsfuck.com/ and I was wondering if closure can "unfuck" it. Fuck is related to the Brainfuck language.

MatrixFrog commented 8 years ago

Fun, but probably a non-goal for Closure Compiler.

That said, it might be a fun side project for someone to do. Check out https://github.com/google/closure-compiler/wiki/Writing-Compiler-Pass if interested.

Dominator008 commented 8 years ago

Could potentially be a peephole optimization.

krk commented 2 years ago

ended up writing jsunfuck: https://github.com/krk/jsunfuck