Commit graph

445 commits

Author SHA1 Message Date
Dunqing
58f6ec21f3 refactor(ast): enter node before scope (#4347)
close: #4276
2024-07-18 19:18:01 +00: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
DonIsaac
21d0eee182 refactor(semantic): use error codes for ts diagnostics (#4336)
Part of #4333
2024-07-18 16:09:28 +00:00
github-actions[bot]
7d751898b3
Release crates v0.21.0 (#4344)
## [0.21.0] - 2024-07-18

- d7ab0b8 semantic: [**BREAKING**] Simplify node creation (#4226)
(lucab)

### Features

- af4dc01 ast: Align ts ast scope with typescript (#4253) (Dunqing)
- 83c2c62 codegen: Add option for choosing quotes; remove slow
`choose_quot` method (#4219) (Boshen)
- 5d17675 mangler: Add debug mode (#4314) (Boshen)
- e3e663b mangler: Initialize crate and integrate into minifier (#4197)
(Boshen)
- c818472 minifier: Dce conditional expression `&&` or `||` (#4190)
(Boshen)
- 8a190eb oxc: Export `oxc_mangler` (Boshen)
- 20cdb1f semantic: Align class scope with typescript (#4195) (Dunqing)
- 92ee774 semantic: Add `ScopeFlags::CatchClause` for use in CatchClause
(#4205) (Dunqing)
- 205c259 sourcemap: Support SourceMapBuilder#token_chunks (#4220)
(underfin)
- 7eb960d transformer: Decode xml character entity `&#xhhhh` and
`&#nnnn;` (#4235) (Boshen)

### Bug Fixes

- bf3d8d3 codegen: Print annotation comment inside parens for new and
call expressions (#4290) (Boshen)
- 084ab76 codegen: Use `ryu-js` for f64 to string (Boshen)
- e167ef7 codegen: Print parenthesis properly (#4245) (Boshen)
- c65198f codegen: Choose the right quote for jsx attribute string
(#4236) (Boshen)
- be82c28 codegen: Print `JSXAttributeValue::StringLiteral` directly
(#4231) (Boshen)
- 3df9e69 mangler: No shorthand `BindingProperty`; handle var hoisting
and export variables (#4319) (Boshen)
- f144082 minifier: RemoveDeadCode should visit nested expression
(#4268) (underfin)
- 66b455a oxc_codegen: Avoid print same pure comments multiple time
(#4230) (IWANABETHATGUY)
- 9a87e41 parser: Avoid crashing on invalid const modifier (#4267)
(lucab)
- 641a78b parser: Fix tests for number parsing (#4254) (overlookmotel)
- 9badac0 semantic: Avoid var hosting insert the var variable to the
`CatchClause` scope (#4337) (Dunqing)
- 95e15b6 semantic: Incorrect resolve references for `ExportSpecifier`
(#4320) (Dunqing)
- c362bf7 semantic: Incorrect resolve references for
`TSInterfaceHeritage` (#4311) (Dunqing)
- 351ecf2 semantic: Incorrect resolve references for `TSTypeQuery`
(#4310) (Dunqing)
- 1108f2a semantic: Resolve references to the incorrect symbol (#4280)
(Dunqing)
- 22d56bd semantic: Do not resolve references after `FormalParameters`
in TS type (#4241) (overlookmotel)- 1c117eb Avoid print extra semicolon
after accessor property (#4199) (IWANABETHATGUY)

### Performance

- a8dc4f3 parser: Speed up parsing numbers with `_` separators (#4259)
(overlookmotel)
- b94540d parser: Speed up parsing octal literals (#4258)
(overlookmotel)
- a7b328c parser: Faster parsing decimal numbers (#4257) (overlookmotel)
- f9d3f2e semantic: Inline ast record functions (#4272) (overlookmotel)
- 8fad7db semantic: Reduce `AstNodeId` to `u32` (#4264) (overlookmotel)
- 23743db semantic: Do not record ast nodes for cfg if cfg disabled
(#4263) (overlookmotel)
- da69076 semantic: Reduce overhead of cfg recording ast nodes (#4262)
(overlookmotel)
- cb15303 semantic: Reduce memory copies (#4216) (overlookmotel)
- ef4c1f4 semantic: Reduce lookups (#4214) (overlookmotel)
- f23e54f semantic: Recycle unresolved references hash maps (#4213)
(overlookmotel)
- 2602ce2 semantic: Reuse existing map of unresolved refs (#4206)
(lucab)

### Refactor

- 2c7bb9f ast: Pass final `ScopeFlags` into `visit_function` (#4283)
(overlookmotel)
- 3e099fe ast: Move `enter_scope` after `visit_binding_identifier`
(#4246) (Dunqing)
- aab7aaa ast/visit: Fire node events as the outermost one. (#4203)
(rzvxa)
- d1c4be0 codegen: Clean up annotation_comment (Boshen)
- 06197b8 codegen: Separate tests (Boshen)
- aa22073 codegen: Improve print API (#4196) (Boshen)
- c5731a5 semantic: Remove defunct code setting ScopeFlags twice (#4286)
(overlookmotel)
- 16698bc semantic: Move function/class-specific code into specific
visitors (#4278) (overlookmotel)
- ee16668 semantic: Rename function param (#4277) (overlookmotel)
- 25f0771 semantic: Alter syntax of `control_flow!` macro (#4275)
(overlookmotel)
- 639fd48 semantic: Comment why extra CFG enabled check (#4274)
(overlookmotel)
- c418bf5 semantic: Directly record `current_node_id` when adding a
scope (#4265) (Dunqing)
- ace4f1f semantic: Update the order of `visit_function` and `Visit`
fields in the builder to be consistent (#4248) (Dunqing)
- 8bfeabf semantic: Simplify adding `SymbolFlags::Export` (#4249)
(Dunqing)
- dc2b3c4 semantic: Add strict mode in scope flags for class definitions
(#4156) (Dunqing)
- 81ed588 semantic: Convert scope fields to IndexVecs (#4208) (lucab)
- bbe5ded semantic: Set `current_scope_id` to `scope_id` in
`enter_scope` (#4193) (Dunqing)
- 7f1addd semantic: Correct scope in CatchClause (#4192) (Dunqing)
- fc0b17d syntax: Turn the `AstNodeId::dummy` into a constant field.
(#4308) (rzvxa)
- a197e01 transformer/typescript: Remove unnecessary code (#4321)
(Dunqing)
- 1458d81 visit: Add `#[inline]` to empty functions (#4330)
(overlookmotel)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-18 14:39:07 +08:00
Dunqing
fc39ffa009
Revert "Release crates v0.21.0" (#4342)
Reverts oxc-project/oxc#4338


https://github.com/oxc-project/oxc/actions/runs/9986290706/job/27598542089
Release failed
2024-07-18 14:11:42 +08:00
github-actions[bot]
0abcf499b7
Release crates v0.21.0 (#4338)
## [0.21.0] - 2024-07-18

- d7ab0b8 semantic: [**BREAKING**] Simplify node creation (#4226)
(lucab)

### Features

- af4dc01 ast: Align ts ast scope with typescript (#4253) (Dunqing)
- 83c2c62 codegen: Add option for choosing quotes; remove slow
`choose_quot` method (#4219) (Boshen)
- 5d17675 mangler: Add debug mode (#4314) (Boshen)
- e3e663b mangler: Initialize crate and integrate into minifier (#4197)
(Boshen)
- c818472 minifier: Dce conditional expression `&&` or `||` (#4190)
(Boshen)
- 8a190eb oxc: Export `oxc_mangler` (Boshen)
- 20cdb1f semantic: Align class scope with typescript (#4195) (Dunqing)
- 92ee774 semantic: Add `ScopeFlags::CatchClause` for use in CatchClause
(#4205) (Dunqing)
- 205c259 sourcemap: Support SourceMapBuilder#token_chunks (#4220)
(underfin)
- 7eb960d transformer: Decode xml character entity `&#xhhhh` and
`&#nnnn;` (#4235) (Boshen)

### Bug Fixes

- bf3d8d3 codegen: Print annotation comment inside parens for new and
call expressions (#4290) (Boshen)
- 084ab76 codegen: Use `ryu-js` for f64 to string (Boshen)
- e167ef7 codegen: Print parenthesis properly (#4245) (Boshen)
- c65198f codegen: Choose the right quote for jsx attribute string
(#4236) (Boshen)
- be82c28 codegen: Print `JSXAttributeValue::StringLiteral` directly
(#4231) (Boshen)
- 3df9e69 mangler: No shorthand `BindingProperty`; handle var hoisting
and export variables (#4319) (Boshen)
- f144082 minifier: RemoveDeadCode should visit nested expression
(#4268) (underfin)
- 66b455a oxc_codegen: Avoid print same pure comments multiple time
(#4230) (IWANABETHATGUY)
- 9a87e41 parser: Avoid crashing on invalid const modifier (#4267)
(lucab)
- 641a78b parser: Fix tests for number parsing (#4254) (overlookmotel)
- 9badac0 semantic: Avoid var hosting insert the var variable to the
`CatchClause` scope (#4337) (Dunqing)
- 95e15b6 semantic: Incorrect resolve references for `ExportSpecifier`
(#4320) (Dunqing)
- c362bf7 semantic: Incorrect resolve references for
`TSInterfaceHeritage` (#4311) (Dunqing)
- 351ecf2 semantic: Incorrect resolve references for `TSTypeQuery`
(#4310) (Dunqing)
- 1108f2a semantic: Resolve references to the incorrect symbol (#4280)
(Dunqing)
- 22d56bd semantic: Do not resolve references after `FormalParameters`
in TS type (#4241) (overlookmotel)- 1c117eb Avoid print extra semicolon
after accessor property (#4199) (IWANABETHATGUY)

### Performance

- a8dc4f3 parser: Speed up parsing numbers with `_` separators (#4259)
(overlookmotel)
- b94540d parser: Speed up parsing octal literals (#4258)
(overlookmotel)
- a7b328c parser: Faster parsing decimal numbers (#4257) (overlookmotel)
- f9d3f2e semantic: Inline ast record functions (#4272) (overlookmotel)
- 8fad7db semantic: Reduce `AstNodeId` to `u32` (#4264) (overlookmotel)
- 23743db semantic: Do not record ast nodes for cfg if cfg disabled
(#4263) (overlookmotel)
- da69076 semantic: Reduce overhead of cfg recording ast nodes (#4262)
(overlookmotel)
- cb15303 semantic: Reduce memory copies (#4216) (overlookmotel)
- ef4c1f4 semantic: Reduce lookups (#4214) (overlookmotel)
- f23e54f semantic: Recycle unresolved references hash maps (#4213)
(overlookmotel)
- 2602ce2 semantic: Reuse existing map of unresolved refs (#4206)
(lucab)

### Refactor

- 2c7bb9f ast: Pass final `ScopeFlags` into `visit_function` (#4283)
(overlookmotel)
- 3e099fe ast: Move `enter_scope` after `visit_binding_identifier`
(#4246) (Dunqing)
- aab7aaa ast/visit: Fire node events as the outermost one. (#4203)
(rzvxa)
- d1c4be0 codegen: Clean up annotation_comment (Boshen)
- 06197b8 codegen: Separate tests (Boshen)
- aa22073 codegen: Improve print API (#4196) (Boshen)
- c5731a5 semantic: Remove defunct code setting ScopeFlags twice (#4286)
(overlookmotel)
- 16698bc semantic: Move function/class-specific code into specific
visitors (#4278) (overlookmotel)
- ee16668 semantic: Rename function param (#4277) (overlookmotel)
- 25f0771 semantic: Alter syntax of `control_flow!` macro (#4275)
(overlookmotel)
- 639fd48 semantic: Comment why extra CFG enabled check (#4274)
(overlookmotel)
- c418bf5 semantic: Directly record `current_node_id` when adding a
scope (#4265) (Dunqing)
- ace4f1f semantic: Update the order of `visit_function` and `Visit`
fields in the builder to be consistent (#4248) (Dunqing)
- 8bfeabf semantic: Simplify adding `SymbolFlags::Export` (#4249)
(Dunqing)
- dc2b3c4 semantic: Add strict mode in scope flags for class definitions
(#4156) (Dunqing)
- 81ed588 semantic: Convert scope fields to IndexVecs (#4208) (lucab)
- bbe5ded semantic: Set `current_scope_id` to `scope_id` in
`enter_scope` (#4193) (Dunqing)
- 7f1addd semantic: Correct scope in CatchClause (#4192) (Dunqing)
- fc0b17d syntax: Turn the `AstNodeId::dummy` into a constant field.
(#4308) (rzvxa)
- a197e01 transformer/typescript: Remove unnecessary code (#4321)
(Dunqing)
- 1458d81 visit: Add `#[inline]` to empty functions (#4330)
(overlookmotel)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-18 13:56:35 +08:00
Dunqing
9badac030d fix(semantic): avoid var hosting insert the var variable to the CatchClause scope (#4337)
related: #4192 #4323

I will figure it out #4323 later
2024-07-18 02:52:14 +00:00
Dunqing
95e15b6dc5 fix(semantic): incorrect resolve references for ExportSpecifier (#4320)
```ts
type A = any;
const B = 0;
export { A, B }
       ^^^^^^^^ ExportSpecifiers

export { A }
       ^^^^^ type-only ExportSpecifiers

```

non-type-only `ExportSpecifier` can reference value and type symbols. but currently, `IdentifierReference` in ExportSpecifier only has a `ReferenceFlags::Read`
2024-07-17 09:52:58 +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
Dunqing
48724a0d44 chore(semantic): copy tests from typescript-eslint’s scope-manager (#3990)
close:  #2947

These fixtures were copied from a5b652da1e/packages/scope-manager/tests/fixtures. We used them to test out semantic `ScopeTree` and `SymbolTable`
2024-07-17 02:50:50 +00:00
Dunqing
1108f2a700 fix(semantic): resolve references to the incorrect symbol (#4280)
close: #3799
related: #3863
2024-07-17 02:50:48 +00:00
Dunqing
af4dc0112e feat(ast): align ts ast scope with typescript (#4253)
close: #3969
close: #2023

We need to add scope according to [this](d8086f14b6/src/compiler/binder.ts (L3883-L3962)). There are still some ASTs that need to be added to the scope.

---

Context from @Boshen:

Before this whole journey of fixing symbols and scopes I asked @Dunqing to debug through binder.ts via a debugger to fully understand how it does resolution.

We then agreed to align the implementation so that when a problem occurs, we can debug through both implementations and find where our problem is.

tsc doesn't have a specification, so we need to align with the reference implementation instead.
2024-07-17 02:50:47 +00:00
rzvxa
fc0b17d5a0 refactor(syntax): turn the AstNodeId::dummy into a constant field. (#4308) 2024-07-16 22:43:21 +00:00
overlookmotel
c5731a5431 refactor(semantic): remove defunct code setting ScopeFlags twice (#4286)
Scope flags for functions is set when the scope is created. Remove redundant code that sets them again.
2024-07-16 07:32:36 +00:00
overlookmotel
2c7bb9f6c8 refactor(ast): pass final ScopeFlags into visit_function (#4283)
We have a strange workaround for `visit_function` where we pass in `ScopeFlags`, to support creating the scope inside `Function`, but setting different flags for `MethodDefinition`s.

Previously `visit_function` took `Option<ScopeFlags>` and then did `flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function` to it. Personally, I found this confusing. When I was looking at `MethodDefinition`, I was wondering "It's a function, why doesn't it set Function flag too?"

This changes makes it more explicit and clear what `ScopeFlags` everything has.
2024-07-16 07:22:07 +00:00
overlookmotel
16698bc191 refactor(semantic): move function/class-specific code into specific visitors (#4278)
Instead of calling `bind_function_or_class_expression` for every scope, and then branching on the AST node kind, insert the relevant code into the visitors for functions and classes. This reduces work on all other kinds of scopes e.g. block statements.
2024-07-15 18:36:20 +00:00
overlookmotel
ee16668168 refactor(semantic): rename function param (#4277)
Small style nit. It's nicer to have Rust Analyser's param name hint show `builder` rather than `_builder`.
2024-07-15 15:06:59 +00:00
overlookmotel
25f0771185 refactor(semantic): alter syntax of control_flow! macro (#4275)
Previously:

```rs
let ix = control_flow!(|self, cfg| cfg.current_node_ix);
```

after this PR:

```rs
let ix = control_flow!(self, |cfg| cfg.current_node_ix);
```

It expands to:

```rs
let ix = if let Some(ref mut cfg) = self.cfg {
    cfg.current_node_ix
} else {
    Default::default()
};
```

So rationale for this change is that it makes it clearer that `self` is passed *in* and `cfg` comes *out* into the "closure".
2024-07-15 14:31:04 +00:00
overlookmotel
639fd48227 refactor(semantic): comment why extra CFG enabled check (#4274)
Add a comment referencing conclusions of #4273.
2024-07-15 12:11:04 +00:00
overlookmotel
f9d3f2ef55 perf(semantic): inline ast record functions (#4272)
Inline these functions so that when CFG is disabled, it doesn't cost a function call just for the trivial `if self.cfg.is_some()` check.

Based on @rzvxa's suggestion in https://github.com/oxc-project/oxc/pull/4263#pullrequestreview-2176762670.
2024-07-15 11:43:48 +00:00
overlookmotel
23743dbd59 perf(semantic): do not record ast nodes for cfg if cfg disabled (#4263)
Control flow graph builder records AST node IDs in a temp structure `ast_node_records`. Disable this if CFG is disabled.
2024-07-15 04:31:47 +00:00
overlookmotel
da69076c98 perf(semantic): reduce overhead of cfg recording ast nodes (#4262)
Control flow graph builder records AST node IDs in a temp structure `ast_nodes_records`. Only the first AST node ID inserted into the `Vec` is ever used, so turn it into just a single value.

Using `AstNodeId::dummy()` as sentinel for "not set" instead of using `Option<AstNodeId>` to reduce size of the records stack. `Option<AstNodeId>` is 16 bytes.
2024-07-15 04:31:43 +00:00
Dunqing
c418bf53ce refactor(semantic): directly record current_node_id when adding a scope (#4265)
close: #4234
2024-07-15 03:02:18 +00:00
Dunqing
ace4f1ff77 refactor(semantic): update the order of visit_function and Visit fields in the builder to be consistent (#4248)
Same as #4195
2024-07-14 11:39:15 +00:00
Dunqing
8bfeabfe6a refactor(semantic): simplify adding SymbolFlags::Export (#4249)
```ts
export default class Binding {}
//                   ^^^^^^^ SymbolFlags::Export

export default function Binding () {}
//                      ^^^^^^^ SymbolFlags::Export

// No binding, so we should not have SymbolFlags::Export
export default function() {}
export default class {}

```
2024-07-14 11:39:13 +00:00
Dunqing
3e099febf6 refactor(ast): move enter_scope after visit_binding_identifier (#4246)
This is now consistent with other ASTs that require bind

2019043e72/crates/oxc_ast/src/ast/ts.rs (L814-L815)
2024-07-14 04:06:02 +00:00
Dunqing
dc2b3c44fb refactor(semantic): add strict mode in scope flags for class definitions (#4156)
related: https://github.com/oxc-project/oxc/issues/4142#issuecomment-2219125356

Although we called `enter_node(Class)`, that doesn't mean we're in the `class` scope. It causes our must to visit decorators before `enter_node`.

Let's look at this case. It causes a syntax error if we don't visit decorators before `enter_node`
```js
// This file was procedurally generated from the following sources:
// - src/decorator/decorator-call-expr-identifier-reference-yield.case
// - src/decorator/syntax/valid/cls-expr-decorators-valid-syntax.template
/*---
description: Decorator @ DecoratorCallExpression (Valid syntax for decorator on class expression)
esid: prod-ClassExpression
features: [class, decorators]
flags: [generated, noStrict]
info: |
    ClassExpression[Yield, Await] :
      DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await]

    DecoratorList[Yield, Await] :
      DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

    Decorator[Yield, Await] :
      @ DecoratorMemberExpression[?Yield, ?Await]
      @ DecoratorParenthesizedExpression[?Yield, ?Await]
      @ DecoratorCallExpression[?Yield, ?Await]

    ...

    DecoratorCallExpression[Yield, Await] :
      DecoratorMemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

    DecoratorMemberExpression[Yield, Await] :
      IdentifierReference[?Yield, ?Await]
      DecoratorMemberExpression[?Yield, ?Await] . IdentifierName
      DecoratorMemberExpression[?Yield, ?Await] . PrivateIdentifier

    IdentifierReference[Yield, Await] :
      [~Yield] yield
      ...

---*/
function decorator() {
  return () => {};
}
var yield = decorator;

var C = @yield() class {};

```
Errors:
```shell
  × The keyword 'yield' is reserved
    ╭─[language/statements/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js:45:2]
 44 │
 45 │ @yield() class C {}
    ·  ─────
    ╰────
```

The changed code makes more sense. Only if we call `enter_scope` for class, the flags will contain `StrictMode`. Also, we can get the exact `flags` of the `scope` in the `class` at the transformer

For example:

```
class A {
   B() {
       // Before: flags is `Function`
      //  After: flags is `Function | StrictMode`
   }
}
```

The regression tests will be fixed in follow-up PRs
2024-07-14 03:35:12 +00:00
Dunqing
20cdb1fe0a feat(semantic): align class scope with typescript (#4195)
```ts
class Klass <T>   extends Root       <R>                   {}
//    ^^^^^ ^^^           ^^^^       ^^^                   ^^
//    id type_paramter super_class super_type_parameters  body
```
I reorder fields according to the order above

The class scope is not defined in the spec. But we need to create a scope for `class` to store `TypeParamters`
2024-07-14 03:19:30 +00:00
overlookmotel
22d56bdcac fix(semantic): do not resolve references after FormalParameters in TS type (#4241)
Semantic resolves references when exiting `FormalParameters` to ensure references in param initializers don't get bound to bindings inside the function body.

However, it shouldn't do this for `FormalParameters` in TS types e.g. `TSTypeAnnotation` because they don't have their own scopes.
2024-07-13 02:43:01 +00:00
lucab
d7ab0b8413 refactor(semantic)!: simplify node creation (#4226)
This tweaks AST node creation and tree manipulation, directly
building new nodes with a valid node ID.
2024-07-13 02:19:02 +00:00
lucab
81ed5885a8 refactor(semantic): convert scope fields to IndexVecs (#4208)
Closes: https://github.com/oxc-project/backlog/issues/10
2024-07-12 09:43:58 +00:00
Dunqing
92ee77487f feat(semantic): add ScopeFlags::CatchClause for use in CatchClause (#4205) 2024-07-12 03:47:07 +00:00
rzvxa
aab7aaaa06 refactor(ast/visit): fire node events as the outermost one. (#4203)
I'm going to be AFK today(till about 9 PM UTC). Meanwhile, I Didn't want to be a blocker so here we go.
It would fix the #4200 merge if you guys find it in the correct order otherwise feel free to close it.
2024-07-12 03:27:59 +00:00
overlookmotel
cb15303644 perf(semantic): reduce memory copies (#4216)
Reduce memory copies when resolving references in `Semantic`.

If parent scope has no unresolved references for `name`, there is no need to generate a new `Vec<ReferenceId>` for `name` and copy in contents from current scope. Just move the existing `Vec` to the parent.
2024-07-12 02:05:22 +00:00
overlookmotel
ef4c1f4e32 perf(semantic): reduce lookups (#4214)
Small performance optimization (I hope) to resolving references in `Semantic`. Look up current bindings once rather than on every turn of the loop.
2024-07-12 01:41:28 +00:00
overlookmotel
f23e54f97b perf(semantic): recycle unresolved references hash maps (#4213)
Closes #4169.

Reduce allocations while building `Semantic` by recycling hash maps used for tracking unresolved references, rather than creating a new one for every scope.
2024-07-12 01:41:27 +00:00
lucab
2602ce2b71 perf(semantic): reuse existing map of unresolved refs (#4206) 2024-07-11 15:35:22 +00:00
Dunqing
bbe5dede07 refactor(semantic): set current_scope_id to scope_id in enter_scope (#4193)
close: #4170
2024-07-11 08:45:35 +00:00
Dunqing
7f1adddaf0 refactor(semantic): correct scope in CatchClause (#4192)
close: #4186

CatchClause has two scopes. The first one is `CatchClause`, which will add a `CatchParameter` to it. The second one is `Block`, which will add binding that declares in the current block scope.

The spec has a syntax error about `CatchParameter`
- It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the LexicallyDeclaredNames of Block.
2024-07-11 08:45:30 +00:00
github-actions[bot]
2a169d1969
Release crates v0.20.0 (#4189)
## [0.20.0] - 2024-07-11

- 5731e39 ast: [**BREAKING**] Store span details inside comment struct
(#4132) (Luca Bruno)

### Features

- 67fe75e ast, ast_codegen: Pass the `scope_id` to the `enter_scope`
event. (#4168) (rzvxa)
- 54cd04a minifier: Implement dce with var hoisting (#4160) (Boshen)
- 44a894a minifier: Implement return statement dce (#4155) (Boshen)
- 725571a napi/transformer: Add `jsx` option to force parsing with jsx
(#4133) (Boshen)

### Bug Fixes

- 48947a2 ast: Put `decorators` before everything else. (#4143) (rzvxa)
- 7a059ab cfg: Double resolution of labeled statements. (#4177) (rzvxa)
- 4a656c3 lexer: Incorrect lexing of large hex/octal/binary literals
(#4072) (DonIsaac)
- 28eeee0 parser: Fix asi error diagnostic pointing at invalid text
causing crash (#4163) (Boshen)

### Performance

- ddfa343 diagnostic: Use `Cow<'static, str>` over `String` (#4175)
(DonIsaac)
- 2203143 semantic: Store unresolved refs in a stack (#4162) (lucab)
- fca9706 semantic: Faster search for leading comments (#4140) (Boshen)

### Documentation

- bdcc298 ast: Update the note regarding the `ast_codegen` markers.
(#4149) (rzvxa)

### Refactor

- 03ad1e3 semantic: Tweak comment argument type (#4157) (lucab)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-11 11:05:49 +08:00
rzvxa
67fe75ec6c feat(ast, ast_codegen): pass the scope_id to the enter_scope event. (#4168) 2024-07-10 15:19:23 +00:00
lucab
22031430b1 perf(semantic): store unresolved refs in a stack (#4162)
This tweaks `SemanticBuilder` logic in order to accumulate unresolved
references in a stack, getting rid of the previous index-vector which
is not required under the current access pattern.

Ref: https://github.com/oxc-project/oxc/pull/4107#issuecomment-2214167393
2024-07-10 14:59:16 +00:00
lucab
03ad1e32cc refactor(semantic): tweak comment argument type (#4157)
Minor followup from https://github.com/oxc-project/oxc/pull/4132.
2024-07-10 07:19:24 +00:00
Boshen
fca9706ab3
perf(semantic): faster search for leading comments (#4140)
fixes #4114

@leaysgur This is my wild guess, I need a second pairs of eyes to make
sure this is correct.
2024-07-10 09:54:26 +08:00
Luca Bruno
5731e3957f
refactor(ast)!: store span details inside comment struct (#4132)
This tweaks `Comment` definition in order to internally store the start
and end position of its span.

Closes: https://github.com/oxc-project/oxc/issues/4069
2024-07-09 23:23:43 +08:00
github-actions[bot]
714bf1dd7f
Release crates v0.19.0 (#4137)
## [0.19.0] - 2024-07-09

- b936162 ast/ast_builder: [**BREAKING**] Shorter allocator utility
method names. (#4122) (rzvxa)

### Features

- 485c871 ast: Allow conversion from `Expression` into `Statement` with
`FromIn` trait. (#4124) (rzvxa)

### Refactor

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-09 20:32:06 +08:00
github-actions[bot]
e29cdbfe40
Release crates v0.18.0 (#4136)
## [0.18.0] - 2024-07-09

- d347aed ast: [**BREAKING**] Generate `ast_builder.rs`. (#3890) (rzvxa)

### Features

- c6c16a5 minifier: Dce all conditional expressions (#4135) (Boshen)
- 365d9ba oxc_codegen: Generate annotation comments before
`CallExpression` and `NewExpression` (#4119) (IWANABETHATGUY)
- 3a0f2aa parser: Check for illegal modifiers in modules and namespaces
(#4126) (DonIsaac)
- 2f53bdf semantic: Check for abstract ClassElements in non-abstract
classes (#4127) (DonIsaac)
- c4ee9f8 semantic: Check for abstract initializations and
implementations (#4125) (Don Isaac)
- 44c7fe3 span: Add various implementations of `FromIn` for `Atom`.
(#4090) (rzvxa)

### Bug Fixes

- cb1af04 isolated-declarations: Remove the `async` and `generator`
keywords from `MethodDefinition` (#4130) (Dunqing)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-09 19:56:10 +08:00
DonIsaac
2f53bdf72d feat(semantic): check for abstract ClassElements in non-abstract classes (#4127)
feat(semantic): check for abstract ClassElements in non-abstract classes

chore: update coverage snapshots
2024-07-09 03:35:32 +00:00