8000 [pull] master from tdewolff:master by pull[bot] · Pull Request #172 · RepoBackup/minify · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
dry-run: false
language: go
- name: Upload Crash
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
run: npm run build:go

- name: Upload artifact
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: prebuild-${{ matrix.goos }}-${{ matrix.goarch }}
path: bindings/js/build/${{ matrix.goos }}-${{ matrix.goarch }}
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
PKG_VERSION: ${{ github.ref_name || '0.0.0-dev' }}

- name: Download prebuilts
uses: actions/download-artifact@v7
uses: actions/download-artifact@v8
with:
pattern: prebuild-*
path: bindings/js/build/_artifacts
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
CIBW_BEFORE_ALL: .ci/ensure-go.sh; make -C bindings/py compile
- name: Upload wheels
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: wheels-linux-${{ matrix.go_target }}
path: ./wheelhouse/*.whl
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
env:
CIBW_ARCHS: ${{ matrix.cibw_target }}
- name: Upload wheels
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: wheels-windows-${{ matrix.go_target }}
path: ./wheelhouse/*.whl
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
env:
CIBW_ARCHS: ${{ matrix.cibw_target }}
- name: Upload wheels
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: wheels-macos-${{ matrix.go_target }}
path: ./wheelhouse/*.whl
Expand All @@ -132,7 +132,7 @@ jobs:
- name: Build package
run: make -C bindings/py build
- name: Upload sdist
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: wheels
path: bindings/py/dist/*
Expand All @@ -143,7 +143,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v7
uses: actions/download-artifact@v8
with:
path: bindings/py/artifacts
- name: Bundle release artifacts
Expand Down
222 changes: 111 additions & 111 deletions bindings/js/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"go"
],
"devDependencies": {
"@types/node": "^25.2.3",
"@types/node": "^25.3.0",
"tsdown": "^0.20.3",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/djherbis/atime v1.1.0
github.com/fsnotify/fsnotify v1.9.0
github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e
github.com/tdewolff/parse/v2 v2.8.8
github.com/tdewolff/parse/v2 v2.8.10
github.com/tdewolff/test v1.0.11
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e h1:2jfHhbjBKS2wfyvcz5W2eOkQVKv57DKM1C/QYhTovhs=
github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e/go.mod h1:xw2b1X81m4zY1OGytzHNr/YKXbf/STHkK5idoNamlYE=
github.com/tdewolff/parse/v2 v2.8.8 h1:l3yOJ4OUKq1sKeQQxZ7P2yZ6daW/Oq4IDxL98uTOpPI=
github.com/tdewolff/parse/v2 v2.8.8/go.mod h1:Hwlni2tiVNKyzR1o6nUs4FOF07URA+JLBLd6dlIXYqo=
github.com/tdewolff/parse/v2 v2.8.10 h1:5a8o388UmuiU3zlOBJ56PN0rxVi67LRNED/zzuHAfC0=
github.com/tdewolff/parse/v2 v2.8.10/go.mod h1:Hwlni2tiVNKyzR1o6nUs4FOF07URA+JLBLd6dlIXYqo=
github.com/tdewolff/test v1.0.11 h1:FdLbwQVHxqG16SlkGveC0JVyrJN62COWTRyUFzfbtBE=
github.com/tdewolff/test v1.0.11/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
Expand Down
42 changes: 21 additions & 21 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
panic(fmt.Sprintf("bad type: %T!=(js.LiteralExpr,*js.Var)", expr.Y)) // should never happen
}

optionalLeft := false
if group, ok := expr.X.(*js.GroupExpr); ok {
if lit, ok := group.X.(*js.LiteralExpr); ok && (lit.TokenType == js.DecimalToken || lit.TokenType == js.IntegerToken) {
if lit.TokenType == js.DecimalToken {
Expand All @@ -1144,17 +1143,13 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.write(dotBytes)
m.write(yData)
break
} else if dot, ok := group.X.(*js.DotExpr); ok {
optionalLeft = dot.Optional
} else if call, ok := group.X.(*js.CallExpr); ok {
optionalLeft = call.Optional
}
}
if js.OpMember <= prec || optionalLeft {
m.minifyExpr(expr.X, js.OpMember)
} else {
m.minifyExpr(expr.X, js.OpCall)
precInner := expr.Prec
if precInner == js.OpMember && prec < js.OpMember {
precInner = js.OpCall
}
m.minifyExpr(expr.X, precInner)
if expr.Optional {
m.write(questionBytes)
} else if last := m.prev[len(m.prev)-1]; '0' <= last && last <= '9' {
Expand All @@ -1177,8 +1172,8 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
if cond, ok := expr.X.(*js.CondExpr); ok {
expr.X = m.optimizeCondExpr(cond, js.OpExpr)
}
precInside := exprPrec(expr.X)
if prec <= precInside || precInside == js.OpCoalesce && prec == js.OpBitOr {
precInner := exprPrec(expr.X)
if prec <= precInner || precInner == js.OpCoalesce && prec == js.OpBitOr {
m.minifyExpr(expr.X, prec)
} else {
parentInFor := m.inFor
Expand Down Expand Up @@ -1228,11 +1223,11 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.inFor = parentInFor
case *js.TemplateExpr:
if expr.Tag != nil {
if prec < js.OpMember {
m.minifyExpr(expr.Tag, js.OpCall)
} else {
m.minifyExpr(expr.Tag, js.OpMember)
precInner := expr.Prec
if precInner == js.OpMember && prec < js.OpMember {
precInner = js.OpCall
}
m.minifyExpr(expr.Tag, precInner)
if expr.Optional {
m.write(optChainBytes)
}
Expand All @@ -1255,6 +1250,7 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.inFor = parentInFor
case *js.NewExpr:
if expr.Args == nil && js.OpLHS < prec && prec != js.OpNew {
// new a() => (new a), when inside a Member, Call or OptChain expression
m.write(openNewBytes)
m.writeSpaceBeforeIdent()
m.minifyExpr(expr.X, js.OpNew)
Expand All @@ -1266,6 +1262,7 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.minifyExpr(expr.X, js.OpMember)
m.minifyArguments(*expr.Args)
} else {
// new a() => new a
m.minifyExpr(expr.X, js.OpNew)
}
}
Expand Down Expand Up @@ -1391,7 +1388,11 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
}
}
}
m.minifyExpr(expr.X, js.OpCall)
precInner := expr.Prec
if precInner == js.OpMember && prec < js.OpMember {
precInner = js.OpCall
}
m.minifyExpr(expr.X, precInner)
parentInFor := m.inFor
m.inFor = false
if expr.Optional {
Expand All @@ -1405,12 +1406,11 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.write(notBytes)
}
}
if prec < js.OpMember {
m.minifyExpr(expr.X, js.OpCall)
} else {
m.minifyExpr(expr.X, js.OpMember)
precInner := expr.Prec
if precInner == js.OpMember && prec < js.OpMember {
precInner = js.OpCall
}

m.minifyExpr(expr.X, precInner)
if expr.Optional {
m.write(optChainBytes)
}
Expand Down
5 changes: 4 additions & 1 deletion js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ func TestJS(t *testing.T) {
{`(new a().b).c(d)`, `(new a).b.c(d)`},
{`new a()`, `new a`},
{`new a()()`, `(new a)()`},
{`new a()?.()`, `(new a)?.()`},
{`new(a.b)instanceof c`, `new a.b instanceof c`},
{`new(a[b])instanceof c`, `new a[b]instanceof c`},
{"new(a`tmpl`)instanceof c", "new a`tmpl`instanceof c"},
Expand All @@ -559,7 +560,7 @@ func TestJS(t *testing.T) {
{"(a()`tmpl`).b(c)", "a()`tmpl`.b(c)"},
{`(a?.b).c(d)`, `(a?.b).c(d)`},
{`(a?.(c)).d(e)`, `(a?.(c)).d(e)`},
{`(a?.b.c).d`, `a?.b.c.d`},
{`(a?.b.c).d`, `(a?.b.c).d`},
{`class a extends (new b){}`, `class a extends new b{}`},
{`(new.target)`, `new.target`},
{`(import.meta)`, `import.meta`},
Expand Down Expand Up @@ -861,6 +862,8 @@ func TestJS(t *testing.T) {
DB92 {`var c="";for(let i=0;;);var d="";for(let i=0;;);`, `var d,c="";for(let i=0;;);d="";for(let i=0;;);`}, // #687
{"String.raw`\\b`", "String.raw`\\b`"}, // #701
{"if(true){const a=setInterval(()=>{clearInterval(a)},100)}", "{const a=setInterval(()=>{clearInterval(a)},100)}"}, // #867
{"({a(key){if(x){b.push({key})}}})", "({a(key){x&&b.push({key})}})"}, // #910
{"(a?.b()).c", "(a?.b()).c"}, // #912
}

m := minify.New()
Expand Down
4 changes: 2 additions & 2 deletions js/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func exprPrec(i js.IExpr) js.OpPrec {
case *js.NewTargetExpr, *js.ImportMetaExpr:
return js.OpMember
case *js.CallExpr:
return js.OpCall
return expr.Prec
case *js.CondExpr, *js.YieldExpr, *js.ArrowFunc:
return js.OpAssign
case *js.GroupExpr:
Expand Down Expand Up @@ -843,7 +843,7 @@ func (m *jsMinifier) optimizeCondExpr(expr *js.CondExpr, prec js.OpPrec) js.IExp
if isCallX && isCallY && len(callX.Args.List) == 1 && len(callY.Args.List) == 1 && !callX.Args.List[0].Rest && !callY.Args.List[0].Rest && isEqualExpr(callX.X, callY.X) {
expr.X = callX.Args.List[0].Value
expr.Y = callY.Args.List[0].Value
return &js.CallExpr{callX.X, js.Args{[]js.Arg{{expr, false}}}, false} // recompress the conditional expression inside
return &js.CallExpr{callX.X, js.Args{[]js.Arg{{expr, false}}}, js.OpCall, false} // recompress the conditional expression inside
}

// shorten when true and false bodies are true and false
Expand Down
Loading
0