Commit graph

181 commits

Author SHA1 Message Date
Boshen
bd9fc6d169
feat(transformer): react jsx transform (#2961) 2024-04-14 10:50:17 +08:00
Miles Johnson
e67355045e
feat(transformer): start on TypeScript annotation removal (#2951) 2024-04-13 18:49:54 +08:00
Boshen
e651e50bda
feat(transformer): add the most basic plugin toggles (#2950) 2024-04-12 20:25:34 +08:00
Boshen
60ccbb105c
refactor(transformer): clean up some code (#2949) 2024-04-12 20:23:44 +08:00
Boshen
14754777a4
feat(transformer): implement react-jsx-source (#2948) 2024-04-12 20:21:54 +08:00
Boshen
f903a225a8
feat(transformer): implement react-jsx-self (#2946) 2024-04-12 18:08:36 +08:00
Boshen
0c04bf743f
feat(transformer): transform TypeScript namespace (#2942) 2024-04-12 10:19:13 +08:00
Boshen
3419306ac0
feat(transformer): add filename (#2941) 2024-04-11 18:43:51 +08:00
Boshen
614f73b66c
Release crates v0.12.3 2024-04-11 16:18:17 +08:00
Boshen
02adc76760
feat(transformer): implement plugin-transform-react-display-name top-down (#2937)
Missing case:


https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/nested/input.js

```js
var foo = qux(createReactClass({}));
var bar = qux(React.createClass({}));
```

This requires recursing down.

Top-down implementation in swc:


67ec5e09b9/crates/swc_ecma_transforms_react/src/display_name/mod.rs (L108-L132)

Or bottom-up in babel:


08b0472069/packages/babel-plugin-transform-react-display-name/src/index.ts (L87-L98)
2024-04-11 15:32:32 +08:00
Boshen
255c74ccc5
feat(transformer): add transform context to all plugins (#2931) 2024-04-10 14:49:00 +08:00
Boshen
79ca6feca9
feat(transformer): add transform callback methods (#2929)
For milestone 1, I think it's safe to just layout all the
transformations manually.


In TypeScript, the transformers are collected dynamically and ran on
each ast node; this achieves a single AST pass.
https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformer.ts#L129-L145

To maximize performance and reduce confusion, I think it's safe to
layout all the transformations manually for milestone 1.

The next PR will add transformation context to all presets so we can
start adding "context".
2024-04-10 11:06:49 +08:00
Boshen
d65eab3b8b
feat(transformer): add react preset (#2921) 2024-04-09 12:39:33 +08:00
Boshen
09452659e2
Release crates v0.12.2 2024-04-08 11:13:13 +08:00
Boshen
366a7fb0d4
Release crates v0.11.2 2024-04-03 19:36:54 +08:00
Boshen
54f7cd3978
Release crates v0.11.1 2024-04-03 16:57:52 +08:00
Boshen
21a5e4433f
fix(transformer): add serde "derive" feature to fix compile error 2024-04-03 11:56:27 +08:00
Boshen
23d3c4e0a4
chore: add changelogs via git cliff (#2878)
This is generated alongside https://github.com/oxc-project/release-oxc
2024-04-01 20:04:48 +08:00
Boshen
7710d8caf1
feat(transformer): add compiler assumptions (#2872)
closes #2869
2024-03-31 02:04:21 +00:00
Boshen
7034bcc47d
feat(transformer): add proposal-decorators (#2868) 2024-03-30 21:07:36 +08:00
Boshen
ffadcb08d9
feat(transformer): add react plugins (#2867) 2024-03-30 20:56:10 +08:00
Boshen
293b9f482a
feat(transformer): add transform-typescript boilerplate (#2866) 2024-03-30 20:48:35 +08:00
Boshen
c1a2958a5a
chore: remove oxc_transformer for a reimplementation (#2865)
closes #2860
2024-03-30 17:19:46 +08:00
Boshen
31ed532b79
Release crates v0.11.0 2024-03-30 13:54:53 +08:00
Ali Rezvani
528744ca0a
fix(transformer): optional-catch-binding unused variable side effect (#2822)
Before this PR for this given case:

```javascript
const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch {
  console.log(_unused);
}
```

We would've generated this:

```javascript
const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch (_unused) {
  console.log(_unused);
}
```

This is incorrect, This PR aims to use the `CreateVars` trait in order
to ensure the variable uniqueness.

Now it would output this:

```javascript
const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch (_unused2) {
  console.log(_unused);
}
```
2024-03-27 13:53:02 +08:00
Ali Rezvani
b76b02d019
fix(parser): add support for empty module declaration (#2834)
Should be merged after #2829, Tried a few times to get it done with
graphite stacking but found no success. I guess it either doesn't work
with forks or It is just a skill issue since I'm not familiar with it.

closes: #2829
closes: #2830

---------

Co-authored-by: Dmytro Maretskyi <maretskii@gmail.com>
2024-03-27 13:48:03 +08:00
Ali Rezvani
fe12617315
refactor(transformer): pass options via context. (#2794)
With this PR all transformers would get their `AstBuilder` and options
via `TransformerCtx`.
2024-03-26 21:21:31 +08:00
Ali Rezvani
243131d7a4
feat(transformer): numeric separator plugin. (#2795)
[es2021 numeric
separator](https://babeljs.io/docs/babel-plugin-transform-numeric-separator)
2024-03-26 18:15:12 +08:00
Ali Rezvani
56493bd02b
feat(transformer): add transform literal for numeric literals. (#2797)
[es2015 transform
literals](https://babeljs.io/docs/babel-plugin-transform-literals)

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-03-26 16:27:32 +08:00
Ali Rezvani
fc3878350f
refactor(ast): add walk_mut functions (#2776)
* move `visit` and `visit_mut` modules to a super module called `visit`
* add `walk_mut` module containing walk functions
* update `enter_node` and `leave_node` events to not pass a reference in the `VisitMut` trait
* add `AstType`, a non-referencing version of `AstKind` to use with `VisitMut` trait
* update the `VisitMut` trait's usages.
2024-03-25 20:40:13 +03:30
Dunqing
398a0346b3
feat(transformer/typescript): remove verbatim_module_syntax option (#2796)
Remove `verbatim_module_syntax` option, Because Babel's
[onlyRemoveTypeImports](https://babeljs.io/docs/babel-plugin-transform-typescript#onlyremovetypeimports)
option same behavior with `verbatim_module_syntax` , You can see
https://github.com/babel/babel/issues/15493#issuecomment-1466453493
2024-03-25 04:51:23 +08:00
Ali Rezvani
813226b648
refactor(ast): get rid of unsafe transmutation in VisitMut trait. (#2764)
This will close #2745,

In this PR I attempt to fix this issue using a combination of ideas
discussed in the issue mentioned above, I've created this early draft so
people can pitch in if there is something I should consider doing.

The first goal of this PR is to resolve the issue with the possible
illegal references, As a result of my approach it would also end up with
a bunch of walk_* and walk_*_mut functions to help with the abstraction.
I want to eliminate enter_node and leave_node functions, but I still
haven't started working on it since I first want to familiarize myself
with all of its usage throughout the project. I'm hesitating to do it at
the moment, When we want to do this it would require quite a bit of
refactoring so we should make sure it is probably going to work and end
up being a better implementation.
2024-03-23 13:48:30 +00:00
underfin
d9b77d853b
refactor(sourcemap): change sourcemap name to take a reference (#2779) 2024-03-23 21:40:05 +08:00
Boshen
ef1108a749
chore: Rust v1.77.0 (#2781) 2024-03-21 17:21:57 +00:00
Boshen
a5ddb5b452
Release crates v0.10.0 2024-03-14 18:23:34 +08:00
Boshen
0f86333437
refactor(ast): refactor Trivias API - have less noise around it (#2692) 2024-03-12 20:16:36 +08:00
Dunqing
308b780ff6
feat(transformer/decorators): handling the coexistence of class decorators and member decorators (#2636)
No snapshots have been updated. Because our output is a bit different
from babel's
<img width="961" alt="image"
src="https://github.com/oxc-project/oxc/assets/29533304/9926766c-b1ec-46c3-8c8f-53f053b14f84">
2024-03-07 16:52:30 +08:00
magic-akari
2a235d3b8c
fix(ast): parse with_clause in re-export declaration (#2634) 2024-03-07 14:09:31 +08:00
Boshen
4f9dd98a97
feat(span): remove From<String> and From<Cow> API because they create memory leak (#2628)
closes #2621
2024-03-06 20:38:21 +08:00
overlookmotel
0646bf34fa
refactor: rename CompactString to CompactStr (#2619)
Preparatory step for #2620.

This PR purely changes names of types and methods:

* `CompactString` -> `CompactStr`
* `Atom::to_compact_string` -> `to_compact_str`
* `Atom::into_compact_string` -> `into_compact_str`

Have split this into a separate PR as the diff is large, but it does absolutely nothing but renaming (I've checked the whole diff twice, so feel free not to check it again!). This should make it easier to see the content of the substantive change in #2620.
2024-03-06 12:24:23 +08:00
Boshen
cca6eb073c
Release crates v0.9.0 2024-03-05 15:57:31 +08:00
Dunqing
7a12514151
fix(transformer/decorators): missing check private function (#2607) 2024-03-05 11:37:00 +08:00
Boshen
ef932a3c27
refactor(codegen): clean up API around building sourcemaps (#2602)
closes #2564
2024-03-04 16:03:33 +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
Dunqing
6d43e851e8
feat(transformer/typescript): support transform constructor method (#2551) 2024-03-01 21:12:30 +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
2c2256a82f
refactor(transformer/typescript): improve implementation of remove import/export (#2530) 2024-02-28 14:41:43 +08:00
Dunqing
f760108094
feat(transformer): call build module record (#2529) 2024-02-28 14:35:35 +08:00
Boshen
46e779194a
chore: fix clippy warnings (#2519) 2024-02-26 23:55:18 +08:00
Boshen
be6b8b7ce6
[BREAKING CHANGE] Change Atom to Atom<'a> to make it safe (#2497)
Part of #2295

This PR splits the `Atom` type into `Atom<'a>` and `CompactString`.

All the AST node strings now use `Atom<'a>` instead of `Atom` to signify
it belongs to the arena.

It is now up to the user to select which form of the string to use.

This PR essentially removes the really unsafe code 


93742f89e9/crates/oxc_span/src/atom.rs (L98-L107)

which can lead to 

![image](https://github.com/oxc-project/oxc/assets/1430279/8c513c4f-19b0-4b63-b61c-e07c187c95b5)
2024-02-26 19:34:40 +08:00