Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_parser): export default function in declare module #3485 #3775

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 66 additions & 0 deletions crates/rome_js_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions crates/rome_js_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/rome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6318,6 +6318,21 @@ impl IntoFormat<crate::JsFormatContext> for rome_js_syntax::JsFunctionExportDefa
FormatOwnedWithRule :: new (self , crate :: js :: declarations :: function_export_default_declaration :: FormatJsFunctionExportDefaultDeclaration :: default ())
}
}
impl FormatRule < rome_js_syntax :: TsDeclareFunctionExportDefaultDeclaration > for crate :: ts :: declarations :: declare_function_export_default_declaration :: FormatTsDeclareFunctionExportDefaultDeclaration { type Context = JsFormatContext ; # [inline (always)] fn fmt (& self , node : & rome_js_syntax :: TsDeclareFunctionExportDefaultDeclaration , f : & mut JsFormatter) -> FormatResult < () > { FormatNodeRule :: < rome_js_syntax :: TsDeclareFunctionExportDefaultDeclaration > :: fmt (self , node , f) } }
denbezrukov marked this conversation as resolved.
Show resolved Hide resolved
impl AsFormat for rome_js_syntax::TsDeclareFunctionExportDefaultDeclaration {
type Format < 'a > = FormatRefWithRule < 'a , rome_js_syntax :: TsDeclareFunctionExportDefaultDeclaration , crate :: ts :: declarations :: declare_function_export_default_declaration :: FormatTsDeclareFunctionExportDefaultDeclaration > ;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule :: new (self , crate :: ts :: declarations :: declare_function_export_default_declaration :: FormatTsDeclareFunctionExportDefaultDeclaration :: default ())
}
}
impl IntoFormat<crate::JsFormatContext>
for rome_js_syntax::TsDeclareFunctionExportDefaultDeclaration
{
type Format = FormatOwnedWithRule < rome_js_syntax :: TsDeclareFunctionExportDefaultDeclaration , crate :: ts :: declarations :: declare_function_export_default_declaration :: FormatTsDeclareFunctionExportDefaultDeclaration > ;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule :: new (self , crate :: ts :: declarations :: declare_function_export_default_declaration :: FormatTsDeclareFunctionExportDefaultDeclaration :: default ())
}
}
impl FormatRule<rome_js_syntax::JsExportNamedShorthandSpecifier>
for crate::js::module::export_named_shorthand_specifier::FormatJsExportNamedShorthandSpecifier
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ impl FormatRule<JsAnyExportDefaultDeclaration> for FormatJsAnyExportDefaultDecla
JsAnyExportDefaultDeclaration::JsFunctionExportDefaultDeclaration(node) => {
node.format().fmt(f)
}
JsAnyExportDefaultDeclaration::TsDeclareFunctionDeclaration(node) => {
JsAnyExportDefaultDeclaration::TsInterfaceDeclaration(node) => node.format().fmt(f),
JsAnyExportDefaultDeclaration::TsDeclareFunctionExportDefaultDeclaration(node) => {
node.format().fmt(f)
}
JsAnyExportDefaultDeclaration::TsInterfaceDeclaration(node) => node.format().fmt(f),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use rome_formatter::{write, RemoveSoftLinesBuffer};
use rome_js_syntax::{
JsAnyBinding, JsFunctionBody, JsFunctionDeclaration, JsFunctionExportDefaultDeclaration,
JsFunctionExpression, JsParameters, JsSyntaxToken, TsAnyReturnType,
TsDeclareFunctionDeclaration, TsReturnTypeAnnotation, TsType, TsTypeParameters,
TsDeclareFunctionDeclaration, TsDeclareFunctionExportDefaultDeclaration,
TsReturnTypeAnnotation, TsType, TsTypeParameters,
};
use rome_rowan::{declare_node_union, SyntaxResult};

Expand All @@ -24,7 +25,8 @@ declare_node_union! {
JsFunctionDeclaration |
JsFunctionExpression |
JsFunctionExportDefaultDeclaration |
TsDeclareFunctionDeclaration
TsDeclareFunctionDeclaration |
TsDeclareFunctionExportDefaultDeclaration
}

#[derive(Copy, Clone, Debug, Default)]
Expand All @@ -42,6 +44,9 @@ impl FormatFunction {
declaration.async_token()
}
FormatFunction::TsDeclareFunctionDeclaration(member) => member.async_token(),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => {
member.async_token()
}
}
}

