You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Function declaration in a block conflicts with global const declaration #1043
Version (complete output of terser -V or specific git commit)
terser 4.8.0
Complete CLI command or minify() options used ./node_modules/.bin/terser asd.js --mangle --compress
terser input
if(true){
function asd(){}
}
const asd = 123;
terser output or error
Parse error at asd.js:8,6
const asd = 123;
^
ERROR: "asd" is redeclared
at js_error (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/parse.js:369:11)
at On.visit (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/scope.js:328:17)
at On._visit (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:1509:24)
at AST_SymbolConst._walk (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:121:24)
at AST_VarDef.call (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:809:23)
at On._visit (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:1513:21)
at AST_VarDef._walk (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:808:24)
at AST_Const.call (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:779:32)
at On._visit (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:1513:21)
at AST_Const._walk (/home/wutll/home/git/rui/main/server/node_modules/terser/lib/ast.js:776:24)
Expected result
The code works, because JS hoisting is not the same thing as a declaration, there is no redeclaration. Terser works fine when the const asd is above the if-block.
Maybe there is an option for this, but I think this should work out of the box by default...
Btw I am aware that this isn't nice code, but this is something dropping out of rollup.
changed the title [-]Function Declaration in a block conflicts with global const. [/-][+]Function declaration in a block conflicts with global const declaration[/+]on Aug 9, 2021
This shouldn't be a parse error though. js_error is called in lib/scope. That error message is a bit misleading though so it should probably be tackled as well.
Activity
[-]Function Declaration in a block conflicts with global const. [/-][+]Function declaration in a block conflicts with global const declaration[/+]jridgewell commentedon Sep 19, 2021
Seems to be a parser issue? If I add a
"use strict"directive it works correctly, but without it errors.fabiosantoscode commentedon Sep 25, 2021
The intersection of declaring a function decl in a block, and strict/nonstrict mode, is really weird.
https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-block-level-function-declarations-web-legacy-compatibility-semantics
This shouldn't be a parse error though.
js_erroris called in lib/scope. That error message is a bit misleading though so it should probably be tackled as well.lal12 commentedon Sep 26, 2021
I think in my original use case I also had the error with
"use strict";, but I will try to find out if that really was the case.when 'module' is enabled, assume strict mode when figuring out scopes. …