From a023eb6e95f1aaba8967a3b48c7f35c34f650f35 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:37:20 +0000 Subject: [PATCH] Format code with gofmt and gofumpt This commit fixes the style issues introduced in d70c3d0 according to the output from gofmt and gofumpt. Details: https://deepsource.io/gh/QuackatronHQ/esbuild/transform/192c2838-6a94-42b8-a606-b23f169fa54c/ --- cmd/esbuild/service.go | 12 +++--- internal/bundler/bundler_test.go | 14 ++++--- internal/bundler/linker.go | 38 +++++++++++------ internal/config/config.go | 6 ++- internal/config/globals.go | 6 ++- internal/css_ast/css_decl_table.go | 6 ++- internal/css_parser/css_decls_color.go | 27 ++++++++----- internal/css_parser/css_parser.go | 6 ++- internal/fs/iswin_wasm.go | 6 ++- internal/js_ast/js_ast.go | 14 ++++--- internal/js_lexer/js_lexer.go | 8 ++-- internal/js_parser/js_parser.go | 56 +++++++++++++++----------- internal/js_parser/js_parser_lower.go | 12 ++++-- internal/js_parser/ts_parser_test.go | 5 +-- internal/js_printer/js_printer.go | 24 ++++++----- internal/logger/logger.go | 6 ++- internal/logger/logger_windows.go | 10 +++-- internal/resolver/resolver.go | 6 ++- internal/sourcemap/sourcemap.go | 2 +- pkg/api/api_impl.go | 1 - 20 files changed, 164 insertions(+), 101 deletions(-) diff --git a/cmd/esbuild/service.go b/cmd/esbuild/service.go index 3b646985805..bde6800c6e2 100644 --- a/cmd/esbuild/service.go +++ b/cmd/esbuild/service.go @@ -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 diff --git a/internal/bundler/bundler_test.go b/internal/bundler/bundler_test.go index ae8fc6b8bcc..4492dab3928 100644 --- a/internal/bundler/bundler_test.go +++ b/internal/bundler/bundler_test.go @@ -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() diff --git a/internal/bundler/linker.go b/internal/bundler/linker.go index ec6b691fa4f..2e4fce49f1d 100644 --- a/internal/bundler/linker.go +++ b/internal/bundler/linker.go @@ -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 } } @@ -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 } } @@ -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}}, + }}}, + }) } } @@ -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 { @@ -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}, + }}}, + }, + }) } } diff --git a/internal/config/config.go b/internal/config/config.go index 28d7fe5ac38..574845b8a32 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 == "" { diff --git a/internal/config/globals.go b/internal/config/globals.go index de798d29ca7..619df59c57f 100644 --- a/internal/config/globals.go +++ b/internal/config/globals.go @@ -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 diff --git a/internal/css_ast/css_decl_table.go b/internal/css_ast/css_decl_table.go index 177b6873f71..edb33c30dc2 100644 --- a/internal/css_ast/css_decl_table.go +++ b/internal/css_ast/css_decl_table.go @@ -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 diff --git a/internal/css_parser/css_decls_color.go b/internal/css_parser/css_decls_color.go index e1402cf4e9c..fa197141bf6 100644 --- a/internal/css_parser/css_decls_color.go +++ b/internal/css_parser/css_decls_color.go @@ -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)}, } } @@ -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)}, } } @@ -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}, } } diff --git a/internal/css_parser/css_parser.go b/internal/css_parser/css_parser.go index 6a560770d2a..aac01f35a4a 100644 --- a/internal/css_parser/css_parser.go +++ b/internal/css_parser/css_parser.go @@ -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)}}, + }) } } diff --git a/internal/fs/iswin_wasm.go b/internal/fs/iswin_wasm.go index b44a60e06dc..abfc53e438e 100644 --- a/internal/fs/iswin_wasm.go +++ b/internal/fs/iswin_wasm.go @@ -7,8 +7,10 @@ import ( "os" ) -var checkedIfWindows bool -var cachedIfWindows bool +var ( + checkedIfWindows bool + cachedIfWindows bool +) func CheckIfWindows() bool { if !checkedIfWindows { diff --git a/internal/js_ast/js_ast.go b/internal/js_ast/js_ast.go index 362f6367306..992c0453da2 100644 --- a/internal/js_ast/js_ast.go +++ b/internal/js_ast/js_ast.go @@ -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 diff --git a/internal/js_lexer/js_lexer.go b/internal/js_lexer/js_lexer.go index f86fe0fd99e..6bc1e2b6ee9 100644 --- a/internal/js_lexer/js_lexer.go +++ b/internal/js_lexer/js_lexer.go @@ -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 diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index e7aa849b2f5..31df37819e8 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -1269,7 +1269,6 @@ func (p *parser) declareSymbol(kind js_ast.SymbolKind, loc logger.Loc, name stri // Overwrite this name in the declaring scope p.currentScope.Members[name] = js_ast.ScopeMember{Ref: ref, Loc: loc} return ref - } func (p *parser) hoistSymbols(scope *js_ast.Scope) { @@ -2444,7 +2443,8 @@ func (p *parser) parseAsyncPrefixExpr(asyncRange logger.Range, level js_ast.L, f case js_lexer.TEqualsGreaterThan: if level <= js_ast.LAssign { arg := js_ast.Arg{Binding: js_ast.Binding{Loc: asyncRange.Loc, Data: &js_ast.BIdentifier{ - Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"})}}} + Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"}), + }}} p.pushScopeForParsePass(js_ast.ScopeFunctionArgs, asyncRange.Loc) defer p.popScope() @@ -2508,7 +2508,8 @@ func (p *parser) parseAsyncPrefixExpr(asyncRange logger.Range, level js_ast.L, f // "async" // "async + 1" return js_ast.Expr{Loc: asyncRange.Loc, Data: &js_ast.EIdentifier{ - Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"})}} + Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"}), + }} } func (p *parser) parseFnExpr(loc logger.Loc, isAsync bool, asyncRange logger.Range) js_ast.Expr { @@ -2735,7 +2736,8 @@ func (p *parser) parseParenExpr(loc logger.Loc, level js_ast.L, opts parenExprOp if isAsync { p.logExprErrors(&errors) async := js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{ - Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"})}} + Ref: p.storeNameInRef(js_lexer.MaybeSubstring{String: "async"}), + }} return js_ast.Expr{Loc: loc, Data: &js_ast.ECall{ Target: async, Args: items, @@ -3411,7 +3413,8 @@ func (p *parser) parsePrefix(level js_ast.L, errors *deferredErrors, flags exprF how = " You can use 'Loader: map[string]api.Loader{\".js\": api.LoaderJSX}' to do that." } p.log.AddErrorWithNotes(&p.tracker, p.lexer.Range(), "The JSX syntax extension is not currently enabled", []logger.MsgData{{ - Text: "The esbuild loader for this file is currently set to \"js\" but it must be set to \"jsx\" to be able to parse JSX syntax." + how}}) + Text: "The esbuild loader for this file is currently set to \"js\" but it must be set to \"jsx\" to be able to parse JSX syntax." + how, + }}) p.options.jsx.Parse = true } @@ -5987,7 +5990,8 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt { expr := p.parseSuffix(p.parseAsyncPrefixExpr(asyncRange, js_ast.LComma, 0), js_ast.LComma, nil, 0) p.lexer.ExpectOrInsertSemicolon() return js_ast.Stmt{Loc: loc, Data: &js_ast.SExportDefault{ - DefaultName: defaultName, Value: js_ast.Stmt{Loc: loc, Data: &js_ast.SExpr{Value: expr}}}} + DefaultName: defaultName, Value: js_ast.Stmt{Loc: loc, Data: &js_ast.SExpr{Value: expr}}, + }} } if p.lexer.Token == js_lexer.TFunction || p.lexer.Token == js_lexer.TClass || p.lexer.IsContextualKeyword("interface") { @@ -6049,7 +6053,8 @@ func (p *parser) parseStmt(opts parseStmtOpts) js_ast.Stmt { p.lexer.ExpectOrInsertSemicolon() defaultName := createDefaultName() return js_ast.Stmt{Loc: loc, Data: &js_ast.SExportDefault{ - DefaultName: defaultName, Value: js_ast.Stmt{Loc: loc, Data: &js_ast.SExpr{Value: expr}}}} + DefaultName: defaultName, Value: js_ast.Stmt{Loc: loc, Data: &js_ast.SExpr{Value: expr}}, + }} case js_lexer.TAsterisk: if !opts.isModuleScope && (!opts.isNamespaceScope || !opts.isTypeScriptDeclare) { @@ -7520,7 +7525,8 @@ func (p *parser) visitStmts(stmts []js_ast.Stmt, kind stmtsKind) []js_ast.Stmt { index = len(letDecls) fnStmts[s.Fn.Name.Ref] = index letDecls = append(letDecls, js_ast.Decl{Binding: js_ast.Binding{ - Loc: s.Fn.Name.Loc, Data: &js_ast.BIdentifier{Ref: s.Fn.Name.Ref}}}) + Loc: s.Fn.Name.Loc, Data: &js_ast.BIdentifier{Ref: s.Fn.Name.Ref}, + }}) // Also write the function to the hoisted sibling symbol if applicable if hoistedRef, ok := p.hoistedRefForSloppyModeBlockFn[s.Fn.Name.Ref]; ok { @@ -7840,8 +7846,10 @@ func (p *parser) mangleStmts(stmts []js_ast.Stmt, kind stmtsKind) []js_ast.Stmt if len(result) > 0 && s.ValueOrNil.Data != nil { prevStmt := result[len(result)-1] if prevS, ok := prevStmt.Data.(*js_ast.SExpr); ok { - result[len(result)-1] = js_ast.Stmt{Loc: prevStmt.Loc, - Data: &js_ast.SReturn{ValueOrNil: js_ast.JoinWithComma(prevS.Value, s.ValueOrNil)}} + result[len(result)-1] = js_ast.Stmt{ + Loc: prevStmt.Loc, + Data: &js_ast.SReturn{ValueOrNil: js_ast.JoinWithComma(prevS.Value, s.ValueOrNil)}, + } continue } } @@ -8956,7 +8964,8 @@ func (p *parser) maybeKeepExprSymbolName(value js_ast.Expr, name string, wasAnon } func (p *parser) keepExprSymbolName(value js_ast.Expr, name string) js_ast.Expr { - value = p.callRuntime(value.Loc, "__name", []js_ast.Expr{value, + value = p.callRuntime(value.Loc, "__name", []js_ast.Expr{ + value, {Loc: value.Loc, Data: &js_ast.EString{Value: helpers.StringToUTF16(name)}}, }) @@ -11744,7 +11753,8 @@ pattern: p.log.AddIDWithNotes(logger.MsgID_JS_UnsupportedRegExp, logger.Debug, &p.tracker, r, fmt.Sprintf("%s in %s", what, where), append(notes, logger.MsgData{ Text: "This regular expression literal has been converted to a \"new RegExp()\" constructor " + "to avoid generating code with a syntax error. However, you will need to include a " + - "polyfill for \"RegExp\" for your code to have the correct behavior at run-time."})) + "polyfill for \"RegExp\" for your code to have the correct behavior at run-time.", + })) } return @@ -15266,8 +15276,10 @@ func newParser(log logger.Log, source logger.Source, lexer js_lexer.Lexer, optio return p } -var defaultJSXFactory = []string{"React", "createElement"} -var defaultJSXFragment = []string{"React", "Fragment"} +var ( + defaultJSXFactory = []string{"React", "createElement"} + defaultJSXFragment = []string{"React", "Fragment"} +) func Parse(log logger.Log, source logger.Source, options Options) (result js_ast.AST, ok bool) { ok = true @@ -15371,7 +15383,7 @@ func Parse(log logger.Log, source logger.Source, options Options) (result js_ast CanBeRemovedIfUnused: true, } - var before = []js_ast.Part{nsExportPart} + before := []js_ast.Part{nsExportPart} var parts []js_ast.Part var after []js_ast.Part @@ -15612,14 +15624,12 @@ func (p *parser) prepareForVisitPass() { } // Determine whether or not this file is ESM - p.isFileConsideredToHaveESMExports = - p.esmExportKeyword.Len > 0 || - p.esmImportMeta.Len > 0 || - p.topLevelAwaitKeyword.Len > 0 || - p.options.moduleTypeData.Type.IsESM() - p.isFileConsideredESM = - p.isFileConsideredToHaveESMExports || - p.esmImportStatementKeyword.Len > 0 + p.isFileConsideredToHaveESMExports = p.esmExportKeyword.Len > 0 || + p.esmImportMeta.Len > 0 || + p.topLevelAwaitKeyword.Len > 0 || + p.options.moduleTypeData.Type.IsESM() + p.isFileConsideredESM = p.isFileConsideredToHaveESMExports || + p.esmImportStatementKeyword.Len > 0 // Legacy HTML comments are not allowed in ESM files if p.isFileConsideredESM && p.lexer.LegacyHTMLCommentRange.Len > 0 { diff --git a/internal/js_parser/js_parser_lower.go b/internal/js_parser/js_parser_lower.go index e3ea2d34162..3424d942d5d 100644 --- a/internal/js_parser/js_parser_lower.go +++ b/internal/js_parser/js_parser_lower.go @@ -327,8 +327,10 @@ func (p *parser) lowerFunction( (*args)[i].Binding.Data = &js_ast.BIdentifier{Ref: ref} // Append a variable declaration to the function body - prefixStmts = append(prefixStmts, js_ast.Stmt{Loc: arg.Binding.Loc, - Data: &js_ast.SLocal{Kind: js_ast.LocalVar, Decls: decls}}) + prefixStmts = append(prefixStmts, js_ast.Stmt{ + Loc: arg.Binding.Loc, + Data: &js_ast.SLocal{Kind: js_ast.LocalVar, Decls: decls}, + }) } } } @@ -1515,8 +1517,10 @@ func (p *parser) lowerObjectRestHelper( for i, capturedKey := range capturedKeys { keysToExclude[i] = capturedKey() } - assign(binding, p.callRuntime(binding.Loc, "__objRest", []js_ast.Expr{init, - {Loc: binding.Loc, Data: &js_ast.EArray{Items: keysToExclude, IsSingleLine: isSingleLine}}})) + assign(binding, p.callRuntime(binding.Loc, "__objRest", []js_ast.Expr{ + init, + {Loc: binding.Loc, Data: &js_ast.EArray{Items: keysToExclude, IsSingleLine: isSingleLine}}, + })) } splitArrayPattern := func( diff --git a/internal/js_parser/ts_parser_test.go b/internal/js_parser/ts_parser_test.go index 079f949aa7f..29a89c54f12 100644 --- a/internal/js_parser/ts_parser_test.go +++ b/internal/js_parser/ts_parser_test.go @@ -442,9 +442,8 @@ func TestTSClass(t *testing.T) { expectPrintedTS(t, "class A implements B.C, F.G {}", "class A {\n}\n") expectPrintedTS(t, "class A extends X implements B.C, F.G {}", "class A extends X {\n}\n") - reservedWordError := - " is a reserved word and cannot be used in strict mode\n" + - ": NOTE: All code inside a class is implicitly in strict mode\n" + reservedWordError := " is a reserved word and cannot be used in strict mode\n" + + ": NOTE: All code inside a class is implicitly in strict mode\n" expectParseErrorTS(t, "class Foo { constructor(public) {} }", ": ERROR: \"public\""+reservedWordError) expectParseErrorTS(t, "class Foo { constructor(protected) {} }", ": ERROR: \"protected\""+reservedWordError) diff --git a/internal/js_printer/js_printer.go b/internal/js_printer/js_printer.go index c28d1be42ce..e2083dcbb6f 100644 --- a/internal/js_printer/js_printer.go +++ b/internal/js_printer/js_printer.go @@ -19,16 +19,20 @@ import ( "github.com/evanw/esbuild/internal/sourcemap" ) -var positiveInfinity = math.Inf(1) -var negativeInfinity = math.Inf(-1) - -const hexChars = "0123456789ABCDEF" -const firstASCII = 0x20 -const lastASCII = 0x7E -const firstHighSurrogate = 0xD800 -const lastHighSurrogate = 0xDBFF -const firstLowSurrogate = 0xDC00 -const lastLowSurrogate = 0xDFFF +var ( + positiveInfinity = math.Inf(1) + negativeInfinity = math.Inf(-1) +) + +const ( + hexChars = "0123456789ABCDEF" + firstASCII = 0x20 + lastASCII = 0x7E + firstHighSurrogate = 0xD800 + lastHighSurrogate = 0xDBFF + firstLowSurrogate = 0xDC00 + lastLowSurrogate = 0xDFFF +) func canPrintWithoutEscape(c rune, asciiOnly bool) bool { if c <= lastASCII { diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 92d86fe9b9c..a86c4fc5ca8 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -256,8 +256,10 @@ func (a Path) ComesBeforeInSortedOrder(b Path) bool { (a.Flags == b.Flags && a.IgnoredSuffix < b.IgnoredSuffix))))) } -var noColorResult bool -var noColorOnce sync.Once +var ( + noColorResult bool + noColorOnce sync.Once +) func hasNoColorEnvironmentVariable() bool { noColorOnce.Do(func() { diff --git a/internal/logger/logger_windows.go b/internal/logger/logger_windows.go index f2383ff87e1..ab6cefc8077 100644 --- a/internal/logger/logger_windows.go +++ b/internal/logger/logger_windows.go @@ -12,10 +12,12 @@ import ( const SupportsColorEscapes = true -var kernel32 = syscall.NewLazyDLL("kernel32.dll") -var getConsoleMode = kernel32.NewProc("GetConsoleMode") -var setConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") -var getConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + getConsoleMode = kernel32.NewProc("GetConsoleMode") + setConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") + getConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") +) type consoleScreenBufferInfo struct { dwSizeX int16 diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index cfbf9490f74..1fe5a7edb62 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -883,8 +883,10 @@ func (r resolverQuery) dirInfoCached(path string) *dirInfo { return cached } -var errParseErrorImportCycle = errors.New("(import cycle)") -var errParseErrorAlreadyLogged = errors.New("(error already logged)") +var ( + errParseErrorImportCycle = errors.New("(import cycle)") + errParseErrorAlreadyLogged = errors.New("(error already logged)") +) // This may return "parseErrorAlreadyLogged" in which case there was a syntax // error, but it's already been reported. No further errors should be logged. diff --git a/internal/sourcemap/sourcemap.go b/internal/sourcemap/sourcemap.go index d0c3f8ace9a..6d37c8912b0 100644 --- a/internal/sourcemap/sourcemap.go +++ b/internal/sourcemap/sourcemap.go @@ -175,7 +175,7 @@ func DecodeVLQUTF16(encoded []uint16) (int, int, bool) { } // Recover the value - var value = vlq >> 1 + value := vlq >> 1 if (vlq & 1) != 0 { value = -value } diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index b282fd2edc1..be5cb7df7b0 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -1551,7 +1551,6 @@ func (impl *pluginImpl) onStart(callback func() (OnStartResult, error)) { Name: impl.plugin.Name, Callback: func() (result config.OnStartResult) { response, err := callback() - if err != nil { result.ThrownError = err return