Skip to content

Commit e541e49

Browse files
authored
refactor: extract cfg-javascript as a library (#103)
1 parent 5c54088 commit e541e49

File tree

16 files changed

+169
-12
lines changed

16 files changed

+169
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ dist
116116
.vscode-test
117117

118118
### Syntest Javascript ###
119+
!packages/cfg-javascript/lib
119120

120121
# End of https://www.toptal.com/developers/gitignore/api/node
121122

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"type": "git",
2121
"url": "git+https://github.com/syntest-framework/syntest-javascript.git"
2222
},
23+
"bin": {
24+
"syntest-javascript": "./packages/javascript/dist/bin.js"
25+
},
2326
"scripts": {
2427
"lint-staged": "lint-staged",
2528
"build": "lerna run build",

packages/cfg-javascript/NOTICE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SynTest Javascript
2+
Copyright 2020-2023 Delft University of Technology and SynTest contributors
3+
4+
This product includes software developed at
5+
Delft University of Technology (http://www.tudelft.nl/).

packages/cfg-javascript/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Control Flow Graph library for JavaScript

packages/javascript/lib/analysis/static/cfg/CFGGenerator.ts renamed to packages/cfg-javascript/lib/CFGGenerator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ export class CFGGenerator {
3030
/**
3131
* Generate function map for specified target.
3232
*
33-
* @param targetPath The path of the AST
3433
* @param targetAST The AST of the target
3534
*/
36-
generate(targetPath: string, targetAST: t.Node): CFG {
37-
const visitor = new ControlFlowGraphVisitor(targetPath);
35+
generate(targetAST: t.Node): CFG {
36+
const visitor = new ControlFlowGraphVisitor();
3837
traverse(targetAST, visitor);
3938

4039
return visitor.cfg;

packages/javascript/lib/analysis/static/cfg/ControlFlowGraphVisitor.ts renamed to packages/cfg-javascript/lib/ControlFlowGraphVisitor.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import { Visitor } from "../Visitor";
2019
import {
2120
BranchNode,
2221
CFG,
@@ -27,7 +26,7 @@ import {
2726
RootNode,
2827
} from "@syntest/cfg-core";
2928

30-
export class ControlFlowGraphVisitor extends Visitor {
29+
export class ControlFlowGraphVisitor {
3130
private _cfg: CFG;
3231

3332
// private _nodeStack: Node[][]
@@ -42,8 +41,7 @@ export class ControlFlowGraphVisitor extends Visitor {
4241

4342
private _nodeStack: Node[];
4443

45-
constructor(filePath: string) {
46-
super(filePath);
44+
constructor() {
4745
this._cfg = new CFG();
4846

4947
this._trackingLeaves = [];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
3+
*
4+
* This file is part of SynTest Framework - SynTest Javascript.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export * from "./CFGGenerator";
20+
export * from "./ControlFlowGraphGenerator";
21+
export * from "./ControlFlowGraphVisitor";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../../tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "../dist",
5+
"rootDir": ".",
6+
"composite": true
7+
},
8+
"include": ["**/*.ts"]
9+
}

0 commit comments

Comments
 (0)