{"id":13387,"library":"jinx-rust","title":"Rust Parser for TypeScript","description":"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.","status":"active","version":"0.1.6","language":"javascript","source_language":"en","source_url":"https://github.com/jinxdash/jinx-rust","tags":["javascript","rust","parser","AST","IDE","typescript"],"install":[{"cmd":"npm install jinx-rust","lang":"bash","label":"npm"},{"cmd":"yarn add jinx-rust","lang":"bash","label":"yarn"},{"cmd":"pnpm add jinx-rust","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"`rs` is the primary parser instance and is a named export. The package primarily uses ESM.","wrong":"import rs from 'jinx-rust';","symbol":"rs","correct":"import { rs } from 'jinx-rust';"},{"note":"For type-only imports, use `import type` to avoid unnecessary runtime imports and improve tree-shaking.","wrong":"import { MacroInvocation } from 'jinx-rust';","symbol":"MacroInvocation","correct":"import type { MacroInvocation } from 'jinx-rust';"},{"note":"Utility functions like `each_node` and `is_StatementNode` are found under the `jinx-rust/utils` sub-path.","wrong":"import { each_node } from 'jinx-rust';","symbol":"each_node","correct":"import { each_node } from 'jinx-rust/utils';"}],"quickstart":{"code":"import { rs } from \"jinx-rust\";\n\nconst file = rs.parseFile(\"let leet: u32 = 1337;\");\n\nconsole.log(JSON.stringify(file, null, 2));\n\n// Expected output (simplified):\n// {\n//   \"type\": \"SourceFile\",\n//   \"program\": {\n//     \"type\": \"Program\",\n//     \"ast\": [\n//       {\n//         \"type\": \"LetVariableDeclaration\",\n//         \"pattern\": { \"type\": \"Identifier\", \"name\": \"leet\" },\n//         \"typeAnnotation\": { \"type\": \"Identifier\", \"name\": \"u32\" },\n//         \"expression\": { \"type\": \"Literal\", \"kind\": 11, \"value\": \"1337\" }\n//       }\n//     ],\n//     \"danglingAttributes\": [],\n//     \"comments\": []\n//   }\n// }","lang":"typescript","description":"Demonstrates parsing a simple Rust `let` declaration and logging its Abstract Syntax Tree (AST) structure."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.4"},{"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.","message":"Node 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`.","severity":"gotcha","affected_versions":">=0.1.4"},{"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.","message":"Attributes 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)`.","severity":"gotcha","affected_versions":">=0.1.4"},{"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.","message":"As `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.","severity":"breaking","affected_versions":">=0.1.4"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"`rs` is a named export, not a default one, and `jinx-rust` primarily uses ES Modules (ESM).","error":"TypeError: (0 , jinx_rust_1.rs) is not a function"},{"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.","cause":"Attempting to access properties that do not exist on a given AST node type without proper TypeScript type narrowing.","error":"Property 'parameters' does not exist on type 'LetVariableDeclaration'."},{"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.","cause":"The tolerant parser encountered syntax it couldn't fully parse into a concrete node, inserting a `MissingNode` placeholder rather than throwing an error.","error":"Unexpected AST output containing 'MissingNode' or 'ErrorNode' types."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}