From 9b9372eb942a40a613d4866b0d5c8cfbf6a88fcd Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 11 Oct 2020 04:10:51 +0800 Subject: [PATCH] update cases --- src/compiler/checker.ts | 37 ++++++-- tests/baselines/reference/spreadEnum2.js | 7 +- tests/baselines/reference/spreadEnum2.symbols | 89 ++++++++++--------- tests/baselines/reference/spreadEnum2.types | 34 +++---- tests/cases/conformance/enums/spreadEnum2.ts | 3 +- 5 files changed, 100 insertions(+), 70 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 40a6b771e44f9..c9a5b6424e23e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9463,15 +9463,27 @@ namespace ts { if (getEnumKind(symbol) === EnumKind.Literal) { enumCount++; const memberTypeList: Type[] = []; - const enumExports = getExportsOfSymbol(symbol); - enumExports.forEach(enumExport => { - if (enumExport.valueDeclaration && isEnumMember(enumExport.valueDeclaration)) { - const value = getEnumMemberValue(enumExport.valueDeclaration); - const memberType = getFreshTypeOfLiteralType(getLiteralType(value !== undefined ? value : 0, enumCount, enumExport)); - getSymbolLinks(enumExport).declaredType = memberType; - memberTypeList.push(getRegularTypeOfLiteralType(memberType)); - } - }) + for (const declaration of symbol.declarations) { + if (declaration.kind === SyntaxKind.EnumDeclaration) { + for (const member of (declaration).members) { + if (isEnumMember(member)) { + appendEnumMemberIntoTypeList(member, memberTypeList) + } + else { + const enumSymbol = resolveEntityName(member.name, SymbolFlags.Enum); + if (enumSymbol) { + const enumExports = getExportsOfSymbol(symbol); + enumExports.forEach(enumExport => { + if (enumExport.valueDeclaration && isEnumMember(enumExport.valueDeclaration)) { + appendEnumMemberIntoTypeList(enumExport.valueDeclaration, memberTypeList); + } + }) + } + } + } + } + } + if (memberTypeList.length) { const enumType = getUnionType(memberTypeList, UnionReduction.Literal, symbol, /*aliasTypeArguments*/ undefined); if (enumType.flags & TypeFlags.Union) { @@ -9484,6 +9496,13 @@ namespace ts { const enumType = createType(TypeFlags.Enum); enumType.symbol = symbol; return links.declaredType = enumType; + + function appendEnumMemberIntoTypeList(member: EnumMember, memberTypeList: Type[]) { + const value = getEnumMemberValue(member); + const memberType = getFreshTypeOfLiteralType(getLiteralType(value !== undefined ? value : 0, enumCount, getSymbolOfNode(member))); + getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType; + memberTypeList.push(getRegularTypeOfLiteralType(memberType)); + } } function getDeclaredTypeOfEnumMember(symbol: Symbol): Type { diff --git a/tests/baselines/reference/spreadEnum2.js b/tests/baselines/reference/spreadEnum2.js index 17fa044980161..bc3a079af34b2 100644 --- a/tests/baselines/reference/spreadEnum2.js +++ b/tests/baselines/reference/spreadEnum2.js @@ -1,6 +1,7 @@ //// [spreadEnum2.ts] enum A { - AA = 'A' + AA = 'A', + AAA = 'AAA' } enum B { @@ -58,6 +59,7 @@ var __assign = (this && this.__assign) || function () { var A; (function (A) { A["AA"] = "A"; + A["AAA"] = "AAA"; })(A || (A = {})); var B; (function (B) { @@ -98,7 +100,8 @@ E.EE; //// [spreadEnum2.d.ts] declare enum A { - AA = "A" + AA = "A", + AAA = "AAA" } declare enum B { ...A, diff --git a/tests/baselines/reference/spreadEnum2.symbols b/tests/baselines/reference/spreadEnum2.symbols index 818a0756308fc..1a7a7fbd05c17 100644 --- a/tests/baselines/reference/spreadEnum2.symbols +++ b/tests/baselines/reference/spreadEnum2.symbols @@ -2,40 +2,43 @@ enum A { >A : Symbol(A, Decl(spreadEnum2.ts, 0, 0)) - AA = 'A' + AA = 'A', >AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) + + AAA = 'AAA' +>AAA : Symbol(A.AAA, Decl(spreadEnum2.ts, 1, 13)) } enum B { ->B : Symbol(B, Decl(spreadEnum2.ts, 2, 1)) +>B : Symbol(B, Decl(spreadEnum2.ts, 3, 1)) ...A, BB = 'B' ->BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) +>BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) } enum C { ->C : Symbol(C, Decl(spreadEnum2.ts, 7, 1)) +>C : Symbol(C, Decl(spreadEnum2.ts, 8, 1)) ...B, CC = 'C' ->CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) +>CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) } enum D { ->D : Symbol(D, Decl(spreadEnum2.ts, 12, 1)) +>D : Symbol(D, Decl(spreadEnum2.ts, 13, 1)) ...C, DD = 'D' ->DD : Symbol(D.DD, Decl(spreadEnum2.ts, 15, 9)) +>DD : Symbol(D.DD, Decl(spreadEnum2.ts, 16, 9)) } enum E { ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) ...D, EE = 'E' ->EE : Symbol(E.EE, Decl(spreadEnum2.ts, 20, 9)) +>EE : Symbol(E.EE, Decl(spreadEnum2.ts, 21, 9)) } A.AA; @@ -45,71 +48,71 @@ A.AA; B.AA; >B.AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) ->B : Symbol(B, Decl(spreadEnum2.ts, 2, 1)) +>B : Symbol(B, Decl(spreadEnum2.ts, 3, 1)) >AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) B.BB; ->B.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) ->B : Symbol(B, Decl(spreadEnum2.ts, 2, 1)) ->BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) +>B.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) +>B : Symbol(B, Decl(spreadEnum2.ts, 3, 1)) +>BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) C.AA; >C.AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) ->C : Symbol(C, Decl(spreadEnum2.ts, 7, 1)) +>C : Symbol(C, Decl(spreadEnum2.ts, 8, 1)) >AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) C.BB; ->C.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) ->C : Symbol(C, Decl(spreadEnum2.ts, 7, 1)) ->BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) +>C.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) +>C : Symbol(C, Decl(spreadEnum2.ts, 8, 1)) +>BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) C.CC; ->C.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) ->C : Symbol(C, Decl(spreadEnum2.ts, 7, 1)) ->CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) +>C.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) +>C : Symbol(C, Decl(spreadEnum2.ts, 8, 1)) +>CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) D.AA; >D.AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) ->D : Symbol(D, Decl(spreadEnum2.ts, 12, 1)) +>D : Symbol(D, Decl(spreadEnum2.ts, 13, 1)) >AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) D.BB; ->D.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) ->D : Symbol(D, Decl(spreadEnum2.ts, 12, 1)) ->BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) +>D.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) +>D : Symbol(D, Decl(spreadEnum2.ts, 13, 1)) +>BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) D.CC; ->D.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) ->D : Symbol(D, Decl(spreadEnum2.ts, 12, 1)) ->CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) +>D.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) +>D : Symbol(D, Decl(spreadEnum2.ts, 13, 1)) +>CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) D.DD; ->D.DD : Symbol(D.DD, Decl(spreadEnum2.ts, 15, 9)) ->D : Symbol(D, Decl(spreadEnum2.ts, 12, 1)) ->DD : Symbol(D.DD, Decl(spreadEnum2.ts, 15, 9)) +>D.DD : Symbol(D.DD, Decl(spreadEnum2.ts, 16, 9)) +>D : Symbol(D, Decl(spreadEnum2.ts, 13, 1)) +>DD : Symbol(D.DD, Decl(spreadEnum2.ts, 16, 9)) E.AA; >E.AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) >AA : Symbol(A.AA, Decl(spreadEnum2.ts, 0, 8)) E.BB; ->E.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) ->BB : Symbol(B.BB, Decl(spreadEnum2.ts, 5, 9)) +>E.BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) +>BB : Symbol(B.BB, Decl(spreadEnum2.ts, 6, 9)) E.CC; ->E.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) ->CC : Symbol(C.CC, Decl(spreadEnum2.ts, 10, 9)) +>E.CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) +>CC : Symbol(C.CC, Decl(spreadEnum2.ts, 11, 9)) E.DD; ->E.DD : Symbol(D.DD, Decl(spreadEnum2.ts, 15, 9)) ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) ->DD : Symbol(D.DD, Decl(spreadEnum2.ts, 15, 9)) +>E.DD : Symbol(D.DD, Decl(spreadEnum2.ts, 16, 9)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) +>DD : Symbol(D.DD, Decl(spreadEnum2.ts, 16, 9)) E.EE; ->E.EE : Symbol(E.EE, Decl(spreadEnum2.ts, 20, 9)) ->E : Symbol(E, Decl(spreadEnum2.ts, 17, 1)) ->EE : Symbol(E.EE, Decl(spreadEnum2.ts, 20, 9)) +>E.EE : Symbol(E.EE, Decl(spreadEnum2.ts, 21, 9)) +>E : Symbol(E, Decl(spreadEnum2.ts, 18, 1)) +>EE : Symbol(E.EE, Decl(spreadEnum2.ts, 21, 9)) diff --git a/tests/baselines/reference/spreadEnum2.types b/tests/baselines/reference/spreadEnum2.types index 9ce352b7cb7f3..55f820fb9c65b 100644 --- a/tests/baselines/reference/spreadEnum2.types +++ b/tests/baselines/reference/spreadEnum2.types @@ -2,9 +2,13 @@ enum A { >A : A - AA = 'A' + AA = 'A', >AA : A.AA >'A' : "A" + + AAA = 'AAA' +>AAA : A.AAA +>'AAA' : "AAA" } enum B { @@ -52,9 +56,9 @@ enum E { } A.AA; ->A.AA : A +>A.AA : A.AA >A : typeof A ->AA : A +>AA : A.AA B.AA; >B.AA : A.AA @@ -67,9 +71,9 @@ B.BB; >BB : B.BB C.AA; ->C.AA : A.AA +>C.AA : A >C : typeof C ->AA : A.AA +>AA : A C.BB; >C.BB : B.BB @@ -82,14 +86,14 @@ C.CC; >CC : C.CC D.AA; ->D.AA : A.AA +>D.AA : A >D : typeof D ->AA : A.AA +>AA : A D.BB; ->D.BB : B.BB +>D.BB : B >D : typeof D ->BB : B.BB +>BB : B D.CC; >D.CC : C.CC @@ -102,19 +106,19 @@ D.DD; >DD : D.DD E.AA; ->E.AA : A.AA +>E.AA : A >E : typeof E ->AA : A.AA +>AA : A E.BB; ->E.BB : B.BB +>E.BB : B >E : typeof E ->BB : B.BB +>BB : B E.CC; ->E.CC : C.CC +>E.CC : C >E : typeof E ->CC : C.CC +>CC : C E.DD; >E.DD : D.DD diff --git a/tests/cases/conformance/enums/spreadEnum2.ts b/tests/cases/conformance/enums/spreadEnum2.ts index b640988882833..e392a716f394b 100644 --- a/tests/cases/conformance/enums/spreadEnum2.ts +++ b/tests/cases/conformance/enums/spreadEnum2.ts @@ -1,7 +1,8 @@ // @declaration: true enum A { - AA = 'A' + AA = 'A', + AAA = 'AAA' } enum B {