Skip to content

Commit

Permalink
feat(prettier): print with_clause in reexport declaration (#2635)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Mar 7, 2024
1 parent 2a235d3 commit 8e3e404
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Expand Up @@ -2216,6 +2216,17 @@ impl<'a> ModuleDeclaration<'a> {
| Self::TSNamespaceExportDeclaration(_) => None,
}
}

pub fn with_clause(&self) -> Option<&WithClause<'a>> {
match self {
Self::ImportDeclaration(decl) => decl.with_clause.as_ref(),
Self::ExportAllDeclaration(decl) => decl.with_clause.as_ref(),
Self::ExportNamedDeclaration(decl) => decl.with_clause.as_ref(),
Self::ExportDefaultDeclaration(_)
| Self::TSExportAssignment(_)
| Self::TSNamespaceExportDeclaration(_) => None,
}
}
}

#[derive(Debug, Hash)]
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_prettier/src/format/module.rs
Expand Up @@ -35,6 +35,11 @@ pub(super) fn print_export_declaration<'a>(
parts.push(source.format(p));
}

if let Some(with_clause) = decl.with_clause() {
parts.push(space!());
parts.push(with_clause.format(p));
}

if let Some(doc) = print_semicolon_after_export_declaration(p, decl) {
parts.push(doc);
}
Expand Down
12 changes: 1 addition & 11 deletions tasks/prettier_conformance/prettier.js.snap.md
@@ -1,4 +1,4 @@
js compatibility: 258/586 (44.03%)
js compatibility: 264/586 (45.05%)

# Failed

Expand Down Expand Up @@ -261,20 +261,10 @@ js compatibility: 258/586 (44.03%)

### import-assertions
* import-assertions/empty.js
* import-assertions/re-export.js

### import-assertions/bracket-spacing
* import-assertions/bracket-spacing/empty.js
* import-assertions/bracket-spacing/re-export.js

### import-attributes
* import-attributes/empty.js
* import-attributes/keyword-detect.js
* import-attributes/re-export.js

### import-attributes/bracket-spacing
* import-attributes/bracket-spacing/empty.js
* import-attributes/bracket-spacing/re-export.js

### label
* label/comment.js
Expand Down

0 comments on commit 8e3e404

Please sign in to comment.