Commit graph

5325 commits

Author SHA1 Message Date
dalaoshu
bc7be70077
chore(linter/react_perf): improve docs for react_perf rules (#5481)
Please fill in the "why this is bad" section

_Originally posted by @DonIsaac in
https://github.com/oxc-project/oxc/pull/5360#discussion_r1739617907_
2024-09-05 09:20:55 -04:00
overlookmotel
bfab0914fa perf(transformer): store needed options only on RegExp (#5484)
#5482 makes most of the `RegExpOptions` not be needed outside `new` method. So only store the remaining options which are actually needed on `RegExp`. This reduces size of `RegExp`.

(this is micro-optimization, and unlikely to make a measurable difference, but why not?)
2024-09-05 12:47:36 +00:00
overlookmotel
b4765af82a perf(transformer): pre-calculate if unsupported patterns in RegExp transform (#5483)
Similar to #5482. Calculate whether any unsupported RegExp patterns at start, to make checking if need to check for patterns cheaper (a single comparison operation, rather than 3 comparisons and ORs).
2024-09-05 12:47:35 +00:00
overlookmotel
182ab91570 perf(transformer): pre-calculate unsupported flags in RegExp transform (#5482)
Calculate unsupported RegExp flags at start, to make checking flags on each RegExp during traversal cheaper (a single OR operation). i.e. do work once at the start, rather than over and over each time you find a `RegExp`.
2024-09-05 12:47:34 +00:00
Dunqing
2514cc92e5 refactor(transformer/react): move all entry points to implementation of Traverse trait (#5473) 2024-09-05 11:04:45 +00:00
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
Boshen
d9d29f8705
ci: fix pr.yml
closes #5477
2024-09-05 18:09:40 +08:00
Boshen
3cbf9ef70a
ci: add release to pr title check (#5475) 2024-09-05 17:10:12 +08:00
IWANABETHATGUY
91b39c4b82 feat(oxc_diagnostic): impl DerefMut for OxcDiagnostic (#5474)
1. Impl `DerefMut` for `OxcDiagnositc` so downstream user could move `OxcDiagnostic` rather clone it,
40ae24d597/crates/rolldown_ecmascript/src/ecma_compiler.rs (L36-L48)
2024-09-05 08:55:52 +00:00
rzvxa
9b984b31bd fix(regex): panic on displaying surrogated UnicodeEscape characters. (#5469)
fixes https://github.com/oxc-project/oxc/pull/5387#issuecomment-2330534180
2024-09-05 06:18:11 +00:00
rzvxa
0df1d9d97b fix(ast, codegen, linter): panics in fixers. (#5431)
Closes #5434

https://github.com/oxc-project/oxlint-ecosystem-ci/actions/runs/10685877915/job/29619941099
2024-09-05 05:59:22 +00:00
rzvxa
9f6e0ed099 refactor(ast): simplify ContentEq trait definition. (#5468)
Addresses the concerns brought up in #5427
2024-09-05 05:36:51 +00:00
rzvxa
ccc8a27e4f refactor(ast, ast_tools): use full method path for generated derives trait calls. (#5462)
As of now if we remove the implementation of a trait for a type and implement the method on that type directly it wouldn't break while it isn't the original trait anymore so that method might do something entirely different.
This change is more explicit on trait calls so we hit compile errors on these kinds of changes.
2024-09-05 05:36:50 +00:00
rzvxa
90facd3657 feat(ast): add ContentHash trait; remove noop Hash implementation from Span (#5451)
closes #5283

Also removes the noop Hash implementation on `Span` in favor of a real implementation.
2024-09-05 07:20:04 +03:30
mysteryven
5187f384cb fix(linter/tree-shaking): detect the correct export symbol resolution (#5467)
fixes: #5455
2024-09-05 03:05:46 +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
overlookmotel
82c0a167c4 fix(linter): tree_shaking/no_side_effects_in_initialization handle JSX correctly (#5450)
#5223 altered `JSXElementName` so `JSXElementName::Identifier` is used only for non-reference JSX names (e.g. `<div>`). `JSXElementName::IdentifierReference` is used where the name is a reference (e.g. `<Foo>`). Similarly `JSXMemberExpressionObject`'s `object` is always an `IdentifierReference` now.

So, the net result is that `JSXIdentifier` is now never a reference, it's just the JSX equivalent of `IdentifierName`. So I don't think `JSXIdentifier` can ever have side-effects.

This PR:

1. Removes `impl ListenerMap for JSXIdentifier`
2. Adds `impl ListenerMap for JSXMemberExpression` and makes sure the root `IdentifierReference` (`Foo` in `<Foo.bar.qux>`) is visited.
2024-09-05 02:06:19 +00:00
Dunqing
e4ed41d4fa refactor(semantic): change the reference flag to ReferenceFlags::Type if it is used within a TSTypeQuery (#5444)
So far, the `ReferenceFlags::TSTypeQuery` only used indicates it is referenced by `TSTypeQuery` that we can confirm the reference should be regarded as a type reference, namely `ReferenceFlags::Type`.

This PR adds a `ReferenceFlags::ValueAsType` instead of `ReferenceFlags::TSTypeQuery`.  The new flag has the same behavior as the previous one. But it looks more general and is not only used in `TSTypeQuery`. But now it is a temporary flag. We use it to resolve the symbol correctly and replace `ReferenceFlags::ValueAsTyoe` with `ReferenceFlags::Type` after resolved.

Also, this change eliminates the inconsistency in behavior between the `Reference::is_type` and `ReferenceFlags::is_type` methods.
2024-09-05 01:50: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
overlookmotel
87c5df2226 refactor(ast)!: rename Expression::without_parentheses (#5448)
Rename `without_parenthesized` to `without_parentheses`. Both are hard-to-spell words, but "without parenthesized" does not make sense.
2024-09-05 01:25:00 +00:00
overlookmotel
a43e9512f3 refactor(ast): use loop instead of recursion (#5447)
Use loop instead of recursive function call. Loops are usually cheaper.
2024-09-05 01:24:59 +00:00
overlookmotel
6285a02274 fix(linter): eslint/radix rule correctly check for unbound symbols (#5446)
`SymbolTable::get_symbol_id_from_name(name).is_none()` is not always correct, because it will return `false` if there is a binding *anywhere* in the AST with that name, whereas what we actually want to know is whether *this* `IdentifierReference` is referring to a global or not.

Instead, look up whether this reference is resolved or not using `SymbolTable::is_global_reference`.

The 3 test cases added were not working prior to this change.
2024-09-05 01:18:24 +00:00
overlookmotel
2224cc4e62 refactor(ast): renumber JSXMemberExpressionObject discriminants (#5464)
Number discriminants starting at 0, not 1. This likely makes no difference, but starting numbering at 1 seems odd.
2024-09-04 22:59:53 +00:00
overlookmotel
a952c47265 refactor(ast): use loop not recursion (#5449)
`Expression::get_inner_expression` and `Expression::get_inner_expression_mut` use a loop rather than recursive function calls. Loops are usually cheaper.
2024-09-04 20:24:45 +00:00
overlookmotel
1d3e973f10 refactor(linter): simplify eslint/radix rule (#5445)
Refactor to remove duplicate logic.
2024-09-04 16:52:27 +00:00
Boshen
9c937e06e8 fix(benchmark): do not measure initialization of transformer options (#5442)
relates #5267
2024-09-04 14:52:21 +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
rzvxa
fdb8857630 refactor(linter): use "parsed pattern" in no_div_regex rule. (#5417)
Part of #5416, Paves the road for upcoming refactors by adding the `oxc_regular_expression` dependency and a helper method for ease of access.
2024-09-04 14:00:47 +00:00
Jelle van der Waa
aff2c71423
feat(linter/react): implement self-closing-comp (#5415)
Rule Detail:


[link](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-09-04 10:00:23 -04:00
Boshen
ba4b68cf63 feat(minifier): remove parenthesized expression for dce (#5439)
relates #5436
2024-09-04 12:58:39 +00:00
overlookmotel
d9d7e7c596 refactor(ast): remove IdentifierName from TSThisParameter (#5327)
`TSThisParameter` does not need to include an `IdentifierName` which is always "this". Just storing the `Span` is sufficient.
2024-09-04 12:46:53 +00:00
Jelle van der Waa
81709549d9
perf(linter/react): add should_run conditions for react rules (#5402) 2024-09-04 08:37:15 -04:00
dalaoshu
f89c776ac4
chore(linter/vitest): improve docs for vitest rules (#5428) 2024-09-04 08:29:57 -04:00
rzvxa
23285f431d feat(ast): add ContentEq trait. (#5427)
Part of #5283
2024-09-04 11:53:50 +00:00
Dunqing
c78291600e feat(codegen): print type_parameters in TaggedTemplateExpression (#5438) 2024-09-04 11:24:04 +00:00
IWANABETHATGUY
caf800700d
chore(justfile): bundle wasm with different flag (#5433)
1. wasm-pack with release flag will increase wasm bundling time, which
hurts dx when developing playground.
2. only enable `release` flag when `build-wasm`.
2024-09-04 13:30:48 +08:00
Boshen
f7f63bc3e2
chore(README): update playground link 2024-09-04 12:18:24 +08:00
Boshen
cd0516752c
chore(justfile): build-wasm should build in prod 2024-09-04 08:58:14 +08:00
overlookmotel
e7bd49dae4 refactor(regular_expression): correct typo (#5429)
Just correct a misspelling.
2024-09-04 00:54:22 +00:00
Dunqing
c984219e06 refactor(transformer/typescript): move all entry points to implementation of Traverse trait (#5422) 2024-09-03 18:26:20 +00:00
Dunqing
0617249716 fix(transformer/nullish-coalescing-operator): incorrect reference flags (#5408)
Fixes an obvious problem
2024-09-03 15:29:07 +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
b9ef357868 test(transformer): add tests for nested JSX this member expressions in arrow function transform (#5413)
Follow-up after #5356. Handle nested JSX member expressions with `this` as base object in arrow functions transform (e.g. `<this.foo.bar />`).
2024-09-03 15:06:06 +00:00
Boshen
51b15ca143
ci: set show-progress: false in clone-submodules 2024-09-03 22:03:34 +08:00
overlookmotel
bfabd8facc perf(syntax): further optimize is_identifier_name (#5426)
Follow-on after #5425. Further optimize `oxc_syntax::identifier::is_identifier_name` by processing string in blocks of 8 bytes, and checking if all bytes in a block are ASCII in one go, rather than testing each byte individually.
2024-09-03 13:48:36 +00:00
overlookmotel
aeda84f904 perf(syntax): optimize is_identifier_name (#5425)
Optimize `oxc_syntax::identifier::is_identifier_name`. Add a fast path for ASCII, which will be the common case. Only fall back to iterating over `char`s and using the more expensive test functions e.g. `is_identifier_start_unicode` if non-ASCII chars are found.
2024-09-03 12:48:32 +00:00