Plugin panics when trying to read line number from SourceMapper

I've got a plugin where part of the logic involves reading the current line number:
pub struct MyVisitor {
// Provided by in from TransformPluginProgramMetadata
source_map: Arc<dyn SourceMapper>,
}

impl MyVisitor {
fn my_fn(&mut self, node: &mut Expr) -> Result<(), Box<SpanLinesError>> {
let line_num = self
.source_map
.span_to_lines(node.span())
.map(|lines| lines.lines[0])?;

// also using `self.source_map.span_to_snippet` and that part works okay
}
}
pub struct MyVisitor {
// Provided by in from TransformPluginProgramMetadata
source_map: Arc<dyn SourceMapper>,
}

impl MyVisitor {
fn my_fn(&mut self, node: &mut Expr) -> Result<(), Box<SpanLinesError>> {
let line_num = self
.source_map
.span_to_lines(node.span())
.map(|lines| lines.lines[0])?;

// also using `self.source_map.span_to_snippet` and that part works okay
}
}
This is working okay for tests, but I'm trying to run the plugin via the @swc/cli - npx swc /* input file */ and it's panicking:
Returned value should be serializable: wasm plugin bytecheck failed "check bytes error: check failed for tuple struct member 0: check failed for enum tuple variant Ok: check failed for tuple struct member 0: check failed for struct member file: check failed for enum tuple variant Some: check failed for tuple struct member 0: check failed for struct member lazy: invalid tag for enum: 180"
Returned value should be serializable: wasm plugin bytecheck failed "check bytes error: check failed for tuple struct member 0: check failed for enum tuple variant Ok: check failed for tuple struct member 0: check failed for struct member file: check failed for enum tuple variant Some: check failed for tuple struct member 0: check failed for struct member lazy: invalid tag for enum: 180"
I know it's the line_number lookup that's breaking it because I replace that with let line_num = 0; and it works. The two things I'm seeing from the error are 1. swc_core version issue or 2. wasi vs wasm issue But for #1, I believe the versions I'm using are compatible: * @swc/cli - 0.5.0 * @swc/core - 1.9.1 * swc_core - 4.0.3 * swc_plugin_runner - 4.0.0 And looking at the compat table, if I'm reading this right, the @swc/core version is in range https://plugins.swc.rs/versions/range/19.
(The error message points me at https://plugins.swc.rs/versions/from-plugin-runner/4.0.0 but it's a dead link) And #2, I'm doing cargo build --target wasm32-wasip1 and pointing at target/wasm32-wasip1/debug/my_plugin.wasm which seems like it should be the wasi version.
Compat Range
Compat ranges for swc_core
8 Replies
Retsam19
Retsam19OP3w ago
If anyone can look at this, I've put it up on github with a script for reproducing it:
git clone -b swc-panic-repro [email protected]:Retsam/power-assert-swc.git && cd power-assert-swc && ./compile-and-test
git clone -b swc-panic-repro [email protected]:Retsam/power-assert-swc.git && cd power-assert-swc && ./compile-and-test
Retsam19
Retsam19OP3w ago
Or here's the full error as a text file
Retsam19
Retsam19OP2w ago
@kdy1 I did see that issue, but wasn't that fixed in 1.9.0? I'm on 1.9.1 and still seeing a panic. (Also tried 1.9.3 just to be sure but still seeing it)
kdy1
kdy12w ago
You are using wrong version of swc_core
Retsam19
Retsam19OP2w ago
Am I reading the compatibility table wrong? I selected the version of @swc/core and it showed swc_core @4.0.0 - * so I thought 4.x was the right version
kdy1
kdy12w ago
No I forgot adding 5.x, but at least 4.x cannot work due to the issue
Retsam19
Retsam19OP2w ago
Okay, yeah, that seems to fix it. Thanks!
Want results from more Discord servers?
Add your server