diff --git a/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs b/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs index 2664df3afe630..48148efd7760e 100644 --- a/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs +++ b/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs @@ -404,12 +404,6 @@ impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> { self.convert_offset(&mut it.span.end); } - fn visit_formal_parameters(&mut self, it: &mut FormalParameters<'a>) { - self.convert_offset(&mut it.span.start); - walk_mut::walk_formal_parameters(self, it); - self.convert_offset(&mut it.span.end); - } - fn visit_formal_parameter(&mut self, it: &mut FormalParameter<'a>) { self.convert_offset(&mut it.span.start); walk_mut::walk_formal_parameter(self, it); @@ -1067,6 +1061,10 @@ impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> { self.convert_offset(&mut it.span.end); } + fn visit_formal_parameters(&mut self, params: &mut FormalParameters<'a>) { + walk_mut::walk_formal_parameters(self, params); + } + fn visit_object_property(&mut self, prop: &mut ObjectProperty<'a>) { self.convert_offset(&mut prop.span.start); match (prop.shorthand, &mut prop.key, &mut prop.value) { diff --git a/tasks/ast_tools/src/generators/utf8_to_utf16.rs b/tasks/ast_tools/src/generators/utf8_to_utf16.rs index ff5c505c5bd5d..c1cc97b76b685 100644 --- a/tasks/ast_tools/src/generators/utf8_to_utf16.rs +++ b/tasks/ast_tools/src/generators/utf8_to_utf16.rs @@ -42,6 +42,7 @@ impl Generator for Utf8ToUtf16ConverterGenerator { /// have span before the start of `ExportNamedDeclaration` / `ExportDefaultDeclaration` span. /// 5. `BindingPattern` where `type_annotation` has span within `BindingPatternKind`. /// Except for `BindingRestElement`, where `type_annotation`'s span is after `BindingPatternKind`. +/// 6. `FormalParameters` where span can include a `TSThisParameter` which is visited before it. /// /// Define custom visitors for these types, which ensure `convert_offset` is always called with offsets /// in ascending order. @@ -52,6 +53,7 @@ fn generate(schema: &Schema, codegen: &Codegen) -> TokenStream { // Types with custom visitors (see comment above). // Also skip `Comment` because we handle adjusting comment spans separately. let skip_type_ids = [ + "FormalParameters", "ObjectProperty", "BindingProperty", "ExportNamedDeclaration", @@ -100,6 +102,14 @@ fn generate(schema: &Schema, codegen: &Codegen) -> TokenStream { impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> { #(#methods)* + ///@@line_break + fn visit_formal_parameters(&mut self, params: &mut FormalParameters<'a>) { + // Span of `FormalParameters` itself does not appear in ESTree AST, + // and its span includes `TSThisParameter` in types like `Function`, + // which is converted before `FormalParameters`. So skip converting span. + walk_mut::walk_formal_parameters(self, params); + } + ///@@line_break fn visit_object_property(&mut self, prop: &mut ObjectProperty<'a>) { self.convert_offset(&mut prop.span.start);