Skip to content

Commit 6d26654

Browse files
authored
fix(2271): Invalid declaration emit for enum value type (#2319)
1 parent 31ce997 commit 6d26654

File tree

5 files changed

+175
-1
lines changed

5 files changed

+175
-1
lines changed

internal/checker/nodebuilderimpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (b *NodeBuilderImpl) appendReferenceToType(root *ast.TypeNode, ref *ast.Typ
155155
imprt := root.AsImportTypeNode()
156156
// then move qualifiers
157157
ids := getAccessStack(ref)
158-
var qualifier *ast.Node
158+
qualifier := root.AsImportTypeNode().Qualifier
159159
for _, id := range ids {
160160
if qualifier != nil {
161161
qualifier = b.f.NewQualifiedName(qualifier, id)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//// [tests/cases/compiler/declarationEmitQualifiedName.ts] ////
2+
3+
//// [e.ts]
4+
export enum E {
5+
A = 'a',
6+
B = 'b',
7+
}
8+
9+
//// [a.ts]
10+
import { E } from './e.js'
11+
export const A = {
12+
item: {
13+
a: E.A,
14+
},
15+
} as const
16+
17+
//// [b.ts]
18+
import { A } from './a.js'
19+
export const B = { ...A } as const
20+
21+
22+
//// [e.js]
23+
"use strict";
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.E = void 0;
26+
var E;
27+
(function (E) {
28+
E["A"] = "a";
29+
E["B"] = "b";
30+
})(E || (exports.E = E = {}));
31+
//// [a.js]
32+
"use strict";
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
exports.A = void 0;
35+
const e_js_1 = require("./e.js");
36+
exports.A = {
37+
item: {
38+
a: e_js_1.E.A,
39+
},
40+
};
41+
//// [b.js]
42+
"use strict";
43+
Object.defineProperty(exports, "__esModule", { value: true });
44+
exports.B = void 0;
45+
const a_js_1 = require("./a.js");
46+
exports.B = Object.assign({}, a_js_1.A);
47+
48+
49+
//// [e.d.ts]
50+
export declare enum E {
51+
A = "a",
52+
B = "b"
53+
}
54+
//// [a.d.ts]
55+
import { E } from './e.js';
56+
export declare const A: {
57+
readonly item: {
58+
readonly a: E.A;
59+
};
60+
};
61+
//// [b.d.ts]
62+
export declare const B: {
63+
readonly item: {
64+
readonly a: import("./e.js").E.A;
65+
};
66+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//// [tests/cases/compiler/declarationEmitQualifiedName.ts] ////
2+
3+
=== e.ts ===
4+
export enum E {
5+
>E : Symbol(E, Decl(e.ts, 0, 0))
6+
7+
A = 'a',
8+
>A : Symbol(E.A, Decl(e.ts, 0, 15))
9+
10+
B = 'b',
11+
>B : Symbol(E.B, Decl(e.ts, 1, 12))
12+
}
13+
14+
=== a.ts ===
15+
import { E } from './e.js'
16+
>E : Symbol(E, Decl(a.ts, 0, 8))
17+
18+
export const A = {
19+
>A : Symbol(A, Decl(a.ts, 1, 12))
20+
21+
item: {
22+
>item : Symbol(item, Decl(a.ts, 1, 18))
23+
24+
a: E.A,
25+
>a : Symbol(a, Decl(a.ts, 2, 11))
26+
>E.A : Symbol(E.A, Decl(e.ts, 0, 15))
27+
>E : Symbol(E, Decl(a.ts, 0, 8))
28+
>A : Symbol(E.A, Decl(e.ts, 0, 15))
29+
30+
},
31+
} as const
32+
>const : Symbol(const)
33+
34+
=== b.ts ===
35+
import { A } from './a.js'
36+
>A : Symbol(A, Decl(b.ts, 0, 8))
37+
38+
export const B = { ...A } as const
39+
>B : Symbol(B, Decl(b.ts, 1, 12))
40+
>A : Symbol(A, Decl(b.ts, 0, 8))
41+
>const : Symbol(const)
42+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tests/cases/compiler/declarationEmitQualifiedName.ts] ////
2+
3+
=== e.ts ===
4+
export enum E {
5+
>E : E
6+
7+
A = 'a',
8+
>A : E.A
9+
>'a' : "a"
10+
11+
B = 'b',
12+
>B : E.B
13+
>'b' : "b"
14+
}
15+
16+
=== a.ts ===
17+
import { E } from './e.js'
18+
>E : typeof E
19+
20+
export const A = {
21+
>A : { readonly item: { readonly a: E.A; }; }
22+
>{ item: { a: E.A, },} as const : { readonly item: { readonly a: E.A; }; }
23+
>{ item: { a: E.A, },} : { readonly item: { readonly a: E.A; }; }
24+
25+
item: {
26+
>item : { readonly a: E.A; }
27+
>{ a: E.A, } : { readonly a: E.A; }
28+
29+
a: E.A,
30+
>a : E.A
31+
>E.A : E.A
32+
>E : typeof E
33+
>A : E.A
34+
35+
},
36+
} as const
37+
38+
=== b.ts ===
39+
import { A } from './a.js'
40+
>A : { readonly item: { readonly a: import("e").E.A; }; }
41+
42+
export const B = { ...A } as const
43+
>B : { readonly item: { readonly a: import("e").E.A; }; }
44+
>{ ...A } as const : { readonly item: { readonly a: import("e").E.A; }; }
45+
>{ ...A } : { readonly item: { readonly a: import("e").E.A; }; }
46+
>A : { readonly item: { readonly a: import("e").E.A; }; }
47+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @declaration: true
2+
3+
// @filename: e.ts
4+
export enum E {
5+
A = 'a',
6+
B = 'b',
7+
}
8+
9+
// @filename: a.ts
10+
import { E } from './e.js'
11+
export const A = {
12+
item: {
13+
a: E.A,
14+
},
15+
} as const
16+
17+
// @filename: b.ts
18+
import { A } from './a.js'
19+
export const B = { ...A } as const

0 commit comments

Comments
 (0)