Retsam19
Retsam19
SDSWC Developers
Created by Retsam19 on 11/18/2024 in #questions
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.
9 replies