Skip to content

Commit

Permalink
Typescript improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Sep 20, 2024
1 parent f4a6079 commit a4bc436
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ jobs:
env:
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
shell: bash
- name: Generate SBOM with cdxgen
run: |
npm install -g @cyclonedx/cdxgen
cdxgen -t sbt -o bom.json . -p --no-recurse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}
- name: Generate SBOM with cdxgen
run: |
npm install -g @cyclonedx/cdxgen
cdxgen -t sbt -o bom.json . -p --no-recurse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
bom.json
target/atom.zip
target/atom.zip.sha512
target/graalvm-native-image/atom-amd64
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name := "atom"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "2.0.18"
ThisBuild / version := "2.0.19"
ThisBuild / scalaVersion := "3.5.0"

val chenVersion = "2.1.5"
val chenVersion = "2.1.6"

lazy val atom = Projects.atom

Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"downloadUrl": "https://github.com/AppThreat/atom",
"issueTracker": "https://github.com/AppThreat/atom/issues",
"name": "atom",
"version": "2.0.18",
"version": "2.0.19",
"description": "Atom is a novel intermediate representation for next-generation code analysis.",
"applicationCategory": "code-analysis",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.1
sbt.version=1.10.2
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.4")
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.2.0")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.2.1")
47 changes: 27 additions & 20 deletions wrapper/nodejs/astgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ const babelSafeParserOptions = {
*/
const getAllSrcJSAndTSFiles = (src) =>
Promise.all([
getAllFiles(src, ".js"),
getAllFiles(src, ".jsx"),
getAllFiles(src, ".cjs"),
getAllFiles(src, ".mjs"),
getAllFiles(src, ".ts"),
getAllFiles(src, ".tsx"),
getAllFiles(src, ".vue"),
getAllFiles(src, ".svelte")
getAllFiles(src, undefined, undefined, undefined, new RegExp("\\.(js|jsx|cjs|mjs|ts|tsx|vue|svelte)$"))
]);

/**
Expand Down Expand Up @@ -100,6 +93,15 @@ const vueBindRegex = /(:\[)([\s\S]*?)(\])/gi;
const vuePropRegex = /\s([.:@])([a-zA-Z]*?=)/gi;
const vueOpenImgTag = /(<img)((?!>)[\s\S]+?)( [^/]>)/gi;

const TSC_FLAGS =
tsc.TypeFormatFlags.NoTruncation |
tsc.TypeFormatFlags.InTypeAlias |
tsc.TypeFormatFlags.WriteArrayAsGenericType |
tsc.TypeFormatFlags.GenerateNamesForShadowedTypeParams |
tsc.TypeFormatFlags.WriteTypeArgumentsOfSignature |
tsc.TypeFormatFlags.UseFullyQualifiedType |
tsc.TypeFormatFlags.NoTypeReduction;

/**
* Convert a single vue file to AST
*/
Expand Down Expand Up @@ -132,6 +134,10 @@ function createTsc(srcFiles) {
const program = tsc.createProgram(srcFiles, {
target: tsc.ScriptTarget.ES2020,
module: tsc.ModuleKind.CommonJS,
allowImportingTsExtensions: false,
allowArbitraryExtensions: false,
allowSyntheticDefaultImports: true,
allowUmdGlobalAccess: true,
allowJs: true,
allowUnreachableCode: true,
allowUnusedLabels: true,
Expand All @@ -150,22 +156,15 @@ function createTsc(srcFiles) {

const safeTypeToString = (node) => {
try {
return typeChecker.typeToString(
node,
tsc.TypeFormatFlags.NoTruncation | tsc.TypeFormatFlags.InTypeAlias
);
return typeChecker.typeToString(node, null, TSC_FLAGS);
} catch (err) {
return "any";
}
};

const safeTypeWithContextToString = (node, context) => {
try {
return typeChecker.typeToString(
node,
context,
tsc.TypeFormatFlags.NoTruncation | tsc.TypeFormatFlags.InTypeAlias
);
return typeChecker.typeToString(node, context, TSC_FLAGS);
} catch (err) {
return "any";
}
Expand All @@ -176,10 +175,18 @@ function createTsc(srcFiles) {
if (
tsc.isSetAccessor(node) ||
tsc.isGetAccessor(node) ||
tsc.isGetAccessorDeclaration(node) ||
tsc.isCallSignatureDeclaration(node) ||
tsc.isIndexSignatureDeclaration(node) ||
tsc.isClassStaticBlockDeclaration(node) ||
tsc.isConstructSignatureDeclaration(node) ||
tsc.isMethodDeclaration(node) ||
tsc.isFunctionDeclaration(node) ||
tsc.isConstructorDeclaration(node)
tsc.isConstructorDeclaration(node) ||
tsc.isTypeAliasDeclaration(node) ||
tsc.isEnumDeclaration(node) ||
tsc.isNamespaceExportDeclaration(node) ||
tsc.isImportEqualsDeclaration(node)
) {
const signature = typeChecker.getSignatureFromDeclaration(node);
const returnType = typeChecker.getReturnTypeOfSignature(signature);
Expand All @@ -204,8 +211,9 @@ function createTsc(srcFiles) {
node
);
}
if (!["any", "unknown", "any[]", "unknown[]"].includes(typeStr))
if (!["any", "unknown", "any[]", "unknown[]"].includes(typeStr)) {
seenTypes.set(node.getStart(), typeStr);
}
tsc.forEachChild(node, addType);
};

Expand All @@ -232,7 +240,6 @@ const createJSAst = async (options) => {
if (options.tsTypes) {
ts = createTsc(srcFiles);
}

for (const file of srcFiles) {
try {
const ast = fileToJsAst(file);
Expand Down
13 changes: 7 additions & 6 deletions wrapper/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wrapper/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appthreat/atom",
"version": "2.0.18",
"version": "2.0.19",
"description": "Create atom (⚛) representation for your application, packages and libraries",
"exports": "./index.js",
"type": "module",
Expand All @@ -10,7 +10,7 @@
},
"dependencies": {
"@babel/parser": "^7.25.6",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down

0 comments on commit a4bc436

Please sign in to comment.