Skip to content

Commit

Permalink
update cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Oct 10, 2020
1 parent 0cde3e2 commit 9b9372e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 70 deletions.
37 changes: 28 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<EnumDeclaration>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) {
Expand All @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions tests/baselines/reference/spreadEnum2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//// [spreadEnum2.ts]
enum A {
AA = 'A'
AA = 'A',
AAA = 'AAA'
}

enum B {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -98,7 +100,8 @@ E.EE;

//// [spreadEnum2.d.ts]
declare enum A {
AA = "A"
AA = "A",
AAA = "AAA"
}
declare enum B {
...A,
Expand Down
89 changes: 46 additions & 43 deletions tests/baselines/reference/spreadEnum2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))

34 changes: 19 additions & 15 deletions tests/baselines/reference/spreadEnum2.types
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/conformance/enums/spreadEnum2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @declaration: true

enum A {
AA = 'A'
AA = 'A',
AAA = 'AAA'
}

enum B {
Expand Down

0 comments on commit 9b9372e

Please sign in to comment.