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

Function checkTypeForDuplicateIndexSignatures

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

Source from the content-addressed store, hash-verified

80385 }
80386 }
80387 function checkTypeForDuplicateIndexSignatures(node) {
80388 if (node.kind === 258 /* SyntaxKind.InterfaceDeclaration */) {
80389 var nodeSymbol = getSymbolOfNode(node);
80390 // in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration
80391 // to prevent this run check only for the first declaration of a given kind
80392 if (nodeSymbol.declarations && nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
80393 return;
80394 }
80395 }
80396 // TypeScript 1.0 spec (April 2014)
80397 // 3.7.4: An object type can contain at most one string index signature and one numeric index signature.
80398 // 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration
80399 var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
80400 if (indexSymbol === null || indexSymbol === void 0 ? void 0 : indexSymbol.declarations) {
80401 var indexSignatureMap_1 = new ts.Map();
80402 var _loop_27 = function (declaration) {
80403 if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
80404 forEachType(getTypeFromTypeNode(declaration.parameters[0].type), function (type) {
80405 var entry = indexSignatureMap_1.get(getTypeId(type));
80406 if (entry) {
80407 entry.declarations.push(declaration);
80408 }
80409 else {
80410 indexSignatureMap_1.set(getTypeId(type), { type: type, declarations: [declaration] });
80411 }
80412 });
80413 }
80414 };
80415 for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
80416 var declaration = _a[_i];
80417 _loop_27(declaration);
80418 }
80419 indexSignatureMap_1.forEach(function (entry) {
80420 if (entry.declarations.length > 1) {
80421 for (var _i = 0, _a = entry.declarations; _i < _a.length; _i++) {
80422 var declaration = _a[_i];
80423 error(declaration, ts.Diagnostics.Duplicate_index_signature_for_type_0, typeToString(entry.type));
80424 }
80425 }
80426 });
80427 }
80428 }
80429 function checkPropertyDeclaration(node) {
80430 // Grammar checking
80431 if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarProperty(node))

Callers 3

Calls 6

getSymbolOfNodeFunction · 0.85
getIndexSymbolFunction · 0.85
_loop_27Function · 0.85
typeToStringFunction · 0.85
errorFunction · 0.70
forEachMethod · 0.65

Tested by

no test coverage detected