Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TSModuleDeclaration(node) {
const astRoot = this.scopeManager.globalScope.block;
const scope = this.currentScope();
const { id, body } = node;
// https://github.com/JamesHenry/typescript-estree/issues/27
if (isGlobalAugmentation(node, astRoot.tokens)) {
this.visitGlobalAugmentation(node);
return;
}
if (id && id.type === "Identifier") {
scope.__define(
id,
new Definition("NamespaceName", id, node, null, null, null)
);
}
this.visit(body);
}
TSEnumMember(node) {
const { id, initializer } = node;
const scope = this.currentScope();
scope.__define(id, new Definition("EnumMemberName", id, node));
// Set `eslintUsed` flag to the defined variable because the enum member is obviously exported.
const variable = scope.set.get(id.name);
variable.eslintUsed = true;
if (initializer) {
scope.__referencing(
id,
Reference.WRITE,
initializer,
null,
false,
true
);
this.visit(initializer);
}
TSEmptyBodyFunctionDeclaration(node) {
const upperTypeMode = this.typeMode;
const scope = this.currentScope();
const { id, typeParameters, params, returnType } = node;
// Ignore this if other overloadings have already existed.
const variable = scope.set.get(id.name);
const defs = variable && variable.defs;
const existed = defs && defs.some(d => d.type === "FunctionName");
if (!existed) {
scope.__define(
id,
new Definition("FunctionName", id, node, null, null, null)
);
}
// Find `typeof` expressions.
this.typeMode = true;
this.visit(typeParameters);
params.forEach(this.visit, this);
this.visit(returnType);
this.typeMode = upperTypeMode;
}
TSEmptyBodyDeclareFunction(node) {
return null;
}
const parentScope = this.scopeManager.__currentScope;
const scope = new escope.Scope(
this.scopeManager,
"type-parameters",
parentScope,
node,
false,
);
this.scopeManager.__nestScope(scope);
for (let j = 0; j < node.typeParameters.params.length; j++) {
const name = node.typeParameters.params[j];
scope.__define(name, new Definition("TypeParameter", name, name));
if (name.typeAnnotation) {
this._checkIdentifierOrVisit(name);
}
}
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);
};
return scope;
}
TSEnumDeclaration(node) {
const { id, members } = node;
const scopeManager = this.scopeManager;
const scope = this.currentScope();
if (id) {
scope.__define(id, new Definition("EnumName", id, node));
}
scopeManager.__nestScope(new EnumScope(scopeManager, scope, node));
for (const member of members) {
this.visit(member);
}
this.close(node);
}
function nestTypeParamScope(manager, node) {
var parentScope = manager.__currentScope;
var scope = new escope.Scope(
manager,
'type-parameters',
parentScope,
node,
false
);
manager.__nestScope(scope);
for (var j = 0; j < node.typeParameters.params.length; j++) {
var name = node.typeParameters.params[j];
scope.__define(name, new Definition('TypeParameter', name, name));
if (name.typeAnnotation) {
checkIdentifierOrVisit.call(this, name);
}
}
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);
};
return scope;
}
_createScopeVariable(node, name) {
this.currentScope().variableScope.__define(
name,
new Definition("Variable", name, node, null, null, null),
);
}
function createScopeVariable(node, name) {
this.currentScope().variableScope.__define(
name,
new Definition('Variable', name, node, null, null, null)
);
}