fix: correct JsExportNamedFromSpecifier printing order
MODIFY
crates/rome_formatter/src/js/lists/export_named_from_specifier_list.rs
crates/rome_formatter/src/js/lists/export_named_from_specifier_list.rs
-use crate::{FormatElement, FormatResult, Formatter, ToFormatElement};
-use rslint_parser::{ast::JsExportNamedFromSpecifierList, AstNode};
+use crate::{
+ join_elements, soft_line_break_or_space, token, FormatElement, FormatResult, Formatter,
+ ToFormatElement,
+};
+use rslint_parser::ast::JsExportNamedFromSpecifierList;
+
impl ToFormatElement for JsExportNamedFromSpecifierList {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
- Ok(formatter.format_verbatim(self.syntax()))
+ Ok(join_elements(
+ soft_line_break_or_space(),
+ formatter.format_separated(self.clone(), || token(","))?,
+ ))
}
}

MODIFY
crates/rome_formatter/src/js/lists/export_named_specifier_list.rs
crates/rome_formatter/src/js/lists/export_named_specifier_list.rs
-use crate::{FormatElement, FormatResult, Formatter, ToFormatElement};
-use rslint_parser::{ast::JsExportNamedSpecifierList, AstNode};
+use crate::{
+ join_elements, soft_line_break_or_space, token, FormatElement, FormatResult, Formatter,
+ ToFormatElement,
+};
+use rslint_parser::ast::JsExportNamedSpecifierList;
+
impl ToFormatElement for JsExportNamedSpecifierList {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
- Ok(formatter.format_verbatim(self.syntax()))
+ Ok(join_elements(
+ soft_line_break_or_space(),
+ formatter.format_separated(self.clone(), || token(","))?,
+ ))
}
}

MODIFY
crates/rome_formatter/src/js/module/export_named_from_specifier.rs
crates/rome_formatter/src/js/module/export_named_from_specifier.rs
@@ -13,13 +13,15 @@ impl ToFormatElement for JsExportNamedFromSpecifier {
.format_with_or_empty(formatter, |type_token| {
format_elements![type_token, space_token()]
})?;
+
+ let source_name = self.source_name().format(formatter)?;
+
let export_as = self
.export_as()
.format_with_or_empty(formatter, |export_as| {
- format_elements![export_as, space_token()]
+ format_elements![space_token(), export_as]
})?;
- let source = self.source_name().format(formatter)?;
- Ok(format_elements![type_token, export_as, source])
+ Ok(format_elements![type_token, source_name, export_as])
}
}

MODIFY
crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap
crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap
---
source: crates/rome_formatter/tests/spec_test.rs
-assertion_line: 157
+assertion_line: 163
expression: named_from_clause.js
---
@@ -21,11 +21,11 @@ export {
Indent style: Tab
Line width: 80
-----
-export { a, as c b } from "fancy" assert { type: "json" };
+export { a, b as c } from "fancy" assert { type: "json" };
export {
lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem,
- as ipsum_ipsum_ipsum_ipsum_ipsum_ipsum_ lorem_lorem_lorem_lorem_lorem_,
+ lorem_lorem_lorem_lorem_lorem_ as ipsum_ipsum_ipsum_ipsum_ipsum_ipsum_,
} from "fancy" assert {
type: "json",
"type2": "json",

MODIFY
crates/rome_formatter/tests/specs/prettier/export/same-local-and-exported.js.snap
crates/rome_formatter/tests/specs/prettier/export/same-local-and-exported.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: same-local-and-exported.js
---
@@ -15,8 +15,8 @@ export {c as /* comment */c} from 'c';
# Output
```js
export { a } from 'a' ;
-export { as b b } from 'b' ;
-export { as /* comment */ c c } from 'c' ;
+export { b as b } from 'b' ;
+export { c as /* comment */ c } from 'c' ;
```

MODIFY
crates/rome_formatter/tests/specs/prettier/exports/test.js.snap
crates/rome_formatter/tests/specs/prettier/exports/test.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 83
+assertion_line: 121
expression: test.js
---
@@ -22,9 +22,9 @@ export { undefinedExport };
```js
export {
value1,
- as value2_renamed value2,
+ value2 as value2_renamed,
value3,
- as value4_renamed value4,
+ value4 as value4_renamed,
value5,
} from "exports" ;

fix: correct JsExportNamedFromSpecifier printing order (#2094)