-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ast.go
71 lines (51 loc) · 1.94 KB
/
ast.go
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
package ast
import "github.com/evanw/esbuild/internal/logger"
// This file contains data structures that are used with the AST packages for
// both JavaScript and CSS. This helps the bundler treat both AST formats in
// a somewhat format-agnostic manner.
type ImportKind uint8
const (
// An ES6 import or re-export statement
ImportStmt ImportKind = iota
// A call to "require()"
ImportRequire
// An "import()" expression with a string argument
ImportDynamic
// A call to "require.resolve()"
ImportRequireResolve
// A CSS "@import" rule
ImportAt
// A CSS "url(...)" token
ImportURL
// An entry point provided by the user
ImportEntryPoint
)
func (kind ImportKind) IsFromCSS() bool {
return kind == ImportAt || kind == ImportURL
}
type ImportRecord struct {
Range logger.Range
Path logger.Path
// The resolved source index for an internal import (within the bundle) or
// nil for an external import (not included in the bundle)
SourceIndex *uint32
// Sometimes the parser creates an import record and decides it isn't needed.
// For example, TypeScript code may have import statements that later turn
// out to be type-only imports after analyzing the whole file.
IsUnused bool
// If this is true, the import contains syntax like "* as ns". This is used
// to determine whether modules that have no exports need to be wrapped in a
// CommonJS wrapper or not.
ContainsImportStar bool
// If true, this "export * from 'path'" statement is evaluated at run-time by
// calling the "__exportStar()" helper function
CallsRunTimeExportStarFn bool
// Tell the printer to wrap this call to "require()" in "__toModule(...)"
WrapWithToModule bool
// True for require calls like this: "try { require() } catch {}". In this
// case we shouldn't generate an error if the path could not be resolved.
IsInsideTryBody bool
// If true, this was originally written as a bare "import 'file'" statement
WasOriginallyBareImport bool
Kind ImportKind
}