Commit graph

4595 commits

Author SHA1 Message Date
DonIsaac
834ee2aa6c fix(semantic): TSConditionalType scope enter/exit locations (#6351)
Fixes the same problem as #6270, but uses `#[scope(enter_before)]` and `#[scope(exit_after)]` to correct scope entry/exit locations.
2024-10-09 01:34:46 +00:00
DonIsaac
d9718adc8d feat(ast_tools): support #[scope(exit_before)] (#6350)
Closes #6311.

Adds support for `#[scope(exit_before)]`, which is the opposite of `#[scope(enter_before)]`
2024-10-09 01:34:44 +00:00
camchenry
c8174e2ab4 feat(linter): add suggestions for no-plusplus (#6376)
Implements naive suggestions for the `no-plusplus` rule. This is not implemented as a fix, because there isn't an exact 1:1 equivalence between `++` and `+= 1`. But most cases should be autofixable by this, but I've marked it as dangerous suggestion due to the semantics change
2024-10-09 01:20:07 +00:00
DonIsaac
a6cae98fbf test(linter): make sure all auto-fixing rules have fixer test (#6378)
Testing will now fail If a rule advertises an auto-fix capability but no fixer test cases are added.

This behavior may be bypassed using `intentionally_allow_no_fix_tests`. This should only be used in certain conditions, and we can check that it's not being abused in PR reviews.

```rs
declare_oxc_lint!(
  /// Some docs
  SomeRule,
  correctness,
  fix
);

#[test]
fn test() {
  use crate::tester::Tester;

  let pass = vec![/* ... */];
  let fail = vec![/* ... */];

  // now fails, since `fix` is reported but no cases are passed to `.expect_fix()`
  Tester::new(SomeRule::NAME, pass, fail).test_and_snapshot();
}
2024-10-09 01:15:07 +00:00
DonIsaac
f71c91ed7d fix(linter): move eslint/sort-keys to style category (#6377)
Closes #6363
2024-10-09 01:06:28 +00:00
dalaoshu
13b0b0b07e
feat(minifier): fold literal object constructors on window (#6379)
Fold literal object constructors on window: `window.Object()` -> `{}` or
`window.Object?.()` -> `Object?.()`


92d42692bb/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java (L98-L99)
2024-10-09 09:04:43 +08:00
DonIsaac
6e3224d5fa feat(linter): configure by category in config files (#6120)
> closes #5454

Adds a `categories` property to config files, where each key is a `RuleCategory` and each value is `"allow"/"off"`, `"warn"`, or `"deny"/"error"`.

Note that this change won't come into effect until after #6088 is merged.
2024-10-08 22:19:07 +00:00
DonIsaac
d5cf1f823b chore(traverse): add JSDoc type hints to JS codegen scripts (#6375)
Use JSDoc comments in `build.mjs` and related scripts to provide type hints and better intellisense. I was having a hard time knowing what fields are available in different methods, and I found this quite helpful. I'm sure other newcomers to this part of our codegen infrastructure will find it helpful as well.
2024-10-08 21:00:34 +00:00
oxc-bot
6921d50371
release(crates): v0.31.0 (#6360)
## [0.31.0] - 2024-10-08

- 01b878e parser: [**BREAKING**] Use `BindingIdentifier` for `namespace`
declaration names (#6003) (DonIsaac)

- 95ca01c cfg: [**BREAKING**] Make BasicBlock::unreachable private
(#6321) (DonIsaac)

- 020bb80 codegen: [**BREAKING**] Change to `CodegenReturn::code` and
`CodegenReturn::map` (#6310) (Boshen)

- 409dffc traverse: [**BREAKING**] `generate_uid` return a
`BoundIdentifier` (#6294) (overlookmotel)

- 5a73a66 regular_expression: [**BREAKING**] Simplify public APIs
(#6262) (leaysgur)

- 32d972e parser: [**BREAKING**] Treat unambiguous files containing TS
export assignments as modules (#6253) (overlookmotel)

- 4f6bc79 transformer: [**BREAKING**] Remove `source_type` param from
`Transformer::new` (#6251) (overlookmotel)

- afc3ccb napi/transform: [**BREAKING**] Rename
`TransformOptions::react` to `jsx`. (#6211) (Boshen)

- 82ab689 transformer,minifier: [**BREAKING**] Move define and inject
plugin from minifier to transformer (#6199) (Boshen)

### Features

- fa4d505 cfg: Derive more base traits for CFG blocks (#6320) (DonIsaac)
- 14275b1 cfg: Color-code edges in CFG dot diagrams (#6314) (DonIsaac)
- 7566c2d data_structures: Add `as_slice` + `as_mut_slice` methods to
stacks (#6216) (overlookmotel)
- c3c3447 data_structures: Add `oxc_data_structures` crate; add stack
(#6206) (Boshen)
- e304e8c minifier: Minify exponential arithmetic operation. (#6281)
(7086cmd)
- f9ae70c minifier: Minify basic arithmetic calculations. (#6280)
(7086cmd)
- 4008afe minifier: Fold array and object constructors (#6257)
(camchenry)
- 115ccc9 minifier: Bitwise not in exceeded value. (#6235) (7086cmd)
- ee6c850 minifier: Scaffold peephole replace known methods. (#6245)
(7086cmd)
- c32af57 minifier: Fold demical bitwise not for bigint. (#6233)
(7086cmd)
- 23b6464 minifier: Fold true / false comparison. (#6225) (7086cmd)
- 585ccda minifier: Support subtraction assignment. (#6214) (7086cmd)
- cca0034 minifier: Handle positive `NaN` and `Infinity`. (#6207)
(7086cmd)
- dac8f09 minifier: Minify unary plus negation. (#6203) (7086cmd)
- 3b79e1b minifier: Evaluate bigint in fold constant (#6178) (Boshen)
- abd3a9f napi/transform: Perform dce after define plugin (#6312)
(Boshen)
- a0ccc26 napi/transform: Add `lang` option to change source type
(#6309) (Boshen)
- f98e12c napi/transform: Add inject plugin (#6250) (Boshen)
- 291891e napi/transform: Add `define` option (#6212) (Boshen)
- 51a78d5 napi/transform: Rename all mention of React to Jsx; remove
mention of `Binding` (#6198) (Boshen)
- 2f888ed oxc: Add napi transform options (#6268) (Boshen)
- 8729755 oxc,napi/transform: Napi/transform use oxc compiler pipeline
(#6298) (Boshen)
- f6e42b6 sourcemap: Add support for sourcemap debug IDs (#6221) (Tim
Fish)
- 9e62396 syntax_operations: Add crate `oxc_syntax_operations` (#6202)
(Boshen)
- cf20f3a transformer: Exponentiation transform: support private fields
(#6345) (overlookmotel)

### Bug Fixes

- 84b2d07 codegen: Converts line comment to block comment if it is a
`PURE` comment (#6356) (Dunqing)
- e9eeae0 isolated-declarations: False positive for function with a type
asserted parameters (#6181) (Dunqing)
- d953a6b minifier: Correct the reference link (#6283) (dalaoshu)
- 37cbabb minifier: Should not handle the strict operation for bool
comparison. (#6261) (7086cmd)
- e29c067 minifier: Handle exceeded shifts. (#6237) (7086cmd)
- 294da86 napi/transform: Fix index.d.ts (Boshen)
- 9736aa0 oxc_transformer: Define `import.meta` and `import.meta.*`
(#6277) (IWANABETHATGUY)
- 6159560 parser: String `ImportSpecifier`s for type imports (#6352)
(DonIsaac)
- 1380d8b parser: Should regard comments where after `=` as leading
comments of next token (#6355) (Dunqing)
- 2bcd12a transformer: Exponentiation transform: fix reference flags
(#6330) (overlookmotel)
- 28cbfa7 transformer: Exponentiation transform: fix temp var names
(#6329) (overlookmotel)
- 3a4bcc7 transformer: Exponentiation transform: fix temp var names
(#6318) (overlookmotel)
- ccb7bdc transformer: Exponentiation transform: do not replace object
when private property (#6313) (overlookmotel)
- 56d50cf transformer: Exponentiation transform: do not assume `Math` is
not a local var (#6302) (overlookmotel)
- bd81c51 transformer: Exponentiation transform: fix duplicate symbols
(#6300) (overlookmotel)
- 06797b6 transformer: Logical assignment operator transform: fix
reference IDs (#6289) (overlookmotel)
- 4b42047 transformer: Fix memory leak in `ReplaceGlobalDefines` (#6224)
(overlookmotel)
- a28926f transformer: Fix inserting `require` with `front` option
(#6188) (overlookmotel)
- b92fe84 transformer: `NonEmptyStack::push` write value before updating
cursor (#6169) (overlookmotel)

### Performance

- 5db9b30 allocator: Use lower bound of size hint when creating Vecs
from an iterator (#6194) (DonIsaac)
- 788e444 transformer: Parse options from comments only once (#6152)
(overlookmotel)
- da2b2a4 transformer: Look up `SymbolId` for `require` only once
(#6192) (overlookmotel)
- 40bd919 transformer: Faster parsing JSX pragmas from comments (#6151)
(overlookmotel)

### Documentation

- eb1d0b8 transformer: Exponentiation transform: update doc comments
(#6315) (overlookmotel)
- c7636d7 traverse: Remove erroneous doc comment (#6328) (overlookmotel)

### Refactor

- f7d1136 allocator: Remove unnecessary `Vec` impl (#6213)
(overlookmotel)
- 40932f7 cfg: Use IndexVec for storing basic blocks (#6323) (DonIsaac)
- a1e0d30 cfg: Add type alias for Graph (#6322) (DonIsaac)
- 7672793 cfg: Move block data types to separate file (#6319) (DonIsaac)
- cc57541 data_structures: `NonEmptyStack::len` hint that `len` is never
0 (#6220) (overlookmotel)
- 147a5d5 data_structures: Remove `is_empty` methods for non-empty
stacks (#6219) (overlookmotel)
- 61805fd data_structures: Add debug assertion to `SparseStack` (#6218)
(overlookmotel)
- dbfa0bc data_structures: Add `len` method to `StackCommon` trait
(#6215) (overlookmotel)
- ac5a23f minifier: Use ctx.ast.vec instead of Vec::new. (#6331)
(7086cmd)
- 1cee207 minifier: Some boilerplate work for PeepholeFoldConstants
(#6054) (Boshen)
- 5b5daec napi: Use vitest (#6307) (Boshen)
- 58a8615 napi/transform: Remove context (#6306) (Boshen)
- 099ff3a napi/transform: Remove "Binding" from types; fix type error
(#6260) (Boshen)
- 54c1c53 napi/transform: Remove a call on `TransformOptions::clone`
(#6210) (Boshen)
- aa0dbb6 oxc: Add `napi` feature, change napi parser to use `oxc` crate
(#6265) (Boshen)
- 3b53dd4 parser: Provide better error messages for `const` modifiers on
class elements (#6353) (DonIsaac)
- acab777 regular_expression: Misc fixes (#6234) (leaysgur)
- bdd9e92 semantic: Rename vars from `ast_node_id` to `node_id` (#6304)
(overlookmotel)
- d110700 semantic: Dereference IDs as quickly as possible (#6303)
(overlookmotel)
- 03bc041 syntax: Remove some unsafe code creating IDs (#6324)
(overlookmotel)
- bd5fb5a transformer: Exponentiation transform: rename methods (#6344)
(overlookmotel)
- 4aa4e6b transformer: Exponentiation transform: do not wrap in
`SequenceExpression` if not needed (#6343) (overlookmotel)
- a15235a transformer: Exponentiation transform: no cloning (#6338)
(overlookmotel)
- 7d93b25 transformer: Exponentiation transform: split into 2 paths
(#6316) (overlookmotel)
- 15cc8af transformer: Exponentiation transform: break up into functions
(#6301) (overlookmotel)
- 7f5a94b transformer: Use `Option::get_or_insert_with` (#6299)
(overlookmotel)
- 0cea6e9 transformer: Exponentiation transform: reduce identifier
cloning (#6297) (overlookmotel)
- ac7a3ed transformer: Logical assignment transform: reduce identifier
cloning (#6296) (overlookmotel)
- 527f7c8 transformer: Nullish coalescing transform: no cloning
identifier references (#6295) (overlookmotel)
- 7b62966 transformer: Move `BoundIdentifier` into `oxc_traverse` crate
(#6293) (overlookmotel)
- c7fbf68 transformer: Logical assignment operator transform: no cloning
identifier references (#6290) (overlookmotel)
- f0a74ca transformer: Prefer `create_bound_reference_id` to
`create_reference_id` (#6282) (overlookmotel)
- ba3e85b transformer: Fix spelling (#6279) (overlookmotel)
- bc757c8 transformer: Move functionality of common transforms into
stores (#6243) (overlookmotel)
- 1c31932 transformer: Rename var in `VarDeclarations` common transform
(#6242) (overlookmotel)
- 0400ff9 transformer: `VarDeclarations` common transform: check if at
top level with `ctx.parent()` (#6231) (overlookmotel)
- 235cdba transformer: Use AstBuilder instance from TraverseCtx (#6209)
(overlookmotel)
- a7ed29e transformer: Insert `import` statement or `require` depending
on source type (#6191) (overlookmotel)
- 4c63f0e transformer: Rename methods (#6190) (overlookmotel)
- 900cb46 transformer: Convert `ModuleImports` into common transform
(#6186) (overlookmotel)
- 00e2802 transformer: Introduce `TopLevelStatements` common transform
(#6185) (overlookmotel)
- 70d4c56 transformer: Rename `VarDeclarationsStore` methods (#6184)
(overlookmotel)
- 81be545 transformer: Export `var_declarations` module from `common`
module (#6183) (overlookmotel)
- 02fedf5 transformer: Shorten import (#6180) (overlookmotel)
- f2ac584 transformer: Use TraverseCtx's ast in ModuleImports (#6175)
(Dunqing)
- 21b08ba transformer: Shared `VarDeclarations` (#6170) (overlookmotel)
- 0dd9a2e traverse: Add helper methods to `BoundIdentifier` (#6341)
(overlookmotel)
- c0e2fef traverse: Function to get var name from node (#6317)
(overlookmotel)
- adc5381 traverse: `TraverseAncestry` use `NonEmptyStack` (#6217)
(overlookmotel)

### Testing

- 964d71e minifier: Add arithmetic tests for fold constants. (#6269)
(7086cmd)
- fcb4651 minifier: Enable null comparison with bigint. (#6252)
(7086cmd)
- d4f2ee9 transformer: Tidy up transform checker (#6287) (overlookmotel)
- 0f5afd7 transformer: Transform checker output symbol name for
mismatches (#6286) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-08 20:55:24 +08:00
DonIsaac
01b878ecdb feat(parser)!: use BindingIdentifier for namespace declaration names (#6003)
Use `BindingIdentifier` instead of `IdentifierName` so that AST visitors can access the bound symbol id for the namespace's name. This makes namespace consistent with other named declarations, such as `Class`, `Function`, and `TSInterfaceDeclaration`.

We should consider modifying `TSModuleDeclarationName::StringLiteral(...)` to also store a `symbol_id`, since one gets bound in semantic for it as well.
2024-10-08 08:39:31 +00:00
dalaoshu
87f700fa24
chore(minifier): align test name with closure-compiler (#6359)
Keep consistency in test naming.
2024-10-08 16:35:14 +08:00
DonIsaac
3b53dd4deb refactor(parser): provide better error messages for const modifiers on class elements (#6353)
Quality-of-life improvement for invalid `const` modifiers on class elements. Instead of panicking, the parser will eat `const` and report it as an error.

```ts
class C {
  static const H = 1;
}
```
2024-10-08 08:23:32 +00:00
DonIsaac
6159560170 fix(parser): string ImportSpecifiers for type imports (#6352)
Fixes a parse failure on imports like this:
```ts
import { type "<A>" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module";
```
2024-10-08 08:17:30 +00:00
Dunqing
585cdd5bcd chore(codegen): add more tests for comments from esbuild (#6357)
Copy from https://github.com/rolldown-rs/rolldown/blob/main/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js
2024-10-08 05:42:43 +00:00
Dunqing
84b2d072e8 fix(codegen): converts line comment to block comment if it is a PURE comment (#6356)
The last part of fixing https://github.com/rolldown/rolldown/pull/2375/files#r1789011257

In the following case, the pure comment was written by `//`
```ts
const Component = // #__PURE__
React.forwardRef((props, ref) => {});
```

The printed code looks like this
```ts
const Component =
// #__PURE__ React.forwardRef((props, ref) => {});
```

As you can see, it is broken because the code also commented, so we need to replace `//` with `/* */`
2024-10-08 05:42:42 +00:00
Dunqing
1380d8b5dc fix(parser): should regard comments where after = as leading comments of next token (#6355)
A part of fixing https://github.com/rolldown/rolldown/pull/2375/files#r1789011257

### Compare to `Babel`
This is also among its behavior, see

<img width="1470" alt="image" src="https://github.com/user-attachments/assets/1b1f9c78-3e44-495d-b2f7-38e6c3bc8bf1">

### Compare to `esbuild`

I haven't looked through related code from esbuild, from its playground, the behavior looks the same

https://esbuild.github.io/try/#dAAwLjI0LjAAAGNvbnN0IEEgPSAvLyBzZGRkZGQKKCkgPT4ge30
2024-10-08 05:42:41 +00:00
oxc-bot
62d45bf14e
release(oxlint): v0.9.10 (#6340)
## [0.9.10] - 2024-10-07

### Features

- f272137 editors/vscode: Clear diagnostics on file deletion (#6326)
(dalaoshu)
- 1a5f293 editors/vscode: Update VSCode extention to use project's
language server (#6132) (dalaoshu)
- 376cc09 linter: Implement `no-throw-literal` (#6144) (dalaoshu)
- 5957214 linter: Allow fixing in files with source offsets (#6197)
(camchenry)
- a089e19 linter: Eslint/no-else-return (#4305) (yoho)
- 183739f linter: Implement prefer-await-to-callbacks (#6153) (dalaoshu)
- ae539af linter: Implement no-return-assign (#6108) (Radu Baston)

### Bug Fixes

- 9e9808b linter: Fix regression when parsing ts in vue files (#6336)
(Boshen)
- 93c6db6 linter: Improve docs and diagnostics message for
no-else-return (#6327) (DonIsaac)
- e0a3378 linter: Correct false positive in
`unicorn/prefer-string-replace-all` (#6263) (H11)
- ea28ee9 linter: Improve the fixer of `prefer-namespace-keyword`
(#6230) (dalaoshu)
- f6a3450 linter: Get correct source offsets for astro files (#6196)
(camchenry)
- be0030c linter: Allow whitespace control characters in
`no-control-regex` (#6140) (camchenry)
- e7e8ead linter: False positive in `no-return-assign` (#6128)
(DonIsaac)

### Performance

- ac0a82a linter: Reuse allocator when there are multiple source texts
(#6337) (Boshen)
- 50a0029 linter: Do not concat vec in `no-useless-length-check` (#6276)
(camchenry)

### Documentation

- 7ca70dd linter: Add docs for `ContextHost` and `LintContext` (#6272)
(camchenry)
- a949ecb linter: Improve docs for `eslint/getter-return` (#6229)
(DonIsaac)
- 14ba263 linter: Improve docs for `eslint-plugin-import` rules (#6131)
(dalaoshu)

### Refactor

- 642725c linter: Rename vars from `ast_node_id` to `node_id` (#6305)
(overlookmotel)
- 8413175 linter: Move shared function from utils to rule (#6127)
(dalaoshu)
- ba9c372 linter: Make jest/vitest rule mapping more clear (#6273)
(camchenry)
- 82b8f21 linter: Add schemars and serde traits to AllowWarnDeny and
RuleCategories (#6119) (DonIsaac)
- ea908f7 linter: Consolidate file loading logic (#6130) (DonIsaac)
- db751f0 linter: Use regexp AST visitor in `no-control-regex` (#6129)
(camchenry)
- 3aa7e42 linter: Use RegExp AST visitor for `no-hex-escape` (#6117)
(camchenry)
- 9d5b44a linter: Use regex visitor in `no-regex-spaces` (#6063)
(camchenry)
- 0d44cf7 linter: Use regex visitor in `no-useless-escape` (#6062)
(camchenry)
- eeb8873 linter: Use regex visitor in `no-empty-character-class`
(#6058) (camchenry)

### Testing

- d883562 linter: Invalid `eslint/no-unused-vars` options (#6228)
(DonIsaac)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-08 12:14:54 +08:00
overlookmotel
cf20f3a89d feat(transformer): exponentiation transform: support private fields (#6345)
Babel doesn't support private fields in this transform, but there's no reason not to. So we can.
2024-10-08 01:32:06 +00:00
overlookmotel
bd5fb5ab5c refactor(transformer): exponentiation transform: rename methods (#6344)
Pure refactor. Rename methods only. I named them badly in #6338.
2024-10-08 01:32:06 +00:00
overlookmotel
4aa4e6bec0 refactor(transformer): exponentiation transform: do not wrap in SequenceExpression if not needed (#6343)
`left **= right` is transformed to `left = Math.pow(left, right)`. There is no need to wrap it in a `SequenceExpression`.
2024-10-08 01:32:05 +00:00
overlookmotel
0dd9a2ecf3 refactor(traverse): add helper methods to BoundIdentifier (#6341)
Add helper methods to `BoundIdentifier` for common operations - creating an `IdentifierReference` as an `Expression` or an `AssignmentTarget`.
2024-10-08 01:32:05 +00:00
DonIsaac
00df6e5ccb fix(linter): friendly diagnostic messages for no-else-return (#6349)
### Before

```
  ⚠ eslint(no-else-return): Unnecessary 'else' after 'return'.
   ╭─[no_else_return.tsx:1:48]
 1 │ function foo1() { if (true) { return x; } else { return y; } }
   ·                                                ─────────────
   ╰────
  help: Replace ` else { return y; }` with `  return y; `.
```

### After

```
  ⚠ eslint(no-else-return): Unnecessary 'else' after 'return'.
   ╭─[no_else_return.tsx:1:31]
 1 │ function foo1() { if (true) { return x; } else { return y; } }
   ·                               ────┬────  ───┬──
   ·                                   │         ╰── Making this `else` block unnecessary.
   ·                                   ╰── This consequent block always returns,
   ╰────
  help: Remove the `else` block, moving its contents outside of the `if` statement.
```
2024-10-08 01:27:00 +00:00
DonIsaac
40932f79b1 refactor(cfg): use IndexVec for storing basic blocks (#6323)
Use an `IndexVec` when storing basic blocks. This makes the link between nodes in `.graph` and elements of `.basic_blocks` more clear. I had to rename `BasicBlockId` to `BlockNodeId` to avoid a name collision. I wasn't sure what else to name the `Idx` type for the basic blocks vec.
2024-10-07 19:28:40 -04:00
DonIsaac
71ad5d3e3f fix(linter): no-else-return fixer fails when else has no trailing whitespace (#6348)
Fixes a bug in `eslint/no_else_return`'s fixer where fixes were not being
property applied when `else` had no whitespace immediately after it. For
example:
```js
if(x){ return x }else{ return y }
```

I also refactored the rule's fixer to avoid string allocations as much as
possible.
2024-10-07 23:19:54 +00:00
DonIsaac
a1e0d30f20 refactor(cfg): add type alias for Graph (#6322)
Pure refactor. No logic changes
2024-10-07 15:28:30 +00:00
DonIsaac
95ca01ccc1 refactor(cfg)!: make BasicBlock::unreachable private (#6321)
Protect `unreachable` property of basic blocks in preparation of upcoming
refactors. This is technically a breaking change.
2024-10-07 15:13:56 +00:00
overlookmotel
a15235ac14 refactor(transformer): exponentiation transform: no cloning (#6338)
Exponentiation Operator transform was cloning a lot of values unnecessarily. This is not great for performance and would also have produced incorrect symbol IDs, as `clone_in` loses scope/symbol information.

Instead just move parts of the original AST around, without cloning.

Also split up the transform and document it more clearly.
2024-10-07 15:06:56 +00:00
Boshen
ac0a82af71 perf(linter): reuse allocator when there are multiple source texts (#6337) 2024-10-07 14:43:23 +00:00
Boshen
9e9808b429 fix(linter): fix regression when parsing ts in vue files (#6336) 2024-10-07 14:28:44 +00:00
Boshen
f243cf23c6
chore(linter): change NoElseReturn and NoThrowLiteral to pedantic 2024-10-07 22:02:33 +08:00
dalaoshu
376cc092ee
feat(linter): implement no-throw-literal (#6144) 2024-10-07 09:17:35 -04:00
7086cmd
e304e8cd2b feat(minifier): minify exponential arithmetic operation. (#6281) 2024-10-07 12:59:27 +00:00
7086cmd
ac5a23fd34 refactor(minifier): use ctx.ast.vec instead of Vec::new. (#6331) 2024-10-07 12:25:35 +00:00
7086cmd
f9ae70c74a feat(minifier): minify basic arithmetic calculations. (#6280)
It uses to_string to check which is shorter, which is extremely tough. Waiting for further refactor.
2024-10-07 10:41:06 +00:00
overlookmotel
2bcd12a868 fix(transformer): exponentiation transform: fix reference flags (#6330) 2024-10-07 10:35:34 +00:00
7086cmd
964d71e1d2 test(minifier): add arithmetic tests for fold constants. (#6269) 2024-10-07 09:37:30 +00:00
overlookmotel
28cbfa7c64 fix(transformer): exponentiation transform: fix temp var names (#6329)
Fix one case that I missed in #6318.
2024-10-07 09:00:35 +00:00
overlookmotel
c7636d7213 docs(traverse): remove erroneous doc comment (#6328)
`TraverseCtx::generate_uid_in_current_scope_based_on_node` no longer delegates to a method on `TraverseScoping`, so this comment was outdated.
2024-10-07 07:35:00 +00:00
camchenry
4008afe512 feat(minifier): fold array and object constructors (#6257)
This will fold expressions like `new Object()` to `{}`, and `new Array()` to `[]`. Based on the closure compiler tests: b7e380b632/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java (L78).

This is outside my usual area, so feedback is welcome.

NOTE: this was previously a full stack of PRs, but Graphite decided to stop working completely for some reason and only gave me this error when I submitted a PR:
```
ERROR: Failed to submit PR for 10-02-feat_minifier_fold_single_arg_new_array_expressions:
{}
```
so I decided to just completely remake this stack and submit as 1 PR.
2024-10-07 06:02:07 +00:00
DonIsaac
93c6db6550 fix(linter): improve docs and diagnostics message for no-else-return (#6327) 2024-10-07 05:54:59 +00:00
Tim Fish
f6e42b6d85
feat(sourcemap): Add support for sourcemap debug IDs (#6221)
The sourcemap [`debugId`
proposal](https://github.com/tc39/source-map/blob/main/proposals/debug-id.md)
adds globally unique build or debug IDs to source maps and generated
code, making build artifacts self-identifying.

Support for debug IDs was added to
[`rust-sourcemap`](https://github.com/getsentry/rust-sourcemap/pull/66)
in 2023 and Sentry have made use of this to aid in matching up source
and sourcemap files without having to worry about path mismatches or
release versions.

I want to add debug ID support to Rolldown but it uses `oxc::sourcemap`
so it looks like I need to start here first!
2024-10-07 13:54:08 +08:00
Boshen
9e62396803 feat(syntax_operations): add crate oxc_syntax_operations (#6202)
I intend to add constant folding and eval logic to this crate. There are downstream tools that require these functionalities alone.

It's also reasonable to move these traits out of the `ast` crate.
2024-10-07 05:39:59 +00:00
DonIsaac
fa4d505b92 feat(cfg): derive more base traits for CFG blocks (#6320) 2024-10-07 05:01:07 +00:00
DonIsaac
7672793542 refactor(cfg): move block data types to separate file (#6319)
Pure refactor. No logic has been changed.
2024-10-07 05:01:06 +00:00
DonIsaac
14275b138e feat(cfg): color-code edges in CFG dot diagrams (#6314)
- add `Attrs`, a nominal struct for cleaner management of node/edge styles and
  other attributes
- Style edges in DOT diagrams based on their kind
2024-10-07 02:43:30 +00:00
overlookmotel
03bc041ddf refactor(syntax): remove some unsafe code creating IDs (#6324) 2024-10-06 23:26:26 +00:00
overlookmotel
3a4bcc77fc fix(transformer): exponentiation transform: fix temp var names (#6318)
Make naming of temp vars follow Babel. It wasn't apparent that our version of this transform was behaving differently from Babel because the Babel plugin has very few tests. The added tests replicate Babel's output.
2024-10-06 23:08:10 +00:00
overlookmotel
c0e2fef0af refactor(traverse): function to get var name from node (#6317)
Pure refactor. Separate out the logic for creating a var name from an AST node into its own function, so it can be used standalone, outside of `generate_uid_based_on_node`.

Apart from the new `get_var_name_from_node` function, and changing return type of `to_identifier` to `String`, the only other changes are moving files around.
2024-10-06 23:08:09 +00:00
overlookmotel
7d93b25221 refactor(transformer): exponentiation transform: split into 2 paths (#6316)
Exponentiation transform has 2 paths for when left-hand side of `**=` is an identifier, and when it's a member expression. But these two paths are mixed up together in the `convert_assignment_expression`, `explode`, and `get_obj_ref` functions, with each branching on the same condition (is it an identifier or a member expression?).

Refactor to separate out these 2 code paths, and make the logic easier to follow.
2024-10-06 23:08:09 +00:00
overlookmotel
eb1d0b8838 docs(transformer): exponentiation transform: update doc comments (#6315)
Just update docs for this transform.
2024-10-06 23:08:08 +00:00