Commit Graph

14 Commits

Author SHA1 Message Date
Dunqing e7163b6720 feat(ecmascript): add known-globals to side-effect-free property reads (#20212)
## Summary

close: #13067

Part of https://github.com/oxc-project/oxc/issues/19673

Depends on #20217.

Port known-globals lists from Rolldown to Oxc's side-effect detection:

- **Global identifiers** (Math, Array, console, DOM classes, etc.) are now considered side-effect-free to access via `is_known_global_identifier`, matching Rolldown's `GLOBAL_IDENT` set
- **Property reads** like `Math.PI`, `console.log`, `Object.keys` are considered side-effect-free via `is_known_global_property`
- **3-level chains** like `Object.prototype.hasOwnProperty` are supported via `is_known_global_property_deep`

## Test plan

- [x] Added tests for known global identifiers (Math, Array, Object, console, etc.)
- [x] Added tests for known global property reads (Math.PI, Object.keys, etc.)
- [x] Added tests for 3-level chains (Object.prototype.hasOwnProperty, etc.)
- [x] Existing minifier test expectations updated for improved side-effect detection
- [x] All existing tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-12 09:22:57 +00:00
sapphi-red 2bf7293c69 feat(mangler)!: enable top_level by default for modules and commonjs (#18278)
I think we can enable `top_level` by default.

refs #18233
2026-02-06 12:48:44 +00:00
Boshen 523a30a016 style(all): apply oxfmt default options (#16091)
Embrace the defaults!

---------

Co-authored-by: Yuji Sugiura <y.sugiura.0316@gmail.com>
2025-11-25 15:56:24 +09:00
Boshen ea51b0b5c8 feat(napi)!: standardize function naming with sync suffixes (#15661)
closes #15576

## Summary

Standardizes function naming across all NAPI packages (parser, transform, minify) with a consistent pattern:
- Async functions: `verb` (no suffix)
- Sync functions: `verbSync` (with Sync suffix)

## Changes

### Breaking Changes

**napi/parser:**
- `parseAsync` → `parse` (async)
- `parseSync` remains unchanged (sync)

**napi/transform:**
- `transformAsync` → `transform` (async)
- `transform` → `transformSync` (sync)
- `isolatedDeclaration` → `isolatedDeclarationSync` (sync)
- Added new `isolatedDeclaration` function (async)
- `moduleRunnerTransform` → `moduleRunnerTransformSync` (sync)
- Added new `moduleRunnerTransform` function (async)

**napi/minify:**
- `minify` → `minifySync` (sync)
- Added new `minify` function (async)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-11-13 12:28:23 +00:00
Boshen a286dd4a5b feat(minifier): remove unnecessary 'use strict' directive (#12642) 2025-07-31 05:07:44 +00:00
Boshen 1b80633434 feat(minifier): remove unused function declaration (#12318) 2025-07-16 10:29:07 +00:00
Boshen 3f33e8c8b5 feat(minifier): remove unused assignment expression (#12314)
```
var x = 1;
x = 2; // remove
```

Remove the entier thing if the binding has no read references.
2025-07-16 07:37:21 +00:00
Dunqing cd984263c2 fix(semantic): handle var hoisting in catch block with same catch parameter name (#12313)
The root cause is that the variable was hoisted to a scope that has the same name binding

```js
var a = 1;
try {
  throw 2
} catch (a) {
  var a = 3;
//    ^ Shouldn't hoist to the top scope because there is a same name variable.
}
console.log(a);
```

Ref: https://tc39.es/ecma262/#sec-variablestatements-in-catch-blocks

Note

The [Block](https://tc39.es/ecma262/#prod-Block) of a [Catch](https://tc39.es/ecma262/#prod-Catch) clause may contain var declarations that bind a name that is also bound by the [CatchParameter](https://tc39.es/ecma262/#prod-CatchParameter). At runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the [CatchParameter](https://tc39.es/ecma262/#prod-CatchParameter) and hence the [Initializer](https://tc39.es/ecma262/#prod-Initializer) for such var declarations will assign to the corresponding catch parameter rather than the var binding.
2025-07-16 06:54:38 +00:00
Boshen fb8289c5d3 feat(minifier): remove unused variable declaration (#11796)
closes #10033
2025-07-16 13:31:44 +08:00
sapphi-red 86b6219d26 feat(mangler): use characters in the order of their likely frequency (#8771)
Just noticed that we can use a static list here. I think this has no downsides. To have better compression, we can actually count the characters, but I guess there won't be much difference normally.
2025-01-29 02:20:44 +00:00
Boshen 9ec4e24eb7 test(napi/minify): fix more broken tests 2025-01-16 16:09:23 +08:00
Boshen 0acbef356a test(napi/minify): fix matching of arrays 2025-01-16 15:34:20 +08:00
Boshen 855c8395cf fix(codegen): shorthand assignment target identifier consider mangled names (#8536) 2025-01-16 07:26:07 +00:00
Boshen c63c8b924d test(napi/minify): add runtime test (#8501) 2025-01-15 21:13:00 +08:00