Skip to content

Commit baab240

Browse files
authored
fix(es/parser): allow no-default builds (#11956)
**Description:** Fixes `swc_ecma_parser` compilation when default features are disabled. Shared parser modules reference Flow reserved-name helpers even when the `typescript` feature is disabled, but those helpers only existed in the TypeScript parser implementation. This adds matching no-op stubs in `typescript_stubs.rs`, so the no-default build compiles without enabling TypeScript or Flow behavior. Also adds a `swc_ecma_parser` no-default check to `tests.yml` and a patch changeset for `swc_ecma_parser` and `swc_core`. Validation: - `git submodule update --init --recursive` - `cargo check -p swc_ecma_parser --no-default-features` - `cargo test -p swc_ecma_parser` - `cargo fmt --all` - `cargo clippy --all --all-targets -- -D warnings` - `cargo check --no-default-features` from `crates/swc_ecma_parser` **Related issue:** Fixes #11942
1 parent 09273c0 commit baab240

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_parser: patch
4+
---
5+
6+
fix(es/parser): allow compilation without default features

crates/swc_ecma_parser/src/parser/typescript_stubs.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
//! Stub implementations for TypeScript parsing methods when the `typescript`
22
//! feature is disabled.
33
//!
4-
//! These methods are never called at runtime (the calls are guarded by
5-
//! `syntax().typescript()` which returns `false` when the feature is disabled),
6-
//! but Rust needs them to exist for compilation to succeed.
4+
//! Shared parser modules call these methods even when the `typescript` feature
5+
//! is disabled. Runtime syntax checks make TypeScript and Flow behavior
6+
//! unavailable in this configuration, but Rust still needs matching method
7+
//! definitions for compilation to succeed.
78
8-
use swc_common::BytePos;
9+
use swc_common::{BytePos, Span};
910
use swc_ecma_ast::*;
1011

1112
use crate::{input::Tokens, lexer::Token, PResult, Parser};
1213

1314
impl<I: Tokens> Parser<I> {
15+
pub(super) fn is_flow_reserved_type_name(_name: &str) -> bool {
16+
false
17+
}
18+
19+
pub(super) fn emit_flow_reserved_type_name_error(&mut self, _span: Span, _name: &str) {}
20+
1421
pub(crate) fn try_parse_ts<T, F>(&mut self, _op: F) -> Option<T>
1522
where
1623
F: FnOnce(&mut Self) -> PResult<Option<T>>,

tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ check:
4040
- "cargo hack check --feature-powerset --exclude-features __rkyv"
4141
swc_ecma_loader:
4242
- "cargo hack check --feature-powerset"
43+
swc_ecma_parser:
44+
- "cargo check --no-default-features"
4345
swc_ecma_transforms:
4446
# - "cargo hack check --feature-powerset"
4547
- "cargo check --features concurrent --features par-core/chili"

0 commit comments

Comments
 (0)