Commit graph

178 commits

Author SHA1 Message Date
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
bb2c0c219b refactor(transformer)!: return String as error instead of OxcDiagnostic (#7424) 2024-11-22 16:22:49 +00:00
overlookmotel
f4fda2dba6 test(transformer): add --debug option to transform conformance (#7400)
Add `--debug` command line option for transformer conformance runner, same as for `cargo coverage`. It prints the paths of test fixtures before running them.
2024-11-22 02:23:10 +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
885e37f8eb feat(transformer): Optional Chaining (#6990)
close: #6958
2024-11-21 03:12:18 +00:00
Boshen
514878d927 fix(transform_conformance): only run exec tests when specified (#7359) 2024-11-19 13:13:11 +00: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
Boshen
d0e64fd80a refactor(transform_conformance): remove TestCase trait (#7356) 2024-11-19 10:52:42 +00:00
Boshen
65f1e82bd8 refactor(transform_conformance): clean up some code (#7354) 2024-11-19 09:15:14 +00:00
Boshen
846711cf41 feat(transformer)!: change API to take a &TransformOptions instead of TransformOptions (#7213)
closes #7185

`TransformOption`s has an initialization cost, it should be initialized once and shared across files.
2024-11-09 06:01:13 +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
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
Boshen
f83a760d8a refactor(transformer): deserialize BabelOptions::presets (#7047) 2024-11-01 06:56:27 +00:00
Boshen
52c20d633c refactor(transformer): deserialize BabelOptions::plugins (#7045) 2024-11-01 05:44:57 +00:00
Dunqing
934cb5e746 feat(transformer): add async_generator_functions plugin (#6573)
Passed 15/19 tests. The remaining 4 failed tests related to `this` expression, the problem same as I mentioned in #6658. I will fix them in follow-up PRs.
2024-10-31 09:14:17 +00:00
overlookmotel
2a57a66753 test(transformer): support exec tests in Oxc folder (#7030)
Fix error when `tasks/transform_conformance/tests` contains exec tests.
2024-10-31 01:18:09 +00:00
Boshen
b8daab3663 refactor(transformer)!: API to TryFrom<&EnvOptions> for TransformOptions and TryFrom<&BabelOptions> TransformOptions (#7020)
…ions` and `TryFrom<&BabelOptions> TransformOptions`
2024-10-30 09:40:09 +00:00
Boshen
4618aa22d9 refactor(transformer)!: rename TransformerOptions::react to jsx (#6888) 2024-10-25 12:04:33 +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
Ethan Goh
a9260cf6d1
feat(transformer): async-to-generator plugin. (#5590)
Tests are still not passed. A lot need to do yet.

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-10-14 17:16:58 +08:00
Boshen
7645e5c34b refactor(codegen)!: remove CommentOptions API (#6451) 2024-10-11 13:53:28 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
Boshen
020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
Boshen
8729755baa feat(oxc,napi/transform): napi/transform use oxc compiler pipeline (#6298)
part of #6156
2024-10-05 16:35:09 +00:00
overlookmotel
e19deaa102 ci(transformer): move post-transform checker to tasks crate (#6288)
Move post-transform checker into a `tasks` crate. It doesn't feel like it belongs in `oxc_semantic`. It also feels like too heavy a lump of code to put in `tasks/common`.
2024-10-05 14:48:37 +00:00
overlookmotel
bd318b1eec test(transformer): join paths in cross-platform compatible way (#5920) 2024-09-20 11:30:12 +00:00
overlookmotel
9dac6dfb23 test(transformer): move transformer conformance snapshots into separate directory (#5917)
Move snapshots for transform conformance into a `snapshots` sub-folder.
2024-09-20 10:25:17 +00:00
Boshen
213dbc04ff chore(transform_conformance): do not print comments yet (#5788) 2024-09-15 15:48:58 +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
c9fea5dd16 chore(tasks/transformer_conformance): remove an ignored test that has passed (#5750) 2024-09-13 09:03:48 +00:00
dalaoshu
d18c896a2c
perf(rust): use cow_utils instead (#5664)
Related to #5586 and #5662

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-11 18:39:30 +08:00
Boshen
f49e6ebd41 fix(span): treat .js as module file (reverts the previous breaking change) (#5612)
As it turns out it's not ideal to treat `.js` as `script` in today's world anymore.

This makes https://github.com/oxc-project/oxlint-ecosystem-ci pass again.
2024-09-08 15:14:04 +00:00
Boshen
919d17fc5c fix(transform_conformance): only print semantic mismatch errors when output is correct (#5589)
closes #5166

Had to rerun for mismatch errors :-/
2024-09-07 16:32:53 +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
Boshen
1bed5ce2a5 chore: run cargo +nightly fmt to sort imports (#5503)
They are never going to be stable are they ... cedf7a4daa/.rustfmt.toml (L8-L16)
2024-09-06 04:04:26 +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
be4642fc02 feat(semantic): transform checker check child scope IDs (#5410)
Transform checker check child scope IDs. If we have to track child scope IDs, we should make sure they're correct!
2024-09-03 00:57:13 +00:00
magic-akari
08dc0adeab feat(transformer): add object-spread plugin (#3133) 2024-08-28 15:57:20 +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
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
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
Boshen
1bd9365bd0 fix(coverage): correctly check semantic data after transform (#5035)
closes #4999
2024-08-21 09:35:04 +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
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