Fix ReferenceError
This commit is contained in:
Родитель
025892d959
Коммит
1b66ea9184
|
@ -2272,6 +2272,15 @@ var utils_1 = require("./utils");
|
|||
var rule_1 = require("./rule");
|
||||
var matcher_1 = require("./matcher");
|
||||
var debug_1 = require("./debug");
|
||||
var performanceNow = (function () {
|
||||
if (typeof performance === 'undefined') {
|
||||
// performance.now() is not available in this environment, so use Date.now()
|
||||
return function () { return Date.now(); };
|
||||
}
|
||||
else {
|
||||
return function () { return performance.now(); };
|
||||
}
|
||||
})();
|
||||
function createGrammar(grammar, initialLanguage, embeddedLanguages, tokenTypes, grammarRepository, onigLib) {
|
||||
return new Grammar(grammar, initialLanguage, embeddedLanguages, tokenTypes, grammarRepository, onigLib); //TODO
|
||||
}
|
||||
|
@ -2829,8 +2838,16 @@ function matchInjections(injections, grammar, lineText, isFirstLine, linePos, st
|
|||
function matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPosition) {
|
||||
var rule = stack.getRule(grammar);
|
||||
var ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos === anchorPosition);
|
||||
var perfStart = 0;
|
||||
if (debug_1.DebugFlags.InDebugMode) {
|
||||
perfStart = performanceNow();
|
||||
}
|
||||
var r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
|
||||
if (debug_1.DebugFlags.InDebugMode) {
|
||||
var elapsedMillis = performanceNow() - perfStart;
|
||||
if (elapsedMillis > 5) {
|
||||
console.warn("Rule " + rule.debugName + " (" + rule.id + ") matching took " + elapsedMillis + " against '" + lineText + "'");
|
||||
}
|
||||
// console.log(` scanning for (linePos: ${linePos}, anchorPosition: ${anchorPosition})`);
|
||||
// console.log(debugCompiledRuleToString(ruleScanner));
|
||||
if (r) {
|
||||
|
|
|
@ -11,9 +11,14 @@ import { DebugFlags } from './debug';
|
|||
import { FontStyle, ThemeTrieElementRule } from './theme';
|
||||
|
||||
declare let performance: { now: () => number } | undefined;
|
||||
if (typeof process !== 'undefined' && process.release.name === 'node') {
|
||||
performance = require('perf_hooks').performance;
|
||||
}
|
||||
const performanceNow = (function() {
|
||||
if (typeof performance === 'undefined') {
|
||||
// performance.now() is not available in this environment, so use Date.now()
|
||||
return () => Date.now();
|
||||
} else {
|
||||
return () => performance!.now();
|
||||
}
|
||||
})();
|
||||
|
||||
export const enum TemporaryStandardTokenType {
|
||||
Other = 0,
|
||||
|
@ -710,18 +715,16 @@ function matchRule(grammar: Grammar, lineText: OnigString, isFirstLine: boolean,
|
|||
const ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos === anchorPosition);
|
||||
|
||||
let perfStart = 0;
|
||||
if (DebugFlags.InDebugMode && performance) {
|
||||
perfStart = performance.now();
|
||||
if (DebugFlags.InDebugMode) {
|
||||
perfStart = performanceNow();
|
||||
}
|
||||
|
||||
const r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
|
||||
|
||||
if (DebugFlags.InDebugMode) {
|
||||
if (performance) {
|
||||
const timeMillis = performance.now() - perfStart;
|
||||
if (timeMillis > 5) {
|
||||
console.warn(`Rule ${rule.debugName} (${rule.id}) matching took ${timeMillis} against '${lineText}'`);
|
||||
}
|
||||
const elapsedMillis = performanceNow() - perfStart;
|
||||
if (elapsedMillis > 5) {
|
||||
console.warn(`Rule ${rule.debugName} (${rule.id}) matching took ${elapsedMillis} against '${lineText}'`);
|
||||
}
|
||||
// console.log(` scanning for (linePos: ${linePos}, anchorPosition: ${anchorPosition})`);
|
||||
// console.log(debugCompiledRuleToString(ruleScanner));
|
||||
|
|
Загрузка…
Ссылка в новой задаче