Skip to content
Open
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
340 changes: 248 additions & 92 deletions deps/swc/Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion deps/swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ thiserror = "1.0.30"
tokio = { version = "1", default-features = false }
toml = "0.8.2"
tracing = "0.1.41"
tracing-chrome = "0.7.2"
tracing-subscriber = "0.3.20"
triomphe = "0.1.13"
unicode-id-start = "1.2.0"
Expand Down
3 changes: 1 addition & 2 deletions deps/swc/bindings/binding_core_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["unbounded_depth"] }
tracing = { workspace = true, features = ["release_max_level_info"] }
tracing-chrome = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

swc_core = { path = "../../crates/swc_core", features = [
"allocator_node",
Expand All @@ -63,5 +61,6 @@ swc_core = { path = "../../crates/swc_core", features = [
"base_concurrent",
"base_flow",
"base_module",
"base_react_compiler",
] }
swc_malloc = { path = "../../crates/swc_malloc" }
3 changes: 1 addition & 2 deletions deps/swc/bindings/binding_core_node/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use swc_core::{
common::{comments::SingleThreadedComments, FileName},
node::MapErr,
};
use tracing::instrument;

use crate::{get_fresh_compiler, util::try_with};

Expand All @@ -24,7 +23,7 @@ impl Task for AnalyzeTask {
type JsValue = String;
type Output = String;

#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
fn compute(&mut self) -> napi::Result<Self::Output> {
let options: WasmAnalysisOptions = serde_json::from_slice(self.options.as_ref())?;

Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_core_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct JsCompiler {
impl JsCompiler {
#[napi(constructor)]
#[allow(clippy::new_without_default)]
#[tracing::instrument(level = "info", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "info", skip_all))]
pub fn new() -> Self {
Self {
_compiler: COMPILER.clone(),
Expand Down
9 changes: 4 additions & 5 deletions deps/swc/bindings/binding_core_node/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use swc_core::{
ecma::ast::noop_pass,
node::{get_deserialized, MapErr},
};
use tracing::instrument;

use crate::{
ast_context::{deserialize_program_input, prepare_program_with_context, ProgramInput},
Expand Down Expand Up @@ -82,7 +81,7 @@ impl Task for TransformTask {
type JsValue = TransformOutput;
type Output = TransformOutput;

#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
fn compute(&mut self) -> napi::Result<Self::Output> {
let mut options: Options = serde_json::from_slice(self.options.as_ref())?;
if !options.filename.is_empty() {
Expand Down Expand Up @@ -143,7 +142,7 @@ impl Task for TransformTask {
}

#[napi]
#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
pub fn transform(
src: String,
is_module: bool,
Expand All @@ -163,7 +162,7 @@ pub fn transform(
}

#[napi]
#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<TransformOutput> {
crate::util::init_default_trace_subscriber();

Expand Down Expand Up @@ -212,7 +211,7 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<
}

#[napi]
#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
pub fn transform_file(
src: String,
_is_module: bool,
Expand Down
56 changes: 6 additions & 50 deletions deps/swc/bindings/binding_core_node/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ use anyhow::{anyhow, Error};
use napi::Env;
use swc_core::{
base::{config::ErrorFormat, try_with_handler},
common::{
errors::Handler,
sync::{Lrc, OnceCell},
SourceMap, GLOBALS,
},
};
use tracing::instrument;
use tracing_chrome::ChromeLayerBuilder;
use tracing_subscriber::{
filter, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
common::{errors::Handler, sync::Lrc, SourceMap, GLOBALS},
};

static TARGET_TRIPLE: &str = include_str!(concat!(env!("OUT_DIR"), "/triple.txt"));
static CUSTOM_TRACE_SUBSCRIBER: OnceCell<bool> = OnceCell::new();

#[napi]
pub fn get_target_triple() -> napi::Result<String> {
Expand All @@ -28,36 +18,13 @@ pub fn get_target_triple() -> napi::Result<String> {

#[napi]
pub fn init_custom_trace_subscriber(
env: Env,
trace_out_file_path: Option<String>,
_env: Env,
_trace_out_file_path: Option<String>,
) -> napi::Result<()> {
CUSTOM_TRACE_SUBSCRIBER.get_or_init(|| {
let mut layer = ChromeLayerBuilder::new().include_args(true);
if let Some(trace_out_file) = trace_out_file_path {
layer = layer.file(trace_out_file);
}

let (chrome_layer, guard) = layer.build();
tracing_subscriber::registry()
.with(chrome_layer.with_filter(filter::filter_fn(|metadata| {
!metadata.target().contains("cranelift") && !metadata.name().contains("log ")
})))
.try_init()
.expect("Failed to register tracing subscriber");

env.add_env_cleanup_hook(guard, |flush_guard| {
flush_guard.flush();
drop(flush_guard);
})
.expect("Should able to initialize cleanup for custom trace subscriber");

true
});

Ok(())
}

#[instrument(level = "trace", skip_all)]
#[cfg_attr(debug_assertions, tracing::instrument(level = "trace", skip_all))]
pub fn try_with<F, Ret>(
cm: Lrc<SourceMap>,
skip_filename: bool,
Expand Down Expand Up @@ -101,16 +68,5 @@ where
// interface for the custom binary - they should choose own trace initialization
// instead. Will keep as hidden for now until there's proper usecase.

/// Trying to initialize default subscriber if global dispatch is not set.
/// This can be called multiple time, however subsequent calls will be ignored
/// as tracing_subscriber only allows single global dispatch.
pub fn init_default_trace_subscriber() {
let _unused = tracing_subscriber::FmtSubscriber::builder()
.without_time()
.with_target(false)
.with_writer(std::io::stderr)
.with_ansi(true)
.with_env_filter(EnvFilter::from_env("SWC_LOG"))
.pretty()
.try_init();
}
/// Deprecated no-op kept for compatibility with existing binding entrypoints.
pub fn init_default_trace_subscriber() {}
3 changes: 2 additions & 1 deletion deps/swc/bindings/binding_core_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
name = "binding_core_wasm"
publish = false
repository = { workspace = true }
version = "1.15.41"
version = "1.15.43"

[lib]
bench = false
Expand Down Expand Up @@ -45,6 +45,7 @@ swc_core = { path = "../../crates/swc_core", features = [
"ecma_helpers_inline",
"ecma_lints",
"base_module",
"base_react_compiler",
] }
tracing = { workspace = true, features = ["max_level_off"] }
wasm-bindgen = { workspace = true, features = ["enable-interning"] }
Expand Down
104 changes: 104 additions & 0 deletions deps/swc/bindings/binding_core_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ export interface TransformConfig {
*/
react?: ReactConfig;

reactCompiler?: boolean | ReactCompilerOptions;

constModules?: ConstModulesConfig;

/**
Expand All @@ -862,6 +864,108 @@ export interface TransformConfig {
useDefineForClassFields?: boolean;
}

export interface ReactCompilerOptions {
/**
* Which functions to compile.
*
* Defaults to `"infer"`.
*/
compilationMode?: "infer" | "syntax" | "annotation" | "all";

/**
* What to do when a function cannot be compiled.
*
* Defaults to `"none"`.
*/
panicThreshold?: "none" | "critical_errors" | "all_errors";

/**
* React runtime version target.
*
* Defaults to `"19"`.
*/
target?: "17" | "18" | "19";

/**
* Analyze and report diagnostics only; emit no transformed code.
*
* Defaults to `false`.
*/
noEmit?: boolean;

/**
* Defaults to `"client"`.
*/
outputMode?: "client" | "ssr" | "lint";

/**
* Compile even functions marked with opt-out directives.
*
* Defaults to `false`.
*/
ignoreUseNoForget?: boolean;

/**
* Treat Flow suppression comments as opt-outs.
*
* Defaults to `true`.
*/
flowSuppressions?: boolean;

/**
* Enable react-native-reanimated support.
*
* Defaults to `false`.
*/
enableReanimated?: boolean;

/**
* Development mode.
*
* Defaults to `false`.
*/
isDev?: boolean;

/**
* ESLint rules whose suppressions opt a function out of compilation.
*/
eslintSuppressionRules?: string[];

/**
* Extra directives that opt a function out of compilation.
*/
customOptOutDirectives?: string[];

/**
* Emit a gated version of each compiled function.
*/
gating?: ReactCompilerGatingConfig;

/**
* Dynamically-gated compilation.
*/
dynamicGating?: ReactCompilerDynamicGatingConfig;
}

export interface ReactCompilerGatingConfig {
/**
* Module the gating import comes from.
*/
source: string;

/**
* Imported specifier used as the gate.
*/
importSpecifierName: string;
}

export interface ReactCompilerDynamicGatingConfig {
/**
* Module the gating import comes from.
*/
source: string;
}

export interface ReactConfig {
/**
* Replace the function used when compiling JSX expressions.
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_es_ast_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = { workspace = true }
name = "binding_es_ast_viewer"
publish = false
repository = { workspace = true }
version = "1.15.41"
version = "1.15.43"

[dependencies]
anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_html_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
name = "binding_html_wasm"
publish = false
repository = { workspace = true }
version = "1.15.41"
version = "1.15.43"

[lib]
bench = false
Expand Down
2 changes: 0 additions & 2 deletions deps/swc/bindings/binding_minifier_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ napi-derive = { workspace = true, features = ["type-def"] }
par-core = { workspace = true, features = ["chili"] }
serde = { workspace = true, features = ["derive"] }
tracing = { workspace = true, features = ["release_max_level_info"] }
tracing-chrome = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }


swc_compiler_base = { path = "../../crates/swc_compiler_base", features = [
Expand Down
Loading
Loading