Commit graph

2899 commits

Author SHA1 Message Date
Boshen
fbb7a5a75c
fix: revert Cargo.toml change 2024-03-05 15:51:15 +08:00
Boshen
bf42158ad7
perf(parser): inline end_span and parse_identifier_kind which are on the hot path (#2612) 2024-03-05 15:39:53 +08:00
Boshen
49778abb80
fix(ast): temporary fix tsify not generating some typings (#2611)
seems like a bug in tsify
2024-03-05 14:13:28 +08:00
Boshen
1db307abbf
feat(ast): serialize BindingPattern to estree (#2610) 2024-03-05 13:48:43 +08:00
Arnaud Barré
97aa9cfd54
fix(parser): fix span end for TSEmptyBodyFunctionExpression (#2606)
https://oxc-project.github.io/oxc/playground/?code=3YCAAICXgICAgICAgICxG4jI43W9aqTWr3WzyAs1pNu4fnf%2FXXEB3Yt%2FfiBIgA%3D%3D

The conformance test are going back to initial state. I think the `.asi`
should be smarter, i can rethink that later

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-05 12:45:11 +08:00
Dunqing
7a12514151
fix(transformer/decorators): missing check private function (#2607) 2024-03-05 11:37:00 +08:00
cinchen
35ce3ccdc0
feat(linter): eslint-plugin-jest: prefer-to-have-length (#2580)
Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/prefer-to-have-length.ts)
2024-03-05 09:15:19 +08:00
Wenzhe Wang
951297ee59
fix(linter): avoid crash if no members in TSTypeLiteral in typescript/prefer-function-type (#2604) 2024-03-04 22:57:02 +08:00
Arnaud Barré
f6709e4737
feat(ast): serialize identifiers to ESTree (#2521) 2024-03-04 14:53:33 +00:00
Boshen
e2d2ce3369
feat(parser): parse decorators properly (#2603)
closes #2562
2024-03-04 19:30:41 +08:00
Boshen
7cc90134d3
fix: broken build from codegen API change 2024-03-04 19:24:06 +08:00
cinchen
212f128b33
feat(linter): eslint-plugin-jest: prefer-strict-equal (#2581)
Rule detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/prefer-strict-equal.ts)
2024-03-04 16:36:08 +08:00
Boshen
ef932a3c27
refactor(codegen): clean up API around building sourcemaps (#2602)
closes #2564
2024-03-04 16:03:33 +08:00
Boshen
20c7bf7835
feat(ast): add AssignmentTargetRest (#2601)
closes #2598
2024-03-04 14:31:22 +08:00
Boshen
9cc960e591
fix(parser): fix duplicated comments during parser rewind (#2600)
closes #2592
2024-03-04 14:07:33 +08:00
Boshen
6b42233628
feat(playground): display comments (#2599) 2024-03-04 14:02:22 +08:00
overlookmotel
b7f5c63833
perf(codegen): speed up generating sourcemap mappings (#2597)
This PR optimizes the `update_generated_line_and_column` function used in generating source maps.

The main change is that `generated_column` only depends on the last line, so just spin through bytes to find the last line break, and then only convert last line UTF-8 to UTF-16. There's also a fast path for when last line is ASCII, to avoid iterating over the last line twice in that common case.
2024-03-04 12:46:32 +08:00
overlookmotel
42fa8ebbc2
perf(codegen): speed up building sourcemap line tables (#2591)
Speed up building the line tables for source maps, using same kind of techniques as have been using in the lexer:

* Iterate byte-by-byte not char-by-char (`chars` iterator is slow).
* Fast path for ASCII (common case).
2024-03-04 12:40:39 +08:00
overlookmotel
ea30fd5b12
fix(codegen): fix adding mapping to sourcemaps (#2590)
Fix creating a sourcemap mapping when last byte of output in `\r`. Currently this panics because it assumes there's another byte after it when checking for `\n`, and reads out of bounds.
2024-03-04 12:33:28 +08:00
Arnaud Barré
24d46bccb5
fix(parser): fix span start for TSModuleDeclaration (#2593)
[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAICZgICAgICAgICymcgR7351T2PErukD7UXVyom%2F90VSbC7jSaCgoj9%2BqCyA)

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-04 04:29:32 +00:00
Arnaud Barré
f66059e91b
fix(ast)!: align TSImportType with ESTree (#2578)
Implements
https://github.com/typescript-eslint/typescript-eslint/issues/2998

The copy of props feels wrong, but could not get it working otherwise
with the box and borrow things 😅

Also I found that TSImportType was missing some entries for visitors and
codegen.

In the case of codegen I'm not really understand the need as all the
types seems to be dismissed?
2024-03-04 12:28:18 +08:00
overlookmotel
fe29fa4797
fix(codegen): correct sourcemaps when Windows line breaks + unicode (#2584)
Fix source mapping of Window-style line breaks in presence of Unicode chars.

`content.chars().nth(i + 1)` gets the `i + 1`th *char*, but `i` is a byte offset not a char offset.

The replacement `content.as_bytes().get(i + 1)` gets the `i + 1`th *byte*, and should also be faster as doesn't require iterating through `chars` again.
2024-03-04 12:27:28 +08:00
overlookmotel
517026b1db
fix(codegen): correct sourcemaps when unicode chars (#2583)
#2565 added source map support in codegen. But there was a bug in creating the line offset tables for Unicode. This PR fixes that.

This function could probably be made more efficient, but I think this at least makes it correct.
2024-03-04 12:22:47 +08:00
Dunqing
c09c602ea0
fix(linter): exclude typescript syntax function in only_used_in_recursion (#2595)
close: #2559
2024-03-04 11:43:32 +08:00
Arnaud Barré
ac520d01a9
fix(parser): fix span start for TSExportAssignment (#2594)
[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDRgICAgICAgICymcgR7351T2PErukD7UXVyom%2F90V9gN2l18vERCm6ABJAvuZFDanGfdTjE8wAVsdwZMQHIswA2DgraPxXUAF2ua%2F8b0XoyRw%2FfyXZIIA%3D)
2024-03-04 11:41:23 +08:00
Arnaud Barré
1d657134ea
fix(ast): expose NumericLiteral.raw (#2588)
This is needed for Prettier to preserve the base when printing numbers.
This is not in the spec but available in both Babel and TSESLint.
2024-03-04 11:34:42 +08:00
Arnaud Barré
9d4e255a73
feat(playground): support TS codegen (#2587) 2024-03-04 11:33:48 +08:00
renovate[bot]
9bd1d5b25e
chore(deps): update rust crates (#2589) 2024-03-04 11:23:06 +08:00
renovate[bot]
00b9c0b698
chore(deps): update dependency @codemirror/autocomplete to v6.13.0 (#2586) 2024-03-04 10:47:51 +08:00
renovate[bot]
00368f3d45
chore(deps): update dependency @types/node to v20.11.24 (#2585) 2024-03-04 10:47:42 +08:00
Arnaud Barré
d9cc429d4a
fix(parser): parse empty method declaration as TSEmptyBodyFunctionExpression (#2574)
That a tricky one, because it's time to decide what does ESTree
compliant means in the TS world (re #2463)

This code:

```ts
export declare class ByteBuffer {
  clear(): void;
     // ^^
}
```

- Is parsed by
[Babel](d38530204e)
as `FunctionExpression` with an empty body
- By
[TS-ESLint](4ea4e2feb5)
as
[TSEmptyBodyFunctionExpression](https://github.com/typescript-eslint/typescript-eslint/pull/1289)
- By
[OXC](https://oxc-project.github.io/oxc/playground/?code=3YCAAIC1gICAgICAgICyHorESipoTXPdvBaE9wxzlOraoWs19SUxDvdcwSVU0kbBO2b7ppX3x2P5IhQlpGHOYEHNCEfLf38HUICA)
as `TSDeclareFunction`

I'm going the easy way to fix this to the Babel way, but I think
following TS-ESLint would make sense. There is an [open babel
issue](https://github.com/babel/babel/issues/13878) about that.

Edit: Ok that not so easy and require updating some logic.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-03 13:59:17 +00:00
Boshen
9479865d9b
feat(napi/parser): expose preserveParans option (#2582)
closes #2576
2024-03-03 15:18:47 +08:00
Arnaud Barré
637cd1dea4
fix(ast): support TSIndexSignature.readonly (#2579)
[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDKgICAgICAgIC0GwpuZs97oWDqPM4xvCuoRB73mPOSrYb%2BTQEZf3b8RF0G%2B60jF5tYXUE9Me2%2FmMqVEwVy%2FiBIlyIMX6PqBpqsSmIXTJcsRqi4f3%2Bj6ICA)
2024-03-03 14:58:57 +08:00
Boshen
8bb1084863
feat(codegen): add sourcemap (#2565)
Co-authored-by: underfin <2218301630@qq.com>
2024-03-03 14:44:49 +08:00
Arnaud Barré
258b9b1c14
fix(ast): support FormalParameter.override (#2577)
This
[code](https://oxc-project.github.io/oxc/playground/?code=3YCAAIC1gICAgICAgICxG4jI43W9aqTWr3WzyA0TqSOjtB34F78iblvTQruFcqR6BUbbiLtWhj5rEL0NnFkDs4pF3dHiw39X7YCA)
can't be represented in the current OXC AST:

```ts
class Foo {
  constructor(override bar: string) {}
}
```
2024-03-03 14:41:42 +08:00
Arnaud Barré
78f30bc2db
fix(ast): change TSMappedType.type_annotation from TSTypeAnnotation to TSType (#2571)
Is ESTree, in that special case, there is no TSTypeAnnotation wrapper:

(See `type X` in each)

- [oxc
playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIAWgICAgICAgICyHorESipoToAAwTlix58geR2%2Beeu9rZHQZOqK%2B%2BX85ZQ9ldchOoVw2oAm2qi9okF3bJ9o4l78ENP3f%2Bc%2B8cIK6Itp%2B3SIInU72Vk0%2FSqawy1VNV5zTgBr7gOpGtUZsvkc12Yp8MC2shel9fbpgDySpYsWdgDhf3jVlIA%3D)
- [astexplorer TSESLint
parser](9fc767f3a5)
- [astexplorer Babel
parser](9a4b02fae1)

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-03 14:38:45 +08:00
Arnaud Barré
32028eb1c5
fix(parser): TSConditionalType span start (#2570)
Span start should be the checkType.start

(as all my PR, I try to make it work, don't hesitate to close and to it
in a better way)


[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDFgICAgICAgIC6nsrEgtelB%2FCnUFVHa8WBImPvKP4Ye3U5jBKASUfm8OtkXZASTLptdPlvM%2Fult4BgRbjIq3Yts9L2pZ%2FhVs8hMF%2Bwpqd%2FfdHggA%3D%3D)
2024-03-03 06:25:55 +00:00
Clément Lafont
2263377e3f
fix(oxc_language_server): use config path at init (#2569)
`config_path` was not use in initialization.
Must merge #2568 before to fix vscode.

Co-authored-by: Clément Lafont <johnrazeur@MacBook-Pro-de-Clement.local>
2024-03-03 14:01:16 +08:00
Arnaud Barré
670081050f
fix(parser): set span end for TSEnumDeclaration (#2573)
[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDHgICAgICAgICyHorESipoTXPdvBaE9wxyPnC9nb7Q6xEpIf3AzkuhOU2arZOLF1u08q1G2hs5klxiUYA6%2BBkL693d0iAZC%2BUFyne3yIKPv32k8IA%3D)

(Tell me if you prefer that I group this kind of small fixes together)
2024-03-03 13:54:43 +08:00
Arnaud Barré
8a81851bf3
fix(parser): don't parse null as a literal type (#2572)
See playgrounds:

-
[oxc](https://oxc-project.github.io/oxc/playground/?code=3YCAAIDbgICAgICAgIC6nsrEgteLFrCnQnPuEizmC%2BDQ8C8bP9fXPj%2B7%2FjjmRZPvpAH3N7PfIPDu7RDOlrl79cHiork8WA08r39%2FqpCAgA%3D%3D)
-
[Babel](3a263be55b)
2024-03-03 13:54:16 +08:00
IWANABETHATGUY
ad8ca2a066
fix(oxc_language_server): serialize with camelCase (#2568)
Closed https://github.com/oxc-project/oxc/issues/2563
2024-03-02 22:56:06 +08:00
overlookmotel
e339461a9f
fix(ast): rename serialized fields to camel case (#2566)
Fixes a few more AST fields names which are currently snake case in
serialized JSON.
2024-03-02 22:47:29 +08:00
overlookmotel
78f8c2ce7f
perf(parser): lex JSXText with memchr (#2558)
Lexing JSXText only requires searching for 2 possible characters (`<`
and `{`), so can use `memchr`.
2024-03-01 22:26:53 +08:00
BlackSoulHub
f00834d0fd
fix(linter): fix getter return rule false positives in TypeScript (#2543)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-01 13:42:13 +00:00
overlookmotel
dd31c6453a
refactor(parser): byte_search macro evaluate to matched byte (#2555)
Change behavior of `byte_search!` macro, to make it easier to understand and use:

1. `handle_match` removed. Macro instead evaluates to the first matching byte.
2. `handle_eof` does not return from enclosing function.
3. Alter syntax to make clear that `continue_if` and `handle_eof` are not closures, so can use `return` statements in them.

These changes enabled by #2552.
2024-03-01 21:28:39 +08:00
overlookmotel
c579620701
refactor(parser): small efficiencies in byte_search macro usage (#2554)
A few small efficiencies in usage of `byte_search` macro for lexing comments.
2024-03-01 21:23:34 +08:00
Dunqing
3d354d44a3
refactor(ast) improve ExportDefaultDeclarationKind's is_typescript_syntax() method (#2561) 2024-03-01 21:20:33 +08:00
overlookmotel
18cff6aab8
refactor(parser): remove start params for byte_search macro arms (#2553)
Simplify `byte_search` macro a bit more.
2024-03-01 21:15:27 +08:00
Dunqing
6d43e851e8
feat(transformer/typescript): support transform constructor method (#2551) 2024-03-01 21:12:30 +08:00
Dunqing
37de80d9c9
fix(semantic): jsx reference with an incorrect node id (#2546)
The get kind from the node id should be `JSXIdentifier`, but now it's `JSXOpeningElement`.
2024-03-01 21:07:57 +08:00