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
2 changes: 1 addition & 1 deletion tsc/internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool {
}

nodeAsCall := node.AsCallExpression()
if nodeAsCall.TypeArguments != nil {
if nodeAsCall.TypeArguments != nil || nodeAsCall.QuestionDotToken != nil {
return c.grammarErrorOnNode(node, diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments)
Comment on lines +2171 to 2172

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should issue a different error message here.

}

Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5245,7 +5245,7 @@ func (p *Parser) parseLeftHandSideExpressionOrHigher() *ast.Expression {
p.nextToken() // advance past the dot
expression = p.finishNode(p.factory.NewMetaProperty(ast.KindImportKeyword, p.parseIdentifierName()), pos)
if expression.Text() == "defer" {
if p.token == ast.KindOpenParenToken || p.token == ast.KindLessThanToken {
if p.token == ast.KindOpenParenToken || p.token == ast.KindLessThanToken || p.token == ast.KindQuestionDotToken {
p.sourceFlags |= ast.NodeFlagsPossiblyContainsDynamicImport
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
importDeferOptionalChain.ts(1,1): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.
importDeferOptionalChain.ts(1,16): error TS2307: Cannot find module './a' or its corresponding type declarations.


==== importDeferOptionalChain.ts (2 errors) ====
import.defer?.("./a");
~~~~~~~~~~~~~~~~~~~~~
!!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.
~~~~~
!!! error TS2307: Cannot find module './a' or its corresponding type declarations.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/conformance/importDefer/importDeferOptionalChain.ts] ////

//// [importDeferOptionalChain.ts]
import.defer?.("./a");


//// [importDeferOptionalChain.js]
"use strict";
import.defer?.("./a");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/conformance/importDefer/importDeferOptionalChain.ts] ////

=== importDeferOptionalChain.ts ===

import.defer?.("./a");

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [tests/cases/conformance/importDefer/importDeferOptionalChain.ts] ////

=== importDeferOptionalChain.ts ===
import.defer?.("./a");
>import.defer?.("./a") : Promise<any>
>defer : any
>"./a" : "./a"

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @target: esnext
// @module: esnext

import.defer?.("./a");