Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.emitter = new Emitter()
this.repository = null
this.initialRule = null
this.rawPatterns = patterns
this.rawRepository = repository
if (injectionSelector) {
this.injectionSelector = new ScopeSelector(injectionSelector)
} else {
this.injectionSelector = null
}
if (firstLineMatch) {
this.firstLineRegex = new OnigRegExp(firstLineMatch)
} else {
this.firstLineRegex = null
}
if (!this.fileTypes) { this.fileTypes = [] }
this.includedGrammarScopes = []
// Create last since Injections uses APIs from this class
this.injections = new Injections(this, injections)
}
FilterGrok.prototype.expandGrokPattern = function(regex, extra_patterns) {
var offset = 0;
var reduced = regex;
var result;
var grokFinder = new OnigRegExp('%{[^}]+}');
var grokParts = new RegExp('%{([^:]+):?(.*)}');
while ((result = grokFinder.searchSync(regex, offset))) {
offset = result[0].end;
var grokExp = result[0].match;
var parts = grokExp.match(grokParts);
var p = global_patterns[parts[1]] || extra_patterns[parts[1]];
if (p) {
if (parts[2].length > 0) {
this.fields.push(parts[2]);
}
var reg = this.expandGrokPattern(p, extra_patterns);
if (parts[2].length > 0) {
// create a named capturing group
reg = '(?<' + parts[2] + '>' + reg + ')';
if (value === undefined) return "undefined";
if (value === null) return "null";
if (value.constructor == OnigString) return value;
return value.toString();
};
OnigScanner.prototype.convertToNumber = function(value) {
value = parseInt(value);
if (!isFinite(value)) {
value = 0;
}
value = Math.max(value, 0);
return value;
};
OnigString.prototype.substring = function(start, end) {
return this.content.substring(start, end);
};
OnigString.prototype.toString = function(start, end) {
return this.content;
};
Object.defineProperty(OnigString.prototype, "length", {
get() {
return this.content.length;
},
// https://github.com/facebook/jest/issues/3552
configurable: true,
});
// exports.OnigScanner = OnigScanner
if (!isFinite(value)) {
value = 0;
}
value = Math.max(value, 0);
return value;
};
OnigString.prototype.substring = function(start, end) {
return this.content.substring(start, end);
};
OnigString.prototype.toString = function(start, end) {
return this.content;
};
Object.defineProperty(OnigString.prototype, "length", {
get() {
return this.content.length;
},
// https://github.com/facebook/jest/issues/3552
configurable: true,
});
// exports.OnigScanner = OnigScanner
// exports.OnigRegExp = OnigRegExp
// exports.OnigString = OnigString
return { OnigScanner, OnigRegExp, OnigString };
});
/* eslint-enable */
};
OnigScanner.prototype.convertToNumber = function(value) {
value = parseInt(value);
if (!isFinite(value)) {
value = 0;
}
value = Math.max(value, 0);
return value;
};
OnigString.prototype.substring = function(start, end) {
return this.content.substring(start, end);
};
OnigString.prototype.toString = function(start, end) {
return this.content;
};
Object.defineProperty(OnigString.prototype, "length", {
get() {
return this.content.length;
},
// https://github.com/facebook/jest/issues/3552
configurable: true,
});
// exports.OnigScanner = OnigScanner
// exports.OnigRegExp = OnigRegExp
// exports.OnigString = OnigString
return { OnigScanner, OnigRegExp, OnigString };
});
jest.doMock("oniguruma", function mockOniguruma() {
// https://github.com/atom/node-oniguruma/blob/3664b41e615697a3abd3b13e67226d177fa4143b/src/oniguruma.js
// with just "configurable: true" on Object.defineProperty
"use strict";
const OnigScanner = require("oniguruma/build/Release/onig_scanner.node")
.OnigScanner;
const OnigString = require("oniguruma/build/Release/onig_scanner.node")
.OnigString;
function OnigRegExp(source) {
this.source = source;
this.scanner = new OnigScanner([this.source]);
}
OnigRegExp.prototype.captureIndicesForMatch = function(string, match) {
var capture, captureIndices, i, len;
if (match != null) {
captureIndices = match.captureIndices;
string = this.scanner.convertToString(string);
for (i = 0, len = captureIndices.length; i < len; i++) {
capture = captureIndices[i];
capture.match = string.slice(capture.start, capture.end);
}
pattern => new oniguruma.OnigRegExp(pattern)
);
constructor(patterns, recorder) {
this.onigScanner = new oniguruma.OnigScanner(patterns);
this.regexps = patterns.map(
pattern => new oniguruma.OnigRegExp(pattern)
);
this.patterns = patterns;
this.recorder = recorder;
}
/**
t.parseSync = function(str) {
if (!t.regexp) {
t.regexp = new OnigRegExp(t.resolved);
}
var result = t.regexp.searchSync(str);
if(!result)
return null;
var r = {};
result.forEach(function(item, index) {
var field = t.fields[index];
if(field && item.match) {
r[field] = item.match;
}
});
regexForPattern(pattern) {
if (pattern) {
if (!this.regexesByPattern[pattern]) {
this.regexesByPattern[pattern] = new OnigRegExp(pattern);
}
return this.regexesByPattern[pattern];
}
}