Boshen
c479a58718
feat(napi/parser): expose dynamic import expressions ( #8540 )
...
closes #8369
2025-01-16 22:25:22 +08:00
overlookmotel
7066d1cc4f
feat(ast, span, syntax, regular_expression)!: remove ContentHash ( #8512 )
...
#8483 removed codegen-ed impls of `ContentHash` for AST nodes, because `ContentHash` is not useful. Complete the removal by removing `ContentHash` trait definition, and all remaining references to it.
2025-01-15 15:01:14 +00:00
Boshen
7eb6ccde66
feat(ast)!: remove unused and not useful ContentHash ( #8483 )
...
`ContentEq` is preferred.
2025-01-14 09:53:27 +00:00
Boshen
c0a3ddac28
fix(minifier): instanceof has error throwing side effect ( #8378 )
2025-01-09 06:49:27 +00:00
sapphi-red
ec88c68c28
feat(minifier): compress a || (a = b) to a ||= b ( #8315 )
...
Compress `a || (a = b)` to `a ||= b` and for other logical operators that are possible to.
I didn't find other minifiers doing this, but this is safe for identifiers. [Quoting MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment#description ):
> Logical OR assignment short-circuits, meaning that `x ||= y` is equivalent to `x || (x = y)`, except that the expression x is only evaluated once.
I actually checked the spec and the only difference was that `Let lRef be ? Evaluation of LeftHandSideExpression` was done twice. Evaluating an IdentifierReference is idempotent so it should be safe to do this compression.
References:
- [Spec of `&&=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-assignment-operators:~:text=Return%20r.-,AssignmentExpression,7.%20Return%20rVal.,-AssignmentExpression )
- [Spec of `=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#prod-AssignmentExpression:~:text=Runtime%20Semantics%3A%20Evaluation-,AssignmentExpression,6.%20Return%20rVal.,-AssignmentExpression )
- [Spec of `&&`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators:~:text=Runtime%20Semantics%3A%20Evaluation-,LogicalANDExpression,5.%20Return%20%3F%C2%A0GetValue(rRef).,-LogicalORExpression )
I think this is safe for `a.b || (a.b = foo)` as well because the number of `GetValue` and `SetValue` does not change, but I didn't include that in this PR.
2025-01-07 23:19:52 +00:00
sapphi-red
e6fe84d674
feat(minifier): compress a = a + b to a += b ( #8314 )
...
Compress `a = a + b` to `a += b` and for other binary operators that are possible to.
2025-01-07 23:19:50 +00:00
camc314
7f19211736
feat(minifier): minimize unary expression statements ( #8256 )
...
`delete` cannot be minified as it may have side effect.
2025-01-06 02:21:24 +00:00
Boshen
41ddf60ab0
feat(minfier): add CompressOptions::target ( #8179 )
2024-12-29 12:27:32 +00:00
Boshen
2331ea85d9
feat(minifier): typeof foo === 'number' => typeof foo == 'number' ( #8112 )
2024-12-25 14:52:58 +00:00
overlookmotel
be4feb4ad7
feat(syntax): add SymbolId::new method ( #8041 )
...
Add `SymbolId::new` method, same as `ScopeId::new`. The advantage over `SymbolId::from_usize` is that `new` can be a `const` method.
2024-12-21 10:10:56 +00:00
Boshen
e7476a1a28
refactor(semantic): remove serialize ( #8015 )
2024-12-19 09:51:12 +00:00
overlookmotel
84b75a0e5f
refactor(semantic)!: remove ScopeFlags::Modifiers ( #7935 )
...
#7932 removed the only usage of `ScopeFlags::Modifiers`. So we don't need it any more. Remove it.
2024-12-16 12:15:12 +00:00
overlookmotel
3858221f45
refactor(global): sort imports ( #7883 )
...
Pure refactor. Re-order imports for clarity:
1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules
This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.
`cargo +nightly fmt` (#7877 ) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
Boshen
7fb9d47460
style(rust): cargo +nightly fmt ( #7877 )
2024-12-14 06:03:31 +00:00
overlookmotel
8cf9766be3
refactor(semantic, syntax, wasm): remove #![allow(non_snake_case)] ( #7863 )
...
`#![allow(non_snake_case)]` was required in files using `#[derive(Tsify)]`, as a bug in Rust Analyser caused erroneous warnings. This appears to be fixed now, so we can remove these `#![allow]` attributes.
2024-12-14 01:52:32 +00:00
Dunqing
0f367e5ab6
refactor(semantic): improve the logic of resolving references to be cleaner ( #7829 )
...
fine-tuning the logic, reducing unnecessary calls, and early return if it doesn't resolve. Also, add many comments to describe what code does.
2024-12-13 09:08:44 +00:00
Boshen
00fea9285b
feat(napi/parser): expose span positions of import.meta ( #7677 )
2024-12-05 11:03:52 +00:00
Boshen
b8dc333ed4
feat(syntax): add ExportEntry::is_type ( #7676 )
2024-12-05 09:02:18 +00:00
Boshen
7c62a33a06
feat(napi/parser): return esm info ( #7602 )
...
The parser now returns import / export statement information, which can be used for parser plugins.
2024-12-03 11:21:54 +00:00
Boshen
33e5a49c78
feat(syntax): add statement span to ImportEntry and ExportEntry ( #7583 )
2024-12-02 14:20:30 +00:00
Boshen
f0e7acc68b
refactor(syntax): change ModuleRecord::not_esm to has_module_syntax ( #7579 )
2024-12-02 09:32:57 +00:00
Boshen
18519dea33
refactor(syntax): remove ModuleRecord::export_default ( #7578 )
...
This value can be derived.
2024-12-02 09:17:57 +00:00
Boshen
d476660b0b
refactor(syntax): remove ModuleRecord::exported_bindings_duplicated because it is a syntax error ( #7577 )
2024-12-02 08:48:01 +00:00
Boshen
17663f55d3
refactor(syntax): remove ModuleRecord::export_default_duplicated because it is a syntax error ( #7576 )
2024-12-02 08:19:59 +00:00
Boshen
79014ffb1d
refactor(syntax): clean up ModuleRecord ( #7568 )
2024-12-01 14:49:04 +00:00
Boshen
c2ced15dfd
feat(parser,linter)!: use a different ModuleRecord for linter ( #7554 )
...
The parser returns a simple `ModuleRecord` that is allocated in the arena for performance reasons.
The linter uses a more complicated, `Send` + `Sync` `ModuleRecord` that will hold more cross-module information.
The next step is to return more esm information from the parser to eliminated the need of the `oxc_module_lexer` crate.
2024-11-30 16:02:01 +00:00
Boshen
8a788b8f4b
feat(parser)!: Build ModuleRecord directly in parser ( #7546 )
...
This has the benefit of:
* expose dynamic import / import meta info from parser
* 1 less ast shallow in semantic builder
* no ast walk in oxc's module lexer
* some more benefits coming soon
2024-11-29 14:50:42 +00:00
Boshen
d942a8d41a
chore: Rust v1.83.0 changes ( #7535 )
...
This PR does not upgrade rustc. Only changes are applied.
We cannot upgrade to the lastet Rust version yet due to wasm-bindgen
breaking some generated types.
THere's also some elided lifetimes in `**/generated/**`, which requires
modification to ast tools.
2024-11-29 11:59:45 +08:00
overlookmotel
4a98230f07
perf(syntax): use FxDashMap for exported bindings ( #7525 )
...
Same as #7521 . Use `FxDashMap` instead of plain `DashMap` for hash map storing exported bindings.
2024-11-28 12:15:11 +00:00
overlookmotel
169b8bfa5c
refactor(linter, syntax): introduce type alias FxDashMap ( #7520 )
...
Pure refactor. Introduce a type alias `FxDashMap<K, V>` for `DashMap<K, V, FxBuildHasher>`. This makes the code using it clearer.
2024-11-28 11:45:14 +00:00
Dunqing
d7d073578d
refactor(semantic): remove SymbolFlags::TypeLiteral ( #7415 )
2024-11-25 11:34:34 +00:00
Dunqing
27b2268a6c
refactor(semantic)!: remove SymbolFlags::Export ( #7414 )
...
close : #7338
close : #7344
The `SymbolFlags::Export` is Initially used to solve `ExportSpecifier` that is not `IdentifierReference` that causes we cannot determine whether a Binding is not used everywhere by `Semantic`.
Since #3820 this problem is solved, so we don't need `SymbolFlags::Export` no longer. Also, removing this can help us easier to pass the `Semantic` check in `Transformer`
2024-11-22 09:17:37 +00:00
Dunqing
6f0fe38bff
fix(semantic)!: correct all ReferenceFlags::Write according to the spec ( #7388 )
...
close #7323
According to the specification re-design the JavaScript-part ReferenceFlags inferring approach.
* https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-postfix-increment-operator-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-runtime-semantics-restdestructuringassignmentevaluation
* ... See references of https://tc39.es/ecma262/#sec-putvalue
### Changes
1. The left-hand of `AssignmentExpression` is always `ReferenceFlags::Write`
```js
let a = 0;
console.log(a = 0);
^ Write only
```
2. The `argument` of `UpdateExpression` is always `ReferenceFlags::Read | Write`
```js
let a = 0;
a++;
^ Read and Write
```
This change might cause some trouble for `Minfier` to remove this code, because ‘a’ is not used elsewhere. I have taken a look at `esbuild` and `Terser`. Only the `Terser` can remove this code.
2024-11-22 06:08:30 +00:00
overlookmotel
b3d5802ef1
docs(syntax): more comments for ReferenceFlags ( #7392 )
...
Add more docs to `ReferenceFlags`, mainly to include the runtime test in https://github.com/oxc-project/oxc/issues/5165#issuecomment-2488333549 .
2024-11-21 11:20:28 +00:00
Boshen
9b9d02078c
docs(semantic): document the meaning of ReferenceFlags::Read and Write ( #7368 )
...
closes #5165
2024-11-20 09:18:25 +00:00
overlookmotel
c335f92ada
perf(syntax): reorder operator enum variants ( #7351 )
...
Re-order enum variants of `AssignmentOperator`, `BinaryOperator` and `UnaryOperator`.
* `Exponential` moved to after `Remainder` (so with the rest of the arithmetic operators).
* `Shift*` operators follow arithmetic operators.
* `AssignmentOperator::Bitwise*` ops moved to before `Logical*` ops (so all ops which correspond to `BinaryOperator`s are together).
* `*Or` always before `*And`.
* Plus/Addition always before Minus/Subtraction.
The purpose is to make the various methods on these types maximally efficient:
1. Group together variants so that `AssignmentOperator::is_*` methods can be executed with the minimum number of operations (essentially `variant - min <= max`).
2. Align the variants of `AssignmentOperator` and `BinaryOperator` so that conversion methods added in #7350 become very cheap too (essentially `if variant - min <= max { Some(variant + offset) } else { None }`).
2024-11-19 01:23:28 +00:00
overlookmotel
2534cdecb7
feat(syntax): add AssignmentOperator::to_logical_operator and to_binary_operator methods ( #7350 )
...
Add methods to convert `AssignmentOperator` to `LogicalOperator` or `BinaryOperator`. e.g. `+=` -> `+`, `&&=` -> `&&`.
2024-11-19 01:12:11 +00:00
overlookmotel
b5a202711c
style(syntax): improve formatting ( #7349 )
...
Style nit. Adjust formatting.
2024-11-18 22:26:30 +00:00
ottomated
169fa22350
feat(ast_tools): Default enums to rename_all = "camelCase" ( #6933 )
...
Part of #6347
2024-10-28 01:39:25 +00:00
Boshen
423d54cb74
refactor(rust): remove the annoying clippy::wildcard_imports ( #6860 )
2024-10-24 13:57:19 +00:00
ottomated
1145341a92
feat(ast_tools): output typescript to a separate package ( #6755 )
...
Part of #6347 .
Moves typescript logic from derive_estree into a new ast_tools generator.
2024-10-24 13:08:57 +00:00
overlookmotel
85e69a11ef
refactor(ast_tools): add line breaks to generated code for ESTree derive ( #6680 )
...
Follow-on after #6404 . Style nit. Add line breaks to generated code, to make it easier to read.
2024-10-19 19:50:13 +00:00
overlookmotel
ad8e293197
refactor(ast_tools): shorten generated code for impl Serialize ( #6684 )
...
Follow-on after #6404 . Shorten generated code for `impl Serialize`.
2024-10-19 19:50:12 +00:00
overlookmotel
9ba2b0e3a3
refactor(ast_tools): move #[allow] attrs to top of generated files ( #6679 )
...
Follow-on after #6404 . Shorten generated code for `impl Serialize` by moving `#[allow]` attrs to top of file.
2024-10-19 19:50:12 +00:00
ottomated
e310e52ca2
feat(parser): Generate Serialize impls in ast_tools ( #6404 )
...
Beginning of #6347 . Instead of using serde-derive, we generate
`Serialize` impls manually.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-10-19 09:38:44 +01:00
Boshen
2ce3e5fefc
fix(identifier): add ZWSP to is_irregular_whitespace ( #6662 )
...
closes #6646
2024-10-18 22:20:02 +00:00
magic-akari
1d3d256db3
fix(transformer): Correctly trim JSX ( #6639 )
...
- Closes : #6638
2024-10-17 14:41:02 +00:00
DonIsaac
335b7f22c5
docs(syntax): enable lint warnings on missing docs, and add a lot of documentation ( #6611 )
...
Part of https://github.com/oxc-project/backlog/issues/130
I didn't add doc comments to everything; I'm missing context for module-related data types and I have other things to do :P
2024-10-15 22:50:45 +00:00
Boshen
856cab5000
refactor(ecmascript): move ToInt32 from oxc_syntax to oxc_ecmascript ( #6471 )
2024-10-12 09:29:46 +00:00
overlookmotel
03bc041ddf
refactor(syntax): remove some unsafe code creating IDs ( #6324 )
2024-10-06 23:26:26 +00:00