Files
Donny/강동윤andGitHub 735600f6f9 feat(es/parser): finish flow strip support for core syntax gaps (#11689)
## Summary

This PR completes Flow stripping coverage in `swc_ecma_parser` for four
syntax gaps by normalizing Flow-only forms into existing TS-compatible
parser paths, so downstream strip behavior removes them consistently.

## What changed

- `declare module.exports: T;`
  - Added Flow-mode handling in `parse_ts_decl` (`module` branch).
- Normalized to synthetic `TsTypeAliasDecl` with id
`__flow_module_exports`.

- `declare export default ...`
  - Added dedicated default handling in Flow `export` declare branch.
  - Supports:
    - `declare export default class ...`
    - `declare export default function ...`
- `declare export default <Type>;` (normalized via synthetic alias
`__flow_default_export`)

- Flow predicate `%checks` / `%checks(expr)`
- Added consume-only parsing after return type and before function body.
  - No AST node introduced (strip-friendly behavior).

- Class field variance `+x` / `-y`
  - Added Flow variance token consumption before class field names.
  - `+` maps to readonly semantics on fields.
  - `-` maps to writable semantics.
  - Variance in method contexts emits error and continues.

## Tests

Added parser fixtures:

- `crates/swc_ecma_parser/tests/flow/class-variance/basic.js`
- `crates/swc_ecma_parser/tests/flow/declare-export-default/basic.js`
- `crates/swc_ecma_parser/tests/flow/module-exports/basic.js`
- `crates/swc_ecma_parser/tests/flow/predicate/basic.js`

Expanded flow-strip e2e fixture:

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

Validation run:

- `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 03:20:27 -07:00

8 lines
162 B
JavaScript

function isString(x: mixed): boolean %checks {
return typeof x === "string";
}
function hasValue(x: mixed): boolean %checks(x != null) {
return x != null;
}