Commit graph

254 commits

Author SHA1 Message Date
Dunqing
5501d5ce33 feat(transformer/typescript): transform import {} from "mod" to import "mod" (#3866)
close: #3736
2024-06-24 03:27:39 +00:00
Boshen
445603444f feat(ast)!: add IdentifierReference to ExportSpecifier (#3820)
closes #3795
closes #3796
2024-06-22 11:43:41 +00:00
Boshen
2a16ce0624 feat(traverse): disable syntax check and disable build module record (#3794)
These can be skipped because :
 * semantic errors are not passed to the caller
 * module record is not used
2024-06-20 13:05:35 +00:00
Dunqing
497769cb60 feat(ast): add some visitor functions (#3785) 2024-06-20 05:23:04 +00:00
Boshen
4e9d8a5585
chore: fix some nightly clippy warnings 2024-06-19 00:53:58 +08:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Boshen
5c38a0fd69 feat(codegen)!: new code gen API (#3740)
This PR introduces two type alias to avoid the confusing const generic `pub struct Codegen<'a, const MINIFY: bool>`

* CodeGenerator - Code generator without whitespace removal.
* WhitespaceRemover - Code generator with whitespace removal.

Usage is changed to a builder pattern:

```rust
CodeGenerator::new()
  .enable_comment(...)
  .enable_sourcemap(...)
  .build(&program);
```
2024-06-18 15:50:12 +00:00
Boshen
5a99d30eba feat(codegen): improve codegen formatting (#3735) 2024-06-18 11:10:36 +00:00
Boshen
982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
Boshen
534242a729
feat(codegen)!: remove CodegenOptions::enable_typescript (#3674)
The typescript transform pass is now required to strip typescript syntax
for codegen to print things properly.

Codegen will now print whatever is in the AST.
2024-06-14 21:56:00 +08:00
Dunqing
59666e0127
fix(transformer): do not rename accessible identifier references (#3623)
close: #3620

In `Babel`, the expected output is:

```ts
var x = 10;
var Foo = function(Foo) {
       Foo[Foo['a'] = 10] = 'a';
       Foo[Foo['b'] = 10] = 'b';
       Foo[Foo['c'] = 30] = 'c';
       return Foo;
}(Foo || {});
```

IMO, `Foo.b + x` is enough, because `x` is not a const variable. The
output same as with `typescript`
2024-06-13 15:26:38 +08:00
Boshen
c041e9d1a9
chore: bump test262, babel and TypeScript submodules (#3644) 2024-06-12 18:42:32 +08:00
Boshen
b58d8eb88f fix!(codegen): remove the unecessary 4th argument from Codegen::new (#3640) 2024-06-12 07:58:54 +00:00
Boshen
d77ec9f95a
chore: remove trailing whitespaces for all files; add .editorconfig (#3639) 2024-06-12 15:47:26 +08:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc (#3638)
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.

`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
Dunqing
5793ff1986
refactor(transformer): replace &’a Trivias with Rc<Trivias> (#3580)
`Transformer` needs to borrow `Trivias`.
8be1cc8052 (r1630711060)
2024-06-11 13:23:41 +08:00
Dunqing
e8a20f8d50 feat(transformer/typescript): remove typescript ast nodes (#3559)
According to Babel tests feedback, remove some known ts AST nodes.
There are still many TS AST nodes that need to be deleted
2024-06-07 05:04:22 +00:00
Dunqing
0007ee47be
chore(coverage, transformer_conformance): print all AST whether or not they are Typecript AST (#3556)
We have a conclusion that codegen will print whatever is in the AST,
instead of having an option to enable printing TypeScript syntax. I plan
to remove codegen's `enable_typescript` option after we strip out all
typescript AST in the transformer typescript plugin.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-06 15:45:20 +08:00
overlookmotel
837776e1ab fix(transformer): TS namespace transform do not track var decl names (#3501)
Don't track variable declaration or import binding names in TS namespace transform.

Babel does, but it appears to be wrong. It's illegal to have a `var`/`let`/`const` declaration or import in same scope as a TS namespace declaration with same binding.

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAQTgMyhEcDkUCmBDAYxkwG4AoAOzxBwGcxCdE4BvAXzLIIgtvgCE4AXjgBGclRr1GcQSzJxFcADY54AD3Icyq+AGFhYidToMCTA-KUq1cTWW0A3PFDgARQ+Monp596wUlXTstMiA
2024-06-03 12:35:57 +00:00
overlookmotel
8e4f33557d
fix(transformer): output empty file for TS definition files (#3500)
As discussed in
https://github.com/oxc-project/oxc/pull/3489#issuecomment-2143482458,
transformer should output an empty file for TS definition files.
2024-06-03 20:25:02 +08:00
IWANABETHATGUY
0cdb45a1ff
feat(oxc_codegen): preserve annotate comment (#3465)
1. Copy tests from
efa3dd2d8e/internal/bundler_tests/bundler_dce_test.go (L3833-L3971)
2. Add option to preserve annotate comment like `/* #__NO_SIDE_EFFECTS__
*/` and `/* #__PURE__ */`
2024-05-30 15:25:23 +08:00
Dunqing
b4fd1ad31c fix(transformer/typescript): variable declarations are not created when a function has a binding with the same name (#3460) 2024-05-29 23:00:22 +00:00
Dunqing
1a50b86281 refactor(typescript/namespace): reuse TSModuleBlock's scope id (#3459) 2024-05-29 23:00:15 +00:00
overlookmotel
90b0f6da81
fix(transformer): use UIDs for React imports (#3431)
Use UIDs for local var names for React JSX imports e.g. `_jsx` in
`import { jsx as _jsx } from "react/jsx-runtime";`.
2024-05-29 18:32:10 +08:00
Dunqing
6a1f2c21df chore(transform_conformance): skip some test cases (#3449) 2024-05-28 13:38:03 +00:00
Dunqing
92df98b005 feat(transformer/typescript): report error that do not allow namespaces (#3448) 2024-05-28 13:38:01 +00:00
Dunqing
a6b073a47c feat(transformer/typescript): report error for namespace exporting non-const (#3447) 2024-05-28 13:38:00 +00:00
Dunqing
150255c704 feat(transformer/typescript): if within a block scope, use let to declare enum name (#3446) 2024-05-28 13:37:58 +00:00
Dunqing
e80552c797 feat(transformer/typescript): if binding exists, variable declarations are not created for namespace name (#3445) 2024-05-28 13:37:57 +00:00
Dunqing
816a782254
feat(transformer): support targets option of preset-env (#3371)
The implementation of the `targets` options was copied from
[swc](https://github.com/swc-project/swc/tree/main/crates/preset_env_base),
which resulted in some added dependencies in transformer.
Currently, it has supported enabling plugins by `targets`
2024-05-27 10:33:40 +08:00
Dunqing
241e8d1899
feat(transformer/typescript): if the binding exists, the identifier reference is not renamed (#3387)
Related:
https://github.com/oxc-project/oxc/discussions/3251#discussioncomment-9528247
2024-05-27 01:00:04 +00:00
overlookmotel
d4371e8f95
fix(transformer): use UIDs in TS namespace transforms (#3395)
Use the `TraverseCtx::generate_uid` method introduced in #3395 to fix
some of the TS namespace test cases.

But... I honestly have no idea what I'm doing here!

I am running up against a combination of 3 different areas where I know
very little:

1. I am unfamiliar with `Semantic`.
2. I am unfamiliar with Oxc's conventions for writing transforms.
3. I don't "speak" Typescript!

This PR should not be merged as is. I'm pretty sure it's wrong. I've
done it mostly just to test out `generate_uid`.

In particular:

1. Is `SymbolFlags::FunctionScopedVariable` the right flags to use in
all cases here?
2. `generate_uid` creates a symbol, and registers a binding for it in
the scope tree. So if there are any branches in this logic where `name`
doesn't actually get used after `generate_uid` is called, then it's not
right.
3. Identifiers which are added to AST should also have corresponding
`ReferenceId`s created for them (but I imagine this is also missing in
many other places in the transformer).

On point 2: We could split up `generate_uid` into 2 functions. One
function would find a valid UID name *but not register a binding for
it*. If you want to actually use that name, you'd call a 2nd function to
generate the binding. Would that be a better API?

Could someone help me out to progress this please?

(Sorry my lack of knowledge is a bit useless here. I will learn all
these things in time, but just trying to be honest about where I'm at
right now. I'm sure I could figure it out myself, but it would take me
hours, whereas others will probably look at it and know what to do in
about 5 mins.)
2024-05-27 08:53:13 +08:00
mysteryven
d7849f8865 refactor(linter): find return statement by using CFG in react/require-render-return (#3353)
Maybe currently Class components are relatively few in quantity, didn't performance changed.
2024-05-19 14:59:12 +00:00
Dunqing
e2c6fe0cb1
feat(transformer): report errors when options have unknown fields (#3322) 2024-05-19 01:19:40 +08:00
Dunqing
9ee962add8 feat(transformer): support from_babel_options in TransformOptions (#3301)
Move `BabelOptions` to Transformer. The `output.json` is a standard babel configuration. We can reuse BabelOptions to read [babel.config.json](https://babeljs.io/docs/configuration#babelconfigjson) or our configuration(maybe oxc.config.json)

The current `from_babel_options` implementation is copied from the `transform_options` in `test_case.rs`, which I'll completely reimplement next
2024-05-16 10:10:39 +00:00
Dunqing
8ff1ffba74
feat(transformer_conformance): skip some tests that are known to fail (#3293)
I don't think we need to be completely consistent with Babel's output.
Because Babel's output doesn't always make sense.
2024-05-15 22:06:00 +08:00
Dunqing
b9d69ad665
feat(transformer): do not add self attribute in react/jsx plugin (#3287)
follow-up: https://github.com/oxc-project/oxc/pull/3258.
2024-05-15 17:59:57 +08:00
Dunqing
b4fa27a2ee
fix(transformer): do no add __self when the jsx is inside constructor (#3258) 2024-05-14 16:12:49 +01:00
Boshen
530455849b chore(tasks): add commit sha to snapshots to make sure submodules are not outdated (#3267)
If submodules are outdated, it'll panic with the following message

```
Repository is outdated, please run `just submodules` to update it.
```

For us maintainers, we'll need the env `UPDATE_SNAPSHOT` to force an update.
2024-05-14 10:18:00 +00:00
Dunqing
eefb66f750 feat(ast): add type to AccessorProperty to support TSAbractAccessorProperty (#3256) 2024-05-13 12:35:58 +00:00
Dunqing
34dd53cc98 feat(transformer): report ambient module cannot be nested error (#3253) 2024-05-13 07:51:06 +00:00
Boshen
dbde5b3a04
refactor(diagnostics): remove export of miette 2024-05-12 11:46:48 +08:00
Boshen
09f34fc942
refactor(semantic): unify diagnostic in checker 2024-05-12 01:07:28 +08:00
Boshen
7067f9c646
refactor(transformer): clean up more diagnostics 2024-05-12 00:57:58 +08:00
Dunqing
1b29e63300 feat(transformer): do not elide jsx imports if a jsx element appears somewhere (#3237) 2024-05-11 15:00:26 +00:00
Dunqing
fd6a1aa1d2 feat(transformer_conformance): correct source type (#3233) 2024-05-11 09:30:43 +00:00
Dunqing
6ac8a8479e
fix(transformer): correctly jsx-self inside arrow-function (#3224) 2024-05-11 00:48:18 +00:00
Dunqing
18d853bb2b
feat(transformer/react): support development mode (#3143) 2024-05-10 22:07:33 +08:00
Dunqing
0ba7778e5e
fix(parser): correctly parse cls.fn<C> = x (#3208)
close: #3206
2024-05-09 10:23:45 +08:00
overlookmotel
9590eb0cf4
fix(transform): implement transform-react-display-name with bottom-up lookup (#3183)
Sliced off from #3152.

Re-implement `transform-react-display-name` using bottom-up lookup
provided by `Traverse` trait.

This fixes the 1 remaining failing test case for this plugin (see
#2937).

`Traverse` is not complete yet (see #3182), so this is also not ready to
merge yet.
2024-05-08 15:33:39 +00:00