Commit graph

7504 commits

Author SHA1 Message Date
Boshen
41ddf60ab0 feat(minfier): add CompressOptions::target (#8179) 2024-12-29 12:27:32 +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
1fa53413e0
test(minifier): port tests from ConvertToDottedPropertiesTest (#8175) 2024-12-29 07:19:13 +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
Alexander S.
faf7464733
fix(linter): disable rule react/rules-of-hook by file extension (#8168) 2024-12-28 18:52:10 +00:00
Alexander S.
d8d2ec6257
perf(linter): run rules which require typescript syntax only when source type is actually typescript (#8166) 2024-12-28 17:03:11 +00: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
Yuichiro Yamashita
65796c47a1
feat(linter): implement eslint/prefer-rest-params (#8155)
implement: https://eslint.org/docs/latest/rules/prefer-rest-params
2024-12-28 16:42:01 +00:00
Alexander S.
1171e00a3c
fix(linter): disable react/rules-of-hooks for vue and svelte files (#8165)
because of https://github.com/oxc-project/oxc/issues/8003

I used the FrameworkFlags in hope they are only active in `.vue` and
`.svelte` files.
2024-12-28 16:34:58 +00:00
camc314
1b9a5bae2e fix(linter): false positiver in private member expr in oxc/const-comparison (#8164)
fixes https://github.com/oxc-project/oxc/issues/8163
2024-12-28 13:49:10 +00:00
Boshen
37c9959611 feat(minifier): normalize Infinity into f64::Infinity (#8148) 2024-12-28 06:05:04 +00:00
Yuichiro Yamashita
5234d964fb
feat(linter): implement eslint/no-nested-ternary (#8150)
implement: https://eslint.org/docs/latest/rules/no-nested-ternary

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-12-27 23:44:44 +00:00
Anson Heung
1c5db72986
feat(linter): implement eslint/no-labels (#8131)
Implements [eslint/no-labels](https://eslint.org/docs/latest/rules/no-labels) rule.

Part of #479
2024-12-27 15:30:14 +00:00
Boshen
8fb71f518f feat(minifier): minify string PropertyKey (#8147) 2024-12-27 15:09:41 +00:00
camc314
79af10070d fix(semantic): reference flags not correctly resolved when after an export stmt (#8134)
fixes https://github.com/oxc-project/oxc/issues/7879#issuecomment-2562574889

TLDR is curently here:

cdd121bfa4/crates/oxc_semantic/src/builder.rs (L2130-L2135)

`self.current_reference_flags.is_empty()` is not empty, which causes the current ref flags to be used (this is incorrect, we should be using a fresh version of reference flags). Buy setting ref flags to `None` on exit export node, this issue is avoided

`export` **BEFORE** the reference ( incorrect reference flags)

https://playground.oxc.rs/#eNpVjjuOwzAMRK8isElj7A/YxtttkVOkkR3aECCJBskkdgzdPZISG0ilGc3DcFbooQUXJmI1q/m3bJIZmII5fHx2lg9/p4hzTXWZsCL3N+RekB3qvRUxRyKDs2I8S61cEzRA0K7Al1geWaLaGVrlCzbgXdRNS08T7mYJHfnNKdsoA3GAdrBeMDUwWRbk3Jh1adn0jtYPUMsj5hOA8vP1/QuZ6OmMI5Yx2QQX3eCebLBx9K8FlYvK5I+ebiW9InckOX4uSOkBCrdvkw==

`export` **AFTER** the reference ( correct reference flags)

https://playground.oxc.rs/#eNpVjj2uwjAQhK9ibZMmen/Sa0JHwSlonLCJLNm70a6BhMh3xzEEQeUZz6fZWaCDBlwYWaJZzN6KSaYXDqb6+m6tVLsjHQmnknfeqpoDs8EpIp208Et6Q+I8Yum5ffTcqh3UwNAsIGdaH50p2gmaKGeswTuKm9aOR3yZObTsNxfFkvYsAZreesVUw2hFUXJj1mvLpl9o+YBoZcB8AlD/fn7/IRMdn3DAdUw2wZHr3YMNlgb/XFA4isL+4Pm6pheUljXHjwUp3QEtmnBd

this PR fixes this issue by resetting the reference flags after exising an export stmt
2024-12-27 14:20:17 +00:00
翠 / green
74572de625
fix(ecmascript): incorrect to_int_32 value for Infinity (#8144)
https://tc39.es/ecma262/#sec-toint32
Infinity should return `0` when passed to `ToInt32` abstract operation.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-27 21:48:25 +08:00
翠 / green
6615e1ea93
feat(minifier): constant fold instanceof (#8142) 2024-12-27 21:45:31 +08:00
Boshen
75264ed7d6 refactor(minifier): clean up try_optimize_block (#8139) 2024-12-27 06:46:21 +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
ad61e70186 fix(codegen): print if else without block with proper indentation (#8135) 2024-12-27 00:39:52 +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
04c7d38287
chore(semantic): use assert_eq! instead of assert! (crates/oxc_semantic/src/scope.rs) (#8128)
related to https://github.com/oxc-project/oxc/pull/8124
2024-12-26 22:14:33 +08:00
Yuichiro Yamashita
eb0f57f40f
chore(semantic): use assert_eq! instead of assert! (crates/oxc_semantic/src/lib.rs) (#8127)
related to https://github.com/oxc-project/oxc/pull/8124
2024-12-26 13:54:21 +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
Yuichiro Yamashita
093ddd6f4d
chore(ast): use assert_eq! instead of assert! (crates/oxc_ast/src/lib.rs) (#8125)
related to https://github.com/oxc-project/oxc/pull/8124
2024-12-26 13:52:55 +00:00
Yuichiro Yamashita
777e13c534
chore(linter): use assert_eq! instead of assert! (#8124)
This ensures that both the expected and actual values are printed in the
log when the test fails.
2024-12-26 20:21:01 +08: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
c22062bab3 refactor(minifier): cleanup peephole_minimize_conditions (#8114) 2024-12-25 15:47:42 +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
oxc-bot
5a1311e76c
release(crates): v0.44.0 (#8110)
## [0.44.0] - 2024-12-25

- ad2a620 ast: [**BREAKING**] Add missing
`AssignmentTargetProperty::computed` (#8097) (Boshen)

### Features

- c2daa20 ast: Add `Expression::into_inner_expression` (#8048)
(overlookmotel)
- 618b6aa codege: Minify whitespace in object getter / setter (#8080)
(Boshen)
- 4727667 codegen: Minify arrow expr `(x) => y` -> `x => y` (#8078)
(Boshen)
- 0562830 codegen: Minify string with backtick when needed (#8095)
(Boshen)
- 6237c05 codegen: Minify more whitespace (#8089) (Boshen)
- 6355b7c codegen: Minify `export { 's' as 's' }` -> `export { 's' }`
(#8093) (Boshen)
- fccfda9 codegen: Minify `class{static[computed]}` (#8088) (Boshen)
- f873139 codegen: Minify `for (_ of [])` -> `for(_ of[])` (#8086)
(Boshen)
- 8b8cbcd codegen: Minify `case "foo"` -> `case"foo"` (#8085) (Boshen)
- 414c118 codegen: Minify `yield "s"` -> `yield"s"` (#8084) (Boshen)
- f8f067b codegen: Minify class method `async*fn(){}` (#8083) (Boshen)
- 1d5ae81 codegen: Minify `const [foo] = bar` -> `const[foo]=bar`
(#8079) (Boshen)
- e3f78fb codegen: `new Foo()` -> `new Foo` when minify (#8077) (Boshen)
- d84d60a codegen: Minify numbers with large exponents (#8074) (Boshen)
- 373279b codegen: Balance string quotes when minify whitespace (#8072)
(Boshen)
- 5397fe9 minifier: Constant fold `undefined?.bar` -> `undefined`
(#8075) (Boshen)
- 1932f1e minifier: Fold `foo === undefined || foo === null` (#8063) (翠
/ green)
- 11c4bd8 span: Implement source type `{file basename}.d.{extension}.ts`
(#8109) (Boshen)
- be4feb4 syntax: Add `SymbolId::new` method (#8041) (overlookmotel)
- e632a7b transformer: Remove typescript symbols after transform (#8069)
(Boshen)

### Bug Fixes

- bdc241d codegen: Disallow template literals in object property key
(#8108) (Boshen)
- 728ed20 codegen: Print `yield * ident` correctly (Boshen)
- b605baa minifier: Constant fold strings with tab char (#8096) (Boshen)
- de82492 parser: Report syntax errors for missing constructor
implementations (#8081) (camc314)
- 55d6eb9 parser: Disallow type parameters on class constructors (#8071)
(injuly)
- be2c60d parser: Parse `import source from from 'mod'` (#8056) (Boshen)
- 708e9cf semantic: Report errors for missing class method impls (#8082)
(camc314)
- 3057686 transformer/class-properties: Unwrap parenthesised expressions
(#8049) (overlookmotel)
- e67cd05 transformer/class-properties: Correctly resolve private fields
pointing to private accessors (#8047) (overlookmotel)
- 6b08c6e transformer/class-properties: Correctly resolve private fields
pointing to private methods (#8042) (overlookmotel)
- 274f117 transformer/nullish-coalescing: Use correct scope id for
binding (#8053) (camc314)

### Performance

- 78d2e83 sourcemap: Improve perf of `search_original_line_and_column`
(#7926) (Cameron)

### Refactor

- 7110c7b codegen: Add `print_quoted_utf16` and `print_unquoted_utf16`
methods (#8107) (Boshen)
- 8b54d89 minifier: Remove parens must happen on enter (#8060) (Boshen)
- 7cb84f3 minifier: Only minify on ast node exit (#8059) (Boshen)
- 77d845a minifier: Fuse DCE AST passes (#8058) (Boshen)
- 6123f5e minifier: Fold statements on exit (#8057) (Boshen)
- cbd5169 transformer/class-properties: Do not recreate private field if
not transforming it (#8044) (overlookmotel)
- 98e8a72 transformer/class-properties: Do not take mut ref when immut
ref will do (#8040) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-25 21:03:09 +08: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
bdc241d41d fix(codegen): disallow template literals in object property key (#8108) 2024-12-25 11:22:54 +00:00
Boshen
7110c7b94c refactor(codegen): add print_quoted_utf16 and print_unquoted_utf16 methods (#8107) 2024-12-25 09:19:55 +00:00
Boshen
47276679f5 feat(codegen): minify arrow expr (x) => y -> x => y (#8078) 2024-12-24 14:25:01 +00:00
Boshen
728ed20c1c
fix(codegen): print yield * ident correctly 2024-12-24 21:57:58 +08:00
Boshen
0562830549 feat(codegen): minify string with backtick when needed (#8095) 2024-12-24 13:39:31 +00:00
Boshen
ad2a620d61 fix(ast)!: add missing AssignmentTargetProperty::computed (#8097) 2024-12-24 13:27:00 +00:00
Boshen
b605baa4ac fix(minifier): constant fold strings with tab char (#8096) 2024-12-24 12:15:06 +00:00