Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Program() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
const trackMap = {
RegExp: { [CALL]: true, [CONSTRUCT]: true }
};
for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
const flagsNode = node.arguments[1];
const flags = getStringIfConstant(flagsNode, scope);
if (!flagsNode || (typeof flags === "string" && !flags.includes("u"))) {
context.report({ node, messageId: "requireUFlag" });
}
}
}
};
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
const references = tracker.iterateGlobalReferences({
require: {
[CALL]: true,
resolve: { [CALL]: true },
},
})
for (const { node } of references) {
const targetNode = node.arguments[0]
const rawName = getStringIfConstant(targetNode)
const name = rawName && stripImportPathParams(rawName)
if (name && (includeCore || !resolve.isCore(name))) {
targets.push(new ImportTarget(targetNode, name, options))
}
}
callback(targets)
},
}
Program() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
const traceMap = {
RegExp: {
[CALL]: true,
[CONSTRUCT]: true
}
};
for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
const regex = getStringIfConstant(node.arguments[0]);
const flags = getStringIfConstant(node.arguments[1]);
if (regex) {
checkRegex(regex, node, flags && flags.includes("u"));
}
}
}
};
"Program"() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
/*
* Iterate calls of RegExp.
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
* `const {RegExp: a} = window; new a()`, etc...
*/
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true }
})) {
const [patternNode, flagsNode] = node.arguments;
const pattern = getStringIfConstant(patternNode, scope);
const flags = getStringIfConstant(flagsNode, scope);
if (typeof pattern === "string") {
verify(node, pattern, flags || "");
}
}
}
};
"Program"() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
/*
* Iterate calls of RegExp.
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
* `const {RegExp: a} = window; new a()`, etc...
*/
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true }
})) {
const [patternNode, flagsNode] = node.arguments;
const pattern = getStringIfConstant(patternNode, scope);
const flags = getStringIfConstant(flagsNode, scope);
if (typeof pattern === "string") {
verify(node, pattern, flags || "");
}
}
}
};
"Program"() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
/*
* Iterate calls of RegExp.
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
* `const {RegExp: a} = window; new a()`, etc...
*/
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true }
})) {
const [patternNode, flagsNode] = node.arguments;
const pattern = getStringIfConstant(patternNode, scope);
const flags = getStringIfConstant(flagsNode, scope);
if (typeof pattern === "string") {
verify(node, pattern, flags || "");
}
}
}
};
"Program"() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
/*
* Iterate calls of RegExp.
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
* `const {RegExp: a} = window; new a()`, etc...
*/
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true }
})) {
const [patternNode, flagsNode] = node.arguments;
const pattern = getStringIfConstant(patternNode, scope);
const flags = getStringIfConstant(flagsNode, scope);
if (typeof pattern === "string") {
verify(node, pattern, flags || "");
}
}
}
};
*getRegExpCalls(globalScope) {
const tracker = new ReferenceTracker(globalScope)
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true },
})) {
const [patternNode, flagsNode] = node.arguments
yield {
node,
pattern: getStringIfConstant(patternNode, globalScope),
flags: getStringIfConstant(flagsNode, globalScope),
}
}
},
}
*getRegExpCalls(globalScope) {
const tracker = new ReferenceTracker(globalScope)
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true },
})) {
const [patternNode, flagsNode] = node.arguments
yield {
node,
pattern: getStringIfConstant(patternNode, globalScope),
flags: getStringIfConstant(flagsNode, globalScope),
}
}
},
}
Program() {
const scope = context.getScope();
const tracker = new ReferenceTracker(scope);
const traceMap = {
RegExp: {
[CALL]: true,
[CONSTRUCT]: true
}
};
for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
const regex = getStringIfConstant(node.arguments[0]);
const flags = getStringIfConstant(node.arguments[1]);
if (regex) {
checkRegex(regex, node, flags && flags.includes("u"));
}
}
}
};