forked from babel/babel
/
no-undefined-identifier.cjs
39 lines (35 loc) · 1 KB
/
no-undefined-identifier.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const getReferenceOrigin = require("../utils/get-reference-origin.cjs");
const isFromBabelTypes = require("../utils/is-from-babel-types.cjs");
function firstArgumentIsUndefinedString(argumentsArray) {
return (
argumentsArray.length > 0 &&
argumentsArray[0].type === "Literal" &&
argumentsArray[0].value === "undefined"
);
}
module.exports = {
meta: {
schema: [],
},
create(context) {
return {
CallExpression(node) {
const { callee } = node;
const scope = context.getScope();
const origin = getReferenceOrigin(callee, scope);
if (!origin) return;
const { name } = origin;
if (
(name === "identifier" || name === "Identifier") &&
firstArgumentIsUndefinedString(node.arguments) &&
isFromBabelTypes(origin, scope)
) {
context.report(
node,
"Use path.scope.buildUndefinedNode() to create an undefined identifier directly.",
);
}
},
};
},
};