From af0ab3e2a73b1dde8b1fde132e3545fc2004eef1 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Tue, 2 Aug 2022 16:03:09 -0400 Subject: [PATCH] run the new go formatter, which mangles comments --- internal/bundler/bundler_default_test.go | 9 ++- internal/bundler/bundler_ts_test.go | 7 +- internal/bundler/linker.go | 20 +++--- internal/cache/cache.go | 35 +++++----- internal/config/config.go | 33 +++++----- internal/css_parser/css_decls_box.go | 15 ++--- internal/css_parser/css_parser.go | 18 ++--- internal/fs/filepath.go | 18 ++--- internal/js_ast/js_ast.go | 46 ++++++------- internal/js_parser/js_parser.go | 68 ++++++++++--------- internal/js_parser/js_parser_lower.go | 20 +++--- internal/js_parser/ts_parser.go | 17 +++-- internal/resolver/resolver.go | 6 +- internal/sourcemap/sourcemap.go | 11 ++-- pkg/api/api.go | 83 ++++++++++++------------ pkg/cli/cli.go | 54 +++++++-------- 16 files changed, 223 insertions(+), 237 deletions(-) diff --git a/internal/bundler/bundler_default_test.go b/internal/bundler/bundler_default_test.go index 465695864a..18f7b461d6 100644 --- a/internal/bundler/bundler_default_test.go +++ b/internal/bundler/bundler_default_test.go @@ -5772,11 +5772,10 @@ func TestToESMWrapperOmission(t *testing.T) { // This is coverage for a past bug in esbuild. We used to generate this, which is wrong: // -// let x = function(foo) { -// var foo2; -// return foo2; -// }; -// +// let x = function(foo) { +// var foo2; +// return foo2; +// }; func TestNamedFunctionExpressionArgumentCollision(t *testing.T) { loader_suite.expectBundled(t, bundled{ files: map[string]string{ diff --git a/internal/bundler/bundler_ts_test.go b/internal/bundler/bundler_ts_test.go index eb4f5ee93b..e1060ffbdf 100644 --- a/internal/bundler/bundler_ts_test.go +++ b/internal/bundler/bundler_ts_test.go @@ -1969,10 +1969,9 @@ func TestTSEnumExportClause(t *testing.T) { // This checks that we don't generate a warning for code that the TypeScript // compiler generates that looks like this: // -// var __rest = (this && this.__rest) || function (s, e) { -// ... -// }; -// +// var __rest = (this && this.__rest) || function (s, e) { +// ... +// }; func TestTSThisIsUndefinedWarning(t *testing.T) { ts_suite.expectBundled(t, bundled{ files: map[string]string{ diff --git a/internal/bundler/linker.go b/internal/bundler/linker.go index 7ec4cbf750..96f97effa6 100644 --- a/internal/bundler/linker.go +++ b/internal/bundler/linker.go @@ -2974,11 +2974,11 @@ func sanitizeFilePathForVirtualModulePath(path string) string { // order that JavaScript modules were evaluated in before the top-level await // feature was introduced. // -// A -// / \ -// B C -// \ / -// D +// A +// / \ +// B C +// \ / +// D // // If A imports B and then C, B imports D, and C imports D, then the JavaScript // traversal order is D B C A. @@ -3042,11 +3042,11 @@ func (c *linkerContext) findImportedCSSFilesInJSOrder(entryPoint uint32) (order // CSS file multiple times is equivalent to evaluating it once at the last // location. So we drop all but the last evaluation in the order. // -// A -// / \ -// B C -// \ / -// D +// A +// / \ +// B C +// \ / +// D // // If A imports B and then C, B imports D, and C imports D, then the CSS // traversal order is B D C A. diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 000af6be2e..7eacea39ab 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -11,26 +11,25 @@ import ( // able to reuse the results of parsing between builds and make subsequent // builds faster by avoiding redundant parsing work. This only works if: // -// * The AST information in the cache must be considered immutable. There is -// no way to enforce this in Go, but please be disciplined about this. The -// ASTs are shared in between builds. Any information that must be mutated -// in the AST during a build must be done on a shallow clone of the data if -// the mutation happens after parsing (i.e. a clone that clones everything -// that will be mutated and shares only the parts that won't be mutated). +// - The AST information in the cache must be considered immutable. There is +// no way to enforce this in Go, but please be disciplined about this. The +// ASTs are shared in between builds. Any information that must be mutated +// in the AST during a build must be done on a shallow clone of the data if +// the mutation happens after parsing (i.e. a clone that clones everything +// that will be mutated and shares only the parts that won't be mutated). // -// * The information in the cache must not depend at all on the contents of -// any file other than the file being cached. Invalidating an entry in the -// cache does not also invalidate any entries that depend on that file, so -// caching information that depends on other files can result in incorrect -// results due to reusing stale data. For example, do not "bake in" some -// value imported from another file. -// -// * Cached ASTs must only be reused if the parsing options are identical -// between builds. For example, it would be bad if the AST parser depended -// on options inherited from a nearby "package.json" file but those options -// were not part of the cache key. Then the cached AST could incorrectly be -// reused even if the contents of that "package.json" file have changed. +// - The information in the cache must not depend at all on the contents of +// any file other than the file being cached. Invalidating an entry in the +// cache does not also invalidate any entries that depend on that file, so +// caching information that depends on other files can result in incorrect +// results due to reusing stale data. For example, do not "bake in" some +// value imported from another file. // +// - Cached ASTs must only be reused if the parsing options are identical +// between builds. For example, it would be bad if the AST parser depended +// on options inherited from a nearby "package.json" file but those options +// were not part of the cache key. Then the cached AST could incorrectly be +// reused even if the contents of that "package.json" file have changed. type CacheSet struct { FSCache FSCache CSSCache CSSCache diff --git a/internal/config/config.go b/internal/config/config.go index 043313fd97..49e29653dd 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -339,32 +339,31 @@ type UnusedImportFlagsTS uint8 // With !UnusedImportKeepStmt && !UnusedImportKeepValues: // -// "import 'foo'" => "import 'foo'" -// "import * as unused from 'foo'" => "" -// "import { unused } from 'foo'" => "" -// "import { type unused } from 'foo'" => "" +// "import 'foo'" => "import 'foo'" +// "import * as unused from 'foo'" => "" +// "import { unused } from 'foo'" => "" +// "import { type unused } from 'foo'" => "" // // With UnusedImportKeepStmt && !UnusedImportKeepValues: // -// "import 'foo'" => "import 'foo'" -// "import * as unused from 'foo'" => "import 'foo'" -// "import { unused } from 'foo'" => "import 'foo'" -// "import { type unused } from 'foo'" => "import 'foo'" +// "import 'foo'" => "import 'foo'" +// "import * as unused from 'foo'" => "import 'foo'" +// "import { unused } from 'foo'" => "import 'foo'" +// "import { type unused } from 'foo'" => "import 'foo'" // // With !UnusedImportKeepStmt && UnusedImportKeepValues: // -// "import 'foo'" => "import 'foo'" -// "import * as unused from 'foo'" => "import * as unused from 'foo'" -// "import { unused } from 'foo'" => "import { unused } from 'foo'" -// "import { type unused } from 'foo'" => "" +// "import 'foo'" => "import 'foo'" +// "import * as unused from 'foo'" => "import * as unused from 'foo'" +// "import { unused } from 'foo'" => "import { unused } from 'foo'" +// "import { type unused } from 'foo'" => "" // // With UnusedImportKeepStmt && UnusedImportKeepValues: // -// "import 'foo'" => "import 'foo'" -// "import * as unused from 'foo'" => "import * as unused from 'foo'" -// "import { unused } from 'foo'" => "import { unused } from 'foo'" -// "import { type unused } from 'foo'" => "import {} from 'foo'" -// +// "import 'foo'" => "import 'foo'" +// "import * as unused from 'foo'" => "import * as unused from 'foo'" +// "import { unused } from 'foo'" => "import { unused } from 'foo'" +// "import { type unused } from 'foo'" => "import {} from 'foo'" const ( UnusedImportKeepStmt UnusedImportFlagsTS = 1 << iota // "importsNotUsedAsValues" != "remove" UnusedImportKeepValues // "preserveValueImports" == true diff --git a/internal/css_parser/css_decls_box.go b/internal/css_parser/css_decls_box.go index 52587fdff3..75f7afa743 100644 --- a/internal/css_parser/css_decls_box.go +++ b/internal/css_parser/css_decls_box.go @@ -40,15 +40,14 @@ const ( // We want to avoid a situation where the browser treats some of the original // rules as valid and others as invalid. // -// Safe: -// top: 1px; left: 0; bottom: 1px; right: 0; -// top: 1Q; left: 2Q; bottom: 3Q; right: 4Q; -// -// Unsafe: -// top: 1vh; left: 2vw; bottom: 3vh; right: 4vw; -// top: 1Q; left: 2Q; bottom: 3Q; right: 0; -// inset: 1Q 0 0 0; top: 0; +// Safe: +// top: 1px; left: 0; bottom: 1px; right: 0; +// top: 1Q; left: 2Q; bottom: 3Q; right: 4Q; // +// Unsafe: +// top: 1vh; left: 2vw; bottom: 3vh; right: 4vw; +// top: 1Q; left: 2Q; bottom: 3Q; right: 0; +// inset: 1Q 0 0 0; top: 0; type unitSafetyTracker struct { unit string status unitSafetyStatus diff --git a/internal/css_parser/css_parser.go b/internal/css_parser/css_parser.go index 6a560770d2..40016efa47 100644 --- a/internal/css_parser/css_parser.go +++ b/internal/css_parser/css_parser.go @@ -521,17 +521,17 @@ var nonDeprecatedElementsSupportedByIE7 = map[string]bool{ // if any of the selectors are unsafe, since then browsers which don't support // that particular feature would ignore the entire merged qualified rule: // -// Input: -// a { color: red } -// b { color: red } -// input::-moz-placeholder { color: red } +// Input: +// a { color: red } +// b { color: red } +// input::-moz-placeholder { color: red } // -// Valid output: -// a, b { color: red } -// input::-moz-placeholder { color: red } +// Valid output: +// a, b { color: red } +// input::-moz-placeholder { color: red } // -// Invalid output: -// a, b, input::-moz-placeholder { color: red } +// Invalid output: +// a, b, input::-moz-placeholder { color: red } // // This considers IE 7 and above to be a browser that a user could possibly use. // Versions of IE less than 6 are not considered. diff --git a/internal/fs/filepath.go b/internal/fs/filepath.go index ae65991b49..166eca5bf6 100644 --- a/internal/fs/filepath.go +++ b/internal/fs/filepath.go @@ -343,13 +343,13 @@ func (fp goFilepath) fromSlash(path string) string { // by purely lexical processing. It applies the following rules // iteratively until no further processing can be done: // -// 1. Replace multiple Separator elements with a single one. -// 2. Eliminate each . path name element (the current directory). -// 3. Eliminate each inner .. path name element (the parent directory) -// along with the non-.. element that precedes it. -// 4. Eliminate .. elements that begin a rooted path: -// that is, replace "/.." by "/" at the beginning of a path, -// assuming Separator is '/'. +// 1. Replace multiple Separator elements with a single one. +// 2. Eliminate each . path name element (the current directory). +// 3. Eliminate each inner .. path name element (the parent directory) +// along with the non-.. element that precedes it. +// 4. Eliminate .. elements that begin a rooted path: +// that is, replace "/.." by "/" at the beginning of a path, +// assuming Separator is '/'. // // The returned path ends in a slash only if it represents a root directory, // such as "/" on Unix or `C:\` on Windows. @@ -359,8 +359,8 @@ func (fp goFilepath) fromSlash(path string) string { // If the result of this process is an empty string, Clean // returns the string ".". // -// See also Rob Pike, ``Lexical File Names in Plan 9 or -// Getting Dot-Dot Right,'' +// See also Rob Pike, “Lexical File Names in Plan 9 or +// Getting Dot-Dot Right,” // https://9p.io/sys/doc/lexnames.html func (fp goFilepath) clean(path string) string { originalPath := path diff --git a/internal/js_ast/js_ast.go b/internal/js_ast/js_ast.go index 55fc0c233f..b9ede5c66d 100644 --- a/internal/js_ast/js_ast.go +++ b/internal/js_ast/js_ast.go @@ -982,11 +982,11 @@ type SSwitch struct { // This object represents all of these types of import statements: // -// import 'path' -// import {item1, item2} from 'path' -// import * as ns from 'path' -// import defaultItem, {item1, item2} from 'path' -// import defaultItem, * as ns from 'path' +// import 'path' +// import {item1, item2} from 'path' +// import * as ns from 'path' +// import defaultItem, {item1, item2} from 'path' +// import defaultItem, * as ns from 'path' // // Many parts are optional and can be combined in different ways. The only // restriction is that you cannot have both a clause and a star namespace. @@ -1542,27 +1542,27 @@ func (s *Scope) RecursiveSetStrictMode(kind StrictModeKind) { // block are merged into a single namespace while the non-exported code is // still scoped to just within that block: // -// let x = 1; -// namespace Foo { -// let x = 2; -// export let y = 3; -// } -// namespace Foo { -// console.log(x); // 1 -// console.log(y); // 3 -// } +// let x = 1; +// namespace Foo { +// let x = 2; +// export let y = 3; +// } +// namespace Foo { +// console.log(x); // 1 +// console.log(y); // 3 +// } // // Doing this also works inside an enum: // -// enum Foo { -// A = 3, -// B = A + 1, -// } -// enum Foo { -// C = A + 2, -// } -// console.log(Foo.B) // 4 -// console.log(Foo.C) // 5 +// enum Foo { +// A = 3, +// B = A + 1, +// } +// enum Foo { +// C = A + 2, +// } +// console.log(Foo.B) // 4 +// console.log(Foo.C) // 5 // // This is a form of identifier lookup that works differently than the // hierarchical scope-based identifier lookup in JavaScript. Lookup now needs diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index 90b64074f0..9edcdee573 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -24,10 +24,10 @@ import ( // // 1. Parse the source into an AST, create the scope tree, and declare symbols. // -// 2. Visit each node in the AST, bind identifiers to declared symbols, do -// constant folding, substitute compile-time variable definitions, and -// lower certain syntactic constructs as appropriate given the language -// target. +// 2. Visit each node in the AST, bind identifiers to declared symbols, do +// constant folding, substitute compile-time variable definitions, and +// lower certain syntactic constructs as appropriate given the language +// target. // // So many things have been put in so few passes because we want to minimize // the number of full-tree passes to improve performance. However, we need @@ -1707,20 +1707,19 @@ func (p *parser) logDeferredArrowArgErrors(errors *deferredErrors) { // // Specifically, for await: // -// // This is ok -// async function foo() { (x = await y) } +// // This is ok +// async function foo() { (x = await y) } // -// // This is an error -// async function foo() { (x = await y) => {} } +// // This is an error +// async function foo() { (x = await y) => {} } // // And for yield: // -// // This is ok -// function* foo() { (x = yield y) } -// -// // This is an error -// function* foo() { (x = yield y) => {} } +// // This is ok +// function* foo() { (x = yield y) } // +// // This is an error +// function* foo() { (x = yield y) => {} } type deferredArrowArgErrors struct { invalidExprAwait logger.Range invalidExprYield logger.Range @@ -7455,10 +7454,10 @@ func findIdentifiers(binding js_ast.Binding, identifiers []js_ast.Decl) []js_ast // can. Everything can be trimmed except for hoisted declarations ("var" and // "function"), which affect the parent scope. For example: // -// function foo() { -// if (false) { var x; } -// x = 1; -// } +// function foo() { +// if (false) { var x; } +// x = 1; +// } // // We can't trim the entire branch as dead or calling foo() will incorrectly // assign to a global variable instead. @@ -10106,22 +10105,21 @@ func isUnsightlyPrimitive(data js_ast.E) bool { // a constant declared later on, then we need to end the const local prefix. // We want to avoid situations like this: // -// const x = y; // This is supposed to throw due to TDZ -// const y = 1; +// const x = y; // This is supposed to throw due to TDZ +// const y = 1; // // or this: // -// const x = 1; -// const y = foo(); // This is supposed to throw due to TDZ -// const z = 2; -// const foo = () => z; +// const x = 1; +// const y = foo(); // This is supposed to throw due to TDZ +// const z = 2; +// const foo = () => z; // // But a situation like this is ok: // -// const x = 1; -// const y = [() => z]; -// const z = 2; -// +// const x = 1; +// const y = [() => z]; +// const z = 2; func isSafeForConstLocalPrefix(expr js_ast.Expr) bool { switch e := expr.Data.(type) { case *js_ast.EMissing, *js_ast.EString, *js_ast.ERegExp, *js_ast.EBigInt, *js_ast.EFunction, *js_ast.EArrow: @@ -10254,14 +10252,14 @@ const ( // // Example usage: // -// // "value" => "value + value" -// // "value()" => "(_a = value(), _a + _a)" -// valueFunc, wrapFunc := p.captureValueWithPossibleSideEffects(loc, 2, value) -// return wrapFunc(js_ast.Expr{Loc: loc, Data: &js_ast.EBinary{ -// Op: js_ast.BinOpAdd, -// Left: valueFunc(), -// Right: valueFunc(), -// }}) +// // "value" => "value + value" +// // "value()" => "(_a = value(), _a + _a)" +// valueFunc, wrapFunc := p.captureValueWithPossibleSideEffects(loc, 2, value) +// return wrapFunc(js_ast.Expr{Loc: loc, Data: &js_ast.EBinary{ +// Op: js_ast.BinOpAdd, +// Left: valueFunc(), +// Right: valueFunc(), +// }}) // // This returns a function for generating references instead of a raw reference // because AST nodes are supposed to be unique in memory, not aliases of other diff --git a/internal/js_parser/js_parser_lower.go b/internal/js_parser/js_parser_lower.go index 50daf17d34..fa2e0ceda2 100644 --- a/internal/js_parser/js_parser_lower.go +++ b/internal/js_parser/js_parser_lower.go @@ -948,26 +948,26 @@ func (p *parser) lowerNullishCoalescing(loc logger.Loc, left js_ast.Expr, right // properties are grouped into object literals and then passed to the // "__spreadValues" and "__spreadProps" functions like this: // -// "{a, b, ...c, d, e}" => "__spreadProps(__spreadValues(__spreadProps({a, b}, c), {d, e})" +// "{a, b, ...c, d, e}" => "__spreadProps(__spreadValues(__spreadProps({a, b}, c), {d, e})" // // If the object literal starts with a spread, then we pass an empty object // literal to "__spreadValues" to make sure we clone the object: // -// "{...a, b}" => "__spreadProps(__spreadValues({}, a), {b})" +// "{...a, b}" => "__spreadProps(__spreadValues({}, a), {b})" // // It's not immediately obvious why we don't compile everything to a single // call to a function that takes any number of arguments, since that would be // shorter. The reason is to preserve the order of side effects. Consider // this code: // -// let a = { -// get x() { -// b = {y: 2} -// return 1 -// } -// } -// let b = {} -// let c = {...a, ...b} +// let a = { +// get x() { +// b = {y: 2} +// return 1 +// } +// } +// let b = {} +// let c = {...a, ...b} // // Converting the above code to "let c = __spreadFn({}, a, null, b)" means "c" // becomes "{x: 1}" which is incorrect. Converting the above code instead to diff --git a/internal/js_parser/ts_parser.go b/internal/js_parser/ts_parser.go index 9ed63e3a66..ff2b45427d 100644 --- a/internal/js_parser/ts_parser.go +++ b/internal/js_parser/ts_parser.go @@ -130,18 +130,17 @@ func (p *parser) skipTypeScriptFnArgs() { // This is a spot where the TypeScript grammar is highly ambiguous. Here are // some cases that are valid: // -// let x = (y: any): (() => {}) => { }; -// let x = (y: any): () => {} => { }; -// let x = (y: any): (y) => {} => { }; -// let x = (y: any): (y[]) => {}; -// let x = (y: any): (a | b) => {}; +// let x = (y: any): (() => {}) => { }; +// let x = (y: any): () => {} => { }; +// let x = (y: any): (y) => {} => { }; +// let x = (y: any): (y[]) => {}; +// let x = (y: any): (a | b) => {}; // // Here are some cases that aren't valid: // -// let x = (y: any): (y) => {}; -// let x = (y: any): (y) => {return 0}; -// let x = (y: any): asserts y is (y) => {}; -// +// let x = (y: any): (y) => {}; +// let x = (y: any): (y) => {return 0}; +// let x = (y: any): asserts y is (y) => {}; func (p *parser) skipTypeScriptParenOrFnType() { if p.trySkipTypeScriptArrowArgsWithBacktracking() { p.skipTypeScriptReturnType() diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 551c0f8c06..09c279e717 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -1180,8 +1180,8 @@ func (r resolverQuery) dirInfoUncached(path string) *dirInfo { } // https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#resolution-customization-with-modulesuffixes -// "Note that the empty string '' in moduleSuffixes is necessary for TypeScript to -// also look-up ./foo.ts. In a sense, the default value for moduleSuffixes is ['']." +// "Note that the empty string ” in moduleSuffixes is necessary for TypeScript to +// also look-up ./foo.ts. In a sense, the default value for moduleSuffixes is [”]." var defaultModuleSuffixes = []string{""} var rewrittenFileExtensions = map[string][]string{ @@ -2146,7 +2146,7 @@ func IsPackagePath(path string) bool { // This list can be obtained with the following command: // -// node --experimental-wasi-unstable-preview1 -p "[...require('module').builtinModules].join('\n')" +// node --experimental-wasi-unstable-preview1 -p "[...require('module').builtinModules].join('\n')" // // Be sure to use the *LATEST* version of node when updating this list! var BuiltInNodeModules = map[string]bool{ diff --git a/internal/sourcemap/sourcemap.go b/internal/sourcemap/sourcemap.go index 31631ab55b..93effc2102 100644 --- a/internal/sourcemap/sourcemap.go +++ b/internal/sourcemap/sourcemap.go @@ -76,12 +76,11 @@ var base64 = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 // bit. The continuation bit tells us whether there are more digits in this // value following this digit. // -// Continuation -// | Sign -// | | -// V V -// 101011 -// +// Continuation +// | Sign +// | | +// V V +// 101011 func encodeVLQ(encoded []byte, value int) []byte { var vlq int if value < 0 { diff --git a/pkg/api/api.go b/pkg/api/api.go index 8d5745e44f..5a7af90b3b 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -5,7 +5,7 @@ // creating a child process, there is also an API for the command-line // interface itself: https://godoc.org/github.com/evanw/esbuild/pkg/cli. // -// Build API +// # Build API // // This function runs an end-to-end build operation. It takes an array of file // paths as entry points, parses them and all of their dependencies, and @@ -14,29 +14,29 @@ // // Example usage: // -// package main +// package main // -// import ( -// "os" +// import ( +// "os" // -// "github.com/evanw/esbuild/pkg/api" -// ) +// "github.com/evanw/esbuild/pkg/api" +// ) // -// func main() { -// result := api.Build(api.BuildOptions{ -// EntryPoints: []string{"input.js"}, -// Outfile: "output.js", -// Bundle: true, -// Write: true, -// LogLevel: api.LogLevelInfo, -// }) +// func main() { +// result := api.Build(api.BuildOptions{ +// EntryPoints: []string{"input.js"}, +// Outfile: "output.js", +// Bundle: true, +// Write: true, +// LogLevel: api.LogLevelInfo, +// }) // -// if len(result.Errors) > 0 { -// os.Exit(1) -// } -// } +// if len(result.Errors) > 0 { +// os.Exit(1) +// } +// } // -// Transform API +// # Transform API // // This function transforms a string of source code into JavaScript. It can be // used to minify JavaScript, convert TypeScript/JSX to JavaScript, or convert @@ -45,36 +45,35 @@ // // Example usage: // -// package main -// -// import ( -// "fmt" -// "os" +// package main // -// "github.com/evanw/esbuild/pkg/api" -// ) +// import ( +// "fmt" +// "os" // -// func main() { -// jsx := ` -// import * as React from 'react' -// import * as ReactDOM from 'react-dom' +// "github.com/evanw/esbuild/pkg/api" +// ) // -// ReactDOM.render( -//

Hello, world!

, -// document.getElementById('root') -// ); -// ` +// func main() { +// jsx := ` +// import * as React from 'react' +// import * as ReactDOM from 'react-dom' // -// result := api.Transform(jsx, api.TransformOptions{ -// Loader: api.LoaderJSX, -// }) +// ReactDOM.render( +//

Hello, world!

, +// document.getElementById('root') +// ); +// ` // -// fmt.Printf("%d errors and %d warnings\n", -// len(result.Errors), len(result.Warnings)) +// result := api.Transform(jsx, api.TransformOptions{ +// Loader: api.LoaderJSX, +// }) // -// os.Stdout.Write(result.Code) -// } +// fmt.Printf("%d errors and %d warnings\n", +// len(result.Errors), len(result.Warnings)) // +// os.Stdout.Write(result.Code) +// } package api type SourceMap uint8 diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index ec2fac7ee4..d8a9e1e57e 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -3,18 +3,17 @@ // // Example usage: // -// package main +// package main // -// import ( -// "os" +// import ( +// "os" // -// "github.com/evanw/esbuild/pkg/cli" -// ) -// -// func main() { -// os.Exit(cli.Run(os.Args[1:])) -// } +// "github.com/evanw/esbuild/pkg/cli" +// ) // +// func main() { +// os.Exit(cli.Run(os.Args[1:])) +// } package cli import ( @@ -38,14 +37,13 @@ func Run(osArgs []string) int { // // Example usage: // -// options, err := cli.ParseBuildOptions([]string{ -// "input.js", -// "--bundle", -// "--minify", -// }) -// -// result := api.Build(options) +// options, err := cli.ParseBuildOptions([]string{ +// "input.js", +// "--bundle", +// "--minify", +// }) // +// result := api.Build(options) func ParseBuildOptions(osArgs []string) (options api.BuildOptions, err error) { options = newBuildOptions() _, errWithNote := parseOptionsImpl(osArgs, &options, nil, kindExternal) @@ -61,14 +59,13 @@ func ParseBuildOptions(osArgs []string) (options api.BuildOptions, err error) { // // Example usage: // -// options, err := cli.ParseTransformOptions([]string{ -// "--minify", -// "--loader=tsx", -// "--define:DEBUG=false", -// }) -// -// result := api.Transform(input, options) +// options, err := cli.ParseTransformOptions([]string{ +// "--minify", +// "--loader=tsx", +// "--define:DEBUG=false", +// }) // +// result := api.Transform(input, options) func ParseTransformOptions(osArgs []string) (options api.TransformOptions, err error) { options = newTransformOptions() _, errWithNote := parseOptionsImpl(osArgs, nil, &options, kindExternal) @@ -85,14 +82,13 @@ func ParseTransformOptions(osArgs []string) (options api.TransformOptions, err e // // Example usage: // -// serveOptions, args, err := cli.ParseServeOptions([]string{ -// "--serve=8000", -// }) -// -// buildOptions, err := cli.ParseBuildOptions(args) +// serveOptions, args, err := cli.ParseServeOptions([]string{ +// "--serve=8000", +// }) // -// result := api.Serve(serveOptions, buildOptions) +// buildOptions, err := cli.ParseBuildOptions(args) // +// result := api.Serve(serveOptions, buildOptions) func ParseServeOptions(osArgs []string) (options api.ServeOptions, remainingArgs []string, err error) { return parseServeOptionsImpl(osArgs) }