Commit graph

2986 commits

Author SHA1 Message Date
overlookmotel
1061baabbf refactor(traverse): separate #[scope] attr (#3901)
Separate out attributes which communicate info to codegen related to scopes into `#[scope]` attr.

Before:

```rs
#[visited_node(scope(ScopeFlags::empty()))]
pub struct BlockStatement<'a> { /* ... */ }
```

After:

```rs
#[visited_node]
#[scope]
pub struct BlockStatement<'a> { /* ... */ }
```

I think this is clearer.
2024-06-26 05:43:10 +00:00
overlookmotel
5ef28b7375 refactor(transformer): shorten code (#3912)
Abbreviate `self.ctx.ast` to just `ast` to shorten code.
2024-06-26 05:16:07 +00:00
overlookmotel
08fcfb3c2f fix(transformer): fix spans and scopes in TS enum transform (#3911)
Fix scope and spans in TS `enum` transform.

Incomplete - not yet fixed either scopes or spans for the interior of the function which TS `enum` is transformed into, only what's outside the function.
2024-06-26 05:16:05 +00:00
overlookmotel
17ad8f7d93 fix(transformer): create new scopes for new blocks in TS transform (#3908)
Create scopes for new `BlockStatement`s inserted in TS transform, and update scope tree.
2024-06-26 05:16:02 +00:00
DonIsaac
01572f037d feat(sourcemap): impl std::fmt::Display for Error (#3902) 2024-06-26 05:10:48 +00:00
camc314
77a4a0b77c feat(minifier) minify conditional expressions (#3907) 2024-06-26 05:06:53 +00:00
overlookmotel
6f260871d7 refactor(ast): add comment about alternatives to AstBuilder::copy (#3905)
Expand on comment added in #3891.
2024-06-25 18:45:06 +00:00
Jelle van der Waa
fafe67c817
feat(linter/import): Implement max-dependencies (#3814)
Rule Detail:

[link](https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/max-dependencies.md)

---

This lacks the handling of `require()` which seems to be the case for
most existing `import` rules.

Another "issue" could be if you have:
```
import { foo } from "./foo";
import { bar } from "./foo";
```

But then again there should be another rule to filter these duplicate
imports out and combine them into one.

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-06-25 13:18:01 -04:00
rzvxa
2e026e1b7f feat(ast_codegen): generate ast_kind.rs. (#3888)
[List of 68 blacklisted items](https://github.com/oxc-project/oxc/pull/3888/files#diff-59cbea4a1444e752992821d3429a5f27bf1027a530977d075ec89aa55995912aR11)
2024-06-25 15:47:04 +00:00
rzvxa
6796891e2e fix(ast)!: rename all instances of BigintLiteral to BigIntLiteral. (#3898)
Notice the casing! Just for the sake of consistency.
2024-06-25 14:39:42 +00:00
rzvxa
09f4d3c4d3 feat(ast_codegen): add ImplGetSpanGenerator. (#3852)
This one is ready to replace the handwritten module.
2024-06-25 14:39:39 +00:00
Luca Bruno
92c21b266e
perf(diagnostics): optimize string-buffer reallocations (#3897)
This improves `GraphicalReportHandler` logic by using a string-buffer
with a capacity hint. That avoids growing the buffer from zero each
time, saving a bunch of reallocations.
2024-06-25 17:55:53 +08:00
rzvxa
1f85f1a5f7 refactor(ast)!: revert adding span field to the BindingPattern type. (#3899)
Since this is a temporary solution in the time that we are waiting for the `#[span]` hint, And there are already other workarounds used in our `ast_codegen` I propose removing it right away - sorry in my opinion adding it in the first place was a mistake - in favor of adding an edge case in the codegen. It is better to do the refactoring in the codegen instead of the production code which people may depend on.
2024-06-25 09:43:48 +00:00
Boshen
4bf405ddfc perf(parser): add a few more inline hints to cursor functions (#3894) 2024-06-25 06:00:46 +00:00
Boshen
187f0782c1 refactor(parser): improve parsing of parse_function_or_constructor_type (#3892)
part of #3502
2024-06-25 03:43:02 +00:00
overlookmotel
442aca3ba8
refactor(ast): add comment not to use AstBuilder::copy (#3891)
As discussed in #3483, `AstBuilder::copy` is unsound. It's going to be a
hard slog removing all uses of it. This PR adds a comment to please not
introduce any further usages of it in meantime.
2024-06-25 09:12:43 +08:00
mysteryven
328445b4ca feat(linter): support vitest/no-disabled-tests (#3717) 2024-06-24 15:16:32 +00:00
Dunqing
ef82c78a72 fix(parser): trailing comma is not allowed in ParenthesizedExpression (#3885)
close: #3878

The implementation is copied from `SeparatedList`'s `print_list`.
```diff
    fn parse_list(&mut self, p: &mut ParserImpl<'a>) -> Result<()> {
        p.expect(self.open())?;

        let mut first = true;

        while !p.at(self.close()) && !p.at(Kind::Eof) {
            if first {
                first = false;
            } else {
                p.expect(self.separator())?;
-                if p.at(self.close()) {
-                    break;
-               }
            }

            self.parse_element(p)?;
        }

        p.expect(self.close())?;
        Ok(())
    }
```
2024-06-24 14:56:32 +00:00
overlookmotel
fcd21a6a75 refactor(traverse): indicate scope entry point with scope(enter_before) attr (#3882)
Improve annotation of AST types for codegen.

Currently:

```rs
#[visited_node(
    scope(ScopeFlags::empty()),
    enter_scope_before(cases),
)]
pub struct SwitchStatement<'a> {
    pub span: Span,
    pub discriminant: Expression<'a>,
    pub cases: Vec<'a, SwitchCase<'a>>,
    pub scope_id: Cell<Option<ScopeId>>,
}
```

After this PR:

```rs
#[visited_node(scope(ScopeFlags::empty()))]
pub struct SwitchStatement<'a> {
    pub span: Span,
    pub discriminant: Expression<'a>,
    #[scope(enter_before)]
    pub cases: Vec<'a, SwitchCase<'a>>,
    pub scope_id: Cell<Option<ScopeId>>,
}
```

I think this is easier to read.

In order to enable use of `#[scope]` attr, this introduces a dummy `VisitedNode` derive macro. Like the `visited_node` macro, `VisitedNode` derive macro is designed to do very minimal work and have no heavy dependencies, so it should be almost 0 cost in terms of compile time.
2024-06-24 14:12:15 +00:00
overlookmotel
24979c98b2 refactor(traverse): use camel case props internally (#3880)
Small change to internals of `oxc_traverse` codegen. Use camel-case property names.
2024-06-24 13:19:34 +00:00
overlookmotel
2045c92338 refactor(traverse): improve parsing attrs in traverse codegen (#3879)
Make parser in `oxc_traverse` codegen a bit more robust - handle trailing comma in `#[visited_node]` attrs.
2024-06-24 13:19:31 +00:00
Boshen
7f1266a37b chore(deps): update rust crates (#3873) 2024-06-24 11:24:54 +00:00
Dunqing
5e2baf3edd feat(isolated-declarations): report error for expando functions (#3872)
close: #3703
2024-06-24 10:56:23 +00:00
kaykdm
8c61f9c0b4
feat(linter): implement @typescript-eslint/no-non-null-assertion (#3825)
Related issue: https://github.com/oxc-project/oxc/issues/2180

original implementation

- code:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/no-non-null-assertion.ts
- test:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/tests/rules/no-non-null-assertion.test.ts
- doc: https://typescript-eslint.io/rules/no-non-null-assertion/


typescript-eslint has a feature that is manually fixable by editor
suggestions on this rule, but oxc does not have one as far as I know, so
the implementation is simple compared to typescript-eslint
2024-06-24 00:09:52 -04:00
Dunqing
5501d5ce33 feat(transformer/typescript): transform import {} from "mod" to import "mod" (#3866)
close: #3736
2024-06-24 03:27:39 +00:00
DonIsaac
10d1de584b perf(semantic): remove uneccessary allocation in builder (#3867) 2024-06-24 02:57:08 +00:00
overlookmotel
8c9fc6347d fix(semantic): apply strict mode scope flag for strict mode TS Modules (#3861)
#3830 added a `directives` field to `TSModuleBlock`. Make semantic apply strict mode scope flag if directives include `'use strict'`.
2024-06-24 02:38:59 +00:00
overlookmotel
acf69fa1b6 refactor(ast): refactor custom Serialize impls (#3859)
Store `&[T]` instead of `&Vec<'a, T>` in temp structures in custom `Serialize` impls. Slightly cleaner and removes some lifetimes.
2024-06-24 02:31:59 +00:00
overlookmotel
063cfdeb40 fix(ast): correct JSON serialization of TSModuleBlock (#3858)
Fix #3848.

#3830 added a `directives` field to `TSModuleBlock`. ESTree AST treats directives in module blocks as `StringLiteral`s. Add a custom `Serialize` impl to combine any directives back into `body` in JS AST.

NB: `#[serde(skip)]` attr on `directives` field is for benefit of `Tsify` derive macro, so TS defs match the actual JSON AST.
2024-06-24 02:25:49 +00:00
overlookmotel
66f404c2f3 fix(ast): fix JSON serialization of BindingPattern (#3856)
#3855 added a `span` field to `BindingPattern` but it's duplicate information from `BindingPatternKind`. `BindingPatternKind`'s `span` is already included in JS AST, so serde can skip the duplicate in `BindingPattern`.
2024-06-24 02:21:40 +00:00
overlookmotel
9e148e97a9 refactor(ast): add line breaks (#3860)
Code style nit. Add line breaks between some `impl`s.
2024-06-23 20:22:11 +00:00
Boshen
777f12b6fd
chore(isolated-declarations): run integration tests only once 2024-06-24 00:24:16 +08:00
Boshen
f3a21a28d7
chore: do not compile test crates that have no tests 2024-06-24 00:20:04 +08:00
rzvxa
363d3d57d7 refactor(ast): add span field to the BindingPattern type. (#3855)
So we don't have to introduce a special case while generating `GetSpan` implementations for all of our Ast types.
2024-06-23 16:00:40 +00:00
Boshen
d6437fec0b refactor: clean up some usages of with_labels (#3854) 2024-06-23 15:24:37 +00:00
Boshen
13754cbd3d fix(parser): change diagnostic to "modifier cannot be used here" (#3853) 2024-06-23 15:14:27 +00:00
Boshen
97d59fc2f3 refactor(parser): move code around for parsing Modifiers (#3849) 2024-06-23 12:46:42 +00:00
Boshen
2f5d50e710 refactor(isolated-declarations): remove Modifiers (#3847) 2024-06-23 12:46:36 +00:00
Boshen
ae09a97a09
refactor(ast)!: remove Modifiers from ts nodes (#3846) 2024-06-23 19:44:35 +08:00
Boshen
1af5ed3d89 refactor(ast)!: replace Modifiers with declare and const on EnumDeclaration (#3845) 2024-06-23 10:34:55 +00:00
Boshen
0673677317 refactor(ast)!: replace Modifiers with declare on Function (#3844) 2024-06-23 10:34:54 +00:00
Boshen
ee6ec4ee57 refactor(ast)!: replace Modifiers with declare and abstract on Class (#3841) 2024-06-23 10:34:53 +00:00
Boshen
9b38119ec9 refactor(ast)!: replace Modifiers with declare on VariableDeclaration (#3839)
part of #2958
2024-06-23 10:34:52 +00:00
rzvxa
f029273b04 chore(ast): move the rest of ast implementations to ast_impl (#3840) 2024-06-23 09:56:35 +00:00
overlookmotel
d76f34b130 fix(transformer): TODO comments for missing scopes (#3837)
Where we create new block statements, need to generate scopes for them. Just adding TODO comments for this at present - we need an API to make this easy.
2024-06-23 08:45:28 +00:00
overlookmotel
d9f268dd55 refactor(transformer): shorten TS transform code (#3836)
Shorten code in TS transform. Remove a pointless reallocation of a `Box` in `transform_simple_assignment_target`.
2024-06-23 08:45:27 +00:00
overlookmotel
e4707315c0 fix(transformer): TS transform handle when type exports first (#3833)
Fix 2 bugs in TS transform:

1. Handle where export declaration precedes its import/definition. e.g. `export { X }; import { type X } from "x";`
2. Don't insert `export {}` statement if any other `export` statements remain.

Also refactor to simplify logic for removing imports/exports.
2024-06-23 08:45:25 +00:00
overlookmotel
d774e54f8e fix(transformer): TS transform generate do not copy statements (#3832)
Remove an unsound usage of `ast.copy` from TS transform. Previously the same statements were inserted into the AST multiple times. Instead generate these statements on demand.

Also use a `std::vec::Vec` for temporary values, rather than allocating them into arena, where they take up space to no purpose.
2024-06-23 08:45:24 +00:00
Don Isaac
d5f6aeb1ca
feat(semantic): check for illegal symbol modifiers (#3838) 2024-06-23 12:36:09 +08:00
overlookmotel
a6487482bc
refactor(ast): shorten code in AST builder (#3835)
Shorten code in AST builder. `MemberExpression` can be converted
directly to `AssignmentTarget`.
2024-06-23 10:47:15 +08:00