Commit graph

612 commits

Author SHA1 Message Date
Dunqing
673b66620b chore(transform_conformance): do not extend plugins if current options has plugins (#6627)
I saw many tests were ignored even if they don't contain any unsupported plugins
2024-10-17 02:07:03 +00:00
Boshen
e5ed6a56a8 feat(codegen): print negative numbers (#6624) 2024-10-16 22:38:54 +00:00
Tapan Prakash
9f9057b99f
fix(regular_expression): Fixed control Y regular expression (#6524)
Fixes https://github.com/oxc-project/oxc/issues/6413

Fixed regular expression for control Y
2024-10-14 11:19:37 +08: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
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
cb8f4210c3 refactor(prettier)!: remove source_text argument from constructor (#6448) 2024-10-11 06:27:33 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +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
Boshen
6a194f9086 docs(span): document validity of ModuleKind::Unambiguous (#6423)
relates #6249
2024-10-10 14:59:41 +00:00
leaysgur
b5b0af98cb feat(regular_expression): Support RegExp Modifiers (#6410)
Fixes #6354
2024-10-10 14:46:17 +00:00
leaysgur
c822b48d4f fix(regular_expression): Fix CharacterClass negative codegen (#6415)
Part of #6413 , fixes these mismatch.

```
  × Regular Expression content mismatch for `/[^]a/m`: `[]a` == `[]a`
  × Regular Expression content mismatch for `/a[^]/`: `a[]` == `a[]`
  × Regular Expression content mismatch for `/[^]/`: `[]` == `[]`
  × Regular Expression content mismatch for `/[^]/`: `[]` == `[]`
```
2024-10-10 05:00:45 +00:00
Boshen
95892ecc86 feat(coverage): add ContentEq test for regular_expression (#6411)
closes #6409

Marking as good first issue if anyone wants to pick this up and fix the failing test.
2024-10-10 02:21:21 +00:00
Boshen
eacde0553e chore(coverage): proposal-json-modules to stage 4 (#6380) 2024-10-09 03:09:35 +00:00
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
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
Boshen
020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
Boshen
8729755baa feat(oxc,napi/transform): napi/transform use oxc compiler pipeline (#6298)
part of #6156
2024-10-05 16:35:09 +00:00
overlookmotel
e19deaa102 ci(transformer): move post-transform checker to tasks crate (#6288)
Move post-transform checker into a `tasks` crate. It doesn't feel like it belongs in `oxc_semantic`. It also feels like too heavy a lump of code to put in `tasks/common`.
2024-10-05 14:48:37 +00:00
overlookmotel
0f5afd7ede test(transformer): transform checker output symbol name for mismatches (#6286)
Transform checker include symbol names in output for symbol mismatches. This is rather more helpful for locating bugs than just `SymbolId(3)`.
2024-10-05 14:42:06 +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
4f6bc79734 refactor(transformer)!: remove source_type param from Transformer::new (#6251)
Closes #6248.
2024-10-03 00:21:01 +00:00
overlookmotel
900cb46f6c refactor(transformer): convert ModuleImports into common transform (#6186)
An alternative version of #6177.

Convert `ModuleImports` into a common transform. Works much as before, but it inserts `import` / `require` statements by passing them to `TopLevelStatements` common transform, so they get inserted in one go with any other inserted top-level statements. This avoids shuffling up the `Vec<Statement>` multiple times, which can be slow with large files.

`VarDeclarations` also inserts any declarations via `TopLevelStatements` but runs after `ModuleImports`, so can control whether a `var` statement is inserted before or after `import` statements by inserting it via `VarDeclarations` (to appear after `import` statements) or directly into `TopLevelStatements` (to appear before `import` statements). Insertion order is not actually important, but allows us to match Babel's output and pass its tests.
2024-10-01 07:40:17 +00:00
Boshen
51a78d5946
feat(napi/transform): rename all mention of React to Jsx; remove mention of Binding (#6198)
This does not alter field names nor file names.

part of #6156
2024-10-01 11:52:50 +08:00
DonIsaac
b1af73db81 fix(semantic): do not create a global symbol for declare global {} (#6040)
Re-creation of #6004 to unblock it from down-stack PRs. @Boshen has already reviewed the previous PR and determined this to be correct behavior.
2024-09-25 08:46:00 +00:00
DonIsaac
f866781f49 feat(semantic): check for type annotations on left side of for..in and for..of iterators (#6043) 2024-09-25 02:51:17 +00:00
DonIsaac
8b2e9aa744 feat(semantic): check for JSDoc types in TS type annotations (#6042)
Closes #5982
2024-09-25 02:35:59 +00:00
Cam McHenry
65d8f9e8fe
perf(linter, ast-tools, coverage): Use FxHashSet instead of std::collections::HashSet (#6001) 2024-09-24 19:29:08 +08: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
c8682e9fcb fix(semantic,codegen,transformer): handle definite ! operator in variable declarator (#6019)
closes #5999
2024-09-24 08:32:05 +00:00
camchenry
02d5637dbc perf(ast-tools): use FxHashMap over std::collections::HashMap (#5997) 2024-09-23 18:28:54 +00:00
Boshen
0a2f68756f refactor(minifier): move dce conditional expression to RemoveDeadCode (#5971)
This is aligned to closure compiler
2024-09-23 10:22:00 +00:00
DonIsaac
74d8714d5a feat(semantic): add help message for invalid let x?: number (#5969) 2024-09-22 15:59:49 +00:00
DonIsaac
f1551d64bc fix(semantic): ? on variable declaration type annotations is a syntax error (#5956)
Closes #5955
2024-09-22 00:01:47 +00:00
Dunqing
4a62703d88 feat(isolated-declarations): handle export in the namespace correctly (#5950)
Previous I didn't follow the behavior of `TypeScript` to handle `export` in `namespace` as I thought no one used this
2024-09-21 16:39:58 +00:00
overlookmotel
eadffb900e test(conformance): move conformance snapshots into separate directory (#5924) 2024-09-20 12:30:39 +00:00
Boshen
84a5816d03
feat(isolated_declarations): add stripInternal (#5878)
closes #3906
closes #5687
closes #3958

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-09-19 23:14:47 +08:00
overlookmotel
c96b712f6b refactor(syntax)!: remove SymbolFlags::ArrowFunction (#5857)
`SymbolFlags::ArrowFunction` is an oddity, as whether a symbol is an arrow function is not statically knowable. In the following cases, `f` symbol did not have `ArrowFunction` flag set:

```js
const {f} = {f: () => {}};
```

```js
let f = 123;
f = () => {};
```

`SymbolFlags::ArrowFunction` is therefore not particularly useful, and possibly misleading. Having it complicates the transformer, and it's not used anywhere in Oxc.

This PR removes it.
2024-09-18 14:03:03 +00:00
Boshen
5901d2a0f1 fix(codegen): various spacing issues (#5820) 2024-09-17 09:03:28 +00:00
Boshen
512be65fa7 refactor(coverage): remove sourcemap snapshot (#5782) 2024-09-15 08:56:54 +00:00
Dunqing
36e698b411 perf(transformer): call transform_jsx in exit_expression rather than enter_expression (#5751)
### Difference

In `enter_expression`: Recursive transform JSX
In `exit_expression`: Deep first transform

After the change,  `transform_jsx` still has a lot of room for improvement.
2024-09-13 17:58:41 +00:00
Boshen
6bc13f6cd4 feat(minifier): add MinimizeConditions pass (#5747)
I expect small performance regression.

But managed to improve the following case from react.developmement.js

```
oxc  main ❯ diff before.js after.js
670c670
< 		if (!(dispatcher !== null)) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
---
> 		if (dispatcher === null) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
```
2024-09-13 08:31:45 +00:00
dalaoshu
d18c896a2c
perf(rust): use cow_utils instead (#5664)
Related to #5586 and #5662

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-11 18:39:30 +08:00
leaysgur
304ce25446 fix(regular_expression): Keep LegacyOctalEscape raw digits for to_string (#5692)
Fixes #5690

- Update `CharacterKind` enum from `Octal` to `Octal1`, `Octal2` and `Octal3`
- Stylistic refactoring for `impl Display`
2024-09-11 07:07:00 +00:00
Boshen
2016bae98c feat(coverage): add regular expression idempotency test (#5676)
closes #5634
2024-09-11 02:07:42 +00:00
Boshen
f9e3a41dd2 fix(semantic): bind SymbolId to function name in if (foo) function id() {} (#5673) 2024-09-10 11:05:26 +00:00
leaysgur
0511d55aa8 fix(regular_expression): Report more MayContainStrings error in (nested)class (#5661)
Fixes #5632
2024-09-10 01:55:51 +00:00
Boshen
f49e6ebd41 fix(span): treat .js as module file (reverts the previous breaking change) (#5612)
As it turns out it's not ideal to treat `.js` as `script` in today's world anymore.

This makes https://github.com/oxc-project/oxlint-ecosystem-ci pass again.
2024-09-08 15:14:04 +00:00