Commit graph

1923 commits

Author SHA1 Message Date
Boshen
cfb51f2551 refactor(minifier): fuse ast passes (#8184) 2024-12-29 14:57:20 +00:00
Boshen
8149e34bf0 feat(minifier): optional catch binding when es target >= es2019 (#8180) 2024-12-29 12:27:33 +00:00
Boshen
ad146bbb90 feat(codegen): print real newline when \n is inside template literals (#8178) 2024-12-29 12:20:47 +00:00
sapphi-red
75d5f17dbd
fix(minifier): minify string PropertyKey (#8177)
#8169 added `if self.in_fixed_loop` in `try_compress_property_key`. Because `exit_property_key` was not called for `PeepholeOptimizations`, `try_compress_property_key` was never called.

refs #8147
2024-12-29 07:49:42 +00:00
sapphi-red
fc43ec530e
feat(minifier): fold string.length / array.length (#8172) 2024-12-29 07:14:13 +00:00
Boshen
29dc0dc070 feat(minifier): change foo['bar'] -> foo.bar (#8169) 2024-12-29 04:09:42 +00:00
翠 / green
3c5718d68b
feat(minifier): fold typeof foo == undefined into foo == undefined when possible (#8160) 2024-12-29 11:49:57 +08:00
翠 / green
9d62284202
chore(tasks): print diff for minify idempotency assertion (#8161)
Made the assertion error output more easier to understand.

Example output:

![image](https://github.com/user-attachments/assets/445910fb-b389-4884-b4c5-70a095bc523f)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-29 00:55:45 +08:00
翠 / green
f3a36e1dbf
feat(minifier): fold typeof foo != "undefined" into typeof foo < "u" (#8159) 2024-12-29 00:50:56 +08:00
Boshen
37c9959611 feat(minifier): normalize Infinity into f64::Infinity (#8148) 2024-12-28 06:05:04 +00:00
Boshen
8fb71f518f feat(minifier): minify string PropertyKey (#8147) 2024-12-27 15:09:41 +00:00
Boshen
2b2a37347c feat(minifier): minimize a + 'b' + 'c' -> a + 'bc' (#8137) 2024-12-27 05:46:51 +00:00
Boshen
213364a400 feat(minifier): minimize if (x) if (y) z -> if (x && y) z (#8136) 2024-12-27 02:44:47 +00:00
Boshen
6b51e6dff1 feat(minifier): minimize if(foo) bar else baz -> foo ? bar : baz (#8133) 2024-12-26 16:21:34 +00:00
Boshen
f615bfa773 feat(minifier): minimize if (x) return; return 1 -> return x ? void 0 : 1 (#8130) 2024-12-26 15:36:25 +00:00
Yuichiro Yamashita
e676fdfd83
chore(tasks): use assert_eq! instead of assert! (tasks/minsize/src/lib.rs) (#8129)
related to https://github.com/oxc-project/oxc/pull/8124
2024-12-26 13:54:05 +00:00
Boshen
f0b1ee5a06 feat(minifier): minimize if(!x) foo() -> x || foo() (#8122) 2024-12-26 09:42:34 +00:00
Boshen
f8200a8882 feat(minifier): minimize if(foo) bar -> foo && bar (#8121) 2024-12-26 09:01:38 +00:00
Boshen
72d996709e feat(minifier): add Normalize ast pass (#8120) 2024-12-26 07:02:45 +00:00
Boshen
fef0b25fd3 feat(minifier): collapse var into for loop initializer (#8119)
`var a = 0; for(;a<0;a++) {}` => `for(var a = 0;a<0;a++) {}`
2024-12-26 05:22:02 +00:00
Boshen
2331ea85d9 feat(minifier): typeof foo === 'number' => typeof foo == 'number' (#8112) 2024-12-25 14:52:58 +00:00
Boshen
e594c3988d refactor(minifier): clean up peephole_substitute_alternate_syntax.rs (#8111) 2024-12-25 13:54:51 +00:00
Boshen
11c4bd8687 feat(span): implement source type {file basename}.d.{extension}.ts (#8109) 2024-12-25 12:24:34 +00:00
camc314
708e9cfac0 fix(semantic): report errors for missing class method impls (#8082) 2024-12-25 12:24:33 +00:00
camc314
de82492e97 fix(parser): report syntax errors for missing constructor implementations (#8081) 2024-12-25 12:24:32 +00:00
Boshen
47276679f5 feat(codegen): minify arrow expr (x) => y -> x => y (#8078) 2024-12-24 14:25:01 +00:00
Boshen
0562830549 feat(codegen): minify string with backtick when needed (#8095) 2024-12-24 13:39:31 +00:00
Boshen
6237c0527f feat(codegen): minify more whitespace (#8089) 2024-12-24 09:54:13 +00:00
Boshen
8b8cbcd2db feat(codegen): minify case "foo" -> case"foo" (#8085) 2024-12-24 01:07:58 +00:00
Boshen
f8f067bfc6 feat(codegen): minify class method async*fn(){} (#8083) 2024-12-24 00:35:29 +00:00
injuly
55d6eb9507
fix(parser): disallow type parameters on class constructors (#8071)
TypeScript does not allow type parameters on constructors:

```ts
class A {
  constructor<T>(t: T) {} // <- should be an error
}
```

Here's a comparison snippet on:
1. [TypeScript
playground](https://www.typescriptlang.org/play/?#code/MYGwhgzhAECC0G8BQ1XWAewHYQC4CcBXYXDfAHlgD4AKASkSRTQF8kWg)
(syntax error).
2. [SWC
playground](https://play.swc.rs/?version=1.10.1&code=H4sIAAAAAAAAA0vOSSwuVnBWqOZSUEjOzysuKSpNLskvsgmx09BUqFao5aoFAOf92%2FAiAAAA&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BCIOhERP9mOVBTl7oUE0maH3xszsA5KwcwGnmotxzIkTYx0ziXhHER%2FSgKSE7IhmwRuvRWu1agd4x5tRwOiaUKpW8j3hoOLkbHjLfM22DH%2FC030iZD5ClZUh8nhVTc0Jfj4XvayfaQ%2B9tA%2F4Ad12XkxWH71TaEFh%2B0LYuVI0xQBAAA%3D)
(syntax error)
3. [OXC
playground](https://playground.oxc.rs/#eNo9T8EKwjAM/ZWSk8IOKngpInjxCzx66Wo2Cl0zkk4do/9u6+guyXshL+9lAQsarDci6qaWZ1DKUpDIk43El8d1t1+nSpWaniFBAwR6AZ5CaTKHaL6gswQb8C7EisXSiBuZh5Z8ZZFNkI54AN0ZL5gaGA0Lcr6YcblS8bb6H0A03GO2AJTT4XiGvGHphT2WMJkMLrjOVXH+JTL5u6dPEb+RW5KcaTVN6QerbleM)
(parses as valid syntax)

This PR makes OXC behave exactly like `tsc`, with a little test case.
Happy holidays!

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-24 07:38:39 +08:00
Boshen
618b6aa085 feat(codege): minify whitespace in object getter / setter (#8080) 2024-12-23 16:36:03 +00:00
Boshen
1d5ae817d7 feat(codegen): minify const [foo] = bar -> const[foo]=bar (#8079) 2024-12-23 16:20:37 +00:00
Boshen
373279b7f4 feat(codegen): balance string quotes when minify whitespace (#8072) 2024-12-23 13:24:22 +00:00
Boshen
e632a7b158 feat(transformer): remove typescript symbols after transform (#8069)
part of #7460
2024-12-23 08:24:54 +00:00
Yuji Sugiura
922670e4b7
feat(prettier): Print directive (#8066)
Part of #5068 

- [x] Directive
2024-12-23 14:46:47 +08:00
overlookmotel
6b08c6e6c4 fix(transformer/class-properties): correctly resolve private fields pointing to private methods (#8042)
We don't transform private methods yet, but in class properties transform, still need to record private methods that classes have, so can correctly resolve private fields.

```js
class Outer {
  #foo = 123;
  method() {
    class Inner {
      #foo() {}
      // Refers to `Inner`'s `#foo` method, not `Outer`'s `#foo` property
      prop = this.#foo;
    }
  }
}
```
2024-12-23 03:44:08 +00:00
翠 / green
1932f1e0a0
feat(minifier): fold foo === undefined || foo === null (#8063)
This PR implements folding `foo === undefined || foo === null` into `foo
== null`.

I checked the minified output diff this time, so hoping that there isn't
a bug.
2024-12-23 00:10:44 +08:00
Boshen
23b563730f
feat(tasks/minsize): save minified file 2024-12-21 18:57:36 +08:00
Boshen
be2c60dd10 fix(parser): parse import source from from 'mod' (#8056) 2024-12-21 10:20:14 +00:00
Boshen
8b025e36db chore(coverage): bump test262 (#8055) 2024-12-21 10:20:14 +00:00
camc314
274f117d4e fix(transformer/nullish-coalescing): use correct scope id for binding (#8053) 2024-12-21 07:08:29 +00:00
overlookmotel
3d83396f0b test(transformer/nullish-coalescing): failing test (#8051)
Add failing test for nullish coalescing operator. The output is correct, but temp var is created in wrong scope.

My guess is that it needs to use `current_hoist_scope_id`, not `current_scope_id`.

This test from class properties also shows the same problem: ac097e9160/tasks/transform_conformance/snapshots/oxc.snap.md (L20-L35)
2024-12-21 07:08:29 +00:00
Boshen
2736657dcd perf(semantic): allocate UnresolvedReferences in allocator (#8046) 2024-12-20 15:18:16 +00:00
Boshen
414e8285cd perf(semantic): allocate symbol data in Allocator (#8012) 2024-12-20 14:13:41 +00:00
overlookmotel
043252dcd1 fix(transformer/class-properties): replace this and class name in static blocks (#8035)
Transform `this`, class name, and `super` in static blocks.
2024-12-20 10:07:23 +00:00
overlookmotel
273795d471 fix(transformer/class-properties): run other transforms on static properties, static blocks, and computed keys (#7982)
Large re-architecting of class properties transform. Split transform into 3 phases:

1. Transform instance properties when entering class.
2. Transform private fields during traversal of class body.
3. Transform static properties and static blocks when exiting class.

This ensures that code which has to be moved outside of the class (static property initializers, static blocks, computed keys) can get transformed by other transforms before they're moved out.

Also fixes a problem where we previously registered private properties too early - on entering the class, rather than the class *body*, so private fields in `extends` clause of a nested class were misinterpretted.
2024-12-20 10:07:23 +00:00
overlookmotel
897a1a8946 feat(transformer/class-properties): exit faster from super replacement visitor (#8028)
When inserting instance property initializers into class constructor, need to search for and transform `super()`. Exit that visit earlier in some cases, for better performance and smaller output.
2024-12-20 03:10:22 +00:00
Boshen
7aebed012d perf(semantic): allocate Bindings in allocator (#8021) 2024-12-19 15:16:03 +00:00
Boshen
02f968d02d refactor(semantic): change Bindings to a plain FxHashMap (#8019)
`IndexMap` was needed for the insertion order requirement in mangler.

Bindings (symbol ids) are monotonically increasing by binding
positions, which means we can get insertion order by sorting the symbol ids in
mangler.

Previous attempt: https://github.com/oxc-project/oxc/pull/4228
2024-12-19 14:16:28 +00:00