Commit graph

3739 commits

Author SHA1 Message Date
Boshen
08fdb267b4
chore: update CHANGELOG.md 2024-06-06 20:24:19 +08:00
Boshen
2cdc4085f7
ci: only run "update rules" when rules.rs changes 2024-06-06 16:04:41 +08:00
Boshen
604b7cf92b
ci: prepare release oxlint 2024-06-06 16:04:41 +08:00
rzvxa
60f89d1fcf improvement(semantic/cfg): better throw control flow. (#3473)
https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9306698136
2024-06-06 07:55:50 +00:00
rzvxa
987a3f36a8 improvement(linter/react): use CFG for detecting cyclic subgraphs in rules-of-hooks. (#3454) 2024-06-06 07:55:44 +00:00
rzvxa
61bae74f76 improvement(semantic/cfg): better CFG API (#3472) 2024-06-06 07:55:37 +00:00
rzvxa
3c7ee85ce4 improvement(semantic/cfg): better break and continue flow. (#3462)
This PR adds a new edge type called `Jump` to distinguish between normal edges and jumps.
There is also a control flow context which is used to keep track of cfg scopes and labels. It replaces the old `preserve_state` and `restore_state`.
It corrects some mistakes - such as labeled blocks especially labeled continue which wasn't easy to implement with the old approach - in the old control flow but other than that it is mostly refactored to have a more declarative API instead of a procedural approach.
2024-06-06 07:55:31 +00:00
Boshen
769227b7b4
chore: regenerate changelogs 2024-06-06 15:51:53 +08:00
Dunqing
0007ee47be
chore(coverage, transformer_conformance): print all AST whether or not they are Typecript AST (#3556)
We have a conclusion that codegen will print whatever is in the AST,
instead of having an option to enable printing TypeScript syntax. I plan
to remove codegen's `enable_typescript` option after we strip out all
typescript AST in the transformer typescript plugin.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-06 15:45:20 +08:00
Boshen
6db4d7dc09
chore: update cliff.toml 2024-06-06 15:09:07 +08:00
Boshen
509ed2bcf3
ci: update prepare release crates; regenerate the changelogs 2024-06-06 14:28:51 +08:00
Yuji Sugiura
747500ac5a
feat(linter/jsdoc): Implement require-returns-type rule (#3458)
Part of #1170

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns-type.md
2024-06-06 14:11:39 +08:00
Don Isaac
1fb9d234a6
feat(linter): add fixer for no-useless-fallback-in-spread rule (#3544) 2024-06-06 13:59:42 +08:00
rzvxa
ff3f37dbbd improvement(semantic/cfg): better control flow for ForStatements. (#3453)
similar to #3451 and #3452
2024-06-06 05:41:08 +00:00
rzvxa
91c999546c improvement(semantic/cfg): better control flow for DoWhileStatements. (#3452)
similar to #3451
2024-06-06 05:41:06 +00:00
rzvxa
0012094188 improvement(semantic/cfg): better control flow for WhileStatements. (#3451)
Fixes a simple cfg issue, previously it wouldn't follow the body subgraph correctly.
2024-06-06 05:41:04 +00:00
rzvxa
209a99d49f improvement(semantic/cfg): rework basic blocks. (#3381)
I've replaced the `BasicBlockElement` with an `Instruction` type which would keep both the instruction kind and its associated AstNodeId.
I also removed the register scheme in the control flow in favor of a simpler approach using explicit enums.

https://github.com/oxc-project/oxc/pull/3381#issuecomment-2126622774
2024-06-06 05:41:01 +00:00
Dunqing
646b9937ee feat(coverage/transformer): handle @jsx option (#3553)
if has`@jsx: react`, configure transformer options to match `@jsx: react` behavior
2024-06-06 05:34:22 +00:00
Dunqing
3ba2a932d6 refactor(coverage): use code without meta options in TypeScriptSuite (#3552)
The `@jsx: react` is a typescript option. The `Babel` typescript plugin handles @jsx as well, but this is different. `@jsx` in babel is a [pragma](https://babeljs.io/docs/babel-plugin-transform-react-jsx#pragma) option. So we should use code without these meta options to avoid Babel parsing `@jsx` incorrectly
2024-06-06 05:34:18 +00:00
overlookmotel
f6939cbd92 fix(transformer): store react_importer in Bindings in JSX transform (#3551)
Fix a small bug in React JSX transform. If `import_source` is invalid, the default value `"react"` is used for JSX runtime imports. But for importing React alone, it was still using the old invalid value.

This also allowed removing `ReactOptions` from `Bindings` and just storing `is_development` instead.
2024-06-06 03:19:53 +00:00
overlookmotel
09481244c0 refactor(transformer): pass Rcs by value (#3550)
`Rc<T>` is already a pointer, so passing `&Rc<T>` to functions adds unnecessary indirection (reference to a reference).
2024-06-06 03:19:50 +00:00
overlookmotel
7982b93fb5 fix(transformer): correct spans for JSX transform (#3549)
Correct spans in output of React JSX transform, so it should produce correct source maps.

Have copied which AST nodes have spans and which don't from Babel.
2024-06-06 03:19:47 +00:00
overlookmotel
e4d74ac3ee refactor(transformer): remove update_fragment from JSX transform (#3541)
Fix #3464.

Import of fragment has to be done late in order to replicate the order of imports in Babel's output. But do that in a simpler way.
2024-06-06 03:19:44 +00:00
overlookmotel
73b78643f2 refactor(transformer): combine import and usage in JSX transform (#3540)
React JSX transform contains some confusing logic (ported directly from Babel) where in automatic mode, imports are inserted in one place, and then used in another.

Logic for which imports are needed is duplicated in both places, and it's hard to figure out whether they're in sync or not (I don't think they are in all cases).

This PR unifies the logic in one place. Imports are now added as and when they're used.

The `Bindings` enum is responsible for creating imports and also holds the state of which "mode" the plugin is working in:

1. Classic
2. Automatic script
3. Automatic module

Combining the two choices classic/automatic and script/module into a single enum:

1. clarifies the logic
2. reduces branching
3. reduces lookups on `ReactJsx::options` (which is behind an `Rc` and therefore costly to read from).
2024-06-06 03:19:41 +00:00
overlookmotel
4586f0bf5c improve(transformer): validate JSX import source option (#3537)
Validate `import_source` option for React JSX transform - disallow empty string.
2024-06-06 03:19:38 +00:00
overlookmotel
14c00a5c1d improve(transformer): validate JSX pragma options (#3536)
Validate React JSX `pragma` and `pragma_frag` options. Don't allow:

* empty string
* `foo.bar.qux`
* `foo.`
* `.bar`
* `.`

If options provided are invalid, raise an error and use the defaults.

Also fast path the defaults.
2024-06-06 03:19:34 +00:00
Don Isaac
6506d086b3
feat(linter): add fixer for no-single-promise-in-promise-methods (#3531)
Fixes look like this:

```rs
let fix = vec![
    ("Promise.all([null]).then()", "Promise.resolve(null).then()", None),
    ("let x = await Promise.all([foo()])", "let x = await foo()", None),
    ("let x = await (Promise.all([foo()]))", "let x = await (foo())", None),
];
```

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-06 01:40:03 +08:00
Boshen
0674604d7a
chore: regenerate changelog 2024-06-06 01:29:38 +08:00
Don Isaac
1d3c0d7879
docs(span): add doc comments to oxc_span::Span (#3543) 2024-06-06 01:05:34 +08:00
Boshen
dd42f279f7
chore: change website url to https://oxc.rs 2024-06-05 22:05:08 +08:00
overlookmotel
9f467b8479
perf(transformer): avoid fragment update where possible (#3535)
Due to needing to align output with Babel, React JSX transform has to
perform imports for fragments after dealing with the fragments'
children.

Transform generates a dummy identifier initially, and then generates a
UID later on and replaces the dummy.

The PR avoids that process 2-stage process unless we have to. If the UID
was already generated for a previous fragment, we can just use it
straight away.
2024-06-05 19:35:07 +08:00
overlookmotel
ac394f0ec3
perf(transformer): JSX parse pragma only once (#3534)
Currently React JSX transform in classic mode with a custom
`options.pragma` value parses `options.pragma` on every JSX node, and
inserts new `Atom`s into arena every time.

This PR makes it parse `options.pragma` only once at the start of the
transform pass, and re-use the same `Atom`s for each JSX node.
2024-06-05 18:42:43 +08:00
Dunqing
6978269be0 refactor(transformer/typescript): replace reference collector with symbols references (#3533)
https://github.com/oxc-project/oxc/pull/3524 handled the references correctly, now we can remove the reference collector.
2024-06-05 09:02:51 +00:00
Dunqing
ee9a215a21 feat(transformer/typescript): handle namespace directive correctly (#3532) 2024-06-05 09:02:49 +00:00
Boshen
30ba828bc3
Update README.md 2024-06-05 16:35:38 +08:00
Dunqing
affb2c864e
fix(codegen): print indentation before directive (#3512) 2024-06-05 16:32:12 +08:00
overlookmotel
c00598b9d4
fix(transformer): JSX set reference_id on refs to imports (#3524)
Set `reference_id` for references to new imported bindings. e.g. `_jsx`
in `_jsx(Foo, {})` where JSX transform has inserted `import {jsx as
_jsx} from "react/jsx-runtime";`.
2024-06-05 10:57:05 +08:00
IWANABETHATGUY
9fe0863479
chore(oxc_codegen): Pass trivias reference instead of ownership in CommentGenRelated (#3529)
1. Avoid clone or move the ownership when generate comment with `oxc`
2024-06-04 23:21:06 +08:00
Boshen
19bc7eb20f
ci: fix mac build in release_napi_parser 2024-06-04 18:40:24 +08:00
Boshen
119d87510d
ci: fix release crate push tag permission 2024-06-04 18:22:22 +08:00
Boshen
20f1754f57
chore: update Cargo.lock 2024-06-04 18:05:57 +08:00
github-actions[bot]
d48e62aca4
Publish crates v0.13.3 (#3527)
Automated Release

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-04 18:02:40 +08:00
Dunqing
ddac2a0e12
refactor(codegen): reduce allocation for print_unquoted_str (#3525) 2024-06-04 16:46:56 +08:00
Boshen
9706c3b533
ci: adjust publish workflow 2024-06-04 16:40:15 +08:00
Boshen
9a0d1ad165
chore: format top level toml files 2024-06-04 16:05:08 +08:00
Boshen
ebd683bb4b
chore: add oxc_release.toml 2024-06-04 16:05:08 +08:00
overlookmotel
591c54bd31 fix(transformer): JSX set symbol_id on imports (#3523)
JSX transform set `symbol_id` on imported bindings. e.g. `_jsx` in `import {jsx as _jsx} from "react/jsx-runtime";`.

Setting matching `reference_id` on `IdentifierReference`s referring to the imports is not yet implemented.
2024-06-04 03:02:44 +00:00
overlookmotel
91519d9e67 perf(transformer): React JSX reduce allocations (#3522)
React JSX transform was creating `CompactStr`s (which can involve heap allocations) and then converting them back to `Atom`s to insert into AST.

This PR removes the intermediate `CompactStr`s and allocates strings directly into the arena without intermediate heap allocations.
2024-06-04 03:02:42 +00:00
overlookmotel
f3a755c3dc perf(transformer): React JSX reuse same Atoms (#3521)
Previously new `Atom`s were generated and allocated into arena each time e.g. `_React` is used. This PR changes that to allocate each string into arena once only, and then re-use that same `Atom` over and over.
2024-06-04 03:02:39 +00:00
overlookmotel
7bbd3da0f2 refactor(traverse): generate_uid return SymbolId (#3520)
Preparatory step for setting correct `SymbolId` for identifiers added to AST in transformer.
2024-06-04 03:02:37 +00:00