Commit graph

272 commits

Author SHA1 Message Date
Dunqing
48031ada93 fix(transformer/typescript) shadowed imports have not been removed (#4550)
close: #4423
2024-08-05 03:15:14 +00:00
Dunqing
4efd54b84d fix(transformer/typescript): incorrect SymbolFlags for jsx imports (#4549)
All `SymbolFlags` for imports should be `SymbolFlags::Import`
2024-08-05 03:15:13 +00:00
Dunqing
3a6e4d91cf feat(transformer_conformance): test ScopeTree and SymbolTable for correctness after transformation (#4581)
part of #4549

This test verifies that the correct symbols and scopes were added/changed during the transformation. From the snapshots, most of them are incorrect currently
2024-08-04 11:45:10 +00:00
Dunqing
ecdee88cfb
fix(transformer/typescript): incorrect eliminate exports when the referenced symbol is both value and type (#4507) 2024-07-27 12:11:29 -04:00
Dunqing
f8565ae3cd fix(transformer/typescript): unexpectedly removed class binding from ExportNamedDeclaration (#4351)
The original `SymbolFlags` methods were a bit confusing I renamed and re-implemented them.
2024-07-18 16:44:38 +00:00
Dunqing
a88d588a07 feat(semantic): add ReferenceFlags::TSTypeQuery to indicate referenced by TSTypeQuery (#4317)
`ReferenceFlags::TSTypeQuery` can be used to help us insist on whether the reference is referenced by the type or not.
2024-07-17 09:52:57 +00:00
Dunqing
c362bf7edf fix(semantic): incorrect resolve references for TSInterfaceHeritage (#4311)
related issue: https://github.com/oxc-project/oxc/issues/3963
fixes: https://github.com/oxc-project/monitor-oxc/actions/runs/9960183591/job/27518854841
2024-07-17 03:33:02 +00:00
Dunqing
351ecf2707 fix(semantic): incorrect resolve references for TSTypeQuery (#4310)
```ts
type A = typeof Foo
                ^^^ Only allow reference to value symbol
```

I have verified the changed snapshot. That's correct
2024-07-17 03:33:00 +00:00
Boshen
83bd40db4e
chore: turn off doctest for all [[bin]] 2024-07-14 16:55:19 +08:00
Boshen
e167ef79c6 fix(codegen): print parenthesis properly (#4245)
`TSParenthesizedType` handles parenthesis in ts types.

It should be considered a bug if parenthesis is not printed correctly after this PR.
2024-07-14 04:13:10 +00:00
Don Isaac
4413e2d298
fix(transformer): missing initializer for readonly consructor properties (#4103) 2024-07-08 12:45:50 +08:00
Boshen
aaac2d8775
fix(codegen): preserve parentheses from AST instead calculating from operator precedence (#4055)
…operator precedence

Calculating from operator precedence is currently unsafe and will result
incorrect semantics.
2024-07-05 14:01:17 +08:00
Dunqing
bdee156c5d fix(transformer/typescript): declare class incorrectly preserved as runtime class (#3997)
fix: #3993
2024-07-01 16:04:40 +00:00
Dunqing
a50ce3d299 fix(transformer/typescript): missing initializer for class constructor arguments with private and protected modifier (#3996)
close: #3992
2024-07-01 15:10:32 +00:00
Boshen
5845057bff refactor(transformer): pass in symbols and scopes (#3978)
This PR adds a new method `build_with_symbols_and_scopes` to make semantic building optional, there may be prior steps that has the semantic data already built.
2024-06-30 06:33:48 +00:00
DonIsaac
63f36daae0 feat(parser): parse modifiers with parse_modifiers (take 2) (#3977)
Same as #3948, with fixes for bugs found by @Boshen.
2024-06-30 03:46:34 +00:00
Boshen
14bc31ee74
Revert "feat(parser): parse modifiers with parse_modifiers (#3948)"
This reverts commit 7b38bde073.
2024-06-29 14:16:26 +08:00
DonIsaac
7b38bde073 feat(parser): parse modifiers with parse_modifiers (#3948)
Closes #3929
2024-06-29 05:29:47 +00:00
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