Skip to content

Commit

Permalink
chore: Update swc_core to v0.40.40 (#42326)
Browse files Browse the repository at this point in the history
This PR updates swc crates to
swc-project/swc@5784ae2



Applies

 - swc-project/swc#6300

Closes #42171.

 - swc-project/swc#6293
 
 - swc-project/swc#6272

Closes #41992.
  • Loading branch information
kdy1 committed Nov 4, 2022
1 parent 00df9f3 commit 670f2a8
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 223 deletions.
381 changes: 185 additions & 196 deletions packages/next-swc/Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -19,11 +19,11 @@ pathdiff = "0.2.0"
regex = "1.5"
serde = "1"
serde_json = "1"
swc_emotion = "0.28.1"
styled_components = "0.52.1"
styled_jsx = "0.29.1"
modularize_imports = "0.25.1"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
swc_emotion = "0.28.2"
styled_components = "0.52.2"
styled_jsx = "0.29.2"
modularize_imports = "0.25.2"
tracing = { version = "0.1.37", features = ["release_max_level_info"] }

swc_core = { features = [
"common_concurrent",
Expand All @@ -42,9 +42,9 @@ swc_core = { features = [
"ecma_parser_typescript",
"cached",
"base"
], version = "0.40.16" }
], version = "0.40.40" }

[dev-dependencies]
swc_core = { features = ["testing_transform"], version = "0.40.16" }
testing = "0.31.10"
swc_core = { features = ["testing_transform"], version = "0.40.40" }
testing = "0.31.13"
walkdir = "2.3.2"
7 changes: 5 additions & 2 deletions packages/next-swc/crates/core/tests/full.rs
Expand Up @@ -3,6 +3,7 @@ use serde::de::DeserializeOwned;
use std::path::{Path, PathBuf};
use swc_core::{
base::Compiler,
common::comments::SingleThreadedComments,
ecma::parser::{Syntax, TsConfig},
ecma::transforms::base::pass::noop,
};
Expand Down Expand Up @@ -71,12 +72,14 @@ fn test(input: &Path, minify: bool) {

let options = options.patch(&fm);

let comments = SingleThreadedComments::default();
match c.process_js_with_custom_pass(
fm.clone(),
None,
&handler,
&options.swc,
|_, comments| {
comments.clone(),
|_| {
custom_before_pass(
cm.clone(),
fm.clone(),
Expand All @@ -85,7 +88,7 @@ fn test(input: &Path, minify: bool) {
Default::default(),
)
},
|_, _| noop(),
|_| noop(),
) {
Ok(v) => {
NormalizedOutput::from(v.code)
Expand Down
8 changes: 5 additions & 3 deletions packages/next-swc/crates/core/tests/telemetry.rs
Expand Up @@ -8,7 +8,7 @@ use once_cell::sync::Lazy;

use swc_core::{
base::{try_with_handler, Compiler},
common::{FileName, FilePathMapping, SourceMap, GLOBALS},
common::{comments::SingleThreadedComments, FileName, FilePathMapping, SourceMap, GLOBALS},
ecma::transforms::base::pass::noop,
};

Expand Down Expand Up @@ -42,13 +42,15 @@ export function getServerSideProps() {
assert!(
try_with_handler(COMPILER.cm.clone(), Default::default(), |handler| {
GLOBALS.set(&Default::default(), || {
let comments = SingleThreadedComments::default();
COMPILER.process_js_with_custom_pass(
fm,
None,
handler,
&Default::default(),
|_, _| next_ssg(eliminated_packages.clone()),
|_, _| noop(),
comments.clone(),
|_| next_ssg(eliminated_packages.clone()),
|_| noop(),
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ sentry_native_tls = ["_sentry_native_tls"]
sentry_rustls = ["_sentry_rustls"]

[dependencies]
anyhow = "1.0"
anyhow = "1.0.66"
backtrace = "0.3"
fxhash = "0.2.1"
napi = { version = "2", default-features = false, features = ["napi3", "serde-json", "tokio_rt", "error_anyhow"] }
Expand Down Expand Up @@ -50,8 +50,8 @@ swc_core = { features = [
"ecma_transforms_typescript",
"ecma_utils",
"ecma_visit",
], version = "0.40.16" }
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
], version = "0.40.40" }
tracing = { version = "0.1.37", features = ["release_max_level_info"] }
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.9"
tracing-chrome = "0.5.0"
Expand Down
9 changes: 8 additions & 1 deletion packages/next-swc/crates/napi/src/minify.rs
Expand Up @@ -31,8 +31,9 @@ use fxhash::FxHashMap;
use napi::bindgen_prelude::*;
use serde::Deserialize;
use swc_core::{
base::{config::JsMinifyOptions, try_with_handler, TransformOutput},
base::{config::JsMinifyOptions, try_with_handler, BoolOrDataConfig, TransformOutput},
common::{errors::ColorConfig, sync::Lrc, FileName, SourceFile, SourceMap, GLOBALS},
ecma::minifier::option::terser::TerserCompressorOptions,
};

use crate::{get_compiler, util::MapErr};
Expand Down Expand Up @@ -92,6 +93,12 @@ impl Task for MinifyTask {
fm,
handler,
&JsMinifyOptions {
compress: TerserCompressorOptions {
// inline: TerserInlineOption::Num(0).into(),
..Default::default()
}
.into(),
mangle: BoolOrDataConfig::from_bool(false),
..self.opts.clone()
},
)
Expand Down
7 changes: 5 additions & 2 deletions packages/next-swc/crates/napi/src/transform.rs
Expand Up @@ -38,6 +38,7 @@ use anyhow::{anyhow, bail, Context as _};
use fxhash::FxHashSet;
use napi::bindgen_prelude::*;
use next_swc::{custom_before_pass, TransformOptions};
use swc_core::common::comments::SingleThreadedComments;
use swc_core::{
base::{try_with_handler, Compiler, TransformOutput},
common::{errors::ColorConfig, FileName, GLOBALS},
Expand Down Expand Up @@ -107,12 +108,14 @@ impl Task for TransformTask {
let cm = self.c.cm.clone();
let file = fm.clone();

let comments = SingleThreadedComments::default();
self.c.process_js_with_custom_pass(
fm,
None,
handler,
&options.swc,
|_, comments| {
comments.clone(),
|_| {
custom_before_pass(
cm,
file,
Expand All @@ -121,7 +124,7 @@ impl Task for TransformTask {
eliminated_packages.clone(),
)
},
|_, _| noop(),
|_| noop(),
)
})
},
Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/wasm/Cargo.toml
Expand Up @@ -17,15 +17,15 @@ plugin = [
]

[dependencies]
anyhow = "1.0.42"
anyhow = "1.0.66"
console_error_panic_hook = "0.1.6"
next-swc = {version = "0.0.0", path = "../core"}
once_cell = "1.13.0"
parking_lot_core = "=0.8.0"
path-clean = "0.1"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
tracing = { version = "0.1.32", features = ["release_max_level_off","max_level_off"] }
tracing = { version = "0.1.37", features = ["release_max_level_off","max_level_off"] }
wasm-bindgen = {version = "0.2", features = ["enable-interning"]}
wasm-bindgen-futures = "0.4.8"
getrandom = { version = "0.2.5", optional = true, default-features = false }
Expand All @@ -46,7 +46,7 @@ swc_core = { features = [
"ecma_parser_typescript",
"ecma_utils",
"ecma_visit"
], version = "0.40.16" }
], version = "0.40.40" }


# Workaround a bug
Expand Down
10 changes: 7 additions & 3 deletions packages/next-swc/crates/wasm/src/lib.rs
Expand Up @@ -8,7 +8,9 @@ use wasm_bindgen_futures::future_to_promise;
use swc_core::{
base::{config::JsMinifyOptions, config::ParseOptions, try_with_handler, Compiler},
common::{
comments::Comments, errors::ColorConfig, FileName, FilePathMapping, SourceMap, GLOBALS,
comments::{Comments, SingleThreadedComments},
errors::ColorConfig,
FileName, FilePathMapping, SourceMap, GLOBALS,
},
ecma::transforms::base::pass::noop,
};
Expand Down Expand Up @@ -84,12 +86,14 @@ pub fn transform_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
);
let cm = c.cm.clone();
let file = fm.clone();
let comments = SingleThreadedComments::default();
c.process_js_with_custom_pass(
fm,
None,
handler,
&opts.swc,
|_, comments| {
comments.clone(),
|_| {
custom_before_pass(
cm,
file,
Expand All @@ -98,7 +102,7 @@ pub fn transform_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
Default::default(),
)
},
|_, _| noop(),
|_| noop(),
)
.context("failed to process js file")?
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/next-swc.test.ts
Expand Up @@ -82,7 +82,7 @@ var ref = _slicedToArray(useState(0), 2), count = ref[0], setCount = ref[1];
expect(output).toMatchInlineSnapshot(`
"function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i1 = 0, arr2 = new Array(len); i1 < len; i1++)arr2[i1] = arr[i1];
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
Expand All @@ -95,7 +95,7 @@ function _nonIterableRest() {
throw new TypeError(\\"Invalid attempt to destructure non-iterable instance.\\\\\\\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\\");
}
function _toArray(arr) {
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
Expand Down

0 comments on commit 670f2a8

Please sign in to comment.