Commit graph

6961 commits

Author SHA1 Message Date
Boshen
f955ba2fae feat(wasm): add transformer target API (#7513) 2024-11-28 03:45:59 +00:00
Boshen
85d4c93778
chore(.gitignore): ignore all wasm files 2024-11-28 10:34:14 +08:00
IWANABETHATGUY
a23ce152af
feat(oxc_transformer): replace_global_define for assignmentTarget (#7505)
related esbuild test:

d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L5430-L5497)
2024-11-28 10:33:44 +08:00
overlookmotel
4d157c583b
docs(traverse): document soundness hole (#7515)
Document the remaining (small) soundness hole in `Traverse`.
2024-11-28 10:30:53 +08:00
overlookmotel
f2f31a8d7a
fix(traverse)!: remove unsound APIs (#7514)
It's essential to `oxc_traverse`'s safety scheme that the user cannot create a `TraverseAncestry`, because they could then substitute it for the one stored in `TraverseCtx`, and cause a buffer underrun when an ancestor gets popped off stack which should never be empty - but it is because user has sneakily swapped it for another one.

Not being able to create a `TraverseAncestry` also requires that user cannot obtain an owned `TraverseCtx` either, because you can obtain an owned `TraverseAncestry` from an owned `TraverseCtx`.

Therefore, it's unsound for `TraverseCtx::new` to be public.

However, it is useful in minifier to be able to re-use the same `TraverseCtx` over and over, which requires having an owned `TraverseCtx`.

To support this use case, introduce `ReusableTraverseCtx`. It is an opaque wrapper around `TraverseCtx`, which prevents accessing the `TraverseCtx` inside it. It's safe for user to own a `ReusableTraverseCtx`, because there's nothing they can do with it except for using it to traverse via `traverse_mut_with_ctx`, which ensures the safety invariants are upheld.

At some point, we'll hopefully be able to reduce the number of passes in the minifier, and so remove the need for `ReusableTraverseCtx`.But in the meantime, this keeps `Traverse`'s API safe from unsound abuse.

Note: Strictly speaking, there is still room to abuse the API and produce UB by initiating a 2nd traversal of a different AST in an `Traverse` visitor, and then `mem::swap` the 2 x `&mut TraverseCtx`s. But this is a completely bizarre thing to do, and would basically require you to write malicious code specifically designed to cause UB, so it's not a real risk in practice. We'd need branded lifetimes to close that hole too.

So this PR doesn't 100% ensure safety in a formal sense, but it at least makes it very hard to trigger UB *by accident*, which was the risk before.
2024-11-28 10:30:53 +08:00
Nicholas Rayburn
99ecc687ba
feat(language_server): Add code actions to disable rules for the current line or entire file (#6968)
This definitely needs some cleanup by somebody more familiar with Rust,
but I think it contains most of the important pieces. I'll leave a
review with the different pieces that I know need cleanup.

Ref #6966.
2024-11-28 10:30:53 +08:00
Boshen
df58ebd914
chore: update wasm related configs (#7511) 2024-11-28 10:30:53 +08:00
Boshen
2077ff9269
refactor(linter): remove once_cell (#7510) 2024-11-28 10:30:52 +08: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
Dunqing
968863bef3 refactor(transformer/class-properties): move transform logic of callee of CallExpression to transform_private_field_callee (#7503)
This transform logic is also can be used to `tag` of `TaggedTemplateExpression`, so let's move it to a separate function.
2024-11-27 12:08:10 +00:00
overlookmotel
5261547c25 refactor(transformer/class-properties): remove a branch from transform_call_expression_impl (#7507)
Small optimization. `transform_call_expression_impl` does not require the `Expression::CallExpression`, only the `CallExpression` itself. So pass that into the function, instead of having to unwrap it (which is an unnecessary branch).
2024-11-27 11:24:10 +00:00
overlookmotel
1c4b29c100 refactor(transformer/class-properties): correct comments (#7506)
Correct comments. I did too much mindless copy-and-paste.
2024-11-27 11:11:39 +00:00
camc314
053bc081fb feat(linter): implement typescript/no-unused-expressions (#7498) 2024-11-27 10:28:41 +00:00
Cameron
7da9a39b5d
fix(rulegen): update lint rule template (#7502) 2024-11-27 17:40:38 +08:00
camc314
60b28fc23a feat(linter): implement typescript/consistent-generic-constructors (#7497) 2024-11-27 09:21:08 +00:00
leaysgur
32c7db0ec6 chore(tasks): Update prettier_conformance task (#7500)
- Update Prettier version: `3.3.3` > `3.4.1`
- Add more ignored tests
- Add `jsx` tests
- Remove unused `runner.rs`
- Refactoring
2024-11-27 08:40:43 +00:00
camc314
bd0693bcd0 feat(linter): allow lint rules with the same name (#7496)
Apologies @Boshen for the stupidly large diff.

I've done the following:

 - `RuleEnum`'s members are now prefixed with the plugin name. e.g. `NoDebugger` has become `EslintNoDebugger`
- updated tester.rs to accept the rule's NAME, CATEGORY to allow us to test rules with the same name (diff category)
- updates `declare_all_lint_rules` satisfy the first above change.
2024-11-27 04:25:05 +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
Dunqing
fed8327441 test(semantic): add a test for UpdateExpression (#7495)
related: https://github.com/oxc-project/oxc/pull/7388#issuecomment-2496044394
2024-11-27 02:00:52 +00:00
Dunqing
4b0720aabb test(semantic): re-organize snapshot-based tests (#7494)
Reorignize tests by splitting tests to js, ts, and jsx folders
2024-11-27 02:00:50 +00:00
Dunqing
ef62b9dacc refactor(transformer/react-refresh): use generate_uid_in_current_hoist_scope to add hoisted binding (#7492) 2024-11-26 16:12:11 +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
f3850eb53b fix(semantic): correctly resolve binding for return type of functions (#6388)
Fixes #6387.
2024-11-26 15:43:35 +00:00
Boshen
b0e1c03284
feat(ast)!: add StringLiteral::raw field (#7393)
part of #7254
2024-11-26 23:33:56 +08:00
7086cmd
97af341cac feat(minifier): minify alternated one child if block (#7231) 2024-11-26 15:00:16 +00:00
camc314
2ac9f963df feat(linter): typescript/no-inferrable-types (#7438) 2024-11-26 14:49:31 +00:00
Ethan Goh
ac0d25c426
feat(minifier): minify one child if statement expression (#7230) 2024-11-26 22:48:27 +08:00
Boshen
c133693e5c perf(minifier): fuse ast passes (#7493) 2024-11-26 14:30:04 +00:00
Dunqing
58a125ff88 fix(transformer/async-to-generator): correct the SymbolFlags of function id in module (#7470) 2024-11-26 11:59:22 +00:00
Dunqing
37842c166d fix(transformer/object-rest-spread): generate catch variable binding with correct SymbolFlags (#7469) 2024-11-26 11:59:21 +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
5ca6eea77e perf(transformer/class-properties): inline visitor methods (#7485)
Inline visitor methods in class properties transform.
2024-11-26 11:36:09 +00:00
7086cmd
24189f28ad feat(ecma): implement array join method (#6936) 2024-11-26 11:28:07 +00:00
Dunqing
9c9deaeffe feat(traverse): add generate_uid_in_current_hoist_scope method (#7423)
Add an API to handle variable hoisting.
2024-11-26 11:21:36 +00:00
Boshen
4f23689e79
chore(CODEOWNERS): add @leaysgur to oxc_prettier and oxc_regular_expression 2024-11-26 19:19:56 +08:00
leaysgur
3a1ef6a230 refactor(prettier): Refactor IR related macros (#7491)
- Remove `format!` macro
- Rename string related macros, `&'static`: `text!` and `'a`: `dynamic_text!`
- Apply `wrap!` macro instead of manually using `enter|leave_node`
- Introduce `/ir` directory and move `Doc`, `impl Display`, `DocBuilder`, etc.

I'm not yet determined how to, how deep to use macro, but this is first stepping stone... 🥌
2024-11-26 09:31:30 +00:00
tbashiyy
8d89fdc886
feat(linter): add eslint/prefer-spread (#7112)
In this PR, 
- move existing `unicorn:prefer-spread` to `eslint:prefer-spread`.
- combine 2 rules from `eslint:prefer-spread` and
`unicorn:prefer-spread`

([This is already talked in
discord](https://discord.com/channels/1079625926024900739/1080712072012238858/1299981398064496652))

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-26 17:30:38 +08:00
Boshen
cd7f62b311
chore(Cargo.toml): remove incremental = true because it uses too much disk space 2024-11-26 16:04:56 +08:00
Boshen
17c0dd8fb2
fix(linter): fix jsx_no_script_url doc failed to build
"Element is missing end tag."
2024-11-26 16:03:14 +08:00
oxc-bot
861ae1581a
release(oxlint): v0.13.2 (#7489) 2024-11-26 15:25:31 +08:00
oxc-bot
00a7372eaf
release(crates): v0.38.0 (#7490) 2024-11-26 14:38:47 +08:00
Boshen
45ef3eb2be chore(transformer): disable class properties transform from the target API (#7487) 2024-11-26 06:10:35 +00:00
Boshen
713e210012 chore(transformor): disable class properties transform (#7486)
The plugin is not ready.
2024-11-26 03:47:46 +00:00
Alexander S.
571d7e2419
fix(language_server): calculate correct column when Unicode chars (#7484)
Before:

![grafik](https://github.com/user-attachments/assets/ddae446d-9167-405b-b44e-c7f76850ffd0)

After:

![grafik](https://github.com/user-attachments/assets/e8d7ac5c-8fe9-4c51-897d-bdb55f7f33dc)

Closes #3625
2024-11-26 10:44:13 +08:00
Guillaume Piedigrossi
87c893fb49
feat(linter): add the eslint/no_duplicate_imports rule (#7309) 2024-11-25 20:56:29 +00:00
overlookmotel
e5d49db360 refactor(transformer/class-properties): placeholder method for transforming private field assignment patterns (#7482)
Add a no-op placeholder method for transforming private fields as `AssignmentPattern`s. e.g. `[object.#prop] = []`.

Implementation will be added later.
2024-11-25 20:10:07 +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
d2745df3bc fix(transformer/class-properties): stop searching for super() in TSModuleBlocks (#7480)
Fix edge case in class static properties transform. When transforming `super()` in class constructor, stop searching when hit a `TSModuleBlock`. `TSModuleBlock` is essentially a function, so `super()` there is invalid.
2024-11-25 20:10:03 +00:00
overlookmotel
2a5954ae71 docs(transformer/class-properties): document transform options (#7478)
Add docs for the `loose` option / `set_public_class_fields` assumption.
2024-11-25 17:17:28 +00:00
overlookmotel
abb0e0e08e refactor(transformer/class-properties): rename var (#7477)
Pure refactor. Name var more descriptively.
2024-11-25 16:45:21 +00:00