Skip to content

Commit

Permalink
fix: throw error when using private field in an object (#1011) (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Solo-steven committed Oct 22, 2022
1 parent 4255fb3 commit 76fdb92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parse.js
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions test/compress/syntax-errors.js
Expand Up @@ -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
})
}

0 comments on commit 76fdb92

Please sign in to comment.