Commit graph

45 commits

Author SHA1 Message Date
overlookmotel
4fd89e8eed test(transformer): fix indentation in transformer test fixtures (#6346)
Unimportant nit. Fix whitespace in the transformer test fixtures.
2024-10-08 01:32:07 +00:00
overlookmotel
cf20f3a89d feat(transformer): exponentiation transform: support private fields (#6345)
Babel doesn't support private fields in this transform, but there's no reason not to. So we can.
2024-10-08 01:32:06 +00:00
overlookmotel
4aa4e6bec0 refactor(transformer): exponentiation transform: do not wrap in SequenceExpression if not needed (#6343)
`left **= right` is transformed to `left = Math.pow(left, right)`. There is no need to wrap it in a `SequenceExpression`.
2024-10-08 01:32:05 +00:00
overlookmotel
28cbfa7c64 fix(transformer): exponentiation transform: fix temp var names (#6329)
Fix one case that I missed in #6318.
2024-10-07 09:00:35 +00:00
overlookmotel
3a4bcc77fc fix(transformer): exponentiation transform: fix temp var names (#6318)
Make naming of temp vars follow Babel. It wasn't apparent that our version of this transform was behaving differently from Babel because the Babel plugin has very few tests. The added tests replicate Babel's output.
2024-10-06 23:08:10 +00:00
overlookmotel
ccb7bdcc56 fix(transformer): exponentiation transform: do not replace object when private property (#6313)
Fix exponentiation operator transform to bail out early if a private class property.

We can't transform this:

```js
class C {
    #p;
    method() {
        this.#p **= 2;
    }
}
```

But we should at least leave it alone. Previously `get_obj_ref` called `ast.move_expression(expr)` on the member expression's object before bailing out, so example above was transformed to:

```js
class C {
    #p;
    method() {
        null.#p **= 2; // <-- `null`
    }
}
```

This PR makes it spot this case early and bail out *before* calling `ast.move_expression(expr)`.
2024-10-06 23:08:08 +00:00
Dunqing
bfd19882b0 fix(transformer/react): should not collect use-hooks if it's a nested member expression (#6143)
close: #6139

I still remember this logic and I call `get_first_object` for it intentionally 🥲
2024-09-28 14:38:14 +00:00
Boshen
28da77195b feat(transformer): do not transform ** with bigint literals (#6023)
part of #5822

They will produce runtime errors.
2024-09-24 10:33:02 +00:00
overlookmotel
4e9e838838 fix(transformer): fix arrow function transform (#5933)
Fix arrow function transform's treatment of `this` within classes.
2024-09-21 07:48:18 +00:00
overlookmotel
15743344b1 test(transformer): add test for arrow function transform (#5932)
Add test for `this` in nested block inside arrow function.
2024-09-21 00:53:43 +00:00
overlookmotel
cab441c572 test(transformer): fix JSX test options (#5895)
Fix a test by setting correct options.
2024-09-20 01:26:52 +00:00
overlookmotel
9758c1a5cc fix(transformer): JSX source: add var _jsxFileName statement (#5894)
Fix JSX source transform when run alone without main JSX transform.

The added test case is same as one of Babel's exec test cases, but the exec test fails due to `transformAsync` not being present.
2024-09-20 01:26:52 +00:00
overlookmotel
0c8733df23 test(transformer): clean up identation in test fixtures (#5863)
Not sure how added up with mix of tabs and spaces.
2024-09-18 15:19:59 +00:00
overlookmotel
ef8dcc9d4d test(transformer): more tests for arrow function transform (#5849) 2024-09-18 09:46:58 +00:00
overlookmotel
49ee1dcff2 fix(transformer): arrow function transform handle this in arrow function in class static block (#5848)
Class static blocks also hold a `this` binding.
2024-09-18 09:46:57 +00:00
Dunqing
3cc38dfc05 fix(transformer/react): react refresh panics when encounter use hook (#5768)
close: #5766

I even forgot that React has a `use` hook in the latest version
2024-09-13 16:17:33 +00:00
Dunqing
77d9170f84 fix(transformer/react): isStaticChildren should be false when there is only one child (#5745)
We found a warning report [here](206df66e70/packages/react/src/jsx/ReactJSXElement.js (L614-L632)). It caused by we transform incorrectly
2024-09-13 13:20:59 +00:00
Dunqing
ffbc4625b4 chore(transformer): treat all React Refresh tests as ESM syntax (#5644)
related: #5612
2024-09-11 07:57:17 +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
3bf6aaf06a fix(transformer/react): support emit_full_signatures option in refresh plugin (#5629) 2024-09-11 07:57:14 +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
overlookmotel
87a79d9cd0 test(transformer): add trailing line breaks to conformance fixtures (#5537)
Currently whether conformance fixture files have trailing line breaks is inconsistent - some have them, some don't. Make all of them have a trailing line break.
2024-09-06 12:02:46 +00:00
overlookmotel
e18c2edfcb test(transformer): move RegExp transform conformance tests (#5536)
Rename transform conformance RegExp test fixtures folder from "esbuild-tests" to "regexp", to reflect that not all these tests are copied from ESBuild.
2024-09-06 12:02:45 +00:00
overlookmotel
d1ece197c4 fix(transformer): RegExp transform handle Term::Quantifier (#5501)
`Term::Quantifier` contains a nested `Term` so we need to recurse into that `Term` to check if it contains any unsupported syntax.
2024-09-06 11:51:35 +00:00
Dunqing
c59d8b3c9b feat(transformer): support all /regex/ to new RegExp transforms (#5387)
related: #4754

The implementation port from [esbuild](332727499e/internal/js_parser/js_parser.go (L12820-L12840)). And cover all babel's regexp plugins

---

## The following description was generated by `Graphite` 😋

### TL;DR

Added support for transforming various RegExp features to ensure compatibility with older JavaScript environments.

### What changed?

- Implemented a new `RegExp` transformer to handle unsupported RegExp literal features
- Added options to control different RegExp transformations (e.g., sticky flag, unicode flag, dot-all flag, etc.)
- Updated the transformer to convert unsupported RegExp literals into `new RegExp()` constructor calls
- Added test cases for different RegExp transformations
- Integrated the new RegExp transformer into the existing transformation pipeline

### How to test?

1. Run the existing test suite to ensure no regressions
2. Execute the new RegExp-specific tests in the `tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/` directory
3. Try transforming code with various RegExp features using different target environments to verify correct transformations
2024-09-05 11:04:45 +00:00
overlookmotel
b9ef357868 test(transformer): add tests for nested JSX this member expressions in arrow function transform (#5413)
Follow-up after #5356. Handle nested JSX member expressions with `this` as base object in arrow functions transform (e.g. `<this.foo.bar />`).
2024-09-03 15:06:06 +00:00
Dunqing
0eb32a6770 fix(traverse): invalid variable name generated by generate_uid_based_on_node (#5407)
close: #5371
2024-09-03 12:13:30 +00:00
Dunqing
0abfc5049f feat(transformer/typescript): support rewrite_import_extensions option (#5399)
close: #5395

Babel only supports `rewrite`, we also support `remove`
2024-09-03 01:57:42 +00:00
Dunqing
94ff94cd34 fix(transformer/arrow-functions): reaches unreachable when <this.foo> is inside an arrow function (#5356)
Fixes: https://github.com/oxc-project/oxc/issues/5353#issuecomment-2321792915
2024-09-02 18:06:08 +00:00
Dunqing
35f03db464 fix(transformer): ArrowfunctionExpression's expression is true but has more than one body statement (#5366)
close: #5363

We insert the new statement here, but it's broken if it a `() => x;`, we need to transform it to `function () { return x }`

8d565d5b23/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs (L59-L76)

I don't where we should put the fallback logic, It's useful for all plugins. We had already done the same thing in the react refresh plugin.

8d565d5b23/crates/oxc_transformer/src/react/refresh.rs (L578-L605)
2024-08-31 14:49:58 +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
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
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
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
48031ada93 fix(transformer/typescript) shadowed imports have not been removed (#4550)
close: #4423
2024-08-05 03:15:14 +00:00
Dunqing
ecdee88cfb
fix(transformer/typescript): incorrect eliminate exports when the referenced symbol is both value and type (#4507) 2024-07-27 12:11:29 -04:00
Dunqing
f8565ae3cd fix(transformer/typescript): unexpectedly removed class binding from ExportNamedDeclaration (#4351)
The original `SymbolFlags` methods were a bit confusing I renamed and re-implemented them.
2024-07-18 16:44:38 +00:00
Don Isaac
4413e2d298
fix(transformer): missing initializer for readonly consructor properties (#4103) 2024-07-08 12:45:50 +08:00
Dunqing
bdee156c5d fix(transformer/typescript): declare class incorrectly preserved as runtime class (#3997)
fix: #3993
2024-07-01 16:04:40 +00:00
Dunqing
a50ce3d299 fix(transformer/typescript): missing initializer for class constructor arguments with private and protected modifier (#3996)
close: #3992
2024-07-01 15:10:32 +00:00
Dunqing
59666e0127
fix(transformer): do not rename accessible identifier references (#3623)
close: #3620

In `Babel`, the expected output is:

```ts
var x = 10;
var Foo = function(Foo) {
       Foo[Foo['a'] = 10] = 'a';
       Foo[Foo['b'] = 10] = 'b';
       Foo[Foo['c'] = 30] = 'c';
       return Foo;
}(Foo || {});
```

IMO, `Foo.b + x` is enough, because `x` is not a const variable. The
output same as with `typescript`
2024-06-13 15:26:38 +08:00
overlookmotel
8e4f33557d
fix(transformer): output empty file for TS definition files (#3500)
As discussed in
https://github.com/oxc-project/oxc/pull/3489#issuecomment-2143482458,
transformer should output an empty file for TS definition files.
2024-06-03 20:25:02 +08:00
Dunqing
843318cdbe
refactor(transformer/typescript): reimplementation of Enum conversion based on Babel (#3102)
The remaining test cases will perform better with a scope
implementation, and while we can implement them without the scope, it
still requires us to do what the scope did.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-04-29 16:26:22 +08:00
Boshen
35e3b0f1cb
fix(transformer): fix incorrect jsx whitespace text handling (#2969) 2024-04-14 18:40:40 +08:00
Dunqing
d67100730b
feat(tasks/transforme_conformance): support for testing oxc's test cases (#2835)
Related to:
https://github.com/oxc-project/oxc/pull/2822#issuecomment-2021802212

Although `babel` has a lot of test cases, we still need to add edge
cases that `babel` doesn't have.

This PR will allow us to add out test cases to
`/root/oxc/tasks/transform_conformance/tests`. The directory structure
is consistent with `babel`

For example
```shell
# cd /root/oxc/tasks/transform_conformance/tests
- babel-transform-plugin–optional-catch-binding
   - test
       - fixtures
           - your tests # add test cases here
```
2024-03-27 14:14:15 +08:00