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

Function visitImportEqualsDeclaration

test/fixtures/snapshot/typescript.js:93948–93983  ·  view source on GitHub ↗

* Visits an import equals declaration. * * @param node The import equals declaration node.

(node)

Source from the content-addressed store, hash-verified

93946 * @param node The import equals declaration node.
93947 */
93948 function visitImportEqualsDeclaration(node) {
93949 // Always elide type-only imports
93950 if (node.isTypeOnly) {
93951 return undefined;
93952 }
93953 if (ts.isExternalModuleImportEqualsDeclaration(node)) {
93954 var isReferenced = shouldEmitAliasDeclaration(node);
93955 // If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
93956 if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* ImportsNotUsedAsValues.Preserve */) {
93957 return ts.setOriginalNode(ts.setTextRange(factory.createImportDeclaration(
93958 /*decorators*/ undefined,
93959 /*modifiers*/ undefined,
93960 /*importClause*/ undefined, node.moduleReference.expression,
93961 /*assertClause*/ undefined), node), node);
93962 }
93963 return isReferenced ? ts.visitEachChild(node, visitor, context) : undefined;
93964 }
93965 if (!shouldEmitImportEqualsDeclaration(node)) {
93966 return undefined;
93967 }
93968 var moduleReference = ts.createExpressionFromEntityName(factory, node.moduleReference);
93969 ts.setEmitFlags(moduleReference, 1536 /* EmitFlags.NoComments */ | 2048 /* EmitFlags.NoNestedComments */);
93970 if (isNamedExternalModuleExport(node) || !isExportOfNamespace(node)) {
93971 // export var ${name} = ${moduleReference};
93972 // var ${name} = ${moduleReference};
93973 return ts.setOriginalNode(ts.setTextRange(factory.createVariableStatement(ts.visitNodes(node.modifiers, modifierVisitor, ts.isModifier), factory.createVariableDeclarationList([
93974 ts.setOriginalNode(factory.createVariableDeclaration(node.name,
93975 /*exclamationToken*/ undefined,
93976 /*type*/ undefined, moduleReference), node)
93977 ])), node), node);
93978 }
93979 else {
93980 // exports.${name} = ${moduleReference};
93981 return ts.setOriginalNode(createNamespaceExport(node.name, moduleReference, node), node);
93982 }
93983 }
93984 /**
93985 * Gets a value indicating whether the node is exported from a namespace.
93986 *

Callers 4

visitElidableStatementFunction · 0.85
visitTypeScriptFunction · 0.85
topLevelVisitorFunction · 0.85
visitorFunction · 0.85

Calls 12

isExportOfNamespaceFunction · 0.85
createNamespaceExportFunction · 0.85
createExportExpressionFunction · 0.85
createRequireCallFunction · 0.85
hoistVariableDeclarationFunction · 0.85
assertMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected