Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(semantic): syntax error for delete object?.#a #7636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/oxc_semantic/src/checker/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ fn delete_of_unqualified(span: Span) -> OxcDiagnostic {
}

fn delete_private_field(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Private fields can not be deleted").with_label(span)
OxcDiagnostic::error("The operand of a 'delete' operator cannot be a private identifier.")
.with_label(span)
}

pub fn check_unary_expression<'a>(
Expand All @@ -1016,6 +1017,11 @@ pub fn check_unary_expression<'a>(
Expression::PrivateFieldExpression(expr) => {
ctx.error(delete_private_field(expr.span));
}
Expression::ChainExpression(chain_expr) => {
if let ChainElement::PrivateFieldExpression(e) = &chain_expr.expression {
ctx.error(delete_private_field(e.field.span));
}
}
_ => {}
}
}
Expand Down
13 changes: 10 additions & 3 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 54a8389f
parser_babel Summary:
AST Parsed : 2205/2218 (99.41%)
Positive Passed: 2190/2218 (98.74%)
Negative Passed: 1510/1634 (92.41%)
Negative Passed: 1511/1634 (92.47%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.1-sloppy-labeled-functions-if-body/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-if/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js
Expand All @@ -28,7 +28,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread-nested/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/no-pattern-in-rest/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/no-pattern-in-rest-with-ts/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-properties/failure-delete-optional-private-property/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/super-inside-function/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/yield-in-class-property-in-generator/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-static-block/invalid-decorators/input.js
Expand Down Expand Up @@ -7869,7 +7868,15 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
4 │ }
╰────

× Private fields can not be deleted
× The operand of a 'delete' operator cannot be a private identifier.
╭─[babel/packages/babel-parser/test/fixtures/es2022/class-private-properties/failure-delete-optional-private-property/input.js:4:18]
3 │ constructor() {
4 │ delete this?.#x;
· ──
5 │ }
╰────

× The operand of a 'delete' operator cannot be a private identifier.
╭─[babel/packages/babel-parser/test/fixtures/es2022/class-private-properties/failure-delete-private-property/input.js:4:12]
3 │ constructor() {
4 │ delete this.#x;
Expand Down
Loading
Loading