diff --git a/internal/printer/emitcontext.go b/internal/printer/emitcontext.go index ca5d395912..b81fc97a44 100644 --- a/internal/printer/emitcontext.go +++ b/internal/printer/emitcontext.go @@ -943,11 +943,11 @@ func (c *EmitContext) VisitIterationBody(body *ast.Statement, visitor *ast.NodeV } func (c *EmitContext) VisitEmbeddedStatement(node *ast.Statement, visitor *ast.NodeVisitor) *ast.Statement { - embeddedStatement := visitor.VisitEmbeddedStatement(node) - if embeddedStatement == nil { + if node == nil { return nil } - if ast.IsNotEmittedStatement(embeddedStatement) { + embeddedStatement := visitor.VisitEmbeddedStatement(node) + if embeddedStatement == nil || ast.IsNotEmittedStatement(embeddedStatement) { emptyStatement := visitor.Factory.NewEmptyStatement() emptyStatement.Loc = node.Loc c.SetOriginal(emptyStatement, node) diff --git a/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.errors.txt b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.errors.txt new file mode 100644 index 0000000000..2dec61a017 --- /dev/null +++ b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.errors.txt @@ -0,0 +1,8 @@ +typeOnlyExportAsIfBody.ts(1,11): error TS1233: An export declaration can only be used at the top level of a namespace or module. + + +==== typeOnlyExportAsIfBody.ts (1 errors) ==== + if (true) export type {}; + ~~~~~~ +!!! error TS1233: An export declaration can only be used at the top level of a namespace or module. + \ No newline at end of file diff --git a/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.js b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.js new file mode 100644 index 0000000000..cabf288d52 --- /dev/null +++ b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.js @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/typeOnlyExportAsIfBody.ts] //// + +//// [typeOnlyExportAsIfBody.ts] +if (true) export type {}; + + +//// [typeOnlyExportAsIfBody.js] +"use strict"; +if (true) + ; diff --git a/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.symbols b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.symbols new file mode 100644 index 0000000000..0e5778eb1c --- /dev/null +++ b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.symbols @@ -0,0 +1,6 @@ +//// [tests/cases/compiler/typeOnlyExportAsIfBody.ts] //// + +=== typeOnlyExportAsIfBody.ts === + +if (true) export type {}; + diff --git a/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.types b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.types new file mode 100644 index 0000000000..65291b44f5 --- /dev/null +++ b/testdata/baselines/reference/compiler/typeOnlyExportAsIfBody.types @@ -0,0 +1,6 @@ +//// [tests/cases/compiler/typeOnlyExportAsIfBody.ts] //// + +=== typeOnlyExportAsIfBody.ts === +if (true) export type {}; +>true : true + diff --git a/testdata/tests/cases/compiler/typeOnlyExportAsIfBody.ts b/testdata/tests/cases/compiler/typeOnlyExportAsIfBody.ts new file mode 100644 index 0000000000..5c025ff045 --- /dev/null +++ b/testdata/tests/cases/compiler/typeOnlyExportAsIfBody.ts @@ -0,0 +1,4 @@ +// @module: esnext +// @moduleResolution: bundler + +if (true) export type {};