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

Function visitEnumDeclaration

test/fixtures/snapshot/typescript.js:93439–93498  ·  view source on GitHub ↗

* Visits an enum declaration. * * This function will be called any time a TypeScript enum is encountered. * * @param node The enum declaration node.

(node)

Source from the content-addressed store, hash-verified

93437 * @param node The enum declaration node.
93438 */
93439 function visitEnumDeclaration(node) {
93440 if (!shouldEmitEnumDeclaration(node)) {
93441 return factory.createNotEmittedStatement(node);
93442 }
93443 var statements = [];
93444 // We request to be advised when the printer is about to print this node. This allows
93445 // us to set up the correct state for later substitutions.
93446 var emitFlags = 2 /* EmitFlags.AdviseOnEmitNode */;
93447 // If needed, we should emit a variable declaration for the enum. If we emit
93448 // a leading variable declaration, we should not emit leading comments for the
93449 // enum body.
93450 var varAdded = addVarForEnumOrModuleDeclaration(statements, node);
93451 if (varAdded) {
93452 // We should still emit the comments if we are emitting a system module.
93453 if (moduleKind !== ts.ModuleKind.System || currentLexicalScope !== currentSourceFile) {
93454 emitFlags |= 512 /* EmitFlags.NoLeadingComments */;
93455 }
93456 }
93457 // `parameterName` is the declaration name used inside of the enum.
93458 var parameterName = getNamespaceParameterName(node);
93459 // `containerName` is the expression used inside of the enum for assignments.
93460 var containerName = getNamespaceContainerName(node);
93461 // `exportName` is the expression used within this node's container for any exported references.
93462 var exportName = ts.hasSyntacticModifier(node, 1 /* ModifierFlags.Export */)
93463 ? factory.getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true)
93464 : factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
93465 // x || (x = {})
93466 // exports.x || (exports.x = {})
93467 var moduleArg = factory.createLogicalOr(exportName, factory.createAssignment(exportName, factory.createObjectLiteralExpression()));
93468 if (hasNamespaceQualifiedExportName(node)) {
93469 // `localName` is the expression used within this node's containing scope for any local references.
93470 var localName = factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
93471 // x = (exports.x || (exports.x = {}))
93472 moduleArg = factory.createAssignment(localName, moduleArg);
93473 }
93474 // (function (x) {
93475 // x[x["y"] = 0] = "y";
93476 // ...
93477 // })(x || (x = {}));
93478 var enumStatement = factory.createExpressionStatement(factory.createCallExpression(factory.createFunctionExpression(
93479 /*modifiers*/ undefined,
93480 /*asteriskToken*/ undefined,
93481 /*name*/ undefined,
93482 /*typeParameters*/ undefined, [factory.createParameterDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)],
93483 /*type*/ undefined, transformEnumBody(node, containerName)),
93484 /*typeArguments*/ undefined, [moduleArg]));
93485 ts.setOriginalNode(enumStatement, node);
93486 if (varAdded) {
93487 // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement.
93488 ts.setSyntheticLeadingComments(enumStatement, undefined);
93489 ts.setSyntheticTrailingComments(enumStatement, undefined);
93490 }
93491 ts.setTextRange(enumStatement, node);
93492 ts.addEmitFlags(enumStatement, emitFlags);
93493 statements.push(enumStatement);
93494 // Add a DeclarationMarker for the enum to preserve trailing comments and mark
93495 // the end of the declaration.
93496 statements.push(factory.createEndOfDeclarationMarker(node));

Callers 1

visitTypeScriptFunction · 0.85

Calls 7

transformEnumBodyFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…