Expand All @@ -53,6 +58,9 @@ impl FormatFunction {
declaration.function_token()
}
FormatFunction::TsDeclareFunctionDeclaration(member) => member.function_token(),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => {
member.function_token()
}
}
}

Expand All @@ -64,6 +72,7 @@ impl FormatFunction {
declaration.star_token()
}
FormatFunction::TsDeclareFunctionDeclaration(_) => None,
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(_) => None,
}
}

Expand All @@ -73,6 +82,7 @@ impl FormatFunction {
FormatFunction::JsFunctionExpression(expression) => Ok(expression.id()),
FormatFunction::JsFunctionExportDefaultDeclaration(declaration) => Ok(declaration.id()),
FormatFunction::TsDeclareFunctionDeclaration(member) => member.id().map(Some),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => Ok(member.id()),
}
}

Expand All @@ -84,6 +94,9 @@ impl FormatFunction {
declaration.type_parameters()
}
FormatFunction::TsDeclareFunctionDeclaration(member) => member.type_parameters(),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => {
member.type_parameters()
}
}
}

Expand All @@ -95,6 +108,9 @@ impl FormatFunction {
declaration.parameters()
}
FormatFunction::TsDeclareFunctionDeclaration(member) => member.parameters(),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => {
member.parameters()
}
}
}

Expand All @@ -108,6 +124,9 @@ impl FormatFunction {
declaration.return_type_annotation()
}
FormatFunction::TsDeclareFunctionDeclaration(member) => member.return_type_annotation(),
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(member) => {
member.return_type_annotation()
}
}
}

Expand All @@ -119,6 +138,7 @@ impl FormatFunction {
Some(declaration.body()?)
}
FormatFunction::TsDeclareFunctionDeclaration(_) => None,
FormatFunction::TsDeclareFunctionExportDefaultDeclaration(_) => None,
})
}

Expand Down
12 changes: 2 additions & 10 deletions crates/rome_js_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,9 @@ function() {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
// different output than prettier
function Component4() {

return (
<div>
{fn(datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadata)}{' '}
<div/>
</div>
);
declare module 'x' {
export default function (option: any): void
}

"#;
let syntax = SourceType::tsx();
let tree = parse(src, FileId::zero(), syntax);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::js::declarations::function_declaration::FormatFunction;
use crate::prelude::*;
use crate::utils::FormatStatementSemicolon;
use rome_formatter::write;
use rome_js_syntax::TsDeclareFunctionExportDefaultDeclaration;

#[derive(Debug, Clone, Default)]
pub struct FormatTsDeclareFunctionExportDefaultDeclaration;
impl FormatNodeRule<TsDeclareFunctionExportDefaultDeclaration>
for FormatTsDeclareFunctionExportDefaultDeclaration
{
fn fmt_fields(
&self,
node: &TsDeclareFunctionExportDefaultDeclaration,
f: &mut JsFormatter,
) -> FormatResult<()> {
write![
f,
[
FormatFunction::from(node.clone()),
FormatStatementSemicolon::new(node.semicolon_token().as_ref())
]
]
}
}
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/ts/declarations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

pub(crate) mod declare_function_declaration;
pub(crate) mod declare_function_export_default_declaration;
pub(crate) mod enum_declaration;
pub(crate) mod external_module_declaration;
pub(crate) mod global_declaration;
Expand Down
Loading