Skip to content

Commit

Permalink
fix(parser): change diagnostic to "modifier cannot be used here" (#3853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 23, 2024
1 parent 97d59fc commit 13754cb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 68 deletions.
7 changes: 2 additions & 5 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ pub fn jsx_element_no_match(span0: Span, span1: Span, name: &str) -> OxcDiagnost
}

#[cold]
pub fn modifiers_cannot_appear(span: Span, name: &str) -> OxcDiagnostic {
OxcDiagnostic::error(format!(
"TS1044: '{name}' modifier cannot appear on a module or namespace element."
))
.with_label(span)
pub fn modifier_cannot_be_used_here(span: Span, name: &str) -> OxcDiagnostic {
OxcDiagnostic::error(format!("'{name}' modifier cannot be used here.")).with_label(span)
}
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if !matches!(modifier.kind, ModifierKind::Declare | ModifierKind::Abstract) {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if modifier.kind != ModifierKind::Declare {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if !matches!(modifier.kind, ModifierKind::Declare | ModifierKind::Async) {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if !matches!(modifier.kind, ModifierKind::Declare | ModifierKind::Const) {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if modifier.kind != ModifierKind::Declare {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if modifier.kind != ModifierKind::Declare {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'a> ParserImpl<'a> {

for modifier in modifiers.iter() {
if modifier.kind != ModifierKind::Declare {
self.error(diagnostics::modifiers_cannot_appear(
self.error(diagnostics::modifier_cannot_be_used_here(
modifier.span,
modifier.kind.as_str(),
));
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10137,7 +10137,7 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
· ──
╰────

× TS1044: 'abstract' modifier cannot appear on a module or namespace element.
× 'abstract' modifier cannot be used here.
╭─[typescript/interface/abstract/input.ts:1:1]
1 │ abstract interface Foo {
· ────────
Expand All @@ -10152,7 +10152,7 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
╰────
help: Try insert a semicolon here

× TS1044: 'abstract' modifier cannot appear on a module or namespace element.
× 'abstract' modifier cannot be used here.
╭─[typescript/interface/export-abstract-interface/input.ts:1:8]
1 │ export abstract interface I {
· ────────
Expand Down
Loading

0 comments on commit 13754cb

Please sign in to comment.