Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tsc/internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ func (c *Checker) checkGrammarTypeArguments(node *ast.Node, typeArguments *ast.N
}

func (c *Checker) checkGrammarTaggedTemplateChain(node *ast.TaggedTemplateExpression) bool {
if node.QuestionDotToken != nil || node.Flags&ast.NodeFlagsOptionalChain != 0 {
tag := ast.SkipOuterExpressions(node.Tag, ast.OEKNonNullAssertions)
if node.QuestionDotToken != nil || node.Flags&ast.NodeFlagsOptionalChain != 0 || tag.Flags&ast.NodeFlagsOptionalChain != 0 {
return c.grammarErrorOnNode(node.Template, diagnostics.Tagged_template_expressions_are_not_permitted_in_an_optional_chain)
}
return false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
nonNullAssertedOptionalChainTemplate.ts(3,6): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(4,7): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(5,8): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(6,7): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(7,6): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(8,6): error TS1358: Tagged template expressions are not permitted in an optional chain.


==== nonNullAssertedOptionalChainTemplate.ts (6 errors) ====
var f: any;

f?.x!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.[0]!`text${1}`;
~~~~~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.()!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!`text`();
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!`text`.x;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.

(f?.x)!`text`;
(f?.x!)`text`;
f.x!`text`;

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

//// [nonNullAssertedOptionalChainTemplate.ts]
var f: any;

f?.x!`text`;
f?.x!!`text`;
f?.[0]!`text${1}`;
f?.()!`text`;
f?.x!`text`();
f?.x!`text`.x;

(f?.x)!`text`;
(f?.x!)`text`;
f.x!`text`;


//// [nonNullAssertedOptionalChainTemplate.js]
"use strict";
var f;
(f === null || f === void 0 ? void 0 : f.x) `text`;
(f === null || f === void 0 ? void 0 : f.x) `text`;
(f === null || f === void 0 ? void 0 : f[0]) `text${1}`;
(f === null || f === void 0 ? void 0 : f()) `text`;
(f === null || f === void 0 ? void 0 : f.x) `text`();
(f === null || f === void 0 ? void 0 : f.x) `text`.x;
(f === null || f === void 0 ? void 0 : f.x) `text`;
(f === null || f === void 0 ? void 0 : f.x) `text`;
f.x `text`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

=== nonNullAssertedOptionalChainTemplate.ts ===
var f: any;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.[0]!`text${1}`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.()!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`();
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`.x;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

(f?.x)!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

(f?.x!)`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f.x!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

=== nonNullAssertedOptionalChainTemplate.ts ===
var f: any;
>f : any

f?.x!`text`;
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.x!!`text`;
>f?.x!!`text` : any
>f?.x!! : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.[0]!`text${1}`;
>f?.[0]!`text${1}` : any
>f?.[0]! : any
>f?.[0] : any
>f : any
>0 : 0
>`text${1}` : string
>1 : 1

f?.()!`text`;
>f?.()!`text` : any
>f?.()! : any
>f?.() : any
>f : any
>`text` : "text"

f?.x!`text`();
>f?.x!`text`() : any
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.x!`text`.x;
>f?.x!`text`.x : any
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"
>x : any

(f?.x)!`text`;
>(f?.x)!`text` : any
>(f?.x)! : any
>(f?.x) : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

(f?.x!)`text`;
>(f?.x!)`text` : any
>(f?.x!) : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f.x!`text`;
>f.x!`text` : any
>f.x! : any
>f.x : any
>f : any
>x : any
>`text` : "text"

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
nonNullAssertedOptionalChainTemplate.ts(3,6): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(4,7): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(5,8): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(6,7): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(7,6): error TS1358: Tagged template expressions are not permitted in an optional chain.
nonNullAssertedOptionalChainTemplate.ts(8,6): error TS1358: Tagged template expressions are not permitted in an optional chain.


==== nonNullAssertedOptionalChainTemplate.ts (6 errors) ====
var f: any;

f?.x!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.[0]!`text${1}`;
~~~~~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.()!`text`;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!`text`();
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.
f?.x!`text`.x;
~~~~~~
!!! error TS1358: Tagged template expressions are not permitted in an optional chain.

(f?.x)!`text`;
(f?.x!)`text`;
f.x!`text`;

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

//// [nonNullAssertedOptionalChainTemplate.ts]
var f: any;

f?.x!`text`;
f?.x!!`text`;
f?.[0]!`text${1}`;
f?.()!`text`;
f?.x!`text`();
f?.x!`text`.x;

(f?.x)!`text`;
(f?.x!)`text`;
f.x!`text`;


//// [nonNullAssertedOptionalChainTemplate.js]
"use strict";
var f;
(f?.x) `text`;
(f?.x) `text`;
(f?.[0]) `text${1}`;
(f?.()) `text`;
(f?.x) `text`();
(f?.x) `text`.x;
(f?.x) `text`;
(f?.x) `text`;
f.x `text`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

=== nonNullAssertedOptionalChainTemplate.ts ===
var f: any;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.[0]!`text${1}`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.()!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`();
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f?.x!`text`.x;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

(f?.x)!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

(f?.x!)`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

f.x!`text`;
>f : Symbol(f, Decl(nonNullAssertedOptionalChainTemplate.ts, 0, 3))

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//// [tests/cases/compiler/nonNullAssertedOptionalChainTemplate.ts] ////

=== nonNullAssertedOptionalChainTemplate.ts ===
var f: any;
>f : any

f?.x!`text`;
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.x!!`text`;
>f?.x!!`text` : any
>f?.x!! : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.[0]!`text${1}`;
>f?.[0]!`text${1}` : any
>f?.[0]! : any
>f?.[0] : any
>f : any
>0 : 0
>`text${1}` : string
>1 : 1

f?.()!`text`;
>f?.()!`text` : any
>f?.()! : any
>f?.() : any
>f : any
>`text` : "text"

f?.x!`text`();
>f?.x!`text`() : any
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f?.x!`text`.x;
>f?.x!`text`.x : any
>f?.x!`text` : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"
>x : any

(f?.x)!`text`;
>(f?.x)!`text` : any
>(f?.x)! : any
>(f?.x) : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

(f?.x!)`text`;
>(f?.x!)`text` : any
>(f?.x!) : any
>f?.x! : any
>f?.x : any
>f : any
>x : any
>`text` : "text"

f.x!`text`;
>f.x!`text` : any
>f.x! : any
>f.x : any
>f : any
>x : any
>`text` : "text"

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @target: es2015, esnext
var f: any;

f?.x!`text`;
f?.x!!`text`;
f?.[0]!`text${1}`;
f?.()!`text`;
f?.x!`text`();
f?.x!`text`.x;

(f?.x)!`text`;
(f?.x!)`text`;
f.x!`text`;