Hoisted var declaration will cause unexpected simplification with different target
Input code
(function () {
var first = state();
var on = true;
var obj = {
state: state
};
log(first)
log(obj.state());
function state() {
return on ? "ON" : "OFF";
}
})();
Describe the bug
Hoisted var declaration will cause unexpected simplification with different target
Input code
Config
Playground link
https://play.swc.rs/?version=1.3.15&code=H4sIAAAAAAAAA9NIK81LLsnMz1PQ0FSo5uIsSyxSSMssKi5RsFUoLkksSdXQtIaIApXYKpQUlabC%2BElZQAGgFk6wOiuIci7OWqB8Tn66BtgUTQgbqFYPahrIOLidUDGwKUWpJaVFeSBr7BWU%2FP2UFKyAlJubElB9LVetJsgdXACvpGevrgAAAA%3D%3D&config=H4sIAAAAAAAAA22TS5LjIAyG78I625lFDjC7OQNFQDj0GOSSRDquVO7ewk5wnMwOffwSenEzX%2BzN8WaEXOGIlJtB4Lysh0jAZz3e7%2FeDmRwxULvguYi7mqMBnx17SpOYg8ZSJFRBteJoAGkK%2FqVXIyKDOUY3MhxMTiXFuQXymCd9gttZPWqGItx1jgi%2FeY15MCfEETTNd9s6tqkIDECbq8dxdBODvTjqHu01R4mx7FAVCHYinF5oCUkSFg32ZAFcsB4DdJAIvKQLbBKNoZLCmljPZIEBTnUYWvNWJVzcWJ30WHBd2qAvdr8zJhYba%2BE3tMt0RWuRD1WKlkAqlafmC1PZ9eEfgOY5OubiMmyeC486h70y%2FkeVStQhytypTnjLqsCgxdmUYq%2BwZQ0kaesWQageWoV%2BC%2F6Au4I4BbAQo3a7O%2FN3En%2Fegsk8AcZuatdc3Gawmva5T3vaVuAD%2FtGs5HUcD56dnN8Zz%2FmE40eIDHLG8IG1EYLvkHR7r9M7rSWAthnCy0XlZvY11eEL2rF9tWefdSHUxw4jnvr66o%2FMrgx9Ldt3zhhqA7electX%2FW2UJ%2F77uFk8fwARW3AUJAQAAA%3D%3D
Expected behavior
__With the
ES5
target you will getfirst
should be'off'
rather than'on'
Actual behavior
If you set the target to
ES2022
, you will getVersion
1.3.15
Additional context
Not the same problem, but could be related https://github.com/terser/terser/issues/1306