Commit graph

63 commits

Author SHA1 Message Date
Boshen
224775c056 feat(transformer): transform object rest spread (#7003)
https://babel.dev/docs/babel-plugin-transform-object-rest-spread
2024-11-21 11:33:26 +00:00
overlookmotel
5d853869eb refactor(transformer/arrow-functions): use IndexMap for super getter/setters (#7317)
Generate getter/setter declarations in same order as Babel by using `IndexMap` instead of `HashMap` to store `super` getter/setter method details.
2024-11-17 10:07:34 +00:00
Dunqing
7d75130865 fix(transformer/async-to-generator): arguments isn't correct after transformation (#7234)
Fix due to this plugin transforming the async method and async arrow function, it caused arguments no longer point the original function.

For example:

Before

```js
class Cls {
  async method() {
    () => {
    	console.log(arguments)
    }
  }
}
```

After:

```js
class Cls {
  method() {
    var _arguments = arguments;
    return babelHelpers.asyncToGenerator(function* () {
      () => {
        console.log(_arguments);
      };
    })();
  }
}
```

In this way, the `_arguments` is its original function's arguments

### For performance regression

It seems we need to check the IdentifierReference and BindingIdentifier if it's an `arguments`, that causes a significant regression, we may need a cheap way to do checking
2024-11-17 05:01:44 +00:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
Dunqing
ede10dc030 fix(transformer/async-to-generator): incorrect transform when super expression is inside async method (#7171)
After transformation, super expressions have moved to unexpected places. This PR replaces super expression to call expression, and then inserts the super methods to the top of the method body.

For example:

Before:
```js
class G {
  async method() {
    super.foo()
  }
}
```

After:
```js
class G {
  method() {
    var _superprop_getFoo = () => super.foo,
      _this = this;
    return _asyncToGenerator(function* () {
      _superprop_getFoo().call(_this);
    })();
  }
}```
2024-11-08 08:18:45 +00:00
Dunqing
1910227590 feat(transformer/async-to-generator): support inferring the function name from the ObjectPropertyValue's key (#7201)
Support for inferring function name from ObjectPropertyValue's key

For example:
```js
({ foo: async function() {} })
```

After this, we will able to infer `foo` for the object method
2024-11-08 08:18:44 +00:00
Dunqing
293d072e77 fix(transformer/async-to-generator): only transform object method in exit_function (#7199)
part of #7175
2024-11-08 03:03:27 +00:00
Dunqing
b2a888df0d fix(transformer/async-generator-functions): incorrect transformation for for await if it's not placed in a block (#7148)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/11681867380/job/32527898715
2024-11-06 05:51:01 +00:00
Dunqing
19892ede40 fix(transformer/async-generator-functions): transform incorrectly for for await if it's in LabeledStatement (#7147)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/11681867380/job/32527898715
2024-11-06 03:27:14 +00:00
Dunqing
cd1006fec1 refactor(transformer/async-generator-functions): do not transform yield expression where inside generator function (#7134) 2024-11-06 03:27:13 +00:00
Dunqing
a2244ff089 fix(transformer/async-to-generator): output is incorrect when arrow function without params (#7052) 2024-11-01 15:35:57 +00:00
Dunqing
1ca8cd2fd9 refactor(transformer/react-refresh): avoid panic for init of VariableDeclarator isn't a BindingIdentifier (#6937)
related: https://github.com/oxc-project/oxc/pull/6881#discussion_r1816597462
2024-10-28 01:19:53 +00:00
Dunqing
5f153aca0c refactor(transformer/react-refresh): use VarDeclarations to insert declarators (#6884) 2024-10-27 07:05:24 +00:00
Dunqing
142da1d2ff chore(transform_conformance): reorganize react-refresh related tests (#6918)
Move all tests that are copied from [react-refresh](https://github.com/facebook/react/blob/main/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js) to the `react-refresh` directory, and add a README to describe the source of these tests. This way we can better stay in sync with upstream.

related: https://github.com/oxc-project/oxc/pull/6884#discussion_r1816888813
2024-10-26 13:07:10 +00:00
Dunqing
0d0bb17ad9 feat(transformer): complete the async-to-generator plugin (#6658)
In this PR, most of the async functions have transformed correctly. But the async arrow functions don't fully transform correctly yet, it is related to we need to transform the arrow function to the generator function. For example:

Input:
```js
function declaration() {
  const asy = async () => {
  console.log(this.name)
 }
}
```

Output:
```js
function declaration() {
  const asy = babelHelpers.asyncToGenerator(function* () {
     console.log(this.name);
  });
}
```

Expected Output:

```js
function declaration() {
  var _this = this;
  const asy = /*#__PURE__*/function () {
    var _ref = babelHelpers.asyncToGenerator(function* () {
      console.log(_this.name);
    });
    return function asy() {
      return _ref.apply(this, arguments);
    };
  }();
}
```

From the expected output, we haven't handled `this` correctly, which means even if the `arrow-function` plugin doesn't enable, we still need to handle this correctly as the `arrow-function` plugin does, and further question if `arrow-function` plugin is enabled, how to avoid these making conflict?

I thought we may move out the implementation of `arrow-function` and as a common helper, this way every plugin can handle this well
2024-10-25 03:23:31 +00:00
Dunqing
076f5c39f4 fix(transformer/typescript): retain ExportNamedDeclaration without specifiers and declaration (#6848)
close: #6825
2024-10-24 07:59:07 +00:00
overlookmotel
10484cdeeb feat(transformer): class static block transform (#6733)
Add ES2022 class static block transform.
2024-10-22 03:40:02 +00:00
magic-akari
1d3d256db3 fix(transformer): Correctly trim JSX (#6639)
- Closes: #6638
2024-10-17 14:41:02 +00:00
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