JavaScript Highlighter: disable debug prints by default

Este commit está contenido en:
Shadowfacts 2020-04-05 11:54:22 -04:00
padre 83cfba74a8
commit 7b54a18bcc
Firmado por: shadowfacts
ID de clave GPG: 94A5AB95422746E5
Se han modificado 2 ficheros con 8 adiciones y 4 borrados

Ver fichero

@ -27,6 +27,7 @@ class JavaScriptHighlighter {
private var currentIndex: String.Index!
private var indent = ""
private(set) var tokens = [(token: TokenType, range: NSRange)]()
var debug = false
init(text: String) {
self.text = text
@ -38,8 +39,10 @@ class JavaScriptHighlighter {
self.attributed = mutableAttributed
}
private func print(_ str: String) {
Swift.print("\(indent)\(str)")
private func print(_ str: @autoclosure () -> String) {
if debug {
Swift.print("\(indent)\(str())")
}
}
private func range(from: String.Index, to: String.Index) -> NSRange {

Ver fichero

@ -9,5 +9,6 @@
import Foundation
let source = "`$foo ${blah} bar`"
_ = JavaScriptHighlighter(text: source).highlight()
let highlighter = JavaScriptHighlighter(text: source)
highlighter.debug = true
highlighter.highlight()