From 3a9ad1e146890d4f6b4745521bfa3788d93d8027 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 11 Sep 2020 00:21:54 -0700 Subject: [PATCH] follow-up fix for #377 --- internal/parser/parser.go | 5 +++++ internal/parser/parser_ts_test.go | 1 + 2 files changed, 6 insertions(+) diff --git a/internal/parser/parser.go b/internal/parser/parser.go index a755e35c070..cd72802a85f 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -4434,7 +4434,12 @@ func (p *parser) parseStmt(opts parseStmtOpts) ast.Stmt { switch p.lexer.Identifier { case "type": // "export type foo = ..." + typeRange := p.lexer.Range() p.lexer.Next() + if p.lexer.HasNewlineBefore { + p.log.AddError(&p.source, logger.Loc{Start: typeRange.End()}, "Unexpected newline after \"type\"") + panic(lexer.LexerPanic{}) + } p.skipTypeScriptTypeStmt(parseStmtOpts{isModuleScope: opts.isModuleScope, isExport: true}) return ast.Stmt{Loc: loc, Data: &ast.STypeScript{}} diff --git a/internal/parser/parser_ts_test.go b/internal/parser/parser_ts_test.go index 18e65ea2584..41f6cf56942 100644 --- a/internal/parser/parser_ts_test.go +++ b/internal/parser/parser_ts_test.go @@ -118,6 +118,7 @@ func TestTSTypes(t *testing.T) { expectPrintedTS(t, "type x = {0: number, readonly 1: boolean}\n[]", "[];\n") expectPrintedTS(t, "type x = {'a': number, readonly 'b': boolean}\n[]", "[];\n") expectPrintedTS(t, "type\nFoo = {}", "type;\nFoo = {};\n") + expectParseErrorTS(t, "export type\nFoo = {}", ": error: Unexpected newline after \"type\"\n") expectPrintedTS(t, "let x: {x: 'a', y: false, z: null}", "let x;\n") expectPrintedTS(t, "let x: {foo(): void}", "let x;\n") expectPrintedTS(t, "let x: {['x']: number}", "let x;\n")