JavaScript Highlighter: Fix numbers starting with dot
This commit is contained in:
parent
7b54a18bcc
commit
7b090bcb4a
|
@ -295,8 +295,19 @@ class JavaScriptHighlighter {
|
|||
|
||||
private func consumeDotLookup() {
|
||||
consume() // .
|
||||
guard let char = peek() else { return }
|
||||
if identifierStarts.contains(char) {
|
||||
print("Dot lookup")
|
||||
emit(token: .punctuation, range: prevCharRange())
|
||||
consumeIdentifier()
|
||||
} else if CharacterSet.decimalDigits.contains(char) {
|
||||
let numberStart = text.index(before: currentIndex)
|
||||
while let char = peek(), CharacterSet.decimalDigits.contains(char) {
|
||||
consume()
|
||||
}
|
||||
print("Number: \(text[numberStart..<currentIndex])")
|
||||
emit(token: .number, range: range(from: numberStart, to: currentIndex))
|
||||
}
|
||||
}
|
||||
|
||||
private func consumeArray() {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
let source = "`$foo ${blah} bar`"
|
||||
let source = ".1 + .2"
|
||||
let highlighter = JavaScriptHighlighter(text: source)
|
||||
highlighter.debug = true
|
||||
highlighter.highlight()
|
||||
|
|
Loading…
Reference in New Issue