From a4b56e7b971fa81c56a59b465f90c8016f01320d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 11 Oct 2022 09:54:56 +0200 Subject: Add support for proper positional info in swc tree * Fix some positional info in SWC error messages * Add positional info in `to_document` on duplicate layouts * Add support for `path` on `Program` (`to_swc`, `to_document`, `jsx_rewrite`), for the path of a file on disk * Add support for `development` to `jsx-rewrite`, which when defined will embed info on where tags were written into the runtime code when they are not passed * Refactor to move some utilities to `micromark_swc_utils.rs`, `swc_utils.rs` --- src/construct/mdx_esm.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/construct/mdx_esm.rs') diff --git a/src/construct/mdx_esm.rs b/src/construct/mdx_esm.rs index 53f8beb..4fb6b50 100644 --- a/src/construct/mdx_esm.rs +++ b/src/construct/mdx_esm.rs @@ -31,10 +31,7 @@ use crate::event::Name; use crate::state::{Name as StateName, State}; use crate::tokenizer::Tokenizer; -use crate::util::{ - mdx_collect::{collect, place_to_point}, - slice::Slice, -}; +use crate::util::{mdx_collect::collect, slice::Slice}; use crate::MdxSignal; use alloc::format; @@ -197,16 +194,24 @@ fn parse_esm(tokenizer: &mut Tokenizer) -> State { // Collect the body of the ESM and positional info for each run of it. let result = collect( - tokenizer, + &tokenizer.events, + tokenizer.parse_state.bytes, tokenizer.tokenize_state.start, &[Name::MdxEsmData, Name::LineEnding], + &[], ); // Parse and handle what was signaled back. match parse(&result.value) { MdxSignal::Ok => State::Ok, - MdxSignal::Error(message, place) => { - let point = place_to_point(&result, place); + MdxSignal::Error(message, relative) => { + let point = tokenizer + .parse_state + .location + .as_ref() + .expect("expected location index if aware mdx is on") + .relative_to_point(&result.stops, relative) + .expect("expected non-empty string"); State::Error(format!("{}:{}: {}", point.line, point.column, message)) } MdxSignal::Eof(message) => { -- cgit