Commit graph

518 commits

Author SHA1 Message Date
Boshen
e6922df3bb feat(parser): fix incorrect AST for x?.f<T>() (#7387) 2024-11-21 06:10:48 +00:00
Boshen
f059b0e655 fix(ast)!: add missing ChainExpression from TSNonNullExpression (#7377)
closes #7375

* `foo?.bar!`
* `foo?.[bar]!`

`TSNonNullExpression` was not wrapped inside `ChainExpression`.
2024-11-20 15:54:28 +00:00
Boshen
878189c407 feat(parser,linter)!: add ParserReturn::is_flow_language; linter ignore flow error (#7373)
closes #7123
2024-11-20 12:50:24 +00:00
Boshen
666b6c104c fix(parser): add missing ChainExpression in optional TSInstantiationExpression (#7371) 2024-11-20 11:51:55 +00:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
overlookmotel
44375a5662 refactor(ast)!: rename TSEnumMemberName enum variants (#7250)
Variants of `TSEnumMemberName` were previously only prefixed with `Static` to avoid naming conflicts with the variants inherited from `Expression` for non-static member names. #7219 removed the variants inherited from `Expression`, so all variants are now static. So we can shorten the names again (back to what they were before `inherit_variants!` was introduced).
2024-11-12 12:22:21 +00:00
Boshen
b11ed2cf7b refactor(ast)!: remove useless ObjectProperty::init field (#7220)
closes https://github.com/oxc-project/backlog/issues/143
2024-11-09 09:00:29 +00:00
Boshen
0e4adc15dd feat(ast)!: remove invalid expressions from TSEnumMemberName (#7219) 2024-11-09 08:48:14 +00:00
ottomated
9d6cc9d3af feat(estree): ESTree compatibility for all literals (#7152)
Adds some new estree macro directives:
- `#[estree(via = foo::Foo)`: Uses From to convert this struct to foo::Foo before serialization
- `#[estree(add_ts = "foo: string")]`: Adds additional fields to the typescript definitions

Used these to make all different literals estree-compatible.
2024-11-06 21:25:41 +00:00
Boshen
d1d187417b feat(ast)!: change comment.span to real position that contain // and /* (#7154)
closes #7150
2024-11-06 05:10:33 +00:00
Boshen
953b0516e8
refactor(parser): remove oxc_ecmascript crate (#7109) 2024-11-04 16:29:26 +08:00
overlookmotel
fdd480d84c refactor(parser): do not use AstBuilder::*_from_* methods (#7068)
Preparation for #7073. Avoid using `AstBuilder::*_from_*` methods to construct enums, use explicit construction instead.

Before:

```rs
let ident = self.ast.binding_pattern_kind_from_binding_identifier(ident);
```

After:

```rs
let ident = BindingPatternKind::BindingIdentifier(ident);
```

Often this produces shorter code, as well as (in my opinion) being easier to read.
2024-11-02 01:22:55 +00:00
overlookmotel
9e85b104e2 refactor(parser): add ParserImpl::alloc method (#7063)
Pure refactor. Introduce `ParserImpl::alloc` method. Shorten `self.ast.alloc(...)` to `self.alloc(...)`.

Also reduce `alloc` calls by using `AstBuilder` methods which already allocate where possible.
2024-11-01 17:09:06 +00:00
Boshen
17a938ee1f
refactor(parser): use function parse_type_member_semicolon (#7018) 2024-10-30 17:20:03 +08:00
Boshen
aa1b29c0cf
refactor(parser): remove parse_ts_index_signature_member function (#7017) 2024-10-30 17:20:02 +08:00
Boshen
caaf00e081 fix(parser): fix incorrect parsed TSIndexSignature (#7016)
closes #6985
2024-10-30 07:34:22 +00:00
Boshen
fa9a4ecd4a perf(parser): check . before [ in parse_member_expression_rest (#6979) 2024-10-28 11:00:28 +00:00
Boshen
423d54cb74 refactor(rust): remove the annoying clippy::wildcard_imports (#6860) 2024-10-24 13:57:19 +00:00
overlookmotel
a1ca964560 refactor(ast, parser)!: remove NumericLiteral::new method (#6787) 2024-10-23 03:36:31 +00:00
overlookmotel
aeaa27a618 refactor(ast, parser, transformer, traverse)!: remove BindingIdentifier::new methods (#6786) 2024-10-23 03:36:31 +00:00
overlookmotel
ecc9151f99 refactor(ast, parser, transformer, traverse)!: remove IdentifierReference::new methods (#6785) 2024-10-23 03:36:30 +00:00
leaysgur
8032813bf8 fix(regular_expression)!: Migrate to new regexp parser API (#6741)
Follow up #6635

- [x] Remove old APIs
- [x] Update linter usage
- [x] Update parser usage
- [x] Update transformer usage
2024-10-22 05:34:18 +00:00
DonIsaac
03427af85b chore(parser): enable lint warnings on missing docs (#6608)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 21:51:41 +00:00
Dunqing
721cf0f8b4 fix(parser): should be treated comments where after ( as leading comments of next token (#6588)
same as #6355

The behaviour is also same as esbuild and babel does
2024-10-15 16:23:40 +00:00
overlookmotel
c45723be77 refactor(parser): fix typo in var name (#6500) 2024-10-13 10:14:37 +00:00
DonIsaac
58467a53a1 feat(parser): better handling of invalid modifiers (#6482)
## What This PR Does

1. Recover on, and provide a better message for, invalid `export` modifier on constructor parameters. Before, an `unexpected token` error would be produced and the parser would panic. Now, the parser recovers and produces a message saying `'export' modifier cannot appear on a parameter.`
  ```ts
class Foo {
    constructor(export x: number) {}
}
  ```

2. Recover on, and provide a better message for, invalid modifiers on index signatures. Same recovery/message characteristics as above.
  ```ts
class Foo {
    public [x: string]: string;
}
```
2024-10-13 03:16:02 +00:00
DonIsaac
8ea6b721b8 feat(parser): better errors for reserved words used as identifier names (#6478)
## What This PR Does
Provide better error messages when a reserved word is used as a `BindingIdentifier`
```ts
var const = 1;
export enum const {}
const if = 1;
```
2024-10-13 03:16:01 +00:00
Boshen
455dab4900 chore(oxc): rename crate oxc_syntax_operations to oxc_ecmascript (#6469) 2024-10-12 08:34:42 +00:00
overlookmotel
073b02af14 refactor(ast): type params field before params in TS function declaration types (#6391)
Our convention is that AST type fields are ordered in order they appear in source. Move `type_parameters` fields in TS function declaration types to before `this_param` and formal parameters.
2024-10-11 09:57:28 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2808973af3 feat(ast)!: add Program::comments (#6445) 2024-10-11 04:47:36 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
Boshen
4d8bc8c8af perf(parser): precompute is_typescript (#6443) 2024-10-11 03:39:38 +00:00
Boshen
b1bf12c336 fix(parser): do not parse as and satisfies expression in javascript (#6442)
closes #6427
2024-10-11 03:31:24 +00: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
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
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
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
leaysgur
5a73a663dc refactor(regular_expression)!: Simplify public APIs (#6262)
This PR makes 2 changes to improve the existing API that are not very useful.

- Remove `(Literal)Parser` and `FlagsParser` and their ASTs
- Add `with_flags(flags_text)` helper to `ParserOptions`

Here are the details.

> Remove `(Literal)Parser` and `FlagsParser` and their ASTs

Previously, the `oxc_regular_expression` crate exposed 3 parsers.

- `(Literal)Parser`: assumes `/pattern/flags` format
- `PatternParser`: assumes `pattern` part only
- `FlagsParser`: assumes `flags` part only

However, it turns out that in actual usecases, only the `PatternParser` is actually sufficient, as the pattern and flags are validated and sliced in advance on the `oxc_parser` side.

The current usecase for `(Literal)Parser` is mostly for internal testing.

There were also some misuses of `(Literal)Parser` that restore `format!("/{pattern}/{flags}")` back and use `(Literal)Parser`.

Therefore, only `PatternParser` is now published, and unnecessary ASTs have been removed.
(This also obsoletes #5592 .)

> Added `with_flags(flags_text)` helper to `ParserOptions`

Strictly speaking, there was a subtle difference between the "flag" strings that users were aware of and the "mode" recognised by the parser.

Therefore, it was a common mistake to forget to enable `unicode_mode` when using the `v` flag.

With this helper, crate users no longer need to distinguish between flags and modes.
2024-10-03 02:47:08 +00:00
overlookmotel
32d972e2a4 refactor(parser)!: treat unambiguous files containing TS export assignments as modules (#6253)
An "unambiguous" TS source which contains an `export = <value>;` statement should be interpreted as an ES module.

This is in line with [this Babel test case](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous) which has [input option of `sourceType: "unambiguous"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/options.json (L2)), and [outputs an AST with `sourceType: "module"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/output.json (L7)).
2024-10-03 00:28:00 +00:00
Boshen
fd6798ffbc fix(parser): remove unintended pub Kind (#6109) 2024-09-27 12:44:40 +00:00
Boshen
0658576718 fix(paresr): do not report missing initializer error in ambient context (#6020)
closes #5958
2024-09-24 09:04:09 +00:00
Boshen
bcdbba3981 feat(codegen): print jsdoc comments that are attached to statements and class elements (#5845)
I am unable to print all comments correctly. Comments have way too much semantic meaning in JavaScript.

This PR reduces the scope to only print jsdoc comments that are attached to statements and class elements, in order to get isolated declarations shipped.
2024-09-18 07:58:22 +00:00
DonIsaac
3120c6c5ba docs(parser): add module and struct level documentation (#5831) 2024-09-18 06:27:24 +00:00
Boshen
42dcadfccf fix(parser): hashbang comment should not keep the end newline char (#5844)
Previously it included a newline in the value

```
  "hashbang": {
    "type": "Hashbang",
    "start": 0,
    "end": 16,
    "value": "/usr/bin/node\n"
  },
```

This change will also make the lexer emit a `\n` token, which will make comment position detection correct.
2024-09-18 05:41:44 +00:00
Boshen
8e7556f842 feat(parser): calculate leading and trailing position for comments (#5785) 2024-09-16 16:37:35 +00:00
overlookmotel
31e9db442d refactor(parser): shorten UniquePromise code (#5805)
Pure refactor. Shorten code a little.
2024-09-16 15:37:01 +00:00
overlookmotel
2322b8b713 refactor(parser): remove dead code warning when running tests (#5804)
`UniquePromise::new_for_tests` is not used in tests, so produces a dead code warning when running tests. Prevent that.

Also, rename it to `new_for_benchmarks`, since that's where it's used.
2024-09-16 15:37:00 +00:00
Boshen
6dd6f7ca26 refactor(ast): change Comment struct (#5783) 2024-09-15 09:22:58 +00:00