Files
codeql/javascript/ql/test/query-tests/Expressions/MissingAwait/tst.js
Asger F 87ed86e4fd JS: Update UnusedOrUndefinedStateProperty
Using RelatedLocations to add clarity
2025-02-28 13:29:18 +01:00

76 lines
1.3 KiB
JavaScript

async function getThing() {
return something();
}
function useThing() {
let thing = getThing();
if (thing === undefined) {} // $ Alert
if (thing == null) {} // $ Alert
something(thing ? 1 : 2); // $ Alert
for (let x in thing) { // $ Alert
something(x);
}
let obj = something();
something(obj[thing]); // $ Alert
obj[thing] = 5; // $ Alert
something(thing + "bar"); // $ Alert
if (something()) {
if (thing) { // $ Alert
something(3);
}
}
}
async function useThingCorrectly() {
let thing = await getThing();
if (thing === undefined) {}
if (thing == null) {}
return thing + "bar";
}
async function useThingCorrectly2() {
let thing = getThing();
if (await thing === undefined) {}
if (await thing == null) {}
return thing + "bar"; // $ Alert
}
function getThingSync() {
return something();
}
function useThingPossiblySync(b) {
let thing = b ? getThing() : getThingSync();
if (thing === undefined) {}
if (thing == null) {}
return thing + "bar"; // $ MISSING: Alert
}
function useThingInVoid() {
void getThing();
}
function useThing() {
if (random()) {
return getThing() ?? null; // $ Alert
} else {
return getThing?.() ?? null;
}
}