Skip to content

Commit

Permalink
fix #231: add environment versions to --target
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 7, 2020
1 parent b436c4e commit fbb7c54
Show file tree
Hide file tree
Showing 19 changed files with 901 additions and 636 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

You can now assign the `binary` loader to a file extension to load all files of that type into a Uint8Array. The data is encoded as a base64 string and decoded into a Uint8Array at run time. The decoder defaults to a custom platform-independent implementation (faster than `atob`) but it switches to using the `Buffer` API with `--platform=node`.

* Add fine-grained `--target` environments ([#231](https://github.com/evanw/esbuild/issues/231))

You can now configure individual JavaScript environments as targets. The `--target` flag now takes a comma-separated list of values like this: `--target=chrome58,firefox57,safari11,edge16`. Compatibility data was mainly sourced from [this widely-used compatibility table](https://kangax.github.io/compat-table/es2016plus/).

## 0.5.24

* Smaller code for loaders that generate expressions
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Here are some of the main features that esbuild offers (a non-exhaustive list):
* Respects `/* @__PURE__ */` annotations
* Output formats
* CommonJS
* [IIFE](https://en.wikipedia.org/wiki/Immediately_invoked_function_expression)
* <abbr title="Immediately Invoked Function Expression">IIFE</abbr>
* ES6 module (supports code splitting)
* Source map generation
* Transpilation of JSX and newer JS syntax down to ES6
Expand All @@ -112,7 +112,7 @@ Here are some of the main features that esbuild offers (a non-exhaustive list):

#### JavaScript syntax support:

Syntax transforms convert newer JavaScript syntax to older JavaScript syntax for use with older browsers. You can set the language target with the `--target` flag, which goes back as far as ES6. Note that if you use a syntax feature that esbuild doesn't yet have support for transforming to your current language target, esbuild will still build successfully but will generate a warning where the unsupported syntax is used and will pass the syntax through un-transformed.
Syntax transforms convert newer JavaScript syntax to older JavaScript syntax for use with older browsers. You can set the language target with the `--target` flag, which goes back as far as ES6. You can also set `--target` to a comma-separated list of browsers and versions (e.g. `--target=chrome58,firefox57,safari11,edge16`). Note that if you use a syntax feature that esbuild doesn't yet have support for transforming to your current language target, esbuild will generate an error where the unsupported syntax is used.

These syntax features are always transformed for older browsers:

Expand Down Expand Up @@ -350,7 +350,7 @@ Options:
--outfile=... The output file (for one entry point)
--outdir=... The output directory (for multiple entry points)
--sourcemap Emit a source map
--target=... Language target (default esnext)
--target=... Environment target (e.g. es2017, chrome80)
--platform=... Platform target (browser or node, default browser)
--external:M Exclude module M from the bundle
--format=... Output format (iife, cjs, esm)
Expand Down
2 changes: 1 addition & 1 deletion cmd/esbuild/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
--outfile=... The output file (for one entry point)
--outdir=... The output directory (for multiple entry points)
--sourcemap Emit a source map
--target=... Language target (default esnext)
--target=... Environment target (e.g. es2017, chrome80)
--platform=... Platform target (browser or node, default browser)
--external:M Exclude module M from the bundle
--format=... Output format (iife, cjs, esm)
Expand Down
28 changes: 27 additions & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ast

import (
"strings"

"github.com/evanw/esbuild/internal/compat"
)

// Every module (i.e. file) is parsed into a separate AST data structure. For
Expand Down Expand Up @@ -984,6 +986,11 @@ const (
SymbolPrivateGet
SymbolPrivateSet
SymbolPrivateGetSetPair
SymbolPrivateStaticField
SymbolPrivateStaticMethod
SymbolPrivateStaticGet
SymbolPrivateStaticSet
SymbolPrivateStaticGetSetPair

// TypeScript enums can merge with TypeScript namespaces and other TypeScript
// enums.
Expand All @@ -1002,7 +1009,26 @@ const (
)

func (kind SymbolKind) IsPrivate() bool {
return kind >= SymbolPrivateField && kind <= SymbolPrivateGetSetPair
return kind >= SymbolPrivateField && kind <= SymbolPrivateStaticGetSetPair
}

func (kind SymbolKind) Feature() compat.Feature {
switch kind {
case SymbolPrivateField:
return compat.ClassPrivateField
case SymbolPrivateMethod:
return compat.ClassPrivateMethod
case SymbolPrivateGet, SymbolPrivateSet, SymbolPrivateGetSetPair:
return compat.ClassPrivateAccessor
case SymbolPrivateStaticField:
return compat.ClassPrivateStaticField
case SymbolPrivateStaticMethod:
return compat.ClassPrivateStaticMethod
case SymbolPrivateStaticGet, SymbolPrivateStaticSet, SymbolPrivateStaticGetSetPair:
return compat.ClassPrivateStaticAccessor
default:
return 0
}
}

func (kind SymbolKind) IsHoisted() bool {
Expand Down
Loading

0 comments on commit fbb7c54

Please sign in to comment.