Skip to content

Commit

Permalink
fix: regression - panic analyzing dynamic imports in jsdocs (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Nov 26, 2024
1 parent 765c6ea commit 684eb1a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,13 +832,16 @@ fn parse_jsdoc_dynamic_import(input: &str) -> monch::ParseResult<JsDocImport> {
use monch::*;
let original_input = input;
let (mut input, _) = ch('{')(input)?;
for (index, c) in input.char_indices() {
if c == '}' {
return ParseError::backtrace();
}
input = &original_input[index..];
if input.starts_with("import") {
break;
{
let original_input = input;
for (index, c) in input.char_indices() {
if c == '}' {
return ParseError::backtrace();
}
input = &original_input[index..];
if input.starts_with("import") {
break;
}
}
}
let (input, _) = tag("import")(input)?;
Expand Down Expand Up @@ -1559,6 +1562,7 @@ export {};

assert!(parse_jsdoc_dynamic_import("{ import('testing') }").is_ok());
assert!(parse_jsdoc_dynamic_import("{ Test<import('testing')> }").is_ok());
assert!(parse_jsdoc_dynamic_import("{ * // … test }").is_err());
assert_eq!(
parse_resolution_mode(
r#"{Set<import("./e.js", { with: { "resolution-mode": "require" } }).F>}"#
Expand Down

0 comments on commit 684eb1a

Please sign in to comment.