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

Function getModuleInstanceStateWorker

test/fixtures/snapshot/typescript.js:44560–44631  ·  view source on GitHub ↗
(node, visited)

Source from the content-addressed store, hash-verified

44558 return result;
44559 }
44560 function getModuleInstanceStateWorker(node, visited) {
44561 // A module is uninstantiated if it contains only
44562 switch (node.kind) {
44563 // 1. interface declarations, type alias declarations
44564 case 258 /* SyntaxKind.InterfaceDeclaration */:
44565 case 259 /* SyntaxKind.TypeAliasDeclaration */:
44566 return 0 /* ModuleInstanceState.NonInstantiated */;
44567 // 2. const enum declarations
44568 case 260 /* SyntaxKind.EnumDeclaration */:
44569 if (ts.isEnumConst(node)) {
44570 return 2 /* ModuleInstanceState.ConstEnumOnly */;
44571 }
44572 break;
44573 // 3. non-exported import declarations
44574 case 266 /* SyntaxKind.ImportDeclaration */:
44575 case 265 /* SyntaxKind.ImportEqualsDeclaration */:
44576 if (!(ts.hasSyntacticModifier(node, 1 /* ModifierFlags.Export */))) {
44577 return 0 /* ModuleInstanceState.NonInstantiated */;
44578 }
44579 break;
44580 // 4. Export alias declarations pointing at only uninstantiated modules or things uninstantiated modules contain
44581 case 272 /* SyntaxKind.ExportDeclaration */:
44582 var exportDeclaration = node;
44583 if (!exportDeclaration.moduleSpecifier && exportDeclaration.exportClause && exportDeclaration.exportClause.kind === 273 /* SyntaxKind.NamedExports */) {
44584 var state = 0 /* ModuleInstanceState.NonInstantiated */;
44585 for (var _i = 0, _a = exportDeclaration.exportClause.elements; _i < _a.length; _i++) {
44586 var specifier = _a[_i];
44587 var specifierState = getModuleInstanceStateForAliasTarget(specifier, visited);
44588 if (specifierState > state) {
44589 state = specifierState;
44590 }
44591 if (state === 1 /* ModuleInstanceState.Instantiated */) {
44592 return state;
44593 }
44594 }
44595 return state;
44596 }
44597 break;
44598 // 5. other uninstantiated module declarations.
44599 case 262 /* SyntaxKind.ModuleBlock */: {
44600 var state_1 = 0 /* ModuleInstanceState.NonInstantiated */;
44601 ts.forEachChild(node, function (n) {
44602 var childState = getModuleInstanceStateCached(n, visited);
44603 switch (childState) {
44604 case 0 /* ModuleInstanceState.NonInstantiated */:
44605 // child is non-instantiated - continue searching
44606 return;
44607 case 2 /* ModuleInstanceState.ConstEnumOnly */:
44608 // child is const enum only - record state and continue searching
44609 state_1 = 2 /* ModuleInstanceState.ConstEnumOnly */;
44610 return;
44611 case 1 /* ModuleInstanceState.Instantiated */:
44612 // child is instantiated - record state and stop
44613 state_1 = 1 /* ModuleInstanceState.Instantiated */;
44614 return true;
44615 default:
44616 ts.Debug.assertNever(childState);
44617 }

Callers 1

Calls 4

getModuleInstanceStateFunction · 0.85
forEachChildMethod · 0.80

Tested by

no test coverage detected