Source File
js_parser_lower.go
Belonging Package
github.com/evanw/esbuild/internal/js_parser
package js_parser
import (
)
func ( *parser) ( compat.JSFeature, logger.Range) ( bool) {
= true
if !.options.unsupportedJSFeatures.Has() {
if == compat.TopLevelAwait {
if .options.mode == config.ModeBundle {
.log.AddRangeError(&.source, , "Top-level await is currently not supported when bundling")
return
}
if .options.mode == config.ModeConvertFormat && !.options.outputFormat.KeepES6ImportExportSyntax() {
.log.AddRangeError(&.source, , fmt.Sprintf(
"Top-level await is currently not supported with the %q output format", .options.outputFormat.String()))
return
}
}
= false
return
}
var string
:= "the configured target environment"
switch {
case compat.DefaultArgument:
= "default arguments"
case compat.RestArgument:
= "rest arguments"
case compat.ArraySpread:
= "array spread"
case compat.ForOf:
= "for-of loops"
case compat.ObjectAccessors:
= "object accessors"
case compat.ObjectExtensions:
= "object literal extensions"
case compat.TemplateLiteral:
= "tagged template literals"
case compat.Destructuring:
= "destructuring"
case compat.NewTarget:
= "new.target"
case compat.Const:
= "const"
case compat.Let:
= "let"
case compat.Class:
= "class syntax"
case compat.Generator:
= "generator functions"
case compat.AsyncAwait:
= "async functions"
case compat.AsyncGenerator:
= "async generator functions"
case compat.ForAwait:
= "for-await loops"
case compat.NestedRestBinding:
= "non-identifier array rest patterns"
case compat.TopLevelAwait:
.log.AddRangeError(&.source, ,
fmt.Sprintf("Top-level await is not available in %s", ))
return
.log.AddRangeError(&.source, ,
fmt.Sprintf("Big integer literals are not available in %s", ))
return
.log.AddRangeWarning(&.source, ,
fmt.Sprintf("\"import.meta\" is not available in %s and will be empty", ))
return
default:
.log.AddRangeError(&.source, ,
fmt.Sprintf("This feature is not available in %s", ))
return
}
.log.AddRangeError(&.source, ,
fmt.Sprintf("Transforming %s to %s is not supported yet", , ))
return
}
func ( *parser) () bool {
return .currentScope.StrictMode != js_ast.SloppyMode
}
func ( *parser) () bool {
return .options.outputFormat == config.FormatESModule
}
type strictModeFeature uint8
const (
withStatement strictModeFeature = iota
deleteBareName
forInVarInit
evalOrArguments
reservedWord
legacyOctalLiteral
legacyOctalEscape
ifElseFunctionStmt
)
func ( *parser) ( strictModeFeature, logger.Range, string) {
var string
:= false
switch {
case withStatement:
= "With statements"
case deleteBareName:
= "Delete of a bare identifier"
case forInVarInit:
= "Variable initializers inside for-in loops"
= true
case evalOrArguments:
= fmt.Sprintf("Declarations with the name %q", )
case reservedWord:
= fmt.Sprintf("%q is a reserved word and", )
case legacyOctalLiteral:
= "Legacy octal literals"
case legacyOctalEscape:
= "Legacy octal escape sequences"
case ifElseFunctionStmt:
= "Function declarations inside if statements"
default:
= "This feature"
}
if .isStrictMode() {
var string
var []logger.MsgData
var logger.Range
switch .currentScope.StrictMode {
case js_ast.ImplicitStrictModeImport:
= "This file is implicitly in strict mode because of the \"import\" keyword"
= .es6ImportKeyword
case js_ast.ImplicitStrictModeExport:
= "This file is implicitly in strict mode because of the \"export\" keyword"
= .es6ExportKeyword
case js_ast.ImplicitStrictModeTopLevelAwait:
= "This file is implicitly in strict mode because of the top-level \"await\" keyword"
= .topLevelAwaitKeyword
case js_ast.ImplicitStrictModeClass:
= "All code inside a class is implicitly in strict mode"
= .enclosingClassKeyword
}
if != "" {
= []logger.MsgData{logger.RangeData(&.source, , )}
}
.log.AddRangeErrorWithNotes(&.source, ,
fmt.Sprintf("%s cannot be used in strict mode", ), )
} else if ! && .isStrictModeOutputFormat() {
.log.AddRangeError(&.source, ,
fmt.Sprintf("%s cannot be used with the \"esm\" output format due to strict mode", ))
}
}
func ( *parser) ( compat.JSFeature, logger.Range, compat.JSFeature) {
if .options.unsupportedJSFeatures.Has() {
.markSyntaxFeature(, )
}
}
func ( *parser) ( *js_ast.EPrivateIdentifier) bool {
return .options.unsupportedJSFeatures.Has(.symbols[.Ref.InnerIndex].Kind.Feature())
}
func ( *parser) () js_ast.Ref {
if .fnOnlyDataVisit.thisCaptureRef == nil {
:= .newSymbol(js_ast.SymbolHoisted, "_this")
.fnOnlyDataVisit.thisCaptureRef = &
}
return *.fnOnlyDataVisit.thisCaptureRef
}
func ( *parser) () js_ast.Ref {
if .fnOnlyDataVisit.argumentsCaptureRef == nil {
:= .newSymbol(js_ast.SymbolHoisted, "_arguments")
.fnOnlyDataVisit.argumentsCaptureRef = &
}
return *.fnOnlyDataVisit.argumentsCaptureRef
}
func ( *parser) (
*bool,
*[]js_ast.Arg,
logger.Loc,
*[]js_ast.Stmt,
*bool,
*bool,
bool,
if .options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
var []js_ast.Stmt
for , := range * {
if bindingHasObjectRest(.Binding) {
:= .generateTempRef(tempRefNoDeclare, "")
:= .convertBindingToExpr(.Binding, nil)
:= js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EIdentifier{Ref: }}
.recordUsage()
(*)[].Binding.Data = &js_ast.BIdentifier{Ref: }
:= ! && .fnOnlyDataVisit.argumentsRef != nil && .symbolUses[*.fnOnlyDataVisit.argumentsRef].CountEstimate > 0
var js_ast.Expr
.Args = *
.HasRestArg = *
* = nil
* = false
for , := range .Args {
break
}
= js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: *.fnOnlyDataVisit.argumentsRef}}
:= make([]js_ast.Expr, 0, len(*))
for , := range * {
:= .Binding.Data.(*js_ast.BIdentifier)
:= js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EIdentifier{Ref: .Ref}}
if * && +1 == len(*) {
.Data = &js_ast.ESpread{Value: }
}
= append(, )
}
= js_ast.Expr{Loc: , Data: &js_ast.EArray{Items: , IsSingleLine: true}}
}
}
if .fnOrArrowDataVisit.superIndexRef != nil {
:= .newSymbol(js_ast.SymbolOther, "key")
.currentScope.Generated = append(.currentScope.Generated, *.fnOrArrowDataVisit.superIndexRef, )
:= js_ast.Stmt{Loc: , Data: &js_ast.SLocal{
Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Loc: , Data: &js_ast.BIdentifier{Ref: *.fnOrArrowDataVisit.superIndexRef}},
Value: &js_ast.Expr{Loc: , Data: &js_ast.EArrow{
Args: []js_ast.Arg{{
Binding: js_ast.Binding{Loc: , Data: &js_ast.BIdentifier{Ref: }},
}},
Body: js_ast.FnBody{
Loc: ,
Stmts: []js_ast.Stmt{{Loc: , Data: &js_ast.SReturn{
Value: &js_ast.Expr{Loc: , Data: &js_ast.EIndex{
Target: js_ast.Expr{Loc: , Data: &js_ast.ESuper{}},
Index: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }},
}},
}}},
},
PreferExpr: true,
}},
}},
}}
.recordUsage()
* = []js_ast.Stmt{, }
} else {
* = []js_ast.Stmt{}
}
}
}
func ( *parser) ( js_ast.Expr, exprIn, exprOut) (js_ast.Expr, exprOut) {
:= js_ast.Expr{Loc: .Loc, Data: &js_ast.EUndefined{}}
:= false
:= false
:= false
:=
:= []js_ast.Expr{}
:= .Loc
if , := .Index.Data.(*js_ast.EPrivateIdentifier); && .isPrivateUnsupported() {
= true
}
if .OptionalChain == js_ast.OptionalChainStart {
break
}
case *js_ast.ECall:
= .Target
if .OptionalChain == js_ast.OptionalChainStart {
= true
break
}
case *js_ast.EUnary: // UnOpDelete
= js_ast.Expr{Loc: , Data: &js_ast.EBoolean{Value: true}}
= .Value
default:
panic("Internal error")
}
}
if , , := .extractPrivateIndex(); != nil {
= true
}
if !.options.unsupportedJSFeatures.Has(compat.OptionalChain) && ! {
return , exprOut{}
}
= .thisArgFunc()
if .shouldLowerSuperPropertyAccess(.Target) {
:= js_ast.Expr{Loc: .NameLoc, Data: &js_ast.EString{Value: js_lexer.StringToUTF16(.Name)}}
= .lowerSuperPropertyAccess(.Loc, )
}
if .shouldLowerSuperPropertyAccess(.Target) {
= .lowerSuperPropertyAccess(.Loc, .Index)
}
, := .captureValueWithPossibleSideEffects(, 2, )
= ()
:= ()
if != nil {
= (js_ast.Expr{Loc: , Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: , Data: &js_ast.EDot{
Target: ,
Name: "call",
NameLoc: ,
}},
Args: append([]js_ast.Expr{()}, .Args...),
CanBeUnwrappedIfUnused: .CanBeUnwrappedIfUnused,
}})
= nil
break
}
= js_ast.Expr{Loc: , Data: &js_ast.ECall{
Target: ,
Args: .Args,
IsDirectEval: .IsDirectEval,
CanBeUnwrappedIfUnused: .CanBeUnwrappedIfUnused,
}}
case *js_ast.EUnary:
= js_ast.Expr{Loc: , Data: &js_ast.EUnary{
Op: js_ast.UnOpDelete,
Value: ,
}}
default:
panic("Internal error")
}
}
= js_ast.Expr{Loc: , Data: &js_ast.EIf{
Test: js_ast.Expr{Loc: , Data: &js_ast.EBinary{
Op: js_ast.BinOpLooseEq,
Left: ,
Right: js_ast.Expr{Loc: , Data: &js_ast.ENull{}},
}},
Yes: ,
No: ,
}}
if != nil {
= ()
}
if != nil {
= ()
}
if .thisArgWrapFunc != nil {
= .thisArgWrapFunc()
}
return , exprOut{
thisArgFunc: ,
thisArgWrapFunc: ,
}
}
func ( *parser) ( js_ast.Expr, func(js_ast.Expr, js_ast.Expr) js_ast.Expr) js_ast.Expr {
switch left := .Data.(type) {
case *js_ast.EDot:
if .OptionalChain == js_ast.OptionalChainNone {
, := .captureValueWithPossibleSideEffects(.Loc, 2, .Target)
return ((
js_ast.Expr{Loc: .Loc, Data: &js_ast.EDot{
Target: (),
Name: .Name,
NameLoc: .NameLoc,
}},
js_ast.Expr{Loc: .Loc, Data: &js_ast.EDot{
Target: (),
Name: .Name,
NameLoc: .NameLoc,
}},
))
}
case *js_ast.EIndex:
if .OptionalChain == js_ast.OptionalChainNone {
, := .captureValueWithPossibleSideEffects(.Loc, 2, .Target)
, := .captureValueWithPossibleSideEffects(.Loc, 2, .Index)
return (((
js_ast.Expr{Loc: .Loc, Data: &js_ast.EIndex{
Target: (),
Index: (),
}},
js_ast.Expr{Loc: .Loc, Data: &js_ast.EIndex{
Target: (),
Index: (),
}},
)))
}
case *js_ast.EIdentifier:
return (
js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .Ref}},
,
)
}
, := .captureValueWithPossibleSideEffects(, 2, )
return (.lowerPrivateSet((), , ,
.callRuntime(, "__pow", []js_ast.Expr{
.lowerPrivateGet((), , ),
.Right,
})))
}
, := .captureValueWithPossibleSideEffects(, 2, )
:= .lowerPrivateGet((), , )
:= .lowerPrivateSet((), , , .Right)
return (.lowerNullishCoalescing(, , ))
}
, := .captureValueWithPossibleSideEffects(, 2, )
return (js_ast.Expr{Loc: , Data: &js_ast.EBinary{
Op: js_ast.BinOpNullishCoalescing,
Left: .lowerPrivateGet((), , ),
Right: .lowerPrivateSet((), , , .Right),
}})
}
return .lowerAssignmentOperator(.Left, func( js_ast.Expr, js_ast.Expr) js_ast.Expr {
return .lowerNullishCoalescing(, , js_ast.Assign(, .Right))
}
, := .captureValueWithPossibleSideEffects(, 2, )
return (js_ast.Expr{Loc: , Data: &js_ast.EBinary{
Op: ,
Left: .lowerPrivateGet((), , ),
Right: .lowerPrivateSet((), , , .Right),
}})
}
func ( *parser) ( logger.Loc, *js_ast.EObject) js_ast.Expr {
:= false
if .options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
for , := range .Properties {
if .Kind == js_ast.PropertySpread {
= true
break
}
}
}
if ! {
return js_ast.Expr{Loc: , Data: }
}
var js_ast.Expr
:= []js_ast.Property{}
for , := range .Properties {
if .Kind != js_ast.PropertySpread {
= append(, )
continue
}
if len() > 0 || .Data == nil {
= js_ast.Expr{Loc: , Data: &js_ast.EObject{
Properties: ,
IsSingleLine: .IsSingleLine,
}}
= .callRuntime(, "__assign",
[]js_ast.Expr{, {Loc: , Data: &js_ast.EObject{
Properties: ,
IsSingleLine: .IsSingleLine,
}}})
}
= []js_ast.Property{}
}
= .callRuntime(, "__assign", []js_ast.Expr{, *.Value})
}
= .callRuntime(, "__assign", []js_ast.Expr{, {Loc: , Data: &js_ast.EObject{
Properties: ,
IsSingleLine: .IsSingleLine,
}}})
}
return
}
func ( *parser) ( js_ast.Expr, logger.Loc, *js_ast.EPrivateIdentifier) js_ast.Expr {
switch .symbols[.Ref.InnerIndex].Kind {
:= .privateGetters[.Ref]
.recordUsage()
return .callRuntime(.Loc, "__privateMethod", []js_ast.Expr{
,
{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}},
{Loc: , Data: &js_ast.EIdentifier{Ref: }},
})
case js_ast.SymbolPrivateGet, js_ast.SymbolPrivateStaticGet,
:= .privateGetters[.Ref]
.recordUsage()
return .callRuntime(.Loc, "__privateGet", []js_ast.Expr{
,
{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}},
{Loc: , Data: &js_ast.EIdentifier{Ref: }},
})
return .callRuntime(.Loc, "__privateGet", []js_ast.Expr{
,
{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}},
})
}
}
func ( *parser) (
js_ast.Expr,
logger.Loc,
*js_ast.EPrivateIdentifier,
js_ast.Expr,
) js_ast.Expr {
switch .symbols[.Ref.InnerIndex].Kind {
case js_ast.SymbolPrivateSet, js_ast.SymbolPrivateStaticSet,
:= .privateSetters[.Ref]
.recordUsage()
return .callRuntime(.Loc, "__privateSet", []js_ast.Expr{
,
{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}},
,
{Loc: , Data: &js_ast.EIdentifier{Ref: }},
})
, := .captureValueWithPossibleSideEffects(.Loc, 2, )
return (.lowerPrivateSet((), , , js_ast.Expr{Loc: .Loc, Data: &js_ast.EBinary{
Op: ,
Left: .lowerPrivateGet((), , ),
Right: ,
}}))
}
func ( *parser) ( js_ast.Expr) (js_ast.Expr, logger.Loc, *js_ast.EPrivateIdentifier) {
if , := .Data.(*js_ast.EIndex); {
if , := .Index.Data.(*js_ast.EPrivateIdentifier); && .isPrivateUnsupported() {
return .Target, .Index.Loc,
}
}
return js_ast.Expr{}, logger.Loc{}, nil
}
func ( js_ast.Binding) bool {
switch b := .Data.(type) {
case *js_ast.BArray:
for , := range .Items {
if (.Binding) {
return true
}
}
case *js_ast.BObject:
for , := range .Properties {
if .IsSpread || (.Value) {
return true
}
}
}
return false
}
func ( js_ast.Expr) bool {
switch e := .Data.(type) {
case *js_ast.EBinary:
if .Op == js_ast.BinOpAssign && (.Left) {
return true
}
case *js_ast.EArray:
for , := range .Items {
if () {
return true
}
}
case *js_ast.EObject:
for , := range .Properties {
if .Kind == js_ast.PropertySpread || (*.Value) {
return true
}
}
}
return false
}
func ( *parser) ( []js_ast.Decl) []js_ast.Decl {
if !.options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
return
}
for , := range {
if .Value != nil && bindingHasObjectRest(.Binding) {
:= append([]js_ast.Decl{}, [:]...)
for , := range [:] {
if .Value != nil {
:= .convertBindingToExpr(.Binding, nil)
if , := .lowerObjectRestToDecls(, *.Value, ); {
=
continue
}
}
= append(, )
}
return
}
}
return
}
func ( *parser) ( js_ast.Stmt, *js_ast.Stmt) {
if !.options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
return
}
var js_ast.Stmt
switch s := .Data.(type) {
if exprHasObjectRest(.Value) {
:= .generateTempRef(tempRefNeedsDeclare, "")
if , := .lowerObjectRestInAssign(.Value, js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }}); {
.Value.Data = &js_ast.EIdentifier{Ref: }
= js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }}
}
}
if len(.Decls) == 1 && bindingHasObjectRest(.Decls[0].Binding) {
:= .generateTempRef(tempRefNoDeclare, "")
:= js_ast.Decl{Binding: .Decls[0].Binding, Value: &js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }}}
.recordUsage()
:= .lowerObjectRestInDecls([]js_ast.Decl{})
.Decls[0].Binding.Data = &js_ast.BIdentifier{Ref: }
= js_ast.Stmt{Loc: .Loc, Data: &js_ast.SLocal{Kind: .Kind, Decls: }}
}
}
if .Data != nil {
.Data = &js_ast.SBlock{Stmts: []js_ast.Stmt{, *}}
}
}
}
func ( *parser) ( *js_ast.Catch) {
if !.options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
return
}
if .Binding != nil && bindingHasObjectRest(*.Binding) {
:= .generateTempRef(tempRefNoDeclare, "")
:= js_ast.Decl{Binding: *.Binding, Value: &js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EIdentifier{Ref: }}}
.recordUsage()
:= .lowerObjectRestInDecls([]js_ast.Decl{})
.Binding.Data = &js_ast.BIdentifier{Ref: }
:= make([]js_ast.Stmt, 0, 1+len(.Body))
= append(, js_ast.Stmt{Loc: .Binding.Loc, Data: &js_ast.SLocal{Kind: js_ast.LocalLet, Decls: }})
.Body = append(, .Body...)
}
}
func ( *parser) ( js_ast.Expr, js_ast.Expr) (js_ast.Expr, bool) {
var js_ast.Expr
:= func( js_ast.Expr, js_ast.Expr) {
= maybeJoinWithComma(, js_ast.Assign(, ))
}
if .lowerObjectRestHelper(, , , tempRefNeedsDeclare) {
return , true
}
return js_ast.Expr{}, false
}
func ( *parser) ( js_ast.Expr, js_ast.Expr, []js_ast.Decl) ([]js_ast.Decl, bool) {
:= func( js_ast.Expr, js_ast.Expr) {
, := .convertExprToBinding(, nil)
if len() > 0 {
panic("Internal error")
}
= append(, js_ast.Decl{Binding: , Value: &})
}
if .lowerObjectRestHelper(, , , tempRefNoDeclare) {
return , true
}
return nil, false
}
func ( *parser) (
js_ast.Expr,
js_ast.Expr,
func(js_ast.Expr, js_ast.Expr),
generateTempRefArg,
) bool {
if !.options.unsupportedJSFeatures.Has(compat.ObjectRestSpread) {
return false
}
:= make(map[js_ast.E]bool)
var func(js_ast.Expr) bool
= func( js_ast.Expr) bool {
:= false
switch e := .Data.(type) {
case *js_ast.EBinary:
if .Op == js_ast.BinOpAssign && (.Left) {
= true
}
case *js_ast.EArray:
for , := range .Items {
if () {
= true
}
}
case *js_ast.EObject:
for , := range .Properties {
if .Kind == js_ast.PropertySpread || (*.Value) {
= true
}
}
}
if {
[.Data] = true
}
return
}
()
if len() == 0 {
return false
}
:= ()
(js_ast.Expr{Loc: [0].Key.Loc, Data: &js_ast.EObject{Properties: , IsSingleLine: }},
js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }})
= js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }}
.recordUsage()
.recordUsage()
}
:= .generateTempRef(, "")
:= *
.Data = &js_ast.EIdentifier{Ref: }
:= append(, )
var js_ast.Expr
var js_ast.Expr
if len() > 0 {
:= .generateTempRef(, "")
:= [0].Loc
= js_ast.Expr{Loc: , Data: &js_ast.EArray{Items: , IsSingleLine: }}
= js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }}
= append(, js_ast.Expr{Loc: , Data: &js_ast.ESpread{Value: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }}}})
.recordUsage()
.recordUsage()
}
(, js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }}, nil)
.recordUsage()
:= .generateTempRef(, "")
:= *
.Data = &js_ast.EIdentifier{Ref: }
.recordUsage()
(js_ast.Expr{Loc: .Loc, Data: &js_ast.EObject{Properties: , IsSingleLine: }}, )
(, js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }}, nil)
.recordUsage()
if len() > 0 {
(js_ast.Expr{Loc: .Loc, Data: &js_ast.EObject{
Properties: ,
IsSingleLine: ,
}}, , )
}
}
if [.Data] {
(.Items[:], , append([]js_ast.Expr{}, .Items[+1:]...), , .IsSingleLine)
return
}
}
case *js_ast.EObject:
:= len(.Properties) - 1
:= >= 0 && .Properties[].Kind == js_ast.PropertySpread
for := range .Properties {
:= &.Properties[]
if .Kind == js_ast.PropertySpread {
(.Properties[:], *.Value, , , .IsSingleLine)
return
}
if {
, := .captureKeyForObjectRest(.Key)
.Key =
= append(, )
}
if [.Value.Data] {
(.Properties[:+1], .Properties[+1:], , , .IsSingleLine)
return
}
}
}
(, )
}
(, , nil)
return true
}
= func() js_ast.Expr {
return js_ast.Expr{Loc: , Data: &js_ast.EBinary{
Op: js_ast.BinOpAdd,
Left: js_ast.Expr{Loc: , Data: &js_ast.ENumber{Value: .Value}},
Right: js_ast.Expr{Loc: , Data: &js_ast.EString{}},
}}
}
case *js_ast.EIdentifier:
= func() js_ast.Expr {
.recordUsage(.Ref)
return .callRuntime(, "__restKey", []js_ast.Expr{{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}}})
}
:= .generateTempRef(tempRefNeedsDeclare, "")
= js_ast.Assign(js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }}, )
= func() js_ast.Expr {
.recordUsage()
return .callRuntime(, "__restKey", []js_ast.Expr{{Loc: , Data: &js_ast.EIdentifier{Ref: }}})
}
}
return
}
if != js_ast.InvalidRef {
.mergeSymbols(, .Name.Ref)
}
if .options.mangleSyntax && .UseCountEstimate == 0 {
.Name = nil
}
}
} else if , := .Data.(*js_ast.SClass); {
= &.Class
if .IsExport {
=
} else {
=
}
= .symbols[.Name.Ref.InnerIndex].OriginalName
} else {
, := .Data.(*js_ast.SExportDefault)
, := .Value.Stmt.Data.(*js_ast.SClass)
= &.Class
= .DefaultName
=
if .Name != nil {
= .symbols[.Name.Ref.InnerIndex].OriginalName
} else {
= "default"
}
}
if .Data == nil {
= .Loc
} else {
= .Loc
}
var *js_ast.EFunction
var []js_ast.Stmt
var []js_ast.Stmt
var []js_ast.Stmt
:= 0
if .Name != nil {
.mergeSymbols(.Name.Ref, .Data.(*js_ast.EIdentifier).Ref)
.Name = nil
}
return
} else {
if .Name == nil {
if == {
.Name = &
} else {
.Name = &js_ast.LocRef{Loc: , Ref: .generateTempRef(tempRefNoDeclare, "zomzomz")}
}
}
.recordUsage(.Name.Ref)
return js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: .Name.Ref}}
}
}
:= .options.mode == config.ModeBundle && .currentScope.Parent == nil
, := .Key.Data.(*js_ast.EPrivateIdentifier)
:= != nil && .isPrivateUnsupported()
:= .options.ts.Parse && !.IsMethod && .Initializer == nil &&
!.options.useDefineForClassFields && !
:= !.IsMethod &&
((!.IsStatic && .options.unsupportedJSFeatures.Has(compat.ClassField)) ||
(.IsStatic && .options.unsupportedJSFeatures.Has(compat.ClassStaticField)))
if !.IsMethod && .IsStatic && && != js_ast.InvalidRef {
= true
}
:= .Key
if .IsComputed && (.options.ts.Parse || len(.TSDecorators) > 0 ||
|| .Data != nil) {
:= true
if len(.TSDecorators) == 0 && (.IsMethod || ) {
= false
}
= maybeJoinWithComma(, .Key)
if len(.TSDecorators) > 0 {
:= .Key.Loc
var js_ast.Expr
switch k := .Data.(type) {
case *js_ast.ENumber:
= js_ast.Expr{Loc: , Data: &js_ast.ENumber{Value: .Value}}
case *js_ast.EString:
= js_ast.Expr{Loc: , Data: &js_ast.EString{Value: .Value}}
case *js_ast.EIdentifier:
= js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: .Ref}}
default:
panic("Internal error")
}
var js_ast.Expr
if .Initializer != nil {
= *.Initializer
} else {
= js_ast.Expr{Loc: , Data: &js_ast.EUndefined{}}
}
:= .generateTempRef(tempRefNeedsDeclare, "_"+.symbols[.Ref.InnerIndex].OriginalName[1:])
.symbols[.Ref.InnerIndex].Link =
if .weakMapRef == js_ast.InvalidRef {
.weakMapRef = .newSymbol(js_ast.SymbolUnbound, "WeakMap")
.moduleScope.Generated = append(.moduleScope.Generated, .weakMapRef)
}
= append(, js_ast.Assign(
js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }},
js_ast.Expr{Loc: , Data: &js_ast.ENew{Target: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: .weakMapRef}}}},
))
.recordUsage()
= js_ast.Expr{Loc: , Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: , Data: &js_ast.EDot{
Target: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }},
Name: "set",
NameLoc: ,
}},
Args: []js_ast.Expr{
,
,
},
}}
.recordUsage()
} else if == nil && .options.useDefineForClassFields {
if , := .Data.(*js_ast.EUndefined); {
= .callRuntime(, "__publicField", []js_ast.Expr{, .Key})
} else {
= .callRuntime(, "__publicField", []js_ast.Expr{, .Key, })
}
} else {
if , := .Key.Data.(*js_ast.EString); && !.IsComputed {
= js_ast.Expr{Loc: , Data: &js_ast.EDot{
Target: ,
Name: js_lexer.UTF16ToString(.Value),
NameLoc: ,
}}
} else {
= js_ast.Expr{Loc: , Data: &js_ast.EIndex{
Target: ,
Index: .Key,
}}
}
= js_ast.Assign(, )
}
= append(, )
continue
}
.Initializer = nil
}
:= .generateTempRef(tempRefNeedsDeclare, "_"+.symbols[.Ref.InnerIndex].OriginalName[1:])
.symbols[.Ref.InnerIndex].Link =
if .weakSetRef == js_ast.InvalidRef {
.weakSetRef = .newSymbol(js_ast.SymbolUnbound, "WeakSet")
.moduleScope.Generated = append(.moduleScope.Generated, .weakSetRef)
}
= append(, js_ast.Assign(
js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }},
js_ast.Expr{Loc: , Data: &js_ast.ENew{Target: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: .weakSetRef}}}},
))
.recordUsage()
= append(, )
:= .generateTempRef(tempRefNeedsDeclare, "_")
if .Kind == js_ast.PropertySet {
.symbols[.InnerIndex].Link = .privateSetters[.Ref]
} else {
.symbols[.InnerIndex].Link = .privateGetters[.Ref]
}
= append(, js_ast.Assign(
js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }},
*.Value,
))
continue
} else if , := .Key.Data.(*js_ast.EString); && js_lexer.UTF16EqualsString(.Value, "constructor") {
if , := .Value.Data.(*js_ast.EFunction); {
=
if .options.ts.Parse {
for , := range .Fn.Args {
if .IsTypeScriptCtorField {
if , := .Binding.Data.(*js_ast.BIdentifier); {
= append(, js_ast.AssignStmt(
js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EDot{
Target: js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EThis{}},
Name: .symbols[.Ref.InnerIndex].OriginalName,
NameLoc: .Binding.Loc,
}},
js_ast.Expr{Loc: .Binding.Loc, Data: &js_ast.EIdentifier{Ref: .Ref}},
))
}
}
}
}
}
}
}
.Properties[] =
++
}
.Properties = .Properties[:]
if .Extends != nil {
:= .newSymbol(js_ast.SymbolUnbound, "arguments")
.currentScope.Generated = append(.currentScope.Generated, )
.Fn.Body.Stmts = append(.Fn.Body.Stmts, js_ast.Stmt{Loc: , Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: , Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: , Data: &js_ast.ESuper{}},
Args: []js_ast.Expr{{Loc: , Data: &js_ast.ESpread{Value: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }}}}},
}}}})
}
}
for := 0; < len(.Properties); ++ {
if .Properties[].Value != nil && .Properties[].Value.Data == {
:= .Properties[]
for := ; > 0; -- {
.Properties[] = .Properties[-1]
}
.Properties[0] =
break
}
}
}
if .Data != nil {
= js_ast.JoinWithComma(, )
}
for , := range {
= js_ast.JoinWithComma(, )
}
for , := range {
= js_ast.JoinWithComma(, )
}
for , := range {
= js_ast.JoinWithComma(, )
}
if .Data != nil {
= js_ast.JoinWithComma(, )
}
if != nil {
= ()
}
if .options.keepNames && != "" {
= .keepExprSymbolName(, )
}
return nil,
}
var js_ast.Stmt
if .options.keepNames && != "" {
:= ()
= .keepStmtSymbolName(.Loc, .Data.(*js_ast.EIdentifier).Ref, )
}
:= .newSymbol(js_ast.SymbolOther, .symbols[.InnerIndex].OriginalName)
.currentScope.Generated = append(.currentScope.Generated, )
.recordDeclaredSymbol()
.mergeSymbols(, )
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SLocal{
Kind: .selectLocalKind(js_ast.LocalConst),
Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Loc: .Loc, Data: &js_ast.BIdentifier{Ref: }},
Value: ,
}},
}})
= &js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: }}
.recordUsage()
if != js_ast.InvalidRef {
.mergeSymbols(, )
}
}
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SLocal{
Kind: .selectLocalKind(js_ast.LocalLet),
IsExport: == ,
Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Loc: .Loc, Data: &js_ast.BIdentifier{Ref: }},
Value: ,
}},
}})
} else {
switch {
case :
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SClass{Class: *}})
case :
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SClass{Class: *, IsExport: true}})
case :
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SExportDefault{
DefaultName: ,
Value: js_ast.ExprOrStmt{Stmt: &js_ast.Stmt{Loc: , Data: &js_ast.SClass{Class: *}}},
}})
}
if .Name != nil && != js_ast.InvalidRef {
.mergeSymbols(, .Name.Ref)
}
}
if .Data != nil {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
for , := range {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
for , := range {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
for , := range {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
for , := range {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
for , := range {
= append(, js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExpr{Value: }})
}
if len(.TSDecorators) > 0 {
= append(, js_ast.AssignStmt(
js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .Ref}},
.callRuntime(, "__decorate", []js_ast.Expr{
{Loc: , Data: &js_ast.EArray{Items: .TSDecorators}},
{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .Ref}},
}),
))
.recordUsage(.Ref)
.recordUsage(.Ref)
}
if {
:= .generateTempRef(tempRefNoDeclare, .source.IdentifierName+"_default")
.recordDeclaredSymbol()
:= ()
= append(, js_ast.Stmt{Loc: , Data: &js_ast.SExportDefault{
DefaultName: js_ast.LocRef{Loc: .Loc, Ref: },
Value: js_ast.ExprOrStmt{Expr: &},
}})
}
.Name = nil
}
if .Data != nil {
= append(, )
}
return , js_ast.Expr{}
}
func ( *parser) ( js_ast.Expr) bool {
if .fnOrArrowDataVisit.isAsync && .options.unsupportedJSFeatures.Has(compat.AsyncAwait) {
, := .Data.(*js_ast.ESuper)
return
}
return false
}
func ( *parser) ( logger.Loc, js_ast.Expr) js_ast.Expr {
if .fnOrArrowDataVisit.superIndexRef == nil {
:= .newSymbol(js_ast.SymbolOther, "__super")
.fnOrArrowDataVisit.superIndexRef = &
}
.recordUsage(*.fnOrArrowDataVisit.superIndexRef)
return js_ast.Expr{Loc: , Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: , Data: &js_ast.EIdentifier{Ref: *.fnOrArrowDataVisit.superIndexRef}},
Args: []js_ast.Expr{},
}}
}
func ( *parser) ( *js_ast.ECall) {
var js_ast.Expr
switch e := .Target.Data.(type) {
if !.shouldLowerSuperPropertyAccess(.Target) {
return
}
= .Index
default:
return
}
.Target.Data = &js_ast.EDot{
Target: .lowerSuperPropertyAccess(.Target.Loc, ),
NameLoc: .Loc,
Name: "call",
}
:= js_ast.Expr{Loc: .Target.Loc, Data: &js_ast.EThis{}}
.Args = append([]js_ast.Expr{}, .Args...)
}
func ( js_ast.E) bool {
switch .(type) {
case *js_ast.ENull, *js_ast.EUndefined, *js_ast.EBoolean, *js_ast.ENumber,
*js_ast.EBigInt, *js_ast.EString, *js_ast.EFunction, *js_ast.EArrow:
return false
}
return true
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |