Commit graph

6707 commits

Author SHA1 Message Date
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
24c585a20a
feat(napi/parser): reexport @oxc-project/types (#7214)
closes #7207
2024-11-09 17:24:07 +08:00
no-yan
1fcd70932d
feat(linter): add jsx support for only-used-in-recursion (#7120)
close #5530

This PR adds support for handling recursive JSX components, allowing
detect functions like the one below:

```javascript
function ListItem({ depth }) {
    return <ListItem depth={depth} />
}
```

Some logic is duplicated with the non-JSX case. But the refactor will be
complicated and affects over-all, so we can make it in another PR.

cc: @DonIsaac @camc314

---------

Co-authored-by: Cam McHenry <camchenry@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-09 17:11:27 +08:00
Dmitry Zakharov
4d577cf69f
feat(linter): add import/first rule (#7180) 2024-11-09 17:10:59 +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
Boshen
0e4adc15dd feat(ast)!: remove invalid expressions from TSEnumMemberName (#7219) 2024-11-09 08:48:14 +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
camchenry
c5485ae7ee refactor(semantic): add ancestor_kinds iterator function (#7217)
for convenience, I've added a new function called `ancestor_kinds` which loops overall `ancestors` and gets their `AstKind`. this is a common pattern in a couple of places. I also did some somewhat related refactoring to remove places where we were manually calling `AstNode::kind` instead of using `ancestor_kinds` or calling `parent_kind`.
2024-11-09 08:04:38 +00:00
camchenry
abf1602f33 refactor(semantic): rename iter_parents to ancestors (#7216)
for consistency with the `ancestor_ids` function, this changes it to use the same terminology but make it clear it actually returns the node, not just the ID.

this is pure refactor, no functional changes here.
2024-11-09 07:07:26 +00:00
camchenry
42171eba94 refactor(semantic): rename ancestors to ancestor_ids (#7215)
pure refactor, renaming this method to make it more clear that it returns only IDs, not nodes. in preparation for the next PR.
2024-11-09 07:00:15 +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
ottomated
092de67c47 fix(types)!: append rest field into elements for objects and arrays to align with estree (#7212)
Fixes https://github.com/oxc-project/oxc/pull/7149#discussion_r1831677446 and removes the need for some manual typescript.
2024-11-09 05:23:53 +00:00
Boshen
a166a4abd7 feat(transformer): add esbuild comma separated target API --target=es2020,chrome58 (#7210) 2024-11-08 14:09:20 +00:00
Dunqing
b74686c598 feat(isolated-declarations): support transform TSExportAssignment declaration (#7204)
part of #7141
2024-11-08 11:51:41 +00:00
Dunqing
4a515be24e refactor(transformer/arrow-function-coverter): rename function name and add some comments to explain confusing parts. (#7203)
close: #7174
2024-11-08 08:18:46 +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
Boshen
3a20b906f4 feat(transformer): add es target to engineTargets (#7193) 2024-11-08 03:25:21 +00:00
Dunqing
c82b273154 fix(transformer/async-generator-functions): only transform object method in exit_function (#7200)
close: #7175
2024-11-08 03:15:28 +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
b4cb587477 chore(transformer_conformance): only ignore root fixtures directory (#7198)
This blocks us from adding tests for plugins.

See the URL a2244ff089/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/arrow
2024-11-08 02:36:22 +00:00
Huáng Jùnliàng
9a6423a9f8
test(coverage): enable Babel es2022 tests (#7194)
Enabled the Babel es2022 tests. Previously they were skipped probably
because ES2022 was not yet supported at that time.
2024-11-08 09:29:36 +08:00
Nicholas Rayburn
4dd9b60f5a
feat(editor/vscode): Replace existing output channel and trace output channel with a single LogOutputChannel (#7196)
I don't think we need two separate channels for output. This replaces
the 2 existing channels with a single channel that allows configuring
the log level.

Ref #7136
2024-11-08 09:23:16 +08:00
Dmitry Zakharov
9b8973f425
feat(linter): add import/unambiguous rule (#7187) 2024-11-08 08:54:37 +08:00
Orenbek
5ab1ff6f06
feat(linter): implement @typescript-eslint/no-unsafe-function-type (#6989)
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-07 17:14:19 +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
de560837eb refactor(transformer): add impl TryFrom<EngineTargets> for EnvOptions (#7191) 2024-11-07 14:12:31 +00:00
Boshen
0a43c640e6 refactor(transformer): move ESTarget to its own file (#7189) 2024-11-07 11:52:32 +00:00
Boshen
22898c855a feat(transformer): warn BigInt when targeting < ES2020 (#7184)
closes #5822
2024-11-07 08:29:03 +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
Boshen
14ce0eef44 feat(tasks/compat_data): init compat data task (#7156) 2024-11-07 07:39:32 +00:00
Dmitry Zakharov
500effe5bb
chore(linter): correct links to docs in rules (#7183) 2024-11-07 15:20:47 +08:00
Nicholas Rayburn
eea8879642
fix(editor/vscode): Update language client id to fix the resolution of the oxc.trace.server setting (#7181)
Currently `oxc-vscode.trace.server` needs to be used to enable trace
logging for the language server. This fixes it so that
`oxc.trace.server` can be used. I can't find any guidance on what should
be used for the language client id. The VS Code ESLint plugin uses
"ESLint", so I think this change should be fine.

Ref https://github.com/oxc-project/oxc/issues/7136.
2024-11-07 13:29:52 +08:00
ottomated
9d6cc9d3af feat(estree): ESTree compatibility for all literals (#7152)
Adds some new estree macro directives:
- `#[estree(via = foo::Foo)`: Uses From to convert this struct to foo::Foo before serialization
- `#[estree(add_ts = "foo: string")]`: Adds additional fields to the typescript definitions

Used these to make all different literals estree-compatible.
2024-11-06 21:25:41 +00:00
ottomated
dc0215c906 feat(ast_tools): Add #[estree(append_to)], remove some custom serialization code (#7149)
Removed custom logic for ObjectPattern, ArrayPattern, etc. in favor of a custom attribute macro `#[estree(append_to = "foo")]` as part of #6347
2024-11-06 21:09:45 +00:00
overlookmotel
84ee581980 refactor(transformer/async-generator-functions): simplify identifying whether within an async generator function (#7170)
Follow-on after stack up to #7148.

Split `is_inside_async_generator_function` into 2 functions `yield_is_inside_async_generator_function` and `async_is_inside_async_generator_function`.

There are a couple of differences between `yield` and `await`, which we can leverage to make both these functions simpler:

* `yield` cannot appear at top level (there's no such thing as "top level yield").
* `yield` cannot appear in an arrow function (there's no such thing as a "generator arrow function").

In addition:

* Because each function now handles a specific case, no need to check if function containing `async` is an async function. It must be. Ditto for `yield`.
* Remove the `if ctx.current_scope_flags().is_top()` check. Probably this check costs more than it saves because top level `await` is far less common than `await` within async functions. So this check was optimizing for an uncommon case, at a cost to the common case.
* Add more comments to explain the logic.

This is all quite small optimizations, but I was having difficulty understanding the logic, and found that splitting it up made it clearer (at least for me).
2024-11-06 16:06:51 +00:00
overlookmotel
64b7e3a603 style(transformer/async-generator-functions): import oxc_allocator::Vec as ArenaVec (#7173)
Follow-on after stack up to #7148. Style nit. Following our convention (#6996), import `oxc_allocator::Vec` as `ArenaVec`, to prevent ambiguity.
2024-11-06 16:06:49 +00:00
overlookmotel
1b12328f87 refactor(transformer/async-generator-functions): use clone not clone_in on LabelIdentifier (#7172)
Follow-on after stack up to #7148.

Small optimization. `LabelIdentifier` is `Clone` so we can use `Clone::clone` to clone it, instead of `CloneIn::clone_in`.

The difference is that `clone_in` makes a 2nd copy of the `Atom`'s string in the arena, whereas `clone` creates a new `Atom` referencing the same string. This is an unfortunate shortcoming of `CloneIn` (https://github.com/oxc-project/backlog/issues/96), but the more we can avoid `CloneIn`, the better.
2024-11-06 16:06:48 +00:00
overlookmotel
c307e1b7e8 refactor(transformer/arrow-functions): pass ArenaBox as function param (#7169)
Follow-on after stack up to #7148.

Small optimization. `ArrowFunctionExpression` is 56 bytes, whereas `ArenaBox<ArrowFunctionExpression>` is 8 bytes. So it's preferable to pass the `ArenaBox<ArrowFunctionExpression>` to `transform_arrow_function_expression` and call `unbox` on it there instead of unboxing *before* passing to the function.
2024-11-06 14:08:14 +00:00
overlookmotel
38a6df6f66 style(transformer/arrow-functions): semicolon after return statements (#7168)
Follow-on after stack up to #7148. Style nit. End statements with semi-colons. Usually clippy demands this, not sure why it didn't here.
2024-11-06 14:08:12 +00:00
overlookmotel
1238506980 refactor(transformer/async-generator-function): remove inactive #[allow(clippy::unused_self)] attrs (#7167)
Follow-on after stack up to #7148. Remove 2 x `#[allow(clippy::unused_self)]` attrs where that lint isn't triggered because the functions do use their `&self` param.
2024-11-06 14:08:11 +00:00
overlookmotel
b57d5a5277 refactor(transformer/async-to-generator): remove unused &self function param (#7166)
Follow-on after stack up to #7148. Remove unused `&self` function param. This makes calling this function slightly cheaper, as unused data doesn't get passed to the function.
2024-11-06 14:08:09 +00:00
overlookmotel
217d433eb8 refactor(transformer/arrow-functions): remove unused &mut self function param (#7165)
Follow-on after stack up to #7148. Remove unused `&mut self` function params. This makes calling these functions slightly cheaper, as unused data doesn't get passed to the function.
2024-11-06 14:08:08 +00:00
overlookmotel
426df71c13 refactor(transformer/arrow-functions): use scope_id method (#7164)
Follow-on after #7125. Use `scope_id` method introduced in #7127.
2024-11-06 14:08:06 +00:00
overlookmotel
11c5e1209a refactor(transformer/arrow-functions): correct comments (#7163)
Follow-on after #7113. This comment was outdated after the changes in that PR.
2024-11-06 14:08:04 +00:00
overlookmotel
e2241e6376 refactor(transformer/jsx-self): remove unused &self function params (#7159)
Small nit. Removing the unused `&self` param makes these function calls slightly cheaper.
2024-11-06 13:11:31 +00:00
Boshen
0e1f12c303 refactor(transformer): remove unimplemented EnvOptions::bugfixes (#7162) 2024-11-06 12:54:10 +00:00
Boshen
a981cafd1f refactor(transformer): add Engine enum for EngineTargets (#7161) 2024-11-06 12:40:31 +00:00