Commit graph

1754 commits

Author SHA1 Message Date
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
Boshen
ed6a69e2db
chore(coverage): update runtime.snap 2024-11-25 22:36:05 +08:00
overlookmotel
eb70219821 feat(ast): derive GetAddress on all enum types (#7472)
Implement `GetAddress` on all AST enums where all variants are boxed. Part of #7339.
2024-11-25 12:13:44 +00:00
overlookmotel
a68a2172d2 refactor(ast_tools): move prelude above derive in Derives (#7471)
Pure refactor. Prelude is printed first, so it makes sense to define it first.
2024-11-25 11:08:31 +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
overlookmotel
3b2a3477d4 test(transformer): script to amend Babel fixtures (#7122)
Add a NodeJS script which amends Babel's fixtures in place to remove transform plugins which we don't support from `options.json` files. Where options are changed from the original, the script runs Babel transform with the new options to regenerate the fixture `output.js` files.

Currently limited to transforming the fixtures for `babel-plugin-transform-class-properties` transform, but we can also enable it for other plugins if we wish in future, to get additional test coverage.
2024-11-25 10:24:19 +00:00
Boshen
6f161de10f chore(coverage): bump test262, babel and TypeScript submodules (#7452) 2024-11-24 16:26:45 +00:00
Alexander S.
9558087db9
feat(oxlint): auto detect config file in CLI (#7348)
waiting fior #7352

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-23 23:17:05 +08:00
Dunqing
4d6bd07afe fix(transformer/async-generator-functions): correct all binding scope id (#7425)
Fixed a bunch of semantic errors by removing moving binding logic 😢. This plugin constructs a complex `for-await` replacement so that I wrongly move to an incorrect scope.
2024-11-22 16:29:00 +00:00
Boshen
bb2c0c219b refactor(transformer)!: return String as error instead of OxcDiagnostic (#7424) 2024-11-22 16:22:49 +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
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
1550ffc5b5 fix(tasks/lint_rules): map prefix node to n (#7397)
The `eslint-plugin-n` page is not showing any rules implemented.
2024-11-21 13:58:53 +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
DonIsaac
df143ca7bb docs(linter): add docs for config settings (#4827) 2024-11-21 08:08:30 +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
0c1fb96760 fix(tasks/coverage): run runtime tasks concurrently to avoid timeout (#7384) 2024-11-21 03:05:20 +00:00
Boshen
666b6c104c fix(parser): add missing ChainExpression in optional TSInstantiationExpression (#7371) 2024-11-20 11:51:55 +00:00
Boshen
7bf970a4b6 refactor(linter)!: remove tree_shaking plugin (#7372)
This rule has been in `nursery` for a long time and I don't see it
coming out of `nursery` in the foreseeable future.

closes #7031
clsoes #7057
2024-11-20 11:46:29 +00:00
renovate[bot]
b3965bbff0
chore(deps): update npm packages (#7364) 2024-11-20 17:26:48 +08:00
Alexander S.
d3a0119a42
feat(oxlint): add cwd property to LintRunner (#7352)
allows to use multiple `LintRunner` in one file targeting multiple
directory.
The current problem is for the test in #7348 we can not change
`env::current_dir`,
so as a workaround I introduce a new property :) 

See more info here:
https://discord.com/channels/1079625926024900739/1117322804291964931/1308179827576016897
2024-11-20 12:44:50 +08: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
Dunqing
6cfb5df9b9 feat(transformer): support generate proper binding name from ChainExpression (#7326) 2024-11-19 10:31:54 +00:00
Dunqing
58db9ef322 refactor(codegen): do not print unnecessary parentheses if both sides use the same logical operator (#7325)
As shown by the changing tests, we don't need to print parentheses for them.

### Comparison
In [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAAGEgPz8gKGIgPz8gKGMgPz8gZCkpOwooYSA/PyAoYiA/PyAoYyA/PyBkKSkpOwooYSB8fCAoYiB8fCBjKSkgfHwgZDsKYSB8fCAoYiB8fCAoYyB8fCBkKSk7CmEgJiYgKChiICYmIGMpICYmIGQp), it will print parentheses as-is, in [SWC](https://play.swc.rs/?version=1.9.2&code=H4sIAAAAAAAAA0tUsLdX0EgCk8kgMkVT05pLIxGLMES8pgYkDiSTNTVBVIo1F5IgUDFIDKQ2UUFNTUEDKAykkjVBZIomAGEbiHtuAAAA&config=H4sIAAAAAAAAA1VQzW7DIAy%2B9ykin6tlyrHXTb3ttCdA1GmpACPbSIuqvPuAJml6w9%2Bv8ePQdXAXC6fuUZ5lSIYFeZsLIlNU81cQ0CmhWHZJ4biyKpVSztiQ%2BUmAGr6iVhPK8DkMsOJsoozEYd%2BQBb9xdBHPxF%2FeiJwd%2BossuVsVo7G68xXIhUSsv5TZYi27qSY59T1K%2BJBbn56W48vAOaoLTWuyUjDqLCz0%2FPYDTyRVNxovyw4QXHTjtF%2FdUiglIu%2FCKjXx6jf%2FYc1v6RDokhu5HL0etq5U0gLFu8BLuTZu6eDkZ7W3s8%2F%2FYy0r4MUBAAA%3D), we have the same output now
2024-11-19 10:31:53 +00:00
Boshen
65f1e82bd8 refactor(transform_conformance): clean up some code (#7354) 2024-11-19 09:15:14 +00:00
Boshen
7b83a3ddfa
chore(tasks/coverage): update runtime.snap 2024-11-18 18:01:49 +08: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
Nicholas Rayburn
7b7555a0ab
docs(website): Link to specific ref when generating website docs (#7324)
Currently the website links to main which is subject to change without
an update to the website. This updates the website to link to the
specific commit that was used when the website was published.

Feel free to cleanup anything in this PR.
2024-11-17 14:23:00 +08: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
7086cmd
cf99be0a0d fix(minifier): do not compare bigint with object (#7294)
@Boshen, could you please update the snap of runtime and commit to this PR? I want to see the effects after the unit tests are added.
2024-11-16 06:01:06 +00:00
Boshen
8d8f34cfb5
chore(tasks/coverage): update runtime.snap 2024-11-15 12:48:56 +08:00
overlookmotel
f0dee76a4d style(ast_tools): fix wonky formatting (#7288)
Follow-on after #7283. Pure refactor. `rustfmt` was malfunctioning on this code for some reason. Alter the code slightly so it formats it nicely.
2024-11-14 22:58:16 +00:00
Boshen
b57d00d6fb fix(tasks/compat_data): fix misplaced features (#7284)
closes #7279
2024-11-14 16:36:16 +00:00
dalaoshu
a48ebd6295
fix(tasks): cargo clippy error on rust 1.82.0 (#7283)
I mentioned this clippy issue in the discord help channel. The problem
seems to be related to using the stable rust toolchain, but when I
switched to version `1.81.0`, the issue was resolved.

However, some of the clippy suggestions might still be worth considering
and could be adopted.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-15 00:08:04 +08:00
DonIsaac
2268a0ef90 feat(linter): support overrides config field (#6974)
Part of #5653
2024-11-13 05:40:59 +00:00
camc314
3dcac1ae0b feat(linter): react/exhaustive-deps (#7151)
Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in https://github.com/oxc-project/oxc/pull/2637 !

still a draft. current state:

3x false positives (all todo with refs)

3x false negatives (TS will catch these
13x false negatvies todo with refs
1x false negative TODO

closes  #2637
relates to #2174
2024-11-12 11:42:47 +00:00
Boshen
f54d330eca
feat(tasks/lint_rules): mark eslint/no-undef-init as done (#7244)
closes #6456
2024-11-12 11:55:37 +08:00
Dunqing
eea4ab830a fix(transformer/helper-loader): incorrect SymbolFlags for default import when SourceType is script (#7226) 2024-11-09 14:32:44 +00:00
Boshen
b4258ee58e feat(transformer): add defaulted Module::Preserve option (#7225) 2024-11-09 12:55:13 +00:00
overlookmotel
d27e14f065 refactor(ast): AstKind::as_* methods take self (#5546)
Make `AstKind::as_*` methods (e.g. `AstKind::as_boolean_literal`) take `self`, not `&self`.

`AstKind` is `Copy`.

See: https://github.com/oxc-project/oxc/issues/5506#issuecomment-2332912976
2024-11-09 09:39: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
BitterGourd
94865a9390
feat(rulegen): support outdent and dedent tagged template expressions (#6866)
close #6645

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-11-09 17:26:27 +08:00
Boshen
b11ed2cf7b refactor(ast)!: remove useless ObjectProperty::init field (#7220)
closes https://github.com/oxc-project/backlog/issues/143
2024-11-09 09:00:29 +00:00