Commit graph

548 commits

Author SHA1 Message Date
Dunqing
c59d8b3c9b feat(transformer): support all /regex/ to new RegExp transforms (#5387)
related: #4754

The implementation port from [esbuild](332727499e/internal/js_parser/js_parser.go (L12820-L12840)). And cover all babel's regexp plugins

---

## The following description was generated by `Graphite` 😋

### TL;DR

Added support for transforming various RegExp features to ensure compatibility with older JavaScript environments.

### What changed?

- Implemented a new `RegExp` transformer to handle unsupported RegExp literal features
- Added options to control different RegExp transformations (e.g., sticky flag, unicode flag, dot-all flag, etc.)
- Updated the transformer to convert unsupported RegExp literals into `new RegExp()` constructor calls
- Added test cases for different RegExp transformations
- Integrated the new RegExp transformer into the existing transformation pipeline

### How to test?

1. Run the existing test suite to ensure no regressions
2. Execute the new RegExp-specific tests in the `tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/` directory
3. Try transforming code with various RegExp features using different target environments to verify correct transformations
2024-09-05 11:04:45 +00:00
overlookmotel
cba93f52d0 feat(ast)!: add ThisExpression variants to JSXElementName and JSXMemberExpressionObject (#5466)
Close #5352.

Add to AST:

* `JSXElementName::ThisExpression` (`<this>`)
* `JSXMemberExpressionObject::ThisExpression` (`<this.foo>`, `<this.foo.bar>`)
2024-09-05 02:06:20 +00:00
Dunqing
d8b9909bd8 fix(semantic): IdentifierReference within TSPropertySignature cannot reference type-only import binding (#5441)
close: #5435

The behavior of `IdentifierReference` in `TSPropertySignature` is the same as in `TSTypeQuery`, both allow only reference value bindings and type-only import bindings.

I still use `ReferenceFlags::TSTypeQuery` here because I want to avoid producing many changes unrelated to the bug in this PR. I will refactor it in the follow-up PR soon
2024-09-05 01:50:18 +00:00
DonIsaac
0f50b1ed6d feat(semantic): check for initializers in ambient VariableDeclarations (#5463) 2024-09-05 01:33:11 +00:00
DonIsaac
62f7fff88f feat(semantic): check for non-declared, non-abstract object accessors without bodies (#5461) 2024-09-05 01:33:10 +00:00
DonIsaac
540714393a feat(semantic): check for non-declared, non-abstract class accessors without bodies (#5460)
This should be causing more negative tests to fail than it actually is. This is
because our typescript coverage tests use the "declarations" option to change
the source type to `.d.ts`, which is incorrect. This setting enables `.d.ts`
emits, it does not mean that input files should be treated as `.d.ts`
themselves.
2024-09-05 01:33:09 +00:00
DonIsaac
052e94c94e feat(semantic): check for parameter properties in constructor overloads (#5459)
Adds checks for
```
A parameter property is only allowed in a constructor implementation.ts(2369)
```
2024-09-05 01:33:07 +00:00
Boshen
10279f55d9 feat(parser): add syntax error for hyphen in JSXMemberExpression <Foo.bar-baz /> (#5440)
closes #5355
2024-09-04 14:09:06 +00:00
overlookmotel
cfe54974f1 fix(transformer): do not create double reference in JSX transform (#5414)
Follow on after #5358. Don't create a new `IdentifierReference` with a new `ReferenceId` when we already have one which is correctly resolved.
2024-09-03 15:06:07 +00:00
overlookmotel
be4642fc02 feat(semantic): transform checker check child scope IDs (#5410)
Transform checker check child scope IDs. If we have to track child scope IDs, we should make sure they're correct!
2024-09-03 00:57:13 +00:00
Dunqing
1aa49af010 feat(ast)!: remove JSXMemberExpressionObject::Identifier variant (#5358)
close: #5353

`JSXMemberExpressionObject::Identifier` is dead code.
2024-09-02 18:35:39 +00:00
Boshen
e75e0f1465 chore: update test262 / babel / typescript submodules (#5369)
closes #5215
2024-08-31 12:28:25 +00:00
overlookmotel
8a178075b7 fix(parser): treat JSX element tags starting with _ or $ as IdentifierReferences (#5343)
#5223 added a new variant `JSXElementName::IdentifierReference` for JSX identifiers which are treated as references (e.g. `<Foo>`) as opposed to `JSXElementName::Identifier` which is for lowercase (e.g. `<div>`).

But we were incorrectly categorizing identifiers beginning with `_` or `$` - these should also be treated as references.

(as discussed in https://github.com/oxc-project/oxc/pull/5339#issuecomment-2321037779)
2024-08-30 14:47:06 +00:00
overlookmotel
0de844d23c refactor(transformer): remove unnecessary code from JSX transform (#5339)
Follow-on after #5223.

JSX identifiers which start with a capital letter are now `JSXElementName::IdentifierReference`s, so no need to check for capitalized `JSXElementName::Identifier`s.
2024-08-30 12:17:08 +00:00
Dunqing
32f730085c feat(ast)!: add JSXElementName::IdentifierReference and JSXMemberExpressionObject::IdentifierReference (#5223)
close: #3528

part of #4746
2024-08-30 11:11:04 +00:00
Boshen
8d6b05ca01 fix(transformer): class property with typescript value should not be removed (#5298) 2024-08-28 13:53:41 +00:00
Dunqing
292d162b23 feat(codegen): print missing fields for AccessorProperty (#5291)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/10592050362/job/29350666018
2024-08-28 08:42:39 +00:00
Dunqing
5754c89b5e fix(transformer/typescript): remove accessibility from AccessorProperty (#5292)
Regression by #5290
2024-08-28 08:42:38 +00:00
leaysgur
15b87adb05 chore(regular_expression): Extract diagnostics (#5287)
- Extract `Diagnostic::error()`s to separate file
- Align error message prefix
2024-08-28 03:19:29 +00:00
Boshen
e6fd52e2a6 fix(parser): change unterminated regex error to be non-recoverable (#5285)
closes #5257
2024-08-28 01:57:31 +00:00
overlookmotel
af5713e411 refactor(semantic): transform checker continue checks if missing IDs (#5259)
Transform checker don't bail out if some IDs missing from AST. Continue to check for other problems.

Also simplify iterating over pairs of IDs.
2024-08-27 11:58:20 +00:00
Boshen
a17cf33dc3 refactor(semantic): remove ScopeTree::child_ids (#5232)
closes https://github.com/oxc-project/oxc/issues/5244
2024-08-27 01:49:47 +00:00
leaysgur
1686920e23 fix(parser): Span for invalid regex flags (#5225)
### Before
```
  x Flag u is mentioned twice in regular expression literal
   ,-[1:20]
 1 | const a = /\2(.)/uuxig;
   :                    ^
 2 | debugger;
   `----

  x Unexpected flag x in regular expression literal
   ,-[1:21]
 1 | const a = /\2(.)/uuxig;
   :                     ^
 2 | debugger;
   `----
```

### After
```
  x Flag u is mentioned twice in regular expression literal
   ,-[1:19]
 1 | const a = /\2(.)/uuxig;
   :                   ^
 2 | debugger;
   `----

  x Unexpected flag x in regular expression literal
   ,-[1:20]
 1 | const a = /\2(.)/uuxig;
   :                    ^
 2 | debugger;
   `----
```
2024-08-26 10:24:47 +00:00
DonIsaac
7dfd51a62b feat(parser): report class properties that are both definite and optional (#5181) 2024-08-25 01:02:49 +00:00
DonIsaac
a563968386 feat(parser): report errors on optional accessor properties (#5180) 2024-08-25 01:02:49 +00:00
DonIsaac
c2fa72571f feat(ast,parser): parse TSTypeAnnotations on AccessorProperty (#5179)
Closes #5177

While making this, I noticed an uncaught parse error for accessors: accessors cannot be optional. I'll add a fix for this in an up-stack PR.
2024-08-25 01:02:48 +00:00
Boshen
c96609151e
fix(coverage): fix cases where source_type is incorrectly set to script 2024-08-24 14:40:05 +08:00
Boshen
e4ca3d3901
chore(coverage): ignore annex-b/disabled tests 2024-08-24 14:20:06 +08:00
Boshen
12c21b2bfd
fix(coverage): do not run generated test cases when filter is applied 2024-08-24 14:03:54 +08:00
Boshen
d5a494023e refactor(semantic): rewrite handling of label statement errors (#5138)
This reverts the previous changes to handling labels so that all tests can pass.

This passes all false postivies found in `monitor-oxc` (node_modules/flow-parser/flow_parser.js)

As it turns out this requires less code and produces better diagnostics.
2024-08-24 02:37:49 +00:00
overlookmotel
c100826b42 refactor(semantic)!: always create a scope for for statements (#5110)
Part of #5008. Make scopes for `ForStatement`, `ForInStatement` and `ForOfStatement` unconditional. i.e. always create a scope, even if there is no lexical binding (e.g. `for (i of a) {}`).
2024-08-23 09:28:13 +00:00
overlookmotel
91343913ca fix(semantic): transform checker check unresolved references (#5096)
Transform checker check root unresolved references.

The transform checker is now checking pretty much everything it can.

Only fields of `ScopeTree` and `SymbolTable` that it's *not* checking are those which contain `AstNodeId`s, because transformer does not create node IDs at present:

* `ScopeTree::node_ids`
* `SymbolTable::declarations`
* `Reference::node_id`

Checking also only proceeds in "from AST" direction.

i.e. for each `SymbolId` which appears in the AST, we check everything about that symbol. But we *don't* go through all the "rows" in `SymbolTable` and check if there are any extra symbols in the table which aren't in the AST.

Presumably transformer will leave a lot of old symbols lying around in `SymbolTable` (ditto scopes and references). We'd need to add `ScopeFlags::Deleted`, `SymbolFlags::Deleted` and `ReferenceFlags::Deleted` for the transformer to be able to "delete" existing symbols.
2024-08-23 07:52:30 +00:00
overlookmotel
c57e078c71 fix(semantic): transform checker check unbound references (#5093) 2024-08-23 08:37:48 +01:00
heygsc
ad2be97078
fix(semantic): incorrect semantic check for label has same name (#5041)
fix: #5036

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-08-23 10:36:12 +08:00
overlookmotel
d5de97d6fe fix(semantic): transform checker check reference flags (#5092) 2024-08-23 00:21:21 +00:00
overlookmotel
9da6a21e40 refactor(semantic): rename transform checker output for reference symbol mismatches (#5091) 2024-08-22 23:40:27 +00:00
overlookmotel
90c74ee449 fix(semantic): transform checker check reference symbol IDs (#5090)
Previously was checking that references point to symbols with same name, but not necessarily the same symbol (there could be 2 different symbols with same name).
2024-08-22 23:40:26 +00:00
overlookmotel
a8005b9914 fix(semantic): transform checker check symbol redeclarations (#5089) 2024-08-22 23:40:26 +00:00
overlookmotel
205bff7ea9 fix(semantic): transform checker check symbol references (#5088) 2024-08-22 23:40:25 +00:00
overlookmotel
ea7d2163e3 fix(semantic): transform checker check symbol spans (#5076) 2024-08-22 15:08:47 +00:00
overlookmotel
1b6b27a6de fix(semantic): transform checker check symbol flags (#5074) 2024-08-22 15:08:45 +00:00
Boshen
6d87b0f1f2 fix(semantic): fix error message for duplicated label (#5071) 2024-08-22 12:30:04 +00:00
Boshen
afe728a73a feat(parser): parse regular expression with regex parser (#4998)
Many false positives and incorrect errors. @leaysgur Enjoy 😁

Run `just conformance` to update the snapshot.
2024-08-22 03:09:55 +00:00
overlookmotel
05fff16d55 fix(semantic): transform checker compare binding symbol IDs (#5057) 2024-08-22 02:34:44 +00:00
overlookmotel
f187b71877 fix(semantic): transform checker compare scope children (#5056) 2024-08-22 02:34:44 +00:00
overlookmotel
da64014a6c fix(semantic): transform checker catch more scope flags mismatches (#5054)
There was a bug previously where scope flags were only checked if there was also a bindings mismatch.
2024-08-22 02:34:43 +00:00
overlookmotel
67d1a96391 fix(semantic): transform checker compare scope flags (#5052) 2024-08-22 02:34:41 +00:00
overlookmotel
ee7ac8b0b7 refactor(semantic): store all data in PostTransformChecker in transform checker (#5050)
Pure refactor of transform checker. Store all scope data in `PostTransformChecker` so it doesn't need to be passed around. `SemanticData` contains a full set of all semantic data for semantic pass, so we have 2 instances of it for 1. after transform and 2. rebuilt semantic.
2024-08-21 17:04:48 +00:00
overlookmotel
4e1f4abf89 refactor(semantic): add SemanticIds to transformer checker (#5048)
Transformer checker use `SemanticIds` to store collected IDs. `SemanticIds` only contains the IDs, without the `Vec` of errors which is only used temporarily.
2024-08-21 15:49:07 +00:00
overlookmotel
8cded08eb8 refactor(semantic): rename error labels in transformer checker snapshots (#5044)
Rename labels in transformer checker snapshots "after transform" vs "rebuilt".
2024-08-21 14:33:19 +00:00