arkanalyzer 1.0.87 → 1.0.88
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.
- package/lib/Config.d.ts +4 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +17 -2
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +7 -8
- package/lib/cli/commands/cg.d.ts +27 -6
- package/lib/cli/commands/cg.d.ts.map +1 -1
- package/lib/cli/commands/cg.js +9 -6
- package/lib/core/base/Expr.js +3 -3
- package/lib/core/base/Position.d.ts +1 -1
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +2 -2
- package/lib/core/common/Const.d.ts +1 -0
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +2 -1
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +1 -1
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +3 -33
- package/lib/core/model/ArkClass.d.ts +3 -0
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +13 -2
- package/lib/core/model/ArkMetadata.d.ts +32 -1
- package/lib/core/model/ArkMetadata.d.ts.map +1 -1
- package/lib/core/model/ArkMetadata.js +28 -2
- package/lib/core/model/builder/ArkMetadataBuilder.d.ts +21 -0
- package/lib/core/model/builder/ArkMetadataBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkMetadataBuilder.js +160 -0
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +32 -24
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.d.ts +8 -0
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.js +90 -0
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.d.ts +8 -0
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.js +183 -0
- package/lib/frontend/cppFrontend/ast/astParser.d.ts +25 -0
- package/lib/frontend/cppFrontend/ast/astParser.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/astParser.js +280 -0
- package/lib/frontend/cppFrontend/ast/astUtils.d.ts +12 -45
- package/lib/frontend/cppFrontend/ast/astUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/ast/astUtils.js +62 -374
- package/lib/frontend/cppFrontend/ast/const.d.ts +0 -13
- package/lib/frontend/cppFrontend/ast/const.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/ast/const.js +1 -77
- package/lib/frontend/cppFrontend/ast/index.d.ts +5 -0
- package/lib/frontend/cppFrontend/ast/index.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/index.js +31 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +55 -55
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +151 -151
- package/lib/frontend/cppFrontend/common/IRInference.js +2 -2
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.js +2 -2
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +74 -74
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +3 -3
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +16 -17
- package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +2 -2
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +2 -2
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +3 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -6
- package/lib/save/source/SourceStmt.d.ts.map +1 -1
- package/lib/save/source/SourceStmt.js +3 -1
- package/lib/utils/FileUtils.d.ts +1 -0
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +11 -3
- package/package.json +5 -2
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.EnumInitTypeUserMetadata = exports.CommentsMetadata = exports.ArkMetadata = exports.ArkMetadataKind = void 0;
|
|
17
|
+
exports.EnumInitTypeUserMetadata = exports.JSDocMetadata = exports.CommentsMetadata = exports.ArkMetadata = exports.ArkMetadataKind = void 0;
|
|
18
18
|
var ArkMetadataKind;
|
|
19
19
|
(function (ArkMetadataKind) {
|
|
20
20
|
ArkMetadataKind[ArkMetadataKind["LEADING_COMMENTS"] = 0] = "LEADING_COMMENTS";
|
|
21
21
|
ArkMetadataKind[ArkMetadataKind["TRAILING_COMMENTS"] = 1] = "TRAILING_COMMENTS";
|
|
22
|
-
ArkMetadataKind[ArkMetadataKind["
|
|
22
|
+
ArkMetadataKind[ArkMetadataKind["JSDOC"] = 2] = "JSDOC";
|
|
23
|
+
ArkMetadataKind[ArkMetadataKind["ENUM_INIT_TYPE_USER"] = 3] = "ENUM_INIT_TYPE_USER";
|
|
23
24
|
})(ArkMetadataKind = exports.ArkMetadataKind || (exports.ArkMetadataKind = {}));
|
|
24
25
|
/**
|
|
25
26
|
* ArkMetadata
|
|
@@ -54,6 +55,31 @@ class CommentsMetadata {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
exports.CommentsMetadata = CommentsMetadata;
|
|
58
|
+
class JSDocMetadata {
|
|
59
|
+
constructor(description, params, tags = [], returns = [], throws = []) {
|
|
60
|
+
this.description = description;
|
|
61
|
+
this.params = params;
|
|
62
|
+
this.tags = tags;
|
|
63
|
+
this.returns = returns;
|
|
64
|
+
this.throws = throws;
|
|
65
|
+
}
|
|
66
|
+
getDescription() {
|
|
67
|
+
return this.description;
|
|
68
|
+
}
|
|
69
|
+
getParams() {
|
|
70
|
+
return this.params;
|
|
71
|
+
}
|
|
72
|
+
getTags() {
|
|
73
|
+
return this.tags;
|
|
74
|
+
}
|
|
75
|
+
getReturns() {
|
|
76
|
+
return this.returns;
|
|
77
|
+
}
|
|
78
|
+
getThrows() {
|
|
79
|
+
return this.throws;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.JSDocMetadata = JSDocMetadata;
|
|
57
83
|
class EnumInitTypeUserMetadata {
|
|
58
84
|
constructor(originTypeUser) {
|
|
59
85
|
this.originTypeUser = originTypeUser;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ts from 'ohos-typescript';
|
|
2
|
+
import { SceneOptions } from '../../../Config';
|
|
3
|
+
import { Stmt } from '../../base/Stmt';
|
|
4
|
+
import { ArkBaseModel } from '../ArkBaseModel';
|
|
5
|
+
import { CommentsMetadata, JSDocMetadata } from '../ArkMetadata';
|
|
6
|
+
export declare class ArkMetadataBuilder {
|
|
7
|
+
private static readonly PARAM_TAG_REGEX;
|
|
8
|
+
private static readonly RETURNS_TAG_REGEX;
|
|
9
|
+
private static readonly THROWS_TAG_REGEX;
|
|
10
|
+
private static readonly GENERIC_TAG_REGEX;
|
|
11
|
+
static setComments(metadata: Stmt | ArkBaseModel, node: ts.Node, sourceFile: ts.SourceFile, options: SceneOptions): void;
|
|
12
|
+
static getCommentsMetadata(node: ts.Node, sourceFile: ts.SourceFile, options: SceneOptions, isLeading: boolean): CommentsMetadata;
|
|
13
|
+
static getJSDocMetadata(node: ts.Node, sourceFile: ts.SourceFile, options: SceneOptions): JSDocMetadata[];
|
|
14
|
+
private static parseJSDocContent;
|
|
15
|
+
private static parseJSDocLine;
|
|
16
|
+
private static tryParseParam;
|
|
17
|
+
private static tryParseReturns;
|
|
18
|
+
private static tryParseThrows;
|
|
19
|
+
private static tryParseGenericTag;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ArkMetadataBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArkMetadataBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkMetadataBuilder.ts"],"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160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.ArkMetadataBuilder = void 0;
|
|
21
|
+
const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
|
|
22
|
+
const Position_1 = require("../../base/Position");
|
|
23
|
+
const ArkMetadata_1 = require("../ArkMetadata");
|
|
24
|
+
class ArkMetadataBuilder {
|
|
25
|
+
static setComments(metadata, node, sourceFile, options) {
|
|
26
|
+
const leadingCommentsMetadata = this.getCommentsMetadata(node, sourceFile, options, true);
|
|
27
|
+
if (leadingCommentsMetadata.getComments().length > 0) {
|
|
28
|
+
metadata.setMetadata(ArkMetadata_1.ArkMetadataKind.LEADING_COMMENTS, leadingCommentsMetadata);
|
|
29
|
+
}
|
|
30
|
+
const trailingCommentsMetadata = this.getCommentsMetadata(node, sourceFile, options, false);
|
|
31
|
+
if (trailingCommentsMetadata.getComments().length > 0) {
|
|
32
|
+
metadata.setMetadata(ArkMetadata_1.ArkMetadataKind.TRAILING_COMMENTS, trailingCommentsMetadata);
|
|
33
|
+
}
|
|
34
|
+
const jsDocMetadatas = this.getJSDocMetadata(node, sourceFile, options);
|
|
35
|
+
if (jsDocMetadatas.length > 0) {
|
|
36
|
+
metadata.setMetadata(ArkMetadata_1.ArkMetadataKind.JSDOC, jsDocMetadatas);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
static getCommentsMetadata(node, sourceFile, options, isLeading) {
|
|
40
|
+
const comments = [];
|
|
41
|
+
if ((isLeading && !options.enableLeadingComments) || (!isLeading && !options.enableTrailingComments)) {
|
|
42
|
+
return new ArkMetadata_1.CommentsMetadata(comments);
|
|
43
|
+
}
|
|
44
|
+
const commentRanges = (isLeading ? ohos_typescript_1.default.getLeadingCommentRanges(sourceFile.text, node.pos) : ohos_typescript_1.default.getTrailingCommentRanges(sourceFile.text, node.end)) || [];
|
|
45
|
+
const getPosition = (pos, end) => {
|
|
46
|
+
const start = ohos_typescript_1.default.getLineAndCharacterOfPosition(sourceFile, pos);
|
|
47
|
+
const endPos = ohos_typescript_1.default.getLineAndCharacterOfPosition(sourceFile, end);
|
|
48
|
+
return new Position_1.FullPosition(start.line + 1, start.character + 1, endPos.line + 1, endPos.character + 1);
|
|
49
|
+
};
|
|
50
|
+
for (const range of commentRanges) {
|
|
51
|
+
comments.push({
|
|
52
|
+
content: sourceFile.text.substring(range.pos, range.end).replace(/\r\n/g, '\n'),
|
|
53
|
+
position: getPosition(range.pos, range.end),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return new ArkMetadata_1.CommentsMetadata(comments);
|
|
57
|
+
}
|
|
58
|
+
static getJSDocMetadata(node, sourceFile, options) {
|
|
59
|
+
if (!options.enableJSDoc) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const commentRanges = ohos_typescript_1.default.getLeadingCommentRanges(sourceFile.text, node.pos) || [];
|
|
63
|
+
const jsDocContents = commentRanges
|
|
64
|
+
.map(range => sourceFile.text.substring(range.pos, range.end).replace(/\r\n/g, '\n'))
|
|
65
|
+
.filter(content => content.startsWith('/**'));
|
|
66
|
+
if (jsDocContents.length === 0) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const jsDocMetadatas = [];
|
|
70
|
+
for (const jsDocContent of jsDocContents) {
|
|
71
|
+
jsDocMetadatas.push(this.parseJSDocContent(jsDocContent));
|
|
72
|
+
}
|
|
73
|
+
return jsDocMetadatas;
|
|
74
|
+
}
|
|
75
|
+
static parseJSDocContent(content) {
|
|
76
|
+
const normalizedLines = content
|
|
77
|
+
.split('\n')
|
|
78
|
+
.map(line => line.replace(/^\s*\/\*\*?/, '').replace(/\*\/\s*$/, '').replace(/^\s*\*\s?/, '').trim());
|
|
79
|
+
const descriptionLines = [];
|
|
80
|
+
const params = [];
|
|
81
|
+
const tags = [];
|
|
82
|
+
const returns = [];
|
|
83
|
+
const throws = [];
|
|
84
|
+
for (const line of normalizedLines) {
|
|
85
|
+
this.parseJSDocLine(line, descriptionLines, params, returns, throws, tags);
|
|
86
|
+
}
|
|
87
|
+
const description = descriptionLines.join('\n').trim();
|
|
88
|
+
return new ArkMetadata_1.JSDocMetadata(description, params, tags, returns, throws);
|
|
89
|
+
}
|
|
90
|
+
static parseJSDocLine(line, descriptionLines, params, returns, throws, tags) {
|
|
91
|
+
if (!line) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!line.startsWith('@')) {
|
|
95
|
+
descriptionLines.push(line);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.tryParseParam(line, params)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (this.tryParseReturns(line, returns)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (this.tryParseThrows(line, throws)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.tryParseGenericTag(line, tags);
|
|
108
|
+
}
|
|
109
|
+
static tryParseParam(line, params) {
|
|
110
|
+
const match = line.match(ArkMetadataBuilder.PARAM_TAG_REGEX);
|
|
111
|
+
if (!match) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
params.push({
|
|
115
|
+
name: match[2],
|
|
116
|
+
type: match[1].trim(),
|
|
117
|
+
description: match[3].trim(),
|
|
118
|
+
});
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
static tryParseReturns(line, returns) {
|
|
122
|
+
var _a;
|
|
123
|
+
const match = line.match(ArkMetadataBuilder.RETURNS_TAG_REGEX);
|
|
124
|
+
if (!match) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
returns.push({
|
|
128
|
+
type: (_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim(),
|
|
129
|
+
description: match[2].trim(),
|
|
130
|
+
});
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
static tryParseThrows(line, throws) {
|
|
134
|
+
var _a;
|
|
135
|
+
const match = line.match(ArkMetadataBuilder.THROWS_TAG_REGEX);
|
|
136
|
+
if (!match) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
throws.push({
|
|
140
|
+
type: (_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim(),
|
|
141
|
+
description: match[2].trim(),
|
|
142
|
+
});
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
static tryParseGenericTag(line, tags) {
|
|
146
|
+
const match = line.match(ArkMetadataBuilder.GENERIC_TAG_REGEX);
|
|
147
|
+
if (!match) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
tags.push({
|
|
151
|
+
name: match[1],
|
|
152
|
+
description: match[2].trim(),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.ArkMetadataBuilder = ArkMetadataBuilder;
|
|
157
|
+
ArkMetadataBuilder.PARAM_TAG_REGEX = /^@param\s+\{\s*([^}]+?)\s*\}\s+([^\s-]+)\s*(?:-\s*)?(.*)$/;
|
|
158
|
+
ArkMetadataBuilder.RETURNS_TAG_REGEX = /^@returns?\s*(?:\{\s*([^}]+?)\s*\})?\s*(.*)$/;
|
|
159
|
+
ArkMetadataBuilder.THROWS_TAG_REGEX = /^@throws\s*(?:\{\s*([^}]+?)\s*\})?\s*(.*)$/;
|
|
160
|
+
ArkMetadataBuilder.GENERIC_TAG_REGEX = /^@([^\s]+)\s*(.*)$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkMethodBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkMethodBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,IAAI,EAAe,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAgBjC,OAAO,EAAkE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAmBzC,MAAM,MAAM,cAAc,GACpB,EAAE,CAAC,mBAAmB,GACtB,EAAE,CAAC,iBAAiB,GACpB,EAAE,CAAC,sBAAsB,GACzB,EAAE,CAAC,aAAa,GAChB,EAAE,CAAC,mBAAmB,GACtB,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,eAAe,GAClB,EAAE,CAAC,6BAA6B,GAChC,EAAE,CAAC,wBAAwB,GAC3B,EAAE,CAAC,gBAAgB,CAAC;AAE1B,wBAAgB,iCAAiC,CAAC,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,GAAG,IAAI,CAYxJ;AAED,wBAAgB,0BAA0B,CACtC,UAAU,EAAE,cAAc,EAC1B,cAAc,EAAE,QAAQ,EACxB,GAAG,EAAE,SA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C,IAAI,EAAE,cAAc,GAAG,OAAO,CAepE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAW3E;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,GAAG,IAAI,CA4BnG;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI,CA8CrE"}
|
|
@@ -161,7 +161,7 @@ function buildMethodName(node, declaringClass, sourceFile, declaringMethod) {
|
|
|
161
161
|
name = TSConst_1.CONSTRUCTOR_NAME;
|
|
162
162
|
}
|
|
163
163
|
else if (ohos_typescript_1.default.isConstructSignatureDeclaration(node)) {
|
|
164
|
-
name =
|
|
164
|
+
name = Const_1.CONSTRUCT_SIGNATURE_NAME;
|
|
165
165
|
}
|
|
166
166
|
else if (ohos_typescript_1.default.isCallSignatureDeclaration(node)) {
|
|
167
167
|
name = Const_1.CALL_SIGNATURE_NAME;
|
|
@@ -301,7 +301,8 @@ function needDefaultConstructorInClass(arkClass) {
|
|
|
301
301
|
const originClassType = arkClass.getCategory();
|
|
302
302
|
return (arkClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME) === null &&
|
|
303
303
|
(originClassType === ArkClass_1.ClassCategory.CLASS || originClassType === ArkClass_1.ClassCategory.OBJECT) &&
|
|
304
|
-
arkClass.
|
|
304
|
+
!arkClass.isDefaultArkClass() &&
|
|
305
|
+
!arkClass.isLibraryClass() &&
|
|
305
306
|
!arkClass.isDeclare());
|
|
306
307
|
}
|
|
307
308
|
exports.needDefaultConstructorInClass = needDefaultConstructorInClass;
|
|
@@ -323,10 +324,10 @@ function recursivelyCheckAndBuildSuperConstructor(arkClass, visited = new Set())
|
|
|
323
324
|
}
|
|
324
325
|
function buildDefaultConstructor(arkClass, visited = new Set()) {
|
|
325
326
|
var _a;
|
|
327
|
+
recursivelyCheckAndBuildSuperConstructor(arkClass, visited);
|
|
326
328
|
if (!needDefaultConstructorInClass(arkClass)) {
|
|
327
329
|
return false;
|
|
328
330
|
}
|
|
329
|
-
recursivelyCheckAndBuildSuperConstructor(arkClass, visited);
|
|
330
331
|
const defaultConstructor = new ArkMethod_1.ArkMethod();
|
|
331
332
|
defaultConstructor.setDeclaringArkClass(arkClass);
|
|
332
333
|
defaultConstructor.setCode('');
|
|
@@ -487,41 +488,48 @@ function updateMethodSignaturesAndLineCols(method, presentMethod) {
|
|
|
487
488
|
}
|
|
488
489
|
exports.updateMethodSignaturesAndLineCols = updateMethodSignaturesAndLineCols;
|
|
489
490
|
function replaceSuper2Constructor(constructor) {
|
|
490
|
-
var _a, _b;
|
|
491
|
+
var _a, _b, _c;
|
|
491
492
|
if (constructor.getName() !== TSConst_1.CONSTRUCTOR_NAME) {
|
|
492
493
|
return;
|
|
493
494
|
}
|
|
495
|
+
const startingBlock = (_a = constructor.getBody()) === null || _a === void 0 ? void 0 : _a.getCfg().getStartingBlock();
|
|
496
|
+
if (startingBlock === undefined) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
let superInvokeStmt = null;
|
|
500
|
+
for (const stmt of startingBlock.getStmts()) {
|
|
501
|
+
if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
502
|
+
let invokeExpr = stmt.getInvokeExpr();
|
|
503
|
+
const methodSignature = invokeExpr.getMethodSignature();
|
|
504
|
+
if (methodSignature.getMethodSubSignature().getMethodName() === TSConst_1.SUPER_NAME) {
|
|
505
|
+
superInvokeStmt = stmt;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (!superInvokeStmt) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
// If there are superInvokeStmt, then there must have constructor of its super class.
|
|
494
514
|
const superClass = constructor.getDeclaringArkClass().getSuperClass();
|
|
495
515
|
if (superClass === null) {
|
|
516
|
+
logger.error(`Can not find super class for class ${constructor.getDeclaringArkClass().getSignature().toString()}`);
|
|
496
517
|
return;
|
|
497
518
|
}
|
|
498
|
-
const superConstructor = superClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
519
|
+
const superConstructor = (_b = superClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME)) !== null && _b !== void 0 ? _b : superClass.getMethodWithName(Const_1.CONSTRUCT_SIGNATURE_NAME);
|
|
499
520
|
if (superConstructor === null) {
|
|
500
521
|
if (needDefaultConstructorInClass(superClass)) {
|
|
501
522
|
logger.error(`Can not find constructor method for class ${superClass.getSignature().toString()}`);
|
|
502
523
|
}
|
|
503
524
|
return;
|
|
504
525
|
}
|
|
505
|
-
|
|
506
|
-
if (
|
|
526
|
+
let base = (_c = constructor.getBody()) === null || _c === void 0 ? void 0 : _c.getLocals().get(TSConst_1.THIS_NAME);
|
|
527
|
+
if (base === undefined) {
|
|
528
|
+
logger.error(`Can not find local this in constructor method ${constructor.getSignature().toString()}`);
|
|
507
529
|
return;
|
|
508
530
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const methodSignature = invokeExpr.getMethodSignature();
|
|
513
|
-
if (methodSignature.getMethodSubSignature().getMethodName() !== TSConst_1.SUPER_NAME) {
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
let base = (_b = constructor.getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().get(TSConst_1.THIS_NAME);
|
|
517
|
-
if (base === undefined) {
|
|
518
|
-
logger.error(`Can not find local this in constructor method ${constructor.getSignature().toString()}`);
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const newInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(base, superConstructor.getSignature(), invokeExpr.getArgs());
|
|
522
|
-
stmt.replaceInvokeExpr(newInvokeExpr);
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
531
|
+
const newInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(base, superConstructor.getSignature(), superInvokeStmt.getInvokeExpr().getArgs());
|
|
532
|
+
superInvokeStmt.replaceInvokeExpr(newInvokeExpr);
|
|
533
|
+
return;
|
|
526
534
|
}
|
|
527
535
|
exports.replaceSuper2Constructor = replaceSuper2Constructor;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface AstJsonDumpRequest {
|
|
2
|
+
sourceFile: string;
|
|
3
|
+
outputFile: string;
|
|
4
|
+
ccJsonPath?: string;
|
|
5
|
+
includeDirs?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function dumpAstJson(request: AstJsonDumpRequest, cwd: string, llvmPath?: string): number;
|
|
8
|
+
//# sourceMappingURL=napiApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"napiApi.d.ts","sourceRoot":"","sources":["../../../../../src/frontend/cppFrontend/ast/astJsonNapi/napiApi.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,kBAAkB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AA6BD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAqB/F"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
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
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.dumpAstJson = void 0;
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const logger_1 = __importStar(require("../../../../utils/logger"));
|
|
43
|
+
const astUtils_1 = require("../astUtils");
|
|
44
|
+
const napiRunner_1 = require("./napiRunner");
|
|
45
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'astJsonDumper');
|
|
46
|
+
function buildRunEnv(llvmPath) {
|
|
47
|
+
var _a;
|
|
48
|
+
const out = Object.assign({}, process.env);
|
|
49
|
+
if (!llvmPath) {
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
const sep = path.delimiter;
|
|
53
|
+
const cur = (_a = out.PATH) !== null && _a !== void 0 ? _a : '';
|
|
54
|
+
if (!cur.split(sep).includes(llvmPath)) {
|
|
55
|
+
out.PATH = cur.length === 0 ? llvmPath : cur + sep + llvmPath;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function buildAstJsonArgv(request) {
|
|
60
|
+
const argv = [request.sourceFile, '-o', request.outputFile];
|
|
61
|
+
if (request.ccJsonPath) {
|
|
62
|
+
argv.push('-p', request.ccJsonPath);
|
|
63
|
+
}
|
|
64
|
+
if (request.includeDirs && request.includeDirs.length > 0) {
|
|
65
|
+
request.includeDirs.forEach((dir) => {
|
|
66
|
+
argv.push(`--extra-arg-before=-I${dir}`);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return argv;
|
|
70
|
+
}
|
|
71
|
+
function dumpAstJson(request, cwd, llvmPath) {
|
|
72
|
+
const argv = buildAstJsonArgv(request);
|
|
73
|
+
logger.info('================================================================');
|
|
74
|
+
logger.info(`[Debug] CWD: ${cwd}`);
|
|
75
|
+
logger.info(`[Debug] astJsonDumper args: ${JSON.stringify(argv)}`);
|
|
76
|
+
logger.info('================================================================');
|
|
77
|
+
if (!(0, astUtils_1.isAstJsonDumperAvailable)()) {
|
|
78
|
+
logger.error('[Debug] astJsonDumper backend is unavailable.');
|
|
79
|
+
return -1;
|
|
80
|
+
}
|
|
81
|
+
const env = buildRunEnv(llvmPath);
|
|
82
|
+
const code = (0, napiRunner_1.runAstJsonArgv)(argv, { cwd, env });
|
|
83
|
+
if (code !== 0) {
|
|
84
|
+
logger.error(`[Debug] astJsonDumper exited with code ${code}`);
|
|
85
|
+
return code;
|
|
86
|
+
}
|
|
87
|
+
logger.info('[Debug] astJsonDumper finished successfully.');
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
exports.dumpAstJson = dumpAstJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"napiRunner.d.ts","sourceRoot":"","sources":["../../../../../src/frontend/cppFrontend/ast/astJsonNapi/napiRunner.ts"],"names":[],"mappings":";AAyBA,UAAU,iBAAiB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CAC1B;AA+JD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
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
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.runAstJsonArgv = void 0;
|
|
41
|
+
const node_child_process_1 = require("node:child_process");
|
|
42
|
+
const fs = __importStar(require("node:fs"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const logger_1 = __importStar(require("../../../../utils/logger"));
|
|
45
|
+
const astUtils_1 = require("../astUtils");
|
|
46
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'astJsonDumper');
|
|
47
|
+
let selectedRunArgv = null;
|
|
48
|
+
function startNewAstJsonWorker(addonAbsolutePath, onExit) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const workerPath = path.join(__dirname, 'napiWorker.cjs');
|
|
51
|
+
const proc = (0, node_child_process_1.fork)(workerPath, [addonAbsolutePath], {
|
|
52
|
+
serialization: 'advanced',
|
|
53
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
54
|
+
});
|
|
55
|
+
(_a = proc.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
|
|
56
|
+
const text = chunk.toString();
|
|
57
|
+
if (text.trim().length > 0) {
|
|
58
|
+
logger.info(`[Debug] astJsonDumper worker stdout:\n${text}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
(_b = proc.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (chunk) => {
|
|
62
|
+
const text = chunk.toString();
|
|
63
|
+
if (text.trim().length > 0) {
|
|
64
|
+
logger.error(`[Debug] astJsonDumper worker stderr:\n${text}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
proc.on('exit', (code, signal) => {
|
|
68
|
+
onExit(proc, code, signal);
|
|
69
|
+
});
|
|
70
|
+
return proc;
|
|
71
|
+
}
|
|
72
|
+
function awaitWorkerArgvReply(proc, workerStillCurrent, disposeOnSendFail, context, argv) {
|
|
73
|
+
const state = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2));
|
|
74
|
+
try {
|
|
75
|
+
proc.send({
|
|
76
|
+
type: 'run',
|
|
77
|
+
argv,
|
|
78
|
+
cwd: context.cwd,
|
|
79
|
+
envPath: context.env.PATH,
|
|
80
|
+
state: state.buffer,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.error('[Debug] Failed to send astJsonDumper request to worker:', error);
|
|
85
|
+
disposeOnSendFail(proc);
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
while (Atomics.load(state, 0) === 0) {
|
|
89
|
+
Atomics.wait(state, 0, 0, 1000);
|
|
90
|
+
if (!workerStillCurrent() || proc.exitCode !== null || proc.killed) {
|
|
91
|
+
logger.error('[Debug] astJsonDumper worker exited before replying.');
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return Atomics.load(state, 1);
|
|
96
|
+
}
|
|
97
|
+
function createPersistentWorkerRunner(addonAbsolutePath) {
|
|
98
|
+
let worker = null;
|
|
99
|
+
const disposeWorker = (proc) => {
|
|
100
|
+
if (worker === proc) {
|
|
101
|
+
worker = null;
|
|
102
|
+
}
|
|
103
|
+
if (proc.exitCode === null && !proc.killed) {
|
|
104
|
+
proc.kill();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const ensureWorker = () => {
|
|
108
|
+
if (worker && worker.exitCode === null && !worker.killed) {
|
|
109
|
+
return worker;
|
|
110
|
+
}
|
|
111
|
+
const proc = startNewAstJsonWorker(addonAbsolutePath, (exitedProc, code, signal) => {
|
|
112
|
+
if (worker === exitedProc) {
|
|
113
|
+
worker = null;
|
|
114
|
+
}
|
|
115
|
+
logger.warn(`[Debug] astJsonDumper worker exited (code=${code}, signal=${signal}).`);
|
|
116
|
+
});
|
|
117
|
+
worker = proc;
|
|
118
|
+
return proc;
|
|
119
|
+
};
|
|
120
|
+
return (context, ...argv) => {
|
|
121
|
+
const proc = ensureWorker();
|
|
122
|
+
return awaitWorkerArgvReply(proc, () => worker === proc, disposeWorker, context, argv);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function logSpawnSyncFailure(result) {
|
|
126
|
+
if (result.stdout) {
|
|
127
|
+
logger.error(`[Debug] child stdout:\n${result.stdout}`);
|
|
128
|
+
}
|
|
129
|
+
if (result.stderr) {
|
|
130
|
+
logger.error(`[Debug] child stderr:\n${result.stderr}`);
|
|
131
|
+
}
|
|
132
|
+
logger.error(`[Debug] astJsonDumper child exited with code ${result.status}`);
|
|
133
|
+
return -1;
|
|
134
|
+
}
|
|
135
|
+
function runArgvInSubprocess(context, ...argv) {
|
|
136
|
+
const addonPath = (0, astUtils_1.getAstJsonDumperNodePath)();
|
|
137
|
+
const childScript = 'const addon = require(process.argv[1]); ' +
|
|
138
|
+
'const rc = addon.runArgv(process.argv.slice(2)); ' +
|
|
139
|
+
"process.exitCode = typeof rc === 'number' ? rc : 1;";
|
|
140
|
+
const quoted = ['-e', childScript, addonPath, ...argv]
|
|
141
|
+
.map((arg) => (arg.includes(' ') ? `"${arg}"` : arg))
|
|
142
|
+
.join(' ');
|
|
143
|
+
logger.info('================================================================');
|
|
144
|
+
logger.info(`[Debug] CWD: ${context.cwd}`);
|
|
145
|
+
logger.info(`[Debug] astJsonDumper.node: ${addonPath}`);
|
|
146
|
+
logger.info(`[Debug] CMD: "${process.execPath}" ${quoted}`);
|
|
147
|
+
logger.info('================================================================');
|
|
148
|
+
if (!fs.existsSync(addonPath)) {
|
|
149
|
+
logger.error(`[Debug] Missing addon: ${addonPath}`);
|
|
150
|
+
return -1;
|
|
151
|
+
}
|
|
152
|
+
const result = (0, node_child_process_1.spawnSync)(process.execPath, ['-e', childScript, addonPath, ...argv], {
|
|
153
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
154
|
+
encoding: 'utf-8',
|
|
155
|
+
env: context.env,
|
|
156
|
+
cwd: context.cwd,
|
|
157
|
+
});
|
|
158
|
+
if (result.status !== 0) {
|
|
159
|
+
return logSpawnSyncFailure(result);
|
|
160
|
+
}
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
function shouldIsolateRuns() {
|
|
164
|
+
if (process.env.ARKANALYZER_AST_JSON_SUBPROCESS === '1') {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (process.env.ARKANALYZER_AST_JSON_SUBPROCESS === '0') {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return process.env.VITEST === 'true';
|
|
171
|
+
}
|
|
172
|
+
function getRunArgv() {
|
|
173
|
+
if (!selectedRunArgv) {
|
|
174
|
+
selectedRunArgv = shouldIsolateRuns()
|
|
175
|
+
? runArgvInSubprocess
|
|
176
|
+
: createPersistentWorkerRunner((0, astUtils_1.getAstJsonDumperNodePath)());
|
|
177
|
+
}
|
|
178
|
+
return selectedRunArgv;
|
|
179
|
+
}
|
|
180
|
+
function runAstJsonArgv(argv, context) {
|
|
181
|
+
return getRunArgv()(context, ...argv);
|
|
182
|
+
}
|
|
183
|
+
exports.runAstJsonArgv = runAstJsonArgv;
|