MCPcopy Create free account
hub / github.com/nodejs/node / getDeclarationSpaces

Function getDeclarationSpaces

test/fixtures/snapshot/typescript.js:81197–81253  ·  view source on GitHub ↗
(decl)

Source from the content-addressed store, hash-verified

81195 }
81196 }
81197 function getDeclarationSpaces(decl) {
81198 var d = decl;
81199 switch (d.kind) {
81200 case 258 /* SyntaxKind.InterfaceDeclaration */:
81201 case 259 /* SyntaxKind.TypeAliasDeclaration */:
81202 // A jsdoc typedef and callback are, by definition, type aliases.
81203 // falls through
81204 case 345 /* SyntaxKind.JSDocTypedefTag */:
81205 case 338 /* SyntaxKind.JSDocCallbackTag */:
81206 case 339 /* SyntaxKind.JSDocEnumTag */:
81207 return 2 /* DeclarationSpaces.ExportType */;
81208 case 261 /* SyntaxKind.ModuleDeclaration */:
81209 return ts.isAmbientModule(d) || ts.getModuleInstanceState(d) !== 0 /* ModuleInstanceState.NonInstantiated */
81210 ? 4 /* DeclarationSpaces.ExportNamespace */ | 1 /* DeclarationSpaces.ExportValue */
81211 : 4 /* DeclarationSpaces.ExportNamespace */;
81212 case 257 /* SyntaxKind.ClassDeclaration */:
81213 case 260 /* SyntaxKind.EnumDeclaration */:
81214 case 299 /* SyntaxKind.EnumMember */:
81215 return 2 /* DeclarationSpaces.ExportType */ | 1 /* DeclarationSpaces.ExportValue */;
81216 case 305 /* SyntaxKind.SourceFile */:
81217 return 2 /* DeclarationSpaces.ExportType */ | 1 /* DeclarationSpaces.ExportValue */ | 4 /* DeclarationSpaces.ExportNamespace */;
81218 case 271 /* SyntaxKind.ExportAssignment */:
81219 case 221 /* SyntaxKind.BinaryExpression */:
81220 var node_2 = d;
81221 var expression = ts.isExportAssignment(node_2) ? node_2.expression : node_2.right;
81222 // Export assigned entity name expressions act as aliases and should fall through, otherwise they export values
81223 if (!ts.isEntityNameExpression(expression)) {
81224 return 1 /* DeclarationSpaces.ExportValue */;
81225 }
81226 d = expression;
81227 // The below options all declare an Alias, which is allowed to merge with other values within the importing module.
81228 // falls through
81229 case 265 /* SyntaxKind.ImportEqualsDeclaration */:
81230 case 268 /* SyntaxKind.NamespaceImport */:
81231 case 267 /* SyntaxKind.ImportClause */:
81232 var result_12 = 0 /* DeclarationSpaces.None */;
81233 var target = resolveAlias(getSymbolOfNode(d));
81234 ts.forEach(target.declarations, function (d) {
81235 result_12 |= getDeclarationSpaces(d);
81236 });
81237 return result_12;
81238 case 254 /* SyntaxKind.VariableDeclaration */:
81239 case 203 /* SyntaxKind.BindingElement */:
81240 case 256 /* SyntaxKind.FunctionDeclaration */:
81241 case 270 /* SyntaxKind.ImportSpecifier */: // https://github.com/Microsoft/TypeScript/pull/7591
81242 case 79 /* SyntaxKind.Identifier */: // https://github.com/microsoft/TypeScript/issues/36098
81243 // Identifiers are used as declarations of assignment declarations whose parents may be
81244 // SyntaxKind.CallExpression - `Object.defineProperty(thing, "aField", {value: 42});`
81245 // SyntaxKind.ElementAccessExpression - `thing["aField"] = 42;` or `thing["aField"];` (with a doc comment on it)
81246 // or SyntaxKind.PropertyAccessExpression - `thing.aField = 42;`
81247 // all of which are pretty much always values, or at least imply a value meaning.
81248 // It may be apprpriate to treat these as aliases in the future.
81249 return 1 /* DeclarationSpaces.ExportValue */;
81250 default:
81251 return ts.Debug.failBadSyntaxKind(d);
81252 }
81253 }
81254 }

Calls 3

resolveAliasFunction · 0.85
getSymbolOfNodeFunction · 0.85
forEachMethod · 0.65

Tested by

no test coverage detected