diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index f986ea9b..ddd44cd9 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -33,7 +33,7 @@ import ( ) type scannerFile struct { - module graph.Module + inputFile graph.InputFile pluginData interface{} // If "AbsMetadataFile" is present, this will be filled out with information @@ -153,7 +153,7 @@ func parseFile(args parseArgs) { result := parseResult{ file: scannerFile{ - module: graph.Module{ + inputFile: graph.InputFile{ Source: source, Loader: loader, SideEffects: args.sideEffects, @@ -165,26 +165,26 @@ func parseFile(args parseArgs) { switch loader { case config.LoaderJS: ast, ok := args.caches.JSCache.Parse(args.log, source, js_parser.OptionsFromConfig(&args.options)) - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = ok case config.LoaderJSX: args.options.JSX.Parse = true ast, ok := args.caches.JSCache.Parse(args.log, source, js_parser.OptionsFromConfig(&args.options)) - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = ok case config.LoaderTS: args.options.TS.Parse = true ast, ok := args.caches.JSCache.Parse(args.log, source, js_parser.OptionsFromConfig(&args.options)) - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = ok case config.LoaderTSX: args.options.TS.Parse = true args.options.JSX.Parse = true ast, ok := args.caches.JSCache.Parse(args.log, source, js_parser.OptionsFromConfig(&args.options)) - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = ok case config.LoaderCSS: @@ -193,18 +193,18 @@ func parseFile(args parseArgs) { RemoveWhitespace: args.options.RemoveWhitespace, UnsupportedCSSFeatures: args.options.UnsupportedCSSFeatures, }) - result.file.module.Repr = &graph.CSSRepr{AST: ast} + result.file.inputFile.Repr = &graph.CSSRepr{AST: ast} result.ok = true case config.LoaderJSON: expr, ok := args.caches.JSONCache.Parse(args.log, source, js_parser.JSONOptions{}) ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "") if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = ok case config.LoaderText: @@ -213,11 +213,11 @@ func parseFile(args parseArgs) { ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "") ast.URLForCSS = "data:text/plain;base64," + encoded if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = true case config.LoaderBase64: @@ -227,11 +227,11 @@ func parseFile(args parseArgs) { ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "") ast.URLForCSS = "data:" + mimeType + ";base64," + encoded if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = true case config.LoaderBinary: @@ -240,11 +240,11 @@ func parseFile(args parseArgs) { ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "__toBinary") ast.URLForCSS = "data:application/octet-stream;base64," + encoded if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = true case config.LoaderDataURL: @@ -255,11 +255,11 @@ func parseFile(args parseArgs) { ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "") ast.URLForCSS = url if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = true case config.LoaderFile: @@ -286,11 +286,11 @@ func parseFile(args parseArgs) { ast := js_parser.LazyExportAST(args.log, source, js_parser.OptionsFromConfig(&args.options), expr, "") ast.URLForCSS = publicPath if pluginName != "" { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData_FromPlugin } else { - result.file.module.SideEffects.Kind = graph.NoSideEffects_PureData + result.file.inputFile.SideEffects.Kind = graph.NoSideEffects_PureData } - result.file.module.Repr = &graph.JSRepr{AST: ast} + result.file.inputFile.Repr = &graph.JSRepr{AST: ast} result.ok = true // Optionally add metadata about the file @@ -309,7 +309,7 @@ func parseFile(args parseArgs) { // Copy the file using an additional file payload to make sure we only copy // the file if the module isn't removed due to tree shaking. - result.file.module.AdditionalFiles = []graph.OutputFile{{ + result.file.inputFile.AdditionalFiles = []graph.OutputFile{{ AbsPath: args.fs.Join(args.options.AbsOutputDir, relPath), Contents: []byte(source.Contents), JSONMetadataChunk: jsonMetadataChunk, @@ -328,7 +328,7 @@ func parseFile(args parseArgs) { // This must come before we send on the "results" channel to avoid deadlock if args.inject != nil { var exports []string - if repr, ok := result.file.module.Repr.(*graph.JSRepr); ok { + if repr, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok { exports = make([]string, 0, len(repr.AST.NamedExports)) for alias := range repr.AST.NamedExports { exports = append(exports, alias) @@ -352,7 +352,7 @@ func parseFile(args parseArgs) { // That way the main thread isn't blocked if the resolver takes a while. if args.options.Mode == config.ModeBundle && !args.skipResolve { // Clone the import records because they will be mutated later - recordsPtr := result.file.module.Repr.ImportRecords() + recordsPtr := result.file.inputFile.Repr.ImportRecords() records := append([]ast.ImportRecord{}, *recordsPtr...) *recordsPtr = records result.resolveResults = make([]*resolver.ResolveResult, len(records)) @@ -447,10 +447,10 @@ func parseFile(args parseArgs) { // Attempt to parse the source map if present if loader.CanHaveSourceMap() && args.options.SourceMap != config.SourceMapNone { - if repr, ok := result.file.module.Repr.(*graph.JSRepr); ok && repr.AST.SourceMapComment.Text != "" { + if repr, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok && repr.AST.SourceMapComment.Text != "" { if path, contents := extractSourceMapFromComment(args.log, args.fs, &args.caches.FSCache, args.res, &source, repr.AST.SourceMapComment, absResolveDir); contents != nil { - result.file.module.InputSourceMap = js_parser.ParseSourceMap(args.log, logger.Source{ + result.file.inputFile.InputSourceMap = js_parser.ParseSourceMap(args.log, logger.Source{ KeyPath: path, PrettyPath: args.res.PrettyPath(path), Contents: *contents, @@ -955,7 +955,7 @@ func ScanBundle( source, ast, ok := globalRuntimeCache.parseRuntime(&options) s.resultChannel <- parseResult{ file: scannerFile{ - module: graph.Module{ + inputFile: graph.InputFile{ Source: source, Repr: &graph.JSRepr{AST: ast}, }, @@ -1150,7 +1150,7 @@ func (s *scanner) preprocessInjectedFiles() { result := parseResult{ ok: true, file: scannerFile{ - module: graph.Module{ + inputFile: graph.InputFile{ Source: source, Repr: &graph.JSRepr{AST: ast}, Loader: config.LoaderJSON, @@ -1471,7 +1471,7 @@ func (s *scanner) scanAllDependencies() { // Don't try to resolve paths if we're not bundling if s.options.Mode == config.ModeBundle { - records := *result.file.module.Repr.ImportRecords() + records := *result.file.inputFile.Repr.ImportRecords() for importRecordIndex := range records { record := &records[importRecordIndex] @@ -1485,7 +1485,7 @@ func (s *scanner) scanAllDependencies() { if !resolveResult.IsExternal { // Handle a path within the bundle sourceIndex := s.maybeParseFile(*resolveResult, s.res.PrettyPath(path), - &result.file.module.Source, record.Range, resolveResult.PluginData, inputKindNormal, nil) + &result.file.inputFile.Source, record.Range, resolveResult.PluginData, inputKindNormal, nil) record.SourceIndex = ast.MakeIndex32(sourceIndex) } else { // If the path to the external module is relative to the source @@ -1508,7 +1508,7 @@ func (s *scanner) scanAllDependencies() { } } - s.results[result.file.module.Source.Index] = result + s.results[result.file.inputFile.Source.Index] = result } } @@ -1524,13 +1524,13 @@ func (s *scanner) processScannedFiles() []scannerFile { // Begin the metadata chunk if s.options.NeedsMetafile { - sb.Write(js_printer.QuoteForJSON(result.file.module.Source.PrettyPath, s.options.ASCIIOnly)) - sb.WriteString(fmt.Sprintf(": {\n \"bytes\": %d,\n \"imports\": [", len(result.file.module.Source.Contents))) + sb.Write(js_printer.QuoteForJSON(result.file.inputFile.Source.PrettyPath, s.options.ASCIIOnly)) + sb.WriteString(fmt.Sprintf(": {\n \"bytes\": %d,\n \"imports\": [", len(result.file.inputFile.Source.Contents))) } // Don't try to resolve paths if we're not bundling if s.options.Mode == config.ModeBundle { - records := *result.file.module.Repr.ImportRecords() + records := *result.file.inputFile.Repr.ImportRecords() for importRecordIndex := range records { record := &records[importRecordIndex] @@ -1568,7 +1568,7 @@ func (s *scanner) processScannedFiles() []scannerFile { sb.WriteString(",\n ") } sb.WriteString(fmt.Sprintf("{\n \"path\": %s,\n \"kind\": %s\n }", - js_printer.QuoteForJSON(s.results[record.SourceIndex.GetIndex()].file.module.Source.PrettyPath, s.options.ASCIIOnly), + js_printer.QuoteForJSON(s.results[record.SourceIndex.GetIndex()].file.inputFile.Source.PrettyPath, s.options.ASCIIOnly), js_printer.QuoteForJSON(record.Kind.StringForMetafile(), s.options.ASCIIOnly))) } @@ -1576,26 +1576,26 @@ func (s *scanner) processScannedFiles() []scannerFile { case ast.ImportAt, ast.ImportAtConditional: // Using a JavaScript file with CSS "@import" is not allowed otherFile := &s.results[record.SourceIndex.GetIndex()].file - if _, ok := otherFile.module.Repr.(*graph.JSRepr); ok { - s.log.AddRangeError(&result.file.module.Source, record.Range, - fmt.Sprintf("Cannot import %q into a CSS file", otherFile.module.Source.PrettyPath)) + if _, ok := otherFile.inputFile.Repr.(*graph.JSRepr); ok { + s.log.AddRangeError(&result.file.inputFile.Source, record.Range, + fmt.Sprintf("Cannot import %q into a CSS file", otherFile.inputFile.Source.PrettyPath)) } else if record.Kind == ast.ImportAtConditional { - s.log.AddRangeError(&result.file.module.Source, record.Range, + s.log.AddRangeError(&result.file.inputFile.Source, record.Range, "Bundling with conditional \"@import\" rules is not currently supported") } case ast.ImportURL: // Using a JavaScript or CSS file with CSS "url()" is not allowed otherFile := &s.results[record.SourceIndex.GetIndex()].file - switch otherRepr := otherFile.module.Repr.(type) { + switch otherRepr := otherFile.inputFile.Repr.(type) { case *graph.CSSRepr: - s.log.AddRangeError(&result.file.module.Source, record.Range, - fmt.Sprintf("Cannot use %q as a URL", otherFile.module.Source.PrettyPath)) + s.log.AddRangeError(&result.file.inputFile.Source, record.Range, + fmt.Sprintf("Cannot use %q as a URL", otherFile.inputFile.Source.PrettyPath)) case *graph.JSRepr: if otherRepr.AST.URLForCSS == "" { - s.log.AddRangeError(&result.file.module.Source, record.Range, - fmt.Sprintf("Cannot use %q as a URL", otherFile.module.Source.PrettyPath)) + s.log.AddRangeError(&result.file.inputFile.Source, record.Range, + fmt.Sprintf("Cannot use %q as a URL", otherFile.inputFile.Source.PrettyPath)) } } } @@ -1603,25 +1603,25 @@ func (s *scanner) processScannedFiles() []scannerFile { // If an import from a JavaScript file targets a CSS file, generate a // JavaScript stub to ensure that JavaScript files only ever import // other JavaScript files. - if _, ok := result.file.module.Repr.(*graph.JSRepr); ok { + if _, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok { otherFile := &s.results[record.SourceIndex.GetIndex()].file - if css, ok := otherFile.module.Repr.(*graph.CSSRepr); ok { + if css, ok := otherFile.inputFile.Repr.(*graph.CSSRepr); ok { if s.options.WriteToStdout { - s.log.AddRangeError(&result.file.module.Source, record.Range, - fmt.Sprintf("Cannot import %q into a JavaScript file without an output path configured", otherFile.module.Source.PrettyPath)) + s.log.AddRangeError(&result.file.inputFile.Source, record.Range, + fmt.Sprintf("Cannot import %q into a JavaScript file without an output path configured", otherFile.inputFile.Source.PrettyPath)) } else if !css.JSSourceIndex.IsValid() { - stubKey := otherFile.module.Source.KeyPath + stubKey := otherFile.inputFile.Source.KeyPath if stubKey.Namespace == "file" { stubKey.Text = lowerCaseAbsPathForWindows(stubKey.Text) } sourceIndex := s.allocateSourceIndex(stubKey, cache.SourceIndexJSStubForCSS) source := logger.Source{ Index: sourceIndex, - PrettyPath: otherFile.module.Source.PrettyPath, + PrettyPath: otherFile.inputFile.Source.PrettyPath, } s.results[sourceIndex] = parseResult{ file: scannerFile{ - module: graph.Module{ + inputFile: graph.InputFile{ Source: source, Repr: &graph.JSRepr{ AST: js_parser.LazyExportAST(s.log, source, @@ -1650,8 +1650,8 @@ func (s *scanner) processScannedFiles() []scannerFile { // about it. Note that this can result in esbuild silently generating // broken code. If this actually happens for people, it's probably worth // re-enabling the warning about code inside "node_modules". - if record.WasOriginallyBareImport && !s.options.IgnoreDCEAnnotations && !resolver.IsInsideNodeModules(result.file.module.Source.KeyPath.Text) { - if otherModule := &s.results[record.SourceIndex.GetIndex()].file.module; otherModule.SideEffects.Kind != graph.HasSideEffects && + if record.WasOriginallyBareImport && !s.options.IgnoreDCEAnnotations && !resolver.IsInsideNodeModules(result.file.inputFile.Source.KeyPath.Text) { + if otherModule := &s.results[record.SourceIndex.GetIndex()].file.inputFile; otherModule.SideEffects.Kind != graph.HasSideEffects && // Do not warn if this is from a plugin, since removing the import // would cause the plugin to not run, and running a plugin is a side // effect. @@ -1666,7 +1666,7 @@ func (s *scanner) processScannedFiles() []scannerFile { } notes = append(notes, logger.RangeData(data.Source, data.Range, text)) } - s.log.AddRangeWarningWithNotes(&result.file.module.Source, record.Range, + s.log.AddRangeWarningWithNotes(&result.file.inputFile.Source, record.Range, fmt.Sprintf("Ignoring this import because %q was marked as having no side effects", otherModule.Source.PrettyPath), notes) } @@ -1702,7 +1702,7 @@ func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { result := &s.results[sourceIndex] if result.ok && result.tlaCheck.depth == 0 { - if repr, ok := result.file.module.Repr.(*graph.JSRepr); ok { + if repr, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok { result.tlaCheck.depth = 1 if repr.AST.TopLevelAwaitKeyword.Len > 0 { result.tlaCheck.parent = ast.MakeIndex32(sourceIndex) @@ -1732,11 +1732,11 @@ func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { // Build up a chain of relevant notes for all of the imports for { parentResult := &s.results[otherSourceIndex] - parentRepr := parentResult.file.module.Repr.(*graph.JSRepr) + parentRepr := parentResult.file.inputFile.Repr.(*graph.JSRepr) if parentRepr.AST.TopLevelAwaitKeyword.Len > 0 { - tlaPrettyPath = parentResult.file.module.Source.PrettyPath - notes = append(notes, logger.RangeData(&parentResult.file.module.Source, parentRepr.AST.TopLevelAwaitKeyword, + tlaPrettyPath = parentResult.file.inputFile.Source.PrettyPath + notes = append(notes, logger.RangeData(&parentResult.file.inputFile.Source, parentRepr.AST.TopLevelAwaitKeyword, fmt.Sprintf("The top-level await in %q is here", tlaPrettyPath))) break } @@ -1748,14 +1748,14 @@ func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { otherSourceIndex = parentResult.tlaCheck.parent.GetIndex() - notes = append(notes, logger.RangeData(&parentResult.file.module.Source, + notes = append(notes, logger.RangeData(&parentResult.file.inputFile.Source, parentRepr.AST.ImportRecords[parent.importRecordIndex].Range, fmt.Sprintf("The file %q imports the file %q here", - parentResult.file.module.Source.PrettyPath, s.results[otherSourceIndex].file.module.Source.PrettyPath))) + parentResult.file.inputFile.Source.PrettyPath, s.results[otherSourceIndex].file.inputFile.Source.PrettyPath))) } var text string - importedPrettyPath := s.results[record.SourceIndex.GetIndex()].file.module.Source.PrettyPath + importedPrettyPath := s.results[record.SourceIndex.GetIndex()].file.inputFile.Source.PrettyPath if importedPrettyPath == tlaPrettyPath { text = fmt.Sprintf("This require call is not allowed because the imported file %q contains a top-level await", @@ -1765,7 +1765,7 @@ func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { tlaPrettyPath) } - s.log.AddRangeErrorWithNotes(&result.file.module.Source, record.Range, text, notes) + s.log.AddRangeErrorWithNotes(&result.file.inputFile.Source, record.Range, text, notes) } } } @@ -1843,7 +1843,7 @@ func (b *Bundle) Compile(log logger.Log, options config.Options) ([]graph.Output files := make([]graph.LinkerFile, len(b.files)) for i, file := range b.files { - files[i].Module = file.module + files[i].InputFile = file.inputFile } // Get the base path from the options or choose the lowest common ancestor of all entry points @@ -1890,7 +1890,7 @@ func (b *Bundle) Compile(log logger.Log, options config.Options) ([]graph.Output // Make sure an output file never overwrites an input file sourceAbsPaths := make(map[string]uint32) for _, sourceIndex := range allReachableFiles { - keyPath := b.files[sourceIndex].module.Source.KeyPath + keyPath := b.files[sourceIndex].inputFile.Source.KeyPath if keyPath.Namespace == "file" { lowerAbsPath := lowerCaseAbsPathForWindows(keyPath.Text) sourceAbsPaths[lowerAbsPath] = sourceIndex @@ -1899,7 +1899,7 @@ func (b *Bundle) Compile(log logger.Log, options config.Options) ([]graph.Output for _, outputFile := range outputFiles { lowerAbsPath := lowerCaseAbsPathForWindows(outputFile.AbsPath) if sourceIndex, ok := sourceAbsPaths[lowerAbsPath]; ok { - log.AddError(nil, logger.Loc{}, "Refusing to overwrite input file: "+b.files[sourceIndex].module.Source.PrettyPath) + log.AddError(nil, logger.Loc{}, "Refusing to overwrite input file: "+b.files[sourceIndex].inputFile.Source.PrettyPath) } } @@ -1959,10 +1959,10 @@ func findReachableFiles(files []graph.LinkerFile, entryPoints []entryMeta) []uin if !visited[sourceIndex] { visited[sourceIndex] = true file := &files[sourceIndex] - if repr, ok := file.Module.Repr.(*graph.JSRepr); ok && repr.CSSSourceIndex.IsValid() { + if repr, ok := file.InputFile.Repr.(*graph.JSRepr); ok && repr.CSSSourceIndex.IsValid() { visit(repr.CSSSourceIndex.GetIndex()) } - for _, record := range *file.Module.Repr.ImportRecords() { + for _, record := range *file.InputFile.Repr.ImportRecords() { if record.SourceIndex.IsValid() { visit(record.SourceIndex.GetIndex()) } @@ -2005,17 +2005,17 @@ func (b *Bundle) computeDataForSourceMapsInParallel(options *config.Options, rea results := make([]dataForSourceMap, len(b.files)) for _, sourceIndex := range reachableFiles { - if f := &b.files[sourceIndex]; f.module.Loader.CanHaveSourceMap() { - if repr, ok := f.module.Repr.(*graph.JSRepr); ok { + if f := &b.files[sourceIndex]; f.inputFile.Loader.CanHaveSourceMap() { + if repr, ok := f.inputFile.Repr.(*graph.JSRepr); ok { waitGroup.Add(1) go func(sourceIndex uint32, f *scannerFile, repr *graph.JSRepr) { result := &results[sourceIndex] - result.lineOffsetTables = js_printer.GenerateLineOffsetTables(f.module.Source.Contents, repr.AST.ApproximateLineCount) - sm := f.module.InputSourceMap + result.lineOffsetTables = js_printer.GenerateLineOffsetTables(f.inputFile.Source.Contents, repr.AST.ApproximateLineCount) + sm := f.inputFile.InputSourceMap if !options.ExcludeSourcesContent { if sm == nil { // Simple case: no nested source map - result.quotedContents = [][]byte{js_printer.QuoteForJSON(f.module.Source.Contents, options.ASCIIOnly)} + result.quotedContents = [][]byte{js_printer.QuoteForJSON(f.inputFile.Source.Contents, options.ASCIIOnly)} } else { // Complex case: nested source map result.quotedContents = make([][]byte, len(sm.Sources)) diff --git a/internal/bundler/debug.go b/internal/bundler/debug.go index 6173e09c..fe962f75 100644 --- a/internal/bundler/debug.go +++ b/internal/bundler/debug.go @@ -24,7 +24,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string { } file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) sb := strings.Builder{} quoteSym := func(ref js_ast.Ref) string { @@ -50,7 +50,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string { sb.WriteString(`,"wrapperPartIndex":true`) } else if len(part.Stmts) > 0 { start := part.Stmts[0].Loc.Start - end := len(file.Module.Source.Contents) + end := len(file.InputFile.Source.Contents) if partIndex+1 < len(repr.AST.Parts) { if nextStmts := repr.AST.Parts[partIndex+1].Stmts; len(nextStmts) > 0 { if nextStart := nextStmts[0].Loc.Start; nextStart >= start { @@ -58,7 +58,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string { } } } - code = file.Module.Source.Contents[start:end] + code = file.InputFile.Source.Contents[start:end] } // importRecords @@ -74,7 +74,7 @@ func (c *linkerContext) generateExtraDataForFileJS(sourceIndex uint32) string { } else { sb.WriteByte(',') } - path := c.files[record.SourceIndex.GetIndex()].Module.Source.PrettyPath + path := c.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].Module.Source.PrettyPath, c.options.ASCIIOnly), + js_printer.QuoteForJSON(c.files[dep.SourceIndex].InputFile.Source.PrettyPath, c.options.ASCIIOnly), dep.PartIndex, )) } diff --git a/internal/bundler/linker.go b/internal/bundler/linker.go index 969898d1..c507785a 100644 --- a/internal/bundler/linker.go +++ b/internal/bundler/linker.go @@ -215,13 +215,13 @@ func newLinkerContext( for _, sourceIndex := range c.reachableFiles { file := files[sourceIndex] - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.JSRepr: // Clone the representation { clone := *repr repr = &clone - file.Module.Repr = repr + file.InputFile.Repr = repr } // Clone the symbol map @@ -287,7 +287,7 @@ func newLinkerContext( { clone := *repr repr = &clone - file.Module.Repr = repr + file.InputFile.Repr = repr } // Clone the import records @@ -312,7 +312,7 @@ func newLinkerContext( file := &c.files[entryPoint.sourceIndex] file.EntryPointKind = graph.EntryPointUserSpecified - if repr, ok := file.Module.Repr.(*graph.JSRepr); ok { + if repr, ok := file.InputFile.Repr.(*graph.JSRepr); ok { // Loaders default to CommonJS when they are the entry point and the output // format is not ESM-compatible since that avoids generating the ESM-to-CJS // machinery. @@ -336,7 +336,7 @@ func newLinkerContext( // Allocate a new unbound symbol called "module" in case we need it later if c.options.OutputFormat == config.FormatCommonJS { runtimeSymbols := &c.symbols.SymbolsForSource[runtime.SourceIndex] - runtimeScope := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr).AST.ModuleScope + runtimeScope := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.ModuleScope c.unboundModuleRef = js_ast.Ref{SourceIndex: runtime.SourceIndex, InnerIndex: uint32(len(*runtimeSymbols))} runtimeScope.Generated = append(runtimeScope.Generated, c.unboundModuleRef) *runtimeSymbols = append(*runtimeSymbols, js_ast.Symbol{ @@ -355,7 +355,7 @@ func (c *linkerContext) addPartToFile(sourceIndex uint32, part js_ast.Part) uint if part.SymbolUses == nil { part.SymbolUses = make(map[js_ast.Ref]js_ast.SymbolUse) } - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.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{}) @@ -493,7 +493,7 @@ func (c *linkerContext) generateChunksInParallel(chunks []chunkInfo) []graph.Out // Each file may optionally contain additional files to be copied to the // output directory. This is used by the "file" loader. for _, sourceIndex := range chunk.filesInChunkInOrder { - outputFiles = append(outputFiles, c.files[sourceIndex].Module.AdditionalFiles...) + outputFiles = append(outputFiles, c.files[sourceIndex].InputFile.AdditionalFiles...) } // Path substitution for the chunk itself @@ -662,13 +662,13 @@ func (c *linkerContext) pathRelativeToOutbase( // Use the extension from the explicit output file path. However, don't do // that if this is a CSS chunk but the entry point file is not CSS. In that // case use the standard extension. This happens when importing CSS into JS. - if _, ok := file.Module.Repr.(*graph.CSSRepr); ok || stdExt != c.options.OutputExtensionCSS { + if _, ok := file.InputFile.Repr.(*graph.CSSRepr); ok || stdExt != c.options.OutputExtensionCSS { baseExt = ext } return } - absPath := file.Module.Source.KeyPath.Text + absPath := file.InputFile.Source.KeyPath.Text isCustomOutputPath := false if outPath := c.entryPoints[entryPointBit].outputPath; outPath != "" { @@ -678,7 +678,7 @@ func (c *linkerContext) pathRelativeToOutbase( absPath = c.fs.Join(c.options.AbsOutputBase, absPath) } isCustomOutputPath = true - } else if file.Module.Source.KeyPath.Namespace != "file" { + } else if file.InputFile.Source.KeyPath.Namespace != "file" { // Come up with a path for virtual paths (i.e. non-file-system paths) dir, base, _ := logger.PlatformIndependentPathDirBaseExt(absPath) if avoidIndex && base == "index" { @@ -779,7 +779,7 @@ func (c *linkerContext) computeCrossChunkDependencies(chunks []chunkInfo) { // Go over each file in this chunk for sourceIndex := range chunk.filesWithPartsInChunk { // Go over each part in this file that's marked for inclusion in this chunk - switch repr := c.files[sourceIndex].Module.Repr.(type) { + switch repr := c.files[sourceIndex].InputFile.Repr.(type) { case *graph.JSRepr: for partIndex, partMeta := range repr.Meta.PartMeta { if !partMeta.IsLive { @@ -866,14 +866,14 @@ func (c *linkerContext) computeCrossChunkDependencies(chunks []chunkInfo) { // Include the exports if this is an entry point chunk if chunk.isEntryPoint { - if repr, ok := c.files[chunk.sourceIndex].Module.Repr.(*graph.JSRepr); ok { + if repr, ok := c.files[chunk.sourceIndex].InputFile.Repr.(*graph.JSRepr); ok { if repr.Meta.Wrap != graph.WrapCJS { for _, alias := range repr.Meta.SortedAndFilteredExportAliases { export := repr.Meta.ResolvedExports[alias] targetRef := export.Ref // If this is an import, then target what the import points to - if importData, ok := c.files[export.SourceIndex].Module.Repr.(*graph.JSRepr).Meta.ImportsToBind[targetRef]; ok { + if importData, ok := c.files[export.SourceIndex].InputFile.Repr.(*graph.JSRepr).Meta.ImportsToBind[targetRef]; ok { targetRef = importData.Ref } @@ -1101,24 +1101,24 @@ func (c *linkerContext) scanImportsAndExports() { // Step 1: Figure out what modules must be CommonJS for _, sourceIndex := range c.reachableFiles { file := &c.files[sourceIndex] - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.CSSRepr: // Inline URLs for non-CSS files into the CSS file var additionalFiles []graph.OutputFile for importRecordIndex := range repr.AST.ImportRecords { if record := &repr.AST.ImportRecords[importRecordIndex]; record.SourceIndex.IsValid() { otherFile := &c.files[record.SourceIndex.GetIndex()] - if otherRepr, ok := otherFile.Module.Repr.(*graph.JSRepr); ok { + if otherRepr, ok := otherFile.InputFile.Repr.(*graph.JSRepr); ok { record.Path.Text = otherRepr.AST.URLForCSS record.Path.Namespace = "" record.SourceIndex = ast.Index32{} // Copy the additional files to the output directory - additionalFiles = append(additionalFiles, otherFile.Module.AdditionalFiles...) + additionalFiles = append(additionalFiles, otherFile.InputFile.AdditionalFiles...) } } } - file.Module.AdditionalFiles = additionalFiles + file.InputFile.AdditionalFiles = additionalFiles case *graph.JSRepr: for importRecordIndex := range repr.AST.ImportRecords { @@ -1128,7 +1128,7 @@ func (c *linkerContext) scanImportsAndExports() { } otherFile := &c.files[record.SourceIndex.GetIndex()] - otherRepr := otherFile.Module.Repr.(*graph.JSRepr) + otherRepr := otherFile.InputFile.Repr.(*graph.JSRepr) switch record.Kind { case ast.ImportStmt: @@ -1204,7 +1204,7 @@ func (c *linkerContext) scanImportsAndExports() { // In this case the export star must be evaluated at run time instead of at // bundle time. for _, sourceIndex := range c.reachableFiles { - repr, ok := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr, ok := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if !ok { continue } @@ -1226,7 +1226,7 @@ func (c *linkerContext) scanImportsAndExports() { // that imports that entry point). for _, record := range repr.AST.ImportRecords { if record.SourceIndex.IsValid() { - otherRepr := c.files[record.SourceIndex.GetIndex()].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[record.SourceIndex.GetIndex()].InputFile.Repr.(*graph.JSRepr) if otherRepr.AST.ExportsKind == js_ast.ExportsCommonJS { c.recursivelyWrapDependencies(record.SourceIndex.GetIndex()) } @@ -1239,7 +1239,7 @@ func (c *linkerContext) scanImportsAndExports() { // are ignored for those modules. exportStarStack := make([]uint32, 0, 32) for _, sourceIndex := range c.reachableFiles { - repr, ok := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr, ok := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if !ok { continue } @@ -1276,7 +1276,7 @@ func (c *linkerContext) scanImportsAndExports() { // export stars because imports can bind to export star re-exports. for _, sourceIndex := range c.reachableFiles { file := &c.files[sourceIndex] - repr, ok := file.Module.Repr.(*graph.JSRepr) + repr, ok := file.InputFile.Repr.(*graph.JSRepr) if !ok { continue } @@ -1303,7 +1303,7 @@ func (c *linkerContext) scanImportsAndExports() { // imported using an import star statement. waitGroup := sync.WaitGroup{} for _, sourceIndex := range c.reachableFiles { - repr, ok := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr, ok := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if !ok { continue } @@ -1318,14 +1318,14 @@ func (c *linkerContext) scanImportsAndExports() { for alias, export := range repr.Meta.ResolvedExports { // Re-exporting multiple symbols with the same name causes an ambiguous // export. These names cannot be used and should not end up in generated code. - otherRepr := c.files[export.SourceIndex].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[export.SourceIndex].InputFile.Repr.(*graph.JSRepr) if len(export.PotentiallyAmbiguousExportStarRefs) > 0 { mainRef := export.Ref if imported, ok := otherRepr.Meta.ImportsToBind[export.Ref]; ok { mainRef = imported.Ref } for _, ambiguousExport := range export.PotentiallyAmbiguousExportStarRefs { - ambiguousRepr := c.files[ambiguousExport.SourceIndex].Module.Repr.(*graph.JSRepr) + ambiguousRepr := c.files[ambiguousExport.SourceIndex].InputFile.Repr.(*graph.JSRepr) ambiguousRef := ambiguousExport.Ref if imported, ok := ambiguousRepr.Meta.ImportsToBind[ambiguousExport.Ref]; ok { ambiguousRef = imported.Ref @@ -1360,7 +1360,7 @@ func (c *linkerContext) scanImportsAndExports() { // parts that declare the export to all parts that use the import. for _, sourceIndex := range c.reachableFiles { file := &c.files[sourceIndex] - repr, ok := file.Module.Repr.(*graph.JSRepr) + repr, ok := file.InputFile.Repr.(*graph.JSRepr) if !ok { continue } @@ -1390,7 +1390,7 @@ func (c *linkerContext) scanImportsAndExports() { // Use "init_*" for ESM wrappers instead of "require_*" if repr.Meta.Wrap == graph.WrapESM { - c.symbols.Get(repr.AST.WrapperRef).OriginalName = "init_" + file.Module.Source.IdentifierName + c.symbols.Get(repr.AST.WrapperRef).OriginalName = "init_" + file.InputFile.Source.IdentifierName } // If this isn't CommonJS, then rename the unused "exports" and "module" @@ -1400,7 +1400,7 @@ func (c *linkerContext) scanImportsAndExports() { // this point, we know the CommonJS status will not change further. if repr.Meta.Wrap != graph.WrapCJS && repr.AST.ExportsKind != js_ast.ExportsCommonJS && (!file.IsEntryPoint() || c.options.OutputFormat != config.FormatCommonJS) { - name := file.Module.Source.IdentifierName + name := file.InputFile.Source.IdentifierName c.symbols.Get(repr.AST.ExportsRef).OriginalName = name + "_exports" c.symbols.Get(repr.AST.ModuleRef).OriginalName = name + "_module" } @@ -1409,7 +1409,7 @@ func (c *linkerContext) scanImportsAndExports() { // previous step. The previous step can't do this because it's running in // parallel and can't safely mutate the "importsToBind" map of another file. if repr.Meta.NeedsExportSymbolFromRuntime || repr.Meta.NeedsMarkAsModuleSymbolFromRuntime { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) exportPart := &repr.AST.Parts[repr.Meta.NSExportPartIndex] if repr.Meta.NeedsExportSymbolFromRuntime { exportRef := runtimeRepr.AST.ModuleScope.Members["__export"].Ref @@ -1422,7 +1422,7 @@ func (c *linkerContext) scanImportsAndExports() { } for importRef, importData := range repr.Meta.ImportsToBind { - resolvedRepr := c.files[importData.SourceIndex].Module.Repr.(*graph.JSRepr) + resolvedRepr := c.files[importData.SourceIndex].InputFile.Repr.(*graph.JSRepr) partsDeclaringSymbol := resolvedRepr.AST.TopLevelSymbolToParts[importData.Ref] for _, partIndex := range repr.AST.NamedImports[importRef].LocalPartsWithUses { @@ -1449,7 +1449,7 @@ func (c *linkerContext) scanImportsAndExports() { func (c *linkerContext) generateCodeForLazyExport(sourceIndex uint32) { file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) // Grab the lazy expression if len(repr.AST.Parts) < 1 { @@ -1550,7 +1550,7 @@ func (c *linkerContext) generateCodeForLazyExport(sourceIndex uint32) { } // Generate the default export - generateExport(file.Module.Source.IdentifierName+"_default", "default", jsonValue, prevExports) + generateExport(file.InputFile.Source.IdentifierName+"_default", "default", jsonValue, prevExports) } func (c *linkerContext) createExportsForFile(sourceIndex uint32) { @@ -1560,7 +1560,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { //////////////////////////////////////////////////////////////////////////////// file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) // Generate a getter per export properties := []js_ast.Property{} @@ -1573,7 +1573,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { // was eventually resolved to. We need to do this because imports have // already been resolved by this point, so we can't generate a new import // and have that be resolved later. - if importData, ok := c.files[export.SourceIndex].Module.Repr.(*graph.JSRepr).Meta.ImportsToBind[export.Ref]; ok { + if importData, ok := c.files[export.SourceIndex].InputFile.Repr.(*graph.JSRepr).Meta.ImportsToBind[export.Ref]; ok { export.Ref = importData.Ref export.SourceIndex = importData.SourceIndex nsExportDependencies = append(nsExportDependencies, importData.ReExports...) @@ -1603,7 +1603,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { nsExportSymbolUses[export.Ref] = js_ast.SymbolUse{CountEstimate: 1} // Make sure the part that declares the export is included - for _, partIndex := range c.files[export.SourceIndex].Module.Repr.(*graph.JSRepr).AST.TopLevelSymbolToParts[export.Ref] { + for _, partIndex := range c.files[export.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.TopLevelSymbolToParts[export.Ref] { // Use a non-local dependency since this is likely from a different // file if it came in through an export star nsExportDependencies = append(nsExportDependencies, js_ast.Dependency{ @@ -1633,7 +1633,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { // that have been each converted from ESM to CommonJS may not work correctly. if repr.AST.ExportKeyword.Len > 0 && (repr.AST.ExportsKind == js_ast.ExportsCommonJS || (file.IsEntryPoint() && c.options.OutputFormat == config.FormatCommonJS)) { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) markAsModuleRef := runtimeRepr.AST.ModuleScope.Members["__markAsModule"].Ref nsExportStmts = append(nsExportStmts, js_ast.Stmt{Data: &js_ast.SExpr{Value: js_ast.Expr{Data: &js_ast.ECall{ Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: markAsModuleRef}}, @@ -1657,7 +1657,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { // "__export(exports, { foo: () => foo })" exportRef := js_ast.InvalidRef if len(properties) > 0 { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) exportRef = runtimeRepr.AST.ModuleScope.Members["__export"].Ref nsExportStmts = append(nsExportStmts, js_ast.Stmt{Data: &js_ast.SExpr{Value: js_ast.Expr{Data: &js_ast.ECall{ Target: js_ast.Expr{Data: &js_ast.EIdentifier{Ref: exportRef}}, @@ -1711,7 +1711,7 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) { func (c *linkerContext) matchImportsWithExportsForFile(sourceIndex uint32) { file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) // Sort imports for determinism. Otherwise our unit tests will randomly // fail sometimes when error messages are reordered. @@ -1758,7 +1758,7 @@ func (c *linkerContext) matchImportsWithExportsForFile(sourceIndex uint32) { case matchImportCycle: namedImport := repr.AST.NamedImports[importRef] - c.log.AddRangeError(&file.Module.Source, js_lexer.RangeOfIdentifier(file.Module.Source, namedImport.AliasLoc), + c.log.AddRangeError(&file.InputFile.Source, js_lexer.RangeOfIdentifier(file.InputFile.Source, namedImport.AliasLoc), fmt.Sprintf("Detected cycle while resolving import %q", namedImport.Alias)) case matchImportProbablyTypeScriptType: @@ -1766,13 +1766,13 @@ func (c *linkerContext) matchImportsWithExportsForFile(sourceIndex uint32) { case matchImportAmbiguous: namedImport := repr.AST.NamedImports[importRef] - r := js_lexer.RangeOfIdentifier(file.Module.Source, namedImport.AliasLoc) + r := js_lexer.RangeOfIdentifier(file.InputFile.Source, namedImport.AliasLoc) var notes []logger.MsgData // Provide the locations of both ambiguous exports if possible if result.nameLoc.Start != 0 && result.otherNameLoc.Start != 0 { - a := c.files[result.sourceIndex].Module.Source - b := c.files[result.otherSourceIndex].Module.Source + a := c.files[result.sourceIndex].InputFile.Source + b := c.files[result.otherSourceIndex].InputFile.Source notes = []logger.MsgData{ logger.RangeData(&a, js_lexer.RangeOfIdentifier(a, result.nameLoc), "One matching export is here"), logger.RangeData(&b, js_lexer.RangeOfIdentifier(b, result.otherNameLoc), "Another matching export is here"), @@ -1790,10 +1790,10 @@ func (c *linkerContext) matchImportsWithExportsForFile(sourceIndex uint32) { // "undefined" instead of emitting an error. symbol.ImportItemStatus = js_ast.ImportItemMissing msg := fmt.Sprintf("Import %q will always be undefined because there are multiple matching exports", namedImport.Alias) - c.log.AddRangeWarningWithNotes(&file.Module.Source, r, msg, notes) + c.log.AddRangeWarningWithNotes(&file.InputFile.Source, r, msg, notes) } else { msg := fmt.Sprintf("Ambiguous import %q has multiple matching exports", namedImport.Alias) - c.log.AddRangeErrorWithNotes(&file.Module.Source, r, msg, notes) + c.log.AddRangeErrorWithNotes(&file.InputFile.Source, r, msg, notes) } } } @@ -1876,7 +1876,7 @@ loop: // though. This is the case for star imports, where the import is the // namespace. trackerFile := &c.files[tracker.sourceIndex] - namedImport := trackerFile.Module.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] + namedImport := trackerFile.InputFile.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] if namedImport.NamespaceRef != js_ast.InvalidRef { if result.kind == matchImportNormal { result.kind = matchImportNormalAndNamespace @@ -1893,18 +1893,18 @@ loop: // Warn about importing from a file that is known to not have any exports if status == importCommonJSWithoutExports { - source := trackerFile.Module.Source + source := trackerFile.InputFile.Source symbol := c.symbols.Get(tracker.importRef) symbol.ImportItemStatus = js_ast.ImportItemMissing c.log.AddRangeWarning(&source, js_lexer.RangeOfIdentifier(source, namedImport.AliasLoc), fmt.Sprintf("Import %q will always be undefined because the file %q has no exports", - namedImport.Alias, c.files[nextTracker.sourceIndex].Module.Source.PrettyPath)) + namedImport.Alias, c.files[nextTracker.sourceIndex].InputFile.Source.PrettyPath)) } case importDynamicFallback: // If it's a file with dynamic export fallback, rewrite the import to a property access trackerFile := &c.files[tracker.sourceIndex] - namedImport := trackerFile.Module.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] + namedImport := trackerFile.InputFile.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] if result.kind == matchImportNormal { result.kind = matchImportNormalAndNamespace result.namespaceRef = nextTracker.importRef @@ -1920,8 +1920,8 @@ loop: case importNoMatch: symbol := c.symbols.Get(tracker.importRef) trackerFile := &c.files[tracker.sourceIndex] - source := trackerFile.Module.Source - namedImport := trackerFile.Module.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] + source := trackerFile.InputFile.Source + namedImport := trackerFile.InputFile.Repr.(*graph.JSRepr).AST.NamedImports[tracker.importRef] r := js_lexer.RangeOfIdentifier(source, namedImport.AliasLoc) // Report mismatched imports and exports @@ -1938,7 +1938,7 @@ loop: "Import %q will always be undefined because there is no matching export", namedImport.Alias)) } else { c.log.AddRangeError(&source, r, fmt.Sprintf("No matching export in %q for import %q", - c.files[nextTracker.sourceIndex].Module.Source.PrettyPath, namedImport.Alias)) + c.files[nextTracker.sourceIndex].InputFile.Source.PrettyPath, namedImport.Alias)) } case importProbablyTypeScriptType: @@ -1951,7 +1951,7 @@ loop: // statements, trace them all to see if they point to different things. for _, ambiguousTracker := range potentiallyAmbiguousExportStarRefs { // If this is a re-export of another import, follow the import - if _, ok := c.files[ambiguousTracker.SourceIndex].Module.Repr.(*graph.JSRepr).AST.NamedImports[ambiguousTracker.Ref]; ok { + if _, ok := c.files[ambiguousTracker.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.NamedImports[ambiguousTracker.Ref]; ok { // Save and restore the cycle detector to avoid mixing information oldCycleDetector := c.cycleDetector ambiguousResult, newReExportFiles := c.matchImportWithExport(importTracker{ @@ -1985,7 +1985,7 @@ loop: // Depend on the statement(s) that declared this import symbol in the // original file - for _, resolvedPartIndex := range c.files[tracker.sourceIndex].Module.Repr.(*graph.JSRepr).AST.TopLevelSymbolToParts[tracker.importRef] { + for _, resolvedPartIndex := range c.files[tracker.sourceIndex].InputFile.Repr.(*graph.JSRepr).AST.TopLevelSymbolToParts[tracker.importRef] { reExports = append(reExports, js_ast.Dependency{ SourceIndex: tracker.sourceIndex, PartIndex: resolvedPartIndex, @@ -1994,7 +1994,7 @@ loop: // If this is a re-export of another import, continue for another // iteration of the loop to resolve that import as well - if _, ok := c.files[nextTracker.sourceIndex].Module.Repr.(*graph.JSRepr).AST.NamedImports[nextTracker.importRef]; ok { + if _, ok := c.files[nextTracker.sourceIndex].InputFile.Repr.(*graph.JSRepr).AST.NamedImports[nextTracker.importRef]; ok { tracker = nextTracker continue } @@ -2028,7 +2028,7 @@ loop: } func (c *linkerContext) recursivelyWrapDependencies(sourceIndex uint32) { - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if repr.DidWrapDependencies { return } @@ -2058,7 +2058,7 @@ func (c *linkerContext) recursivelyWrapDependencies(sourceIndex uint32) { func (c *linkerContext) hasDynamicExportsDueToExportStar(sourceIndex uint32, visited map[uint32]bool) bool { // Terminate the traversal now if this file already has dynamic exports - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if repr.AST.ExportsKind == js_ast.ExportsCommonJS || repr.AST.ExportsKind == js_ast.ExportsESMWithDynamicFallback { return true } @@ -2098,7 +2098,7 @@ func (c *linkerContext) addExportsForExportStar( } } sourceIndexStack = append(sourceIndexStack, sourceIndex) - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) for _, importRecordIndex := range repr.AST.ExportStarImportRecords { record := &repr.AST.ImportRecords[importRecordIndex] @@ -2115,7 +2115,7 @@ func (c *linkerContext) addExportsForExportStar( // exports even though it still uses CommonJS features. However, when // doing this we'd also have to rewrite any imports of these export star // re-exports as property accesses off of a generated require() call. - otherRepr := c.files[otherSourceIndex].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[otherSourceIndex].InputFile.Repr.(*graph.JSRepr) if otherRepr.AST.ExportsKind == js_ast.ExportsCommonJS { // All exports will be resolved at run time instead continue @@ -2131,7 +2131,7 @@ func (c *linkerContext) addExportsForExportStar( // This export star is shadowed if any file in the stack has a matching real named export for _, prevSourceIndex := range sourceIndexStack { - prevRepr := c.files[prevSourceIndex].Module.Repr.(*graph.JSRepr) + prevRepr := c.files[prevSourceIndex].InputFile.Repr.(*graph.JSRepr) if _, ok := prevRepr.AST.NamedExports[alias]; ok { continue nextExport } @@ -2205,7 +2205,7 @@ const ( func (c *linkerContext) advanceImportTracker(tracker importTracker) (importTracker, importStatus, []graph.ImportData) { file := &c.files[tracker.sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) namedImport := repr.AST.NamedImports[tracker.importRef] // Is this an external file? @@ -2216,12 +2216,12 @@ func (c *linkerContext) advanceImportTracker(tracker importTracker) (importTrack // Is this a disabled file? otherSourceIndex := record.SourceIndex.GetIndex() - if c.files[otherSourceIndex].Module.Source.KeyPath.IsDisabled() { + if c.files[otherSourceIndex].InputFile.Source.KeyPath.IsDisabled() { return importTracker{sourceIndex: otherSourceIndex, importRef: js_ast.InvalidRef}, importDisabled, nil } // Is this a named import of a file without any exports? - otherRepr := c.files[otherSourceIndex].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[otherSourceIndex].InputFile.Repr.(*graph.JSRepr) if !namedImport.AliasIsStar && !otherRepr.AST.HasLazyExport && // CommonJS exports otherRepr.AST.ExportKeyword.Len == 0 && namedImport.Alias != "default" && @@ -2262,7 +2262,7 @@ func (c *linkerContext) advanceImportTracker(tracker importTracker) (importTrack } // Missing re-exports in TypeScript files are indistinguishable from types - if file.Module.Loader.IsTypeScript() && namedImport.IsExported { + if file.InputFile.Loader.IsTypeScript() && namedImport.IsExported { return importTracker{}, importProbablyTypeScriptType, nil } @@ -2277,7 +2277,7 @@ func (c *linkerContext) markPartsReachableFromEntryPoints() { file := &c.files[sourceIndex] file.EntryBits = helpers.NewBitSet(bitCount) - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.JSRepr: // If this is a CommonJS file, we're going to need to generate a wrapper // for the CommonJS closure. That will end up looking something like this: @@ -2294,7 +2294,7 @@ func (c *linkerContext) markPartsReachableFromEntryPoints() { // dependencies and let the general-purpose reachablity analysis take care // of it. if repr.Meta.Wrap == graph.WrapCJS { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) commonJSRef := runtimeRepr.AST.NamedExports["__commonJS"].Ref commonJSParts := runtimeRepr.AST.TopLevelSymbolToParts[commonJSRef] @@ -2333,7 +2333,7 @@ func (c *linkerContext) markPartsReachableFromEntryPoints() { // This depends on the "__esm" symbol and declares the "init_foo" symbol // for similar reasons to the CommonJS closure above. if repr.Meta.Wrap == graph.WrapESM { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) esmRef := runtimeRepr.AST.NamedExports["__esm"].Ref esmParts := runtimeRepr.AST.TopLevelSymbolToParts[esmRef] @@ -2395,7 +2395,7 @@ func (c *linkerContext) markFileAsReachable(sourceIndex uint32, entryPointBit ui } file.EntryBits.SetBit(entryPointBit) - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.JSRepr: // If the JavaScript stub for a CSS file is included, also include the CSS file if repr.CSSSourceIndex.IsValid() { @@ -2448,7 +2448,7 @@ func (c *linkerContext) markFileAsLive(sourceIndex uint32) { } file.IsLive = true - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.JSRepr: isTreeShakingEnabled := config.IsTreeShakingEnabled(c.options.Mode, c.options.OutputFormat) @@ -2472,7 +2472,7 @@ func (c *linkerContext) markFileAsLive(sourceIndex uint32) { // Don't include this module for its side effects if it can be // considered to have no side effects - if otherFile := &c.files[otherSourceIndex]; otherFile.Module.SideEffects.Kind != graph.HasSideEffects && !c.options.IgnoreDCEAnnotations { + if otherFile := &c.files[otherSourceIndex]; otherFile.InputFile.SideEffects.Kind != graph.HasSideEffects && !c.options.IgnoreDCEAnnotations { // This is currently unsafe when code splitting is enabled, so // disable it in that case if len(c.entryPoints) < 2 { @@ -2505,11 +2505,11 @@ func (c *linkerContext) markFileAsLive(sourceIndex uint32) { targetRef := export.Ref // If this is an import, then target what the import points to - targetRepr := c.files[targetSourceIndex].Module.Repr.(*graph.JSRepr) + targetRepr := c.files[targetSourceIndex].InputFile.Repr.(*graph.JSRepr) if importData, ok := targetRepr.Meta.ImportsToBind[targetRef]; ok { targetSourceIndex = importData.SourceIndex targetRef = importData.Ref - targetRepr = c.files[targetSourceIndex].Module.Repr.(*graph.JSRepr) + targetRepr = c.files[targetSourceIndex].InputFile.Repr.(*graph.JSRepr) } // Pull in all declarations of this symbol @@ -2543,7 +2543,7 @@ func (c *linkerContext) markPartsAsLiveForRuntimeSymbol( part *js_ast.Part, repr *graph.JSRepr, useCount uint32, name string, ) { if useCount > 0 { - runtimeRepr := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr) + runtimeRepr := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) ref := runtimeRepr.AST.NamedExports[name].Ref // Depend on the symbol from the runtime @@ -2584,7 +2584,7 @@ func (c *linkerContext) isExternalDynamicImport(record *ast.ImportRecord, source func (c *linkerContext) markPartAsLive(sourceIndex uint32, partIndex uint32) { file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) partMeta := &repr.Meta.PartMeta[partIndex] // Don't mark this part more than once @@ -2621,7 +2621,7 @@ func (c *linkerContext) markPartAsLive(sourceIndex uint32, partIndex uint32) { } otherSourceIndex := record.SourceIndex.GetIndex() - otherRepr := c.files[otherSourceIndex].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[otherSourceIndex].InputFile.Repr.(*graph.JSRepr) if record.Kind == ast.ImportRequire || record.Kind == ast.ImportDynamic || (record.Kind == ast.ImportStmt && otherRepr.Meta.Wrap != graph.WrapNone) { @@ -2673,7 +2673,7 @@ func (c *linkerContext) markPartAsLive(sourceIndex uint32, partIndex uint32) { happensAtRunTime := !record.SourceIndex.IsValid() && (!file.IsEntryPoint() || !c.options.OutputFormat.KeepES6ImportExportSyntax()) if record.SourceIndex.IsValid() { otherSourceIndex := record.SourceIndex.GetIndex() - otherRepr := c.files[otherSourceIndex].Module.Repr.(*graph.JSRepr) + otherRepr := c.files[otherSourceIndex].InputFile.Repr.(*graph.JSRepr) if otherSourceIndex != sourceIndex && otherRepr.AST.ExportsKind.IsDynamic() { happensAtRunTime = true } @@ -2761,7 +2761,7 @@ func (c *linkerContext) computeChunks() []chunkInfo { filesWithPartsInChunk: make(map[uint32]bool), } - switch file.Module.Repr.(type) { + switch file.InputFile.Repr.(type) { case *graph.JSRepr: info.chunkRepr = &chunkReprJS{} jsChunks[entryBits.String()] = info @@ -2782,7 +2782,7 @@ func (c *linkerContext) computeChunks() []chunkInfo { key := file.EntryBits.String() var chunk chunkInfo var ok bool - switch file.Module.Repr.(type) { + switch file.InputFile.Repr.(type) { case *graph.JSRepr: chunk, ok = jsChunks[key] if !ok { @@ -2842,7 +2842,7 @@ func (c *linkerContext) computeChunks() []chunkInfo { // and a CSS chunk. Don't link the CSS chunk to the JS file since the CSS // chunk is secondary (the JS chunk is primary). if _, ok := chunk.chunkRepr.(*chunkReprCSS); ok { - if _, ok := file.Module.Repr.(*graph.JSRepr); ok { + if _, ok := file.InputFile.Repr.(*graph.JSRepr); ok { continue } } @@ -2968,7 +2968,7 @@ func (c *linkerContext) shouldIncludePart(repr *graph.JSRepr, part js_ast.Part) if len(part.Stmts) == 1 { if s, ok := part.Stmts[0].Data.(*js_ast.SImport); ok { record := &repr.AST.ImportRecords[s.ImportRecordIndex] - if record.SourceIndex.IsValid() && c.files[record.SourceIndex.GetIndex()].Module.Repr.(*graph.JSRepr).Meta.Wrap == graph.WrapNone { + if record.SourceIndex.IsValid() && c.files[record.SourceIndex.GetIndex()].InputFile.Repr.(*graph.JSRepr).Meta.Wrap == graph.WrapNone { return false } } @@ -3009,7 +3009,7 @@ func (c *linkerContext) chunkFileOrder(chunk *chunkInfo) (js []uint32, jsParts [ file := &c.files[sourceIndex] isFileInThisChunk := chunk.entryBits.Equals(file.EntryBits) - switch repr := file.Module.Repr.(type) { + switch repr := file.InputFile.Repr.(type) { case *graph.JSRepr: // Wrapped files can't be split because they are all inside the wrapper canFileBeSplit := repr.Meta.Wrap == graph.WrapNone @@ -3092,7 +3092,7 @@ func (c *linkerContext) shouldRemoveImportExportStmt( namespaceRef js_ast.Ref, importRecordIndex uint32, ) bool { - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) record := &repr.AST.ImportRecords[importRecordIndex] // Is this an external import? @@ -3120,7 +3120,7 @@ func (c *linkerContext) shouldRemoveImportExportStmt( } otherFile := &c.files[record.SourceIndex.GetIndex()] - otherRepr := otherFile.Module.Repr.(*graph.JSRepr) + otherRepr := otherFile.InputFile.Repr.(*graph.JSRepr) switch otherRepr.Meta.Wrap { case graph.WrapNone: // Remove the statement entirely if this module is not wrapped @@ -3160,7 +3160,7 @@ func (c *linkerContext) shouldRemoveImportExportStmt( func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtList, partStmts []js_ast.Stmt) { file := &c.files[sourceIndex] shouldStripExports := c.options.Mode != config.ModePassThrough || !file.IsEntryPoint() - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) shouldExtractESMStmtsForWrap := repr.Meta.Wrap != graph.WrapNone for _, stmt := range partStmts { @@ -3219,7 +3219,7 @@ func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtL } // Prefix this module with "__reExport(exports, ns)" - exportStarRef := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr).AST.ModuleScope.Members["__reExport"].Ref + exportStarRef := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.ModuleScope.Members["__reExport"].Ref stmtList.insideWrapperPrefix = append(stmtList.insideWrapperPrefix, js_ast.Stmt{ Loc: stmt.Loc, Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: stmt.Loc, Data: &js_ast.ECall{ @@ -3239,7 +3239,7 @@ func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtL } } else { if record.SourceIndex.IsValid() { - if otherRepr := c.files[record.SourceIndex.GetIndex()].Module.Repr.(*graph.JSRepr); otherRepr.Meta.Wrap == graph.WrapESM { + if otherRepr := c.files[record.SourceIndex.GetIndex()].InputFile.Repr.(*graph.JSRepr); otherRepr.Meta.Wrap == graph.WrapESM { stmtList.insideWrapperPrefix = append(stmtList.insideWrapperPrefix, js_ast.Stmt{Loc: stmt.Loc, Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: stmt.Loc, Data: &js_ast.ECall{ Target: js_ast.Expr{Loc: stmt.Loc, Data: &js_ast.EIdentifier{Ref: otherRepr.AST.WrapperRef}}}}}}) @@ -3249,7 +3249,7 @@ func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtL if record.CallsRunTimeExportStarFn { var target js_ast.E if record.SourceIndex.IsValid() { - if otherRepr := c.files[record.SourceIndex.GetIndex()].Module.Repr.(*graph.JSRepr); otherRepr.AST.ExportsKind == js_ast.ExportsESMWithDynamicFallback { + if otherRepr := c.files[record.SourceIndex.GetIndex()].InputFile.Repr.(*graph.JSRepr); otherRepr.AST.ExportsKind == js_ast.ExportsESMWithDynamicFallback { // Prefix this module with "__reExport(exports, otherExports)" target = &js_ast.EIdentifier{Ref: otherRepr.AST.ExportsRef} } @@ -3258,7 +3258,7 @@ func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtL // Prefix this module with "__reExport(exports, require(path))" target = &js_ast.ERequire{ImportRecordIndex: s.ImportRecordIndex} } - exportStarRef := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr).AST.ModuleScope.Members["__reExport"].Ref + exportStarRef := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.ModuleScope.Members["__reExport"].Ref stmtList.insideWrapperPrefix = append(stmtList.insideWrapperPrefix, js_ast.Stmt{ Loc: stmt.Loc, Data: &js_ast.SExpr{Value: js_ast.Expr{Loc: stmt.Loc, Data: &js_ast.ECall{ @@ -3440,7 +3440,7 @@ type compileResultJS struct { } func (c *linkerContext) requireOrImportMetaForSource(sourceIndex uint32) (meta js_printer.RequireOrImportMeta) { - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) meta.WrapperRef = repr.AST.WrapperRef meta.IsWrapperAsync = repr.Meta.IsAsyncOrHasAsyncDependency if repr.Meta.Wrap == graph.WrapESM { @@ -3464,7 +3464,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS( dataForSourceMaps []dataForSourceMap, ) { file := &c.files[partRange.sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) nsExportPartIndex := repr.Meta.NSExportPartIndex needsWrapper := false stmtList := stmtList{} @@ -3631,9 +3631,9 @@ func (c *linkerContext) generateCodeForFileInChunkJS( var addSourceMappings bool var inputSourceMap *sourcemap.SourceMap var lineOffsetTables []js_printer.LineOffsetTable - if file.Module.Loader.CanHaveSourceMap() && c.options.SourceMap != config.SourceMapNone { + if file.InputFile.Loader.CanHaveSourceMap() && c.options.SourceMap != config.SourceMapNone { addSourceMappings = true - inputSourceMap = file.Module.InputSourceMap + inputSourceMap = file.InputFile.InputSourceMap lineOffsetTables = dataForSourceMaps[partRange.sourceIndex].lineOffsetTables } @@ -3675,7 +3675,7 @@ func (c *linkerContext) generateEntryPointTailJS( sourceIndex uint32, ) (result compileResultJS) { file := &c.files[sourceIndex] - repr := file.Module.Repr.(*graph.JSRepr) + repr := file.InputFile.Repr.(*graph.JSRepr) var stmts []js_ast.Stmt switch c.options.OutputFormat { @@ -3847,7 +3847,7 @@ func (c *linkerContext) generateEntryPointTailJS( // was eventually resolved to. We need to do this because imports have // already been resolved by this point, so we can't generate a new import // and have that be resolved later. - if importData, ok := c.files[export.SourceIndex].Module.Repr.(*graph.JSRepr).Meta.ImportsToBind[export.Ref]; ok { + if importData, ok := c.files[export.SourceIndex].InputFile.Repr.(*graph.JSRepr).Meta.ImportsToBind[export.Ref]; ok { export.Ref = importData.Ref export.SourceIndex = importData.SourceIndex } @@ -3970,7 +3970,7 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui // Determine the reserved names (e.g. can't generate the name "if") moduleScopes := make([]*js_ast.Scope, len(filesInOrder)) for i, sourceIndex := range filesInOrder { - moduleScopes[i] = c.files[sourceIndex].Module.Repr.(*graph.JSRepr).AST.ModuleScope + moduleScopes[i] = c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr).AST.ModuleScope } reservedNames := renamer.ComputeReservedNames(moduleScopes, c.symbols) @@ -3985,14 +3985,14 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui // Determine the first top-level slot (i.e. not in a nested scope) var firstTopLevelSlots js_ast.SlotCounts for _, sourceIndex := range filesInOrder { - firstTopLevelSlots.UnionMax(c.files[sourceIndex].Module.Repr.(*graph.JSRepr).AST.NestedScopeSlotCounts) + firstTopLevelSlots.UnionMax(c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr).AST.NestedScopeSlotCounts) } r := renamer.NewMinifyRenamer(c.symbols, firstTopLevelSlots, reservedNames) // Accumulate symbol usage counts into their slots freq := js_ast.CharFreq{} for _, sourceIndex := range filesInOrder { - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if repr.AST.CharFreq != nil { freq.Include(repr.AST.CharFreq) } @@ -4050,7 +4050,7 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui } for _, sourceIndex := range filesInOrder { - repr := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) var scopes []*js_ast.Scope // Modules wrapped in a CommonJS closure look like this: @@ -4156,7 +4156,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun chunk := &chunks[chunkIndex] chunkRepr := chunk.chunkRepr.(*chunkReprJS) compileResults := make([]compileResultJS, 0, len(chunk.partsInChunkInOrder)) - runtimeMembers := c.files[runtime.SourceIndex].Module.Repr.(*graph.JSRepr).AST.ModuleScope.Members + runtimeMembers := c.files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr).AST.ModuleScope.Members commonJSRef := js_ast.FollowSymbols(c.symbols, runtimeMembers["__commonJS"].Ref) esmRef := js_ast.FollowSymbols(c.symbols, runtimeMembers["__esm"].Ref) toModuleRef := js_ast.FollowSymbols(c.symbols, runtimeMembers["__toModule"].Ref) @@ -4256,7 +4256,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun isExecutable := false if chunk.isEntryPoint { - repr := c.files[chunk.sourceIndex].Module.Repr.(*graph.JSRepr) + repr := c.files[chunk.sourceIndex].InputFile.Repr.(*graph.JSRepr) // Start with the hashbang if there is one if repr.AST.Hashbang != "" { @@ -4332,7 +4332,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun var aliases []string if c.options.OutputFormat.KeepES6ImportExportSyntax() { if chunk.isEntryPoint { - if fileRepr := c.files[chunk.sourceIndex].Module.Repr.(*graph.JSRepr); fileRepr.Meta.Wrap == graph.WrapCJS { + if fileRepr := c.files[chunk.sourceIndex].InputFile.Repr.(*graph.JSRepr); fileRepr.Meta.Wrap == graph.WrapCJS { aliases = []string{"default"} } else { resolvedExports := fileRepr.Meta.ResolvedExports @@ -4363,7 +4363,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun jMeta.AddString("\n ") } if chunk.isEntryPoint { - entryPoint := c.files[chunk.sourceIndex].Module.Source.PrettyPath + entryPoint := c.files[chunk.sourceIndex].InputFile.Source.PrettyPath jMeta.AddString(fmt.Sprintf("],\n \"entryPoint\": %s,\n \"inputs\": {", js_printer.QuoteForJSON(entryPoint, c.options.ASCIIOnly))) } else { jMeta.AddString("],\n \"inputs\": {") @@ -4397,7 +4397,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun j.AddString("\n") } - path := c.files[compileResult.sourceIndex].Module.Source.PrettyPath + path := c.files[compileResult.sourceIndex].InputFile.Source.PrettyPath // Make sure newlines in the path can't cause a syntax error. This does // not minimize allocations because it's expected that this case never @@ -4437,7 +4437,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun // Include this file in the metadata if c.options.NeedsMetafile { // Accumulate file sizes since a given file may be split into multiple parts - path := c.files[compileResult.sourceIndex].Module.Source.PrettyPath + path := c.files[compileResult.sourceIndex].InputFile.Source.PrettyPath if count, ok := metaByteCount[path]; ok { metaByteCount[path] = count + len(compileResult.JS) } else { @@ -4507,7 +4507,7 @@ func (c *linkerContext) generateChunkJS(chunks []chunkInfo, chunkIndex int, chun } else { jMeta.AddString(",") } - path := c.files[sourceIndex].Module.Source.PrettyPath + path := c.files[sourceIndex].InputFile.Source.PrettyPath extra := c.generateExtraDataForFileJS(sourceIndex) jMeta.AddString(fmt.Sprintf("\n %s: {\n \"bytesInOutput\": %d\n %s}", js_printer.QuoteForJSON(path, c.options.ASCIIOnly), metaByteCount[path], extra)) @@ -4588,7 +4588,7 @@ func (c *linkerContext) generateChunkCSS(chunks []chunkInfo, chunkIndex int, chu waitGroup.Add(1) go func(sourceIndex uint32, compileResult *compileResultCSS) { file := &c.files[sourceIndex] - ast := file.Module.Repr.(*graph.CSSRepr).AST + ast := file.InputFile.Repr.(*graph.CSSRepr).AST // Filter out "@import" rules rules := make([]css_ast.R, 0, len(ast.Rules)) @@ -4687,9 +4687,9 @@ func (c *linkerContext) generateChunkCSS(chunks []chunkInfo, chunkIndex int, chu // Do not generate "entryPoint" for CSS files that are the result of // importing CSS into JavaScript. We want this to be a 1:1 relationship // and there is already an output file for the JavaScript entry point. - if _, ok := file.Module.Repr.(*graph.CSSRepr); ok { + if _, ok := file.InputFile.Repr.(*graph.CSSRepr); ok { jMeta.AddString(fmt.Sprintf("],\n \"entryPoint\": %s,\n \"inputs\": {", - js_printer.QuoteForJSON(file.Module.Source.PrettyPath, c.options.ASCIIOnly))) + js_printer.QuoteForJSON(file.InputFile.Source.PrettyPath, c.options.ASCIIOnly))) } else { jMeta.AddString("],\n \"inputs\": {") } @@ -4705,7 +4705,7 @@ func (c *linkerContext) generateChunkCSS(chunks []chunkInfo, chunkIndex int, chu if newlineBeforeComment { j.AddString("\n") } - j.AddString(fmt.Sprintf("/* %s */\n", c.files[compileResult.sourceIndex].Module.Source.PrettyPath)) + j.AddString(fmt.Sprintf("/* %s */\n", c.files[compileResult.sourceIndex].InputFile.Source.PrettyPath)) } if len(compileResult.printedCSS) > 0 { newlineBeforeComment = true @@ -4720,7 +4720,7 @@ func (c *linkerContext) generateChunkCSS(chunks []chunkInfo, chunkIndex int, chu jMeta.AddString(",") } jMeta.AddString(fmt.Sprintf("\n %s: {\n \"bytesInOutput\": %d\n }", - js_printer.QuoteForJSON(c.files[compileResult.sourceIndex].Module.Source.PrettyPath, c.options.ASCIIOnly), + js_printer.QuoteForJSON(c.files[compileResult.sourceIndex].InputFile.Source.PrettyPath, c.options.ASCIIOnly), len(compileResult.printedCSS))) } } @@ -4847,20 +4847,20 @@ func (c *linkerContext) generateIsolatedHash(chunk *chunkInfo, channel chan []by var filePath string file := &c.files[partRange.sourceIndex] - if file.Module.Source.KeyPath.Namespace == "file" { + if file.InputFile.Source.KeyPath.Namespace == "file" { // Use the pretty path as the file name since it should be platform- // independent (relative paths and the "/" path separator) - filePath = file.Module.Source.PrettyPath + filePath = file.InputFile.Source.PrettyPath } else { // If this isn't in the "file" namespace, just use the full path text // verbatim. This could be a source of cross-platform differences if // plugins are storing platform-specific information in here, but then // that problem isn't caused by esbuild itself. - filePath = file.Module.Source.KeyPath.Text + filePath = file.InputFile.Source.KeyPath.Text } // Include the path namespace in the hash - hashWriteLengthPrefixed(hash, []byte(file.Module.Source.KeyPath.Namespace)) + hashWriteLengthPrefixed(hash, []byte(file.InputFile.Source.KeyPath.Namespace)) // Then include the file path hashWriteLengthPrefixed(hash, []byte(filePath)) @@ -4949,7 +4949,7 @@ func preventBindingsFromBeingRenamed(binding js_ast.Binding, symbols js_ast.Symb // This is only used when a module is compiled independently. We use a very // different way of handling exports and renaming/minifying when bundling. func (c *linkerContext) preventExportsFromBeingRenamed(sourceIndex uint32) { - repr, ok := c.files[sourceIndex].Module.Repr.(*graph.JSRepr) + repr, ok := c.files[sourceIndex].InputFile.Repr.(*graph.JSRepr) if !ok { return } @@ -5041,14 +5041,14 @@ func (c *linkerContext) generateSourceMapForChunk( file := &c.files[result.sourceIndex] // Simple case: no nested source map - if file.Module.InputSourceMap == nil { + if file.InputFile.InputSourceMap == nil { var quotedContents []byte if !c.options.ExcludeSourcesContent { quotedContents = dataForSourceMaps[result.sourceIndex].quotedContents[0] } items = append(items, item{ - path: file.Module.Source.KeyPath, - prettyPath: file.Module.Source.PrettyPath, + path: file.InputFile.Source.KeyPath, + prettyPath: file.InputFile.Source.PrettyPath, quotedContents: quotedContents, }) nextSourcesIndex++ @@ -5056,17 +5056,17 @@ func (c *linkerContext) generateSourceMapForChunk( } // Complex case: nested source map - sm := file.Module.InputSourceMap + sm := file.InputFile.InputSourceMap for i, source := range sm.Sources { path := logger.Path{ - Namespace: file.Module.Source.KeyPath.Namespace, + Namespace: file.InputFile.Source.KeyPath.Namespace, Text: source, } // If this file is in the "file" namespace, change the relative path in // the source map into an absolute path using the directory of this file if path.Namespace == "file" { - path.Text = c.fs.Join(c.fs.Dir(file.Module.Source.KeyPath.Text), source) + path.Text = c.fs.Join(c.fs.Dir(file.InputFile.Source.KeyPath.Text), source) } var quotedContents []byte diff --git a/internal/graph/graph.go b/internal/graph/graph.go index 793994b2..d80573f9 100644 --- a/internal/graph/graph.go +++ b/internal/graph/graph.go @@ -11,7 +11,7 @@ const ( ) type LinkerFile struct { - Module Module + InputFile InputFile // The minimum number of links in the module graph to get from an entry point // to this file diff --git a/internal/graph/module.go b/internal/graph/module.go index fc8a5f4f..d66391d3 100644 --- a/internal/graph/module.go +++ b/internal/graph/module.go @@ -10,9 +10,9 @@ import ( "github.com/evanw/esbuild/internal/sourcemap" ) -type Module struct { +type InputFile struct { Source logger.Source - Repr ModuleRepr + Repr InputFileRepr Loader config.Loader SideEffects SideEffects InputSourceMap *sourcemap.SourceMap @@ -62,7 +62,7 @@ const ( NoSideEffects_PureData_FromPlugin ) -type ModuleRepr interface { +type InputFileRepr interface { ImportRecords() *[]ast.ImportRecord }