JavaScript Highlighter: disable debug prints by default

This commit is contained in:
Shadowfacts 2020-04-05 11:54:22 -04:00
父節點 83cfba74a8
當前提交 7b54a18bcc
簽署人: shadowfacts
GPG Key ID: 94A5AB95422746E5
共有 2 個文件被更改,包括 8 次插入4 次删除

查看文件

@ -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 {

查看文件

@ -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()