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`
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.
> 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>
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.
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.
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.
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));
```
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.
Fixes: #7809
`ExportNamedDecalration` and `ExportDefaultDeclaration` can reference both type binding and value, so we need to make sure the `ReferenceFlags` is `Read | Type`
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.
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
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.
In "takeover" mode, transformer conformance test runner was using `HelperLoaderMode::Runtime`. Switch this to `HelperLoaderMode::External` to match standard test runner mode.
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.
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`.
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>
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
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.
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.
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.