@@ -1211,19 +1211,13 @@ func (c *linkerContext) scanImportsAndExports() {
12111211 c .addExportsForExportStar (repr .Meta .ResolvedExports , sourceIndex , exportStarStack )
12121212 }
12131213
1214- // Add an empty part for the namespace export that we can fill in later
1215- repr .Meta .NSExportPartIndex = c .graph .AddPartToFile (sourceIndex , js_ast.Part {
1216- CanBeRemovedIfUnused : true ,
1217- })
1218-
12191214 // Also add a special export so import stars can bind to it. This must be
12201215 // done in this step because it must come after CommonJS module discovery
12211216 // but before matching imports with exports.
12221217 repr .Meta .ResolvedExportStar = & graph.ExportData {
12231218 Ref : repr .AST .ExportsRef ,
12241219 SourceIndex : sourceIndex ,
12251220 }
1226- repr .AST .TopLevelSymbolToParts [repr .AST .ExportsRef ] = []uint32 {repr .Meta .NSExportPartIndex }
12271221 }
12281222 c .timer .End ("Step 3" )
12291223
@@ -1365,17 +1359,17 @@ func (c *linkerContext) scanImportsAndExports() {
13651359 runtimeRepr := c .graph .Files [runtime .SourceIndex ].InputFile .Repr .(* graph.JSRepr )
13661360 if repr .Meta .NeedsExportSymbolFromRuntime {
13671361 exportRef := runtimeRepr .AST .ModuleScope .Members ["__export" ].Ref
1368- c .graph .GenerateSymbolImportAndUse (sourceIndex , repr . Meta .NSExportPartIndex , exportRef , 1 , runtime .SourceIndex )
1362+ c .graph .GenerateSymbolImportAndUse (sourceIndex , js_ast .NSExportPartIndex , exportRef , 1 , runtime .SourceIndex )
13691363 }
13701364 if repr .Meta .NeedsMarkAsModuleSymbolFromRuntime {
13711365 markAsModuleRef := runtimeRepr .AST .ModuleScope .Members ["__markAsModule" ].Ref
1372- c .graph .GenerateSymbolImportAndUse (sourceIndex , repr . Meta .NSExportPartIndex , markAsModuleRef , 1 , runtime .SourceIndex )
1366+ c .graph .GenerateSymbolImportAndUse (sourceIndex , js_ast .NSExportPartIndex , markAsModuleRef , 1 , runtime .SourceIndex )
13731367 }
13741368 }
13751369
13761370 for importRef , importData := range repr .Meta .ImportsToBind {
13771371 resolvedRepr := c .graph .Files [importData .SourceIndex ].InputFile .Repr .(* graph.JSRepr )
1378- partsDeclaringSymbol := resolvedRepr .AST . TopLevelSymbolToParts [ importData .Ref ]
1372+ partsDeclaringSymbol := resolvedRepr .TopLevelSymbolToParts ( importData .Ref )
13791373
13801374 for _ , partIndex := range repr .AST .NamedImports [importRef ].LocalPartsWithUses {
13811375 part := & repr .AST .Parts [partIndex ]
@@ -1416,7 +1410,7 @@ func (c *linkerContext) scanImportsAndExports() {
14161410 }
14171411
14181412 // Pull in all declarations of this symbol
1419- for _ , partIndex := range targetRepr .AST . TopLevelSymbolToParts [ targetRef ] {
1413+ for _ , partIndex := range targetRepr .TopLevelSymbolToParts ( targetRef ) {
14201414 dependencies = append (dependencies , js_ast.Dependency {
14211415 SourceIndex : targetSourceIndex ,
14221416 PartIndex : partIndex ,
@@ -1428,7 +1422,7 @@ func (c *linkerContext) scanImportsAndExports() {
14281422 if repr .Meta .ForceIncludeExportsForEntryPoint {
14291423 dependencies = append (dependencies , js_ast.Dependency {
14301424 SourceIndex : sourceIndex ,
1431- PartIndex : repr . Meta .NSExportPartIndex ,
1425+ PartIndex : js_ast .NSExportPartIndex ,
14321426 })
14331427 }
14341428
@@ -1564,7 +1558,7 @@ func (c *linkerContext) generateCodeForLazyExport(sourceIndex uint32) {
15641558 if len (repr .AST .Parts ) < 1 {
15651559 panic ("Internal error" )
15661560 }
1567- part := & repr .AST .Parts [0 ]
1561+ part := & repr .AST .Parts [1 ]
15681562 if len (part .Stmts ) != 1 {
15691563 panic ("Internal error" )
15701564 }
@@ -1706,7 +1700,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) {
17061700 nsExportSymbolUses [export .Ref ] = js_ast.SymbolUse {CountEstimate : 1 }
17071701
17081702 // Make sure the part that declares the export is included
1709- for _ , partIndex := range c .graph .Files [export .SourceIndex ].InputFile .Repr .(* graph.JSRepr ).AST . TopLevelSymbolToParts [ export .Ref ] {
1703+ for _ , partIndex := range c .graph .Files [export .SourceIndex ].InputFile .Repr .(* graph.JSRepr ).TopLevelSymbolToParts ( export .Ref ) {
17101704 // Use a non-local dependency since this is likely from a different
17111705 // file if it came in through an export star
17121706 nsExportDependencies = append (nsExportDependencies , js_ast.Dependency {
@@ -1744,7 +1738,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) {
17441738 }}}})
17451739
17461740 // Make sure this file depends on the "__markAsModule" symbol
1747- for _ , partIndex := range runtimeRepr .AST . TopLevelSymbolToParts [ markAsModuleRef ] {
1741+ for _ , partIndex := range runtimeRepr .TopLevelSymbolToParts ( markAsModuleRef ) {
17481742 nsExportDependencies = append (nsExportDependencies , js_ast.Dependency {
17491743 SourceIndex : runtime .SourceIndex ,
17501744 PartIndex : partIndex ,
@@ -1773,7 +1767,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) {
17731767 }}}})
17741768
17751769 // Make sure this file depends on the "__export" symbol
1776- for _ , partIndex := range runtimeRepr .AST . TopLevelSymbolToParts [ exportRef ] {
1770+ for _ , partIndex := range runtimeRepr .TopLevelSymbolToParts ( exportRef ) {
17771771 nsExportDependencies = append (nsExportDependencies , js_ast.Dependency {
17781772 SourceIndex : runtime .SourceIndex ,
17791773 PartIndex : partIndex ,
@@ -1788,7 +1782,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) {
17881782 if len (nsExportStmts ) > 0 {
17891783 // Initialize the part that was allocated for us earlier. The information
17901784 // here will be used after this during tree shaking.
1791- repr .AST .Parts [repr . Meta .NSExportPartIndex ] = js_ast.Part {
1785+ repr .AST .Parts [js_ast .NSExportPartIndex ] = js_ast.Part {
17921786 Stmts : nsExportStmts ,
17931787 SymbolUses : nsExportSymbolUses ,
17941788 Dependencies : nsExportDependencies ,
@@ -1829,7 +1823,7 @@ func (c *linkerContext) createWrapperForFile(sourceIndex uint32) {
18291823 case graph .WrapCJS :
18301824 runtimeRepr := c .graph .Files [runtime .SourceIndex ].InputFile .Repr .(* graph.JSRepr )
18311825 commonJSRef := runtimeRepr .AST .NamedExports ["__commonJS" ].Ref
1832- commonJSParts := runtimeRepr .AST . TopLevelSymbolToParts [ commonJSRef ]
1826+ commonJSParts := runtimeRepr .TopLevelSymbolToParts ( commonJSRef )
18331827
18341828 // Generate the dummy part
18351829 dependencies := make ([]js_ast.Dependency , len (commonJSParts ))
@@ -1866,7 +1860,7 @@ func (c *linkerContext) createWrapperForFile(sourceIndex uint32) {
18661860 case graph .WrapESM :
18671861 runtimeRepr := c .graph .Files [runtime .SourceIndex ].InputFile .Repr .(* graph.JSRepr )
18681862 esmRef := runtimeRepr .AST .NamedExports ["__esm" ].Ref
1869- esmParts := runtimeRepr .AST . TopLevelSymbolToParts [ esmRef ]
1863+ esmParts := runtimeRepr .TopLevelSymbolToParts ( esmRef )
18701864
18711865 // Generate the dummy part
18721866 dependencies := make ([]js_ast.Dependency , len (esmParts ))
@@ -2168,7 +2162,7 @@ loop:
21682162
21692163 // Depend on the statement(s) that declared this import symbol in the
21702164 // original file
2171- for _ , resolvedPartIndex := range c .graph .Files [tracker .sourceIndex ].InputFile .Repr .(* graph.JSRepr ).AST . TopLevelSymbolToParts [ tracker .importRef ] {
2165+ for _ , resolvedPartIndex := range c .graph .Files [tracker .sourceIndex ].InputFile .Repr .(* graph.JSRepr ).TopLevelSymbolToParts ( tracker .importRef ) {
21722166 reExports = append (reExports , js_ast.Dependency {
21732167 SourceIndex : tracker .sourceIndex ,
21742168 PartIndex : resolvedPartIndex ,
@@ -2933,8 +2927,8 @@ func (c *linkerContext) chunkFileOrder(chunk *chunkInfo) (js []uint32, jsParts [
29332927
29342928 // Make sure the generated call to "__export(exports, ...)" comes first
29352929 // before anything else in this file
2936- if canFileBeSplit && isFileInThisChunk && repr .AST .Parts [repr . Meta .NSExportPartIndex ].IsLive {
2937- jsParts = appendOrExtendPartRange (jsParts , sourceIndex , repr . Meta .NSExportPartIndex )
2930+ if canFileBeSplit && isFileInThisChunk && repr .AST .Parts [js_ast .NSExportPartIndex ].IsLive {
2931+ jsParts = appendOrExtendPartRange (jsParts , sourceIndex , js_ast .NSExportPartIndex )
29382932 }
29392933
29402934 for partIndex , part := range repr .AST .Parts {
@@ -2955,7 +2949,7 @@ func (c *linkerContext) chunkFileOrder(chunk *chunkInfo) (js []uint32, jsParts [
29552949 // Then include this part after the files it imports
29562950 if isPartInThisChunk {
29572951 isFileInThisChunk = true
2958- if canFileBeSplit && uint32 (partIndex ) != repr . Meta .NSExportPartIndex && c .shouldIncludePart (repr , part ) {
2952+ if canFileBeSplit && uint32 (partIndex ) != js_ast .NSExportPartIndex && c .shouldIncludePart (repr , part ) {
29592953 if sourceIndex == runtime .SourceIndex {
29602954 jsPartsPrefix = appendOrExtendPartRange (jsPartsPrefix , sourceIndex , uint32 (partIndex ))
29612955 } else {
@@ -3388,7 +3382,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
33883382) {
33893383 file := & c .graph .Files [partRange .sourceIndex ]
33903384 repr := file .InputFile .Repr .(* graph.JSRepr )
3391- nsExportPartIndex := repr . Meta .NSExportPartIndex
3385+ nsExportPartIndex := js_ast .NSExportPartIndex
33923386 needsWrapper := false
33933387 stmtList := stmtList {}
33943388
0 commit comments