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

Function visitClassDeclaration

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

Source from the content-addressed store, hash-verified

92047 || ts.some(node.members, hasTypeScriptClassSyntax);
92048 }
92049 function visitClassDeclaration(node) {
92050 if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && ts.hasSyntacticModifier(node, 1 /* ModifierFlags.Export */))) {
92051 return ts.visitEachChild(node, visitor, context);
92052 }
92053 var staticProperties = ts.getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true);
92054 var facts = getClassFacts(node, staticProperties);
92055 if (facts & 128 /* ClassFacts.UseImmediatelyInvokedFunctionExpression */) {
92056 context.startLexicalEnvironment();
92057 }
92058 var name = node.name || (facts & 5 /* ClassFacts.NeedsName */ ? factory.getGeneratedNameForNode(node) : undefined);
92059 var classStatement = facts & 2 /* ClassFacts.HasConstructorDecorators */
92060 ? createClassDeclarationHeadWithDecorators(node, name)
92061 : createClassDeclarationHeadWithoutDecorators(node, name, facts);
92062 var statements = [classStatement];
92063 // Write any decorators of the node.
92064 addClassElementDecorationStatements(statements, node, /*isStatic*/ false);
92065 addClassElementDecorationStatements(statements, node, /*isStatic*/ true);
92066 addConstructorDecorationStatement(statements, node);
92067 if (facts & 128 /* ClassFacts.UseImmediatelyInvokedFunctionExpression */) {
92068 // When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the
92069 // 'es2015' transformer can properly nest static initializers and decorators. The result
92070 // looks something like:
92071 //
92072 // var C = function () {
92073 // class C {
92074 // }
92075 // C.static_prop = 1;
92076 // return C;
92077 // }();
92078 //
92079 var closingBraceLocation = ts.createTokenRange(ts.skipTrivia(currentSourceFile.text, node.members.end), 19 /* SyntaxKind.CloseBraceToken */);
92080 var localName = factory.getInternalName(node);
92081 // The following partially-emitted expression exists purely to align our sourcemap
92082 // emit with the original emitter.
92083 var outer = factory.createPartiallyEmittedExpression(localName);
92084 ts.setTextRangeEnd(outer, closingBraceLocation.end);
92085 ts.setEmitFlags(outer, 1536 /* EmitFlags.NoComments */);
92086 var statement = factory.createReturnStatement(outer);
92087 ts.setTextRangePos(statement, closingBraceLocation.pos);
92088 ts.setEmitFlags(statement, 1536 /* EmitFlags.NoComments */ | 384 /* EmitFlags.NoTokenSourceMaps */);
92089 statements.push(statement);
92090 ts.insertStatementsAfterStandardPrologue(statements, context.endLexicalEnvironment());
92091 var iife = factory.createImmediatelyInvokedArrowFunction(statements);
92092 ts.setEmitFlags(iife, 33554432 /* EmitFlags.TypeScriptClassWrapper */);
92093 var varStatement = factory.createVariableStatement(
92094 /*modifiers*/ undefined, factory.createVariableDeclarationList([
92095 factory.createVariableDeclaration(factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false),
92096 /*exclamationToken*/ undefined,
92097 /*type*/ undefined, iife)
92098 ]));
92099 ts.setOriginalNode(varStatement, node);
92100 ts.setCommentRange(varStatement, node);
92101 ts.setSourceMapRange(varStatement, ts.moveRangePastDecorators(node));
92102 ts.startOnNewLine(varStatement);
92103 statements = [varStatement];
92104 }
92105 // If the class is exported as part of a TypeScript namespace, emit the namespace export.
92106 // Otherwise, if the class was exported at the top level and was decorated, emit an export

Callers 5

visitTypeScriptFunction · 0.85
visitClassLikeFunction · 0.85
visitorWorkerFunction · 0.85
topLevelVisitorFunction · 0.85
topLevelNestedVisitorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…