diff --git a/lib/parse.js b/lib/parse.js index b32292cb..9387ad9c 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1862,7 +1862,7 @@ function parse($TEXT, options) { name : as_symbol(sym_type), value : is("operator", "=") ? (next(), expression(false, no_in)) - : !no_in && kind === "const" && S.input.has_directive("use strict") + : !no_in && kind === "const" ? croak("Missing initializer in const declaration") : null, end : prev() }); diff --git a/test/compress/block-scope.js b/test/compress/block-scope.js index 6984f62e..f4cac071 100644 --- a/test/compress/block-scope.js +++ b/test/compress/block-scope.js @@ -41,7 +41,7 @@ do_not_remove_anon_blocks_if_they_have_decls: { var x; } { - const y; + const y = 1; class Zee {}; } } @@ -59,7 +59,7 @@ do_not_remove_anon_blocks_if_they_have_decls: { } var x; { - const y; + const y = 1; class Zee {} } } @@ -77,12 +77,12 @@ remove_unused_in_global_block: { input: { { let x; - const y; + const y = 1; class Zee {}; var w; } let ex; - const why; + const why = 2; class Zed {}; var wut; console.log(x, y, Zee); @@ -90,7 +90,7 @@ remove_unused_in_global_block: { expect: { var w; let ex; - const why; + const why = 2; class Zed {}; var wut; console.log(x, y, Zee); diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index e114f050..9101c38f 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -215,7 +215,7 @@ unused_block_decls: { input: { function foo() { { - const x; + const x = 1; } { let y; diff --git a/test/input/invalid/const.js b/test/input/invalid/const.js index 7a2bfd3d..c374c6c2 100644 --- a/test/input/invalid/const.js +++ b/test/input/invalid/const.js @@ -1,8 +1,3 @@ function f() { const a; } - -function g() { - "use strict"; - const a; -} diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 18f71d19..3804d823 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -408,7 +408,7 @@ describe("bin/uglifyjs", function () { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ - "Parse error at test/input/invalid/const.js:7,11", + "Parse error at test/input/invalid/const.js:2,11", " const a;", " ^", "ERROR: Missing initializer in const declaration"