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

Function checkAliasSymbol

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

Source from the content-addressed store, hash-verified

85132 return true;
85133 }
85134 function checkAliasSymbol(node) {
85135 var symbol = getSymbolOfNode(node);
85136 var target = resolveAlias(symbol);
85137 if (target !== unknownSymbol) {
85138 // For external modules, `symbol` represents the local symbol for an alias.
85139 // This local symbol will merge any other local declarations (excluding other aliases)
85140 // and symbol.flags will contains combined representation for all merged declaration.
85141 // Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have,
85142 // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
85143 // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
85144 symbol = getMergedSymbol(symbol.exportSymbol || symbol);
85145 var excludedMeanings = (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */) ? 111551 /* SymbolFlags.Value */ : 0) |
85146 (symbol.flags & 788968 /* SymbolFlags.Type */ ? 788968 /* SymbolFlags.Type */ : 0) |
85147 (symbol.flags & 1920 /* SymbolFlags.Namespace */ ? 1920 /* SymbolFlags.Namespace */ : 0);
85148 if (target.flags & excludedMeanings) {
85149 var message = node.kind === 275 /* SyntaxKind.ExportSpecifier */ ?
85150 ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
85151 ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
85152 error(node, message, symbolToString(symbol));
85153 }
85154 if (compilerOptions.isolatedModules
85155 && !ts.isTypeOnlyImportOrExportDeclaration(node)
85156 && !(node.flags & 16777216 /* NodeFlags.Ambient */)) {
85157 var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
85158 var isType = !(target.flags & 111551 /* SymbolFlags.Value */);
85159 if (isType || typeOnlyAlias) {
85160 switch (node.kind) {
85161 case 267 /* SyntaxKind.ImportClause */:
85162 case 270 /* SyntaxKind.ImportSpecifier */:
85163 case 265 /* SyntaxKind.ImportEqualsDeclaration */: {
85164 if (compilerOptions.preserveValueImports) {
85165 ts.Debug.assertIsDefined(node.name, "An ImportClause with a symbol should have a name");
85166 var message = isType
85167 ? ts.Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled
85168 : ts.Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled;
85169 var name = ts.idText(node.kind === 270 /* SyntaxKind.ImportSpecifier */ ? node.propertyName || node.name : node.name);
85170 addTypeOnlyDeclarationRelatedInfo(error(node, message, name), isType ? undefined : typeOnlyAlias, name);
85171 }
85172 if (isType && node.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */ && ts.hasEffectiveModifier(node, 1 /* ModifierFlags.Export */)) {
85173 error(node, ts.Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided);
85174 }
85175 break;
85176 }
85177 case 275 /* SyntaxKind.ExportSpecifier */: {
85178 // Don't allow re-exporting an export that will be elided when `--isolatedModules` is set.
85179 // The exception is that `import type { A } from './a'; export { A }` is allowed
85180 // because single-file analysis can determine that the export should be dropped.
85181 if (ts.getSourceFileOfNode(typeOnlyAlias) !== ts.getSourceFileOfNode(node)) {
85182 var message = isType
85183 ? ts.Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type
85184 : ts.Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_re_exported_using_a_type_only_re_export_when_isolatedModules_is_enabled;
85185 var name = ts.idText(node.propertyName || node.name);
85186 addTypeOnlyDeclarationRelatedInfo(error(node, message, name), isType ? undefined : typeOnlyAlias, name);
85187 return;
85188 }
85189 }
85190 }
85191 }

Callers 4

checkImportBindingFunction · 0.85
checkExportDeclarationFunction · 0.85
checkExportSpecifierFunction · 0.85

Calls 10

getSymbolOfNodeFunction · 0.85
resolveAliasFunction · 0.85
getMergedSymbolFunction · 0.85
symbolToStringFunction · 0.85
addDeprecatedSuggestionFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected