Skip to content

Commit df511ba

Browse files
authored
fix(swc_core): Fix downstream doc builds (#10401)
**Description:** This PR fixes an issue where downstream projects using swc_core as a dependency encounter build errors when generating documentation with --cfg docsrs. The problem occurs because certain conditional compilation flags include docsrs directly, causing rustdoc to include code that depends on modules not available in downstream projects. The fix modifies conditional compilation flags in lib.rs and plugin.rs to require both docsrs and the relevant feature to be enabled, rather than including code with only docsrs set. This ensures that when a downstream project builds docs with --cfg docsrs, code is only included if the specific feature is also enabled **Related issue:** - Closes #10384
1 parent 3935b60 commit df511ba

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

crates/swc_core/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ pub extern crate swc_ecma_quote_macros;
1919

2020
// Plugins
2121
#[cfg(any(
22-
docsrs,
22+
all(
23+
docsrs,
24+
any(
25+
feature = "__common_plugin_transform",
26+
feature = "__plugin_transform_host"
27+
)
28+
),
2329
feature = "__common_plugin_transform",
2430
feature = "__plugin_transform_host"
2531
))]

crates/swc_core/src/plugin.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// #[plugin_transform] macro
22
#[cfg(any(
3-
docsrs,
3+
all(
4+
docsrs,
5+
any(
6+
feature = "__common_plugin_transform",
7+
feature = "__css_plugin_transform"
8+
)
9+
),
410
feature = "__common_plugin_transform",
511
feature = "__css_plugin_transform",
612
))]
@@ -13,7 +19,14 @@
1319
)]
1420
pub use swc_plugin_macro::css_plugin_transform;
1521
#[cfg(any(
16-
docsrs,
22+
all(
23+
docsrs,
24+
any(
25+
feature = "__common_plugin_transform",
26+
feature = "__css_plugin_transform",
27+
feature = "__ecma_plugin_transform"
28+
)
29+
),
1730
feature = "__common_plugin_transform",
1831
feature = "__css_plugin_transform",
1932
feature = "__ecma_plugin_transform"
@@ -39,7 +52,14 @@ pub mod memory {
3952
/// Global HANDLER implementation for the plugin
4053
/// for error reporting.
4154
#[cfg(any(
42-
docsrs,
55+
all(
56+
docsrs,
57+
any(
58+
feature = "__common_plugin_transform",
59+
feature = "__css_plugin_transform",
60+
feature = "__ecma_plugin_transform"
61+
)
62+
),
4363
feature = "__common_plugin_transform",
4464
feature = "__css_plugin_transform",
4565
feature = "__ecma_plugin_transform"
@@ -58,7 +78,14 @@ pub mod errors {
5878

5979
/// Plugin's environment metadata context.
6080
#[cfg(any(
61-
docsrs,
81+
all(
82+
docsrs,
83+
any(
84+
feature = "__common_plugin_transform",
85+
feature = "__css_plugin_transform",
86+
feature = "__ecma_plugin_transform"
87+
)
88+
),
6289
feature = "__common_plugin_transform",
6390
feature = "__css_plugin_transform",
6491
feature = "__ecma_plugin_transform"
@@ -79,7 +106,13 @@ pub mod metadata {
79106
/// Proxy to the host's data not attached to the AST, like sourcemap / comments.
80107
/// Or interfaces to setup the plugin's environment from the host.
81108
#[cfg(any(
82-
docsrs,
109+
all(
110+
docsrs,
111+
any(
112+
feature = "__common_plugin_transform",
113+
feature = "__plugin_transform_host"
114+
)
115+
),
83116
feature = "__common_plugin_transform",
84117
feature = "__plugin_transform_host"
85118
))]

0 commit comments

Comments
 (0)