Commit graph

4691 commits

Author SHA1 Message Date
rzvxa
2e91ad6c4e feat(ast_codegen): support for generate_derive marker. (#4728)
Follow-on after #4276, related to #4284.
2024-08-07 17:38:13 +00:00
rzvxa
6a36616289 feat(syntax): derive CloneIn for the AST-related items. (#4730)
Follow-on after #4276, related to #4284.
2024-08-07 17:38:08 +00:00
rzvxa
2e63618462 feat(span): implement CloneIn for the AST-related items. (#4729)
Follow-on after #4276, related to #4284.
2024-08-07 17:28:54 +00:00
rzvxa
23b0040c16 feat(allocator): introduce CloneIn trait. (#4726)
Introduce the trait discussed in #4284.
2024-08-07 17:28:54 +00:00
Boshen
e0832f8e18 refactor(minifier): use oxc_traverse for AST passes (#4725) 2024-08-07 13:26:29 +00:00
heygsc
db68a6c290
fix(linter): fixer for eslint/for-direction (#4727) 2024-08-07 08:42:51 -04:00
Boshen
17602db6de
refactor(minifier): move tests and files around 2024-08-07 20:01:55 +08:00
DonIsaac
c29637392e chore(linter): mark many rules as fix-pending (#4723)
Many rules still need `pending` flags, particularly the unicorn rules.

I also enhanced documentation for some rules while I was in the area.
2024-08-07 08:07:20 +00:00
Boshen
3289477197 refactor(minifier): clean up tests (#4724) 2024-08-07 06:29:41 +00:00
Boshen
94d3c31933 fix(minifier): avoid removing function declaration from KeepVar (#4722) 2024-08-07 05:09:32 +00:00
DonIsaac
eaddc8fd1d feat(linter): add fixer for eslint/func_names (#4714) 2024-08-07 04:51:57 +00:00
heygsc
80557a9386
feat(linter): add fixer for eslint/for-direction (#4679)
part of #4179
2024-08-07 00:48:57 -04:00
heygsc
62739949ae
fix(linter): block in eslint/no_cond_assign (#4721)
fix: #4687
2024-08-07 00:44:38 -04:00
DonIsaac
33f1312a8c feat(semantic): impl GetSpan for AstNode (#4717) 2024-08-07 03:59:38 +00:00
DonIsaac
7345bc944c fix(linter/func-names): handle ts accessibility when reporting missing names (#4713) 2024-08-07 03:53:40 +00:00
DonIsaac
475266dde3 refactor(ast): use correct lifetimes for name-related methods (#4712) 2024-08-07 03:53:39 +00:00
DonIsaac
e12bd1e21a feat(ast): allow conversion from TSAccessibility into &'static str (#4711) 2024-08-07 03:53:38 +00:00
Don Isaac
4b7dfd6c7c
docs(linter): correct docs for no-unused-vars (#4716) 2024-08-06 22:44:01 -04:00
DonIsaac
e2859038b6 refactor(linter): clean up eslint/func_names (#4710) 2024-08-07 01:07:56 +00:00
overlookmotel
06efae6e4c refactor(ast_codegen): reorder imports (#4709)
Pure refactor. Reorder imports to clarify what's an external crate and what's a local module.
2024-08-06 20:38:42 +00:00
overlookmotel
654a6e67fa refactor(ast_codegen): list input files explicitly (#4708)
List inputs to the codegen explicitly. This is less DRY, but I think it has the advantage of being more obvious - for #4704.
2024-08-06 19:14:05 +00:00
overlookmotel
06a2e43f93 fix(ci): run ast_changes CI job if span def file changes (#4706)
A detail I forgot in #4703.
2024-08-06 18:34:39 +00:00
overlookmotel
07607d3e94 feat(ast_codegen, span): process Span through ast_codegen (#4703)
Add `#[ast]` attr to `Span`.

Due to how AST codegen works, this necessitates putting the type def in a separate file. https://github.com/oxc-project/oxc/pull/4696#issuecomment-2271781995
2024-08-06 18:22:22 +00:00
overlookmotel
e1429e5ef1 refactor(span): reduce #[cfg_attr] boilerplate in type defs (#4702)
Similar to #4375 and #4698. #4696 added `#[ast]` attribute to types in `oxc_span`, so these types can use `#[serde]` attrs without the `#[cfg_attr(feature = "serialize", ...)]` guard.
2024-08-06 18:00:07 +00:00
rzvxa
125c5fd8ed feat(ast_codegen, span): process SourceType through ast_codegen. (#4696) 2024-08-06 17:42:12 +00:00
overlookmotel
3f3cb629af refactor(syntax, span): reduce #[cfg_attr] boilerplate in type defs (#4698)
Similar to #4375. #4694 added `#[ast]` attribute to types in `oxc_syntax`, so these types can use `#[serde]` attrs without the `#[cfg_attr(feature = "serialize", ...)]` guard.
2024-08-06 17:37:07 +00:00
rzvxa
82e2f6b924 feat(ast_codegen): process AST-related syntax types. (#4694) 2024-08-06 17:14:35 +00:00
rzvxa
b04dc3d026 refactor(ast_codegen): disallow implicit enum discriminants on #[ast] types. (#4690) 2024-08-06 17:14:33 +00:00
rzvxa
1690a57ed3 refactor(ast_codegen): move away from RType in generators. (#4682)
This PR introduces `EarlyCtx` and `LateCtx` in place of the old `CodegenCtx`, Early passes operate at the AST level while generators and other late passes operate on the schema.

It will also replace the confusing `RType` name with something more idiomatic ~~(open for suggestions, I haven't found a good name yet)~~ I've named it `AstType` and dropped the `R` prefix for `REnum` and `RStruct`.

There are some qualities of life improvements too, Things like `to_type_elide` can be used to simplify the code.

Related to #4442 (and can potentially mark it "close as fixed").
2024-08-06 17:14:31 +00:00
rzvxa
e24fb5b093 refactor(syntax): add explicit enum discriminants to AST related types. (#4691) 2024-08-06 17:09:15 +00:00
rzvxa
83b6ca93d9 refactor(ast): add explicit enum discriminants. (#4689)
Related to #4622 but doesn't close it.
2024-08-06 17:05:30 +00:00
overlookmotel
75f22072be refactor(traverse)!: replace find_scope with ancestor_scopes returning iterator (#4693)
Same as #4692. Replace `find_scope` and `find_scope_by_flags` with `ancestor_scopes ` method which returns an iterator. This does the same thing, but is more idiomatic.
2024-08-06 16:02:35 +00:00
overlookmotel
506709f51d refactor(traverse)!: replace find_ancestor with ancestors returning iterator (#4692)
Replace `find_ancestor` with `ancestors` method which returns an iterator. This does the same thing, but is more idiomatic.
2024-08-06 16:02:33 +00:00
overlookmotel
4797eaaab6 fix(transformer): strip TS statements from for in/of statement bodies (#4686)
Remove TS statements in body of `for of` and `for in` statements, as well as plain `for`.
2024-08-06 13:03:02 +00:00
overlookmotel
54f98973d1 refactor(traverse): simpler code for entering/exiting unconditional scopes (#4685)
Simplify generated code for visiting nodes which always have a scope.
2024-08-06 13:03:02 +00:00
overlookmotel
83546d3230 refactor(traverse): enter node before entering scope (#4684)
Closes #4200.

Align `Traverse`'s behavior with `Visit` and `VisitMut`. For types with scopes, call `enter_*` before entering scope, and call `exit_*` after exiting scope.
2024-08-06 13:03:01 +00:00
Boshen
01d85de834
fix(napi/transform): update napi files 2024-08-06 19:35:58 +08:00
Yuji Sugiura
bc611d77c4
chore(module_lexer): Fix invalid regex in test (#4683)
To make the #4242 tests pass.

(My `RegExp` parser tells me `/as)df/` is invalid syntax. 😂)
2024-08-06 19:26:12 +08:00
Boshen
f2901914f5
fix(oxc_ast_macros): fix syn lacking features to build 2024-08-06 16:50:50 +08:00
oxc-bot
61337613da
Release crates v0.23.1 (#4681)
## [0.23.1] - 2024-08-06

### Features

- fd2d9da ast: Improve `AstKind::debug_name` (#4553) (DonIsaac)
- b3b7028 ast: Implement missing Clone, Hash, and Display traits for
literals (#4552) (DonIsaac)
- 54047e0 ast: `GetSpanMut` trait (#4609) (overlookmotel)
- eae401c ast, ast_macros: Apply stable repr to all `#[ast]` enums
(#4373) (rzvxa)
- 0c52c0d ast_codegen: Add alignment and size data to the schema.
(#4615) (rzvxa)
- 229a0e9 minifier: Implement dot define for member expressions (#3959)
(camc314)
- e42ac3a sourcemap: Add `ConcatSourceMapBuilder::from_sourcemaps`
(#4639) (overlookmotel)

### Bug Fixes

- 4a56954 codegen: Print raw if value is number is Infinity (#4676)
(Boshen)
- bf48c7f minifier: Fix `keep_var` keeping vars from arrow functions
(#4680) (Boshen)
- 9be29af minifier: Temporarily fix shadowed `undefined` variable
(#4678) (Boshen)
- e8b662a minifier: Various fixes to pass minifier conformance (#4667)
(Boshen)
- a40a217 parser: Parse `assert` keyword in `TSImportAttributes` (#4610)
(Boshen)
- 03c643a semantic: Incorrect `scope_id` for catch parameter symbols
(#4659) (Dunqing)
- 6c612d1 semantic/jsdoc: Handle whitespace absence (#4642) (leaysgur)
- 0d2c41a semantic/jsdoc: Panic on parsing `type_name_comment`. (#4632)
(rzvxa)
- 9f8f299 syntax: Prevent creating invalid u32 IDs (#4675)
(overlookmotel)
- 5327acd transformer/react: The `require` IdentifierReference does not
have a `reference_id` (#4658) (Dunqing)
- 3987665 transformer/typescript: Incorrect enum-related
`symbol_id`/`reference_id` (#4660) (Dunqing)
- 4efd54b transformer/typescript: Incorrect `SymbolFlags` for jsx
imports (#4549) (Dunqing)

### Performance

- 8dd76e4 codegen: Reduce size of `LineOffsetTable` (#4643)
(overlookmotel)
- b8e6753 codegen: `u32` indexes in `LineOffsetTable` for source maps
(#4641) (overlookmotel)
- 6ff200d linter: Change react rules and utils to use `Cow` and
`CompactStr` instead of `String` (#4603) (DonIsaac)
- 0f5e982 minifier: Only visit arrow expression after dropping
`console.log` (#4677) (Boshen)
- ff43dff sourcemap: Speed up VLQ encoding (#4633) (overlookmotel)
- a330773 sourcemap: Reduce string copying in `ConcatSourceMapBuilder`
(#4638) (overlookmotel)
- 372316b sourcemap: `ConcatSourceMapBuilder` extend `source_contents`
in separate loop (#4634) (overlookmotel)
- c7f1d48 sourcemap: Keep local copy of previous token in VLQ encode
(#4596) (overlookmotel)
- 590d795 sourcemap: Shorten main loop encoding VLQ (#4586)
(overlookmotel)

### Documentation

- c69ada4 ast: Improve AST node documentation (#4051) (Rintaro Itokawa)

### Refactor

- ba70001 ast: Put `assert_layouts.rs` behind `debug_assertions` (#4621)
(rzvxa)
- 3f53b6f ast: Make AST structs `repr(C)`. (#4614) (rzvxa)
- 452e0ee ast: Remove defunct `visit_as` + `visit_args` attrs from
`#[ast]` macro (#4599) (overlookmotel)
- e78cba6 minifier: Ast passes infrastructure (#4625) (Boshen)
- d25dea7 parser: Use `ast_builder` in more places. (#4612) (rzvxa)
- 09d9822 semantic: Simplify setting scope flags (#4674) (overlookmotel)
- 6e453db semantic: Simplify inherit scope flags from parent scope
(#4664) (Dunqing)- 9b51e04 Overhaul napi transformer package (#4592)
(DonIsaac)

### Testing

- 49d5196 ast: Fix `assert_layouts.rs` offset tests on 32bit platforms.
(#4620) (rzvxa)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-06 16:37:29 +08:00
Boshen
bf43148f1e
fix(minifier): do not remove_syntax in dead_code_elimination 2024-08-06 16:34:04 +08:00
Boshen
bf48c7f02a fix(minifier): fix keep_var keeping vars from arrow functions (#4680) 2024-08-06 07:04:25 +00:00
Boshen
451ac4d0e3
chore: s/elimintation/elimination/ 2024-08-06 14:18:44 +08:00
overlookmotel
e42ac3a2a0
feat(sourcemap): add ConcatSourceMapBuilder::from_sourcemaps (#4639)
Introduce new method `ConcatSourceMapBuilder::from_sourcemaps`.

Where all the sourcemaps being concatenated exist at time that you
create `ConcatSourceMapBuilder`, it's faster to use `from_sourcemaps`,
because it pre-allocates enough space for the data it will hold and so
avoids memory copying.

Before:

```rs
let mut builder = ConcatSourceMapBuilder::default();
builder.add_sourcemap(&sourcemap1, 0);
builder.add_sourcemap(&sourcemap2, 100);
builder.add_sourcemap(&sourcemap3, 100);
let combined = builder.into_sourcemap();
```

After:

```rs
let builder = ConcatSourceMapBuilder::from_sourcemaps(&[
    (&sourcemap1, 0),
    (&sourcemap2, 100),
    (&sourcemap3, 200),
]);
let combined = builder.into_sourcemap();
```
2024-08-06 14:08:17 +08:00
Boshen
9be29af9d4 fix(minifier): temporarily fix shadowed undefined variable (#4678) 2024-08-06 04:58:39 +00:00
Boshen
0f5e982d19 perf(minifier): only visit arrow expression after dropping console.log (#4677) 2024-08-06 04:20:41 +00:00
Boshen
4a5695416d fix(codegen): print raw if value is number is Infinity (#4676) 2024-08-06 03:24:40 +00:00
Dunqing
3987665490 fix(transformer/typescript): incorrect enum-related symbol_id/reference_id (#4660)
part of #4581
2024-08-06 02:57:19 +00:00
Dunqing
03c643a8af fix(semantic): incorrect scope_id for catch parameter symbols (#4659)
When we move all the bindings in the CatchClause scope to its child scope (BlockStatement), we also need to replace the scope_id in the symbol with the scope_id of the new scope.
2024-08-06 02:57:18 +00:00
Don Isaac
69c6b650f2
perf(linter-macros): only iterate over all rules once (#4672) 2024-08-06 10:28:49 +08:00