Commit graph

2878 commits

Author SHA1 Message Date
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
overlookmotel
34ecdd58d8
refactor(parser): simplify byte_search macro (#2552)
This PR greatly simplifies the `byte_search!` macro.

Mainly removing `cold_branch()` from the "not enough bytes remaining for a batch" branch, which allows refactoring so that `handle_match` and `continue_if` don't need to be repeated twice.

Result for performance is inconsistent - a little better on some benchmarks, a little worse on others. But not by significant amounts either way. In my view, the benefit of making the macro simpler outweighs a small speed loss anyway.
2024-03-01 21:07:39 +08:00
Dunqing
25e03cb0ef
feat(tasks/transformer): enable typescript when the typescript plugin is provided (#2548)
Babel has many test cases that are js files, but in ts syntax.
2024-03-01 21:04:55 +08:00
Dunqing
fd8f735ed2
fix(ast): missing visit JSXElementName enum (#2547) 2024-03-01 21:03:14 +08:00
overlookmotel
ddccaa1af9
refactor(parser): remove unsafe code in lexer (#2549)
Same as #2527. Just remove some unnecessary unsafe code, no substantive
changes.
2024-02-29 15:00:08 +00:00
Yuji Sugiura
1391e4a86b
refactor(semantic/jsdoc): Misc fixes for JSDoc related things (#2531)
Sorry for the rather large size of PR. 😓 But essentially, not changed so
much.

#### 1. Reorganize directories and namings

```
src/jsdoc
├── builder.rs 👈🏻 for SemanticBuilder
├── finder.rs  👈🏻 `semantic.jsdoc()`
├── mod.rs
└── parser
   ├── jsdoc.rs     👈🏻 `JSDoc` struct which has `comment` and `tags`
   ├── jsdoc_tag.rs 👈🏻 `JSDocTag` struct
   ├── mod.rs
   ├── parse.rs     👈🏻 parsing logic by `JSDocParser`
   └── utils.rs
```

Now `mod.rs` has only export things.

#### 2. Introduce `JSDocTagKind::Unknown(name)`

We need to keep their name as-is to check valid tag names are used.(e.g.
`jsdoc/check-tag-names` rule)

#### 3. Support multiline description

- Comment for JSDoc
- Comment for each JSDocTag

```js
/**
 * @foo this comment continues
 * here but leading * should be ignored!!
 */
```

- - -

Please correct me if I am doing something wrong... 🐰
2024-02-29 17:28:14 +08:00
Dunqing
fe777f330f
feat(linter/import): partial support namespace check (#2538) 2024-02-29 15:40:53 +08:00
overlookmotel
5a13714a18
perf(parser): faster lexing template strings (#2541)
Speed up lexing template strings.

This was the last use of `AutoCow` remaining in the lexer, and it's now removed.

Implementation is quite complex, to avoid repeatedly branching on whether an unescaped string is required or not (the way `AutoCow` did). I tried to simplify it down to a single function, but this hurt performance significantly.

Benchmarks do not show much movement, but I believe that's because there aren't many template strings in the benchmarks. Where there are template strings, I believe this speeds up lexing them significantly.
2024-02-29 13:28:30 +08:00
overlookmotel
9d7ea6b3f0
refactor(parser): single function for all string slicing (#2540)
Pure refactor. Move all string-slicing in `lexer::Source` into a single function.
2024-02-29 13:22:55 +08:00
Boshen
32e5a3aae7
Release napi oxc-parser@v0.7.0 2024-02-28 18:41:14 +08:00
Boshen
ab13504612
Release oxlint and vscode extension v0.2.12 2024-02-28 18:39:55 +08:00
Boshen
d41dcc316e
feat(linter): remove all commonjs logic for import plugin (#2537) 2024-02-28 18:13:44 +08:00
Boshen
3efbbb2e1f
feat(ast): add "abstract" type to MethodDefinition and PropertyDefinition (#2536)
closes #2532

```
pub enum PropertyDefinitionType {
    PropertyDefinition,
    TSAbstractPropertyDefinition,
}

pub enum MethodDefinitionType {
    MethodDefinition,
    TSAbstractMethodDefinition,
}
```
2024-02-28 17:33:11 +08:00
Dunqing
3807d83767
feat(wasm): call build module record when symbol is true (#2533)
symbols depend on module record
2024-02-28 14:47:34 +08:00
Dunqing
2c2256a82f
refactor(transformer/typescript): improve implementation of remove import/export (#2530) 2024-02-28 14:41:43 +08:00
Arnaud Barré
d181209759
fix(ast): add Function to generated TS types and fix ModifierKind serialization (#2534) 2024-02-28 14:40:14 +08:00
overlookmotel
24ded3cb15
perf(parser): lex JSX strings with memchr (#2528)
Simplify lexing JSX string attributes. As the search is purely for 1
byte value (the closing quote), and so doesn't require a byte table, use
`memchr`.

This change doesn't really register on benchmarks, but it's one step
closer to removing `AutoCow`, and transitioning all the searches in the
lexer to byte-by-byte.
2024-02-28 14:39:23 +08:00
Dunqing
f760108094
feat(transformer): call build module record (#2529) 2024-02-28 14:35:35 +08:00
overlookmotel
0ddfc856d2
refactor(parser): remove unsafe code (#2527)
Remove some unnecessary unsafe code.
2024-02-27 20:28:21 +08:00
Boshen
02c82c3f78
feat(cli,linter): provide tsconfig path from the cli (#2526)
closes #891
2024-02-27 20:00:11 +08:00
Boshen
27052ebfed
refactor(span): remove AtomImpl (#2525) 2024-02-27 13:45:58 +08:00
Boshen
903f17c0df
refactor(span): move base54 method to mangler (#2523) 2024-02-27 13:34:33 +08:00