Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): export_named_type should parse default as normal #4903

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
14 changes: 14 additions & 0 deletions .changeset/export_named_type_parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
cli: patch
biome_js_parser: patch
Copy link
Member

Choose a reason for hiding this comment

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

You must add the cli package too. Please read the contribution guide regarding the changesets

Copy link
Member Author

Choose a reason for hiding this comment

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

done, thanks for the reminder.

---

# Export Named Type support `default` parser

The following code:

```ts
export { type A as default } from './b.ts';
```

Should be parsed successfully.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export declare class E { }
export type * from "types";

export type * as types from "types";

export { type default as G } from './types.ts';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: ts/module/export_clause.ts
snapshot_kind: text
---
# Input

Expand Down Expand Up @@ -28,6 +29,8 @@ export type * from "types";

export type * as types from "types";

export { type default as G } from './types.ts';

```


Expand Down Expand Up @@ -76,4 +79,6 @@ export declare class E {}
export type * from "types";

export type * as types from "types";

export { type default as G } from "./types.ts";
```
4 changes: 2 additions & 2 deletions crates/biome_js_parser/src/syntax/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ where
metadata.is_type = true;
}
} else {
// `{ type x }` or `{ type "x" }` or `{ type x as }`
metadata.is_type = is_nth_name(p, 1);
// `{ type x }` or `{ type "x" }` or `{ type x as }` or `{ type default as }`
metadata.is_type = is_nth_name(p, 1) || p.nth_at(1, T![default]);
metadata.has_alias = p.nth_at(2, T![as]);
}
} else if p.at(T![as]) && is_nth_alias(p, 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { type A } from "a"
export { type } from "./type";
export { type default as CrsMeta } from './crs-meta.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ snapshot_kind: text
```ts
export { type A } from "a"
export { type } from "./type";
export { type default as CrsMeta } from './crs-meta.js';

```

Expand Down Expand Up @@ -68,19 +69,48 @@ JsModule {
semicolon_token: [email protected] ";" [] [],
},
},
JsExport {
decorators: JsDecoratorList [],
export_token: [email protected] "export" [Newline("\n")] [Whitespace(" ")],
export_clause: JsExportNamedFromClause {
type_token: missing (optional),
l_curly_token: [email protected] "{" [] [Whitespace(" ")],
specifiers: JsExportNamedFromSpecifierList [
JsExportNamedFromSpecifier {
type_token: [email protected] "type" [] [Whitespace(" ")],
source_name: JsLiteralExportName {
value: [email protected] "default" [] [Whitespace(" ")],
},
export_as: JsExportAsClause {
as_token: [email protected] "as" [] [Whitespace(" ")],
exported_name: JsLiteralExportName {
value: [email protected] "CrsMeta" [] [Whitespace(" ")],
},
},
},
],
r_curly_token: [email protected] "}" [] [Whitespace(" ")],
from_token: [email protected] "from" [] [Whitespace(" ")],
source: JsModuleSource {
value_token: [email protected] "'./crs-meta.js'" [] [],
},
assertion: missing (optional),
semicolon_token: [email protected] ";" [] [],
},
},
],
eof_token: EOF@57..58 "" [Newline("\n")] [],
eof_token: EOF@114..115 "" [Newline("\n")] [],
}
```

## CST

```
0: JS_MODULE@0..58
0: JS_MODULE@0..115
0: (empty)
1: (empty)
2: [email protected]
3: JS_MODULE_ITEM_LIST@0..57
3: JS_MODULE_ITEM_LIST@0..114
0: [email protected]
0: [email protected]
1: [email protected] "export" [] [Whitespace(" ")]
Expand Down Expand Up @@ -117,6 +147,27 @@ JsModule {
0: [email protected] "\"./type\"" [] []
6: (empty)
7: [email protected] ";" [] []
4: [email protected] "" [Newline("\n")] []
2: [email protected]
0: [email protected]
1: [email protected] "export" [Newline("\n")] [Whitespace(" ")]
2: [email protected]
0: (empty)
1: [email protected] "{" [] [Whitespace(" ")]
2: [email protected]
0: [email protected]
0: [email protected] "type" [] [Whitespace(" ")]
1: [email protected]
0: [email protected] "default" [] [Whitespace(" ")]
2: [email protected]
0: [email protected] "as" [] [Whitespace(" ")]
1: [email protected]
0: [email protected] "CrsMeta" [] [Whitespace(" ")]
3: [email protected] "}" [] [Whitespace(" ")]
4: [email protected] "from" [] [Whitespace(" ")]
5: [email protected]
0: [email protected] "'./crs-meta.js'" [] []
6: (empty)
7: [email protected] ";" [] []
4: [email protected] "" [Newline("\n")] []

```
8 changes: 1 addition & 7 deletions crates/biome_js_parser/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_
#[test]
pub fn quick_test() {
let code = r#"
export let shim: typeof import("./foo2") = {
Bar: Bar2
};
export interface Foo {
bar: import('immutable').Map<string, int>;
}
export { type default as CrsMeta } from './crs-meta.js';
"#;

let root = parse(code, JsFileSource::ts(), JsParserOptions::default());
Expand Down
Loading