Source File
linker.go
Belonging Package
github.com/evanw/esbuild/internal/bundler
package bundler
import (
)
type bitSet struct {
entries []byte
}
func ( uint) bitSet {
return bitSet{make([]byte, (+7)/8)}
}
func ( bitSet) ( uint) bool {
return (.entries[/8] & (1 << ( & 7))) != 0
}
func ( bitSet) ( uint) {
.entries[/8] |= 1 << ( & 7)
}
func ( bitSet) ( bitSet) bool {
return bytes.Equal(.entries, .entries)
}
func ( bitSet) ( bitSet) {
copy(.entries, .entries)
}
func ( *bitSet) ( bitSet) {
for := range .entries {
.entries[] |= .entries[]
}
}
type linkerContext struct {
options *config.Options
log logger.Log
fs fs.FS
res resolver.Resolver
symbols js_ast.SymbolMap
entryPoints []uint32
files []file
hasErrors bool
dataForSourceMaps func() []dataForSourceMap
}
sortedAndFilteredExportAliases []string
}
type importToBind struct {
sourceIndex uint32
nameLoc logger.Loc // Optional, goes with sourceIndex, ignore if zero
ref js_ast.Ref
}
type exportData struct {
ref js_ast.Ref
sourceIndex uint32
nameLoc logger.Loc // Optional, goes with sourceIndex, ignore if zero
}
nonLocalDependencies []partRef
}
type partRef struct {
sourceIndex uint32
partIndex uint32
}
type partRange struct {
sourceIndex uint32
partIndexBegin uint32
partIndexEnd uint32
}
isEntryPoint bool
sourceIndex uint32 // An index into "c.sources"
entryPointBit uint // An index into "c.entryPoints"
chunkRepr chunkRepr
}
type generateContinue struct {
crossChunkImportRecords []ast.ImportRecord
crossChunkAbsPaths []string
}
type chunkRepr interface {
generate(c *linkerContext, chunk *chunkInfo) func(generateContinue) []OutputFile
}
crossChunkPrefixStmts []js_ast.Stmt
crossChunkSuffixStmts []js_ast.Stmt
exportsToOtherChunks map[js_ast.Ref]string
importsFromOtherChunks map[uint32]crossChunkImportItemArray
}
type chunkReprCSS struct {
}
:= linkerContext{
options: ,
log: ,
fs: ,
res: ,
entryPoints: append([]uint32{}, ...),
files: make([]file, len()),
symbols: js_ast.NewSymbolMap(len()),
reachableFiles: ,
dataForSourceMaps: ,
for , := range .reachableFiles {
:= []
switch repr := .repr.(type) {
{
:= *
= &
.repr =
}
.ast.ImportRecords = append([]ast.ImportRecord{}, .ast.ImportRecords...)
:= make(map[js_ast.Ref]js_ast.NamedImport, len(.ast.NamedImports))
for , := range .ast.NamedImports {
[] =
}
.ast.NamedImports =
:= make(map[string]exportData)
for , := range .ast.NamedExports {
[] = exportData{
ref: .Ref,
sourceIndex: ,
nameLoc: .AliasLoc,
}
}
:= make(map[js_ast.Ref][]uint32)
for , := range .ast.TopLevelSymbolToParts {
[] =
}
.ast.TopLevelSymbolToParts =
.meta = fileMeta{
cjsStyleExports: .ast.HasCommonJSFeatures() ||
(.Mode == config.ModeBundle && .ast.ModuleScope.ContainsDirectEval) ||
(.ast.HasLazyExport && .options.Mode == config.ModeConvertFormat && !.options.OutputFormat.KeepES6ImportExportSyntax()),
partMeta: make([]partMeta, len(.ast.Parts)),
resolvedExports: ,
isProbablyTypeScriptType: make(map[js_ast.Ref]bool),
importsToBind: make(map[js_ast.Ref]importToBind),
skipCallingToModule: .ast.ExportKeyword.Len > 0 && !.ast.HasCommonJSFeatures(),
}
{
:= *
= &
.repr =
}
.ast.ImportRecords = append([]ast.ImportRecord{}, .ast.ImportRecords...)
}
.distanceFromEntryPoint = ^uint32(0)
.files[] =
}
.stableSourceIndices = make([]uint32, len(.files))
for , := range .reachableFiles {
.stableSourceIndices[] = uint32()
}
for , := range {
:= &.files[]
.isEntryPoint = true
if .ast.HasLazyExport && .options.Mode == config.ModePassThrough {
.meta.cjsStyleExports = true
}
if .ast.ExportKeyword.Len > 0 && (.OutputFormat == config.FormatCommonJS ||
(.OutputFormat == config.FormatIIFE && len(.GlobalName) > 0)) {
.ast.UsesExportsRef = true
.meta.forceIncludeExportsForEntryPoint = true
}
}
}
if .options.OutputFormat == config.FormatCommonJS {
:= &.symbols.Outer[runtime.SourceIndex]
:= .files[runtime.SourceIndex].repr.(*reprJS).ast.ModuleScope
.unboundModuleRef = js_ast.Ref{OuterIndex: runtime.SourceIndex, InnerIndex: uint32(len(*))}
.Generated = append(.Generated, .unboundModuleRef)
* = append(*, js_ast.Symbol{
Kind: js_ast.SymbolUnbound,
OriginalName: "module",
Link: js_ast.InvalidRef,
})
} else {
.unboundModuleRef = js_ast.InvalidRef
}
return
}
= func( uint32) {
if ![] {
[] = true
:= &[]
if , := .repr.(*reprJS); && .cssSourceIndex.IsValid() {
(.cssSourceIndex.GetIndex())
}
for , := range *.repr.importRecords() {
if .SourceIndex.IsValid() {
(.SourceIndex.GetIndex())
}
}
= append(, )
}
}
for , := range {
()
}
return
}
func ( *linkerContext) ( logger.Source, logger.Range, string) {
.log.AddRangeError(&, , )
.hasErrors = true
}
func ( *linkerContext) ( logger.Source, logger.Range, string, []logger.MsgData) {
.log.AddRangeErrorWithNotes(&, , , )
.hasErrors = true
}
func ( *linkerContext) ( uint32, js_ast.Part, partMeta) uint32 {
if .LocalDependencies == nil {
.LocalDependencies = make(map[uint32]bool)
}
if .SymbolUses == nil {
.SymbolUses = make(map[js_ast.Ref]js_ast.SymbolUse)
}
if .entryBits.entries == nil {
.entryBits = newBitSet(uint(len(.entryPoints)))
}
:= .files[].repr.(*reprJS)
:= uint32(len(.ast.Parts))
.prevSibling =
.nextSibling =
.ast.Parts = append(.ast.Parts, )
.meta.partMeta = append(.meta.partMeta, )
return
}
func ( *linkerContext) () []OutputFile {
.scanImportsAndExports()
if .hasErrors {
return []OutputFile{}
}
.markPartsReachableFromEntryPoints()
.handleCrossChunkAssignments()
if .options.Mode == config.ModePassThrough {
for , := range .entryPoints {
.preventExportsFromBeingRenamed()
}
}
:= .computeChunks()
.computeCrossChunkDependencies()
js_ast.FollowAllSymbols(.symbols)
return .generateChunksInParallel()
}
{
:=
for , := range {
, , := .chunkFileOrder(&)
switch .chunkRepr.(type) {
case *chunkReprJS:
[].filesInChunkInOrder =
[].partsInChunkInOrder =
if len() > 0 {
:= .baseNameOrEmpty
if != "" {
if := .options.OutputExtensionJS; strings.HasSuffix(, ) {
= [:len()-len()]
}
+= .options.OutputExtensionCSS
}
= append(, chunkInfo{
filesInChunkInOrder: ,
entryBits: .entryBits,
isEntryPoint: .isEntryPoint,
sourceIndex: .sourceIndex,
entryPointBit: .entryPointBit,
relDir: .relDir,
baseNameOrEmpty: ,
filesWithPartsInChunk: make(map[uint32]bool),
chunkRepr: &chunkReprCSS{},
})
}
case *chunkReprCSS:
[].filesInChunkInOrder =
}
}
}
for := range {
go func( int) {
:= &[]
:= &[]
..Wait()
:= make([]ast.ImportRecord, len(.crossChunkImports))
:= make([]string, len(.crossChunkImports))
for , := range .crossChunkImports {
:= [].relPath()
[] = .fs.Join(.options.AbsOutputDir, )
[] = ast.ImportRecord{
Kind: ast.ImportStmt,
Path: logger.Path{Text: .pathBetweenChunks(.relDir, )},
}
}
[] = (generateContinue{
crossChunkAbsPaths: ,
crossChunkImportRecords: ,
})
.Wait()
var []OutputFile
for , := range {
= append(, ...)
}
return
}
if .options.PublicPath != "" {
return .options.PublicPath +
}
= strings.ReplaceAll(, "\\", "/")
for , := range .ImportRecordIndices {
:= &.ast.ImportRecords[]
if .SourceIndex.IsValid() && .isExternalDynamicImport() {
.Path.Text = .pathBetweenChunks(.relDir, .files[.SourceIndex.GetIndex()].entryPointRelPath)
.SourceIndex = ast.Index32{}
}
}
for , := range .DeclaredSymbols {
if .IsTopLevel {
.symbols.Get(.Ref).ChunkIndex = ast.MakeIndex32(uint32())
}
}
for := range .SymbolUses {
:= .symbols.Get()
if .Kind == js_ast.SymbolUnbound {
continue
}
if .ImportItemStatus == js_ast.ImportItemMissing {
continue
}
if , := .meta.importsToBind[]; {
= .ref
= .symbols.Get()
continue
}
if .NamespaceAlias != nil {
= .NamespaceAlias.NamespaceRef
}
for := range {
:= &[]
, := .chunkRepr.(*chunkReprJS)
if ! {
continue
}
if := .symbols.Get().ChunkIndex; .IsValid() {
if := .GetIndex(); != uint32() {
.importsFromOtherChunks[] =
append(.importsFromOtherChunks[], crossChunkImportItem{ref: })
[].[] = true
}
}
}
if .isEntryPoint {
for , := range {
if != && .entryBits.hasBit(.entryPointBit) {
:= .importsFromOtherChunks[uint32()]
.importsFromOtherChunks[uint32()] =
}
}
}
}
for := range {
:= &[]
, := .chunkRepr.(*chunkReprJS)
if ! {
continue
}
.exportsToOtherChunks = make(map[js_ast.Ref]string)
switch .options.OutputFormat {
case config.FormatESModule:
:= renamer.ExportRenamer{}
var []js_ast.ClauseItem
for , := range .sortedCrossChunkExportItems([].) {
var string
if .options.MinifyIdentifiers {
= .NextMinifiedName()
} else {
= .NextRenamedName(.symbols.Get(.ref).OriginalName)
}
= append(, js_ast.ClauseItem{Name: js_ast.LocRef{Ref: .ref}, Alias: })
.exportsToOtherChunks[.ref] =
}
if len() > 0 {
.crossChunkSuffixStmts = []js_ast.Stmt{{Data: &js_ast.SExportClause{
Items: ,
}}}
}
default:
panic("Internal error")
}
}
for := range {
:= &[]
, := .chunkRepr.(*chunkReprJS)
if ! {
continue
}
var []uint32
var []js_ast.Stmt
for , := range .sortedCrossChunkImports(, .importsFromOtherChunks) {
switch .options.OutputFormat {
case config.FormatESModule:
var []js_ast.ClauseItem
for , := range .sortedImportItems {
= append(, js_ast.ClauseItem{Name: js_ast.LocRef{Ref: .ref}, Alias: .exportAlias})
}
:= uint32(len())
= append(, .chunkIndex)
= append(, js_ast.Stmt{Data: &js_ast.SImport{
ImportRecordIndex: ,
}})
}
default:
panic("Internal error")
}
}
.crossChunkImports =
.crossChunkPrefixStmts =
}
}
type crossChunkImport struct {
chunkIndex uint32
sortingKey string
sortedImportItems crossChunkImportItemArray
}
type crossChunkImportArray []crossChunkImport
func ( crossChunkImportArray) () int { return len() }
func ( crossChunkImportArray) ( int, int) { [], [] = [], [] }
func ( crossChunkImportArray) ( int, int) bool {
return [].sortingKey < [].sortingKey
}
func ( *linkerContext) ( []chunkInfo, map[uint32]crossChunkImportItemArray) crossChunkImportArray {
:= make(crossChunkImportArray, 0, len())
:= [].chunkRepr.(*chunkReprJS).exportsToOtherChunks
for , := range {
[].exportAlias = [.ref]
}
sort.Sort()
= append(, crossChunkImport{
chunkIndex: ,
sortingKey: string([].entryBits.entries),
sortedImportItems: ,
})
}
sort.Sort()
return
}
type crossChunkImportItem struct {
ref js_ast.Ref
exportAlias string
}
type crossChunkImportItemArray []crossChunkImportItem
func ( crossChunkImportItemArray) () int { return len() }
func ( crossChunkImportItemArray) ( int, int) { [], [] = [], [] }
func ( crossChunkImportItemArray) ( int, int) bool {
return [].exportAlias < [].exportAlias
}
type crossChunkExportItem struct {
ref js_ast.Ref
keyPath logger.Path
}
type crossChunkExportItemArray []crossChunkExportItem
func ( crossChunkExportItemArray) () int { return len() }
func ( crossChunkExportItemArray) ( int, int) { [], [] = [], [] }
func ( crossChunkExportItemArray) ( int, int) bool {
:= []
:= []
return .ref.InnerIndex < .ref.InnerIndex ||
(.ref.InnerIndex == .ref.InnerIndex && .keyPath.ComesBeforeInSortedOrder(.keyPath))
}
func ( *linkerContext) ( map[js_ast.Ref]bool) crossChunkExportItemArray {
:= make(crossChunkExportItemArray, 0, len())
for := range {
= append(, crossChunkExportItem{ref: , keyPath: .files[.OuterIndex].source.KeyPath})
}
sort.Sort()
return
}
for , := range .reachableFiles {
:= &.files[]
switch repr := .repr.(type) {
if .additionalFiles != nil {
panic("Internal error")
}
for := range .ast.ImportRecords {
if := &.ast.ImportRecords[]; .SourceIndex.IsValid() {
:= &.files[.SourceIndex.GetIndex()]
if , := .repr.(*reprJS); {
.Path.Text = .ast.URLForCSS
.Path.Namespace = ""
.SourceIndex = ast.Index32{}
.additionalFiles = append(.additionalFiles, .additionalFiles...)
}
}
}
case *reprJS:
for := range .ast.ImportRecords {
:= &.ast.ImportRecords[]
if !.SourceIndex.IsValid() {
continue
}
:= &.files[.SourceIndex.GetIndex()]
:= .repr.(*reprJS)
switch .Kind {
if .ContainsImportStar && !.ast.HasESMFeatures() && !.ast.HasLazyExport {
.meta.cjsStyleExports = true
}
.meta.cjsStyleExports = true
case ast.ImportDynamic:
if !.isEntryPoint {
.entryPoints = append(.entryPoints, .SourceIndex.GetIndex())
.isEntryPoint = true
}
.meta.cjsStyleExports = true
}
}
}
}
}
for , := range .reachableFiles {
if , := .files[].repr.(*reprJS); && len(.ast.ExportStarImportRecords) > 0 {
:= make(map[uint32]bool)
.isCommonJSDueToExportStar(, )
}
}
if .ast.HasLazyExport {
.generateCodeForLazyExport()
}
if .meta.cjsStyleExports &&
(.options.OutputFormat == config.FormatIIFE ||
.options.OutputFormat == config.FormatESModule) {
.meta.cjsWrap = true
}
for , := range .ast.ImportRecords {
if .SourceIndex.IsValid() {
:= .files[.SourceIndex.GetIndex()].repr.(*reprJS)
if .meta.cjsStyleExports {
.meta.cjsWrap = true
}
}
}
if len(.ast.ExportStarImportRecords) > 0 {
.addExportsForExportStar(.meta.resolvedExports, , )
}
.meta.nsExportPartIndex = .addPartToFile(, js_ast.Part{
CanBeRemovedIfUnused: true,
IsNamespaceExport: true,
}, partMeta{})
.meta.resolvedExports["*"] = exportData{
ref: .ast.ExportsRef,
sourceIndex: ,
}
.ast.TopLevelSymbolToParts[.ast.ExportsRef] = []uint32{.meta.nsExportPartIndex}
}
for , := range .reachableFiles {
:= &.files[]
, := .repr.(*reprJS)
if ! {
continue
}
if len(.ast.NamedImports) > 0 {
.matchImportsWithExportsForFile(uint32())
}
if (.options.OutputFormat == config.FormatPreserve || .options.OutputFormat == config.FormatCommonJS) &&
!.meta.cjsWrap && .isEntryPoint {
:= js_ast.FollowSymbols(.symbols, .ast.ExportsRef)
:= js_ast.FollowSymbols(.symbols, .ast.ModuleRef)
.symbols.Get().Kind = js_ast.SymbolUnbound
.symbols.Get().Kind = js_ast.SymbolUnbound
}
}
.Add(1)
:= make([]string, 0, len(.meta.resolvedExports))
:
if == "*" {
continue
}
:= .files[.sourceIndex].repr.(*reprJS)
if len(.potentiallyAmbiguousExportStarRefs) > 0 {
:= .ref
if , := .meta.importsToBind[.ref]; {
= .ref
}
for , := range .potentiallyAmbiguousExportStarRefs {
:= .files[.sourceIndex].repr.(*reprJS)
:= .ref
if , := .meta.importsToBind[.ref]; {
= .ref
}
if != {
continue
}
}
}
if .meta.isProbablyTypeScriptType[.ref] {
continue
}
= append(, )
}
sort.Strings()
.meta.sortedAndFilteredExportAliases =
.createExportsForFile(uint32())
.Done()
}(, )
}
.Wait()
for , := range .reachableFiles {
:= &.files[]
, := .repr.(*reprJS)
if ! {
continue
}
if !.meta.cjsWrap && !.meta.cjsStyleExports && (!.isEntryPoint ||
.options.OutputFormat != config.FormatCommonJS) {
:= .source.IdentifierName
.symbols.Get(.ast.ExportsRef).OriginalName = + "_exports"
.symbols.Get(.ast.ModuleRef).OriginalName = + "_module"
}
if .meta.needsExportSymbolFromRuntime || .meta.needsMarkAsModuleSymbolFromRuntime {
:= .files[runtime.SourceIndex].repr.(*reprJS)
:= &.ast.Parts[.meta.nsExportPartIndex]
if .meta.needsExportSymbolFromRuntime {
:= .ast.ModuleScope.Members["__export"].Ref
.generateUseOfSymbolForInclude(, &.meta, 1, , runtime.SourceIndex)
}
if .meta.needsMarkAsModuleSymbolFromRuntime {
:= .ast.ModuleScope.Members["__markAsModule"].Ref
.generateUseOfSymbolForInclude(, &.meta, 1, , runtime.SourceIndex)
}
}
for , := range .meta.importsToBind {
:= .files[.sourceIndex].repr.(*reprJS)
:= .ast.TopLevelSymbolToParts[.ref]
for , := range .ast.NamedImports[].LocalPartsWithUses {
:= &.meta.partMeta[]
for , := range {
.nonLocalDependencies = append(.nonLocalDependencies, partRef{
sourceIndex: .sourceIndex,
partIndex: ,
})
}
}
js_ast.MergeSymbols(.symbols, , .ref)
}
}
}
func ( *linkerContext) ( uint32) {
:= &.files[]
:= .repr.(*reprJS)
if .meta.cjsStyleExports {
.Stmts = []js_ast.Stmt{js_ast.AssignStmt(
js_ast.Expr{Loc: .Value.Loc, Data: &js_ast.EDot{
Target: js_ast.Expr{Loc: .Value.Loc, Data: &js_ast.EIdentifier{Ref: .ast.ModuleRef}},
Name: "exports",
NameLoc: .Value.Loc,
}},
.Value,
)}
.SymbolUses[.ast.ModuleRef] = js_ast.SymbolUse{CountEstimate: 1}
.ast.UsesModuleRef = true
return
}
:= &.symbols.Outer[]
:= js_ast.Ref{OuterIndex: , InnerIndex: uint32(len(*))}
* = append(*, js_ast.Symbol{Kind: js_ast.SymbolOther, OriginalName: , Link: js_ast.InvalidRef})
.ast.ModuleScope.Generated = append(.ast.ModuleScope.Generated, )
var js_ast.Stmt
if == "default" {
= js_ast.Stmt{Loc: .Loc, Data: &js_ast.SExportDefault{
DefaultName: js_ast.LocRef{Loc: .Loc, Ref: },
Value: js_ast.ExprOrStmt{Expr: &},
}}
} else {
= js_ast.Stmt{Loc: .Loc, Data: &js_ast.SLocal{
IsExport: true,
Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Loc: .Loc, Data: &js_ast.BIdentifier{Ref: }},
Value: &,
}},
}}
}
:= .addPartToFile(, js_ast.Part{
Stmts: []js_ast.Stmt{},
SymbolUses: map[js_ast.Ref]js_ast.SymbolUse{.ast.ModuleRef: {CountEstimate: 1}},
DeclaredSymbols: []js_ast.DeclaredSymbol{{Ref: , IsTopLevel: true}},
CanBeRemovedIfUnused: true,
}, partMeta{})
.ast.TopLevelSymbolToParts[] = []uint32{}
.meta.resolvedExports[] = exportData{ref: , sourceIndex: }
:= &.ast.Parts[]
for , := range {
.SymbolUses[.] = js_ast.SymbolUse{CountEstimate: 1}
.LocalDependencies[.] = true
}
return {: , : }
}
var []
:= .Value
if , := .Data.(*js_ast.EObject); {
:= *
.Properties = append(make([]js_ast.Property, 0, len(.Properties)), .Properties...)
for , := range .Properties {
if , := .Key.Data.(*js_ast.EString); && (!.isEntryPoint || js_lexer.IsIdentifierUTF16(.Value)) {
:= js_lexer.UTF16ToString(.Value)
:= (, , *.Value, nil)
= append(, )
.Properties[].Value = &js_ast.Expr{Loc: .Key.Loc, Data: &js_ast.EIdentifier{Ref: .}}
}
}
.Data = &
}
(.source.IdentifierName+"_default", "default", , )
}
:= .isEntryPoint && !.meta.cjsWrap &&
.options.OutputFormat == config.FormatESModule && len(.meta.sortedAndFilteredExportAliases) > 0
if , := .files[.sourceIndex].repr.(*reprJS).meta.importsToBind[.ref]; {
.ref = .ref
.sourceIndex = .sourceIndex
}
:= &.symbols.Outer[]
:= js_ast.Ref{OuterIndex: , InnerIndex: uint32(len(*))}
* = append(*, js_ast.Symbol{
Kind: js_ast.SymbolOther,
OriginalName: "export_" + ,
Link: js_ast.InvalidRef,
})
:= &.ast.ModuleScope.Generated
* = append(*, )
= append(, js_ast.Stmt{Data: &js_ast.SLocal{
Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Data: &js_ast.BIdentifier{Ref: }},
Value: &js_ast.Expr{Data: &js_ast.EImportIdentifier{Ref: .ref}},
}},
}})
= append(, js_ast.ClauseItem{
Name: js_ast.LocRef{Ref: },
Alias: ,
})
[] = js_ast.SymbolUse{CountEstimate: 2}
}
} else {
= js_ast.Expr{Data: &js_ast.EIdentifier{Ref: .ref}}
var js_ast.Expr
:= js_ast.FnBody{Stmts: []js_ast.Stmt{{Loc: .Loc, Data: &js_ast.SReturn{Value: &}}}}
if .options.UnsupportedJSFeatures.Has(compat.Arrow) {
= js_ast.Expr{Data: &js_ast.EFunction{Fn: js_ast.Fn{Body: }}}
} else {
= js_ast.Expr{Data: &js_ast.EArrow{PreferExpr: true, Body: }}
}
= append(, js_ast.Property{
Key: js_ast.Expr{Data: &js_ast.EString{Value: js_lexer.StringToUTF16()}},
Value: &,
})
[.ref] = js_ast.SymbolUse{CountEstimate: 1}
if .isEntryPoint {
[.ref] = js_ast.SymbolUse{CountEstimate: 1}
}
:= partRef{sourceIndex: .sourceIndex, partIndex: }
= append(, )
if .isEntryPoint {
= append(, )
}
}
}
:= []js_ast.DeclaredSymbol{}
var []js_ast.Stmt
if !.meta.cjsStyleExports && (!.isEntryPoint || .options.OutputFormat != config.FormatCommonJS) {
= append(, js_ast.Stmt{Data: &js_ast.SLocal{Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Data: &js_ast.BIdentifier{Ref: .ast.ExportsRef}},
Value: &js_ast.Expr{Data: &js_ast.EObject{}},
}}}})
= append(, js_ast.DeclaredSymbol{
Ref: .ast.ExportsRef,
IsTopLevel: true,
})
}
if .ast.ExportKeyword.Len > 0 && (.meta.cjsStyleExports || (.isEntryPoint && .options.OutputFormat == config.FormatCommonJS)) {
:= .files[runtime.SourceIndex].repr.(*reprJS)
:= .ast.ModuleScope.Members["__markAsModule"].Ref
= append(, js_ast.Stmt{Data: &js_ast.SExpr{Value: js_ast.Expr{Data: &js_ast.ECall{
Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{{Data: &js_ast.EIdentifier{Ref: .ast.ExportsRef}}},
}}}})
for , := range .ast.TopLevelSymbolToParts[] {
:= partRef{sourceIndex: runtime.SourceIndex, partIndex: }
= append(, )
}
:= js_ast.InvalidRef
if len() > 0 {
:= .files[runtime.SourceIndex].repr.(*reprJS)
= .ast.ModuleScope.Members["__export"].Ref
= append(, js_ast.Stmt{Data: &js_ast.SExpr{Value: js_ast.Expr{Data: &js_ast.ECall{
Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{
{Data: &js_ast.EIdentifier{Ref: .ast.ExportsRef}},
{Data: &js_ast.EObject{
Properties: ,
}},
},
}}}})
for , := range .ast.TopLevelSymbolToParts[] {
:= partRef{sourceIndex: runtime.SourceIndex, partIndex: }
= append(, )
}
.ast.UsesExportsRef = true
}
:= &.ast.Parts[.meta.nsExportPartIndex]
* = js_ast.Part{
Stmts: ,
LocalDependencies: make(map[uint32]bool),
SymbolUses: ,
DeclaredSymbols: ,
if != js_ast.InvalidRef {
.meta.needsExportSymbolFromRuntime = true
}
}
if len() > 0 {
= append(,
js_ast.Stmt{Data: &js_ast.SExportClause{Items: }})
}
var js_ast.Stmt
if .isEntryPoint {
if .meta.cjsWrap {
switch .options.OutputFormat {
if .Data != nil {
[.ast.WrapperRef] = js_ast.SymbolUse{CountEstimate: 1}
= append(, )
}
:= .addPartToFile(, js_ast.Part{
Stmts: ,
SymbolUses: ,
}, partMeta{
nonLocalDependencies: append([]partRef{}, ...),
})
.meta.entryPointExportPartIndex = ast.MakeIndex32()
}
}
func ( *linkerContext) ( uint32) {
:= &.files[]
:= .repr.(*reprJS)
:= make([]int, 0, len(.ast.NamedImports))
for := range .ast.NamedImports {
= append(, int(.InnerIndex))
}
sort.Ints()
.cycleDetector = .cycleDetector[:0]
:= js_ast.Ref{OuterIndex: , InnerIndex: uint32()}
:= .matchImportWithExport(importTracker{sourceIndex: , importRef: })
switch .kind {
case matchImportNormal:
.meta.importsToBind[] = importToBind{
sourceIndex: .sourceIndex,
ref: .ref,
}
case matchImportNamespace:
.symbols.Get().NamespaceAlias = &js_ast.NamespaceAlias{
NamespaceRef: .namespaceRef,
Alias: .alias,
}
case matchImportNormalAndNamespace:
.meta.importsToBind[] = importToBind{
sourceIndex: .sourceIndex,
ref: .ref,
}
.symbols.Get().NamespaceAlias = &js_ast.NamespaceAlias{
NamespaceRef: .namespaceRef,
Alias: .alias,
}
case matchImportCycle:
:= .ast.NamedImports[]
.addRangeError(.source, js_lexer.RangeOfIdentifier(.source, .AliasLoc),
fmt.Sprintf("Detected cycle while resolving import %q", .Alias))
case matchImportProbablyTypeScriptType:
.meta.isProbablyTypeScriptType[] = true
case matchImportAmbiguous:
:= .ast.NamedImports[]
:= js_lexer.RangeOfIdentifier(.source, .AliasLoc)
var []logger.MsgData
if .nameLoc.Start != 0 && .otherNameLoc.Start != 0 {
:= .files[.sourceIndex].source
:= .files[.otherSourceIndex].source
= []logger.MsgData{
logger.RangeData(&, js_lexer.RangeOfIdentifier(, .nameLoc), "One matching export is here"),
logger.RangeData(&, js_lexer.RangeOfIdentifier(, .otherNameLoc), "Another matching export is here"),
}
}
:= .symbols.Get()
.ImportItemStatus = js_ast.ImportItemMissing
:= fmt.Sprintf("Import %q will always be undefined because there are multiple matching exports", .Alias)
.log.AddRangeWarningWithNotes(&.source, , , )
} else {
:= fmt.Sprintf("Ambiguous import %q has multiple matching exports", .Alias)
.addRangeErrorWithNotes(.source, , , )
}
}
}
}
type matchImportKind uint8
matchImportAmbiguous
)
type matchImportResult struct {
kind matchImportKind
namespaceRef js_ast.Ref
alias string
sourceIndex uint32
nameLoc logger.Loc // Optional, goes with sourceIndex, ignore if zero
otherSourceIndex uint32
otherNameLoc logger.Loc // Optional, goes with otherSourceIndex, ignore if zero
ref js_ast.Ref
}
func ( *linkerContext) ( importTracker) ( matchImportResult) {
var []matchImportResult
:
for , := range .cycleDetector {
if == {
= matchImportResult{kind: matchImportCycle}
break
}
}
.cycleDetector = append(.cycleDetector, )
, , := .advanceImportTracker()
switch {
case importCommonJS, importCommonJSWithoutExports, importExternal, importDisabled:
break
}
:= &.files[.sourceIndex]
:= .repr.(*reprJS).ast.NamedImports[.importRef]
if .NamespaceRef != js_ast.InvalidRef {
if .kind == matchImportNormal {
.kind = matchImportNormalAndNamespace
.namespaceRef = .NamespaceRef
.alias = .Alias
} else {
= matchImportResult{
kind: matchImportNamespace,
namespaceRef: .NamespaceRef,
alias: .Alias,
}
}
}
if == importCommonJSWithoutExports {
:= .source
:= .symbols.Get(.importRef)
.ImportItemStatus = js_ast.ImportItemMissing
.log.AddRangeWarning(&, js_lexer.RangeOfIdentifier(, .AliasLoc),
fmt.Sprintf("Import %q will always be undefined because the file %q has no exports",
.Alias, .files[.sourceIndex].source.PrettyPath))
}
case importNoMatch:
:= .symbols.Get(.importRef)
:= &.files[.sourceIndex]
:= .source
:= .repr.(*reprJS).ast.NamedImports[.importRef]
:= js_lexer.RangeOfIdentifier(, .AliasLoc)
.ImportItemStatus = js_ast.ImportItemMissing
.log.AddRangeWarning(&, , fmt.Sprintf("Import %q will always be undefined because there is no matching export", .Alias))
} else {
.addRangeError(, , fmt.Sprintf("No matching export for import %q", .Alias))
}
if , := .files[.sourceIndex].repr.(*reprJS).ast.NamedImports[.ref]; {
= append(, .(importTracker{
sourceIndex: .sourceIndex,
importRef: .ref,
}))
} else {
= append(, matchImportResult{
kind: matchImportNormal,
sourceIndex: .sourceIndex,
ref: .ref,
nameLoc: .nameLoc,
})
}
}
= matchImportResult{
kind: matchImportNormal,
sourceIndex: .sourceIndex,
ref: .importRef,
nameLoc: .nameLoc,
}
if , := .files[.sourceIndex].repr.(*reprJS).ast.NamedImports[.importRef]; {
=
continue
}
default:
panic("Internal error")
}
break
}
for , := range {
if != {
if .kind == matchImportNormal && .kind == matchImportNormal &&
.nameLoc.Start != 0 && .nameLoc.Start != 0 {
return matchImportResult{
kind: matchImportAmbiguous,
sourceIndex: .sourceIndex,
nameLoc: .nameLoc,
otherSourceIndex: .sourceIndex,
otherNameLoc: .nameLoc,
}
}
return matchImportResult{kind: matchImportAmbiguous}
}
}
return
}
for , := range .ast.ExportStarImportRecords {
:= &.ast.ImportRecords[]
if (!.SourceIndex.IsValid() && (!.files[].isEntryPoint || !.options.OutputFormat.KeepES6ImportExportSyntax())) ||
(.SourceIndex.IsValid() && .SourceIndex.GetIndex() != && .(.SourceIndex.GetIndex(), )) {
.meta.cjsStyleExports = true
return true
}
}
return false
}
func ( *linkerContext) (
map[string]exportData,
uint32,
[]uint32,
for , := range {
if == {
return
}
}
= append(, )
:= .files[].repr.(*reprJS)
for , := range .ast.ExportStarImportRecords {
:= &.ast.ImportRecords[]
continue
}
:= .SourceIndex.GetIndex()
continue
}
:
if == "default" {
continue
}
for , := range {
:= .files[].repr.(*reprJS)
if , := .ast.NamedExports[]; {
continue
}
}
[] = exportData{
ref: .Ref,
sourceIndex: ,
nameLoc: .AliasLoc,
}
.meta.importsToBind[.Ref] = importToBind{
ref: .Ref,
sourceIndex: ,
}
.potentiallyAmbiguousExportStarRefs =
append(.potentiallyAmbiguousExportStarRefs, importToBind{
sourceIndex: ,
ref: .Ref,
nameLoc: .AliasLoc,
})
[] =
}
}
.(, , )
}
}
type importTracker struct {
sourceIndex uint32
nameLoc logger.Loc // Optional, goes with sourceIndex, ignore if zero
importRef js_ast.Ref
}
type importStatus uint8
importProbablyTypeScriptType
)
func ( *linkerContext) ( importTracker) (importTracker, importStatus, []importToBind) {
:= &.files[.sourceIndex]
:= .repr.(*reprJS)
:= .ast.NamedImports[.importRef]
:= &.ast.ImportRecords[.ImportRecordIndex]
if !.SourceIndex.IsValid() {
return importTracker{}, importExternal, nil
}
:= .SourceIndex.GetIndex()
if .files[].source.KeyPath.IsDisabled() {
return importTracker{sourceIndex: , importRef: js_ast.InvalidRef}, importDisabled, nil
}
return importTracker{sourceIndex: , importRef: js_ast.InvalidRef}, importCommonJSWithoutExports, nil
}
if .meta.cjsStyleExports {
return importTracker{sourceIndex: , importRef: js_ast.InvalidRef}, importCommonJS, nil
}
return importTracker{
sourceIndex: .sourceIndex,
importRef: .ref,
nameLoc: .nameLoc,
}, importFound, .potentiallyAmbiguousExportStarRefs
}
if .loader.IsTypeScript() && .IsExported {
return importTracker{}, importProbablyTypeScriptType, nil
}
return importTracker{}, importNoMatch, nil
}
:= uint(len(.entryPoints))
for , := range .reachableFiles {
:= &.files[]
.entryBits = newBitSet()
switch repr := .repr.(type) {
case *reprJS:
for := range .meta.partMeta {
:= &.meta.partMeta[]
.entryBits = newBitSet()
.prevSibling = uint32()
.nextSibling = uint32()
}
if .meta.cjsWrap {
:= .files[runtime.SourceIndex].repr.(*reprJS)
:= .ast.NamedExports["__commonJS"].Ref
:= .ast.TopLevelSymbolToParts[]
:= make([]partRef, len())
for , := range {
[] = partRef{sourceIndex: runtime.SourceIndex, partIndex: }
}
:= .addPartToFile(, js_ast.Part{
SymbolUses: map[js_ast.Ref]js_ast.SymbolUse{
.ast.WrapperRef: {CountEstimate: 1},
: {CountEstimate: 1},
},
DeclaredSymbols: []js_ast.DeclaredSymbol{
{Ref: .ast.ExportsRef, IsTopLevel: true},
{Ref: .ast.ModuleRef, IsTopLevel: true},
{Ref: .ast.WrapperRef, IsTopLevel: true},
},
}, partMeta{
nonLocalDependencies: ,
})
.meta.cjsWrapperPartIndex = ast.MakeIndex32()
.ast.TopLevelSymbolToParts[.ast.WrapperRef] = []uint32{}
.meta.importsToBind[] = importToBind{
ref: ,
sourceIndex: runtime.SourceIndex,
}
}
}
}
for , := range .entryPoints {
.includeFile(, uint(), 0)
}
}
func ( *linkerContext) () {
return
}
:= newBitSet(uint(len(.entryPoints)))
for , := range .reachableFiles {
:= &.files[]
, := .repr.(*reprJS)
if ! {
continue
}
for , := range .SymbolUses {
if .IsAssigned {
if , := .ast.TopLevelSymbolToParts[]; {
for , := range {
:= &.meta.partMeta[]
:= &.meta.partMeta[]
for := range .entryPoints {
:= .entryBits.hasBit(uint())
:= .entryBits.hasBit(uint())
if && ! {
.includePart(, , uint(), .distanceFromEntryPoint)
} else if && ! {
.includePart(, uint32(), uint(), .distanceFromEntryPoint)
}
}
.meta.partMeta[.nextSibling].prevSibling = .prevSibling
.meta.partMeta[.prevSibling].nextSibling = .nextSibling
.nextSibling =
.prevSibling = uint32()
}
}
}
}
}
}
}
func ( *linkerContext) ( uint32, uint, uint32) {
:= &.files[]
if < .distanceFromEntryPoint {
.distanceFromEntryPoint =
}
++
if .cssSourceIndex.IsValid() {
.(.cssSourceIndex.GetIndex(), , )
}
for , := range .ast.Parts {
:= .CanBeRemovedIfUnused
if uint32() == .meta.entryPointExportPartIndex.GetIndex() &&
!= .entryPoints[] {
continue
}
for , := range .ImportRecordIndices {
:= &.ast.ImportRecords[]
if .Kind != ast.ImportStmt {
continue
}
if .SourceIndex.IsValid() {
:= .SourceIndex.GetIndex()
if := &.files[]; .ignoreIfUnused && !.options.IgnoreDCEAnnotations {
continue
}
.(, , )
}
= false
}
if ! || (!.ForceTreeShaking && ! && .isEntryPoint) {
.includePart(, uint32(), , )
}
}
if .isEntryPoint {
for , := range .meta.sortedAndFilteredExportAliases {
:= .meta.resolvedExports[]
:= .sourceIndex
:= .ref
:= .files[].repr.(*reprJS)
if , := .meta.importsToBind[]; {
= .sourceIndex
= .ref
}
for , := range .ast.TopLevelSymbolToParts[] {
.includePart(, , , )
}
}
if .meta.forceIncludeExportsForEntryPoint {
.includePart(, .meta.nsExportPartIndex, , )
}
}
for , := range .ast.ImportRecords {
if .SourceIndex.IsValid() {
.(.SourceIndex.GetIndex(), , )
}
}
}
}
func ( *linkerContext) (
*js_ast.Part, *fileMeta, uint32,
string, uint, uint32,
) {
if > 0 {
:= .files[runtime.SourceIndex].repr.(*reprJS)
:= .ast.NamedExports[].Ref
.generateUseOfSymbolForInclude(, , , , runtime.SourceIndex)
for , := range .ast.TopLevelSymbolToParts[] {
.includePart(runtime.SourceIndex, , , )
}
}
}
func ( *linkerContext) (
*js_ast.Part, *fileMeta, uint32,
js_ast.Ref, uint32,
) {
:= .SymbolUses[]
.CountEstimate +=
.SymbolUses[] =
.importsToBind[] = importToBind{
sourceIndex: ,
ref: ,
}
}
func ( *linkerContext) ( *ast.ImportRecord) bool {
return .Kind == ast.ImportDynamic && .files[.SourceIndex.GetIndex()].isEntryPoint
}
func ( *linkerContext) ( uint32, uint32, uint, uint32) {
:= &.files[]
:= .repr.(*reprJS)
:= &.meta.partMeta[]
.includeFile(, , )
for := range .LocalDependencies {
.(, , , )
}
for , := range .nonLocalDependencies {
.(.sourceIndex, .partIndex, , )
}
for := .nextSibling; != ; = .meta.partMeta[].nextSibling {
.(, , , )
}
:= uint32(0)
for , := range .ImportRecordIndices {
:= &.ast.ImportRecords[]
if .Kind != ast.ImportRequire && !.options.OutputFormat.KeepES6ImportExportSyntax() {
.WrapWithToModule = true
++
}
continue
}
:= .SourceIndex.GetIndex()
:= .files[].repr.(*reprJS)
continue
}
.includeFile(, , )
:= .ast.WrapperRef
.generateUseOfSymbolForInclude(, &.meta, 1, , )
if .Kind != ast.ImportRequire && !.meta.skipCallingToModule {
.WrapWithToModule = true
++
}
}
.includePartsForRuntimeSymbol(, &.meta, , "__toModule", , )
:= uint32(0)
for , := range .ast.ExportStarImportRecords {
:= &.ast.ImportRecords[]
if (!.SourceIndex.IsValid() && (!.isEntryPoint || !.options.OutputFormat.KeepES6ImportExportSyntax())) ||
(.SourceIndex.IsValid() && .SourceIndex.GetIndex() != && .files[.SourceIndex.GetIndex()].repr.(*reprJS).meta.cjsStyleExports) {
.CallsRunTimeExportStarFn = true
.ast.UsesExportsRef = true
++
}
}
.includePartsForRuntimeSymbol(, &.meta, , "__exportStar", , )
}
func ( string) string {
, , := logger.PlatformIndependentPathDirBaseExt()
default:
break
}
if .Len() == 0 {
return "_"
}
for , := range .entryPoints {
var string
var string
var chunkRepr
:= &.files[]
switch .repr.(type) {
case *reprJS:
= &chunkReprJS{}
case *reprCSS:
= &chunkReprCSS{}
}
if .options.AbsOutputFile != "" {
= .fs.Base(.options.AbsOutputFile)
} else {
:= .source
if .KeyPath.Namespace != "file" {
= baseFileNameForVirtualModulePath(.KeyPath.Text)
} else if , := .fs.Rel(.options.AbsOutputBase, .KeyPath.Text); {
= .fs.Dir()
= .fs.Base()
= strings.ReplaceAll(, "\\", "/")
:= .fs.Ext()
= [:len()-len()]
switch .(type) {
case *chunkReprJS:
+= .options.OutputExtensionJS
case *chunkReprCSS:
+= .options.OutputExtensionCSS
}
}
.entryPointRelPath = path.Join(, )
:= newBitSet(uint(len(.entryPoints)))
.setBit(uint())
[string(.entries)] = chunkInfo{
entryBits: ,
isEntryPoint: true,
sourceIndex: ,
entryPointBit: uint(),
relDir: ,
baseNameOrEmpty: ,
filesWithPartsInChunk: make(map[uint32]bool),
chunkRepr: ,
}
}
continue
}
, := []
if ! {
.entryBits = .entryBits
.filesWithPartsInChunk = make(map[uint32]bool)
.relDir = .generatedChunkRelDir
.chunkRepr = &chunkReprJS{}
[] =
}
.filesWithPartsInChunk[uint32()] = true
}
case *reprCSS:
:= string(.entryBits.entries)
continue
}
, := []
if ! {
.entryBits = .entryBits
.filesWithPartsInChunk = make(map[uint32]bool)
.relDir = .generatedChunkRelDir
.chunkRepr = &chunkReprJS{}
[] =
}
.filesWithPartsInChunk[uint32()] = true
}
}
type chunkOrderArray []chunkOrder
func ( chunkOrderArray) () int { return len() }
func ( chunkOrderArray) ( int, int) { [], [] = [], [] }
func ( chunkOrderArray) ( int, int) bool {
return [].distance < [].distance || ([].distance == [].distance && [].path.ComesBeforeInSortedOrder([].path))
}
func ( []partRange, uint32, uint32) []partRange {
if := len() - 1; >= 0 {
if := &[]; .sourceIndex == && .partIndexEnd == {
.partIndexEnd = + 1
return
}
}
return append(, partRange{
sourceIndex: ,
partIndexBegin: ,
partIndexEnd: + 1,
})
}
if len(.Stmts) == 1 {
if , := .Stmts[0].Data.(*js_ast.SImport); {
:= &.ast.ImportRecords[.ImportRecordIndex]
if .SourceIndex.IsValid() && !.files[.SourceIndex.GetIndex()].repr.(*reprJS).meta.cjsStyleExports {
return false
}
}
}
return true
}
func ( *linkerContext) ( *chunkInfo) ( []uint32, []partRange, []uint32) {
:= make(chunkOrderArray, 0, len(.filesWithPartsInChunk))
for := range .filesWithPartsInChunk {
:= &.files[]
= append(, chunkOrder{
sourceIndex: ,
distance: .distanceFromEntryPoint,
path: .source.KeyPath,
})
}
for , := range .ImportRecordIndices {
:= &.ast.ImportRecords[]
if .SourceIndex.IsValid() && (.Kind == ast.ImportStmt || ) {
continue
}
(.SourceIndex.GetIndex())
}
}
if {
= true
if && uint32() != .meta.nsExportPartIndex && .shouldIncludePart(, ) {
if == runtime.SourceIndex {
= appendOrExtendPartRange(, , uint32())
} else {
= appendOrExtendPartRange(, , uint32())
}
}
}
}
if {
= append(, )
if ! {
= append(, partRange{
sourceIndex: ,
partIndexBegin: 0,
partIndexEnd: uint32(len(.ast.Parts)),
})
}
}
case *reprCSS:
for , := range .ast.ImportRecords {
if .SourceIndex.IsValid() {
(.SourceIndex.GetIndex())
}
}
= append(, )
}
}
}
(runtime.SourceIndex)
for , := range {
(.sourceIndex)
}
= append(, ...)
return
}
func ( *linkerContext) (
uint32,
*stmtList,
[]js_ast.Stmt,
logger.Loc,
js_ast.Ref,
uint32,
:= .files[].repr.(*reprJS)
:= &.ast.ImportRecords[]
if .SourceIndex.IsValid() {
return true
}
return false
}
if .meta.cjsStyleExports && js_ast.FollowSymbols(.symbols, ) == .ast.ExportsRef {
return true
}
.prefixStmts = append(.prefixStmts, js_ast.Stmt{
Loc: ,
Data: &js_ast.SLocal{Decls: []js_ast.Decl{{
Binding: js_ast.Binding{Loc: , Data: &js_ast.BIdentifier{Ref: }},
Value: &js_ast.Expr{Loc: .Range.Loc, Data: &js_ast.ERequire{ImportRecordIndex: }},
}}},
})
return true
}
func ( *linkerContext) ( uint32, *stmtList, []js_ast.Stmt) {
:= &.files[]
:= .options.Mode != config.ModePassThrough || !.isEntryPoint
:= .repr.(*reprJS)
:= .meta.cjsWrap
for , := range {
switch s := .Data.(type) {
if .shouldRemoveImportExportStmt(, , , .Loc, .NamespaceRef, .ImportRecordIndex) {
continue
}
if {
.es6StmtsForCJSWrap = append(.es6StmtsForCJSWrap, )
continue
}
case *js_ast.SExportStar:
if {
:= &.ast.ImportRecords[.ImportRecordIndex]
if !.SourceIndex.IsValid() && .options.OutputFormat.KeepES6ImportExportSyntax() {
.Data = &js_ast.SImport{
NamespaceRef: .NamespaceRef,
StarNameLoc: &.Loc,
ImportRecordIndex: .ImportRecordIndex,
}
:= .files[runtime.SourceIndex].repr.(*reprJS).ast.ModuleScope.Members["__exportStar"].Ref
.prefixStmts = append(.prefixStmts, js_ast.Stmt{
Loc: .Loc,
Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: .Loc, Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{
{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .ast.ExportsRef}},
{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .NamespaceRef}},
},
}}},
})
if {
.es6StmtsForCJSWrap = append(.es6StmtsForCJSWrap, )
continue
}
}
} else {
:= .files[runtime.SourceIndex].repr.(*reprJS).ast.ModuleScope.Members["__exportStar"].Ref
.prefixStmts = append(.prefixStmts, js_ast.Stmt{
Loc: .Loc,
Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: .Loc, Data: &js_ast.ECall{
Target: js_ast.Expr{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{
{Loc: .Loc, Data: &js_ast.EIdentifier{Ref: .ast.ExportsRef}},
{Loc: .Range.Loc, Data: &js_ast.ERequire{ImportRecordIndex: .ImportRecordIndex}},
},
}}},
})
}
continue
}
}
if .shouldRemoveImportExportStmt(, , , .Loc, .NamespaceRef, .ImportRecordIndex) {
continue
}
.Data = &js_ast.SImport{
NamespaceRef: .NamespaceRef,
StarNameLoc: &.Alias.Loc,
ImportRecordIndex: .ImportRecordIndex,
}
}
if {
.es6StmtsForCJSWrap = append(.es6StmtsForCJSWrap, )
continue
}
}
if .shouldRemoveImportExportStmt(, , , .Loc, .NamespaceRef, .ImportRecordIndex) {
continue
}
for , := range .Items {
.Items[].Alias = .OriginalName
}
.Data = &js_ast.SImport{
NamespaceRef: .NamespaceRef,
Items: &.Items,
ImportRecordIndex: .ImportRecordIndex,
IsSingleLine: .IsSingleLine,
}
}
if {
.es6StmtsForCJSWrap = append(.es6StmtsForCJSWrap, )
continue
}
case *js_ast.SExportClause:
continue
}
if {
.es6StmtsForCJSWrap = append(.es6StmtsForCJSWrap, )
continue
}
if {
= false
[] =
++
}
return [:]
}
entryPointTail []js_ast.Stmt
}
type lineColumnOffset struct {
lines int
columns int
}
type compileResultJS struct {
js_printer.PrintResult
generatedOffset lineColumnOffset
}
func ( *linkerContext) (
renamer.Renamer,
*sync.WaitGroup,
partRange,
bitSet,
string,
js_ast.Ref,
js_ast.Ref,
*compileResultJS,
[]dataForSourceMap,
) {
:= &.files[.sourceIndex]
:= .repr.(*reprJS)
:= .meta.nsExportPartIndex
:= false
:= stmtList{}
if >= .partIndexBegin && < .partIndexEnd &&
.equals(.meta.partMeta[].entryBits) {
.convertStmtsForChunk(.sourceIndex, &, .ast.Parts[].Stmts)
.prefixStmts = append(.prefixStmts, .normalStmts...)
.normalStmts = nil
}
for := .partIndexBegin; < .partIndexEnd; ++ {
:= .ast.Parts[]
continue
}
continue
}
if uint32() == .meta.cjsWrapperPartIndex.GetIndex() {
= true
continue
}
if uint32() == .meta.entryPointExportPartIndex.GetIndex() {
.entryPointTail = append(.entryPointTail, .Stmts...)
continue
}
.convertStmtsForChunk(.sourceIndex, &, .Stmts)
}
:= .normalStmts
if len(.prefixStmts) > 0 {
= append(.prefixStmts, ...)
}
if .options.MangleSyntax {
= mergeAdjacentLocalStmts()
}
var js_ast.Expr
if .options.UnsupportedJSFeatures.Has(compat.Arrow) {
= js_ast.Expr{Data: &js_ast.ECall{
Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{{Data: &js_ast.EFunction{Fn: js_ast.Fn{Args: , Body: js_ast.FnBody{Stmts: }}}}},
}}
} else {
= js_ast.Expr{Data: &js_ast.ECall{
Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: }},
Args: []js_ast.Expr{{Data: &js_ast.EArrow{Args: , Body: js_ast.FnBody{Stmts: }}}},
}}
}
var bool
var *sourcemap.SourceMap
var []js_printer.LineOffsetTable
if .loader.CanHaveSourceMap() && .options.SourceMap != config.SourceMapNone {
= true
= .sourceMap
= [.sourceIndex].lineOffsetTables
}
:= 0
if .options.OutputFormat == config.FormatIIFE {
++
}
:= js_printer.Options{
Indent: ,
OutputFormat: .options.OutputFormat,
RemoveWhitespace: .options.RemoveWhitespace,
MangleSyntax: .options.MangleSyntax,
ASCIIOnly: .options.ASCIIOnly,
ToModuleRef: ,
ExtractComments: .options.Mode == config.ModeBundle && .options.RemoveWhitespace,
UnsupportedFeatures: .options.UnsupportedJSFeatures,
AddSourceMappings: ,
InputSourceMap: ,
LineOffsetTables: ,
WrapperRefForSource: func( uint32) js_ast.Ref {
return .files[].repr.(*reprJS).ast.WrapperRef
},
}
:= .ast
.Directive = "" // This is handled elsewhere
.Parts = []js_ast.Part{{Stmts: }}
* = compileResultJS{
PrintResult: js_printer.Print(, .symbols, , ),
sourceIndex: .sourceIndex,
}
if len(.entryPointTail) > 0 {
:= .ast
.Parts = []js_ast.Part{{Stmts: .entryPointTail}}
:= js_printer.Print(, .symbols, , )
.entryPointTail = &
}
.Done()
}
if .options.Mode != config.ModePassThrough {
["require"] = 1
["Promise"] = 1
}
var js_ast.SlotCounts
for , := range {
.UnionMax(.files[].repr.(*reprJS).ast.NestedScopeSlotCounts)
}
:= renamer.NewMinifyRenamer(.symbols, , )
:= js_ast.CharFreq{}
for , := range {
:= .files[].repr.(*reprJS)
if .ast.CharFreq != nil {
.Include(.ast.CharFreq)
}
if .ast.UsesExportsRef {
.AccumulateSymbolCount(.ast.ExportsRef, 1)
}
if .ast.UsesModuleRef {
.AccumulateSymbolCount(.ast.ModuleRef, 1)
}
for , := range .ast.Parts {
continue
}
for , := range .DeclaredSymbols {
.AccumulateSymbolCount(.Ref, 1)
}
}
}
:= .Compile()
.AssignNamesByFrequency(&)
return
}
var renamer.StableRefArray
for , := range .chunkRepr.(*chunkReprJS).importsFromOtherChunks {
for , := range {
= append(, renamer.StableRef{
StableOuterIndex: .stableSourceIndices[.ref.OuterIndex],
Ref: .ref,
})
}
}
sort.Sort()
for , := range {
.AddTopLevelSymbol(.Ref)
}
for , := range {
:= .files[].repr.(*reprJS)
var []*js_ast.Scope
if .meta.cjsWrap {
.AddTopLevelSymbol(.ast.WrapperRef)
if .options.OutputFormat.KeepES6ImportExportSyntax() {
for , := range .ast.Parts {
for , := range .Stmts {
switch s := .Data.(type) {
case *js_ast.SImport:
if !.ast.ImportRecords[.ImportRecordIndex].SourceIndex.IsValid() {
.AddTopLevelSymbol(.NamespaceRef)
if .DefaultName != nil {
.AddTopLevelSymbol(.DefaultName.Ref)
}
if .Items != nil {
for , := range *.Items {
.AddTopLevelSymbol(.Name.Ref)
}
}
}
case *js_ast.SExportStar:
if !.ast.ImportRecords[.ImportRecordIndex].SourceIndex.IsValid() {
.AddTopLevelSymbol(.NamespaceRef)
}
case *js_ast.SExportFrom:
if !.ast.ImportRecords[.ImportRecordIndex].SourceIndex.IsValid() {
.AddTopLevelSymbol(.NamespaceRef)
for , := range .Items {
.AddTopLevelSymbol(.Name.Ref)
}
}
}
}
}
}
[] = []*js_ast.Scope{.ast.ModuleScope}
continue
}
for , := range .ast.Parts {
if .entryBits.equals(.meta.partMeta[].entryBits) {
for , := range .DeclaredSymbols {
if .IsTopLevel {
.AddTopLevelSymbol(.Ref)
}
}
= append(, .Scopes...)
}
}
[] =
}
.AssignNamesByScope()
return
}
func ( *chunkReprJS) ( *linkerContext, *chunkInfo) func(generateContinue) []OutputFile {
var []OutputFile
:= make([]compileResultJS, 0, len(.partsInChunkInOrder))
:= .files[runtime.SourceIndex].repr.(*reprJS).ast.ModuleScope.Members
:= js_ast.FollowSymbols(.symbols, ["__commonJS"].Ref)
:= js_ast.FollowSymbols(.symbols, ["__toModule"].Ref)
:= .renameSymbolsInChunk(, .filesInChunkInOrder)
:= .fs.Join(.options.AbsOutputDir, .relDir)
:= .dataForSourceMaps()
if .sourceIndex == runtime.SourceIndex && .options.OmitRuntimeForTests {
continue
}
= append(, compileResultJS{})
:= &[len()-1]
.Add(1)
go .generateCodeForFileInChunkJS(
,
&,
,
.entryBits,
,
,
,
,
,
)
}
for , := range .filesInChunkInOrder {
= append(, .files[].additionalFiles...)
}
:= 0
if .options.OutputFormat == config.FormatIIFE {
++
}
:= js_printer.Options{
Indent: ,
OutputFormat: .options.OutputFormat,
RemoveWhitespace: .options.RemoveWhitespace,
MangleSyntax: .options.MangleSyntax,
}
= js_printer.Print(js_ast.AST{
ImportRecords: .crossChunkImportRecords,
Parts: []js_ast.Part{{Stmts: .crossChunkPrefixStmts}},
}, .symbols, , ).JS
= js_printer.Print(js_ast.AST{
Parts: []js_ast.Part{{Stmts: .crossChunkSuffixStmts}},
}, .symbols, , ).JS
}
.Wait()
:= js_printer.Joiner{}
:= lineColumnOffset{}
:= ""
:= " "
:= "\n"
if .options.RemoveWhitespace {
= ""
= ""
}
:= false
:= false
if .isEntryPoint {
:= .files[.sourceIndex].repr.(*reprJS)
if .ast.Directive != "" {
:= string(js_printer.QuoteForJSON(.ast.Directive, .options.ASCIIOnly)) + ";" +
.advanceString()
.AddString()
= true
}
}
if len(.options.Banner) > 0 {
.advanceString(.options.Banner)
.advanceString("\n")
.AddString(.options.Banner)
.AddString("\n")
}
if .options.OutputFormat == config.FormatIIFE {
var string
= " "
if len(.options.GlobalName) > 0 {
= .generateGlobalNamePrefix()
}
if .options.UnsupportedJSFeatures.Has(compat.Arrow) {
+= "(function()" + + "{" +
} else {
+= "(()" + + "=>" + + "{" +
}
.advanceString()
.AddString()
= false
}
if len() > 0 {
= true
.advanceBytes()
.AddBytes()
}
:= js_printer.Joiner{}
:= true
.AddString("{\n \"imports\": [")
for , := range .crossChunkAbsPaths {
if {
= false
} else {
.AddString(",")
}
.AddString(fmt.Sprintf("\n {\n \"path\": %s,\n \"kind\": %s\n }",
js_printer.QuoteForJSON(.res.PrettyPath(logger.Path{Text: , Namespace: "file"}), .options.ASCIIOnly),
js_printer.QuoteForJSON(.crossChunkImportRecords[].Kind.StringForMetafile(), .options.ASCIIOnly)))
}
if ! {
.AddString("\n ")
}
.AddString("],\n \"exports\": [")
var []string
if .options.OutputFormat.KeepES6ImportExportSyntax() {
if .isEntryPoint {
if := .files[.sourceIndex].repr.(*reprJS); .meta.cjsWrap {
= []string{"default"}
} else {
:= .meta.resolvedExports
= make([]string, 0, len())
for := range {
if != "*" {
= append(, )
}
}
}
} else {
= make([]string, 0, len(.exportsToOtherChunks))
for , := range .exportsToOtherChunks {
= append(, )
}
}
}
= true
sort.Strings() // Sort for determinism
for , := range {
if {
= false
} else {
.AddString(",")
}
.AddString(fmt.Sprintf("\n %s",
js_printer.QuoteForJSON(, .options.ASCIIOnly)))
}
if ! {
.AddString("\n ")
}
if .isEntryPoint {
:= .files[.sourceIndex].source.PrettyPath
.AddString(fmt.Sprintf("],\n \"entryPoint\": %s,\n \"inputs\": {", js_printer.QuoteForJSON(, .options.ASCIIOnly)))
} else {
.AddString("],\n \"inputs\": {")
}
}
var []compileResultJS
var *js_printer.PrintResult
var []string
var []string
var map[string]int
:= make(map[string]bool)
:= uint32(0)
if .options.AbsMetadataFile != "" {
= make([]string, 0, len())
= make(map[string]int, len())
}
for , := range {
:= .sourceIndex == runtime.SourceIndex
for := range .ExtractedComments {
if ![] {
[] = true
= append(, )
}
}
if .entryPointTail != nil {
= .entryPointTail
}
if .options.Mode == config.ModeBundle && !.options.RemoveWhitespace && != .sourceIndex && len(.JS) > 0 {
if {
.advanceString("\n")
.AddString("\n")
}
:= .files[.sourceIndex].source.PrettyPath
= strings.ReplaceAll(, "\r", "\\r")
= strings.ReplaceAll(, "\n", "\\n")
= strings.ReplaceAll(, "\u2028", "\\u2028")
= strings.ReplaceAll(, "\u2029", "\\u2029")
:= fmt.Sprintf("%s// %s\n", , )
.advanceString()
.AddString()
= .sourceIndex
}
if {
.advanceString(string(.JS))
.AddBytes(.JS)
.generatedOffset =
.AddBytes(.JS)
if .SourceMapChunk.ShouldIgnore {
.advanceBytes(.JS)
} else {
= lineColumnOffset{}
if .options.SourceMap != config.SourceMapNone {
= append(, )
}
}
:= .files[.sourceIndex].source.PrettyPath
if , := []; {
[] = + len(.JS)
} else {
= append(, )
[] = len(.JS)
}
}
}
if .options.OutputFormat == config.FormatIIFE {
.AddString("})();" + )
}
sort.Strings()
for , := range {
.AddString()
.AddString("\n")
}
if len(.options.Footer) > 0 {
.AddString(.options.Footer)
.AddString("\n")
}
if .options.SourceMap != config.SourceMapNone {
:= .generateSourceMapForChunk(, , )
var bool
var bool
switch .options.SourceMap {
case config.SourceMapInline:
= true
case config.SourceMapLinkedWithComment, config.SourceMapExternalWithoutComment:
= true
case config.SourceMapInlineAndExternal:
= true
= true
}
if {
.AddString("//# sourceMappingURL=data:application/json;base64,")
.AddString(base64.StdEncoding.EncodeToString())
.AddString("\n")
}
:= .baseNameOrEmpty
:= .relDir
if == "" {
var string
:= "chunk"
if config.HasPlaceholder(.options.ChunkPathTemplate, config.HashPlaceholder) {
= .chunkHashForFileName(, )
}
:= config.TemplateToString(config.SubstituteTemplate(.options.ChunkPathTemplate, config.PathPlaceholders{
Name: &,
Hash: &,
})) + .options.OutputExtensionJS
= path.Base()
= [:len()-len()]
}
+= ".map"
if .options.SourceMap == config.SourceMapLinkedWithComment {
.AddString("//# sourceMappingURL=")
.AddString()
.AddString("\n")
}
= append(, OutputFile{
AbsPath: .fs.Join(.options.AbsOutputDir, , ),
Contents: ,
jsonMetadataChunk: ,
})
}
}
:= .Done()
if .baseNameOrEmpty == "" {
var string
:= "chunk"
if config.HasPlaceholder(.options.ChunkPathTemplate, config.HashPlaceholder) {
= .chunkHashForFileName(, )
}
:= config.TemplateToString(config.SubstituteTemplate(.options.ChunkPathTemplate, config.PathPlaceholders{
Name: &,
Hash: &,
})) + .options.OutputExtensionJS
.baseNameOrEmpty = path.Base()
.relDir = [:len()-len(.baseNameOrEmpty)]
}
var []byte
if .options.AbsMetadataFile != "" {
:= true
for , := range {
if {
= false
} else {
.AddString(",")
}
.AddString(fmt.Sprintf("\n %s: {\n \"bytesInOutput\": %d\n }",
js_printer.QuoteForJSON(, .options.ASCIIOnly), []))
}
if ! {
.AddString("\n ")
}
.AddString(fmt.Sprintf("},\n \"bytes\": %d\n }", len()))
= .Done()
}
= append(, OutputFile{
AbsPath: .fs.Join(.options.AbsOutputDir, .relPath()),
Contents: ,
jsonMetadataChunk: ,
IsExecutable: ,
})
return
}
}
func ( *linkerContext) () string {
var string
:= .options.GlobalName[0]
:= " "
:= ";\n"
if .options.RemoveWhitespace {
= ""
= ";"
}
if js_printer.CanQuoteIdentifier(, .options.UnsupportedJSFeatures, .options.ASCIIOnly) {
if .options.ASCIIOnly {
= string(js_printer.QuoteIdentifier(nil, , .options.UnsupportedJSFeatures))
}
= fmt.Sprintf("var %s%s=%s", , , )
} else {
= fmt.Sprintf("this[%s]", js_printer.QuoteForJSON(, .options.ASCIIOnly))
= fmt.Sprintf("%s%s=%s", , , )
}
for , := range .options.GlobalName[1:] {
:=
if js_printer.CanQuoteIdentifier(, .options.UnsupportedJSFeatures, .options.ASCIIOnly) {
if .options.ASCIIOnly {
= string(js_printer.QuoteIdentifier(nil, , .options.UnsupportedJSFeatures))
}
= fmt.Sprintf("%s.%s", , )
} else {
= fmt.Sprintf("%s[%s]", , js_printer.QuoteForJSON(, .options.ASCIIOnly))
}
+= fmt.Sprintf("%s%s||%s{}%s%s%s=%s", , , , , , , )
}
return
}
type compileResultCSS struct {
printedCSS string
sourceIndex uint32
hasCharset bool
externalImportRecords []ast.ImportRecord
}
func ( *chunkReprCSS) ( *linkerContext, *chunkInfo) func(generateContinue) []OutputFile {
var []OutputFile
:= make([]compileResultCSS, 0, len(.filesInChunkInOrder))
= append(, .files[].additionalFiles...)
= append(, compileResultCSS{})
:= &[len()-1]
.Add(1)
go func( uint32, *compileResultCSS) {
:= &.files[]
:= .repr.(*reprCSS).ast
:= make([]css_ast.R, 0, len(.Rules))
for , := range .Rules {
switch r := .(type) {
case *css_ast.RAtCharset:
.hasCharset = true
continue
case *css_ast.RAtImport:
if := .ImportRecords[.ImportRecordIndex]; !.SourceIndex.IsValid() {
.externalImportRecords = append(.externalImportRecords, )
}
continue
}
= append(, )
}
.Rules =
.printedCSS = css_printer.Print(, css_printer.Options{
MangleSyntax: .options.MangleSyntax,
RemoveWhitespace: .options.RemoveWhitespace,
ASCIIOnly: .options.ASCIIOnly,
})
.sourceIndex =
.Done()
}(, )
}
return func( generateContinue) []OutputFile {
.Wait()
:= js_printer.Joiner{}
:= false
for , := range {
if .hasCharset {
.Rules = append(.Rules, &css_ast.RAtCharset{Encoding: "UTF-8"})
break
}
}
for , := range {
for , := range .externalImportRecords {
.Rules = append(.Rules, &css_ast.RAtImport{ImportRecordIndex: uint32(len(.ImportRecords))})
.ImportRecords = append(.ImportRecords, )
}
}
if len(.Rules) > 0 {
:= css_printer.Print(, css_printer.Options{
RemoveWhitespace: .options.RemoveWhitespace,
})
if len() > 0 {
.AddString()
= true
}
}
}
:= js_printer.Joiner{}
if .options.AbsMetadataFile != "" {
:= true
.AddString("{\n \"imports\": [")
for , := range .crossChunkAbsPaths {
if {
= false
} else {
.AddString(",")
}
.AddString(fmt.Sprintf("\n {\n \"path\": %s,\n \"kind\": %s\n }",
js_printer.QuoteForJSON(.res.PrettyPath(logger.Path{Text: , Namespace: "file"}), .options.ASCIIOnly),
js_printer.QuoteForJSON(.crossChunkImportRecords[].Kind.StringForMetafile(), .options.ASCIIOnly)))
}
if ! {
.AddString("\n ")
}
if .isEntryPoint {
:= &.files[.sourceIndex]
if , := .repr.(*reprCSS); {
.AddString(fmt.Sprintf("],\n \"entryPoint\": %s,\n \"inputs\": {",
js_printer.QuoteForJSON(.source.PrettyPath, .options.ASCIIOnly)))
} else {
.AddString("],\n \"inputs\": {")
}
} else {
.AddString("],\n \"inputs\": {")
}
}
:= true
for , := range {
if .options.Mode == config.ModeBundle && !.options.RemoveWhitespace {
if {
.AddString("\n")
}
.AddString(fmt.Sprintf("/* %s */\n", .files[.sourceIndex].source.PrettyPath))
}
if len(.printedCSS) > 0 {
= true
}
.AddString(.printedCSS)
if .options.AbsMetadataFile != "" {
if {
= false
} else {
.AddString(",")
}
.AddString(fmt.Sprintf("\n %s: {\n \"bytesInOutput\": %d\n }",
js_printer.QuoteForJSON(.files[.sourceIndex].source.PrettyPath, .options.ASCIIOnly),
len(.printedCSS)))
}
}
:= .Done()
if .baseNameOrEmpty == "" {
var string
:= "chunk"
if config.HasPlaceholder(.options.ChunkPathTemplate, config.HashPlaceholder) {
= .chunkHashForFileName(, )
}
:= config.TemplateToString(config.SubstituteTemplate(.options.ChunkPathTemplate, config.PathPlaceholders{
Name: &,
Hash: &,
})) + .options.OutputExtensionCSS
.baseNameOrEmpty = path.Base()
.relDir = [:len()-len(.baseNameOrEmpty)]
}
var []byte
if .options.AbsMetadataFile != "" {
if ! {
.AddString("\n ")
}
.AddString(fmt.Sprintf("},\n \"bytes\": %d\n }", len()))
= .Done()
}
= append(, OutputFile{
AbsPath: .fs.Join(.options.AbsOutputDir, .relPath()),
Contents: ,
jsonMetadataChunk: ,
})
return
}
}
func ( *lineColumnOffset) ( []byte) {
for , := 0, len(); < ; ++ {
if [] == '\n' {
.lines++
.columns = 0
} else {
.columns++
}
}
}
func ( *lineColumnOffset) ( string) {
for , := 0, len(); < ; ++ {
if [] == '\n' {
.lines++
.columns = 0
} else {
.columns++
}
}
}
func ( js_ast.Binding, js_ast.SymbolMap) {
switch b := .Data.(type) {
case *js_ast.BMissing:
case *js_ast.BIdentifier:
.Get(.Ref).MustNotBeRenamed = true
case *js_ast.BArray:
for , := range .Items {
(.Binding, )
}
case *js_ast.BObject:
for , := range .Properties {
(.Value, )
}
default:
panic(fmt.Sprintf("Unexpected binding of type %T", .Data))
}
}
:= &.ast.ImportRecords[.ImportRecordIndex]
if .SourceIndex.IsValid() && .SourceIndex.GetIndex() == runtime.SourceIndex {
continue
}
= true
case *js_ast.SLocal:
if .IsExport {
for , := range .Decls {
preventBindingsFromBeingRenamed(.Binding, .symbols)
}
= true
}
case *js_ast.SFunction:
if .IsExport {
.symbols.Get(.Fn.Name.Ref).Kind = js_ast.SymbolUnbound
= true
}
case *js_ast.SClass:
if .IsExport {
.symbols.Get(.Class.Name.Ref).Kind = js_ast.SymbolUnbound
= true
}
case *js_ast.SExportClause, *js_ast.SExportDefault, *js_ast.SExportStar:
= true
case *js_ast.SExportFrom:
= true
}
}
}
if ! {
for , := range .ast.ModuleScope.Members {
.symbols.Get(.Ref).MustNotBeRenamed = true
}
}
}
func ( *linkerContext) (
[]compileResultJS,
string,
[]dataForSourceMap,
) []byte {
:= js_printer.Joiner{}
.AddString("{\n \"version\": 3")
type struct {
logger.Path
string
[]byte
}
:= make([], 0, len())
:= 0
for , := range {
if , := [.sourceIndex]; {
continue
}
[.sourceIndex] =
:= &.files[.sourceIndex]
if .sourceMap == nil {
var []byte
if !.options.ExcludeSourcesContent {
= [.sourceIndex].quotedContents[0]
}
= append(, {
: .source.KeyPath,
: .source.PrettyPath,
: ,
})
++
continue
}
if ..Namespace == "file" {
. = strings.ReplaceAll(, "\\", "/")
}
}
.AddBytes(js_printer.QuoteForJSON(., .options.ASCIIOnly))
}
.AddString("]")
.AddString(",\n \"mappings\": \"")
:= js_printer.SourceMapState{}
:= 0
for , := range {
:= .SourceMapChunk
:= .generatedOffset
:= [.sourceIndex]
if .ShouldIgnore {
panic("Internal error")
}
:= js_printer.SourceMapState{
SourceIndex: ,
GeneratedLine: .lines,
GeneratedColumn: .columns,
}
if .lines == 0 {
.GeneratedColumn +=
}
js_printer.AppendSourceMapChunk(&, , , .Buffer)
= .EndState
.SourceIndex +=
= .FinalGeneratedColumn
if .GeneratedLine == 0 {
.GeneratedColumn += .GeneratedColumn
+= .GeneratedColumn
}
}
.AddString("\"")
var [4]byte
for , := range .partsInChunkInOrder {
var string
:= &.files[.sourceIndex]
= .source.PrettyPath
binary.LittleEndian.PutUint32([:], .partIndexBegin)
.Write([:])
binary.LittleEndian.PutUint32([:], .partIndexEnd)
.Write([:])
}
![]() |
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. |