mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 17:13:19 +08:00
remove the mostly-unnecessary "part meta"
This commit is contained in:
@@ -34,14 +34,13 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string {
|
||||
|
||||
sb.WriteString(`,"parts":[`)
|
||||
for partIndex, part := range repr.AST.Parts {
|
||||
partMeta := &repr.Meta.PartMeta[partIndex]
|
||||
if partIndex > 0 {
|
||||
sb.WriteByte(',')
|
||||
}
|
||||
var isFirst bool
|
||||
code := ""
|
||||
|
||||
sb.WriteString(fmt.Sprintf(`{"isLive":%v`, partMeta.IsLive))
|
||||
sb.WriteString(fmt.Sprintf(`{"isLive":%v`, part.IsLive))
|
||||
sb.WriteString(fmt.Sprintf(`,"canBeRemovedIfUnused":%v`, part.CanBeRemovedIfUnused))
|
||||
|
||||
if partIndex == int(repr.Meta.NSExportPartIndex) {
|
||||
|
||||
@@ -245,7 +245,6 @@ func (c *linkerContext) addPartToFile(sourceIndex uint32, part js_ast.Part) uint
|
||||
repr := c.graph.Files[sourceIndex].InputFile.Repr.(*graph.JSRepr)
|
||||
partIndex := uint32(len(repr.AST.Parts))
|
||||
repr.AST.Parts = append(repr.AST.Parts, part)
|
||||
repr.Meta.PartMeta = append(repr.Meta.PartMeta, graph.PartMeta{})
|
||||
return partIndex
|
||||
}
|
||||
|
||||
@@ -668,7 +667,7 @@ func (c *linkerContext) computeCrossChunkDependencies(chunks []chunkInfo) {
|
||||
// Go over each part in this file that's marked for inclusion in this chunk
|
||||
switch repr := c.graph.Files[sourceIndex].InputFile.Repr.(type) {
|
||||
case *graph.JSRepr:
|
||||
for partIndex, partMeta := range repr.Meta.PartMeta {
|
||||
for partIndex, partMeta := range repr.AST.Parts {
|
||||
if !partMeta.IsLive {
|
||||
continue
|
||||
}
|
||||
@@ -2472,15 +2471,13 @@ func (c *linkerContext) isExternalDynamicImport(record *ast.ImportRecord, source
|
||||
func (c *linkerContext) markPartAsLive(sourceIndex uint32, partIndex uint32) {
|
||||
file := &c.graph.Files[sourceIndex]
|
||||
repr := file.InputFile.Repr.(*graph.JSRepr)
|
||||
partMeta := &repr.Meta.PartMeta[partIndex]
|
||||
part := &repr.AST.Parts[partIndex]
|
||||
|
||||
// Don't mark this part more than once
|
||||
if partMeta.IsLive {
|
||||
if part.IsLive {
|
||||
return
|
||||
}
|
||||
partMeta.IsLive = true
|
||||
|
||||
part := &repr.AST.Parts[partIndex]
|
||||
part.IsLive = true
|
||||
|
||||
// Include the file containing this part
|
||||
c.markFileAsLive(sourceIndex)
|
||||
@@ -2903,12 +2900,12 @@ func (c *linkerContext) chunkFileOrder(chunk *chunkInfo) (js []uint32, jsParts [
|
||||
|
||||
// Make sure the generated call to "__export(exports, ...)" comes first
|
||||
// before anything else in this file
|
||||
if canFileBeSplit && isFileInThisChunk && repr.Meta.PartMeta[repr.Meta.NSExportPartIndex].IsLive {
|
||||
if canFileBeSplit && isFileInThisChunk && repr.AST.Parts[repr.Meta.NSExportPartIndex].IsLive {
|
||||
jsParts = appendOrExtendPartRange(jsParts, sourceIndex, repr.Meta.NSExportPartIndex)
|
||||
}
|
||||
|
||||
for partIndex, part := range repr.AST.Parts {
|
||||
isPartInThisChunk := isFileInThisChunk && repr.Meta.PartMeta[partIndex].IsLive
|
||||
isPartInThisChunk := isFileInThisChunk && repr.AST.Parts[partIndex].IsLive
|
||||
|
||||
// Also traverse any files imported by this part
|
||||
for _, importRecordIndex := range part.ImportRecordIndices {
|
||||
@@ -3359,7 +3356,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
|
||||
// Make sure the generated call to "__export(exports, ...)" comes first
|
||||
// before anything else.
|
||||
if nsExportPartIndex >= partRange.partIndexBegin && nsExportPartIndex < partRange.partIndexEnd &&
|
||||
repr.Meta.PartMeta[nsExportPartIndex].IsLive {
|
||||
repr.AST.Parts[nsExportPartIndex].IsLive {
|
||||
c.convertStmtsForChunk(partRange.sourceIndex, &stmtList, repr.AST.Parts[nsExportPartIndex].Stmts)
|
||||
|
||||
// Move everything to the prefix list
|
||||
@@ -3374,7 +3371,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
|
||||
// Add all other parts in this chunk
|
||||
for partIndex := partRange.partIndexBegin; partIndex < partRange.partIndexEnd; partIndex++ {
|
||||
part := repr.AST.Parts[partIndex]
|
||||
if !repr.Meta.PartMeta[partIndex].IsLive {
|
||||
if !repr.AST.Parts[partIndex].IsLive {
|
||||
// Skip the part if it's not in this chunk
|
||||
continue
|
||||
}
|
||||
@@ -3891,7 +3888,7 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui
|
||||
}
|
||||
|
||||
for partIndex, part := range repr.AST.Parts {
|
||||
if !repr.Meta.PartMeta[partIndex].IsLive {
|
||||
if !repr.AST.Parts[partIndex].IsLive {
|
||||
// Skip the part if it's not in this chunk
|
||||
continue
|
||||
}
|
||||
@@ -4019,7 +4016,7 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui
|
||||
|
||||
// Rename each top-level symbol declaration in this chunk
|
||||
for partIndex, part := range repr.AST.Parts {
|
||||
if repr.Meta.PartMeta[partIndex].IsLive {
|
||||
if repr.AST.Parts[partIndex].IsLive {
|
||||
for _, declared := range part.DeclaredSymbols {
|
||||
if declared.IsTopLevel {
|
||||
r.AddTopLevelSymbol(declared.Ref)
|
||||
|
||||
@@ -138,7 +138,6 @@ func MakeLinkerGraph(
|
||||
}
|
||||
|
||||
// Also associate some default metadata with the file
|
||||
repr.Meta.PartMeta = make([]PartMeta, len(repr.AST.Parts))
|
||||
repr.Meta.ResolvedExports = resolvedExports
|
||||
repr.Meta.IsProbablyTypeScriptType = make(map[js_ast.Ref]bool)
|
||||
repr.Meta.ImportsToBind = make(map[js_ast.Ref]ImportData)
|
||||
|
||||
@@ -46,8 +46,6 @@ const (
|
||||
// linking operations may be happening in parallel with different metadata for
|
||||
// the same file.
|
||||
type JSReprMeta struct {
|
||||
PartMeta []PartMeta
|
||||
|
||||
// This is only for TypeScript files. If an import symbol is in this map, it
|
||||
// means the import couldn't be found and doesn't actually exist. This is not
|
||||
// an error in TypeScript because the import is probably just a type.
|
||||
@@ -181,14 +179,3 @@ type ExportData struct {
|
||||
NameLoc logger.Loc // Optional, goes with sourceIndex, ignore if zero
|
||||
SourceIndex uint32
|
||||
}
|
||||
|
||||
// This contains linker-specific metadata corresponding to a "js_ast.Part" struct
|
||||
// from the initial scan phase of the bundler. It's separated out because it's
|
||||
// conceptually only used for a single linking operation and because multiple
|
||||
// linking operations may be happening in parallel with different metadata for
|
||||
// the same part in the same file.
|
||||
type PartMeta struct {
|
||||
// This is true if this file has been marked as live by the tree shaking
|
||||
// algorithm.
|
||||
IsLive bool
|
||||
}
|
||||
|
||||
@@ -1875,6 +1875,10 @@ type Part struct {
|
||||
// aren't needed. This enables tree shaking for these parts even if global
|
||||
// tree shaking isn't enabled.
|
||||
ForceTreeShaking bool
|
||||
|
||||
// This is true if this file has been marked as live by the tree shaking
|
||||
// algorithm.
|
||||
IsLive bool
|
||||
}
|
||||
|
||||
type Dependency struct {
|
||||
|
||||
Reference in New Issue
Block a user