Skip to content

Commit

Permalink
follow-up fix for #377
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Sep 11, 2020
1 parent 334f4a8 commit 3a9ad1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}}

Expand Down
1 change: 1 addition & 0 deletions internal/parser/parser_ts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}", "<stdin>: 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")
Expand Down

0 comments on commit 3a9ad1e

Please sign in to comment.