diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 09:54:56 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 09:55:16 +0200 |
commit | a4b56e7b971fa81c56a59b465f90c8016f01320d (patch) | |
tree | 7002a44087e57c8158a51dd30b6eb89eb260af2b /src/parser.rs | |
parent | 1fd94f512834aa7bd70f22a60229ce01edfc754e (diff) | |
download | markdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.tar.gz markdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.tar.bz2 markdown-rs-a4b56e7b971fa81c56a59b465f90c8016f01320d.zip |
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`
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/parser.rs b/src/parser.rs index b694bc5..a7962d0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,6 +4,7 @@ use crate::event::{Event, Point}; use crate::state::{Name as StateName, State}; use crate::subtokenize::subtokenize; use crate::tokenizer::Tokenizer; +use crate::util::location::Location; use crate::ParseOptions; use alloc::{string::String, vec, vec::Vec}; @@ -14,6 +15,8 @@ use alloc::{string::String, vec, vec::Vec}; #[derive(Debug)] pub struct ParseState<'a> { /// Configuration. + pub location: Option<Location>, + /// Configuration. pub options: &'a ParseOptions, /// List of chars. pub bytes: &'a [u8], @@ -29,10 +32,17 @@ pub struct ParseState<'a> { pub fn parse<'a>( value: &'a str, options: &'a ParseOptions, -) -> Result<(Vec<Event>, &'a [u8]), String> { +) -> Result<(Vec<Event>, ParseState<'a>), String> { + let bytes = value.as_bytes(); + let mut parse_state = ParseState { options, - bytes: value.as_bytes(), + bytes, + location: if options.mdx_esm_parse.is_some() || options.mdx_expression_parse.is_some() { + Some(Location::new(bytes)) + } else { + None + }, definitions: vec![], gfm_footnote_definitions: vec![], }; @@ -72,5 +82,5 @@ pub fn parse<'a>( } } - Ok((events, parse_state.bytes)) + Ok((events, parse_state)) } |