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

Function checkEnumDeclarationWorker

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

Source from the content-addressed store, hash-verified

84846 addLazyDiagnostic(function () { return checkEnumDeclarationWorker(node); });
84847 }
84848 function checkEnumDeclarationWorker(node) {
84849 // Grammar checking
84850 checkGrammarDecoratorsAndModifiers(node);
84851 checkCollisionsForDeclarationName(node, node.name);
84852 checkExportsOnMergedDeclarations(node);
84853 node.members.forEach(checkEnumMember);
84854 computeEnumMemberValues(node);
84855 // Spec 2014 - Section 9.3:
84856 // It isn't possible for one enum declaration to continue the automatic numbering sequence of another,
84857 // and when an enum type has multiple declarations, only one declaration is permitted to omit a value
84858 // for the first member.
84859 //
84860 // Only perform this check once per symbol
84861 var enumSymbol = getSymbolOfNode(node);
84862 var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind);
84863 if (node === firstDeclaration) {
84864 if (enumSymbol.declarations && enumSymbol.declarations.length > 1) {
84865 var enumIsConst_1 = ts.isEnumConst(node);
84866 // check that const is placed\omitted on all enum declarations
84867 ts.forEach(enumSymbol.declarations, function (decl) {
84868 if (ts.isEnumDeclaration(decl) && ts.isEnumConst(decl) !== enumIsConst_1) {
84869 error(ts.getNameOfDeclaration(decl), ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
84870 }
84871 });
84872 }
84873 var seenEnumMissingInitialInitializer_1 = false;
84874 ts.forEach(enumSymbol.declarations, function (declaration) {
84875 // return true if we hit a violation of the rule, false otherwise
84876 if (declaration.kind !== 260 /* SyntaxKind.EnumDeclaration */) {
84877 return false;
84878 }
84879 var enumDeclaration = declaration;
84880 if (!enumDeclaration.members.length) {
84881 return false;
84882 }
84883 var firstEnumMember = enumDeclaration.members[0];
84884 if (!firstEnumMember.initializer) {
84885 if (seenEnumMissingInitialInitializer_1) {
84886 error(firstEnumMember.name, ts.Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element);
84887 }
84888 else {
84889 seenEnumMissingInitialInitializer_1 = true;
84890 }
84891 }
84892 });
84893 }
84894 }
84895 function checkEnumMember(node) {
84896 if (ts.isPrivateIdentifier(node.name)) {
84897 error(node, ts.Diagnostics.An_enum_member_cannot_be_named_with_a_private_identifier);

Callers 1

checkEnumDeclarationFunction · 0.85

Calls 7

computeEnumMemberValuesFunction · 0.85
getSymbolOfNodeFunction · 0.85
errorFunction · 0.70
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…