Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: panicked at crates/oxc_span/src/span.rs:394:21 #9298

Closed
Dunqing opened this issue Feb 23, 2025 · 3 comments
Closed

wasm: panicked at crates/oxc_span/src/span.rs:394:21 #9298

Dunqing opened this issue Feb 23, 2025 · 3 comments
Assignees
Labels
C-bug Category - Bug

Comments

@Dunqing
Copy link
Member

Dunqing commented Feb 23, 2025

panicked at crates/oxc_span/src/span.rs:394:21:
byte index 20 is not a char boundary; it is inside '😢' (bytes 17..21) of const A /* Hello 😢 */ = 0;

Reproduction

Code like:

const A /* Hello 😢 */ = 0;
  1. Open the Playground
  2. Error shown in the console
@Dunqing Dunqing added the C-bug Category - Bug label Feb 23, 2025
@Boshen
Copy link
Member

Boshen commented Feb 23, 2025

I made a mistake here, I called convert ast pritor to converting comments

fn convert_ast(&mut self, program: &mut Program) {
Utf8ToUtf16::new().convert(program);
self.ast_json = program.to_pretty_estree_ts_json();
self.comments = Self::map_comments(program.source_text, &program.comments);
}
fn map_comments(source_text: &str, comments: &[OxcComment]) -> Vec<Comment> {
comments
.iter()
.map(|comment| Comment {
r#type: match comment.kind {
CommentKind::Line => CommentType::Line,
CommentKind::Block => CommentType::Block,
},
value: comment.content_span().source_text(source_text).to_string(),
start: comment.span.start,
end: comment.span.end,
})
.collect()
}

@Boshen
Copy link
Member

Boshen commented Feb 23, 2025

I think we should move comment serialization into to_estree_json, and remove the separated out comments field from napi and wasm output.

Acorn doesn't have a comments array output, but we can conform it to typescript eslint estree

"comments": [
    {
      "type": "Block",
      "value": " asdf ",
      "range": [
        0,
        10
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 10
        }
      }
    }
  ]

@Boshen Boshen changed the title panicked at crates/oxc_span/src/span.rs:394:21 wasm: panicked at crates/oxc_span/src/span.rs:394:21 Feb 23, 2025
@Boshen
Copy link
Member

Boshen commented Feb 26, 2025

Fixed in #9349

@Boshen Boshen closed this as completed Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug
Projects
None yet
Development

No branches or pull requests

3 participants