Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ts-simple-ast
Advanced tools
TypeScript Compiler API wrapper. Provides a simple way to navigate and manipulate TypeScript and JavaScript code.
v10.2.0 will have some massive performance improvements in some scenarios. If you notice any bugs due to this change then please let me know by opening an issue.
View information on breaking changes in breaking-changes.md.
This library is still under early active development. Most common code manipulation/generation use cases are implemented, but there's still a lot of work to do.
Please open an issue if find a feature missing or bug that isn't in the issue tracker.
View a generated report on what nodes have been wrapped in the wrapped-nodes.md file.
Work in progress: https://dsherret.github.io/ts-simple-ast/
import Project from "ts-simple-ast";
// initialize
const project = new Project();
// add source files
project.addExistingSourceFiles("src/**/*.ts");
const myClassFile = project.createSourceFile("src/MyClass.ts", "export class MyClass {}");
const myEnumFile = project.createSourceFile("src/MyEnum.ts", {
enums: [{
name: "MyEnum",
isExported: true,
members: [{ name: "member" }]
}]
});
// get information from ast
const myClass = myClassFile.getClassOrThrow("MyClass");
myClass.getName(); // returns: "MyClass"
myClass.hasExportKeyword(); // returns: true
myClass.isDefaultExport(); // returns: false
// manipulate ast
const myInterface = myClassFile.addInterface({
name: "IMyInterface",
isExported: true,
properties: [{
name: "myProp",
type: "number"
}]
});
myClass.rename("NewName");
myClass.addImplements(myInterface.getName());
myClass.addProperty({
name: "myProp",
initializer: "5"
});
project.getSourceFileOrThrow("src/ExistingFile.ts").delete();
// asynchronously save all the changes above
project.save();
// get underlying compiler node from the typescript AST from any node
const compilerNode = myClassFile.compilerNode;
Or navigate existing compiler nodes created with the TypeScript compiler (the ts
named export is the TypeScript compiler):
import {createWrappedNode, ClassDeclaration, ts} from "ts-simple-ast";
// some code that creates a class declaration using the ts object
const classNode: ts.ClassDeclaration = ...;
// create and use a wrapped node
const classDec = createWrappedNode(classNode) as ClassDeclaration;
const firstProperty = classDec.getProperties()[0];
// ... do more stuff here ...
FAQs
TypeScript compiler wrapper for static analysis and code manipulation.
The npm package ts-simple-ast receives a total of 31,340 weekly downloads. As such, ts-simple-ast popularity was classified as popular.
We found that ts-simple-ast 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.