Skip to content
Closed
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
31 changes: 14 additions & 17 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ pub fn import_requires_a_specifier(span: Span) -> OxcDiagnostic {

#[cold]
pub fn modifier_cannot_be_used_here(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
OxcDiagnostic::error(format!("'{}' modifier cannot be used here.", modifier.kind))
Expand All @@ -855,7 +855,7 @@ pub fn modifier_cannot_be_used_here(

#[cold]
pub fn modifier_only_on_property_declaration_or_index_signature(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error(
Expand All @@ -870,15 +870,15 @@ pub fn modifier_only_on_property_declaration_or_index_signature(
}

#[cold]
pub fn accessibility_modifier_already_seen(modifier: &Modifier) -> OxcDiagnostic {
pub fn accessibility_modifier_already_seen(modifier: Modifier) -> OxcDiagnostic {
ts_error("1028", "Accessibility modifier already seen.")
.with_label(modifier.span())
.with_help("Remove the duplicate modifier.")
}

#[cold]
pub fn modifier_must_precede_other_modifier(
modifier: &Modifier,
modifier: Modifier,
other_modifier: ModifierKind,
) -> OxcDiagnostic {
ts_error(
Expand All @@ -889,14 +889,14 @@ pub fn modifier_must_precede_other_modifier(
}

#[cold]
pub fn modifier_already_seen(modifier: &Modifier) -> OxcDiagnostic {
pub fn modifier_already_seen(modifier: Modifier) -> OxcDiagnostic {
ts_error("1030", format!("'{}' modifier already seen.", modifier.kind))
.with_label(modifier.span())
.with_help("Remove the duplicate modifier.")
}

pub fn cannot_appear_on_class_elements(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error(
Expand All @@ -908,7 +908,7 @@ pub fn cannot_appear_on_class_elements(
}

pub fn cannot_appear_on_a_type_member(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("1070", format!("'{}' modifier cannot appear on a type member.", modifier.kind))
Expand All @@ -918,7 +918,7 @@ pub fn cannot_appear_on_a_type_member(

#[cold]
pub fn cannot_appear_on_a_type_parameter(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("1273", format!("'{}' modifier cannot be used on a type parameter.", modifier.kind))
Expand All @@ -941,7 +941,7 @@ pub fn can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias(
}

pub fn cannot_appear_on_a_parameter(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("1090", format!("'{}' modifier cannot appear on a parameter.", modifier.kind))
Expand All @@ -956,15 +956,15 @@ pub fn parameter_property_cannot_be_binding_pattern(span: Span) -> OxcDiagnostic
}

pub fn cannot_appear_on_an_index_signature(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("1071", format!("'{}' modifier cannot appear on an index signature.", modifier.kind))
.with_label(modifier.span())
.with_allowed_modifier_help(allowed)
}

pub fn accessor_modifier(modifier: &Modifier, allowed: Option<ModifierKinds>) -> OxcDiagnostic {
pub fn accessor_modifier(modifier: Modifier, allowed: Option<ModifierKinds>) -> OxcDiagnostic {
ts_error(
"1243",
format!("'accessor' modifier cannot be used with '{}' modifier.", modifier.kind),
Expand All @@ -981,7 +981,7 @@ pub fn readonly_in_array_or_tuple_type(span: Span) -> OxcDiagnostic {

#[cold]
pub fn accessibility_modifier_on_private_property(
modifier: &Modifier,
modifier: Modifier,
_allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("18010", "An accessibility modifier cannot be used with a private identifier.")
Expand Down Expand Up @@ -1127,7 +1127,7 @@ pub fn rest_after_tuple_member_name(span: Span) -> OxcDiagnostic {

#[cold]
pub fn parameter_modifiers_in_ts(
modifier: &Modifier,
modifier: Modifier,
allowed: Option<ModifierKinds>,
) -> OxcDiagnostic {
ts_error("8012", "Parameter modifiers can only be used in TypeScript files.")
Expand Down Expand Up @@ -1239,10 +1239,7 @@ pub fn invalid_rest_assignment_target(span: Span) -> OxcDiagnostic {
}

#[cold]
pub fn modifiers_cannot_appear_here(
modifier: &Modifier,
_: Option<ModifierKinds>,
) -> OxcDiagnostic {
pub fn modifiers_cannot_appear_here(modifier: Modifier, _: Option<ModifierKinds>) -> OxcDiagnostic {
ts_error("1184", "Modifiers cannot appear here.").with_label(modifier.span())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
}
_ => {
if self.at(Kind::Export) {
self.error(diagnostics::modifier_already_seen(&Modifier::new(
self.error(diagnostics::modifier_already_seen(Modifier::new(
self.cur_token().start(),
ModifierKind::Export,
)));
Expand Down
18 changes: 9 additions & 9 deletions crates/oxc_parser/src/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use oxc_span::Span;

use crate::{ParserConfig as Config, ParserImpl, diagnostics, lexer::Kind};

#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub struct Modifier {
pub span_start: u32,
pub kind: ModifierKind,
Expand All @@ -23,7 +23,7 @@ impl Modifier {
Self { span_start, kind }
}

pub const fn span(&self) -> Span {
pub const fn span(self) -> Span {
Span::new(self.span_start, self.span_start + self.kind.len())
}
}
Expand Down Expand Up @@ -408,7 +408,7 @@ impl<C: Config> ParserImpl<'_, C> {
while let Some(modifier_kind) = self.get_modifier() {
let modifier = Modifier::new(self.start_span(), modifier_kind);
self.bump_any();
self.check_modifier(modifiers.kinds(), &modifier);
self.check_modifier(modifiers.kinds(), modifier);
modifiers.add(modifier.kind, modifier.span_start);
}
modifiers
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<C: Config> ParserImpl<'_, C> {
permit_const_as_modifier,
stop_on_start_of_class_static_block,
) {
self.check_modifier(modifiers.kinds(), &modifier);
self.check_modifier(modifiers.kinds(), modifier);
modifiers.add(modifier.kind, modifier.span_start);
}

Expand Down Expand Up @@ -621,7 +621,7 @@ const fn get_illegal_preceding_modifiers(kind: ModifierKind) -> ModifierKinds {

impl<C: Config> ParserImpl<'_, C> {
#[inline]
fn check_modifier(&mut self, existing_kinds: ModifierKinds, modifier: &Modifier) {
fn check_modifier(&mut self, existing_kinds: ModifierKinds, modifier: Modifier) {
// Do a quick check that this modifier is not illegal in this position.
//
// This is just 2 instructions:
Expand All @@ -641,7 +641,7 @@ impl<C: Config> ParserImpl<'_, C> {
/// Create an error for an illegal modifier.
#[cold]
#[inline(never)]
fn illegal_modifier_error(&mut self, existing_kinds: ModifierKinds, modifier: &Modifier) {
fn illegal_modifier_error(&mut self, existing_kinds: ModifierKinds, modifier: Modifier) {
const ACCESSIBILITY_KINDS: ModifierKinds = ModifierKinds::new([
ModifierKind::Public,
ModifierKind::Private,
Expand Down Expand Up @@ -686,7 +686,7 @@ impl<C: Config> ParserImpl<'_, C> {
strict: bool,
create_diagnostic: F,
) where
F: Fn(&Modifier, Option<ModifierKinds>) -> OxcDiagnostic,
F: Fn(Modifier, Option<ModifierKinds>) -> OxcDiagnostic,
{
if modifiers.kinds().has_any_not_in(allowed) {
// Invalid modifiers are rare, so handle this case in `#[cold]` function.
Expand All @@ -700,7 +700,7 @@ impl<C: Config> ParserImpl<'_, C> {
strict: bool,
create_diagnostic: F,
) where
F: Fn(&Modifier, Option<ModifierKinds>) -> OxcDiagnostic,
F: Fn(Modifier, Option<ModifierKinds>) -> OxcDiagnostic,
{
// Sort modifiers to produce errors in source code order
let mut disallowed_modifiers = modifiers
Expand All @@ -711,7 +711,7 @@ impl<C: Config> ParserImpl<'_, C> {

debug_assert!(!disallowed_modifiers.is_empty());

for modifier in &disallowed_modifiers {
for modifier in disallowed_modifiers {
parser.error(create_diagnostic(modifier, strict.then_some(allowed)));
}
}
Expand Down
Loading