Follow-on after #12801.
Remove the custom serializer for `TSImportTypeQualifier`. All we need is to rename `TSImportTypeQualifiedName` to `TSQualifiedName`, so we can use `#[estree(rename = "TSQualifiedName")]`, and let the codegen do the rest.
We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`.
The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again.
After #12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all.
So we can remove the whole field.
This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more!
It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal!
(alternative to #12803)
Compile NAPI tests in debug mode (not release mode), to speed up build in CI.
Only exception is `napi/parser` which is compiled with `--profile coverage`. The tests for this package are quite slow, so they'd take too long if package was compiled with no optimizations. `coverage` profile is closer to `--release`, but enables debug assertions, and has somewhat faster compilation (`-O 2` not `-O 3` etc).
In CI:
* Build time reduced by 1m30s.
* Test run time increased by 30s.
* Total reduction in CI time: 1 minute.
NAPI tests are still the slowest task in CI by a long margin. Trimming a minute off the time is something, but this task is still too slow.
In tests for `napi/parser`, don't assume `target` dir exists. It generally should, because you'll have built the `.node` binary. But it `cargo clean` will remove it, and it can also not exist on CI if running build and test in separate jobs.
`WithClause` keyword can only be one of 2 words - `with` or `assert`.
We don't need `Span` for this symbol, so using `IdentiferName` (24 bytes) is overkill. Just use an enum `WithClauseKeyword` (1 byte).
This also has the benefit of constraining the keyword to valid values - prevents creating an invalid AST which would be printed as e.g. `import foo from "source" TROUSERS {};`.
In the absence of benchmarks, I don't know for sure that this is a perf improvement. But I assume so.
`if (exit)` requires coercion of `exit` to a boolean, whereas `if (exit !== null)` is a simpler check - comparison to a single known constant.
Once we have reliable benchmarking set up for raw transfer, we can revisit and tweak the code in many ways, but I think in the meantime this change is *probably* an improvement.
Refactor to oxlint JS plugins and raw transfer. Remove source text length field from `RawTransferMetadata`. It's not necessary - source text is part of `Program`, so the length can be obtained from there, it doesn't need to be duplicated.
Add a field `source_len` to `RawTransferData`, which stores the byte length of source text.
In `napi/parser`, this wasn't required, as the source text is passed in from JS side, so JS already knows how long it is. But in linter, source text passes in the opposite direction, so Rust needs to tell JS it's length. It will do so by recording it in this field, and JS reads it from the buffer.
`RawTransferMetadata` is used to store basic info about the data in the buffer which is used on JS side to locate `Program` in the buffer etc.
This struct lives in `napi/parser` crate but we're going to need it in `napi/oxlint2` too. So make a 2nd copy of it in `napi/oxlint2` and use `oxc_ast_tools` to enforce that the 2 copies are identical.
This is a bit of a hack, but it doesn't seem worthwhile creating a new crate just to hold this one struct, and it doesn't really fit in `oxc_allocator`, or any of our other existing crates.
Fixed size allocator pool give each `Allocator` a unique ID and store it in `FixedSizeAllocatorMetadata` struct at end of the buffer. This prepares the way for sharing buffers created on Rust side with JS while avoiding use-after-free or double-free.
`FixedSizeAllocator`s allocate a block of memory larger than what the `Allocator` controls, and often with a different start pointer. So when `FixedSizeAllocator` is dropped, it needs to deallocate that block of memory using the original pointer.
That pointer way previously stored in `FixedSizeAllocator` itself. Instead store it in a `FixedSizeAllocatorMetadata` struct, which is written into the memory block itself, after the section controlled by the `Allocator`, and other metadata (`RawTransferMetadata`).
This allows getting the original `alloc_ptr` when you only have access to the `Allocator`, but not the `FixedSizeAllocator`.
Correct comment for `get_buffer_offset` (used by raw transfer) about buffer size, and add an additional rounding down. The latter makes no difference because the offset is truncated to `u32` straight after anyway, but better to code defensively in case we change buffer size / alignment later on.
`FixedSizeAllocator` create an inner `Allocator` 16 bytes smaller than the buffer size. The last 16 bytes will be used to store `RawTransferMetadata` (offset of the AST data etc). This prepares `FixedSizeAllocator` for use with raw transfer for JS linter plugins.
Reduce the size of the buffer used for raw transfer by 16 bytes so that there's 16 bytes space for `malloc`'s metadata without committing another memory page. I don't know for sure that `malloc` would store metadata in the allocation for allocations this large, but this is what Bumpalo does, so it's probably a good idea.
Pure refactor. Introduce a `RawTransferMetadata` struct to hold metadata that gets written to end of buffer. Codegen use knowledge of memory layout of this struct to generate constants added in #12268. This is more robust than manually calculating offsets.
Similar to #12268. Instead of hard-coding the size and alignment of raw transfer buffers in multiple places, codegen add these to generated files, and everywhere else import the values from those files. This is more robust.
Pure refactor. Instead of hard-coding constants for fixed offsets of data in the buffer, generate these constants in one place and import them from `constants.js` everywhere else.
Small optimization to raw transfer. Move check that running on a supported platform out of `prepareRaw` function (which runs on every call to `parseSync`) to top level (so we only do the check once). This module is lazy-loaded if user calls `parseSync` with `experimentalRawTransfer`, so the check won't run if user is not using raw transfer.
Reduce size of `oxc-parser` WASM binary by omitting code for raw transfer. Raw transfer is not supported on WASM.
This also allows removing the workaround to prevent compilation failure on 32-bit systems due to `1 << 32` overflowing `usize`. This code is no longer compiled on 32-bit systems.
Pure refactor. `constructors.js` export a statically-constructed object, rather than adding properties to an initially empty object. This should make it faster for JS engine to fetch properties of that object.
Pure refactor. Remove `construct` function, and instead construct `RawTransferData` class in the call site. `constructors.js` can now only export an object containing the constructor classes.