Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evanw/esbuild
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.17.18
Choose a base ref
...
head repository: evanw/esbuild
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.17.19
Choose a head ref
  • 7 commits
  • 46 files changed
  • 1 contributor

Commits on Apr 25, 2023

  1. fix for validation warnings

    evanw committed Apr 25, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7d11ef1 View commit details

Commits on May 12, 2023

  1. Copy the full SHA
    d686756 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c19689a View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a3fcf70 View commit details
  4. Copy the full SHA
    7cf5257 View commit details
  5. update go 1.20.3 => 1.20.4

    evanw committed May 12, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3a81eb5 View commit details

Commits on May 13, 2023

  1. publish 0.17.19 to npm

    evanw committed May 13, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d47ab43 View commit details
Showing with 555 additions and 152 deletions.
  1. +2 −2 .github/workflows/ci.yml
  2. +1 −1 .github/workflows/validate.yml
  3. +79 −0 CHANGELOG.md
  4. +1 −1 Makefile
  5. +1 −1 cmd/esbuild/version.go
  6. +102 −0 internal/bundler_tests/bundler_dce_test.go
  7. +61 −4 internal/bundler_tests/snapshots/snapshots_dce.txt
  8. +1 −1 internal/bundler_tests/snapshots/snapshots_default.txt
  9. +10 −5 internal/css_ast/css_ast.go
  10. +28 −7 internal/css_parser/css_nesting.go
  11. +16 −0 internal/css_parser/css_parser_test.go
  12. +3 −3 internal/js_ast/js_ast.go
  13. +33 −11 internal/js_ast/js_ast_helpers.go
  14. +51 −37 internal/js_parser/js_parser.go
  15. +15 −6 internal/js_parser/js_parser_test.go
  16. +32 −7 internal/js_parser/ts_parser.go
  17. +16 −1 internal/js_parser/ts_parser_test.go
  18. +3 −3 internal/js_printer/js_printer.go
  19. +16 −12 internal/linker/linker.go
  20. +1 −1 npm/@esbuild/android-arm/package.json
  21. +1 −1 npm/@esbuild/android-arm64/package.json
  22. +1 −1 npm/@esbuild/android-x64/package.json
  23. +1 −1 npm/@esbuild/darwin-arm64/package.json
  24. +1 −1 npm/@esbuild/darwin-x64/package.json
  25. +1 −1 npm/@esbuild/freebsd-arm64/package.json
  26. +1 −1 npm/@esbuild/freebsd-x64/package.json
  27. +1 −1 npm/@esbuild/linux-arm/package.json
  28. +1 −1 npm/@esbuild/linux-arm64/package.json
  29. +1 −1 npm/@esbuild/linux-ia32/package.json
  30. +1 −1 npm/@esbuild/linux-loong64/package.json
  31. +1 −1 npm/@esbuild/linux-mips64el/package.json
  32. +1 −1 npm/@esbuild/linux-ppc64/package.json
  33. +1 −1 npm/@esbuild/linux-riscv64/package.json
  34. +1 −1 npm/@esbuild/linux-s390x/package.json
  35. +1 −1 npm/@esbuild/linux-x64/package.json
  36. +1 −1 npm/@esbuild/netbsd-x64/package.json
  37. +1 −1 npm/@esbuild/openbsd-x64/package.json
  38. +1 −1 npm/@esbuild/sunos-x64/package.json
  39. +1 −1 npm/@esbuild/win32-arm64/package.json
  40. +1 −1 npm/@esbuild/win32-ia32/package.json
  41. +1 −1 npm/@esbuild/win32-x64/package.json
  42. +1 −1 npm/esbuild-wasm/package.json
  43. +23 −23 npm/esbuild/package.json
  44. +22 −2 pkg/api/api_impl.go
  45. +15 −1 scripts/js-api-tests.js
  46. +1 −1 version.txt
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.20.3
go-version: 1.20.4
id: go

- name: Setup Node.js environment
@@ -50,7 +50,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.20.3
go-version: 1.20.4
id: go

- name: Setup Node.js environment
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.20.3
go-version: 1.20.4
id: go

- name: Validation checks
79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,84 @@
# Changelog

## 0.17.19

