📄 Referencer¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 67 |
| 🧱 Classes | 1 |
| 📦 Imports | 26 |
| 📐 Interfaces | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/scope-manager/src/referencer/Referencer.ts
📦 Imports¶
| Name | Source |
|---|---|
Lib |
@typescript-eslint/types |
TSESTree |
@typescript-eslint/types |
AST_NODE_TYPES |
@typescript-eslint/types |
GlobalScope |
../scope |
Scope |
../scope |
ScopeManager |
../ScopeManager |
LibDefinition |
../variable |
ReferenceImplicitGlobal |
./Reference |
VisitorOptions |
./Visitor |
assert |
../assert |
CatchClauseDefinition |
../definition |
FunctionNameDefinition |
../definition |
ImportBindingDefinition |
../definition |
ParameterDefinition |
../definition |
TSEnumMemberDefinition |
../definition |
TSEnumNameDefinition |
../definition |
TSModuleNameDefinition |
../definition |
VariableDefinition |
../definition |
TSLibraries |
../lib |
ClassVisitor |
./ClassVisitor |
ExportVisitor |
./ExportVisitor |
ImportVisitor |
./ImportVisitor |
PatternVisitor |
./PatternVisitor |
ReferenceFlag |
./Reference |
TypeVisitor |
./TypeVisitor |
Visitor |
./Visitor |
Functions¶
Referencer.populateGlobalsFromLib(globalScope: GlobalScope): void¶
Parameters:
globalScopeGlobalScope
Returns: void
Calls:
this.resolveLibDefinitionsglobalScope.defineImplicitVariable
Internal Comments:
Code
private populateGlobalsFromLib(globalScope: GlobalScope): void {
const libs = this.resolveLibDefinitions();
for (const lib of libs) {
for (const [name, variable] of lib.variables) {
globalScope.defineImplicitVariable(name, variable);
}
}
// Special implicit global for const assertions (`{} as const`, `<const>{}`)
globalScope.defineImplicitVariable('const', {
eslintImplicitGlobalSetting: 'readonly',
isTypeVariable: true,
isValueVariable: false,
});
}
Referencer.resolveLibDefinitions(): Set<LibDefinition>¶
Resolves lib names into a deduplicated set of LibDefinitions, including all transitive dependencies.
Raw JSDoc
Calls:
TSLibraries.getresolvedLibs.add
Internal Comments:
// Resolve the top-level lib names into LibDefinition objects
// Expand transitive lib dependencies.
// New entries added to the Set during iteration will be visited exactly once.
Code
private resolveLibDefinitions(): Set<LibDefinition> {
const resolvedLibs = new Set<LibDefinition>();
// Resolve the top-level lib names into LibDefinition objects
for (const lib of this.#lib) {
const definition = TSLibraries.get(lib);
if (!definition) {
throw new Error(`Invalid value for lib provided: ${lib}`);
}
resolvedLibs.add(definition);
}
// Expand transitive lib dependencies.
// New entries added to the Set during iteration will be visited exactly once.
for (const lib of resolvedLibs) {
for (const dependency of lib.libs) {
resolvedLibs.add(dependency);
}
}
return resolvedLibs;
}
Referencer.close(node: TSESTree.Node): void¶
Parameters:
nodeTSESTree.Node
Returns: void
Calls:
this.currentScopethis.currentScope().close
Code
Referencer.currentScope(): Scope¶
Returns: Scope
Referencer.referencingDefaultValue(…): void¶
Parameters:
patternTSESTree.Identifierassignments(TSESTree.AssignmentExpression | TSESTree.AssignmentPattern)[]maybeImplicitGlobalReferenceImplicitGlobal | nullinitboolean
Returns: void
Calls:
assignments.forEachthis.currentScope().referenceValue
Code
public referencingDefaultValue(
pattern: TSESTree.Identifier,
assignments: (TSESTree.AssignmentExpression | TSESTree.AssignmentPattern)[],
maybeImplicitGlobal: ReferenceImplicitGlobal | null,
init: boolean,
): void {
assignments.forEach(assignment => {
this.currentScope().referenceValue(
pattern,
ReferenceFlag.Write,
assignment.right,
maybeImplicitGlobal,
init,
);
});
}
Referencer.referenceInSomeUpperScope(name: string): boolean¶
Searches for a variable named "name" in the upper scopes and adds a pseudo-reference from itself to itself
Raw JSDoc
Calls:
scope.set.getscope.referenceValue
Code
Referencer.referenceJsxFragment(): void¶
Returns: void
Calls:
this.referenceInSomeUpperScope
Code
Referencer.referenceJsxPragma(): void¶
Returns: void
Calls:
this.referenceInSomeUpperScope
Code
Referencer.visitClass(node: TSESTree.ClassDeclaration | TSESTree.Cl…): void¶
Parameters:
nodeTSESTree.ClassDeclaration | TSESTree.ClassExpression
Returns: void
Calls:
ClassVisitor.visit
Code
Referencer.visitForIn(node: TSESTree.ForInStatement | TSESTree.ForO…): void¶
Parameters:
nodeTSESTree.ForInStatement | TSESTree.ForOfStatement
Returns: void
Calls:
this.scopeManager.nestForScopethis.visitthis.visitPatternthis.currentScope().referenceValuethis.currentScopethis.referencingDefaultValuethis.close
Code
protected visitForIn(
node: TSESTree.ForInStatement | TSESTree.ForOfStatement,
): void {
if (
node.left.type === AST_NODE_TYPES.VariableDeclaration &&
node.left.kind !== 'var'
) {
this.scopeManager.nestForScope(node);
}
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) {
this.visit(node.left);
this.visitPattern(node.left.declarations[0].id, pattern => {
this.currentScope().referenceValue(
pattern,
ReferenceFlag.Write,
node.right,
null,
true,
);
});
} else {
this.visitPattern(
node.left,
(pattern, info) => {
const maybeImplicitGlobal = !this.currentScope().isStrict
? {
node,
pattern,
}
: null;
this.referencingDefaultValue(
pattern,
info.assignments,
maybeImplicitGlobal,
false,
);
this.currentScope().referenceValue(
pattern,
ReferenceFlag.Write,
node.right,
maybeImplicitGlobal,
false,
);
},
{ processRightHandNodes: true },
);
}
this.visit(node.right);
this.visit(node.body);
this.close(node);
}
Referencer.visitFunction(node: | TSESTree.ArrowFunctionExpression | TS…): void¶
Parameters:
node| TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.TSDeclareFunction | TSESTree.TSEmptyBodyFunctionExpression
Returns: void
Calls:
this.scopeManager.nestFunctionExpressionNameScopethis.currentScope().defineIdentifierthis.scopeManager.nestFunctionScopethis.visitPatternthis.referencingDefaultValuethis.visitFunctionParameterTypeAnnotationparam.decorators.forEachthis.visitthis.visitTypethis.visitChildrenthis.close
Internal Comments:
// FunctionDeclaration name is defined in upper scope
// NOTE: Not referring variableScope. It is intended.
// Since
// in ES5, FunctionDeclaration should be in FunctionBody.
// in ES6, FunctionDeclaration should be block scoped.
// FunctionExpression with name creates its special scope; (x5)
// FunctionExpressionNameScope. (x5)
// id is defined in upper scope (x6)
// Consider this function is in the MethodDefinition. (x5)
// Process parameter declarations.
// In TypeScript there are a number of function-like constructs which have no body,
// so check it exists before traversing
// Skip BlockStatement to prevent creating BlockStatement scope.
Code
protected visitFunction(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression
| TSESTree.TSDeclareFunction
| TSESTree.TSEmptyBodyFunctionExpression,
): void {
// FunctionDeclaration name is defined in upper scope
// NOTE: Not referring variableScope. It is intended.
// Since
// in ES5, FunctionDeclaration should be in FunctionBody.
// in ES6, FunctionDeclaration should be block scoped.
if (node.type === AST_NODE_TYPES.FunctionExpression) {
if (node.id) {
// FunctionExpression with name creates its special scope;
// FunctionExpressionNameScope.
this.scopeManager.nestFunctionExpressionNameScope(node);
}
} else if (node.id) {
// id is defined in upper scope
this.currentScope().defineIdentifier(
node.id,
new FunctionNameDefinition(node.id, node),
);
}
// Consider this function is in the MethodDefinition.
this.scopeManager.nestFunctionScope(node, false);
// Process parameter declarations.
for (const param of node.params) {
this.visitPattern(
param,
(pattern, info) => {
this.currentScope().defineIdentifier(
pattern,
new ParameterDefinition(pattern, node, info.rest),
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
},
{ processRightHandNodes: true },
);
this.visitFunctionParameterTypeAnnotation(param);
param.decorators.forEach(d => this.visit(d));
}
this.visitType(node.returnType);
this.visitType(node.typeParameters);
// In TypeScript there are a number of function-like constructs which have no body,
// so check it exists before traversing
if (node.body) {
// Skip BlockStatement to prevent creating BlockStatement scope.
if (node.body.type === AST_NODE_TYPES.BlockStatement) {
this.visitChildren(node.body);
} else {
this.visit(node.body);
}
}
this.close(node);
}
Referencer.visitFunctionParameterTypeAnnotation(node: TSESTree.Parameter): void¶
Parameters:
nodeTSESTree.Parameter
Returns: void
Calls:
this.visitTypethis.visitFunctionParameterTypeAnnotation
Code
protected visitFunctionParameterTypeAnnotation(
node: TSESTree.Parameter,
): void {
switch (node.type) {
case AST_NODE_TYPES.AssignmentPattern:
this.visitType(node.left.typeAnnotation);
break;
case AST_NODE_TYPES.TSParameterProperty:
this.visitFunctionParameterTypeAnnotation(node.parameter);
break;
default:
this.visitType(node.typeAnnotation);
break;
}
}
Referencer.visitJSXElement(node: TSESTree.JSXClosingElement | TSESTree.J…): void¶
Parameters:
nodeTSESTree.JSXClosingElement | TSESTree.JSXOpeningElement
Returns: void
Calls:
node.name.name[0].toUpperCasethis.visit
Internal Comments:
// lower cased component names are always treated as "intrinsic" names, and are converted to a string, (x4)
// not a variable by JSX transforms: (x4)
// <div /> => React.createElement("div", null) (x4)
// the only case we want to visit a lower-cased component has its name as "this", (x4)
Code
protected visitJSXElement(
node: TSESTree.JSXClosingElement | TSESTree.JSXOpeningElement,
): void {
if (node.name.type === AST_NODE_TYPES.JSXIdentifier) {
if (
node.name.name[0].toUpperCase() === node.name.name[0] ||
node.name.name === 'this'
) {
// lower cased component names are always treated as "intrinsic" names, and are converted to a string,
// not a variable by JSX transforms:
// <div /> => React.createElement("div", null)
// the only case we want to visit a lower-cased component has its name as "this",
this.visit(node.name);
}
} else {
this.visit(node.name);
}
}
Referencer.visitProperty(node: TSESTree.Property): void¶
Parameters:
nodeTSESTree.Property
Returns: void
Calls:
this.visit
Code
Referencer.visitType(node: TSESTree.Node | null | undefined): void¶
Parameters:
nodeTSESTree.Node | null | undefined
Returns: void
Calls:
TypeVisitor.visit
Code
Referencer.visitTypeAssertion(node: | TSESTree.TSAsExpression | TSESTree.TS…): void¶
Parameters:
node| TSESTree.TSAsExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion
Returns: void
Calls:
this.visitthis.visitType
Code
Referencer.ArrowFunctionExpression(node: TSESTree.ArrowFunctionExpression): void¶
Parameters:
nodeTSESTree.ArrowFunctionExpression
Returns: void
Calls:
this.visitFunction
Code
Referencer.AssignmentExpression(node: TSESTree.AssignmentExpression): void¶
Parameters:
nodeTSESTree.AssignmentExpression
Returns: void
Calls:
this.visitExpressionTargetPatternVisitor.isPatternthis.visitPatternthis.currentScopethis.referencingDefaultValuethis.currentScope().referenceValuethis.visit
Code
protected AssignmentExpression(node: TSESTree.AssignmentExpression): void {
const left = this.visitExpressionTarget(node.left);
if (PatternVisitor.isPattern(left)) {
if (node.operator === '=') {
this.visitPattern(
left,
(pattern, info) => {
const maybeImplicitGlobal = !this.currentScope().isStrict
? {
node,
pattern,
}
: null;
this.referencingDefaultValue(
pattern,
info.assignments,
maybeImplicitGlobal,
false,
);
this.currentScope().referenceValue(
pattern,
ReferenceFlag.Write,
node.right,
maybeImplicitGlobal,
false,
);
},
{ processRightHandNodes: true },
);
} else if (left.type === AST_NODE_TYPES.Identifier) {
this.currentScope().referenceValue(
left,
ReferenceFlag.ReadWrite,
node.right,
);
}
} else {
this.visit(left);
}
this.visit(node.right);
}
Referencer.BlockStatement(node: TSESTree.BlockStatement): void¶
Parameters:
nodeTSESTree.BlockStatement
Returns: void
Calls:
this.scopeManager.nestBlockScopethis.visitChildrenthis.close
Code
Referencer.BreakStatement(): void¶
Returns: void
Referencer.CallExpression(node: TSESTree.CallExpression): void¶
Parameters:
nodeTSESTree.CallExpression
Returns: void
Calls:
this.visitChildrenthis.visitType
Code
Referencer.CatchClause(node: TSESTree.CatchClause): void¶
Parameters:
nodeTSESTree.CatchClause
Returns: void
Calls:
this.scopeManager.nestCatchScopethis.visitPatternthis.currentScope().defineIdentifierthis.referencingDefaultValuethis.visitthis.close
Code
protected CatchClause(node: TSESTree.CatchClause): void {
this.scopeManager.nestCatchScope(node);
if (node.param) {
this.visitPattern(
node.param,
(pattern, info) => {
this.currentScope().defineIdentifier(
pattern,
new CatchClauseDefinition(pattern, node),
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
},
{ processRightHandNodes: true },
);
}
this.visit(node.body);
this.close(node);
}
Referencer.ClassDeclaration(node: TSESTree.ClassDeclaration): void¶
Parameters:
nodeTSESTree.ClassDeclaration
Returns: void
Calls:
this.visitClass
Referencer.ClassExpression(node: TSESTree.ClassExpression): void¶
Parameters:
nodeTSESTree.ClassExpression
Returns: void
Calls:
this.visitClass
Referencer.ContinueStatement(): void¶
Returns: void
Referencer.ExportAllDeclaration(): void¶
Returns: void
Referencer.ExportDefaultDeclaration(node: TSESTree.ExportDefaultDeclaration): void¶
Parameters:
nodeTSESTree.ExportDefaultDeclaration
Returns: void
Calls:
ExportVisitor.visitthis.visit
Code
Referencer.ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void¶
Parameters:
nodeTSESTree.ExportNamedDeclaration
Returns: void
Calls:
this.visitExportVisitor.visit
Code
Referencer.ForInStatement(node: TSESTree.ForInStatement): void¶
Parameters:
nodeTSESTree.ForInStatement
Returns: void
Calls:
this.visitForIn
Referencer.ForOfStatement(node: TSESTree.ForOfStatement): void¶
Parameters:
nodeTSESTree.ForOfStatement
Returns: void
Calls:
this.visitForIn
Referencer.ForStatement(node: TSESTree.ForStatement): void¶
Parameters:
nodeTSESTree.ForStatement
Returns: void
Calls:
this.scopeManager.nestForScopethis.visitChildrenthis.close
Internal Comments:
// Create ForStatement declaration.
// NOTE: In ES6, ForStatement dynamically generates per iteration environment. However, this is
// a static analyzer, we only generate one scope for ForStatement.
Code
protected ForStatement(node: TSESTree.ForStatement): void {
// Create ForStatement declaration.
// NOTE: In ES6, ForStatement dynamically generates per iteration environment. However, this is
// a static analyzer, we only generate one scope for ForStatement.
if (
node.init?.type === AST_NODE_TYPES.VariableDeclaration &&
node.init.kind !== 'var'
) {
this.scopeManager.nestForScope(node);
}
this.visitChildren(node);
this.close(node);
}
Referencer.FunctionDeclaration(node: TSESTree.FunctionDeclaration): void¶
Parameters:
nodeTSESTree.FunctionDeclaration
Returns: void
Calls:
this.visitFunction
Code
Referencer.FunctionExpression(node: TSESTree.FunctionExpression): void¶
Parameters:
nodeTSESTree.FunctionExpression
Returns: void
Calls:
this.visitFunction
Code
Referencer.Identifier(node: TSESTree.Identifier): void¶
Parameters:
nodeTSESTree.Identifier
Returns: void
Calls:
this.currentScope().referenceValuethis.visitType
Code
Referencer.ImportAttribute(): void¶
Returns: void
Code
Referencer.ImportDeclaration(node: TSESTree.ImportDeclaration): void¶
Parameters:
nodeTSESTree.ImportDeclaration
Returns: void
Calls:
assert (from ../assert)this.scopeManager.isModuleImportVisitor.visit
Code
Referencer.JSXAttribute(node: TSESTree.JSXAttribute): void¶
Parameters:
nodeTSESTree.JSXAttribute
Returns: void
Calls:
this.visit
Referencer.JSXClosingElement(node: TSESTree.JSXClosingElement): void¶
Parameters:
nodeTSESTree.JSXClosingElement
Returns: void
Calls:
this.visitJSXElement
Code
Referencer.JSXFragment(node: TSESTree.JSXFragment): void¶
Parameters:
nodeTSESTree.JSXFragment
Returns: void
Calls:
this.referenceJsxPragmathis.referenceJsxFragmentthis.visitChildren
Code
Referencer.JSXIdentifier(node: TSESTree.JSXIdentifier): void¶
Parameters:
nodeTSESTree.JSXIdentifier
Returns: void
Calls:
this.currentScope().referenceValue
Code
Referencer.JSXMemberExpression(node: TSESTree.JSXMemberExpression): void¶
Parameters:
nodeTSESTree.JSXMemberExpression
Returns: void
Calls:
this.visit
Code
Referencer.JSXOpeningElement(node: TSESTree.JSXOpeningElement): void¶
Parameters:
nodeTSESTree.JSXOpeningElement
Returns: void
Calls:
this.referenceJsxPragmathis.visitJSXElementthis.visitTypethis.visit
Code
Referencer.LabeledStatement(node: TSESTree.LabeledStatement): void¶
Parameters:
nodeTSESTree.LabeledStatement
Returns: void
Calls:
this.visit
Referencer.MemberExpression(node: TSESTree.MemberExpression): void¶
Parameters:
nodeTSESTree.MemberExpression
Returns: void
Calls:
this.visit
Code
Referencer.MetaProperty(): void¶
Returns: void
Referencer.NewExpression(node: TSESTree.NewExpression): void¶
Parameters:
nodeTSESTree.NewExpression
Returns: void
Calls:
this.visitChildrenthis.visitType
Code
Referencer.PrivateIdentifier(): void¶
Returns: void
Code
Referencer.Program(node: TSESTree.Program): void¶
Parameters:
nodeTSESTree.Program
Returns: void
Calls:
this.scopeManager.nestGlobalScopethis.populateGlobalsFromLibthis.scopeManager.isGlobalReturnthis.currentScopethis.scopeManager.nestFunctionScopethis.scopeManager.isModulethis.scopeManager.nestModuleScopethis.scopeManager.isImpliedStrictthis.visitChildrenthis.close
Internal Comments:
Code
protected Program(node: TSESTree.Program): void {
const globalScope = this.scopeManager.nestGlobalScope(node);
this.populateGlobalsFromLib(globalScope);
if (this.scopeManager.isGlobalReturn()) {
// Force strictness of GlobalScope to false when using node.js scope.
this.currentScope().isStrict = false;
this.scopeManager.nestFunctionScope(node, false);
}
if (this.scopeManager.isModule()) {
this.scopeManager.nestModuleScope(node);
}
if (this.scopeManager.isImpliedStrict()) {
this.currentScope().isStrict = true;
}
this.visitChildren(node);
this.close(node);
}
Referencer.Property(node: TSESTree.Property): void¶
Parameters:
nodeTSESTree.Property
Returns: void
Calls:
this.visitProperty
Referencer.SwitchStatement(node: TSESTree.SwitchStatement): void¶
Parameters:
nodeTSESTree.SwitchStatement
Returns: void
Calls:
this.visitthis.scopeManager.nestSwitchScopethis.close
Code
Referencer.TaggedTemplateExpression(node: TSESTree.TaggedTemplateExpression): void¶
Parameters:
nodeTSESTree.TaggedTemplateExpression
Returns: void
Calls:
this.visitthis.visitType
Code
Referencer.TSAsExpression(node: TSESTree.TSAsExpression): void¶
Parameters:
nodeTSESTree.TSAsExpression
Returns: void
Calls:
this.visitTypeAssertion
Code
Referencer.TSDeclareFunction(node: TSESTree.TSDeclareFunction): void¶
Parameters:
nodeTSESTree.TSDeclareFunction
Returns: void
Calls:
this.visitFunction
Code
Referencer.TSEmptyBodyFunctionExpression(node: TSESTree.TSEmptyBodyFunctionExpression): void¶
Parameters:
nodeTSESTree.TSEmptyBodyFunctionExpression
Returns: void
Calls:
this.visitFunction
Code
Referencer.TSEnumDeclaration(node: TSESTree.TSEnumDeclaration): void¶
Parameters:
nodeTSESTree.TSEnumDeclaration
Returns: void
Calls:
this.currentScope().defineIdentifierthis.scopeManager.nestTSEnumScopethis.currentScope().defineLiteralIdentifierthis.visitthis.close
Internal Comments:
// enum members can be referenced within the enum body (x5)
// TS resolves literal named members to be actual names
// enum Foo {
// 'a' = 1,
// b = a, // this references the 'a' member
// }
Code
protected TSEnumDeclaration(node: TSESTree.TSEnumDeclaration): void {
this.currentScope().defineIdentifier(
node.id,
new TSEnumNameDefinition(node.id, node),
);
// enum members can be referenced within the enum body
this.scopeManager.nestTSEnumScope(node);
for (const member of node.body.members) {
// TS resolves literal named members to be actual names
// enum Foo {
// 'a' = 1,
// b = a, // this references the 'a' member
// }
if (
member.id.type === AST_NODE_TYPES.Literal &&
typeof member.id.value === 'string'
) {
const name = member.id;
this.currentScope().defineLiteralIdentifier(
name,
new TSEnumMemberDefinition(name, member),
);
} else if (member.id.type === AST_NODE_TYPES.Identifier) {
this.currentScope().defineIdentifier(
member.id,
new TSEnumMemberDefinition(member.id, member),
);
}
this.visit(member.initializer);
}
this.close(node);
}
Referencer.TSExportAssignment(node: TSESTree.TSExportAssignment): void¶
Parameters:
nodeTSESTree.TSExportAssignment
Returns: void
Calls:
this.currentScope().referenceDualValueTypethis.visit
Internal Comments:
// this is a special case - you can `export = T` where `T` is a type OR a (x6)
// value however `T[U]` is illegal when `T` is a type and `T.U` is illegal (x6)
// when `T.U` is a type (x6)
// i.e. if the expression is JUST an Identifier - it could be either ref (x6)
// kind; otherwise the standard rules apply (x6)
Code
protected TSExportAssignment(node: TSESTree.TSExportAssignment): void {
if (node.expression.type === AST_NODE_TYPES.Identifier) {
// this is a special case - you can `export = T` where `T` is a type OR a
// value however `T[U]` is illegal when `T` is a type and `T.U` is illegal
// when `T.U` is a type
// i.e. if the expression is JUST an Identifier - it could be either ref
// kind; otherwise the standard rules apply
this.currentScope().referenceDualValueType(node.expression);
} else {
this.visit(node.expression);
}
}
Referencer.TSImportEqualsDeclaration(node: TSESTree.TSImportEqualsDeclaration): void¶
Parameters:
nodeTSESTree.TSImportEqualsDeclaration
Returns: void
Calls:
this.currentScope().defineIdentifierthis.visit
Code
protected TSImportEqualsDeclaration(
node: TSESTree.TSImportEqualsDeclaration,
): void {
this.currentScope().defineIdentifier(
node.id,
new ImportBindingDefinition(node.id, node, node),
);
if (node.moduleReference.type === AST_NODE_TYPES.TSQualifiedName) {
let moduleIdentifier = node.moduleReference.left;
while (moduleIdentifier.type === AST_NODE_TYPES.TSQualifiedName) {
moduleIdentifier = moduleIdentifier.left;
}
this.visit(moduleIdentifier);
} else {
this.visit(node.moduleReference);
}
}
Referencer.TSInstantiationExpression(node: TSESTree.TSInstantiationExpression): void¶
Parameters:
nodeTSESTree.TSInstantiationExpression
Returns: void
Calls:
this.visitChildrenthis.visitType
Code
Referencer.TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration): void¶
Parameters:
nodeTSESTree.TSInterfaceDeclaration
Returns: void
Calls:
this.visitType
Code
Referencer.TSModuleDeclaration(node: TSESTree.TSModuleDeclaration): void¶
Parameters:
nodeTSESTree.TSModuleDeclaration
Returns: void
Calls:
this.currentScope().defineIdentifierthis.scopeManager.nestTSModuleScopethis.visitthis.close
Code
protected TSModuleDeclaration(node: TSESTree.TSModuleDeclaration): void {
if (node.id.type === AST_NODE_TYPES.Identifier && node.kind !== 'global') {
this.currentScope().defineIdentifier(
node.id,
new TSModuleNameDefinition(node.id, node),
);
}
this.scopeManager.nestTSModuleScope(node);
this.visit(node.body);
this.close(node);
}
Referencer.TSSatisfiesExpression(node: TSESTree.TSSatisfiesExpression): void¶
Parameters:
nodeTSESTree.TSSatisfiesExpression
Returns: void
Calls:
this.visitTypeAssertion
Code
Referencer.TSTypeAliasDeclaration(node: TSESTree.TSTypeAliasDeclaration): void¶
Parameters:
nodeTSESTree.TSTypeAliasDeclaration
Returns: void
Calls:
this.visitType
Code
Referencer.TSTypeAssertion(node: TSESTree.TSTypeAssertion): void¶
Parameters:
nodeTSESTree.TSTypeAssertion
Returns: void
Calls:
this.visitTypeAssertion
Code
Referencer.UpdateExpression(node: TSESTree.UpdateExpression): void¶
Parameters:
nodeTSESTree.UpdateExpression
Returns: void
Calls:
this.visitExpressionTargetPatternVisitor.isPatternthis.visitPatternthis.currentScope().referenceValuethis.visitChildren
Code
protected UpdateExpression(node: TSESTree.UpdateExpression): void {
const argument = this.visitExpressionTarget(node.argument);
if (PatternVisitor.isPattern(argument)) {
this.visitPattern(argument, pattern => {
this.currentScope().referenceValue(
pattern,
ReferenceFlag.ReadWrite,
null,
);
});
} else {
this.visitChildren(node);
}
}
Referencer.VariableDeclaration(node: TSESTree.VariableDeclaration): void¶
Parameters:
nodeTSESTree.VariableDeclaration
Returns: void
Calls:
this.currentScopethis.visitPatternvariableTargetScope.defineIdentifierthis.referencingDefaultValuethis.currentScope().referenceValuethis.visitthis.visitType
Code
protected VariableDeclaration(node: TSESTree.VariableDeclaration): void {
const variableTargetScope =
node.kind === 'var'
? this.currentScope().variableScope
: this.currentScope();
for (const decl of node.declarations) {
const init = decl.init;
this.visitPattern(
decl.id,
(pattern, info) => {
variableTargetScope.defineIdentifier(
pattern,
new VariableDefinition(pattern, decl, node),
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
if (init) {
this.currentScope().referenceValue(
pattern,
ReferenceFlag.Write,
init,
null,
true,
);
}
},
{ processRightHandNodes: true },
);
this.visit(decl.init);
this.visitType(decl.id.typeAnnotation);
}
}
Referencer.WithStatement(node: TSESTree.WithStatement): void¶
Parameters:
nodeTSESTree.WithStatement
Returns: void
Calls:
this.visitthis.scopeManager.nestWithScopethis.close
Internal Comments:
Code
Referencer.visitExpressionTarget(left: TSESTree.Node): Node¶
Parameters:
leftTSESTree.Node
Returns: Node
Calls:
this.visitType
Internal Comments:
// explicitly visit the type annotation (x4)
// intentional fallthrough
// unwrap the expression (x3)
Code
private visitExpressionTarget(left: TSESTree.Node) {
switch (left.type) {
case AST_NODE_TYPES.TSAsExpression:
case AST_NODE_TYPES.TSTypeAssertion:
// explicitly visit the type annotation
this.visitType(left.typeAnnotation);
// intentional fallthrough
case AST_NODE_TYPES.TSNonNullExpression:
// unwrap the expression
left = left.expression;
}
return left;
}
Classes¶
Referencer¶
Extends: Visitor
Methods (69) — full entries under Functions
| Method | Signature |
|---|---|
populateGlobalsFromLib |
(globalScope: GlobalScope): void |
resolveLibDefinitions |
(): Set<LibDefinition> |
close |
(node: TSESTree.Node): void |
currentScope |
(): Scope |
currentScope |
(throwOnNull: true): Scope \| null |
currentScope |
(dontThrowOnNull: true): Scope \| null |
referencingDefaultValue |
(pattern: TSESTree.Identifier, assignments: (TSESTree.AssignmentExpression \| TSESTree.Assignment... |
referenceInSomeUpperScope |
(name: string): boolean |
referenceJsxFragment |
(): void |
referenceJsxPragma |
(): void |
visitClass |
(node: TSESTree.ClassDeclaration \| TSESTree.ClassExpression): void |
visitForIn |
(node: TSESTree.ForInStatement \| TSESTree.ForOfStatement): void |
visitFunction |
(node: \| TSESTree.ArrowFunctionExpression \| TSESTree.FunctionDeclaration \| TSESTree.FunctionEx... |
visitFunctionParameterTypeAnnotation |
(node: TSESTree.Parameter): void |
visitJSXElement |
(node: TSESTree.JSXClosingElement \| TSESTree.JSXOpeningElement): void |
visitProperty |
(node: TSESTree.Property): void |
visitType |
(node: TSESTree.Node \| null \| undefined): void |
visitTypeAssertion |
(node: \| TSESTree.TSAsExpression \| TSESTree.TSSatisfiesExpression \| TSESTree.TSTypeAssertion):... |
ArrowFunctionExpression |
(node: TSESTree.ArrowFunctionExpression): void |
AssignmentExpression |
(node: TSESTree.AssignmentExpression): void |
BlockStatement |
(node: TSESTree.BlockStatement): void |
BreakStatement |
(): void |
CallExpression |
(node: TSESTree.CallExpression): void |
CatchClause |
(node: TSESTree.CatchClause): void |
ClassDeclaration |
(node: TSESTree.ClassDeclaration): void |
ClassExpression |
(node: TSESTree.ClassExpression): void |
ContinueStatement |
(): void |
ExportAllDeclaration |
(): void |
ExportDefaultDeclaration |
(node: TSESTree.ExportDefaultDeclaration): void |
ExportNamedDeclaration |
(node: TSESTree.ExportNamedDeclaration): void |
ForInStatement |
(node: TSESTree.ForInStatement): void |
ForOfStatement |
(node: TSESTree.ForOfStatement): void |
ForStatement |
(node: TSESTree.ForStatement): void |
FunctionDeclaration |
(node: TSESTree.FunctionDeclaration): void |
FunctionExpression |
(node: TSESTree.FunctionExpression): void |
Identifier |
(node: TSESTree.Identifier): void |
ImportAttribute |
(): void |
ImportDeclaration |
(node: TSESTree.ImportDeclaration): void |
JSXAttribute |
(node: TSESTree.JSXAttribute): void |
JSXClosingElement |
(node: TSESTree.JSXClosingElement): void |
JSXFragment |
(node: TSESTree.JSXFragment): void |
JSXIdentifier |
(node: TSESTree.JSXIdentifier): void |
JSXMemberExpression |
(node: TSESTree.JSXMemberExpression): void |
JSXOpeningElement |
(node: TSESTree.JSXOpeningElement): void |
LabeledStatement |
(node: TSESTree.LabeledStatement): void |
MemberExpression |
(node: TSESTree.MemberExpression): void |
MetaProperty |
(): void |
NewExpression |
(node: TSESTree.NewExpression): void |
PrivateIdentifier |
(): void |
Program |
(node: TSESTree.Program): void |
Property |
(node: TSESTree.Property): void |
SwitchStatement |
(node: TSESTree.SwitchStatement): void |
TaggedTemplateExpression |
(node: TSESTree.TaggedTemplateExpression): void |
TSAsExpression |
(node: TSESTree.TSAsExpression): void |
TSDeclareFunction |
(node: TSESTree.TSDeclareFunction): void |
TSEmptyBodyFunctionExpression |
(node: TSESTree.TSEmptyBodyFunctionExpression): void |
TSEnumDeclaration |
(node: TSESTree.TSEnumDeclaration): void |
TSExportAssignment |
(node: TSESTree.TSExportAssignment): void |
TSImportEqualsDeclaration |
(node: TSESTree.TSImportEqualsDeclaration): void |
TSInstantiationExpression |
(node: TSESTree.TSInstantiationExpression): void |
TSInterfaceDeclaration |
(node: TSESTree.TSInterfaceDeclaration): void |
TSModuleDeclaration |
(node: TSESTree.TSModuleDeclaration): void |
TSSatisfiesExpression |
(node: TSESTree.TSSatisfiesExpression): void |
TSTypeAliasDeclaration |
(node: TSESTree.TSTypeAliasDeclaration): void |
TSTypeAssertion |
(node: TSESTree.TSTypeAssertion): void |
UpdateExpression |
(node: TSESTree.UpdateExpression): void |
VariableDeclaration |
(node: TSESTree.VariableDeclaration): void |
WithStatement |
(node: TSESTree.WithStatement): void |
visitExpressionTarget |
(left: TSESTree.Node): Node |
Interfaces¶
ReferencerOptions¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
jsxFragmentName |
string \| null |
✗ | not shown |
jsxPragma |
string \| null |
✗ | not shown |
lib |
Lib[] |
✗ | not shown |
Generated by Syntax Scribe