have parser trap const declaration without value (#2756)

fixes #2751
This commit is contained in:
kzc
2018-01-09 23:31:46 -05:00
committed by Alex Lam S.L
parent 1f3f8f25eb
commit 137cb73d1f
5 changed files with 8 additions and 13 deletions

View File

@@ -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()
});

View File

@@ -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);

View File

@@ -215,7 +215,7 @@ unused_block_decls: {
input: {
function foo() {
{
const x;
const x = 1;
}
{
let y;

View File

@@ -1,8 +1,3 @@
function f() {
const a;
}
function g() {
"use strict";
const a;
}

View File

@@ -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"