From fb8025b554a52946582e131cfced20d61efd81a6 Mon Sep 17 00:00:00 2001 From: Solo-steven Date: Thu, 20 Oct 2022 01:01:56 +0800 Subject: [PATCH] fix: throw error when using private field in an object (#1011) --- lib/parse.js | 4 +++- test/compress/syntax-errors.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index e247f6f90..884cf779a 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -2442,7 +2442,9 @@ function parse($TEXT, options) { })); continue; } - + if(is("privatename")) { + croak("private fields are not allowed in an object"); + } var name = as_property_name(); var value; diff --git a/test/compress/syntax-errors.js b/test/compress/syntax-errors.js index 87c1e2e0c..219a36a91 100644 --- a/test/compress/syntax-errors.js +++ b/test/compress/syntax-errors.js @@ -332,3 +332,18 @@ big_int_scientific_format: { col: 8 }) } + +invalid_privatename_in_object: { + input: ` + const myObject = { + foo: 'bar', + #something: 5, + } + ` + expect_error: ({ + name: "SyntaxError", + message: "private fields are not allowed in an object", + line: 4, + col: 12 + }) +}