mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-04-29 01:45:58 +08:00
create a linker graph object
This commit is contained in:
@@ -23,12 +23,12 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
file := &c.files[sourceIndex]
|
||||
file := &c.graph.Files[sourceIndex]
|
||||
repr := file.InputFile.Repr.(*graph.JSRepr)
|
||||
sb := strings.Builder{}
|
||||
|
||||
quoteSym := func(ref js_ast.Ref) string {
|
||||
name := fmt.Sprintf("%d:%d [%s]", ref.SourceIndex, ref.InnerIndex, c.symbols.Get(ref).OriginalName)
|
||||
name := fmt.Sprintf("%d:%d [%s]", ref.SourceIndex, ref.InnerIndex, c.graph.Symbols.Get(ref).OriginalName)
|
||||
return string(js_printer.QuoteForJSON(name, c.options.ASCIIOnly))
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string {
|
||||
} else {
|
||||
sb.WriteByte(',')
|
||||
}
|
||||
path := c.files[record.SourceIndex.GetIndex()].InputFile.Source.PrettyPath
|
||||
path := c.graph.Files[record.SourceIndex.GetIndex()].InputFile.Source.PrettyPath
|
||||
sb.WriteString(fmt.Sprintf(`{"source":%s}`, js_printer.QuoteForJSON(path, c.options.ASCIIOnly)))
|
||||
}
|
||||
sb.WriteByte(']')
|
||||
@@ -115,7 +115,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string {
|
||||
sb.WriteByte(',')
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(`{"source":%s,"partIndex":%d}`,
|
||||
js_printer.QuoteForJSON(c.files[dep.SourceIndex].InputFile.Source.PrettyPath, c.options.ASCIIOnly),
|
||||
js_printer.QuoteForJSON(c.graph.Files[dep.SourceIndex].InputFile.Source.PrettyPath, c.options.ASCIIOnly),
|
||||
dep.PartIndex,
|
||||
))
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
package graph
|
||||
|
||||
import "github.com/evanw/esbuild/internal/helpers"
|
||||
import (
|
||||
"github.com/evanw/esbuild/internal/helpers"
|
||||
"github.com/evanw/esbuild/internal/js_ast"
|
||||
)
|
||||
|
||||
type EntryPointKind uint8
|
||||
|
||||
@@ -39,3 +42,22 @@ type LinkerFile struct {
|
||||
func (f *LinkerFile) IsEntryPoint() bool {
|
||||
return f.EntryPointKind != EntryPointNone
|
||||
}
|
||||
|
||||
type LinkerGraph struct {
|
||||
Files []LinkerFile
|
||||
Symbols js_ast.SymbolMap
|
||||
|
||||
// We should avoid traversing all files in the bundle, because the linker
|
||||
// should be able to run a linking operation on a large bundle where only
|
||||
// a few files are needed (e.g. an incremental compilation scenario). This
|
||||
// holds all files that could possibly be reached through the entry points.
|
||||
// If you need to iterate over all files in the linking operation, iterate
|
||||
// over this array. This array is also sorted in a deterministic ordering
|
||||
// to help ensure deterministic builds (source indices are random).
|
||||
ReachableFiles []uint32
|
||||
|
||||
// This maps from unstable source index to stable reachable file index. This
|
||||
// is useful as a deterministic key for sorting if you need to sort something
|
||||
// containing a source index (such as "js_ast.Ref" symbol references).
|
||||
StableSourceIndices []uint32
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user