Commit graph

2747 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
overlookmotel
837776e1ab fix(transformer): TS namespace transform do not track var decl names (#3501)
Don't track variable declaration or import binding names in TS namespace transform.

Babel does, but it appears to be wrong. It's illegal to have a `var`/`let`/`const` declaration or import in same scope as a TS namespace declaration with same binding.

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAQTgMyhEcDkUCmBDAYxkwG4AoAOzxBwGcxCdE4BvAXzLIIgtvgCE4AXjgBGclRr1GcQSzJxFcADY54AD3Icyq+AGFhYidToMCTA-KUq1cTWW0A3PFDgARQ+Monp596wUlXTstMiA
2024-06-03 12:35:57 +00:00
overlookmotel
8d2beff2fe fix(transformer): use correct scope for TS namespaces (#3489)
Re-use scope ID from `TSModuleDeclaration` for the scope of the function which replaces it in transformed output.

This should mean the scope tree is left in correct state after the transform.

NB: Still incomplete - we also need to transfer the binding ID from `X` in `namespace X {}` to `let X` in output.
2024-06-03 12:31:39 +00:00
overlookmotel
8e4f33557d
fix(transformer): output empty file for TS definition files (#3500)
As discussed in
https://github.com/oxc-project/oxc/pull/3489#issuecomment-2143482458,
transformer should output an empty file for TS definition files.
2024-06-03 20:25:02 +08:00
Dunqing
98c90291b0 fix(codegen): should be double quote for jsx attribute value (#3516) 2024-06-03 10:05:13 +00:00
Dunqing
d4588d7cac chore(codegen): print typescript code for typescript files (#3515)
We should not print typescript code as javascript code. Forcing to print as JavaScript code may result in syntax errors. If we truly want javascript code, we can use the `oxc_transformer`.
2024-06-03 10:05:08 +00:00
Dunqing
d8063b6210
fix(codegen): wrong escape string (#3514)
close: #3492
2024-06-03 15:48:01 +08:00
github-actions[bot]
079d42f68b
Release crates v0.13.2 (#3513)
Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-03 12:40:53 +08:00
Wang Wenzhe
6b39654c80
feat(linter/tree-shaking): support options (#3504) 2024-06-03 11:28:48 +08:00
cinchen
daf559f06f
feat(linter): eslint-plugin-jest/no-large-snapshot (#3436)
part of https://github.com/oxc-project/oxc/issues/492

Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/no-large-snapshots.ts)

---------

Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-06-02 22:58:28 +08:00
overlookmotel
6f71541db0 fix(semantic): set program scope_id for TS definition files (#3496)
Semantic does not visit the AST for TS definition files, but it does create a root scope. Record this scope ID in `Program`'s `scope_id` field.
2024-06-01 10:13:45 +00:00
Boshen
9ff4feaa4c
chore: bump oxc-browserslist to 0.17.0 (#3495) 2024-06-01 15:06:34 +08:00
overlookmotel
ff7e8c7448 refactor(ast): update scope attrs (#3494)
Update scope attrs used by `oxc_traverse` codegen on `MethodDefinition` and `Function` types. These attrs are currently ignored by the codegen anyway, so causes no change in generated code, but bringing them up to date in preparation for #3392.
2024-05-31 17:58:01 +00:00
overlookmotel
3967a15b60 fix(traverse): exit scope early if enter it late (#3493)
Fixes #3490.
2024-05-31 17:53:23 +00:00
overlookmotel
55bbde2888 refactor(ast): move scope from TSModuleBlock to TSModuleDeclaration (#3488)
Closes #3471.

Remove scope from `TSModuleBlock` and add scope to `TSModuleDeclaration` instead.
2024-05-31 17:33:05 +00:00