* Fix CSS transform bugs with nested selectors that start with a combinator ([#3096](https://github.com/evanw/esbuild/issues/3096))

This release fixes several bugs regarding transforming nested CSS into non-nested CSS for older browsers. The bugs were due to lack of test coverage for nested selectors with more than one compound selector where they all start with the same combinator. Here's what some problematic cases look like before and after these fixes:

```css
/* Original code */
.foo {
> &a,
> &b {
color: red;
}
}
.bar {
> &a,
+ &b {
color: green;
}
}

/* Old output (with --target=chrome90) */
.foo :is(> .fooa, > .foob) {
color: red;
}
.bar :is(> .bara, + .barb) {
color: green;
}

/* New output (with --target=chrome90) */
.foo > :is(a.foo, b.foo) {
color: red;
}
.bar > a.bar,
.bar + b.bar {
color: green;
}
```

* Fix bug with TypeScript parsing of instantiation expressions followed by `=` ([#3111](https://github.com/evanw/esbuild/issues/3111))

This release fixes esbuild's TypeScript-to-JavaScript conversion code in the case where a potential instantiation expression is followed immediately by a `=` token (such that the trailing `>` becomes a `>=` token). Previously esbuild considered that to still be an instantiation expression, but the official TypeScript compiler considered it to be a `>=` operator instead. This release changes esbuild's interpretation to match TypeScript. This edge case currently [appears to be problematic](https://sucrase.io/#transforms=typescript&compareWithTypeScript=true&code=x%3Cy%3E%3Da%3Cb%3Cc%3E%3E()) for other TypeScript-to-JavaScript converters as well:

| Original code | TypeScript | esbuild 0.17.18 | esbuild 0.17.19 | Sucrase | Babel |
|---|---|---|---|---|---|
| `x<y>=a<b<c>>()` | `x<y>=a();` | `x=a();` | `x<y>=a();` | `x=a()` | Invalid left-hand side in assignment expression |

* Avoid removing unrecognized directives from the directive prologue when minifying ([#3115](https://github.com/evanw/esbuild/issues/3115))

The [directive prologue](https://262.ecma-international.org/6.0/#sec-directive-prologues-and-the-use-strict-directive) in JavaScript is a sequence of top-level string expressions that come before your code. The only directives that JavaScript engines currently recognize are `use strict` and sometimes `use asm`. However, the people behind React have made up their own directive for their own custom dialect of JavaScript. Previously esbuild only preserved the `use strict` directive when minifying, although you could still write React JavaScript with esbuild using something like `--banner:js="'your directive here';"`. With this release, you can now put arbitrary directives in the entry point and esbuild will preserve them in its minified output:

```js
// Original code
'use wtf'; console.log(123)

// Old output (with --minify)
console.log(123);

// New output (with --minify)
"use wtf";console.log(123);
```

Note that this means esbuild will no longer remove certain stray top-level strings when minifying. This behavior is an intentional change because these stray top-level strings are actually part of the directive prologue, and could potentially have semantics assigned to them (as was the case with React).

* Improved minification of binary shift operators

With this release, esbuild's minifier will now evaluate the `<<` and `>>>` operators if the resulting code would be shorter:

```js
// Original code
console.log(10 << 10, 10 << 20, -123 >>> 5, -123 >>> 10);

// Old output (with --minify)
console.log(10<<10,10<<20,-123>>>5,-123>>>10);

// New output (with --minify)
console.log(10240,10<<20,-123>>>5,4194303);
```

## 0.17.18

* Fix non-default JSON import error with `export {} from` ([#3070](https://github.com/evanw/esbuild/issues/3070))
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ test-all:
@$(MAKE) --no-print-directory -j6 test-common test-deno ts-type-tests test-wasm-node test-wasm-browser lib-typecheck test-yarnpnp

check-go-version:
@go version | grep ' go1\.20\.3 ' || (echo 'Please install Go version 1.20.3' && false)
@go version | grep ' go1\.20\.4 ' || (echo 'Please install Go version 1.20.4' && false)

# Note: Don't add "-race" here by default. The Go race detector is currently
# only supported on the following configurations:
2 changes: 1 addition & 1 deletion cmd/esbuild/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const esbuildVersion = "0.17.18"
const esbuildVersion = "0.17.19"
102 changes: 102 additions & 0 deletions internal/bundler_tests/bundler_dce_test.go
Original file line number Diff line number Diff line change
@@ -3645,3 +3645,105 @@ func TestTreeShakingJSWithAssociatedCSSUnusedNestedImportSideEffectsFalseOnlyJS(
},
})
}

func TestPreserveDirectivesMinifyPassThrough(t *testing.T) {
dce_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
//! 1
'use 1'
//! 2
'use 2'
//! 3
'use 3'
entry()
//! 4
'use 4'
//! 5
'use 5'
//! 6
'use 6'
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModePassThrough,
AbsOutputFile: "/out.js",
MinifySyntax: true,
},
})
}

func TestPreserveDirectivesMinifyIIFE(t *testing.T) {
dce_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
//! 1
'use 1'
//! 2
'use 2'
//! 3
'use 3'
entry()
//! 4
'use 4'
//! 5
'use 5'
//! 6
'use 6'
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeConvertFormat,
OutputFormat: config.FormatIIFE,
AbsOutputFile: "/out.js",
MinifySyntax: true,
},
})
}

func TestPreserveDirectivesMinifyBundle(t *testing.T) {
dce_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
//! 1
'use 1'
//! 2
'use 2'
//! 3
'use 3'
entry()
//! 4
'use 4'
//! 5
'use 5'
//! 6
'use 6'
import "./nested.js"
`,
"/nested.js": `
//! A
'use A'
//! B
'use B'
//! C
'use C'
nested()
//! D
'use D'
//! E
'use E'
//! F
'use F'
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
OutputFormat: config.FormatIIFE,
AbsOutputFile: "/out.js",
MinifySyntax: true,
},
})
}
65 changes: 61 additions & 4 deletions internal/bundler_tests/snapshots/snapshots_dce.txt
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ var ns;

