Skip to content
Merged
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
232 changes: 116 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,24 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }

# SWC crates
swc_core = { version = "34", features = [
swc_core = { version = "35.0.0", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
"parallel_rayon",
] }
swc_plugin_backend_wasmer = { version = "1.0.0" }
testing = "15.0.0"

# Keep consistent with preset_env_base through swc_core
browserslist-rs = "0.19.0"
mdxjs = "1.0.3"
modularize_imports = "0.93.0"
styled_components = "0.121.0"
styled_jsx = "0.97.0"
swc_emotion = "0.97.0"
swc_relay = "0.67.0"
react_remove_properties = "0.47.0"
remove_console = "0.48.0"
modularize_imports = "0.93.1"
styled_components = "0.121.1"
styled_jsx = "0.97.1"
swc_emotion = "0.97.1"
swc_relay = "0.67.1"
react_remove_properties = "0.47.1"
remove_console = "0.48.1"
preset_env_base = "5.0.0"


Expand Down
1 change: 1 addition & 0 deletions crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugin = [
"swc_core/plugin_transform_host_native",
"swc_core/plugin_transform_host_native_filesystem_cache",
"swc_core/plugin_transform_host_native_shared_runtime",
"swc_core/plugin_backend_wasmer",
"next-custom-transforms/plugin",
"next-core/plugin",
"turbopack-ecmascript-plugins",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl ModularizeImportsTransformer {
skip_default_conversion: v.skip_default_conversion,
handle_default_import: false,
handle_namespace_import: false,
style: None,
}),
)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/next-custom-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ remove_console = { workspace = true }
preset_env_base = { workspace = true }

