move source map into module

This commit is contained in:
Evan Wallace
2021-04-10 23:50:26 -07:00
parent c693730ed8
commit fb62ed0044
3 changed files with 11 additions and 11 deletions

View File

@@ -29,7 +29,6 @@ import (
"github.com/evanw/esbuild/internal/logger"
"github.com/evanw/esbuild/internal/resolver"
"github.com/evanw/esbuild/internal/runtime"
"github.com/evanw/esbuild/internal/sourcemap"
"github.com/evanw/esbuild/internal/xxhash"
)
@@ -43,7 +42,6 @@ const (
type file struct {
module graph.Module
sourceMap *sourcemap.SourceMap
pluginData interface{}
// The minimum number of links in the module graph to get from an entry point
@@ -486,7 +484,7 @@ func parseFile(args parseArgs) {
if repr, ok := result.file.module.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.sourceMap = js_parser.ParseSourceMap(args.log, logger.Source{
result.file.module.InputSourceMap = js_parser.ParseSourceMap(args.log, logger.Source{
KeyPath: path,
PrettyPath: args.res.PrettyPath(path),
Contents: *contents,
@@ -2042,7 +2040,7 @@ func (b *Bundle) computeDataForSourceMapsInParallel(options *config.Options, rea
go func(sourceIndex uint32, f *file, repr *graph.JSRepr) {
result := &results[sourceIndex]
result.lineOffsetTables = js_printer.GenerateLineOffsetTables(f.module.Source.Contents, repr.AST.ApproximateLineCount)
sm := f.sourceMap
sm := f.module.InputSourceMap
if !options.ExcludeSourcesContent {
if sm == nil {
// Simple case: no nested source map

View File

@@ -3633,7 +3633,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
var lineOffsetTables []js_printer.LineOffsetTable
if file.module.Loader.CanHaveSourceMap() && c.options.SourceMap != config.SourceMapNone {
addSourceMappings = true
inputSourceMap = file.sourceMap
inputSourceMap = file.module.InputSourceMap
lineOffsetTables = dataForSourceMaps[partRange.sourceIndex].lineOffsetTables
}
@@ -5041,7 +5041,7 @@ func (c *linkerContext) generateSourceMapForChunk(
file := &c.files[result.sourceIndex]
// Simple case: no nested source map
if file.sourceMap == nil {
if file.module.InputSourceMap == nil {
var quotedContents []byte
if !c.options.ExcludeSourcesContent {
quotedContents = dataForSourceMaps[result.sourceIndex].quotedContents[0]
@@ -5056,7 +5056,7 @@ func (c *linkerContext) generateSourceMapForChunk(
}
// Complex case: nested source map
sm := file.sourceMap
sm := file.module.InputSourceMap
for i, source := range sm.Sources {
path := logger.Path{
Namespace: file.module.Source.KeyPath.Namespace,

View File

@@ -7,13 +7,15 @@ import (
"github.com/evanw/esbuild/internal/js_ast"
"github.com/evanw/esbuild/internal/logger"
"github.com/evanw/esbuild/internal/resolver"
"github.com/evanw/esbuild/internal/sourcemap"
)
type Module struct {
Source logger.Source
Repr ModuleRepr
Loader config.Loader
SideEffects SideEffects
Source logger.Source
Repr ModuleRepr
Loader config.Loader
SideEffects SideEffects
InputSourceMap *sourcemap.SourceMap
// If this file ends up being used in the bundle, these are additional files
// that must be written to the output directory. It's used by the "file"