Skip to content

Commit

Permalink
add STypeScriptShared
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 10, 2023
1 parent 8ae4f7c commit c316bb6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
7 changes: 4 additions & 3 deletions internal/js_ast/js_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,13 @@ type EImportMeta struct {
// These help reduce unnecessary memory allocations
var BMissingShared = &BMissing{}
var EMissingShared = &EMissing{}
var ESuperShared = &ESuper{}
var ENullShared = &ENull{}
var EUndefinedShared = &EUndefined{}
var ESuperShared = &ESuper{}
var EThisShared = &EThis{}
var SEmptyShared = &SEmpty{}
var EUndefinedShared = &EUndefined{}
var SDebuggerShared = &SDebugger{}
var SEmptyShared = &SEmpty{}
var STypeScriptShared = &STypeScript{}

type ENew struct {
Target Expr
Expand Down
26 changes: 13 additions & 13 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5929,7 +5929,7 @@ func (p *parser) parseClassStmt(loc logger.Loc, opts parseStmtOpts) js_ast.Stmt
p.hasNonLocalExportDeclareInsideNamespace = true
}

return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

p.popScope()
Expand Down Expand Up @@ -6264,7 +6264,7 @@ func (p *parser) parseFnStmt(loc logger.Loc, opts parseStmtOpts, isAsync bool, a
p.hasNonLocalExportDeclareInsideNamespace = true
}

return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

p.popScope()
Expand Down Expand Up @@ -6473,7 +6473,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
p.lexer.ExpectContextualKeyword("namespace")
p.lexer.Expect(js_lexer.TIdentifier)
p.lexer.ExpectOrInsertSemicolon()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

if p.lexer.IsContextualKeyword("async") {
Expand Down Expand Up @@ -6502,7 +6502,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
panic(js_lexer.LexerPanic{})
}
p.skipTypeScriptTypeStmt(parseStmtOpts{isModuleScope: opts.isModuleScope, isExport: true})
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}

case "namespace", "abstract", "module", "interface":
// "export namespace Foo {}"
Expand Down Expand Up @@ -7232,7 +7232,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
p.lexer.ExpectContextualKeyword("from")
p.parsePath()
p.lexer.ExpectOrInsertSemicolon()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}
}

Expand All @@ -7244,15 +7244,15 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
p.lexer.ExpectContextualKeyword("from")
p.parsePath()
p.lexer.ExpectOrInsertSemicolon()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}

case js_lexer.TOpenBrace:
// "import type {foo} from 'bar';"
p.parseImportClause()
p.lexer.ExpectContextualKeyword("from")
p.parsePath()
p.lexer.ExpectOrInsertSemicolon()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}
}

Expand Down Expand Up @@ -7317,7 +7317,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
//
if p.options.ts.Parse && p.options.ts.Config.UnusedImportFlags() == config.TSUnusedImport_KeepValues && stmt.Items != nil && len(*stmt.Items) == 0 {
if stmt.DefaultName == nil {
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}
stmt.Items = nil
}
Expand Down Expand Up @@ -7470,7 +7470,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
if p.lexer.Token == js_lexer.TIdentifier && !p.lexer.HasNewlineBefore {
// "type Foo = any"
p.skipTypeScriptTypeStmt(parseStmtOpts{isModuleScope: opts.isModuleScope})
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

case "namespace", "module":
Expand All @@ -7486,7 +7486,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
case "interface":
// "interface Foo {}"
p.skipTypeScriptInterfaceStmt(parseStmtOpts{isModuleScope: opts.isModuleScope})
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}

case "abstract":
if p.lexer.Token == js_lexer.TClass || opts.decorators != nil {
Expand All @@ -7499,7 +7499,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
p.lexer.Next()
p.parseStmtsUpTo(js_lexer.TCloseBrace, opts)
p.lexer.Next()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

case "declare":
Expand All @@ -7518,7 +7518,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
p.lexer.Expect(js_lexer.TOpenBrace)
p.parseStmtsUpTo(js_lexer.TCloseBrace, opts)
p.lexer.Next()
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

// "declare const x: any"
Expand Down Expand Up @@ -7566,7 +7566,7 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt {
}
}

return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/js_parser/ts_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ func (p *parser) parseTypeScriptEnumStmt(loc logger.Loc, opts parseStmtOpts) js_
p.hasNonLocalExportDeclareInsideNamespace = true
}

return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

// Save these for when we do out-of-order enum visiting
Expand Down Expand Up @@ -1476,7 +1476,7 @@ func (p *parser) parseTypeScriptImportEqualsStmt(loc logger.Loc, opts parseStmtO
if opts.isTypeScriptDeclare {
// "import type foo = require('bar');"
// "import type foo = bar.baz;"
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

ref := p.declareSymbol(js_ast.SymbolConst, defaultNameLoc, defaultName)
Expand Down Expand Up @@ -1667,7 +1667,7 @@ func (p *parser) parseTypeScriptNamespaceStmt(loc logger.Loc, opts parseStmtOpts
if opts.isModuleScope {
p.localTypeNames[nameText] = true
}
return js_ast.Stmt{Loc: loc, Data: &js_ast.STypeScript{}}
return js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}
}

if !opts.isTypeScriptDeclare {
Expand Down

0 comments on commit c316bb6

Please sign in to comment.