Commit graph

81 commits

Author SHA1 Message Date
Dunqing
86d4c90e4d feat(transformer/class-properties): support for transforming AssignmentTarget (#7697)
Instance prop:
 * `[object.#prop] = arr` -> `[_toSetter(_classPrivateFieldSet, [_prop, object])._] = arr`
 * `({x: object.#prop} = obj)` -> `({ x: _toSetter(_classPrivateFieldSet, [_prop, object])._ } = obj)`

 Static prop:
 * `[object.#prop] = arr` -> `[_assertClassBrand(Class, object, _prop)._] = arr`
 * `({x: object.#prop} = obj)` -> `({ x: _assertClassBrand(Class, object, _prop)._ } = obj)`
2024-12-06 12:18:54 +00:00
Boshen
c3a538c47c
deps: node v22.12.0 (#7693) 2024-12-06 13:59:37 +08:00
overlookmotel
72b5d58560 fix(transformer/class-properties): create temp var for this in computed key (#7686)
`this` in computed key needs a temp var, otherwise once moved into constructor it refers to the wrong `this`.
2024-12-06 02:20:57 +00:00
Dunqing
c793d71a78 feat(transformer/class-properties): transform ChainExpression (#7575)
Fully support transforming ChainExpression in class properties. Our implementation has some differences in execution order compared to Babel, but we have passed all execution-related tests.
2024-12-04 16:52:57 +00:00
IWANABETHATGUY
6af8659624 fix(oxc_transformer): correct generate ThisExpr and import.meta in jsx pragma (#7553) 2024-12-03 13:54:15 +00:00
overlookmotel
eb825edee2 fix(transformer/class-properties): replace references to class name with temp var in static prop initializers (#7610)
Similar to #7516. Fix class properties transform to replace references to class name in static prop initializers with temp var.

Input:

```js
class C {
  static getSelf = () => C;
}
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Output:

```js
var _C;
class C {}
_C = C;
_defineProperty(C, "getSelf", () => _C);
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Previously, temp var wasn't used so code was `_defineProperty(C, "getSelf", () => C);`. `C` is altered later by `C = 123`, so `C2.getSelf()` returned `123`, instead of reference to the class.
2024-12-03 12:43:21 +00:00
overlookmotel
0eadd9f6de fix(transformer/class-properties): create temp var for class where required (#7516)
Fix class properties transform to create a temp var for class when it's required.

Input:

```js
class C {
  static getSelf = () => this;
}
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Output:

```js
var _C;
class C {}
_C = C;
_defineProperty(C, "getSelf", () => _C);
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Previously, temp var wasn't used so code was `_defineProperty(C, "getSelf", () => C);`. `C` is altered later by `C = 123`, so `C2.getSelf()` returned `123`, instead of reference to the class.

The logic around when a temp var is required and when it's not, and when/where it's referenced is ridiculously complicated. So add some debug assert mechanisms to double-check the logic.
2024-12-03 07:46:04 +00:00
overlookmotel
7bd6350978 refactor(transformer/class-properties): move creating temp var out of main loop (#7587)
Small optimization. Move code out of the loop which determines if class property transform has nothing to do and can bail out early. This also clears the way for correcting the logic around when temp vars are/aren't created in #7516.
2024-12-03 07:46:01 +00:00
IWANABETHATGUY
a784a82f4f feat(oxc_transformer): support jsx pragma that are long member expressions (#7538)
related tests:

d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L6188-L6236)
2024-12-02 14:02:38 +00:00
Boshen
bf16668de7 feat(transform_conformance): keep exec snapshot files (#7565)
closes #7564
2024-12-01 10:13:47 +00:00
Dunqing
3539f56cac feat(transformer/class-properties): support for transforming TaggedTemplateExpresssion (#7504)
```js
"object.#prop`xyz`" -> "_classPrivateFieldGet(_prop, object).bind(object)`xyz`"
"object.obj.#prop`xyz`" -> "_classPrivateFieldGet(_prop, _object$obj = object.obj).bind(_object$obj)`xyz`"
```
2024-11-27 12:15:31 +00:00
overlookmotel
bd2ce025c3 test(transformer): fix fixtures updating script (#7499)
Script to update fixtures for class properties transform was failing to transform fixtures where output is `output.mjs` (instead of `output.js`). This PR fixes that.
2024-11-27 02:38:00 +00:00
overlookmotel
488029ea24 test(transformer/async-to-generator): failing test for nested supers (#7314)
Failing test for async-to-generator transform.

When exiting a function which has `super` bindings, need to restore previous state of `super_methods`. It probably needs to be a stack. But not sure if `renamed_arguments_symbol_ids` needs to be a stack too? I don't really understand this transform, so am not attempting to fix myself.

[Babel REPL](https://babeljs.io/repl#?browsers=ie%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYewdgzgLgBCCuUCmAnGBeGBvAUDGAbgIYA28SAXDAAwA0eMREAnmMDALZJQAWIAJgAoAlNgb4RGAHwwI8AA6oAdMTJIA3DnExQkWAEswYVBjH5zhUuSp1t-Jq3ZdeAybgsXJ6GXMUoVVhp2MAC-2iGa2l4-Csqq5Jr4YRE4QA&debug=false&forceAllTransforms=false&modules=commonjs&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=true&targets=&version=7.26.2&externalPlugins=%40babel%2Fplugin-external-helpers%407.25.9%2C%40babel%2Fplugin-transform-async-to-generator%407.25.9&assumptions=%7B%7D)
2024-11-26 15:54:07 +00:00
overlookmotel
199076bd14 fix(transformer/class-properties): transform private property accesses in static prop initializers (#7483)
Transform private property accesses in static prop initializers. e.g.:

Input:

```js
class C {
  static #x = 123;
  static y = this.#x;
}
```

Transformed:

```js
class C {}
var _x = { _: 123 };
babelHelpers.defineProperty(C, "y", babelHelpers.assertClassBrand(C, C, _x)._);
```

`this.#x` has been transformed to `babelHelpers.assertClassBrand(C, C, _x)._`.
2024-11-26 11:36:09 +00:00
overlookmotel
97de0b7be1 fix(transformer/class-properties): transform this in static prop initializers (#7481)
Convert `this` in static property initializers to reference to class name.

`class C { static prop = this; }` -> `class C {}; C.prop = C;`
2024-11-25 20:10:05 +00:00
overlookmotel
9778298fdb feat(transformer): class properties transform (#7011)
Add class properties transform.

Implementation is incomplete. Notable missing parts:

* Scopes are not updated where property initializers move from class body into class constructor / `_super` function.
* Does not handle binding shadowing problems when property initializers move from class body into class constructor.
* `this` and references to class name in static property initializers need to be transformed to point to a temp var.
* Not all usages of private properties are supported (see below).
* Code which is moved to outside of class body is not transformed by other transforms for class declarations (works OK for class expressions). This includes static property initializers, static blocks, and computed property/method keys.
* Only basic checks for whether computed property/method keys may have side effects.
* Numerous other small issues noted in TODO comments through the code.

### Private properties

Currently does not handle the following usages of private properties:

```js
class Class {
  #prop;
  static #static;

  method() {
    object?.#prop;
    object?.#prop();
    [object.#prop] = [1];
    ({x: object.#prop} = {x: 1});
    object.#prop`xyz`;

    object?.#static;
    object?.#static();
    [object.#static] = [1];
    ({x: object.#static} = {x: 1});
    object.#static`xyz`;
  }
}
```
2024-11-25 10:24:20 +00:00
Boshen
6f161de10f chore(coverage): bump test262, babel and TypeScript submodules (#7452) 2024-11-24 16:26:45 +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
7ff9f13973 fix(transformer): correct all ReferenceFlags (#7410) 2024-11-22 09:10:55 +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
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
Boshen
e6922df3bb feat(parser): fix incorrect AST for x?.f<T>() (#7387) 2024-11-21 06:10:48 +00:00
Boshen
885e37f8eb feat(transformer): Optional Chaining (#6990)
close: #6958
2024-11-21 03:12:18 +00:00
Boshen
666b6c104c fix(parser): add missing ChainExpression in optional TSInstantiationExpression (#7371) 2024-11-20 11:51:55 +00:00
renovate[bot]
b3965bbff0
chore(deps): update npm packages (#7364) 2024-11-20 17:26:48 +08:00
Boshen
d60801218e feat(transform_conformance): snapshot our transformed outputs (#7358) 2024-11-19 12:49:44 +00:00
Boshen
84f3bf2f97 refactor(transform_conformance): clean up test execution code (#7357) 2024-11-19 12:22:42 +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
Boshen
b4258ee58e feat(transformer): add defaulted Module::Preserve option (#7225) 2024-11-09 12:55:13 +00:00
Dunqing
5cfdc05d06 feat(transformer/typescript): support transform export = and import = require(...) when module is commonjs (#7206)
close: #7141
2024-11-09 09:32:28 +00:00
Dunqing
e536d47e56 feat(transformer/babel): add support for trying to get the Module from BabelPlugins (#7218)
When configuring a `transform-modules-commonjs` plugin in `options.json`, we should treat it as a `CommonJS` module
2024-11-09 08:38:15 +00:00
Boshen
324c3fe184 feat(transformer): add TransformOptions::module option (#7188) 2024-11-09 08:38:15 +00: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
Boshen
6e1abde5ef chore(transform_conformance): omit tests that we cannot pass right now (#7192) 2024-11-07 14:20:30 +00:00
Boshen
a579011e37 feat(transformer): add features ES2018NamedCapturingGroupsRegex and ES2018LookbehindRegex (#7182) 2024-11-07 07:39:33 +00:00
Boshen
ad3a2f518e feat(tasks/compat_data): generate our own compat table (#7176) 2024-11-07 07:39:33 +00:00
renovate
3da9443b0e chore(deps): update dependency @types/node to v22.9.0 (#7145)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@types/node](https://redirect.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://redirect.github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node)) | [`22.8.4` -> `22.9.0`](https://renovatebot.com/diffs/npm/@types%2fnode/22.8.4/22.9.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@types%2fnode/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@types%2fnode/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@types%2fnode/22.8.4/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@types%2fnode/22.8.4/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - "before 10am on monday" in timezone Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNyIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
2024-11-06 06:17:36 +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
2c5734d49b refactor(transformer/async-generator-functions): do not transform await expression where inside ArrowFunctionExpression (#7132)
The `await expr` should be transformed in AsyncToGenerator rather than AsyncGeneratorFunctions
2024-11-06 03:27:12 +00:00
Dunqing
b6a575009a feat(transformer/arrow-function-converter): move scope to changed scope for this_var if scope have changed (#7125)
The scope can be moved or deleted, we need to check whether the scope id is the same as the container's scope id, if not, we need to move the `this_var` to the target scope id.
2024-11-06 03:02:36 +00:00
Dunqing
df772411ea feat(transformer): enable ArrowFunctionConverter in async-to-generator and async-generator-functions plugins (#7113)
Part of https://github.com/oxc-project/oxc/pull/7074

In async-to-generator and async-generator-functions plugins, we may need to transform the async arrow function to a regular generator function, now we can reuse the ability of the ArrowFunction plugin by enabling `ArrowFunctionConverter`.

I will fix semantic errors in the follow-up PR
2024-11-06 03:02:36 +00:00
Boshen
9386435efb
feat(transform_conformance): use node instead of bun for exec tests (#7121) 2024-11-05 14:20:48 +08:00
Boshen
c2802e63fc feat(transform_conformance): add babel runtime to exec tests (#7114) 2024-11-04 14:38:15 +00:00
Dunqing
f80085c683 refactor(transformer/async-to-generator): move handling of MethodDefinition's value to exit_function (#7105)
Part of #7074

We need to handle this before the `arrow_function` plugin inserts `_this = this` because, in the `async-to-generator` plugin, we will move the body to an inner generator function. However, we don't want `_this = this` moved to the inner generator function as well. So as long as we move first, and then insert, we can fix this problem.

The new semantic error is related to another tricky problem, I will fix it in another PR
2024-11-04 14:32:42 +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
Boshen
52c20d633c refactor(transformer): deserialize BabelOptions::plugins (#7045) 2024-11-01 05:44:57 +00:00