Commit graph

7229 commits

Author SHA1 Message Date
Boshen
fdf01cfe08
ci: pin lycheeverse/lychee-action@v2.1.0 2024-12-13 19:07:57 +08:00
Boshen
ba84acd5cf
ci: pin github action versions (#7826) 2024-12-13 18:53:16 +08:00
Boshen
befb0a5997
ci: pin oxc-project/setup-rust@1.0.0 (#7834) 2024-12-13 18:45:43 +08:00
Boshen
7610dc19ff fix(parser): parse import source from 'mod' (#7833) 2024-12-13 10:26:36 +00:00
Boshen
e4d040583c
chore(renovate): try extend helpers:pinGitHubActionDigests 2024-12-13 18:24:21 +08:00
Dunqing
0f367e5ab6 refactor(semantic): improve the logic of resolving references to be cleaner (#7829)
fine-tuning the logic, reducing unnecessary calls, and early return if it doesn't resolve. Also, add many comments to describe what code does.
2024-12-13 09:08:44 +00:00
Dunqing
57109507db refactor(semantic): move export-related reference flags logic to visit functions (#7828)
Follow-on after #7812, move setting current references flags to visit functions can reduce some unnecessary upward checking
2024-12-13 09:08:43 +00:00
Yuji Sugiura
40334ba66e
refactor(prettier): Align exported function names to Prettier (#7827)
Some refactoring works to update
https://github.com/oxc-project/oxc/issues/5068#issuecomment-2507272735
table.

- Implement `array::is_consisely_printed_array()` and use it
  - This improved compat-rate a bit ✌🏻 
- Align exported function names to align prettier's
- Split `format/mod.rs` into `js`, `jsx` and `typescript`
- Move `format/*.rs` to `format/print/*.rs`
2024-12-13 17:06:15 +08:00
Boshen
d4b8377841
ci: improve benchmark trigger 2024-12-13 13:50:02 +08:00
Nicholas Rayburn
38b1c2ec65
feat(editor): Create a command to apply all auto-fixes for the current active text editor (#7672)
Ref #7456

- Creates a custom action in the language server that applies all
auto-fixes for a given file.
- Updates VS Code to use the custom action with a command to apply fixes
for the currently active text editor.
2024-12-13 13:46:05 +08:00
Alexander S.
b24a636b0a
ci: add zizmor for github actions security (#7822)
> zizmor is a static analysis tool for GitHub Actions. It can find many
common security issues in typical GitHub Actions CI/CD setups.

https://woodruffw.github.io/zizmor/

EDIT: what is the right PR-syntax for this?

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-12-13 13:36:41 +08:00
overlookmotel
4448b63692 perf(codegen): faster writing indentation (#7820)
Write indentation faster. Previously was writing indentation to buffer with a call to `memset`, which is relatively expensive. Where indentation `<= 16` (common case), write 16 tabs with a single 16-byte XMM write, which is faster.
2024-12-13 05:17:32 +00:00
overlookmotel
14896cb318 fix(transformer/class-properties): create temp vars in correct scope (#7824)
Create `var` temp vars in current *hoist* scope, not current scope.
2024-12-13 04:04:45 +00:00
Yunfei He
9479e2b0a2
fix(semantic): missing references when export {} references a type-only binding and a normal (#7812)
https://playground.oxc.rs/#eNpdTzEOgzAM/AryzFAqdUHq2rlD1YklUIMihTiyTQGh/L0BBEMn31l35/MCDZTQkBfNXmRE3xbHQKzZPSsqX3mcNrZkOgfcJU+mIPmfPEIOBOUCPPh1yOzVTFAqD5iDs14PLA0FPMnc1+QOpmy8tMT9vog5BMOCnAITXkMOfCq3BajhDtMFQLleihskRUMf7HDtkkhvvW3tYU7vKpN7OBpX8xe5JkmVWuMEY4w/P71iMw==

Current:

<img width="876" alt="image"
src="https://github.com/user-attachments/assets/58327920-44ef-469d-8c7c-a2d7b17da717"
/>


Expected:


https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=false&spec=false&loose=false&code_lz=MYewdgzgLgBAKiAhtAagSwKYHcAOIBOsAvDAIwBQ5UAnjhvEtAAr4g4QwkXkYAeehGAG8YNOg2RQWbCABoJqTLgKwAvkA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Ctypescript&prettier=false&targets=&version=7.26.4&externalPlugins=&assumptions=%7B%7D

<img width="877" alt="image"
src="https://github.com/user-attachments/assets/9b847baa-5b5a-43be-b77d-d529fb3f8026"
/>

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-12-13 12:00:58 +08:00
overlookmotel
25bb6daa40 fix(transformer/class-properties): fix ScopeIds in instance prop initializers (#7823)
Code in instance property initializers moves from class body into constructor, or a `_super` function. Update parent `ScopeId`s for first level scopes in initializers.
2024-12-13 03:21:37 +00:00
overlookmotel
e70deb9b48 refactor(transformer/class-properties): locate instance props insertion location in separate step (#7819)
Refactor only. Does not change behavior. Determine where instance prop initializers will need to be inserted in a separate step before instance props are extracted from class.

This achieves nothing in itself, but is preparatory work for transforming initializers to correct their `ScopeId`s and deal with binding clashes.
2024-12-13 02:56:47 +00:00
overlookmotel
65b109a582 fix(transformer/class-properties): no raw for generated StringLiteral (#7825)
Follow-on after #7815. Generated `StringLiteral`s should have `raw: None`.
2024-12-13 02:33:38 +00:00
Dunqing
e727ae9698 feat(transformer/class-properties): transform super member expressions that are inside static prop initializer (#7815)
This PR support for transforming `super.prop` to  `babelHelpers.superPropGet(_B, "prop", _B)`

Input:
```js
class A {
  static prop = 1;
}

class B extends A {
  static prop = 2;
  static propA = super.prop;
  static getPropA = () => super.prop;
}
```

Output:
```js
var _B;
class A {}
babelHelpers.defineProperty(A, "prop", 1);
class B extends A {}
_B = B;
babelHelpers.defineProperty(B, "prop", 2);
babelHelpers.defineProperty(B, "propA", babelHelpers.superPropGet(_B, "prop", _B));
babelHelpers.defineProperty(B, "getPropA", () => babelHelpers.superPropGet(_B, "prop", _B));
```
2024-12-13 02:33:37 +00:00
Dunqing
b290ebd2b0 refactor(transformer): handle <CWD> in test runner (#7799)
We should move the handling of  `<CWD>` to the test runner because this is just only used in testing, and it causes us always get a path by `self.ctx.source_path` like `<CWD>/xxx/xxx.js`, we should get a real path for this.
2024-12-12 17:22:01 +00:00
Boshen
fb325dce99 refactor(ast)!: span field must be the first element (#7821)
For consistency. And maybe a small performance improvement when enum
bytes are aligned.
2024-12-12 16:50:01 +00:00
renovate[bot]
358d375bbd
chore(deps): update rust crates (#7787) 2024-12-12 22:45:45 +08:00
Dunqing
7a832307c2 fix(semantic): missing reference when export default references a type alias binding (#7813)
Fixes: #7809

`ExportNamedDecalration` and `ExportDefaultDeclaration` can reference both type binding and value, so we need to make sure the `ReferenceFlags` is `Read | Type`
2024-12-12 14:12:30 +00:00
Boshen
ed93193c32
chore: bump dprint plugins (#7818) 2024-12-12 22:12:01 +08:00
overlookmotel
8991f33fc7 feat(ast): add visit_span to Visit and VisitMut (#7816)
Add `Visit::visit_span` and `VisitMut::visit_span` methods, to facilitate #7811.

Both are no-ops by default, and marked `#[inline]`, so this produces no performance impact.
2024-12-12 13:33:12 +00:00
overlookmotel
d14d360061 test(transformer): remove dead code from fixtures update script (#7808)
Follow-up after #7771 and #7779. Remove dead code from transformer fixtures updater script.
2024-12-12 09:27:54 +00:00
Dunqing
74bf141b1a chore(tasks/transform-conformance): update only when the output differs from the original output (#7779)
From `5xx` files changed to `3xx`
2024-12-11 16:26:36 +00:00
Dunqing
4d33ffbbc8 chore(tasks/transform-conformance): support --override flag (#7774)
The `--override` flag used to write the output which is generated by the transformer to the `overrides` folder according to the test path. The acting is similar to the previous `takeover` mode
2024-12-11 16:18:16 +00:00
Dunqing
b089e8b519 chore(tasks/transform-conformance): support override to replace takeover mode (#7771)
This PR does the following things.

1. Move the override output of the `snapshots` folder to the `overrides` folder.
2. Support `override` mode to replace `takeover` mode
3. The `update_fixtures.js` no longer uses `overrides`'s `output.js` to replace Babel's `output.js`.

### How does `override` mode work?

When running each test, it checks whether an output file for that test exists in the ⁠`overrides` directory. If it does, the output file will be used to compare with the transformed code.
2024-12-11 16:18:14 +00:00
overlookmotel
450bb334da test(transformer): conformance runner use HelperLoaderMode::External in takeover mode (#7807)
In "takeover" mode, transformer conformance test runner was using `HelperLoaderMode::Runtime`. Switch this to `HelperLoaderMode::External` to match standard test runner mode.
2024-12-11 16:07:01 +00:00
Boshen
afaaffa262 perf(codegen): fast path for options.print_comments() (#7806) 2024-12-11 15:13:30 +00:00
overlookmotel
afc5f1e8b2 refactor(transformer/class-properties): de-deduplicate code (#7805)
Follow-on after #7798. Pure refactor. Include `transform_chain_element_recursively` call once instead of twice.
2024-12-11 14:54:49 +00:00
overlookmotel
47a91d2bdc refactor(transformer/class-properties): shorten code (#7804)
Follow-on after #7798. Pure refactor, just shorten code.

I *think* `expect` has same behavior as `unreachable!` in terms of making the compiler backtrack to try to prove the check can be elided. But in this case, I doubt it can prove it either way.
2024-12-11 14:54:49 +00:00
overlookmotel
54ef2b9e18 refactor(transformer/class-properties): rename debug_assert_expr_is_not_parenthesis_or_typescript_syntax (#7803)
Rename function to make it completely clear what it does.
2024-12-11 14:54:49 +00:00
overlookmotel
3cdc47cb0d refactor(transformer/class-properties): #[inline(always)] on assert_expr_neither_parenthesis_nor_typescript_syntax (#7802)
Follow-on after #7795. Add `#[inline(always)]` to this function which is no-op in release mode, to make absolutely sure it gets optimized out in full.
2024-12-11 14:54:48 +00:00
Dunqing
2964a61546 fix(transformer/class-properties): unwrap failed when private field expression doesn't contain optional expression in ChainExpression (#7798)
The root cause is due to transform wrongly a PrivateFieldExpression that doesn't contain any optional expression, so call `to_member_expression_mut` causes unwrap to fail.  I have fixed the incorrect transform and changed `to_member_expression_mut` to `as_member_expression_mut`.
2024-12-11 11:32:21 +00:00
Dunqing
6fa6785d0d fix(transformer/class-properties): panic when the callee or member is ParenthesisExpression or TS-syntax expressions. (#7795)
We need to call `get_inner_expression_mut` to get actual expressions that we need to deal with
2024-12-11 11:15:20 +00:00
camc314
38ba2f640c chore(linter): remove some unused commented code (#7800) 2024-12-11 08:55:21 +00:00
Nicholas Rayburn
06e6d387fa
fix(linter): Fix unicorn/prefer-query-selector to use the correct replacement for getElementsByClassName (#7796)
Note: This uses a regex to replace multiple instances of whitespace with
` .`. May not be the most performant, so if there's a simple alternative
I can change to that instead.

cc @camc314, I know this was assigned to you but I just wanted to throw
something quick together while I had a minute. Feel free to use this, or
decline it and write your own.

Fixes #7794.

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-12-11 16:49:40 +08:00
overlookmotel
bb22c67974 fix(transformer/class-properties): fix ScopeIds in static prop initializers (#7791)
Code in static property initializers moves from inside the class to outside. Update parent `ScopeId`s for first level scopes in initializers.
2024-12-11 03:18:29 +00:00
Dunqing
4a524ed150 chore(transformer): support passing babel options path in example (#7790)
Sometimes we want to use Babel test's options to test some code, If the example can get the TransformerOptions from Babel options, then we can easily do it
2024-12-11 00:33:22 +00:00
overlookmotel
caa57f1649 fix(transformer/class-properties): fix scope flags in static prop initializers (#7786)
Code in static property initializers moves from inside the class to outside. If environment outside the class is not strict mode, then scopes within the initializer become sloppy mode. Update `ScopeFlags` for scopes in static prop initializers accordingly.

We're following Babel for now, but this isn't actually correct. The initializers should be wrapped in a strict mode IIFE to maintain their strict mode behavior. But at least semantic data is now correct for the output.
2024-12-10 23:57:43 +00:00
overlookmotel
4a3bca8354 fix(semantic): fix identifying strict mode arrow functions (#7785)
Semantic analysis was not marking an arrow function containing a `"use strict"` directive as `ScopeFlags::StrictMode`. Fix that.
2024-12-10 23:57:42 +00:00
overlookmotel
f7900ab246 feat(ast): add ArrowFunctionExpression::has_use_strict_directive method (#7784)
Add `ArrowFunctionExpression::has_use_strict_directive` method to go with `Function::has_use_strict_directive` etc.
2024-12-10 23:57:41 +00:00
overlookmotel
96a26d3b29 refactor(ast)!: rename is_strict methods to has_use_strict_directive (#7783)
The name `is_strict` was misleading for these methods, because it doesn't tell you if the e.g. function *is* strict mode, only whether it contains a `"use strict"` directive. `Function::is_strict` might return `false` for a function which does have strict mode semantics because it's e.g. in an ESM file.

Rename these methods to `has_use_strict_directive` to better reflect what they do.

For `Program`, change the method to only check for `"use strict"` directive and not to look at `source_type`. `Semantic` should be the source of truth on strict/sloppy mode of AST nodes. It's cheaper to look up the `ScopeFlags` than to iterate over `directives`, so don't encourage this anti-pattern by providing a "rival" method.
2024-12-10 23:57:40 +00:00
oxc-bot
bde753b4ee
release(oxlint): v0.15.0 (#7782)
## [0.15.0] - 2024-12-10

- 39b9c5d linter: [**BREAKING**] Remove unmaintained security plugin
(#7773) (Boshen)

### Features

- 065f7dc linter: Support `expectTypeOf`, `assert` and `assertType` in
`vitest/expect-expect` (#7742) (Yuichiro Yamashita)
- 3d5f0a1 linter/no_restricted_imports: Add the no_restricted_imports
rules (#7629) (Guillaume Piedigrossi)

### Bug Fixes

- ad27b20 linter: Only resolve esm files for import plugin (#7720)
(Boshen)
- 5e6053f linter: False positive in `eslint/yoda` (#7719) (dalaoshu)

### Refactor

- c6a19aa linter: Remove unused `serde` features (#7738) (Boshen)
- b9a2b35 linter: Remove `aho-corasick` (#7718) (Boshen)

### Testing

- 62f0a22 linter: Port `react-jsx-uses-vars` rules to no_unused_vars
(#7731) (Tyler Earls)
- 02f9903 linter: Add regression tests for `import/namespace` (#7723)
(dalaoshu)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-11 00:58:03 +08:00
oxc-bot
bd572c609b
release(crates): v0.40.1 (#7781)
## [0.40.1] - 2024-12-10

### Bug Fixes

- 18d0ce3 napi: Rename `Error` to `OxcError` to avoid name collision
(#7780) (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-11 00:35:34 +08:00
Boshen
18d0ce3c06
fix(napi): rename Error to OxcError to avoid name collision (#7780) 2024-12-11 00:30:07 +08:00
overlookmotel
4f1ab49440 test(transformer/class-properties): add output.js files to override fixtures (#7777)
In two of the overridden text fixtures for class properties transform, there was no `output.js` file because what was overridden was just `options.json` and `update_fixtures.js` script then generated new output files using Babel with the new options.

That was fine, but doesn't work with #7771. So add `output.js` files to the these overrides too.
2024-12-10 15:25:39 +00:00
oxc-bot
6768f7ded2
release(crates): v0.40.0 (#7775) 2024-12-10 23:04:43 +08:00
overlookmotel
3629a91c4c
docs(napi): fix typo (#7776) 2024-12-10 15:01:26 +00:00