Commit graph

322 commits

Author SHA1 Message Date
Dunqing
3acb3f6461 fix(transformer/react): mismatch output caused by incorrect transformation ordering (#5255)
close: #4767
2024-08-29 00:38:02 +00:00
magic-akari
08dc0adeab feat(transformer): add object-spread plugin (#3133) 2024-08-28 15:57:20 +00:00
Boshen
8d6b05ca01 fix(transformer): class property with typescript value should not be removed (#5298) 2024-08-28 13:53:41 +00:00
Dunqing
5754c89b5e fix(transformer/typescript): remove accessibility from AccessorProperty (#5292)
Regression by #5290
2024-08-28 08:42:38 +00:00
Dunqing
550574982f feat(ast): add accessibility field to AccessorProperty (#5290) 2024-08-28 08:42:37 +00:00
overlookmotel
10861096e0 refactor(semantic): transform checker do not output spans in errors (#5260)
Transform checker don't output spans in errors. They're inaccurate because (a) spans refer to the source text pre-transform, and (b) most errors relate to scopes/symbols/references newly created in transformer, which have no span.
2024-08-27 11:58:21 +00:00
overlookmotel
af5713e411 refactor(semantic): transform checker continue checks if missing IDs (#5259)
Transform checker don't bail out if some IDs missing from AST. Continue to check for other problems.

Also simplify iterating over pairs of IDs.
2024-08-27 11:58:20 +00:00
overlookmotel
943454fa5e refactor(semantic): update transform checker for no conditional scopes (#5252)
All scopes are now unconditional (#5008). Update transform checker to reflect this.
2024-08-27 08:57:15 +00:00
Boshen
a17cf33dc3 refactor(semantic): remove ScopeTree::child_ids (#5232)
closes https://github.com/oxc-project/oxc/issues/5244
2024-08-27 01:49:47 +00:00
Dunqing
f8bb0222b3 fix(transformer/arrow-functions): remove SymbolFlags::ArrowFunction (#5190)
`ArrowFunction` has been transforming to `FunctionExpression`, So we should remove `SymbolFlags::ArrowFunction`
2024-08-25 10:27:00 +00:00
Dunqing
d9ba5ad022 fix(transformer/arrow-functions): correct scope for _this (#5189)
The `_this` will eventually be inserted into a `Program` or `Function`. So we have to go up to the corresponding `scope_id`
2024-08-25 10:26:59 +00:00
Dunqing
056c6679ec feat(transformer/arrow-functions): the output that uses this inside blocks doesn't match Babel (#5188)
Fixes 666282a13b/crates/oxc_transformer/src/es2015/arrow_functions.rs (L35-L62)
2024-08-25 10:26:57 +00:00
Boshen
01c0c3e4b2 feat(transformer): add remaining options to transformer options (#5169)
closes #5168
2024-08-24 14:52:03 +00:00
overlookmotel
eb71a32ee7 refactor(ci): transform conformance snapshot include when output mismatch (#5135)
Include "Output mismatch" in transform conformance snapshots when a test also fails due to scopes/symbols mismatches.

At present, many of the tests are failing on scopes/symbols mismatches, so it's hard to see from snapshots which also have an output mismatch. In particular, when working to fix scope mismatches, it's hard to notice if changes you make cause the output to be wrong. These extra messages make that visible.
2024-08-24 04:52:14 +00:00
overlookmotel
be42b1c76b fix(ci): transform conformance do not skip any errors (#5134)
Snapshots generated by transform conformance were missing a few errors (e.g. `declarations/const-enum/input.ts` at bottom of diff). Make sure all errors fail the test.
2024-08-24 04:52:11 +00:00
Dunqing
47e69a8c94 fix(transformer-optional-catch-binding): the unused binding is not in the correct scope (#5066)
Blocked by #5008

In the SemanticBuilder, we insert all CatchClause parameters in the BlockStatement scope, a child-scope of CatchClause

858f510d59/crates/oxc_semantic/src/builder.rs (L709-L718)

So we should do the same thing in this plugin, but because CatchClause has no parameters, SemanticBuilder doesn't create scope for `CatchClause`. This cause we cannot find the `BlockStatement` scope_id.

This PR has changed to the correct logic. Just to wait #5008 solved
2024-08-23 13:02:53 +00:00
overlookmotel
d304d6f973 refactor(semantic)!: always create a scope for CatchClause (#5109)
Part of #5008. Make scope for `CatchClause` unconditional. i.e. always create a scope, even if there is no catch parameter.
2024-08-23 08:30:27 +00:00
overlookmotel
91343913ca fix(semantic): transform checker check unresolved references (#5096)
Transform checker check root unresolved references.

The transform checker is now checking pretty much everything it can.

Only fields of `ScopeTree` and `SymbolTable` that it's *not* checking are those which contain `AstNodeId`s, because transformer does not create node IDs at present:

* `ScopeTree::node_ids`
* `SymbolTable::declarations`
* `Reference::node_id`

Checking also only proceeds in "from AST" direction.

i.e. for each `SymbolId` which appears in the AST, we check everything about that symbol. But we *don't* go through all the "rows" in `SymbolTable` and check if there are any extra symbols in the table which aren't in the AST.

Presumably transformer will leave a lot of old symbols lying around in `SymbolTable` (ditto scopes and references). We'd need to add `ScopeFlags::Deleted`, `SymbolFlags::Deleted` and `ReferenceFlags::Deleted` for the transformer to be able to "delete" existing symbols.
2024-08-23 07:52:30 +00:00
overlookmotel
c57e078c71 fix(semantic): transform checker check unbound references (#5093) 2024-08-23 08:37:48 +01:00
Boshen
aa7718ab7b feat(transform_conformance): show printed output alongside with errors (#5105)
closes #5098

```
cargo run -p oxc_transform_conformance -- --filter logical-assignment/arrow-functions-transform/input.js

Input:

var a;
a ||= () => {};
a &&= () => {};
a ??= () => {};

Expected:

var a;
a || (a = () => {});
a && (a = () => {});
a ?? (a = () => {});

Transformed:

var a;
a || (a = () => {});
a && (a = () => {});
a ?? (a = () => {});

Errors:

  x Symbol reference IDs mismatch:
  | after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1),
  | ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5),
  | ReferenceId(6), ReferenceId(7), ReferenceId(8)]
  | rebuilt        : SymbolId(0): [ReferenceId(0), ReferenceId(1),
  | ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)]

  x Reference flags mismatch:
  | after transform: ReferenceId(4): ReferenceFlags(Write)
  | rebuilt        : ReferenceId(1): ReferenceFlags(Read | Write)

  x Reference flags mismatch:
  | after transform: ReferenceId(6): ReferenceFlags(Write)
  | rebuilt        : ReferenceId(3): ReferenceFlags(Read | Write)

  x Reference flags mismatch:
  | after transform: ReferenceId(8): ReferenceFlags(Write)
  | rebuilt        : ReferenceId(5): ReferenceFlags(Read | Write)

Passed: true
```
2024-08-23 04:00:45 +00:00
overlookmotel
d5de97d6fe fix(semantic): transform checker check reference flags (#5092) 2024-08-23 00:21:21 +00:00
overlookmotel
9da6a21e40 refactor(semantic): rename transform checker output for reference symbol mismatches (#5091) 2024-08-22 23:40:27 +00:00
overlookmotel
a8005b9914 fix(semantic): transform checker check symbol redeclarations (#5089) 2024-08-22 23:40:26 +00:00
overlookmotel
205bff7ea9 fix(semantic): transform checker check symbol references (#5088) 2024-08-22 23:40:25 +00:00
overlookmotel
4a57086d79 fix(semantic): transform checker check symbol IDs (#5078) 2024-08-22 15:08:48 +00:00
overlookmotel
ea7d2163e3 fix(semantic): transform checker check symbol spans (#5076) 2024-08-22 15:08:47 +00:00
overlookmotel
1b6b27a6de fix(semantic): transform checker check symbol flags (#5074) 2024-08-22 15:08:45 +00:00
Dunqing
3b353321ad fix(transformer/logical-assignment-operators): fix semantic errors (#5047)
Fix semantic error caused by `clone_in` causing `reference_id` to not exist.

In this PR, I try to use `move_expression` as much as possible instead of `expr.clone_in`. But in some cases, we need to reuse the same expression in multiple places. I have added a `clone_expression` to workaround it

I felt a bit painful we missing a [clone_in_scope](https://github.com/oxc-project/oxc/issues/4804) API
2024-08-22 08:41:31 +00:00
overlookmotel
f187b71877 fix(semantic): transform checker compare scope children (#5056) 2024-08-22 02:34:44 +00:00
overlookmotel
b52c6a4269 fix(semantic): transform checker compare scope parents (#5055) 2024-08-22 02:34:43 +00:00
overlookmotel
da64014a6c fix(semantic): transform checker catch more scope flags mismatches (#5054)
There was a bug previously where scope flags were only checked if there was also a bindings mismatch.
2024-08-22 02:34:43 +00:00
overlookmotel
67d1a96391 fix(semantic): transform checker compare scope flags (#5052) 2024-08-22 02:34:41 +00:00
overlookmotel
ee7ac8b0b7 refactor(semantic): store all data in PostTransformChecker in transform checker (#5050)
Pure refactor of transform checker. Store all scope data in `PostTransformChecker` so it doesn't need to be passed around. `SemanticData` contains a full set of all semantic data for semantic pass, so we have 2 instances of it for 1. after transform and 2. rebuilt semantic.
2024-08-21 17:04:48 +00:00
overlookmotel
8cded08eb8 refactor(semantic): rename error labels in transformer checker snapshots (#5044)
Rename labels in transformer checker snapshots "after transform" vs "rebuilt".
2024-08-21 14:33:19 +00:00
overlookmotel
863b9cb921 fix(semantic): transform checker handle conditional scopes (#5040)
Some scopes are conditional e.g. `ForStatement` only gets a scope when initializer has a binding (`for (let i = 0; ...)` vs `for (i = 0; ...)`).

Make transform compare this between post-transform and fresh semantics.
2024-08-21 12:07:14 +00:00
overlookmotel
586e15c814 refactor(semantic): reformat transform checker errors (#5039)
Reformat transform checker error output - shorter and consistent capitalization.
2024-08-21 12:07:11 +00:00
Boshen
1bd9365bd0 fix(coverage): correctly check semantic data after transform (#5035)
closes #4999
2024-08-21 09:35:04 +00:00
Dunqing
f51d3f9169 feat(transformer/nullish-coalescing-operator): handles nullish coalescing expression in the FormalParamter (#4975)
### What I did in this PR
1. Replace `self.clone_identifier_reference` with `ctx.clone_identifier.reference`
2. Remove the usage of `ast.copy`
3. Handle below example correctly

### Example

```js
// Input
var foo = object.foo ?? "default";

// Output
var _object$foo;
var foo =
(_object$foo = object.foo) !== null && _object$foo !== void 0
  ? _object$foo
  : "default";
```
2024-08-20 01:06:37 +00:00
Dunqing
f794870dd4 feat(transformer/nullish-coalescing-operator): generate the correct binding name (#4974)
match Babel's [implementation](440fe41333/packages/babel-plugin-transform-nullish-coalescing-operator/src/index.ts (L40))
2024-08-20 01:06:36 +00:00
Boshen
64ace42566 feat(transform_conformance): show transform conformance errors (#4976) 2024-08-19 09:01:34 +00:00
Boshen
4fdf26dac8 refactor(transform_conformance): add driver (#4969) 2024-08-19 07:27:39 +00:00
Dunqing
f1fcdde593 feat(transformer): support react fast refresh (#4587)
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..
2024-08-15 16:41:30 +00:00
Dunqing
0d7912217a feat(transformer): support logical-assignment-operators plugin (#4890)
part of #4754

The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:36 +00:00
Dunqing
ab1d08ccfb feat(transformer): support optional-catch-binding plugin (#4885)
part of #4754

The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:34 +00:00
Dunqing
69da9fda3a feat(transformer): support nullish-coalescing-operator plugin (#4884)
The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:33 +00:00
Dunqing
3a66e5843d feat(transformer): support exponentiation operator plugin (#4876)
The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:32 +00:00
Dunqing
62f759c1f2 fix(transformer/typescript): generated assignment for constructor arguments with access modifiers should be injected to the top of the constructor (#4808)
fix: #4789
2024-08-10 11:21:45 +00:00
Dunqing
3987665490 fix(transformer/typescript): incorrect enum-related symbol_id/reference_id (#4660)
part of #4581
2024-08-06 02:57:19 +00:00
Dunqing
03c643a8af fix(semantic): incorrect scope_id for catch parameter symbols (#4659)
When we move all the bindings in the CatchClause scope to its child scope (BlockStatement), we also need to replace the scope_id in the symbol with the scope_id of the new scope.
2024-08-06 02:57:18 +00:00
Dunqing
5327acdc1f fix(transformer/react): the require IdentifierReference does not have a reference_id (#4658)
part of #4581. Looks we had to pass `TraverseCtx` to the `ModuleImports`
2024-08-05 22:55:07 +00:00