Commit graph

91 commits

Author SHA1 Message Date
Boshen
99a40ce6ac fix(semantic): export default foo should have ExportLocalName::Default(NameSpan) entry (#3823) 2024-06-22 11:09:23 +00:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
overlookmotel
c00598b9d4
fix(transformer): JSX set reference_id on refs to imports (#3524)
Set `reference_id` for references to new imported bindings. e.g. `_jsx`
in `_jsx(Foo, {})` where JSX transform has inserted `import {jsx as
_jsx} from "react/jsx-runtime";`.
2024-06-05 10:57:05 +08:00
Boshen
e2dd8ac8fc feat(syntax): export is_reserved_keyword and is_global_object method (#3384) 2024-05-22 04:58:04 +00:00
Boshen
bd8a0ddb7f feat(linter): no-barrel-file (#3275)
![image](https://github.com/oxc-project/oxc/assets/1430279/524c8afa-a4c0-45a3-b95d-f8efd359a84f)
2024-05-16 07:54:09 +00:00
Dunqing
b4fa27a2ee
fix(transformer): do no add __self when the jsx is inside constructor (#3258) 2024-05-14 16:12:49 +01:00
overlookmotel
4e20b04acc fix(traverse): create scope for function nested in class method (#3234)
Fixes a bug in #3229.

The logic to prevent a duplicate scope being created for a `Function` which is a `MethodDefinition` would also stop a scope being created for inner function in:

```rs
class X {
  foo() {
    function bar() {}
  }
}
```

or

```rs
class X {
  foo( bar = function() {} ) {}
}
```

This PR fixes that. This change also allows removing `ScopeFlags::Method` which #3229 added.
2024-05-11 12:07:00 +00:00
overlookmotel
46c02aee61 feat(traverse): add scope flags to TraverseCtx (#3229)
Add scope flags to `TraverseCtx`.

Closes #3189.

`walk_*` functions build a stack of `ScopeFlags` as AST is traversed, and they can be queried from within visitors with `ctx.scope()`, `ctx.ancestor_scope()` and `ctx.find_scope()`.

The codegen which generates `walk_*` functions gets the info about which AST types have scopes, and how to check for strict mode from the `#[visited_node]` attrs on AST type definitions in `oxc_ast`.

A few notes:

Each scope inherits the strict mode flag from the level before it in the stack, so if you need to know "am I in strict mode context here?", `ctx.scope().is_strict_mode()` will tell you - no need to travel back up the stack to find out.

Scopes do *not* inherit any other flags from level before it. So `ctx.scope()` in a block nested in a function will return `ScopeFlags::empty()` not `ScopeFlags::Function`.

I had to add an extra flag `ScopeFlags::Method`. The reason for this is to deal with when a `Function` is actually a `MethodDefinition`, and to avoid creating 2 scopes in this case. The principle I'm trying to follow is to encode as little logic in the codegen as possible, as it's rather hidden away. Instead the codegen follows a standard logic for every node, guided by attributes which are visible next to the types in `oxc_ast`. This hopefully makes how `Traverse`'s visitors are generated less mysterious, and easier to change.

The case of `Function` within `MethodDefinition` is a weird one and would not be possible to implement without encoding a magic "special case" within the codegen without this extra `ScopeFlags::Method` variant. Its existence does not alter the operation of any other code in Oxc which uses `ScopeFlags`.

In my view `ScopeFlags` might benefit from a little bit of an overhaul anyway. I believe we could pack more information into the bits and make it more useful.
2024-05-11 04:39:42 +00:00
Boshen
f1ccbd4856
feat(syntax): add ToJsInt32 trait for f64 (#3132) 2024-04-29 21:13:04 +08:00
Boshen
870d11f1bb
feat(syntax): add ToJsString trait for f64 (#3131) 2024-04-29 21:00:04 +08:00
Boshen
a8af5de8f5
refactor(syntax): move number related functions to number module (#3130) 2024-04-29 18:54:35 +08:00
Boshen
ae6561308c
refactor(syntax): use FxHashMap for ModuleRecord::request_modules (#3124)
closes #3121

The ordering is not important here.
2024-04-29 03:37:34 +00:00
Ali Rezvani
e6d11c6190
feat(syntax): module graph visitor. (#3062)
I've tried too hard to make it into a full-fledged depth first iterator, But had no success with it; It is the next best thing that I could've thought of.

Provides a way to visit the module graph from a ModuleRecord as its entry point.
2024-04-22 10:10:27 +08:00
Boshen
1f7033e7ab
fix(semantic): correctly resolve identifiers inside parameter initializers (#3046)
close: #2644
This fixes function parameters. I think we need an extra AST node to fix catch parameters, which will be the next PR.
2024-04-21 23:38:31 +08:00
overlookmotel
1249c6c326
refactor(ast): implement same traits on all fieldless enums (#3031)
Implement same traits on all AST fieldless enums, for consistency. Just
a little bit of tidying.
2024-04-20 01:53:48 +08:00
Don Isaac
1ea24ea0a7
fix(semantic): symbols inside functions and classes incorrectly flagged as exported (#2896)
# What This PR Does

Symbols declared inside exported functions and classes were being
incorrectly flagged with `SymbolFlags::Export`.

For example,
```ts
export function foo<T>(a: T) {
  let b = String(a)
  return b
}
```
`T`, `a`, and `b` were all flagged as exported.

## Further Work
It doesn't seem like exported enums and interfaces are being included in
`ModuleRecord`. Am I looking in the wrong place, or are they actually
missing?
2024-04-05 23:01:27 +08:00
Boshen
7710d8caf1
feat(transformer): add compiler assumptions (#2872)
closes #2869
2024-03-31 02:04:21 +00:00
Dunqing
df628289ff
fix(linter/import): ignore export declaration in no-duplicates (#2863) 2024-03-30 12:57:43 +08:00
Dunqing
1b5e544a36
refactor(semantic): distinguish whether requested_modules is type imports/exports (#2848) 2024-03-29 19:52:30 +08:00
Dunqing
712b3d2a11
feat(semantic): distinguish type imports in ModuleRecord (#2785)
I am not sure moving `ImportOrExportKind` to `oxc-syntax` is a good
solution.
2024-03-23 21:38:17 +08:00
overlookmotel
75226f3b4a
chore: silence erroneous RA warnings for Tsify (#2731) 2024-03-15 12:42:12 +00:00
Boshen
697b6b70c0
feat: merge features serde and wasm to serialize (#2716)
This PR merges the previous confusing features `serde` and `wasm` into a
single `serialize` feature.

We'll eventually do serialize + type information for both wasm and napi
targets.

`oxc_macros` is removed from `oxc_ast`'s dependency because it requires
`syn` and friends, which goes against our policy ["Third-party
dependencies should be
minimal."](https://oxc-project.github.io/docs/contribute/rules.html#development-policy)
2024-03-14 17:13:12 +08:00
overlookmotel
89e8d1526f
refactor: derive SerAttrs on all AST types (#2698)
Add `SerAttrs` derive to a few types that I missed out in #2669.
2024-03-13 00:14:04 +00:00
Boshen
366a87975d
feat(linter): resolve ESM star exports (#2682) 2024-03-11 21:43:11 +08:00
overlookmotel
3c1e0db53f
refactor: reduce cfg_attr boilerplate with SerAttrs derive (#2669)
Closes #2641.

Also added `tsify` attribute to the `SerAttrs` derive macro, so `#[cfg_attr(feature = "wasm", tsify(...))]` can also be reduced to `#[tsify(...)]`.
2024-03-11 13:38:24 +08:00
overlookmotel
cba1e2f338
refactor(ast): import Tsify to shorten code (#2665)
Pure refactor. Import `tsify::Tsify` in files that use it, so then shorten a load of:

```diff
- #[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
+ #[cfg_attr(feature = "wasm", derive(Tsify))]
```
2024-03-11 12:37:10 +08:00
overlookmotel
d76ee6b2db
refactor: "wasm" feature enable "serde" feature (#2639)
Make `wasm` feature also enable `serde` feature. This allows shortening
a lot of `#[cfg_attr]`s.

As discussed in
https://github.com/oxc-project/oxc/pull/2638#issuecomment-1984066757.
2024-03-08 10:06:49 +08:00
overlookmotel
6b5723cdbe
refactor(ast): shorten manual TS defs (#2638)
Does the same thing, just (in my opinion) a little bit more readable.
2024-03-08 00:53:51 +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
d41dcc316e
feat(linter): remove all commonjs logic for import plugin (#2537) 2024-02-28 18:13:44 +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
Boshen
fba66dcc75
fix(linter): improve import/no-named-as-default (#2494) 2024-02-25 21:24:08 +08:00
Boshen
f64c7e04a3
feat(linter): handle cjs module.exports.foo = bar and exports.foo = bar (#2492) 2024-02-24 23:54:43 +08:00
Boshen
3e1794d6c0
feat(syntax): implement Debug for ModuleRecord (#2488) 2024-02-24 17:34:42 +08:00
Andrew McClenaghan
6b3b260dcc
feat(Codegen): Improve codegen (#2460)
This gets all the new TS types working to the same level TS output was
before and fixes a bunch of other codegen

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-21 14:41:57 +08:00
Dunqing
950298d960
feat(semantic): add static property, ElementKind::Getter, ElementKind::Setter in ClassTable (#2445) 2024-02-20 13:07:48 +08:00
Dunqing
67d7a4677f
refactor(linter): get arrow expression by scope_id in no_render_return_value (#2424) 2024-02-17 21:06:28 +08:00
Dunqing
540b2a0396
fix(semantic): remove unnecessary SymbolFlags::Import (#2311) 2024-02-05 14:16:29 +08:00
Boshen
589fd0cdd1
chore: omit warning for unused TS_APPEND_CONTENT 2024-02-01 14:07:40 +08:00
Dunqing
f673e41539
feat(ast): remove serde skip for symbol_id and reference_id (#2220)
We want to see symbol_id and reference_id in ast
2024-01-30 21:03:05 +08:00
Nicholas Roberts
cd5026c015
feat(ast): TypeScript definition for wasm target (#2158)
Closes #2151
2024-01-30 15:43:03 +08:00
overlookmotel
0dc1804a52 refactor(syntax): don't re-export unicode_id_start 2024-01-23 11:05:17 +08:00
overlookmotel
bc7ea0bedb refactor(parser): make is_identifier methods consistent 2024-01-23 11:05:17 +08:00
overlookmotel
27aaff2bef
refactor(syntax): ASCII tables static not const (#2128)
A small nit: `ASCII_CONTINUE` is used in multiple places, so it's
preferable that it's a `static` not a `const` so it only gets included
in the binary once, rather than once for each usage.

Only makes a tiny difference on benchmarks (~0.1 ms), but change seems
worthwhile anyway just to be more "good practice".
2024-01-22 21:49:54 +08:00
overlookmotel
4f59c4fdfc
refactor(syntax): reformat identifier byte tables (#2111)
Not a substantive change, just reformatting the ASCII byte tables in
`oxc_syntax`.

In my opinion, this makes them easier to read.
2024-01-22 13:45:12 +08:00
Wenzhe Wang
29dc5e69ff
fix(codegen): add parenthesis in binary expression by precedence (#2067)
related ESBuild code:
f5f8ff895c/internal/js_printer/js_printer.go (L3348-L3371)
2024-01-17 23:01:42 +08:00
Dunqing
ead4e8df1f
feat(transformer/typescript): remove import if only have type reference (#2001) 2024-01-13 08:52:14 +00:00
Dunqing
3b4fe0edfd
feat(semantic): allow reserved keyword defined in ts module block (#1907)
https://www.typescriptlang.org/play?target=99#code/PTAEAEBcEMCcHMCmkBcpEGcB2iAekAoECAWwHsATAVwBtE1MAmABkcYBpMd8CiwAHKgCNQAYzJYMkUAGUAKgCUAkgGE5AfQCyAeQAiAUXUA5AIKb9MtDOQAeAGQByKdEgBLUaCmwAfKAC8oPwAFgBm6hjIAISgAN58oAkJAESuJPx0JIhYkBhJ7PGJoCnZiLAh0KKIeQWJSXSQ1cSFSfwVANbQSI1gzfywrgBuLlX5TbV9ZJCIolMU3YVFgkI07vPNzm6ia7UAnq6INHOjYAC+ANy8ePxksNIx5wQU0zRwiKBY0JkYrZWgIWRkWKgAgJcSSaSpdKITLZDBoaBYHZnYGgiRSQLCFaieGI5EgsRoiElMoVeigBFIlGgIawUD1HGU-Fg9E-DpIBl41HgwL9IZTDlMwk8ybTWYCrnojbucUE7l7A4UAUnAhAA
2024-01-06 12:56:27 +08:00
Dunqing
6c5b22f728
refactor(semantic): improve ClassTable implmention and merge properties and methods to elements (#1902) 2024-01-05 18:38:51 +08:00
Dunqing
f1b433b126
feat(playground): visualize symbol (#1886)
close: https://github.com/oxc-project/oxc/issues/1048
2024-01-04 15:36:31 +08:00