Skip to content

Commit 17c8229

Browse files
Added tests for erroneous function expressions in both tagged/untagged template expressions.
1 parent 0263d60 commit 17c8229

11 files changed

+95
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.
2+
3+
4+
==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (1 errors) ====
5+
6+
7+
function foo(...rest: any[]) {
8+
}
9+
10+
foo `${function (x: number) { x = "bad"; } }`;
11+
~~~
12+
!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts]
2+
3+
function foo(...rest: any[]) {
4+
}
5+
6+
foo `${function (x: number) { x = "bad"; } }`;
7+
8+
//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js]
9+
function foo() {
10+
var rest = [];
11+
for (var _i = 0; _i < arguments.length; _i++) {
12+
rest[_i - 0] = arguments[_i];
13+
}
14+
}
15+
foo `${function (x) {
16+
x = "bad";
17+
}}`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts ===
2+
3+
function foo(...rest: any[]) {
4+
>foo : (...rest: any[]) => void
5+
>rest : any[]
6+
}
7+
8+
foo `${function (x: number) { x = "bad"; } }`;
9+
>foo : (...rest: any[]) => void
10+
>function (x: number) { x = "bad"; } : (x: number) => void
11+
>x : number
12+
>x = "bad" : string
13+
>x : number
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts]
2+
3+
4+
`${function (x: number) { x = "bad"; } }`;
5+
6+
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js]
7+
"" + function (x) {
8+
x = "bad";
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts ===
2+
3+
4+
`${function (x: number) { x = "bad"; } }`;
5+
>function (x: number) { x = "bad"; } : (x: number) => void
6+
>x : number
7+
>x = "bad" : string
8+
>x : number
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts]
2+
3+
`${function (x: number) { x = "bad"; } }`;
4+
5+
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js]
6+
`${function (x) {
7+
x = "bad";
8+
}}`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts ===
2+
3+
`${function (x: number) { x = "bad"; } }`;
4+
>function (x: number) { x = "bad"; } : (x: number) => void
5+
>x : number
6+
>x = "bad" : string
7+
>x : number
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+

2+
3+
function foo(...rest: any[]) {
4+
}
5+
6+
foo `${function (x: number) { x = "bad"; } }`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@target: es6
2+
3+
function foo(...rest: any[]) {
4+
}
5+
6+
foo `${function (x: number) { x = "bad"; } }`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+

2+
3+
`${function (x: number) { x = "bad"; } }`;

0 commit comments

Comments
 (0)