Files
Donny/강동윤andGitHub 96cc6e71b4 feat(es/parser): extend flow declare export strip compatibility (#11691)
## Summary

This extends Flow strip compatibility in `swc_ecma_parser` for remaining
`declare export` forms by normalizing type-only declarations into
synthetic `TsTypeAlias` nodes.

### Parser changes

- Added Flow `declare export` handling for:
  - `declare export { ... };`
  - `declare export { ... } from "...";`
  - `declare export * from "...";`
  - `declare export * as ns from "...";`
- These declarations are normalized to synthetic aliases with unique
ids:
  - `__flow_declare_export_<bytepos>`
- Enhanced `declare export default` handling:
- anonymous `function` / `async function` / `class` are now accepted and
normalized to synthetic `__flow_default_export: any`
- named default function/class behavior is preserved as `declare`
declarations
  - `declare export default interface` remains unsupported

### Fixtures

Added parser Flow fixtures:

- `crates/swc_ecma_parser/tests/flow/declare-export-specifiers/basic.js`
-
`crates/swc_ecma_parser/tests/flow/declare-export-default-anon/basic.js`

Expanded flow-strip input fixture:

- `crates/swc/tests/fixture/flow-strip/input/index.js`

## Validation

- `git submodule update --init --recursive`
- `UPDATE=1 cargo test -p swc_ecma_parser --test flow --features flow --
--ignored`
- `cargo test -p swc_ecma_parser --test flow --features flow --
--ignored`
- `UPDATE=1 cargo test -p swc --test projects -F flow -- --ignored
flow_strip`
- `cargo test -p swc --test projects -F flow -- --ignored flow_strip`
- `cargo fmt --all`
- `cargo clippy --all --all-targets -- -D warnings`
- `cargo test -p swc_ecma_parser`
2026-03-16 04:46:02 -07:00

119 lines
2.2 KiB
JSON

{
"type": "Script",
"span": {
"start": 1,
"end": 146
},
"body": [
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 1,
"end": 24
},
"declare": true,
"id": {
"type": "Identifier",
"span": {
"start": 1,
"end": 24
},
"ctxt": 0,
"value": "__flow_declare_export_1",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 1,
"end": 24
},
"kind": "any"
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 25,
"end": 78
},
"declare": true,
"id": {
"type": "Identifier",
"span": {
"start": 25,
"end": 78
},
"ctxt": 0,
"value": "__flow_declare_export_25",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 25,
"end": 78
},
"kind": "any"
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 79,
"end": 109
},
"declare": true,
"id": {
"type": "Identifier",
"span": {
"start": 79,
"end": 109
},
"ctxt": 0,
"value": "__flow_declare_export_79",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 79,
"end": 109
},
"kind": "any"
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 110,
"end": 146
},
"declare": true,
"id": {
"type": "Identifier",
"span": {
"start": 110,
"end": 146
},
"ctxt": 0,
"value": "__flow_declare_export_110",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 110,
"end": 146
},
"kind": "any"
}
}
],
"interpreter": null
}