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), name : as_symbol(sym_type),
value : is("operator", "=") value : is("operator", "=")
? (next(), expression(false, no_in)) ? (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, ? croak("Missing initializer in const declaration") : null,
end : prev() end : prev()
}); });

View File

@@ -41,7 +41,7 @@ do_not_remove_anon_blocks_if_they_have_decls: {
var x; var x;
} }
{ {
const y; const y = 1;
class Zee {}; class Zee {};
} }
} }
@@ -59,7 +59,7 @@ do_not_remove_anon_blocks_if_they_have_decls: {
} }
var x; var x;
{ {
const y; const y = 1;
class Zee {} class Zee {}
} }
} }
@@ -77,12 +77,12 @@ remove_unused_in_global_block: {
input: { input: {
{ {
let x; let x;
const y; const y = 1;
class Zee {}; class Zee {};
var w; var w;
} }
let ex; let ex;
const why; const why = 2;
class Zed {}; class Zed {};
var wut; var wut;
console.log(x, y, Zee); console.log(x, y, Zee);
@@ -90,7 +90,7 @@ remove_unused_in_global_block: {
expect: { expect: {
var w; var w;
let ex; let ex;
const why; const why = 2;
class Zed {}; class Zed {};
var wut; var wut;
console.log(x, y, Zee); console.log(x, y, Zee);

View File

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

View File

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

View File

@@ -408,7 +408,7 @@ describe("bin/uglifyjs", function () {
assert.ok(err); assert.ok(err);
assert.strictEqual(stdout, ""); assert.strictEqual(stdout, "");
assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ 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;", " const a;",
" ^", " ^",
"ERROR: Missing initializer in const declaration" "ERROR: Missing initializer in const declaration"