---------- /out/directive-before.js ----------
function nested() {
"directive";
x = [1, 1];
}

@@ -276,9 +277,9 @@ console.log([
3 /* a */ === 6 /* b */,
3 /* a */ !== 6 /* b */
], [
6 /* b */ << 1,
12,
3,
6 /* b */ >>> 1
3
], [
2,
7,
@@ -314,9 +315,9 @@ console.log([
3 === 6,
3 !== 6
], [
6 << 1,
12,
3,
6 >>> 1
3
], [
2,
7,
@@ -1505,6 +1506,62 @@ console.log("hello");
// Users/user/project/src/entry.js
console.log("unused import");

================================================================================
TestPreserveDirectivesMinifyBundle
---------- /out.js ----------
"use 1";
"use 2";
"use 3";
(() => {
// nested.js
//! A
//! B
//! C
nested();
//! D
//! E
//! F

// entry.js
//! 1
//! 2
//! 3
entry();
//! 4
//! 5
//! 6
})();

================================================================================
TestPreserveDirectivesMinifyIIFE
---------- /out.js ----------
"use 1";
"use 2";
"use 3";
(() => {
//! 1
//! 2
//! 3
entry();
//! 4
//! 5
//! 6
})();

================================================================================
TestPreserveDirectivesMinifyPassThrough
---------- /out.js ----------
"use 1";
"use 2";
"use 3";
//! 1
//! 2
//! 3
entry();
//! 4
//! 5
//! 6

================================================================================
TestPureCallsWithSpread
---------- /out.js ----------
2 changes: 1 addition & 1 deletion internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
@@ -5896,7 +5896,7 @@ TestUseStrictDirectiveBundleIssue1837
================================================================================
TestUseStrictDirectiveMinifyNoBundle
---------- /out.js ----------
"use strict";a,b;
"use strict";"use loose";a,b;

================================================================================
TestVarRelocatingBundle
15 changes: 10 additions & 5 deletions internal/css_ast/css_ast.go
Original file line number Diff line number Diff line change
@@ -598,11 +598,14 @@ type ComplexSelector struct {
Selectors []CompoundSelector
}

func (s ComplexSelector) AppendToTokens(tokens []Token) []Token {
func (s ComplexSelector) AppendToTokensWithoutLeadingCombinator(tokens []Token) []Token {
for i, sel := range s.Selectors {
if n := len(tokens); i > 0 && n > 0 {
tokens[n-1].Whitespace |= WhitespaceAfter
}
if i == 0 {
sel.Combinator = 0
}
tokens = sel.AppendToTokens(tokens)
}
return tokens
@@ -714,14 +717,16 @@ func (sel CompoundSelector) AppendToTokens(tokens []Token) []Token {
}
}

if sel.HasNestingSelector {
tokens = append(tokens, Token{Kind: css_lexer.TDelimAmpersand, Text: "&"})
}

if sel.TypeSelector != nil {
tokens = sel.TypeSelector.AppendToTokens(tokens)
}

// Put this after the type selector in case it's substituted for ":is()"
// ".foo { > &a, > &b {} }" => ".foo > :is(b.foo, c.foo) {}" (we don't want to get ".foo > :is(.foob, .fooc) {}" instead)
if sel.HasNestingSelector {
tokens = append(tokens, Token{Kind: css_lexer.TDelimAmpersand, Text: "&"})
}

for _, ss := range sel.SubclassSelectors {
tokens = ss.AppendToTokens(tokens)
}
Loading