Unnamed repository; edit this file 'description' to name the repository.
fix: panic when split float numbers in scientific notation
roife 2024-03-06
parent 52d8ae7 · commit 03420c3
-rw-r--r--crates/parser/src/shortcuts.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/parser/src/shortcuts.rs b/crates/parser/src/shortcuts.rs
index 680a70997d..2beb3c3ef0 100644
--- a/crates/parser/src/shortcuts.rs
+++ b/crates/parser/src/shortcuts.rs
@@ -190,7 +190,7 @@ impl Builder<'_, '_> {
fn do_float_split(&mut self, has_pseudo_dot: bool) {
let text = &self.lexed.range_text(self.pos..self.pos + 1);
- self.pos += 1;
+
match text.split_once('.') {
Some((left, right)) => {
assert!(!left.is_empty());
@@ -216,8 +216,26 @@ impl Builder<'_, '_> {
self.state = State::PendingExit;
}
}
- None => unreachable!(),
+ None => {
+ // illegal float literal which doesn't have dot in form (like 1e0)
+ // we should emit an error node here
+ (self.sink)(StrStep::Error { msg: "illegal float literal", pos: self.pos });
+ (self.sink)(StrStep::Enter { kind: SyntaxKind::ERROR });
+ (self.sink)(StrStep::Token { kind: SyntaxKind::FLOAT_NUMBER, text: text });
+ (self.sink)(StrStep::Exit);
+
+ // move up
+ (self.sink)(StrStep::Exit);
+
+ self.state = if has_pseudo_dot {
+ State::Normal
+ } else {
+ State::PendingExit
+ };
+ }
}
+
+ self.pos += 1;
}
}