Commit graph

4155 commits

Author SHA1 Message Date
Boshen
746f7b3a02 refactor(minifier): align code with closure compiler (#5717)
also fixes #4341
2024-09-12 04:18:41 +00:00
Boshen
4bdc202325 refactor(rust): remove some #[allow(unused)] (#5716) 2024-09-12 02:19:01 +00:00
overlookmotel
c3dd2a048d perf(ast)!: revert: reduce byte size of TaggedTemplateExpression::quasi by Boxing it (#5679) (#5715)
As discussed in #5601, there is little benefit to reducing type sizes for the sake of it. In this case, the `quasi` field in not in an `Option`, so putting it in a `Box` does not save data, only moves where that data is stored, and introduces pointer-indirection.
2024-09-12 00:53:20 +00:00
overlookmotel
a362f51523 feat(index): add IndexVec::shrink_to (#5713)
Add `IndexVec::shrink_to` to match `std::vec::Vec::shrink_to`.
2024-09-11 22:57:58 +00:00
overlookmotel
e02621d2d1 refactor(semantic): re-order use statements (#5712)
Pure refactor. Re-order `use` statements in `oxc_semantic` to follow this order:

1. `std`
2. External crates.
3. `oxc_*` crates.
4. Local crate.
5. `super`
6. `mod`

This is intended to be in order from "furthest above" to "furthest below".
2024-09-11 20:41:49 +00:00
overlookmotel
ac6203c891 refactor(semantic): move Counts code into counter module (#5710)
Pure refactor. Move code for counting nodes etc, and verifying counts, into `counter` module.
2024-09-11 20:41:48 +00:00
overlookmotel
339fcfc8be refactor(semantic): rename Counts in transform checker (#5709)
Pure refactor. Just renaming.
2024-09-11 20:41:48 +00:00
Na'aman Hirschfeld
9ca2593aaa
feat(linter): eslint/sort-keys (#4845)
This PR adds the `eslint/sort-keys` implementation as part of #479 

Note: two tests are commented out. I was not able to model this behavior
properly. I would be happy to have some assistance there.
2024-09-11 13:10:55 -04:00
Boshen
21e2df57a0 refactor(minifier): replace VisitMut with Traverse for inject and define plugins (#5705)
closes #5704
2024-09-11 16:13:10 +00:00
Boshen
945d2744ae
chore(linter: fix snapshot 2024-09-11 21:07:23 +08:00
Boshen
64f9575ed5
docs(linter): add plugin usage to example with configuration
closes #5400
2024-09-11 20:58:29 +08:00
overlookmotel
d8ec78192e refactor(semantic): remove record_ast_node call for Program (#5701)
Remove a tiny bit of dead code from `SemanticBuilder`.

`record_ast_node` does nothing if `ast_node_records` is empty. It is always empty when visiting `Program`, so is a no-op.
2024-09-11 11:31:20 +00:00
overlookmotel
1857ff09eb style(semantic): rename vars for node IDs (#5699)
`test_node_id` not `test_node` to better describe what these vars contain.
2024-09-11 10:55:42 +00:00
dalaoshu
d18c896a2c
perf(rust): use cow_utils instead (#5664)
Related to #5586 and #5662

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-11 18:39:30 +08:00
heygsc
5482e73189
feat(prettier): add assignment/sequence (#5694)
test:
https://github.com/prettier/prettier/blob/main/tests/format/js/assignment/sequence.js


snap:https://github.com/prettier/prettier/blob/main/tests/format/js/assignment/__snapshots__/format.test.js.snap#L870-L888

code:
https://github.com/prettier/prettier/blob/main/src/language-js/needs-parens.js#L790-L796
2024-09-11 18:19:09 +08:00
oxc-bot
a727ee8aca
release(oxc): crates v0.28.0 (#5696)
## [0.28.0] - 2024-09-11

- afc4548 ast: [**BREAKING**] Educe byte size of
`TaggedTemplateExpression::quasi` by `Boxing` it (#5679) (Boshen)

- 7415e85 ast: [**BREAKING**] Reduce byte size of
`TSImportType::attributes` by `Box`ing it (#5678) (Boshen)

- ee4fb42 ast: [**BREAKING**] Reduce size of `WithClause` by `Box`ing it
(#5677) (Boshen)

- 1fa3e56 semantic: [**BREAKING**] Rename `SymbolTable::iter` to
`symbol_ids` (#5621) (overlookmotel)

- 96a1552 semantic: [**BREAKING**] Remove `SymbolTable::iter_rev`
(#5620) (overlookmotel)

- 4a8aec1 span: [**BREAKING**] Change `SourceType::js` to
`SourceType::cjs` and `SourceType::mjs` (#5606) (Boshen)

- 603817b oxc: [**BREAKING**] Add `SourceType::Unambiguous`; parse `.js`
as unambiguous (#5557) (Boshen)

- b060525 semantic: [**BREAKING**] Remove `source_type` argument from
`SemanticBuilder::new` (#5553) (Boshen)

### Features

- 2da5ad1 ast: Add `JSXElementName::get_identifier` method (#5556)
(overlookmotel)
- 2016bae coverage: Add regular expression idempotency test (#5676)
(Boshen)
- 68c3cf5 minifier: Fold `void 1` -> `void 0` (#5670) (Boshen)
- c6bbf94 minifier: Constant fold unary expression (#5669) (Boshen)
- 86256ea minifier: Constant fold `typeof` (#5666) (Boshen)
- e698418 napi/transform: Align output `SourceMap` with Rollup's
`ExistingRawSourceMap` (#5657) (Boshen)
- aba9194 napi/transform: Export react refresh options (#5533)
(underfin)
- 642295c semantic: Add `SymbolTable::delete_resolved_reference` method
(#5558) (overlookmotel)
- b3cbd56 span: `format_compact_str!` macro (#5610) (overlookmotel)
- 95a6d99 transformer: Enable the react refresh plugin in enable_all
(#5630) (Dunqing)
- 7b543df transformer/react: Handle `refresh_sig` and `refresh_reg`
options correctly (#5638) (Dunqing)
- 17226dd traverse: Add methods for deleting references (#5559)
(overlookmotel)

### Bug Fixes

- d62defb codegen: Do not print trailing commas for `ArrayExpression`
(#5551) (Boshen)
- 1bc08e2 coverage: Parse babel unambiguously (#5579) (Boshen)
- 28b934c coverage: Apply `always_strict` to test262 and typescript per
the specifcation (#5555) (Boshen)
- b9bf544 isolated-declarations: False positive for setter method in
`interface` (#5681) (Dunqing)
- 6e8409a isolated-declarations: Bindings referenced in
`TSModuleDeclaration` are removed incorrectly (#5680) (Dunqing)
- b8f8dd6 minifier/replace_global_defines: Do not replace shadowed
identifiers (#5691) (Boshen)
- 304ce25 regular_expression: Keep LegacyOctalEscape raw digits for
`to_string` (#5692) (leaysgur)
- 0511d55 regular_expression: Report more MayContainStrings error in
(nested)class (#5661) (leaysgur)
- 41582ea regular_expression: Improve RegExp `to_string()` results
(#5635) (leaysgur)
- 28aad28 regular_expression: Handle `-` in `/[\-]/u` as escaped
character (#5631) (leaysgur)
- f9e3a41 semantic: Bind `SymbolId` to function name in `if (foo)
function id() {}` (#5673) (Boshen)
- f49e6eb span: Treat `.js` as `module` file (reverts the previous
breaking change) (#5612) (Boshen)
- 919d17f transform_conformance: Only print semantic mismatch errors
when output is correct (#5589) (Boshen)
- 505d064 transformer: JSX transform delete references for
`JSXClosingElement`s (#5560) (overlookmotel)
- 9b7ecc7 transformer: RegExp transform only set span on final
expression (#5508) (overlookmotel)
- d1ece19 transformer: RegExp transform handle `Term::Quantifier`
(#5501) (overlookmotel)
- a1afd48 transformer/react: Incorrect scope_id for var hoisted in fast
refresh plugin (#5695) (Dunqing)
- f2f5e5a transformer/react: Missing scope_id for function in fast
refresh plugin (#5693) (Dunqing)
- a891c31 transformer/react: Refresh plugin has incorrect reference
flags (#5656) (Dunqing)
- 3e8b96f transformer/react: The refresh plugin cannot handle member
expressions with React hooks (#5655) (Dunqing)
- 0739b5f transformer/react: Don't transform declaration of function
overloads (#5642) (Dunqing)
- 3bf6aaf transformer/react: Support `emit_full_signatures` option in
refresh plugin (#5629) (Dunqing)
- 36d864a transformer/react: Don't transform if the variable does not
have a value reference (#5528) (Dunqing)

### Performance

- e8013d2 traverse: Faster string operations generating UIDs (#5626)
(overlookmotel)
- 4996874 traverse: `generate_uid` cache available binding names (#5611)
(overlookmotel)

### Documentation

- fefbbc1 sourcemap: Add trailing newline to README (#5539)
(overlookmotel)
- 9282647 transformer: Comment on RegExp transform for potential
improvement (#5514) (overlookmotel)
- 1c051ae traverse: Correct code comment 2 (#5607) (overlookmotel)
- 2e24a15 traverse: Correct code comment (#5604) (overlookmotel)

### Refactor

- 14ee086 ast: Inline `AstKind::as_*` methods (#5547) (overlookmotel)
- 2de6ea0 index, traverse: Remove unnecessary type annotations (#5650)
(overlookmotel)
- 0ac420d linter: Use meaningful names for diagnostic parameters (#5564)
(Don Isaac)
- 2da42ef regular_expression: Improve AST docs with refactoring
may_contain_strings (#5665) (leaysgur)
- dec1395 regular_expression: Align diagnostics (#5543) (leaysgur)
- 731ffaa semantic: Compare nodes by pointer equality (#5686)
(overlookmotel)
- 067f9b5 semantic: Introduce `IsGlobalReference` trait (#5672) (Boshen)
- d22a9b7 semantic: `SymbolTable::is_empty` use `is_empty` (#5622)
(overlookmotel)
- 3d190a5 span: Move `CompactStr` into separate file (#5609)
(overlookmotel)
- 5532628 span: Put types and impl in the same mod file (Boshen)
- ce71982 transformer: Shorten code in JSX transform (#5554)
(overlookmotel)
- 758a10c transformer: RegExp transform reuse var (#5527)
(overlookmotel)
- fad0a05 transformer: RegExp transform unbox early (#5504)
(overlookmotel)
- 19cdcc5 traverse: Revert changes to `walk.rs` (#5652) (overlookmotel)-
26d9235 Enable clippy::ref_as_ptr (#5577) (夕舞八弦)

### Styling

- e52d006 traverse: Fix formatting of traverse codegen (#5651)
(overlookmotel)
- 97e99bd traverse: Remove excess line break (#5603) (overlookmotel)-
694f032 Add trailing line breaks to `package.json` files (#5542)
(overlookmotel)

### Testing

- 2e367c9 traverse: Enable tests for `oxc_traverse` crate (#5625)
(overlookmotel)- dc92489 Add trailing line breaks to conformance
fixtures (#5541) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-11 17:57:55 +08:00
Dunqing
a1afd48c68 fix(transformer/react): incorrect scope_id for var hoisted in fast refresh plugin (#5695)
Fix the last one semantic error in the fast react plugin
2024-09-11 09:02:29 +00:00
Dunqing
f2f5e5aaf5 fix(transformer/react): missing scope_id for function in fast refresh plugin (#5693)
Fix semantic error in the fast react plugin
2024-09-11 09:02:28 +00:00
Dunqing
a891c31889 fix(transformer/react): refresh plugin has incorrect reference flags (#5656)
As you see the diff
2024-09-11 07:57:17 +00:00
Dunqing
95a6d9984c feat(transformer): enable the react refresh plugin in enable_all (#5630) 2024-09-11 07:57:16 +00:00
Dunqing
3e8b96f165 fix(transformer/react): the refresh plugin cannot handle member expressions with React hooks (#5655)
The previous implementation doesn't handle nested StaticMemberExpression. For example: `A.B.C.useHook`.
2024-09-11 07:57:16 +00:00
Dunqing
0739b5f1e3 fix(transformer/react): don't transform declaration of function overloads (#5642)
Found a bug in https://github.com/oxc-project/oxc/actions/runs/10768809028/job/29858692560; We don't need to transform typescript-syntax-only function
2024-09-11 07:57:15 +00:00
Dunqing
7b543dffd9 feat(transformer/react): handle refresh_sig and refresh_reg options correctly (#5638)
In previous implementations, even if pass `import.meta.xxxx` into these options this plugin still treats them as `IdentifierReference`
2024-09-11 07:57:15 +00:00
Dunqing
3bf6aaf06a fix(transformer/react): support emit_full_signatures option in refresh plugin (#5629) 2024-09-11 07:57:14 +00:00
Boshen
b8f8dd6612 fix(minifier/replace_global_defines): do not replace shadowed identifiers (#5691) 2024-09-11 07:17:17 +00:00
Dunqing
36d864a0c3 fix(transformer/react): don't transform if the variable does not have a value reference (#5528)
close: #4746

Solved the last two tests, but it's a coincidence. I've added a test to cover it.
2024-09-11 07:10:55 +00:00
leaysgur
304ce25446 fix(regular_expression): Keep LegacyOctalEscape raw digits for to_string (#5692)
Fixes #5690

- Update `CharacterKind` enum from `Octal` to `Octal1`, `Octal2` and `Octal3`
- Stylistic refactoring for `impl Display`
2024-09-11 07:07:00 +00:00
DonIsaac
9e9435f03b refactor(linter): add LintFilter (#5685)
Re-creation of #5329
2024-09-11 03:19:04 +00:00
overlookmotel
731ffaa00e refactor(semantic): compare nodes by pointer equality (#5686)
Follow up after #5673.

It's safer to compare nodes by pointer equality than by equality of `Span`s. Transformer can create multiple nodes of same type with same span.

Once nodes have node IDs, we can use them for comparison instead.

That said, `ptr::eq` is much cheaper, as it doesn't have to follow the pointers to check equality. https://godbolt.org/z/hsqaeKr5M
2024-09-11 02:12:12 +00:00
Boshen
2016bae98c feat(coverage): add regular expression idempotency test (#5676)
closes #5634
2024-09-11 02:07:42 +00:00
Dunqing
b9bf54494f fix(isolated-declarations): false positive for setter method in interface (#5681)
close: #5668
2024-09-10 16:22:08 +00:00
Dunqing
6e8409a020 fix(isolated-declarations): bindings referenced in TSModuleDeclaration are removed incorrectly (#5680)
close: #5667
2024-09-10 16:22:07 +00:00
Boshen
afc4548ef4 perf(ast)!: educe byte size of TaggedTemplateExpression::quasi by Boxing it (#5679) 2024-09-10 14:17:29 +00:00
Boshen
7415e85764 perf(ast)!: reduce byte size of TSImportType::attributes by Boxing it (#5678) 2024-09-10 14:07:51 +00:00
Boshen
ee4fb42d70 perf(ast)!: reduce size of WithClause by Boxing it (#5677)
relates #5601
2024-09-10 14:01:36 +00:00
Boshen
f9e3a41dd2 fix(semantic): bind SymbolId to function name in if (foo) function id() {} (#5673) 2024-09-10 11:05:26 +00:00
Boshen
067f9b5a6f refactor(semantic): introduce IsGlobalReference trait (#5672) 2024-09-10 10:12:08 +00:00
Boshen
68c3cf544f feat(minifier): fold void 1 -> void 0 (#5670) 2024-09-10 08:11:10 +00:00
leaysgur
2da42efb6f refactor(regular_expression): Improve AST docs with refactoring may_contain_strings (#5665)
Follow up #5661
2024-09-10 07:32:28 +00:00
Boshen
c6bbf94f4c feat(minifier): constant fold unary expression (#5669) 2024-09-10 07:18:54 +00:00
Boshen
86256ea238 feat(minifier): constant fold typeof (#5666)
closes #5628
2024-09-10 04:43:00 +00:00
DonIsaac
4f70fe5abf refactor(linter): start internal/external split of LintPluginOptions (#5660)
Re-creation of #5142
2024-09-10 03:19:05 +00:00
DonIsaac
5ae9b48509 refactor(linter): start internal/external split of OxlintOptions (#5659)
re-creation of #5141
2024-09-10 03:19:04 +00:00
leaysgur
0511d55aa8 fix(regular_expression): Report more MayContainStrings error in (nested)class (#5661)
Fixes #5632
2024-09-10 01:55:51 +00:00
heygsc
febb29f7f5
perf(formatter): use cow and put cow_ascii on clippy (#5646)
close: #5639 

part of: #5586

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-10 09:38:17 +08:00
overlookmotel
e8013d259e perf(traverse): faster string operations generating UIDs (#5626)
`get_unique_name` perform string manipulation faster, avoiding bounds checks, and use `itoa` crate for faster conversion of integers to strings for postfixes above 100.

No apparent difference on benchmarks, but I imagine that's only because it's outweighed by cost of hashing strings. If measured alone, I believe it would be a perf improvement.
2024-09-10 01:12:22 +00:00
overlookmotel
4996874dda perf(traverse): generate_uid cache available binding names (#5611)
Close #5488.

`generate_uid` previously iterated through every symbol and unresolved reference in the AST to find a unique var name. If the first var name it tried was already in use, it'd iterate again.

Instead build a hash map recording existing var names in use for every name which could clash with a UID (any var name starting with `_`). Once built, use that hash map to generate UIDs without iterating through all symbols again.

I had hoped to make `generate_uid` cheaper still by just recording the highest digits postfix for each var name, and then incrementing that postfix for each UID. i.e. if AST contains vars `_foo1` and `_foo6`, create UIDs starting at one number higher - `_foo7`, `_foo8` etc. This method would be more efficient, but unfortunately it does not match Babel, and so causes some of Babel's tests to fail.
2024-09-10 01:12:19 +00:00
overlookmotel
c8bc6f0549 refactor(linter): use std::ptr::eq (#5649)
Follow-on after #5577.

`!std::ptr::eq(x, y)` is more idiomatic than `std::ptr::from_ref(x) != std::ptr::from_ref(y)`.
2024-09-09 15:28:10 +00:00
overlookmotel
19cdcc565c refactor(traverse): revert changes to walk.rs (#5652)
Revert the changes to `oxc_traverse` made in #5577.

Those changes may well have been good, but...

The soundness of `Traverse` is a finely balanced thing, and the pointer gymnastics are subtle, so I think it's best to be extremely conservative about changes. I last ran Miri on it with the original formulation (`as *mut _` etc) and it passed. Currently it's not possible to usefully run Miri on the transformer because it contains known unsound code (#3483). So until we're able to check soundness with Miri, I think it's best to avoid changes, as it'd be easy to trigger UB unintentionally.
2024-09-09 14:48:10 +00:00
overlookmotel
2de6ea02c0 refactor(index, traverse): remove unnecessary type annotations (#5650)
Follow-on after #5577. These type annotations are not required. Probably they were suggested by clippy.
2024-09-09 14:07:56 +00:00