Commit graph

4323 commits

Author SHA1 Message Date
renovate[bot]
fef5d053e7
chore(deps): update crate-ci/typos action to v1.23.2 (#4260)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [crate-ci/typos](https://togithub.com/crate-ci/typos) | action | patch
| `v1.23.1` -> `v1.23.2` |

---

### Release Notes

<details>
<summary>crate-ci/typos (crate-ci/typos)</summary>

###
[`v1.23.2`](https://togithub.com/crate-ci/typos/releases/tag/v1.23.2)

[Compare
Source](https://togithub.com/crate-ci/typos/compare/v1.23.1...v1.23.2)

#### \[1.23.2] - 2024-07-10

##### Features

-   Automatically ignore JWT tokens

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 10am on monday" in timezone
Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-14 21:15:01 +00:00
Boshen
9a094e861e
chore(codegen): add ts snapshot test 2024-07-14 20:46:22 +08:00
Burlin
a4dc56c36d
feat(linter): add fixer for unicorn/no_useless_promise_resolve_reject (#4244)
Part of https://github.com/oxc-project/oxc/issues/4179

add fixer for unicorn/no_useless_promise_resolve_reject
2024-07-14 20:19:52 +08:00
Dunqing
ace4f1ff77 refactor(semantic): update the order of visit_function and Visit fields in the builder to be consistent (#4248)
Same as #4195
2024-07-14 11:39:15 +00:00
Dunqing
8bfeabfe6a refactor(semantic): simplify adding SymbolFlags::Export (#4249)
```ts
export default class Binding {}
//                   ^^^^^^^ SymbolFlags::Export

export default function Binding () {}
//                      ^^^^^^^ SymbolFlags::Export

// No binding, so we should not have SymbolFlags::Export
export default function() {}
export default class {}

```
2024-07-14 11:39:13 +00:00
Boshen
83bd40db4e
chore: turn off doctest for all [[bin]] 2024-07-14 16:55:19 +08:00
Boshen
d1c4be0020
refactor(codegen): clean up annotation_comment 2024-07-14 15:55:50 +08:00
Boshen
9fbe094948
chore: update logo and asset links 2024-07-14 13:38:35 +08:00
Boshen
084ab7602d
fix(codegen): use ryu-js for f64 to string 2024-07-14 13:23:30 +08:00
Boshen
06197b8be4
refactor(codegen): separate tests 2024-07-14 12:56:02 +08:00
Boshen
e167ef79c6 fix(codegen): print parenthesis properly (#4245)
`TSParenthesizedType` handles parenthesis in ts types.

It should be considered a bug if parenthesis is not printed correctly after this PR.
2024-07-14 04:13:10 +00:00
Dunqing
3e099febf6 refactor(ast): move enter_scope after visit_binding_identifier (#4246)
This is now consistent with other ASTs that require bind

2019043e72/crates/oxc_ast/src/ast/ts.rs (L814-L815)
2024-07-14 04:06:02 +00:00
Dunqing
dc2b3c44fb refactor(semantic): add strict mode in scope flags for class definitions (#4156)
related: https://github.com/oxc-project/oxc/issues/4142#issuecomment-2219125356

Although we called `enter_node(Class)`, that doesn't mean we're in the `class` scope. It causes our must to visit decorators before `enter_node`.

Let's look at this case. It causes a syntax error if we don't visit decorators before `enter_node`
```js
// This file was procedurally generated from the following sources:
// - src/decorator/decorator-call-expr-identifier-reference-yield.case
// - src/decorator/syntax/valid/cls-expr-decorators-valid-syntax.template
/*---
description: Decorator @ DecoratorCallExpression (Valid syntax for decorator on class expression)
esid: prod-ClassExpression
features: [class, decorators]
flags: [generated, noStrict]
info: |
    ClassExpression[Yield, Await] :
      DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await]

    DecoratorList[Yield, Await] :
      DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

    Decorator[Yield, Await] :
      @ DecoratorMemberExpression[?Yield, ?Await]
      @ DecoratorParenthesizedExpression[?Yield, ?Await]
      @ DecoratorCallExpression[?Yield, ?Await]

    ...

    DecoratorCallExpression[Yield, Await] :
      DecoratorMemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

    DecoratorMemberExpression[Yield, Await] :
      IdentifierReference[?Yield, ?Await]
      DecoratorMemberExpression[?Yield, ?Await] . IdentifierName
      DecoratorMemberExpression[?Yield, ?Await] . PrivateIdentifier

    IdentifierReference[Yield, Await] :
      [~Yield] yield
      ...

---*/
function decorator() {
  return () => {};
}
var yield = decorator;

var C = @yield() class {};

```
Errors:
```shell
  × The keyword 'yield' is reserved
    ╭─[language/statements/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js:45:2]
 44 │
 45 │ @yield() class C {}
    ·  ─────
    ╰────
```

The changed code makes more sense. Only if we call `enter_scope` for class, the flags will contain `StrictMode`. Also, we can get the exact `flags` of the `scope` in the `class` at the transformer

For example:

```
class A {
   B() {
       // Before: flags is `Function`
      //  After: flags is `Function | StrictMode`
   }
}
```

The regression tests will be fixed in follow-up PRs
2024-07-14 03:35:12 +00:00
Dunqing
20cdb1fe0a feat(semantic): align class scope with typescript (#4195)
```ts
class Klass <T>   extends Root       <R>                   {}
//    ^^^^^ ^^^           ^^^^       ^^^                   ^^
//    id type_paramter super_class super_type_parameters  body
```
I reorder fields according to the order above

The class scope is not defined in the spec. But we need to create a scope for `class` to store `TypeParamters`
2024-07-14 03:19:30 +00:00
Boshen
ab41c52485
chore(minifier): add two || test cases to dce_if_statement 2024-07-13 11:41:43 +08:00
overlookmotel
22d56bdcac fix(semantic): do not resolve references after FormalParameters in TS type (#4241)
Semantic resolves references when exiting `FormalParameters` to ensure references in param initializers don't get bound to bindings inside the function body.

However, it shouldn't do this for `FormalParameters` in TS types e.g. `TSTypeAnnotation` because they don't have their own scopes.
2024-07-13 02:43:01 +00:00
Boshen
7eb960d6e9 feat(transformer): decode xml character entity &#xhhhh and &#nnnn; (#4235) 2024-07-13 02:38:07 +00:00
mysteryven
9df60da6f3 fix(linter): correct find first non whitespace logic in @typescript-eslint/consistent-type-imports (#4198) 2024-07-13 02:33:03 +00:00
DonIsaac
7089a3d67b refactor(linter): split up fixer code into separate files (#4222)
refactor(linter): split up fixer code into separate files

refactor: mark Fix as non_exhaustive
2024-07-13 02:26:00 +00:00
lucab
d7ab0b8413 refactor(semantic)!: simplify node creation (#4226)
This tweaks AST node creation and tree manipulation, directly
building new nodes with a valid node ID.
2024-07-13 02:19:02 +00:00
mysteryven
67240dce85 fix(linter): not ignore adjacent spans when fixing (#4217)
fixes: #4204
2024-07-13 02:11:40 +00:00
underfin
205c259119
feat(sourcemap): support SourceMapBuilder#token_chunks (#4220)
Because the `token_chunks` need to pre-visit tokens and collect, it
could be done at add tokens phase. So here export it let rolldown could
be improve `renderChunks` sourcemap encode.
2024-07-13 10:11:14 +08:00
Boshen
c65198fa15 fix(codegen): choose the right quote for jsx attribute string (#4236) 2024-07-12 17:30:24 +00:00
Boshen
be82c286d6 fix(codegen): print JSXAttributeValue::StringLiteral directly (#4231)
jsx attribute string is interpreted as is without escaping.

The transformer is responsible for converting it to plain js string.
2024-07-12 16:17:23 +00:00
Jaden Rodriguez
6fb808febf
feat(linter): add typescript-eslint/no-confusing-non-null-assertion (#4224)
Added logic for
https://typescript-eslint.io/rules/no-confusing-non-null-assertion

Left comments for when Suggest feature is added

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-07-12 11:12:43 -04:00
IWANABETHATGUY
66b455a2b2
fix(oxc_codegen): avoid print same pure comments multiple time (#4230)
## Before 
```bash
Original:
const builtInSymbols = new Set(
  /*#__PURE__*/
  Object.getOwnPropertyNames(Symbol)
    .filter(key => key !== 'arguments' && key !== 'caller')
)


Printed:
const builtInSymbols = new Set(/*#__PURE__*/ /*#__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller"));

Minified:
const builtInSymbols=new Set(Object.getOwnPropertyNames(Symbol).filter((key)=>key!=="arguments"&&key!=="caller"))

```

## After
```bash
Original:
const builtInSymbols = new Set(
  /*#__PURE__*/
  Object.getOwnPropertyNames(Symbol)
    .filter(key => key !== 'arguments' && key !== 'caller')
)


Printed:
const builtInSymbols = new Set(/*#__PURE__*/  Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller"));

Minified:
const builtInSymbols=new Set(Object.getOwnPropertyNames(Symbol).filter((key)=>key!=="arguments"&&key!=="caller"))

```
2024-07-12 23:07:43 +08:00
lucab
81ed5885a8 refactor(semantic): convert scope fields to IndexVecs (#4208)
Closes: https://github.com/oxc-project/backlog/issues/10
2024-07-12 09:43:58 +00:00
Dunqing
92ee77487f feat(semantic): add ScopeFlags::CatchClause for use in CatchClause (#4205) 2024-07-12 03:47:07 +00:00
cinchen
126b66c4f8
feat(linter): support eslint-plugin-vitest/valid-describe-callback (#4185)
Rule detail:
[link](https://github.com/veritem/eslint-plugin-vitest/blob/main/src/rules/valid-describe-callback.ts)

---------

Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-07-12 11:35:00 +08:00
rzvxa
aab7aaaa06 refactor(ast/visit): fire node events as the outermost one. (#4203)
I'm going to be AFK today(till about 9 PM UTC). Meanwhile, I Didn't want to be a blocker so here we go.
It would fix the #4200 merge if you guys find it in the correct order otherwise feel free to close it.
2024-07-12 03:27:59 +00:00
cinchen
05b9a7375a
feat(linter): support eslint-plugin-vitest/valid-expect (#4183)
Rule detail:
[link](https://github.com/veritem/eslint-plugin-vitest/blob/main/src/rules/valid-expect.ts)

---------

Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-07-12 11:24:57 +08:00
Boshen
83c2c62f7b feat(codegen): add option for choosing quotes; remove slow choose_quot method (#4219) 2024-07-12 03:08:22 +00:00
cinchen
3e56b2bd16
feat(linter): support eslint-plugin-vitest/no-test-prefixes (#4182)
Rule detail:
[link](https://github.com/veritem/eslint-plugin-vitest/blob/main/src/rules/no-test-prefixes.ts)
2024-07-12 11:03:39 +08:00
overlookmotel
cb15303644 perf(semantic): reduce memory copies (#4216)
Reduce memory copies when resolving references in `Semantic`.

If parent scope has no unresolved references for `name`, there is no need to generate a new `Vec<ReferenceId>` for `name` and copy in contents from current scope. Just move the existing `Vec` to the parent.
2024-07-12 02:05:22 +00:00
overlookmotel
ef4c1f4e32 perf(semantic): reduce lookups (#4214)
Small performance optimization (I hope) to resolving references in `Semantic`. Look up current bindings once rather than on every turn of the loop.
2024-07-12 01:41:28 +00:00
overlookmotel
f23e54f97b perf(semantic): recycle unresolved references hash maps (#4213)
Closes #4169.

Reduce allocations while building `Semantic` by recycling hash maps used for tracking unresolved references, rather than creating a new one for every scope.
2024-07-12 01:41:27 +00:00
DonIsaac
3016f03578 feat(linter): let fixer functions return a None fix (#4210)
Part of #4187.

Adds `CompositeFix::None`, which enables fixer functions to decide not to fix some code.

While I was in the area, I took the liberty of adding some doc comments.
2024-07-12 01:12:42 +00:00
Jelle van der Waa
dd07a5475b
fix(linter): global variables should always check the builtin variables (#4209)
This fixes commit dbbb6fca56.

Closes #3374
2024-07-11 13:22:34 -04:00
Boshen
91dc0f7866
chore(benchmark): add codegen benchmark (#4207) 2024-07-11 23:58:37 +08:00
lucab
2602ce2b71 perf(semantic): reuse existing map of unresolved refs (#4206) 2024-07-11 15:35:22 +00:00
Burlin
bbe6137dc9
feat(linter): implement unicorn/no-useless-undefined (#4079)
Resolves #3870

Hey there, thought I'd give this a try as it's tagged "good first issue"
:) Let me know if there's anything that needs to change

Another part of the code also needs modification:

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/no-useless-undefined.js#L95

I tried to modify it. If there are any issues with these modifications,
please let me know.
```
fn is_has_function_return_type(node: &AstNode, ctx: &LintContext<'_>) -> bool {
    let Some(parent_node) = ctx.nodes().parent_node(node.id()) else {
        return false;
    };
    match parent_node.kind() {
        AstKind::ArrowFunctionExpression(arrow_func_express) => {
            arrow_func_express.return_type.is_some()
        }
        AstKind::Function(func) => func.return_type.is_some(),
        _ => is_has_function_return_type(parent_node, ctx),
    }
}
```
2024-07-11 22:09:25 +08:00
Boshen
bc2631c500
chore(README): update 2024-07-11 21:15:33 +08:00
Boshen
8a190eb166
feat(oxc): export oxc_mangler 2024-07-11 21:15:32 +08:00
Boshen
33e96e23e4 feat(tasks/minsize): include esbuild minified size (#4202) 2024-07-11 13:02:32 +00:00
Boshen
bb646f2bf9 feat(tasks/minsize): show target size for easier comparison (#4201) 2024-07-11 12:38:45 +00:00
IWANABETHATGUY
1c117eb20d
fix: avoid print extra semicolon after accessor property (#4199)
## Before
```js
export default class Foo { @x @y accessor #aDef = 1 }
```
**output** 
```bash
Original:
export default class Foo { @x @y accessor #aDef = 1 }


Printed:
export default class Foo {
        accessor #aDef=1;;
}

```
2024-07-11 20:16:02 +08:00
Boshen
e3e663bae4 feat(mangler): initialize crate and integrate into minifier (#4197) 2024-07-11 10:35:13 +00:00
Dunqing
bbe5dede07 refactor(semantic): set current_scope_id to scope_id in enter_scope (#4193)
close: #4170
2024-07-11 08:45:35 +00:00
Dunqing
7f1adddaf0 refactor(semantic): correct scope in CatchClause (#4192)
close: #4186

CatchClause has two scopes. The first one is `CatchClause`, which will add a `CatchParameter` to it. The second one is `Block`, which will add binding that declares in the current block scope.

The spec has a syntax error about `CatchParameter`
- It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the LexicallyDeclaredNames of Block.
2024-07-11 08:45:30 +00:00
Boshen
aa22073736 refactor(codegen): improve print API (#4196) 2024-07-11 08:41:04 +00:00