Fixes https://github.com/denoland/deno/issues/27062
In the LSP we were passing `npm` specifiers to TSC as roots, but TSC
needs fully resolved specifiers (like the actual file path).
In `deno check` we were often excluding the specifiers entirely from the
roots.
In both cases, we need to resolve the specifiers fully and then pass
them to tsc
This PR changes the underlying buffer backed AST format we use for
JavaScript-based linting plugins. It adds support for various new types,
makes traversal code a lot easier and is more polished compared to
previous iterations.
Here is a quick summary (in no particular order):
- Node prop data is separate from traversal, which makes traversal code
so much easier to reason about. Previously, it was interleaved with node
prop data
- spans are in a separate table as well, as they are rarely needed.
- schema is separate from SWC conversion logic, which makes
- supports recursive plain objects
- supports numbers
- supports bigint
- supports regex
- adds all SWC nodes
Apologies, this is kinda a big PR, but it's worth it imo.
_Marking as draft because I need to update some tests tomorrow._
Fixes https://github.com/denoland/deno/issues/25762. Note that some of
the things in that issue are not resolved (vite/client types not working
properly which has other root causes), but the wildcard module
augmentation specifically is fixed by this.
We were telling TSC that files with unknown media types had an extension
of `.js`, so the ambient module declarations weren't applying. Instead,
just don't resolve them, so the ambient declaration applies.
The selector splitting code that's used for JS linting plugins didn't
properly account for selectors being a single character. This can happen
in the case of `*`.
Instead of comparing against the length, we'll now check if the
remaining string portion is not empty, which is more robust. It also
allows us to detect trailing whitespace, which we didn't before.
Instead of hard erroring, we now surface module not found errors as
TypeScript diagnostics (we have yet to show the source code of the
error, but something we can improve over time).
Addresses the review feedback in
https://github.com/denoland/deno/pull/27416 .
- Hoist the buffer max size variable to make it less confusing
- Remove manual AST field counter in favour of an explicit "commit
schema" step which writes the actual field count.
When running selectors for JS linting plugins we would error when
encountering an unknown attribute name:
```js
// selector
Foo[non-existant]
// error
Error: Missing string id: <number>
```
This was caused by using `0` as the invalid marker, but also overloading
`0` with an actual node type. So the fix is to reserve `0` as the
invalid marker and move the property type to the next index.
This PR extracts the core part of
https://github.com/denoland/deno/pull/27203 to make it easier to review
and land in parts.
It contains:
- The JS plugin code the deserializes and walks the buffer
- The Rust portion to serialize SWC to the buffer format (a bunch of
nodes are still todos, but imo these can land anytime later)
- Basic lint plugin types, without the AST node types to make this PR
easier to review
- Added more code comments to explain the format etc.
More fixes and changes will be done in follow-up PRs.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>