@@ -988,16 +988,44 @@ func (p *parser) skipTypeScriptInterfaceStmt(opts parseStmtOpts) {
988
988
}
989
989
990
990
func (p * parser ) skipTypeScriptTypeStmt (opts parseStmtOpts ) {
991
- if opts .isExport && p .lexer .Token == js_lexer .TOpenBrace {
992
- // "export type {foo}"
993
- // "export type {foo} from 'bar'"
994
- p .parseExportClause ()
995
- if p .lexer .IsContextualKeyword ("from" ) {
991
+ if opts .isExport {
992
+ switch p .lexer .Token {
993
+ case js_lexer .TOpenBrace :
994
+ // "export type {foo}"
995
+ // "export type {foo} from 'bar'"
996
+ p .parseExportClause ()
997
+ if p .lexer .IsContextualKeyword ("from" ) {
998
+ p .lexer .Next ()
999
+ p .parsePath ()
1000
+ }
1001
+ p .lexer .ExpectOrInsertSemicolon ()
1002
+ return
1003
+
1004
+ // This is invalid TypeScript, and is rejected by the TypeScript compiler:
1005
+ //
1006
+ // example.ts:1:1 - error TS1383: Only named exports may use 'export type'.
1007
+ //
1008
+ // 1 export type * from './types'
1009
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1010
+ //
1011
+ // However, people may not know this and then blame esbuild for it not
1012
+ // working. So we parse it anyway and then discard it (since we always
1013
+ // discard all types). People who do this should be running the TypeScript
1014
+ // type checker when using TypeScript, which will then report this error.
1015
+ case js_lexer .TAsterisk :
1016
+ // "export type * from 'path'"
996
1017
p .lexer .Next ()
1018
+ if p .lexer .IsContextualKeyword ("as" ) {
1019
+ // "export type * as ns from 'path'"
1020
+ p .lexer .Next ()
1021
+ p .parseClauseAlias ("export" )
1022
+ p .lexer .Next ()
1023
+ }
1024
+ p .lexer .ExpectContextualKeyword ("from" )
997
1025
p .parsePath ()
1026
+ p .lexer .ExpectOrInsertSemicolon ()
1027
+ return
998
1028
}
999
- p .lexer .ExpectOrInsertSemicolon ()
1000
- return
1001
1029
}
1002
1030
1003
1031
name := p .lexer .Identifier .String
0 commit comments