arkanalyzer 1.0.31 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { ts } from '..';
|
|
1
|
+
import { ArkFile, ts } from '..';
|
|
2
2
|
export declare class AstTreeUtils {
|
|
3
|
+
/**
|
|
4
|
+
* get source file from code segment
|
|
5
|
+
* @param fileName source file name
|
|
6
|
+
* @param code source code
|
|
7
|
+
* @returns ts.SourceFile
|
|
8
|
+
*/
|
|
3
9
|
static getASTNode(fileName: string, code: string): ts.SourceFile;
|
|
10
|
+
/**
|
|
11
|
+
* get source file from ArkFile
|
|
12
|
+
* @param arkFile ArkFile
|
|
13
|
+
* @returns ts.SourceFile
|
|
14
|
+
*/
|
|
15
|
+
static getSourceFileFromArkFile(arkFile: ArkFile): ts.SourceFile;
|
|
16
|
+
static createSourceFile(fileName: string, code: string): ts.SourceFile;
|
|
17
|
+
/**
|
|
18
|
+
* convert source code to hash string
|
|
19
|
+
* @param code source code
|
|
20
|
+
* @returns string
|
|
21
|
+
*/
|
|
22
|
+
private static getKeyFromCode;
|
|
4
23
|
}
|
|
5
24
|
//# sourceMappingURL=AstTreeUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AstTreeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/AstTreeUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"AstTreeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/AstTreeUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;AAMjC,qBAAa,YAAY;IACrB;;;;;OAKG;WACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAWvE;;;;OAIG;WACW,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,EAAE,CAAC,UAAU;WAYzD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAW7E;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CAGhC"}
|
|
@@ -13,14 +13,78 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
16
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
40
|
exports.AstTreeUtils = void 0;
|
|
18
41
|
const __1 = require("..");
|
|
19
42
|
const EtsConst_1 = require("../core/common/EtsConst");
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const sourceFileCache = new Map();
|
|
20
45
|
class AstTreeUtils {
|
|
46
|
+
/**
|
|
47
|
+
* get source file from code segment
|
|
48
|
+
* @param fileName source file name
|
|
49
|
+
* @param code source code
|
|
50
|
+
* @returns ts.SourceFile
|
|
51
|
+
*/
|
|
21
52
|
static getASTNode(fileName, code) {
|
|
22
|
-
const
|
|
53
|
+
const key = this.getKeyFromCode(code);
|
|
54
|
+
let sourceFile = sourceFileCache.get(key);
|
|
55
|
+
if (sourceFile) {
|
|
56
|
+
return sourceFile;
|
|
57
|
+
}
|
|
58
|
+
sourceFile = this.createSourceFile(fileName, code);
|
|
59
|
+
sourceFileCache.set(key, sourceFile);
|
|
60
|
+
return sourceFile;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* get source file from ArkFile
|
|
64
|
+
* @param arkFile ArkFile
|
|
65
|
+
* @returns ts.SourceFile
|
|
66
|
+
*/
|
|
67
|
+
static getSourceFileFromArkFile(arkFile) {
|
|
68
|
+
const signature = arkFile.getFileSignature().toString();
|
|
69
|
+
const key = this.getKeyFromCode(signature);
|
|
70
|
+
let sourceFile = sourceFileCache.get(key);
|
|
71
|
+
if (sourceFile) {
|
|
72
|
+
return sourceFile;
|
|
73
|
+
}
|
|
74
|
+
sourceFile = this.createSourceFile(arkFile.getName(), arkFile.getCode());
|
|
75
|
+
sourceFileCache.set(key, sourceFile);
|
|
23
76
|
return sourceFile;
|
|
24
77
|
}
|
|
78
|
+
static createSourceFile(fileName, code) {
|
|
79
|
+
return __1.ts.createSourceFile(fileName, code, __1.ts.ScriptTarget.Latest, true, undefined, EtsConst_1.ETS_COMPILER_OPTIONS);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* convert source code to hash string
|
|
83
|
+
* @param code source code
|
|
84
|
+
* @returns string
|
|
85
|
+
*/
|
|
86
|
+
static getKeyFromCode(code) {
|
|
87
|
+
return crypto.createHash('sha256').update(code).digest('hex');
|
|
88
|
+
}
|
|
25
89
|
}
|
|
26
90
|
exports.AstTreeUtils = AstTreeUtils;
|