Commit graph

7114 commits

Author SHA1 Message Date
Boshen
b4258ee58e feat(transformer): add defaulted Module::Preserve option (#7225) 2024-11-09 12:55:13 +00:00
oxc-bot
68dc899887
release(oxlint): v0.11.1 (#7224)
## [0.11.1] - 2024-11-09

### Features

- 4dd9b60 editor/vscode: Replace existing output channel and trace
output channel with a single LogOutputChannel (#7196) (Nicholas Rayburn)
- 1fcd709 linter: Add jsx support for only-used-in-recursion (#7120)
(no-yan)
- 4d577cf linter: Add `import/first` rule (#7180) (Dmitry Zakharov)
- 9b8973f linter: Add `import/unambiguous` rule (#7187) (Dmitry
Zakharov)
- 5ab1ff6 linter: Implement @typescript-eslint/no-unsafe-function-type
(#6989) (Orenbek)

### Bug Fixes

- eea8879 editor/vscode: Update language client id to fix the resolution
of the oxc.trace.server setting (#7181) (Nicholas Rayburn)
- b73cfd9 linter: Fix `is_method_call` with parentheses and chain
expression (#7095) (tbashiyy)

### Refactor

- 8c0a362 linter: Use `ctx.source_range(comment.content_span())` API
(#7155) (Boshen)
- c5485ae semantic: Add `ancestor_kinds` iterator function (#7217)
(camchenry)
- abf1602 semantic: Rename `iter_parents` to `ancestors` (#7216)
(camchenry)
- 42171eb semantic: Rename `ancestors` to `ancestor_ids` (#7215)
(camchenry)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-09 19:57:08 +08:00
Boshen
c62e192a68
ci: fix oxlint-ecosystem-ci 2024-11-09 19:56:07 +08:00
7086cmd
a2977655c8 refactor(minifier): use map and and_then instead of let else (#7178)
For the test case, Closure Compiler doesn't handle this at all in the REPL! If it's necessary, I will turn it back.

This PR uses builtin `and_then` and `map` method, which is better instead of a lot of `if let Some`.
2024-11-09 11:48:48 +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
Boshen
fc86703933
refactor(napi/transform): change test files to TypeScript (#7221) 2024-11-09 17:32:15 +08: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
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