Registry / type-stubs / jinx-rust

jinx-rust

JSON →
library0.1.6jsnpmunverified

jinx-rust is a JavaScript/TypeScript library that provides a tolerant parser for the Rust programming language, enabling the development of Rust-specific tooling in TypeScript. As of version 0.1.6, it focuses on being unstrict by default, allowing it to parse malformed or incomplete Rust syntax, which is beneficial for IDEs and linters that need to work with in-progress code. Its release cadence is frequent, with several minor updates addressing parsing fixes since its initial release. A key differentiator is its built-in tolerance for common syntax errors (e.g., missing semicolons, specific Javascript-like operators) and support for 23 Rust nightly features. It also provides a utility sub-package, `jinx-rust/utils`, for common AST traversal and type-checking operations.

npm install jinx-rust
INSTALL
IMPORT
SIG · JINX-RUST
J
jinx-rust
type-stubsjavascriptv0.1.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rs
import { rs } from 'jinx-rust';
import rs from 'jinx-rust';
`rs` is the primary parser instance and is a named export. The package primarily uses ESM.
MacroInvocation
import type { MacroInvocation } from 'jinx-rust';
import { MacroInvocation } from 'jinx-rust';
For type-only imports, use `import type` to avoid unnecessary runtime imports and improve tree-shaking.
each_node
import { each_node } from 'jinx-rust/utils';
import { each_node } from 'jinx-rust';
Utility functions like `each_node` and `is_StatementNode` are found under the `jinx-rust/utils` sub-path.

Demonstrates parsing a simple Rust `let` declaration and logging its Abstract Syntax Tree (AST) structure.

import { rs } from "jinx-rust"; const file = rs.parseFile("let leet: u32 = 1337;"); console.log(JSON.stringify(file, null, 2)); // Expected output (simplified): // { // "type": "SourceFile", // "program": { // "type": "Program", // "ast": [ // { // "type": "LetVariableDeclaration", // "pattern": { "type": "Identifier", "name": "leet" }, // "typeAnnotation": { "type": "Identifier", "name": "u32" }, // "expression": { "type": "Literal", "kind": 11, "value": "1337" } // } // ], // "danglingAttributes": [], // "comments": [] // } // }
Debug
Known issues
gotchaThe parser is unstrict by default and tolerates malformed syntax, producing an AST even for invalid code. This design choice aims to support IDE-like tooling but may yield unexpected AST structures if strict adherence to Rust grammar is expected. A `strict` option is planned for future releases.
fix
Always inspect the generated AST for `MissingNode` or `ErrorNode` types to handle parsing inconsistencies. Be aware that the AST might not reflect perfectly valid Rust.
affects: >=0.1.4
gotchaNode location (`node.loc`) expands to include any preceding outer attributes, which might not always correspond to the precise start of the node itself. The exact node start is available at `node.loc.ownStart`.
fix
Prefer using location helpers from `jinx-rust/utils` like `start(node)` for consistent location access, or explicitly use `node.loc.ownStart` when only the node's internal start is needed.
affects: >=0.1.4
gotchaAttributes and Macro invocation arguments are initially returned as raw tokens within the AST. To convert these tokens into full AST nodes, developers must explicitly call `rs.toCallExpressionArguments(tokens)` or `rs.toBlockBody(tokens)`.
fix
After parsing, if you need a deeper AST for macro arguments or attributes, remember to re-process their token arrays using the appropriate `rs` methods.
affects: >=0.1.4
breakingAs `jinx-rust` is currently in an early `0.x.x` release phase, API stability is not guaranteed. Breaking changes, while not explicitly called out in patch notes yet, should be anticipated in minor or even patch versions as the library evolves.
fix
Pin exact package versions (e.g., `"jinx-rust": "0.1.6"` instead of `"^0.1.6"`) and carefully review release notes for any updates. Consider waiting for a `1.0.0` release for higher stability in production environments.
affects: >=0.1.4
Errors
Common errors & fixes
TypeError: (0 , jinx_rust_1.rs) is not a function
`rs` is a named export, not a default one, and `jinx-rust` primarily uses ES Modules (ESM).
fix
Ensure you are using ES module imports: `import { rs } from 'jinx-rust';`. If in a CommonJS environment, check your build configuration for ESM interoperability or consider using a bundler.
Property 'parameters' does not exist on type 'LetVariableDeclaration'.
Attempting to access properties that do not exist on a given AST node type without proper TypeScript type narrowing.
fix
Utilize type guards or the `is_NodeType()` helpers from `jinx-rust/utils` (e.g., `if (is_FunctionDeclaration(node)) { node.parameters; }`) to narrow down the node type before accessing specific properties.
Unexpected AST output containing 'MissingNode' or 'ErrorNode' types.
The tolerant parser encountered syntax it couldn't fully parse into a concrete node, inserting a `MissingNode` placeholder rather than throwing an error.
fix
Check for `MissingNode` or `ErrorNode` types in the AST, especially when parsing potentially malformed code. Implement logic to gracefully handle or report these missing nodes, understanding that the AST is incomplete at that point.
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
jinx-rust — npm install jinx-rust · libregistry