MCPcopy Index your code
hub / github.com/nodejs/node / checkSuperExpression

Function checkSuperExpression

test/fixtures/snapshot/typescript.js:72127–72323  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

72125 return !!ts.findAncestor(node, function (n) { return ts.isFunctionLikeDeclaration(n) ? "quit" : n.kind === 164 /* SyntaxKind.Parameter */ && n.parent === constructorDecl; });
72126 }
72127 function checkSuperExpression(node) {
72128 var isCallExpression = node.parent.kind === 208 /* SyntaxKind.CallExpression */ && node.parent.expression === node;
72129 var immediateContainer = ts.getSuperContainer(node, /*stopOnFunctions*/ true);
72130 var container = immediateContainer;
72131 var needToCaptureLexicalThis = false;
72132 // adjust the container reference in case if super is used inside arrow functions with arbitrarily deep nesting
72133 if (!isCallExpression) {
72134 while (container && container.kind === 214 /* SyntaxKind.ArrowFunction */) {
72135 container = ts.getSuperContainer(container, /*stopOnFunctions*/ true);
72136 needToCaptureLexicalThis = languageVersion < 2 /* ScriptTarget.ES2015 */;
72137 }
72138 }
72139 var canUseSuperExpression = isLegalUsageOfSuperExpression(container);
72140 var nodeCheckFlag = 0;
72141 if (!canUseSuperExpression) {
72142 // issue more specific error if super is used in computed property name
72143 // class A { foo() { return "1" }}
72144 // class B {
72145 // [super.foo()]() {}
72146 // }
72147 var current = ts.findAncestor(node, function (n) { return n === container ? "quit" : n.kind === 162 /* SyntaxKind.ComputedPropertyName */; });
72148 if (current && current.kind === 162 /* SyntaxKind.ComputedPropertyName */) {
72149 error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
72150 }
72151 else if (isCallExpression) {
72152 error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
72153 }
72154 else if (!container || !container.parent || !(ts.isClassLike(container.parent) || container.parent.kind === 205 /* SyntaxKind.ObjectLiteralExpression */)) {
72155 error(node, ts.Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions);
72156 }
72157 else {
72158 error(node, ts.Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
72159 }
72160 return errorType;
72161 }
72162 if (!isCallExpression && immediateContainer.kind === 171 /* SyntaxKind.Constructor */) {
72163 checkThisBeforeSuper(node, container, ts.Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class);
72164 }
72165 if (ts.isStatic(container) || isCallExpression) {
72166 nodeCheckFlag = 512 /* NodeCheckFlags.SuperStatic */;
72167 if (!isCallExpression &&
72168 languageVersion >= 2 /* ScriptTarget.ES2015 */ && languageVersion <= 8 /* ScriptTarget.ES2021 */ &&
72169 (ts.isPropertyDeclaration(container) || ts.isClassStaticBlockDeclaration(container))) {
72170 // for `super.x` or `super[x]` in a static initializer, mark all enclosing
72171 // block scope containers so that we can report potential collisions with
72172 // `Reflect`.
72173 ts.forEachEnclosingBlockScopeContainer(node.parent, function (current) {
72174 if (!ts.isSourceFile(current) || ts.isExternalOrCommonJsModule(current)) {
72175 getNodeLinks(current).flags |= 134217728 /* NodeCheckFlags.ContainsSuperPropertyInStaticInitializer */;
72176 }
72177 });
72178 }
72179 }
72180 else {
72181 nodeCheckFlag = 256 /* NodeCheckFlags.SuperInstance */;
72182 }
72183 getNodeLinks(node).flags |= nodeCheckFlag;
72184 // Due to how we emit async functions, we need to specialize the emit for an async method that contains a `super` reference.

Callers 3

getTypeOfDottedNameFunction · 0.85
resolveCallExpressionFunction · 0.85
checkExpressionWorkerFunction · 0.85

Calls 11

checkThisBeforeSuperFunction · 0.85
getNodeLinksFunction · 0.85
captureLexicalThisFunction · 0.85
getDeclaredTypeOfSymbolFunction · 0.85
getSymbolOfNodeFunction · 0.85
getBaseTypesFunction · 0.85
getTypeWithThisArgumentFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…