Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
// visit decorators that are in: ClassDeclaration / ClassExpression
var { visitClass } = referencer.prototype;
referencer.prototype.visitClass = function(node) {
visitDecorators.call(this, node);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// visit flow type: ClassImplements
if (node.implements) {
for (var i = 0; i < node.implements.length; i++) {
checkIdentifierOrVisit.call(this, node.implements[i]);
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
}
createScopeVariable.call(this, node, node.id);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// TODO: Handle mixins
for (var i = 0; i < node.extends.length; i++) {
visitTypeAnnotation.call(this, node.extends[i]);
}
visitTypeAnnotation.call(this, node.body);
if (typeParamScope) {
this.close(node);
}
};
referencer.prototype.TypeAlias = function(node) {
createScopeVariable.call(this, node, node.id);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.right) {
visitTypeAnnotation.call(this, node.right);
}
if (typeParamScope) {
this.close(node);
}
};
referencer.prototype.DeclareModule = referencer.prototype.DeclareFunction = referencer.prototype.DeclareVariable = referencer.prototype.DeclareClass = function(
node
) {
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
}
visitClass.call(this, node);
if (typeParamScope) {
this.close(node);
}
};
// visit decorators that are in: Property / MethodDefinition
var { visitProperty } = referencer.prototype;
referencer.prototype.visitProperty = function(node) {
if (node.value && node.value.type === 'TypeCastExpression') {
visitTypeAnnotation.call(this, node.value);
}
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
if (node.value && node.value.type === 'TypeCastExpression') {
visitTypeAnnotation.call(this, node.value);
}
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
// visit ClassPrivateProperty as a Property.
referencer.prototype.ClassPrivateProperty = visitClassProperty;
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
var { visitFunction } = referencer.prototype;
referencer.prototype.visitFunction = function(node) {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.returnType) {
checkIdentifierOrVisit.call(this, node.returnType);
}
// only visit if function parameters have types
if (node.params) {
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
// visit ClassPrivateProperty as a Property.
referencer.prototype.ClassPrivateProperty = visitClassProperty;
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
var { visitFunction } = referencer.prototype;
referencer.prototype.visitFunction = function(node) {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.returnType) {
checkIdentifierOrVisit.call(this, node.returnType);
}
// only visit if function parameters have types
if (node.params) {
for (var i = 0; i < node.params.length; i++) {
var param = node.params[i];
if (param.typeAnnotation) {
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;
}
// visit decorators that are in: ClassDeclaration / ClassExpression
var { visitClass } = referencer.prototype;
referencer.prototype.visitClass = function(node) {
visitDecorators.call(this, node);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// visit flow type: ClassImplements
if (node.implements) {
for (var i = 0; i < node.implements.length; i++) {
checkIdentifierOrVisit.call(this, node.implements[i]);
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
}
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;
}
// visit decorators that are in: ClassDeclaration / ClassExpression
var { visitClass } = referencer.prototype;
referencer.prototype.visitClass = function(node) {
visitDecorators.call(this, node);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// visit flow type: ClassImplements
if (node.implements) {
for (var i = 0; i < node.implements.length; i++) {
checkIdentifierOrVisit.call(this, node.implements[i]);
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
referencer.prototype.TypeAlias = function(node) {
createScopeVariable.call(this, node, node.id);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.right) {
visitTypeAnnotation.call(this, node.right);
}
if (typeParamScope) {
this.close(node);
}
};
referencer.prototype.DeclareModule = referencer.prototype.DeclareFunction = referencer.prototype.DeclareVariable = referencer.prototype.DeclareClass = function(
node
) {
if (node.id) {
createScopeVariable.call(this, node, node.id);
}
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (typeParamScope) {
this.close(node);
}
};
}