Skip to content

Commit

Permalink
move dependency construction from parser to linker
Browse files Browse the repository at this point in the history
This means it's no longer included in the cached AST, so incremental builds will be very slightly longer while full builds should not be affected. But this means it's now easier to defer the decision of whether something is a dependency or not to link time.
  • Loading branch information
evanw committed Dec 28, 2021
1 parent e873959 commit 989f03e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
25 changes: 25 additions & 0 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,31 @@ func (c *linkerContext) scanImportsAndExports() {
// come second after we fill in that array
c.createExportsForFile(uint32(sourceIndex))

// Each part tracks the other parts it depends on within this file
localDependencies := make(map[uint32]uint32)
parts := repr.AST.Parts
namedImports := repr.AST.NamedImports
for partIndex := range parts {
part := &parts[partIndex]
for ref := range part.SymbolUses {
for _, otherPartIndex := range repr.TopLevelSymbolToParts(ref) {
if oldPartIndex, ok := localDependencies[otherPartIndex]; !ok || oldPartIndex != uint32(partIndex) {
localDependencies[otherPartIndex] = uint32(partIndex)
part.Dependencies = append(part.Dependencies, js_ast.Dependency{
SourceIndex: sourceIndex,
PartIndex: otherPartIndex,
})
}
}

// Also map from imports to parts that use them
if namedImport, ok := namedImports[ref]; ok {
namedImport.LocalPartsWithUses = append(namedImport.LocalPartsWithUses, uint32(partIndex))
namedImports[ref] = namedImport
}
}
}

waitGroup.Done()
}(sourceIndex, repr)
}
Expand Down
1 change: 0 additions & 1 deletion internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func CloneLinkerGraph(
clone[ref] = uses
}
part.SymbolUses = clone
part.Dependencies = append([]js_ast.Dependency{}, part.Dependencies...)
}

// Clone the import records
Expand Down
23 changes: 0 additions & 23 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15291,29 +15291,6 @@ func (p *parser) toAST(parts []js_ast.Part, hashbang string, directive string) j

// Pulling in the exports of this module always pulls in the export part
p.topLevelSymbolToParts[p.exportsRef] = append(p.topLevelSymbolToParts[p.exportsRef], js_ast.NSExportPartIndex)

// Each part tracks the other parts it depends on within this file
localDependencies := make(map[uint32]uint32)
for partIndex := range parts {
part := &parts[partIndex]
for ref := range part.SymbolUses {
for _, otherPartIndex := range p.topLevelSymbolToParts[ref] {
if oldPartIndex, ok := localDependencies[otherPartIndex]; !ok || oldPartIndex != uint32(partIndex) {
localDependencies[otherPartIndex] = uint32(partIndex)
part.Dependencies = append(part.Dependencies, js_ast.Dependency{
SourceIndex: p.source.Index,
PartIndex: otherPartIndex,
})
}
}

// Also map from imports to parts that use them
if namedImport, ok := p.namedImports[ref]; ok {
namedImport.LocalPartsWithUses = append(namedImport.LocalPartsWithUses, uint32(partIndex))
p.namedImports[ref] = namedImport
}
}
}
}

// Make a wrapper symbol in case we need to be wrapped in a closure
Expand Down

0 comments on commit 989f03e

Please sign in to comment.