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
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ pub struct ExportNamedDeclaration<'a> {
pub source: Option<StringLiteral<'a>>,
/// `export type { foo }`
#[ts]
#[estree(via = ExportNamedDeclarationExportKind)]
pub export_kind: ImportOrExportKind,
/// Some(vec![]) for empty assertion
#[estree(rename = "attributes", via = ExportNamedDeclarationWithClause)]
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,10 @@ impl ESTree for ExportNamedDeclaration<'_> {
"attributes",
&crate::serialize::ExportNamedDeclarationWithClause(self),
);
state.serialize_ts_field("exportKind", &self.export_kind);
state.serialize_ts_field(
"exportKind",
&crate::serialize::ExportNamedDeclarationExportKind(self),
);
state.end();
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,28 @@ impl ESTree for ExportAllDeclarationWithClause<'_, '_> {
}
}

#[ast_meta]
#[estree(
ts_type = "ImportOrExportKind",
raw_deser = "
const exportKind = DESER[ImportOrExportKind](POS_OFFSET.export_kind);
THIS.declaration?.declare ? 'type' : exportKind
Comment on lines +827 to +828
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const exportKind = DESER[ImportOrExportKind](POS_OFFSET.export_kind);
THIS.declaration?.declare ? 'type' : exportKind
THIS.declaration?.declare ? 'type' : THIS.exportKind

First I tried this. But this seems to generate invalid JS code as a result. 🤔

"
)]
pub struct ExportNamedDeclarationExportKind<'a, 'b>(pub &'b ExportNamedDeclaration<'a>);

impl ESTree for ExportNamedDeclarationExportKind<'_, '_> {
fn serialize<S: Serializer>(&self, serializer: S) {
if let Some(decl) = &self.0.declaration {
if decl.declare() {
ImportOrExportKind::Type.serialize(serializer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether this is a parser bug, where declared exports should be type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

I tried to fix parser at first, but other tests like codegen, isolated_decls failed, so I switched to this one. 😓
I will take another look at the parser side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to fix the parser so that consumers of this AST node knows it's a type export.

To test the theory, we can find a linter rule and double check, e.g.

https://github.com/typescript-eslint/typescript-eslint/blob/fa265a970535e9b8d3ac8bfde9f3a24f1a1ec94a/packages/eslint-plugin/src/rules/consistent-type-exports.ts#L205

I haven't checked, but we may be linting this node incorrectly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I got it this time. => #10389

Since it seems that consistent-type-exports is a type-checking rule, so we don't have it yet. 👀
And other rules are not affected by exportKind.

return;
}
}
self.0.export_kind.serialize(serializer);
}
}

// --------------------
// JSX
// --------------------
Expand Down
6 changes: 4 additions & 2 deletions napi/parser/deserialize-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,16 +1049,18 @@ function deserializeImportAttribute(pos) {
}

function deserializeExportNamedDeclaration(pos) {
const declaration = deserializeOptionDeclaration(pos + 8);
const withClause = deserializeOptionBoxWithClause(pos + 112);
const exportKind = deserializeImportOrExportKind(pos + 104);
return {
type: 'ExportNamedDeclaration',
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
declaration: deserializeOptionDeclaration(pos + 8),
declaration,
specifiers: deserializeVecExportSpecifier(pos + 24),
source: deserializeOptionStringLiteral(pos + 56),
attributes: withClause === null ? [] : withClause.withEntries,
exportKind: deserializeImportOrExportKind(pos + 104),
exportKind: declaration?.declare ? 'type' : exportKind,
};
}

Expand Down
Loading
Loading