Skip to content

Commit 5ada5ef

Browse files
committed
Support template literals in ambient module declaration
1 parent 98e6014 commit 5ada5ef

File tree

5 files changed

+186
-1
lines changed

5 files changed

+186
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33376,7 +33376,7 @@ namespace ts {
3337633376
}
3337733377

3337833378
function isStringOrNumberLiteralExpression(expr: Expression) {
33379-
return expr.kind === SyntaxKind.StringLiteral || expr.kind === SyntaxKind.NumericLiteral ||
33379+
return isStringOrNumericLiteralLike(expr) ||
3338033380
expr.kind === SyntaxKind.PrefixUnaryExpression && (<PrefixUnaryExpression>expr).operator === SyntaxKind.MinusToken &&
3338133381
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
3338233382
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [ambientModuleWithTemplateLiterals.ts]
2+
declare module Foo {
3+
enum Bar {
4+
a = `1`,
5+
b = '2',
6+
c = '3'
7+
}
8+
9+
export const a = 'string';
10+
export const b = `template`;
11+
12+
export const c = Bar.a;
13+
export const d = Bar['b'];
14+
export const e = Bar[`c`];
15+
}
16+
17+
Foo.a;
18+
Foo.b;
19+
Foo.c;
20+
Foo.d;
21+
Foo.e;
22+
23+
//// [ambientModuleWithTemplateLiterals.js]
24+
Foo.a;
25+
Foo.b;
26+
Foo.c;
27+
Foo.d;
28+
Foo.e;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
=== tests/cases/compiler/ambientModuleWithTemplateLiterals.ts ===
2+
declare module Foo {
3+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
4+
5+
enum Bar {
6+
>Bar : Symbol(Bar, Decl(ambientModuleWithTemplateLiterals.ts, 0, 20))
7+
8+
a = `1`,
9+
>a : Symbol(Bar.a, Decl(ambientModuleWithTemplateLiterals.ts, 1, 14))
10+
11+
b = '2',
12+
>b : Symbol(Bar.b, Decl(ambientModuleWithTemplateLiterals.ts, 2, 16))
13+
14+
c = '3'
15+
>c : Symbol(Bar.c, Decl(ambientModuleWithTemplateLiterals.ts, 3, 16))
16+
}
17+
18+
export const a = 'string';
19+
>a : Symbol(a, Decl(ambientModuleWithTemplateLiterals.ts, 7, 16))
20+
21+
export const b = `template`;
22+
>b : Symbol(b, Decl(ambientModuleWithTemplateLiterals.ts, 8, 16))
23+
24+
export const c = Bar.a;
25+
>c : Symbol(c, Decl(ambientModuleWithTemplateLiterals.ts, 10, 16))
26+
>Bar.a : Symbol(Bar.a, Decl(ambientModuleWithTemplateLiterals.ts, 1, 14))
27+
>Bar : Symbol(Bar, Decl(ambientModuleWithTemplateLiterals.ts, 0, 20))
28+
>a : Symbol(Bar.a, Decl(ambientModuleWithTemplateLiterals.ts, 1, 14))
29+
30+
export const d = Bar['b'];
31+
>d : Symbol(d, Decl(ambientModuleWithTemplateLiterals.ts, 11, 16))
32+
>Bar : Symbol(Bar, Decl(ambientModuleWithTemplateLiterals.ts, 0, 20))
33+
>'b' : Symbol(Bar.b, Decl(ambientModuleWithTemplateLiterals.ts, 2, 16))
34+
35+
export const e = Bar[`c`];
36+
>e : Symbol(e, Decl(ambientModuleWithTemplateLiterals.ts, 12, 16))
37+
>Bar : Symbol(Bar, Decl(ambientModuleWithTemplateLiterals.ts, 0, 20))
38+
>`c` : Symbol(Bar.c, Decl(ambientModuleWithTemplateLiterals.ts, 3, 16))
39+
}
40+
41+
Foo.a;
42+
>Foo.a : Symbol(Foo.a, Decl(ambientModuleWithTemplateLiterals.ts, 7, 16))
43+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
44+
>a : Symbol(Foo.a, Decl(ambientModuleWithTemplateLiterals.ts, 7, 16))
45+
46+
Foo.b;
47+
>Foo.b : Symbol(Foo.b, Decl(ambientModuleWithTemplateLiterals.ts, 8, 16))
48+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
49+
>b : Symbol(Foo.b, Decl(ambientModuleWithTemplateLiterals.ts, 8, 16))
50+
51+
Foo.c;
52+
>Foo.c : Symbol(Foo.c, Decl(ambientModuleWithTemplateLiterals.ts, 10, 16))
53+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
54+
>c : Symbol(Foo.c, Decl(ambientModuleWithTemplateLiterals.ts, 10, 16))
55+
56+
Foo.d;
57+
>Foo.d : Symbol(Foo.d, Decl(ambientModuleWithTemplateLiterals.ts, 11, 16))
58+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
59+
>d : Symbol(Foo.d, Decl(ambientModuleWithTemplateLiterals.ts, 11, 16))
60+
61+
Foo.e;
62+
>Foo.e : Symbol(Foo.e, Decl(ambientModuleWithTemplateLiterals.ts, 12, 16))
63+
>Foo : Symbol(Foo, Decl(ambientModuleWithTemplateLiterals.ts, 0, 0))
64+
>e : Symbol(Foo.e, Decl(ambientModuleWithTemplateLiterals.ts, 12, 16))
65+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
=== tests/cases/compiler/ambientModuleWithTemplateLiterals.ts ===
2+
declare module Foo {
3+
>Foo : typeof Foo
4+
5+
enum Bar {
6+
>Bar : Bar
7+
8+
a = `1`,
9+
>a : Bar.a
10+
>`1` : "1"
11+
12+
b = '2',
13+
>b : Bar.b
14+
>'2' : "2"
15+
16+
c = '3'
17+
>c : Bar.c
18+
>'3' : "3"
19+
}
20+
21+
export const a = 'string';
22+
>a : "string"
23+
>'string' : "string"
24+
25+
export const b = `template`;
26+
>b : "template"
27+
>`template` : "template"
28+
29+
export const c = Bar.a;
30+
>c : Bar.a
31+
>Bar.a : Bar.a
32+
>Bar : typeof Bar
33+
>a : Bar.a
34+
35+
export const d = Bar['b'];
36+
>d : Bar.b
37+
>Bar['b'] : Bar.b
38+
>Bar : typeof Bar
39+
>'b' : "b"
40+
41+
export const e = Bar[`c`];
42+
>e : Bar.c
43+
>Bar[`c`] : Bar.c
44+
>Bar : typeof Bar
45+
>`c` : "c"
46+
}
47+
48+
Foo.a;
49+
>Foo.a : "string"
50+
>Foo : typeof Foo
51+
>a : "string"
52+
53+
Foo.b;
54+
>Foo.b : "template"
55+
>Foo : typeof Foo
56+
>b : "template"
57+
58+
Foo.c;
59+
>Foo.c : Foo.Bar.a
60+
>Foo : typeof Foo
61+
>c : Foo.Bar.a
62+
63+
Foo.d;
64+
>Foo.d : Foo.Bar.b
65+
>Foo : typeof Foo
66+
>d : Foo.Bar.b
67+
68+
Foo.e;
69+
>Foo.e : Foo.Bar.c
70+
>Foo : typeof Foo
71+
>e : Foo.Bar.c
72+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
declare module Foo {
2+
enum Bar {
3+
a = `1`,
4+
b = '2',
5+
c = '3'
6+
}
7+
8+
export const a = 'string';
9+
export const b = `template`;
10+
11+
export const c = Bar.a;
12+
export const d = Bar['b'];
13+
export const e = Bar[`c`];
14+
}
15+
16+
Foo.a;
17+
Foo.b;
18+
Foo.c;
19+
Foo.d;
20+
Foo.e;

0 commit comments

Comments
 (0)