[dev-dependencies]
swc_core = { workspace = true, features = ["testing_transform"] }
swc_core = { workspace = true, features = ["testing_transform", "plugin_backend_wasmer"] }
testing = { workspace = true }
25 changes: 10 additions & 15 deletions test/development/acceptance-app/error-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/server/page.js (2:26)
"source": "./app/server/page.js (2:28)
Parsing ecmascript source code failed
> 2 | return <p>Hello world</p>
| ^",
| ^",
"stack": [],
}
`)
Expand All @@ -160,7 +160,6 @@ describe('Error recovery app', () => {
,-[2:1]
1 | export default function Page() {
2 | return <p>Hello world</p>
: ^
\`----
Caused by:
Syntax Error
Expand Down Expand Up @@ -206,10 +205,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/client/page.js (2:26)
"source": "./app/client/page.js (2:28)
Parsing ecmascript source code failed
> 2 | return <p>Hello world</p>
| ^",
| ^",
"stack": [],
}
`)
Expand All @@ -224,7 +223,6 @@ describe('Error recovery app', () => {
,-[2:1]
1 | export default function Page() {
2 | return <p>Hello world</p>
: ^
\`----
Caused by:
Syntax Error
Expand Down Expand Up @@ -623,10 +621,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (10:39)
"source": "./index.js (10:42)
Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() {
| ^",
| ^",
"stack": [],
}
`)
Expand All @@ -640,7 +638,6 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>'
,-[10:1]
10 | export default function FunctionNamed() {
: ^
\`----
Caused by:
Syntax Error
Expand All @@ -660,10 +657,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (10:39)
"source": "./index.js (10:42)
Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() {
| ^",
| ^",
"stack": [],
}
`)
Expand All @@ -677,7 +674,6 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>'
,-[10:1]
10 | export default function FunctionNamed() {
: ^
\`----
Caused by:
Syntax Error
Expand Down Expand Up @@ -1016,10 +1012,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (1:2)
"source": "./app/page.js (1:4)
Parsing ecmascript source code failed
> 1 | {{{
| ^",
| ^",
"stack": [],
}
`)
Expand All @@ -1033,7 +1029,6 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>'
,----
1 | {{{
: ^
\`----
Caused by:
Syntax Error",
Expand Down
10 changes: 4 additions & 6 deletions test/development/acceptance/error-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ describe('pages/ error recovery', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (7:39)
"source": "./index.js (7:42)
Parsing ecmascript source code failed
> 7 | export default function FunctionNamed() {
| ^",
| ^",
"stack": [],
}
`)
Expand Down Expand Up @@ -886,7 +886,6 @@ describe('pages/ error recovery', () => {
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
\`----
Caused by:
Syntax Error
Expand All @@ -908,10 +907,10 @@ describe('pages/ error recovery', () => {
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (7:39)
"source": "./index.js (7:42)
Parsing ecmascript source code failed
> 7 | export default function FunctionNamed() {
| ^",
| ^",
"stack": [],
}
`)
Expand Down Expand Up @@ -954,7 +953,6 @@ describe('pages/ error recovery', () => {
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
Comment on lines 955 to -957
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc now reports an error for a position that is actually after the last character in the source file (i.e. points at the imaginary EOF character). Seems like the Webpack codeframe printer doesn't handle that? @eps1lon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with how build errors work. Iirc they go through a completely separate codepath.

\`----
Caused by:
Syntax Error
Expand Down
2 changes: 2 additions & 0 deletions turbopack/crates/turbopack-ecmascript-plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ transform_emotion = []
swc_ecma_transform_plugin = [
"swc_core/plugin_transform_host_native",
"swc_core/plugin_transform_host_native_shared_runtime",
"swc_plugin_backend_wasmer"
]

[lints]
Expand All @@ -40,6 +41,7 @@ modularize_imports = { workspace = true }
styled_components = { workspace = true }
styled_jsx = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast", "ecma_visit", "common"] }
swc_plugin_backend_wasmer = { workspace = true, optional = true }
swc_emotion = { workspace = true }
swc_relay = { workspace = true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ModularizeImportsTransformer {
skip_default_conversion: v.skip_default_conversion,
handle_default_import: false,
handle_namespace_import: false,
style: None,
}),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use turbopack_ecmascript::{CustomTransformer, TransformContext};
/// cost of the compilation.
#[turbo_tasks::value(serialization = "none", eq = "manual", into = "new", cell = "new")]
pub struct SwcPluginModule(
#[turbo_tasks(trace_ignore)]
#[turbo_tasks(trace_ignore, debug_ignore)]
#[cfg(feature = "swc_ecma_transform_plugin")]
pub swc_core::plugin_runner::plugin_module_bytes::CompiledPluginModuleBytes,
// Dummy field to avoid turbo_tasks macro complaining about empty struct.
Expand All @@ -28,15 +28,15 @@ impl SwcPluginModule {
pub fn new(plugin_name: &str, plugin_bytes: Vec<u8>) -> Self {
#[cfg(feature = "swc_ecma_transform_plugin")]
{
Self({
use swc_core::plugin_runner::plugin_module_bytes::{
CompiledPluginModuleBytes, RawPluginModuleBytes,
};
CompiledPluginModuleBytes::from(RawPluginModuleBytes::new(
plugin_name.to_string(),
plugin_bytes,
))
})
use swc_core::plugin_runner::plugin_module_bytes::{
CompiledPluginModuleBytes, RawPluginModuleBytes,
};
use swc_plugin_backend_wasmer::WasmerRuntime;

Self(CompiledPluginModuleBytes::from_raw_module(
&WasmerRuntime,
RawPluginModuleBytes::new(plugin_name.to_string(), plugin_bytes),
))
}

#[cfg(not(feature = "swc_ecma_transform_plugin"))]
Expand Down Expand Up @@ -132,19 +132,22 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
},
ecma::ast::Module,
plugin::proxies::{COMMENTS, HostCommentsStorage},
plugin_runner::plugin_module_bytes::PluginModuleBytes,
};

let mut plugins = vec![];
for (plugin_module, config) in &self.plugins {
let plugin_module = &plugin_module.await?.0;

plugins.push((
plugin_module.get_module_name().to_string(),
config.clone(),
Box::new(plugin_module.clone()),
));
}
use swc_plugin_backend_wasmer::WasmerRuntime;
use turbo_tasks::TryJoinIterExt;

let plugins = self
.plugins
.iter()
.map(async |(plugin_module, config)| {
let plugin_module = plugin_module.await?;
Ok((
config.clone(),
Box::new(plugin_module.0.clone_module(&WasmerRuntime)),
))
})
.try_join()
.await?;

let should_enable_comments_proxy =
!ctx.comments.leading.is_empty() && !ctx.comments.trailing.is_empty();
Expand Down Expand Up @@ -199,9 +202,7 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
// Note: This doesn't mean plugin won't perform any se/deserialization: it
// still have to construct from raw bytes internally to perform actual
// transform.
for (_plugin_name, plugin_config, plugin_module) in plugins.drain(..) {
let runtime =
swc_core::plugin_runner::wasix_runtime::build_wasi_runtime(None);
for (plugin_config, plugin_module) in plugins {
let mut transform_plugin_executor =
swc_core::plugin_runner::create_plugin_transform_executor(
ctx.source_map,
Expand All @@ -210,7 +211,7 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
None,
plugin_module,
Some(plugin_config),
runtime,
Arc::new(WasmerRuntime),
);

serialized_program = transform_plugin_executor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ impl Analyzer<'_> {

// We cannot analyze recursive IIFE
if let Some(ident) = ident
&& contains_ident_ref(&function.body, &ident.to_id())
&& contains_ident_ref(&function.body, ident)
{
return false;
}
Expand Down
Loading