Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cmd/esbuild/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import (
"github.com/evanw/esbuild/pkg/cli"
)

type responseCallback func(interface{})
type rebuildCallback func(uint32) []byte
type watchStopCallback func()
type serveStopCallback func()
type pluginResolveCallback func(uint32, map[string]interface{}) []byte
type (
responseCallback func(interface{})
rebuildCallback func(uint32) []byte
watchStopCallback func()
serveStopCallback func()
pluginResolveCallback func(uint32, map[string]interface{}) []byte
)

type activeBuild struct {
rebuild rebuildCallback
Expand Down
14 changes: 9 additions & 5 deletions internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ func (s *suite) expectBundled(t *testing.T, args bundled) {
})
}

const snapshotsDir = "snapshots"
const snapshotSplitter = "\n================================================================================\n"
const (
snapshotsDir = "snapshots"
snapshotSplitter = "\n================================================================================\n"
)

var globalTestMutex sync.Mutex
var globalSuites map[*suite]bool
var globalUpdateSnapshots bool
var (
globalTestMutex sync.Mutex
globalSuites map[*suite]bool
globalUpdateSnapshots bool
)

func (s *suite) compareSnapshot(t *testing.T, testName string, generated string) {
t.Helper()
Expand Down
38 changes: 25 additions & 13 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,7 @@ func (c *linkerContext) computeCrossChunkDependencies(chunks []chunkInfo) {
// Ignore uses that aren't top-level symbols
if otherChunkIndex := c.graph.Symbols.Get(importRef).ChunkIndex; otherChunkIndex.IsValid() {
if otherChunkIndex := otherChunkIndex.GetIndex(); otherChunkIndex != uint32(chunkIndex) {
chunkRepr.importsFromOtherChunks[otherChunkIndex] =
append(chunkRepr.importsFromOtherChunks[otherChunkIndex], crossChunkImportItem{ref: importRef})
chunkRepr.importsFromOtherChunks[otherChunkIndex] = append(chunkRepr.importsFromOtherChunks[otherChunkIndex], crossChunkImportItem{ref: importRef})
chunkMetas[otherChunkIndex].exports[importRef] = true
}
}
Expand Down Expand Up @@ -2644,12 +2643,11 @@ func (c *linkerContext) addExportsForExportStar(
}
} else if existing.SourceIndex != otherSourceIndex {
// Two different re-exports colliding makes it potentially ambiguous
existing.PotentiallyAmbiguousExportStarRefs =
append(existing.PotentiallyAmbiguousExportStarRefs, graph.ImportData{
SourceIndex: otherSourceIndex,
Ref: name.Ref,
NameLoc: name.AliasLoc,
})
existing.PotentiallyAmbiguousExportStarRefs = append(existing.PotentiallyAmbiguousExportStarRefs, graph.ImportData{
SourceIndex: otherSourceIndex,
Ref: name.Ref,
NameLoc: name.AliasLoc,
})
resolvedExports[alias] = existing
}
}
Expand Down Expand Up @@ -3657,9 +3655,12 @@ func (c *linkerContext) convertStmtsForChunk(sourceIndex uint32, stmtList *stmtL
} else {
if record.SourceIndex.IsValid() {
if otherRepr := c.graph.Files[record.SourceIndex.GetIndex()].InputFile.Repr.(*graph.JSRepr); otherRepr.Meta.Wrap == graph.WrapESM {
stmtList.insideWrapperPrefix = append(stmtList.insideWrapperPrefix, js_ast.Stmt{Loc: stmt.Loc,
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}}}}}})
Target: js_ast.Expr{Loc: stmt.Loc, Data: &js_ast.EIdentifier{Ref: otherRepr.AST.WrapperRef}},
}}},
})
}
}

Expand Down Expand Up @@ -4349,7 +4350,11 @@ func (c *linkerContext) generateEntryPointTailJS(
Data: &js_ast.SExportDefault{Value: js_ast.Stmt{
Data: &js_ast.SExpr{Value: js_ast.Expr{
Data: &js_ast.ECall{Target: js_ast.Expr{
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef}}}}}}}})
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef},
}},
}},
}},
})
} else {
if repr.Meta.Wrap == graph.WrapESM {
if repr.Meta.IsAsyncOrHasAsyncDependency {
Expand All @@ -4358,13 +4363,20 @@ func (c *linkerContext) generateEntryPointTailJS(
Data: &js_ast.SExpr{Value: js_ast.Expr{
Data: &js_ast.EAwait{Value: js_ast.Expr{
Data: &js_ast.ECall{Target: js_ast.Expr{
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef}}}}}}}})
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef},
}},
}},
}},
})
} else {
// "init_foo();"
stmts = append(stmts, js_ast.Stmt{
Data: &js_ast.SExpr{
Value: js_ast.Expr{Data: &js_ast.ECall{Target: js_ast.Expr{
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef}}}}}})
Data: &js_ast.EIdentifier{Ref: repr.AST.WrapperRef},
}}},
},
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,10 @@ type InjectableExport struct {
Loc logger.Loc
}

var filterMutex sync.Mutex
var filterCache map[string]*regexp.Regexp
var (
filterMutex sync.Mutex
filterCache map[string]*regexp.Regexp
)

func compileFilter(filter string) (result *regexp.Regexp) {
if filter == "" {
Expand Down
6 changes: 4 additions & 2 deletions internal/config/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/evanw/esbuild/internal/js_ast"
)

var processedGlobalsMutex sync.Mutex
var processedGlobals *ProcessedDefines
var (
processedGlobalsMutex sync.Mutex
processedGlobals *ProcessedDefines
)

// If something is in this list, then a direct identifier expression or property
// access chain matching this will be assumed to have no side effects and will
Expand Down
6 changes: 4 additions & 2 deletions internal/css_ast/css_decl_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,10 @@ var KnownDeclarations = map[string]D{
"zoom": DZoom,
}

var typoDetector *helpers.TypoDetector
var typoDetectorMutex sync.Mutex
var (
typoDetector *helpers.TypoDetector
typoDetectorMutex sync.Mutex
)

func MaybeCorrectDeclarationTypo(text string) (string, bool) {
// Ignore CSS variables, which should not be corrected to CSS properties
Expand Down
27 changes: 18 additions & 9 deletions internal/css_parser/css_decls_color.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,12 @@ func (p *parser) lowerColor(token css_ast.Token) css_ast.Token {
token.Text = "rgba"
commaToken := p.commaToken()
token.Children = &[]css_ast.Token{
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: floatToStringForColor(float64(hexA(hex)) / 255)},
}
}
Expand All @@ -305,9 +308,12 @@ func (p *parser) lowerColor(token css_ast.Token) css_ast.Token {
token.Text = "rgba"
commaToken := p.commaToken()
token.Children = &[]css_ast.Token{
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: floatToStringForColor(float64(hexA(hex)) / 255)},
}
}
Expand Down Expand Up @@ -639,9 +645,12 @@ func (p *parser) mangleColor(token css_ast.Token, hex uint32) css_ast.Token {
alpha = alpha[:space]
}
token.Children = &[]css_ast.Token{
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))}, commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexR(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexG(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: strconv.Itoa(hexB(hex))},
commaToken,
{Kind: css_lexer.TNumber, Text: alpha},
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/css_parser/css_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1636,8 +1636,10 @@ stop:
if corrected, ok := css_ast.MaybeCorrectDeclarationTypo(keyText); ok {
data := p.tracker.MsgData(keyToken.Range, fmt.Sprintf("%q is not a known CSS property", keyText))
data.Location.Suggestion = corrected
p.log.AddMsgID(logger.MsgID_CSS_UnsupportedCSSProperty, logger.Msg{Kind: logger.Warning, Data: data,
Notes: []logger.MsgData{{Text: fmt.Sprintf("Did you mean %q instead?", corrected)}}})
p.log.AddMsgID(logger.MsgID_CSS_UnsupportedCSSProperty, logger.Msg{
Kind: logger.Warning, Data: data,
Notes: []logger.MsgData{{Text: fmt.Sprintf("Did you mean %q instead?", corrected)}},
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/fs/iswin_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"os"
)

var checkedIfWindows bool
var cachedIfWindows bool
var (
checkedIfWindows bool
cachedIfWindows bool
)

func CheckIfWindows() bool {
if !checkedIfWindows {
Expand Down
14 changes: 8 additions & 6 deletions internal/js_ast/js_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,14 @@ type EImportMeta struct {
}

// These help reduce unnecessary memory allocations
var BMissingShared = &BMissing{}
var EMissingShared = &EMissing{}
var ESuperShared = &ESuper{}
var ENullShared = &ENull{}
var EUndefinedShared = &EUndefined{}
var EThisShared = &EThis{}
var (
BMissingShared = &BMissing{}
EMissingShared = &EMissing{}
ESuperShared = &ESuper{}
ENullShared = &ENull{}
EUndefinedShared = &EUndefined{}
EThisShared = &EThis{}
)

type ENew struct {
Target Expr
Expand Down
8 changes: 5 additions & 3 deletions internal/js_lexer/js_lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,11 @@ func (lexer *Lexer) NextJSXElementChild() {
} else {
replacement = "{'>'}"
}
msg := logger.Msg{Kind: logger.Error, Data: lexer.tracker.MsgData(logger.Range{Loc: logger.Loc{Start: int32(lexer.end)}, Len: 1},
fmt.Sprintf("The character \"%c\" is not valid inside a JSX element", lexer.codePoint)),
Notes: []logger.MsgData{{Text: fmt.Sprintf("Did you mean to escape it as %q instead?", replacement)}}}
msg := logger.Msg{
Kind: logger.Error, Data: lexer.tracker.MsgData(logger.Range{Loc: logger.Loc{Start: int32(lexer.end)}, Len: 1},
fmt.Sprintf("The character \"%c\" is not valid inside a JSX element", lexer.codePoint)),
Notes: []logger.MsgData{{Text: fmt.Sprintf("Did you mean to escape it as %q instead?", replacement)}},
}
msg.Data.Location.Suggestion = replacement
if !lexer.ts.Parse {
// TypeScript treats this as an error but Babel doesn't treat this
Expand Down
Loading