Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
jinx-rust
is a Rust parser written in Typescript.
npm install jinx-rust
import { rs } from "jinx-rust";
const file = rs.parseFile(`let foo: u8 = 1;`);
console.log(JSON.stringify(file));
{
"type": "SourceFile",
"program": {
"type": "Program",
"ast": [
{
"type": "LetVariableDeclaration",
"pattern": { "type": "Identifier", "name": "foo" },
"typeAnnotation": { "type": "Identifier", "name": "u8" },
"expression": { "type": "Literal", "kind": 11, "value": "1" }
}
],
"danglingAttributes": [],
"comments": []
}
}
Though eventually there should be a strict
parser option to validate the AST,
jinx-rust
is unstrict by default and tolerates many things:
match
and declarations===
and !==
const
declarations)parameter.typeAnnotation
)import { rs } from "jinx-rust";
// Would not parse in Rust or syn
const arg_0 = rs.parseFile("fn foo(arg_0) {}").program.ast[0].parameters[0];
assert(arg_0.typeAnnotation.type === "MissingNode");
Attributes and Macro invocation arguments are returned as tokens in rs.parseFile
.
rs
exposes other methods to re-read tokens in arbitrary contexts, or to re-read nodes as tokens.
import { rs, MacroInvocation } from "jinx-rust";
const node = rs.parseFile("foo!(123);").program.ast[0].expression as MacroInvocation;
// ExpressionNode[]
const args = rs.toCallExpressionArguments(node.tokens).ast;
// StatementNode[]
const block = rs.toBlockBody(node.tokens).ast;
// TokenNode[]
const tokens = rs.toTokens(node).ast;
"jinx-rust/utils"
jinx-rust/utils
is automatically included on install. It is a library of (mostly) auto-generated helpers from the parser's type declarations. Like each_node
traversing, or is_{NodeType}
functions for every node type, and is_{Type}
for every type exported by the parser.
import { each_node, is_StatementNode } from "jinx-rust/utils";
declare const target: Node;
each_node(target, (child, parent) => {
if (is_StatementNode(child)) {
// gets called for every statement in target
}
});
jinx-rust
node.loc.ownStart
import { Node } from "jinx-rust";
import { start, end, ownStart, has_OuterAttributes, hasOwnStart } from "jinx-rust/utils";
declare const node: Node;
start(node) === node.loc[0]; end(node) === node.loc[1];
has_OuterAttributes(node) === hasOwnStart(node);
ownStart(node) === (node.loc.ownStart ?? node.loc[0]);
jinx-rust
0.1.4
Initial release
FAQs
Rust parser
The npm package jinx-rust receives a total of 1,183 weekly downloads. As such, jinx-rust popularity was classified as popular.
We found that jinx-rust demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.