1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
package graph
// The code in this file mainly represents data that passes from the scan phase
// to the compile phase of the bundler. There is currently one exception: the
// "meta" member of the JavaScript file representation. That could have been
// stored separately but is stored together for convenience and to avoid an
// extra level of indirection. Instead it's kept in a separate type to keep
// things organized.
import (
"github.com/evanw/esbuild/internal/ast"
"github.com/evanw/esbuild/internal/config"
"github.com/evanw/esbuild/internal/css_ast"
"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 InputFile struct {
Repr InputFileRepr
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" and
// "copy" loaders.
AdditionalFiles []OutputFile
UniqueKeyForAdditionalFile string
SideEffects SideEffects
Source logger.Source
Loader config.Loader
OmitFromSourceMapsAndMetafile bool
}
type OutputFile struct {
// If "AbsMetadataFile" is present, this will be filled out with information
// about this file in JSON format. This is a partial JSON file that will be
// fully assembled later.
JSONMetadataChunk string
AbsPath string
Contents []byte
IsExecutable bool
}
type SideEffects struct {
// This is optional additional information for use in error messages
Data *resolver.SideEffectsData
Kind SideEffectsKind
}
type SideEffectsKind uint8
const (
// The default value conservatively considers all files to have side effects.
HasSideEffects SideEffectsKind = iota
// This file was listed as not having side effects by a "package.json"
// file in one of our containing directories with a "sideEffects" field.
NoSideEffects_PackageJSON
// This file is considered to have no side effects because the AST was empty
// after parsing finished. This should be the case for ".d.ts" files.
NoSideEffects_EmptyAST
// This file was loaded using a data-oriented loader (e.g. "text") that is
// known to not have side effects.
NoSideEffects_PureData
// Same as above but it came from a plugin. We don't want to warn about
// unused imports to these files since running the plugin is a side effect.
// Removing the import would not call the plugin which is observable.
NoSideEffects_PureData_FromPlugin
)
type InputFileRepr interface {
ImportRecords() *[]ast.ImportRecord
}
type JSRepr struct {
Meta JSReprMeta
AST js_ast.AST
// If present, this is the CSS file that this JavaScript stub corresponds to.
// A JavaScript stub is automatically generated for a CSS file when it's
// imported from a JavaScript file.
CSSSourceIndex ast.Index32
}
func (repr *JSRepr) ImportRecords() *[]ast.ImportRecord {
return &repr.AST.ImportRecords
}
func (repr *JSRepr) TopLevelSymbolToParts(ref ast.Ref) []uint32 {
// Overlay the mutable map from the linker
if parts, ok := repr.Meta.TopLevelSymbolToPartsOverlay[ref]; ok {
return parts
}
// Fall back to the immutable map from the parser
return repr.AST.TopLevelSymbolToPartsFromParser[ref]
}
type CSSRepr struct {
AST css_ast.AST
// If present, this is the JavaScript stub corresponding to this CSS file.
// A JavaScript stub is automatically generated for a CSS file when it's
// imported from a JavaScript file.
JSSourceIndex ast.Index32
}
func (repr *CSSRepr) ImportRecords() *[]ast.ImportRecord {
return &repr.AST.ImportRecords
}
type CopyRepr struct {
// The URL that replaces the contents of any import record paths for this file
URLForCode string
}
func (repr *CopyRepr) ImportRecords() *[]ast.ImportRecord {
return nil
}
|