There are many cases in lint rules where we want to see if a symbol is a
function by checking its SymbolFlags. This is currently not fully possible,
since variables assigned to arrow functions are not distinguished from any other
kind of variable. This PR adds `SymbolFlags::ArrowFunction` for variables that
are initialized to arrow functions. Symbols that are re-assigned to arrow
functions will not have this flag, but this is acceptable for lint rules.
close: #4906
Port completely `gatherNodeParts` from `Babel`. But we don't have test cases to test it, we can find the bugs(if any) after we use this API in transformer plugins
related: #4937
There are no tests/snapshots updates and seems we don't have a way to
test it until #4937 is merged. But I tested it locally and it worked!
Before, this
```ts
export class Bux {
private constructor(
public readonly prop: number = 0,
private readonly prop2: number = 1,
readonly prop3: number = 1,
) {}
}
```
would be emitted as
```ts
export declare class Bux {
private constructor();
}
```
Now it will be emitted as
```ts
export declare class Bux {
readonly prop: number;
private readonly prop2;
readonly prop3: number;
private constructor();
}
```
Co-authored-by: MichaelMitchell-at <=>
closes https://github.com/oxc-project/oxc/issues/4790
@overlookmotel enjoy ... take a look at the snapshots and probably nothing else.
The snapshots are minimal right now, but it's already showing symbols from import specifiers are not being removed. We can iterate on the snapshot representation to aid debugging later.
I'll extend this to `transformer_conformance` and `oxc-monitor` in an up coming PR.
close: #4870
I added the `move_identifier_reference` and `move_member_expression` methods used to take ownership in `ast_builder_impl`. This way can let us get rid of `ast.copy`.
Another possible approach is to add `get_expression_owner` to `SimpleAssignmentTarget` and a `get_inner_expression_owner` method to `Expression`. And add an `into_xxxxx` method for `inherit_variants` macro
The implementation looks like this
```rs
let Some(expression) = self.get_expression_owner() else { return; }
match expr.get_inner_expression_owner() {
Expression::Identifier(ident) => {
*target = self.ctx.ast.simple_assignment_target_from_identifier_reference(ident);
}
inner_expr @ match_member_expression!(Expression) => {
*target = SimpleAssignmentTarget::from(
inner_expr.into_member_expression()
);
}
_ => (),
}
```
Add test cases that cover #4888. I can't reproduce the issue this way,
so I'll try running oxlint as a CLI instead. These test cases will be
useful to have in our repo anyways.
close: #3943
## Further improvements
There is a double visit here. We need to collect all react hooks calling in `Function` and `ArrowFunctionExpression`. If we want to remove this implementation, we may wait for #4188.
d797e595d2/crates/oxc_transformer/src/react/refresh.rs (L744-L947)
## Tests
All tests copy from https://github.com/facebook/react/blob/main/packages/react-refresh/src/__tests__/ReactFresh-test.js
There are still 4 tests that have not been passed
**1. refresh/can-handle-implicit-arrow-returns/input.jsx**
Related to #4767. transform correct, just output doesn't match the expected output
**2. refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx**
**3. refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx**
Blocked by #4746
**4. refresh/supports-typescript-namespace-syntax/input.tsx**
oxc transforms ts to js first, so probably we can ignore this case. If we really want to pass this test, we also need to turn off `TypeScript` plugin.
## What's next?
### Options:
1. Support transform `refresh_reg` and `refresh_sig` options to `MemberExpression`. Currently `import.meta.xxxx` still is an `Identifier`
2. Support `emit_full_signatures` option
### Other
NAPI, testing in `monitor-oxc`, etc..
`AstBuilder::copy` is completely unsound (#3483), and we need to remove it. Make it an `unsafe` function to discourage any further usage of it in meantime.
related: #4804
needs from: #4876
The `clone_identifier_reference` method is used to clone an `IdentifierReference` and create a `Reference` and insert it to `SymbolTable`'s `resolved_references`.
The reason we need this is because we need to make sure that `IdentifierReference`'s `reference_id` is unique
We mostly use `allocator` as var name for an `Allocator`, but in some places used the shorter name `alloc`. Use `allocator` everywhere for consistency.
`BoundIdentifier` helper previously only had methods to create a
read-only `IdentifierReference`. Add methods to also create write-only
or read-write `IdentifierReference`s.