@idlizer/arktscgen 2.1.10-arktscgen-6 → 2.1.10-arktscgen-7
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/build/libarkts-copy/native/meson.build +4 -4
- package/build/libarkts-copy/native/src/{bridges.cc → bridges.cpp} +11 -11
- package/build/libarkts-copy/native/src/{common.cc → common.cpp} +163 -108
- package/build/libarkts-copy/native/src/common.h +22 -22
- package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +9 -3
- package/build/libarkts-copy/package.json +2 -2
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +8 -3
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
- package/build/libarkts-copy/src/arkts-api/index.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/plugins.ts +3 -10
- package/build/libarkts-copy/src/arkts-api/static/global.ts +0 -3
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +7 -34
- package/build/libarkts-copy/src/index.ts +0 -1
- package/build/libarkts-copy/src/plugin-utils.ts +58 -33
- package/build/libarkts-copy/src/reexport-for-generated.ts +1 -1
- package/build/libarkts-copy/tsconfig.json +0 -3
- package/lib/index.js +218 -36
- package/package.json +2 -2
- package/templates/{bridges.cc → bridges.cpp} +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +0 -45
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +0 -1250
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +0 -125
- package/build/libarkts-copy/src/ts-api/index.ts +0 -27
- package/build/libarkts-copy/src/ts-api/static/enums.ts +0 -18
- package/build/libarkts-copy/src/ts-api/types.ts +0 -1075
- package/build/libarkts-copy/src/ts-api/utilities/private.ts +0 -292
- package/build/libarkts-copy/src/ts-api/utilities/public.ts +0 -55
- package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +0 -139
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { KNativePointer } from '@koalaui/interop';
|
|
17
|
-
import {
|
|
17
|
+
import { ETSImportDeclaration, isETSImportDeclaration, Program, Statement } from '../../generated';
|
|
18
18
|
import { passNode, passNodeArray, unpackNonNullableNode } from './utilities/private';
|
|
19
19
|
import { global } from './static/global';
|
|
20
20
|
import { Es2pandaImportFlags, Es2pandaImportKinds } from '../../generated/Es2pandaEnums';
|
|
21
|
-
import { factory } from './factory/nodeFactory';
|
|
22
21
|
|
|
23
22
|
export class ImportStorage {
|
|
24
23
|
// Improve: migrate to wrappers instead of pointers
|
|
@@ -48,12 +47,18 @@ export class ImportStorage {
|
|
|
48
47
|
const newStatements: Statement[] = [];
|
|
49
48
|
for (const statement of statements) {
|
|
50
49
|
if (isETSImportDeclaration(statement) && !this.imports.has(statement.peer)) {
|
|
50
|
+
// Weak workaround to avoid self-imports (see panda issue 31156)
|
|
51
|
+
if (this.program.moduleName == statement.source?.str || this.program.moduleName == `${statement.source?.str}.index`) {
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// On checked state imports from unparsed sources cannot be inserted
|
|
51
56
|
if (!this.isParserState && !this.importSources.has(statement.source?.str)) {
|
|
52
57
|
console.warn('Attempt to insert import from new source after parsed state:');
|
|
53
58
|
console.warn(statement.dumpSrc());
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
const importDeclaration = unpackNonNullableNode<
|
|
61
|
+
const importDeclaration = unpackNonNullableNode<ETSImportDeclaration>(
|
|
57
62
|
// Note: this call is important, we cannot just pass "statement" to "InsertETSImportDeclarationAndParse"
|
|
58
63
|
global.es2panda._ETSParserBuildImportDeclaration(
|
|
59
64
|
global.context,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
TryStatement,
|
|
31
31
|
TSTypeParameter,
|
|
32
32
|
VariableDeclarator,
|
|
33
|
+
OverloadDeclaration,
|
|
33
34
|
} from '../../../generated';
|
|
34
35
|
import { factory as generatedFactory } from '../../../generated/factory';
|
|
35
36
|
import {
|
|
@@ -59,6 +60,7 @@ import { createArrayExpression, updateArrayExpression } from '../node-utilities/
|
|
|
59
60
|
import { updateBlockStatement } from '../node-utilities/BlockStatement';
|
|
60
61
|
import { updateETSModule } from '../node-utilities/ETSModule';
|
|
61
62
|
import { createOpaqueTypeNode } from '../node-utilities/OpaqueTypeNode';
|
|
63
|
+
import { createOverloadDeclaration } from '../node-utilities/OverloadDeclaration';
|
|
62
64
|
|
|
63
65
|
export const factory = {
|
|
64
66
|
...generatedFactory,
|
|
@@ -141,4 +143,6 @@ export const factory = {
|
|
|
141
143
|
updateClassStaticBlock: ClassStaticBlock.updateClassStaticBlock,
|
|
142
144
|
|
|
143
145
|
createOpaqueTypeNode,
|
|
146
|
+
|
|
147
|
+
createOverloadDeclaration,
|
|
144
148
|
};
|
|
@@ -33,7 +33,6 @@ export { GlobalContext } from './peers/Context';
|
|
|
33
33
|
export * from './peers/ExternalSource';
|
|
34
34
|
export * from './peers/Options';
|
|
35
35
|
export * from './node-utilities/ArkTsConfig';
|
|
36
|
-
export * from './node-utilities/Program';
|
|
37
36
|
export * from './peers/ImportPathManager';
|
|
38
37
|
export * from './static/globalUtils';
|
|
39
38
|
export { global as arktsGlobal } from './static/global';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Expression, OverloadDeclaration } from '../../../generated';
|
|
17
|
+
import { Es2pandaOverloadDeclFlags, Es2pandaModifierFlags } from '../../../generated/Es2pandaEnums';
|
|
18
|
+
|
|
19
|
+
export function createOverloadDeclaration(
|
|
20
|
+
key: Expression | undefined,
|
|
21
|
+
overloads: readonly Expression[],
|
|
22
|
+
flags: Es2pandaOverloadDeclFlags,
|
|
23
|
+
modifiers: Es2pandaModifierFlags,
|
|
24
|
+
): OverloadDeclaration {
|
|
25
|
+
const res = OverloadDeclaration.createOverloadDeclaration(key, modifiers);
|
|
26
|
+
res.setOverloadedList(overloads)
|
|
27
|
+
res.addOverloadDeclFlag(flags)
|
|
28
|
+
return res
|
|
29
|
+
}
|
|
@@ -49,7 +49,6 @@ export class Context extends ArktsObject {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
static createFromFile(filePath: string): Context {
|
|
52
|
-
return new Context(global.generatedEs2panda._CreateContextFromStringWithHistory(global.config, passString(filePath), passString(filePath)));
|
|
53
52
|
return new Context(global.generatedEs2panda._CreateContextFromFile(global.config, passString(filePath)));
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -18,7 +18,6 @@ import { ETSModule, Program } from '../../generated';
|
|
|
18
18
|
import { ExternalSource } from './peers/ExternalSource';
|
|
19
19
|
import { KNativePointer, nullptr } from '@koalaui/interop';
|
|
20
20
|
import { global } from './static/global';
|
|
21
|
-
import { RunTransformerHooks } from '../plugin-utils';
|
|
22
21
|
import { Context } from './peers/Context';
|
|
23
22
|
|
|
24
23
|
export interface CompilationOptions {
|
|
@@ -61,6 +60,7 @@ export interface ProjectConfig {
|
|
|
61
60
|
integratedHsp: boolean;
|
|
62
61
|
frameworkMode?: string;
|
|
63
62
|
isUi2abc?: boolean;
|
|
63
|
+
memoPluginOptions?: Object;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface PluginContextBase {
|
|
@@ -84,6 +84,8 @@ export interface PluginContext extends PluginContextBase {
|
|
|
84
84
|
getCodingFilePath(): string | undefined
|
|
85
85
|
|
|
86
86
|
isCoding(): boolean
|
|
87
|
+
|
|
88
|
+
getProjectConfig(): ProjectConfig | undefined
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
|
|
@@ -232,12 +234,3 @@ export function listPrograms(program: Program, filter: (name: string) => boolean
|
|
|
232
234
|
}),
|
|
233
235
|
];
|
|
234
236
|
}
|
|
235
|
-
|
|
236
|
-
export interface PluginEntry {
|
|
237
|
-
name?: string;
|
|
238
|
-
parsed?: (hooks?: RunTransformerHooks) => void;
|
|
239
|
-
checked?: (hooks?: RunTransformerHooks) => void;
|
|
240
|
-
clean?: (hooks?: RunTransformerHooks) => void;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export type PluginInitializer = (parsedJson?: object, checkedJson?: object) => PluginEntry;
|
|
@@ -101,16 +101,16 @@ export class Profiler implements PerformanceData {
|
|
|
101
101
|
this.transformDepStartTime = Date.now();
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
transformEnded(
|
|
104
|
+
transformEnded(): void {
|
|
105
105
|
const transformEndTime = Date.now();
|
|
106
106
|
const consumedTime = transformEndTime - this.transformStartTime;
|
|
107
|
-
this.getPluginData(
|
|
107
|
+
this.getPluginData(this.curPlugin, this.curContextState).transformTime += consumedTime;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
transformDepEnded(
|
|
110
|
+
transformDepEnded(): void {
|
|
111
111
|
const transformEndTime = Date.now();
|
|
112
112
|
const consumedTime = transformEndTime - this.transformDepStartTime;
|
|
113
|
-
this.getPluginData(
|
|
113
|
+
this.getPluginData(this.curPlugin, this.curContextState).transformTimeDeps += consumedTime;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
proceededToState(consumedTime: number) {
|
|
@@ -32,40 +32,6 @@ export const allFlags = Object.values(Es2pandaModifierFlags)
|
|
|
32
32
|
.filter(isNumber)
|
|
33
33
|
.reduce((prev, next) => prev | next, 0);
|
|
34
34
|
|
|
35
|
-
export function assertValidPeer(peer: KPtr, expectedKind: Es2pandaAstNodeType): void {
|
|
36
|
-
if (peer === nullptr) {
|
|
37
|
-
throwError(`invalid peer`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (global.validatePeerTypes) {
|
|
41
|
-
const peerType = global.generatedEs2panda._AstNodeTypeConst(global.context, peer);
|
|
42
|
-
if (
|
|
43
|
-
peerType === Es2pandaAstNodeType.AST_NODE_TYPE_STRUCT_DECLARATION &&
|
|
44
|
-
expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION
|
|
45
|
-
) {
|
|
46
|
-
// Improve: Struct is a child class of Class
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (
|
|
50
|
-
peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_IMPORT_DECLARATION &&
|
|
51
|
-
expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_IMPORT_DECLARATION
|
|
52
|
-
) {
|
|
53
|
-
// Improve: ETSImportDeclaration is a child of a ImportDeclaration
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (
|
|
57
|
-
peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE &&
|
|
58
|
-
expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_BLOCK_STATEMENT
|
|
59
|
-
) {
|
|
60
|
-
// Improve: ETSModule is a child of a BlockStatement
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (peerType !== expectedKind) {
|
|
64
|
-
throwError(`expected: ${Es2pandaAstNodeType[expectedKind]}, got: ${Es2pandaAstNodeType[peerType]}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
35
|
export function acceptNativeObjectArrayResult<T extends ArktsObject>(
|
|
70
36
|
arrayObject: KNativePointer,
|
|
71
37
|
factory: (instance: KNativePointer) => T
|
|
@@ -106,6 +72,13 @@ export function unpackNodeArray<T extends AstNode>(nodesPtr: KNativePointer, typ
|
|
|
106
72
|
return new NativePtrDecoder().decode(nodesPtr).map((peer: KNativePointer) => unpackNonNullableNode(peer, typeHint));
|
|
107
73
|
}
|
|
108
74
|
|
|
75
|
+
export function unpackNativeObjectArray<T extends ArktsObject>(
|
|
76
|
+
arrayObject: KNativePointer,
|
|
77
|
+
factory: (instance: KNativePointer) => T
|
|
78
|
+
): T[] {
|
|
79
|
+
return acceptNativeObjectArrayResult(arrayObject, factory);
|
|
80
|
+
}
|
|
81
|
+
|
|
109
82
|
export function passNodeArray(nodes: readonly ArktsObject[] | undefined): BigUint64Array {
|
|
110
83
|
return new BigUint64Array(nodes?.filter((it) => (!!it.peer))?.map((node) => BigInt(node.peer)) ?? []);
|
|
111
84
|
}
|
|
@@ -28,7 +28,6 @@ export * from './arkts-api/AbstractVisitor';
|
|
|
28
28
|
export * from './arkts-api/plugins';
|
|
29
29
|
export * from './arkts-api/ImportStorage';
|
|
30
30
|
export * from './arkts-api/ProgramProvider';
|
|
31
|
-
export * from './arkts-api/node-utilities/Program';
|
|
32
31
|
export * from './arkts-api/node-utilities/ArkTsConfig';
|
|
33
32
|
|
|
34
33
|
export * from './arkts-api/peers/AstNode';
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
16
18
|
import {
|
|
17
19
|
Es2pandaContextState,
|
|
18
20
|
PluginContext,
|
|
@@ -22,49 +24,24 @@ import {
|
|
|
22
24
|
Program,
|
|
23
25
|
ProgramProvider,
|
|
24
26
|
CompilationOptions,
|
|
25
|
-
|
|
27
|
+
PluginContextImpl,
|
|
26
28
|
} from './arkts-api';
|
|
27
29
|
import { Tracer } from './tracer';
|
|
30
|
+
import { global } from "./arkts-api/static/global";
|
|
28
31
|
|
|
29
32
|
export interface RunTransformerHooks {
|
|
30
33
|
onProgramTransformStart?(options: CompilationOptions, program: Program): void;
|
|
31
34
|
onProgramTransformEnd?(options: CompilationOptions, program: Program): void;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
class
|
|
35
|
-
|
|
36
|
-
constructor() {}
|
|
37
|
-
find(program: Program): boolean {
|
|
38
|
-
return this.processedPrograms.has(program.absoluteName);
|
|
39
|
-
}
|
|
40
|
-
update(program: Program) {
|
|
41
|
-
this.processedPrograms.add(program.absoluteName);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class DumpingHooks implements RunTransformerHooks {
|
|
46
|
-
constructor(
|
|
47
|
-
private state: Es2pandaContextState,
|
|
48
|
-
private pluginName: string,
|
|
49
|
-
private dumpAst: boolean = false
|
|
50
|
-
) {
|
|
51
|
-
if (process.env.KOALA_DUMP_PLUGIN_AST) {
|
|
52
|
-
this.dumpAst = true;
|
|
53
|
-
}
|
|
37
|
+
export class ProfilerHooks implements RunTransformerHooks {
|
|
38
|
+
constructor() {
|
|
54
39
|
}
|
|
55
40
|
onProgramTransformStart(options: CompilationOptions, program: Program) {
|
|
56
|
-
if (this.dumpAst && !program.absoluteName.includes("absolute-sdk-patched")) {
|
|
57
|
-
console.log(`BEFORE ${this.pluginName}:`);
|
|
58
|
-
dumpProgramSrcFormatted(program, true);
|
|
59
|
-
}
|
|
60
41
|
if (!options.isProgramForCodegeneration) arktsGlobal.profiler.transformDepStarted();
|
|
61
42
|
}
|
|
62
43
|
onProgramTransformEnd(options: CompilationOptions, program: Program) {
|
|
63
|
-
if (!options.isProgramForCodegeneration) arktsGlobal.profiler.transformDepEnded(
|
|
64
|
-
if (this.dumpAst && !program.absoluteName.includes("absolute-sdk-patched")) {
|
|
65
|
-
console.log(`AFTER ${this.pluginName}:`);
|
|
66
|
-
dumpProgramSrcFormatted(program, true);
|
|
67
|
-
}
|
|
44
|
+
if (!options.isProgramForCodegeneration) arktsGlobal.profiler.transformDepEnded();
|
|
68
45
|
}
|
|
69
46
|
}
|
|
70
47
|
|
|
@@ -73,8 +50,8 @@ export function runTransformerOnProgram(
|
|
|
73
50
|
options: CompilationOptions,
|
|
74
51
|
transform: ProgramTransformer | undefined,
|
|
75
52
|
pluginContext: PluginContext,
|
|
76
|
-
hooks: RunTransformerHooks
|
|
77
|
-
stableDeps: boolean
|
|
53
|
+
hooks: RunTransformerHooks,
|
|
54
|
+
stableDeps: boolean,
|
|
78
55
|
) {
|
|
79
56
|
arktsGlobal.filePath = program.absoluteName;
|
|
80
57
|
|
|
@@ -108,9 +85,10 @@ export function runTransformer(
|
|
|
108
85
|
state: Es2pandaContextState,
|
|
109
86
|
transform: ProgramTransformer | undefined,
|
|
110
87
|
pluginContext: PluginContext,
|
|
111
|
-
hooks: RunTransformerHooks = {},
|
|
112
88
|
stableDeps: boolean = false,
|
|
113
89
|
) {
|
|
90
|
+
const hooks = new ProfilerHooks()
|
|
91
|
+
|
|
114
92
|
// Program provider used to provide programs to transformer dynamically relative to inserted imports
|
|
115
93
|
const provider = new ProgramProvider(prog, stableDeps);
|
|
116
94
|
|
|
@@ -141,3 +119,50 @@ function isProgramForCodegeneration(program: Program, isMainProgram: boolean): b
|
|
|
141
119
|
}
|
|
142
120
|
return program.isGenAbcForExternal;
|
|
143
121
|
}
|
|
122
|
+
|
|
123
|
+
const isDebugDump: boolean = false;
|
|
124
|
+
|
|
125
|
+
function checkDebugDump() {
|
|
126
|
+
return isDebugDump || process.env.KOALA_DUMP_PLUGIN_AST == "1";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function debugDump(
|
|
130
|
+
dumpDir: string | undefined,
|
|
131
|
+
state: Es2pandaContextState,
|
|
132
|
+
pluginName: string,
|
|
133
|
+
isAfter: boolean,
|
|
134
|
+
program: Program,
|
|
135
|
+
) {
|
|
136
|
+
if (!checkDebugDump()) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!dumpDir) {
|
|
140
|
+
const outDir = global.arktsconfig?.outDir
|
|
141
|
+
if (outDir) {
|
|
142
|
+
dumpDir = path.join(outDir, "../dist/cache")
|
|
143
|
+
} else {
|
|
144
|
+
dumpDir = "dist/cache"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const baseDir = path.join(dumpDir,
|
|
148
|
+
`${state}_${isAfter ? "" : "ORI"}_${pluginName}`
|
|
149
|
+
);
|
|
150
|
+
runTransformer(
|
|
151
|
+
program,
|
|
152
|
+
state,
|
|
153
|
+
(program: Program) => {
|
|
154
|
+
if (program.absoluteName == "") {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
const dumpFilePath = path.join(baseDir, path.sep + program.absoluteName)
|
|
158
|
+
fs.mkdirSync(path.dirname(dumpFilePath), { recursive: true })
|
|
159
|
+
fs.writeFileSync(
|
|
160
|
+
dumpFilePath,
|
|
161
|
+
program.ast.dumpSrc(),
|
|
162
|
+
'utf-8',
|
|
163
|
+
)
|
|
164
|
+
},
|
|
165
|
+
new PluginContextImpl(),
|
|
166
|
+
true,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
@@ -26,8 +26,8 @@ export {
|
|
|
26
26
|
passStringArray,
|
|
27
27
|
unpackNode,
|
|
28
28
|
unpackString,
|
|
29
|
-
assertValidPeer,
|
|
30
29
|
updateNodeByNode,
|
|
30
|
+
unpackNativeObjectArray,
|
|
31
31
|
} from './arkts-api/utilities/private';
|
|
32
32
|
export { nodeByType } from './arkts-api/class-by-peer';
|
|
33
33
|
export { global } from './arkts-api/static/global';
|