@cocos/ccbuild 2.2.5 → 2.2.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/modules/build-engine/lib/engine-js/babel-plugins/decorator-parser.d.ts +2 -0
- package/modules/build-engine/lib/engine-js/babel-plugins/decorator-parser.d.ts.map +1 -0
- package/modules/build-engine/lib/engine-js/babel-plugins/decorator-parser.js +1170 -0
- package/modules/build-engine/lib/engine-js/babel-plugins/decorator-parser.js.map +1 -0
- package/modules/build-engine/lib/engine-js/index.js +60 -29
- package/modules/build-engine/lib/engine-js/index.js.map +1 -1
- package/modules/build-engine/lib/index.d.ts +7 -0
- package/modules/build-engine/lib/index.d.ts.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,1170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable space-before-function-paren */
|
|
4
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
5
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
7
|
+
/* eslint-disable max-len */
|
|
8
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
} : function (o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
});
|
|
24
|
+
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
value: v
|
|
28
|
+
});
|
|
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
|
+
var __importDefault = this && this.__importDefault || function (mod) {
|
|
40
|
+
return mod && mod.__esModule ? mod : {
|
|
41
|
+
"default": mod
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", {
|
|
45
|
+
value: true
|
|
46
|
+
});
|
|
47
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
48
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
49
|
+
const parser = __importStar(require("@babel/parser"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const fs_1 = __importDefault(require("fs"));
|
|
52
|
+
const enginePath = process.env.ENGINE_PATH;
|
|
53
|
+
const applyFnName = `apply`;
|
|
54
|
+
function getParentNodes(path) {
|
|
55
|
+
const parents = [];
|
|
56
|
+
let target = path;
|
|
57
|
+
while (target) {
|
|
58
|
+
parents.push(target.node);
|
|
59
|
+
target = target.parentPath;
|
|
60
|
+
}
|
|
61
|
+
parents.reverse();
|
|
62
|
+
return parents;
|
|
63
|
+
}
|
|
64
|
+
function isInFunctionDeclaration(path) {
|
|
65
|
+
return getParentNodes(path.parentPath).some(parent => parent.type === 'FunctionDeclaration');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* collectt all variables which is defined outside current function and save into `ctx`
|
|
69
|
+
*/
|
|
70
|
+
function collectGlobalVars(code, oldPath, ctx) {
|
|
71
|
+
try {
|
|
72
|
+
const ast = parser.parse(code);
|
|
73
|
+
(0, traverse_1.default)(ast, {
|
|
74
|
+
ReferencedIdentifier(path) {
|
|
75
|
+
const name = path.node.name;
|
|
76
|
+
if (path.scope.hasBinding(name, true)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (name === 'arguments') {
|
|
80
|
+
if (isInFunctionDeclaration(path)) return;
|
|
81
|
+
}
|
|
82
|
+
if (name in globalThis) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (ctx.identifiers.indexOf(path.node.name) === -1) {
|
|
86
|
+
ctx.identifiers.push(path.node.name);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
} catch (e) {
|
|
91
|
+
try {
|
|
92
|
+
const result = visitAst(oldPath);
|
|
93
|
+
mergeArray(ctx.declTypes, result.types);
|
|
94
|
+
mergeArray(ctx.identifiers, result.identifiers);
|
|
95
|
+
} catch (ee) {
|
|
96
|
+
console.error(ee);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* convert decorators to `DecoratorParsedResult[]`
|
|
102
|
+
*/
|
|
103
|
+
function parseNodeDecorators(targetNode, decorators, classCtx) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
const result = [];
|
|
106
|
+
const attrName = (_b = (_a = targetNode === null || targetNode === void 0 ? void 0 : targetNode.key) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
|
|
107
|
+
const attrValue = targetNode.value ? (0, generator_1.default)(targetNode.value).code : 'undefined';
|
|
108
|
+
const isGetterOrSetter = targetNode.kind === 'get' || targetNode.kind === 'set';
|
|
109
|
+
if (targetNode.value) {
|
|
110
|
+
collectGlobalVars(attrValue, targetNode.value, classCtx);
|
|
111
|
+
}
|
|
112
|
+
for (const decor of decorators) {
|
|
113
|
+
if (decor.expression.type === 'CallExpression') {
|
|
114
|
+
const content = {
|
|
115
|
+
decoratorName: decor.expression.callee.name
|
|
116
|
+
};
|
|
117
|
+
content.attrName = attrName;
|
|
118
|
+
content.attrValue = attrValue;
|
|
119
|
+
content.isGetterOrSetter = isGetterOrSetter;
|
|
120
|
+
try {
|
|
121
|
+
const argNodesCode = decor.expression.arguments.map(a => {
|
|
122
|
+
const argCode = (0, generator_1.default)(a).code;
|
|
123
|
+
collectGlobalVars(argCode, a, classCtx);
|
|
124
|
+
return argCode;
|
|
125
|
+
});
|
|
126
|
+
content.decoratorArgs = argNodesCode;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.error(` @[failed]${decor.expression.callee.name} / ${targetNode.key.name}`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
result.push(content);
|
|
132
|
+
} else if (decor.expression.type === 'Identifier') {
|
|
133
|
+
result.push({
|
|
134
|
+
decoratorName: decor.expression.name,
|
|
135
|
+
attrName,
|
|
136
|
+
attrValue,
|
|
137
|
+
isGetterOrSetter
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
console.error(`unknown decorator type ${decor.expression.type}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
// head content for the generated file
|
|
146
|
+
const outputLines = [];
|
|
147
|
+
outputLines.push(`/* This file is generated by script, do not modify it manually. */`);
|
|
148
|
+
outputLines.push('');
|
|
149
|
+
outputLines.push(`/* eslint-disable @typescript-eslint/no-unsafe-return */`);
|
|
150
|
+
outputLines.push(`/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */`);
|
|
151
|
+
outputLines.push(`/* eslint-disable brace-style */`);
|
|
152
|
+
outputLines.push(`/* eslint-disable @typescript-eslint/indent */`);
|
|
153
|
+
outputLines.push(`/* eslint-disable max-len */`);
|
|
154
|
+
outputLines.push(`/* eslint-disable arrow-body-style */`);
|
|
155
|
+
outputLines.push(`/* eslint-disable comma-dangle */`);
|
|
156
|
+
outputLines.push(`/* eslint-disable func-names */`);
|
|
157
|
+
outputLines.push(`/* eslint-disable space-before-function-paren */`);
|
|
158
|
+
outputLines.push('');
|
|
159
|
+
outputLines.push(`import * as $$ from 'cc.decorator';`);
|
|
160
|
+
outputLines.push(`import { _decorator as $ } from '../core';`);
|
|
161
|
+
outputLines.push('');
|
|
162
|
+
outputLines.push(`const defaultExec = (cb: () => void, decorator?: string, attr?: string | null) => { cb(); };`);
|
|
163
|
+
// write lines to file through IPC messages
|
|
164
|
+
function writeLines(lines, className) {
|
|
165
|
+
process.emit('message', {
|
|
166
|
+
event: 'write-decorator',
|
|
167
|
+
lines,
|
|
168
|
+
className
|
|
169
|
+
}, null);
|
|
170
|
+
}
|
|
171
|
+
writeLines(outputLines, '');
|
|
172
|
+
function mergeArray(dst, src) {
|
|
173
|
+
for (const e of src) {
|
|
174
|
+
if (dst.indexOf(e) === -1) {
|
|
175
|
+
dst.push(e);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* generate variable names for property descriptors
|
|
181
|
+
*/
|
|
182
|
+
function allocPropVariable(className, property) {
|
|
183
|
+
return `${property}Descriptor`;
|
|
184
|
+
}
|
|
185
|
+
function nameDecorators(name) {
|
|
186
|
+
if (name.startsWith('rangeM') || name === 'readOnly' || name === 'editorOnly') {
|
|
187
|
+
// these decorators are exported by `import { _decorator as $ } from '../core';`
|
|
188
|
+
// should be referenced from `cc.decorator`
|
|
189
|
+
return `$$.${name}`;
|
|
190
|
+
}
|
|
191
|
+
return `$.${name}`;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* convert class decorator to text
|
|
195
|
+
*/
|
|
196
|
+
function cvtClassDecorators(className) {
|
|
197
|
+
return d => ` ${nameDecorators(d.decoratorName)}${d.decoratorArgs ? `(${d.decoratorArgs.join(',')})` : ''}(${className})`;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* convert property decorator to text
|
|
201
|
+
*/
|
|
202
|
+
function cvtPropDecorators(className, ctx) {
|
|
203
|
+
return d => {
|
|
204
|
+
let gs;
|
|
205
|
+
if (d.isGetterOrSetter) {
|
|
206
|
+
gs = allocPropVariable(className, d.attrName);
|
|
207
|
+
const found = ctx.descriptors.reduce((p, c) => p || c.name === gs, false);
|
|
208
|
+
if (!found) {
|
|
209
|
+
ctx.descriptors.push({
|
|
210
|
+
name: gs,
|
|
211
|
+
decl: `const ${gs} = Object.getOwnPropertyDescriptor(${className}.prototype, '${d.attrName}');`
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return ` ${nameDecorators(d.decoratorName)}${d.decoratorArgs ? `(${d.decoratorArgs.join(',')})` : ''}(${className}.prototype, '${d.attrName}', ${gs || `() => { return ${d.attrValue}; }`})`;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function recordDecorators() {
|
|
219
|
+
return {
|
|
220
|
+
name: 'decorator-collector',
|
|
221
|
+
visitor: {
|
|
222
|
+
ClassDeclaration(nodePath, state) {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
const superClass = nodePath.node.superClass;
|
|
225
|
+
let superClassName = null;
|
|
226
|
+
if (superClass) {
|
|
227
|
+
if (superClass.type === 'Identifier') {
|
|
228
|
+
superClassName = superClass.name;
|
|
229
|
+
} else {
|
|
230
|
+
superClassName = 'others';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (superClassName === 'Component') {
|
|
234
|
+
// filter #1, all sub classes of `Component`
|
|
235
|
+
return;
|
|
236
|
+
} else if (superClassName === 'others') {
|
|
237
|
+
const fileName = (_b = (_a = state === null || state === void 0 ? void 0 : state.file) === null || _a === void 0 ? void 0 : _a.opts) === null || _b === void 0 ? void 0 : _b.filename;
|
|
238
|
+
if (fileName && fileName.indexOf('component') >= 0) {
|
|
239
|
+
// filter #2, skip files which path contains `component` && may be sub class of Compnonet
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const currentClassName = nodePath.node.id.name;
|
|
244
|
+
const classDecoratorNodes = nodePath.node.decorators;
|
|
245
|
+
let classDecoratorResults = [];
|
|
246
|
+
if (!classDecoratorNodes) {
|
|
247
|
+
// filter #3, no decorators for current class
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const cppClasses = getExportedClassesFromCppSourceCode();
|
|
251
|
+
if (!cppClasses.has(currentClassName)) {
|
|
252
|
+
// filter #4, no C++ binding type found with the same name
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const detail = cppClasses.get(currentClassName);
|
|
256
|
+
if (detail.length > 1) {
|
|
257
|
+
console.warn(`class ${currentClassName} has ${detail.length} JSB class: ${detail.map(d => `${d.tip}.${d.name}`).join(', ')}`);
|
|
258
|
+
}
|
|
259
|
+
let classContent = []; // file content to write for current class
|
|
260
|
+
const decoratorCtx = {
|
|
261
|
+
commands: [],
|
|
262
|
+
descriptors: [],
|
|
263
|
+
identifiers: [currentClassName],
|
|
264
|
+
className: currentClassName,
|
|
265
|
+
declTypes: []
|
|
266
|
+
};
|
|
267
|
+
classDecoratorResults = parseNodeDecorators(nodePath.node, classDecoratorNodes, decoratorCtx);
|
|
268
|
+
const classNameByDecorator = classDecoratorResults.filter(x => x.decoratorName === 'ccclass').map(x => x.decoratorArgs[0].replace(/['"]/g, '').replace(/\./g, '_'));
|
|
269
|
+
// filter #5, return if no ccclass found or classes from `sp.` (spine) modules
|
|
270
|
+
// Add more conditions if classes need to be skipped.
|
|
271
|
+
if (classNameByDecorator.length === 0 || classNameByDecorator[0].startsWith('sp_')) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
let classDecorator_Lines = classDecoratorResults.map(cvtClassDecorators(currentClassName));
|
|
275
|
+
classDecorator_Lines = classDecorator_Lines.map((x, idx) => ` ${applyFnName}(() => { ${x.trim()}; }, '${classDecoratorResults[idx].decoratorName}', null);`);
|
|
276
|
+
const ccclassName = classNameByDecorator.length > 0 ? classNameByDecorator[0] : currentClassName;
|
|
277
|
+
const contextArgType = `${ccclassName}_Context_Args`;
|
|
278
|
+
let propDecorator_Lines = [];
|
|
279
|
+
const children = nodePath.node.body.body;
|
|
280
|
+
for (const decro of children) {
|
|
281
|
+
if (decro.decorators) {
|
|
282
|
+
const memberDecorators = parseNodeDecorators(decro, decro.decorators, decoratorCtx);
|
|
283
|
+
let memberLines = memberDecorators.map(cvtPropDecorators(currentClassName, decoratorCtx));
|
|
284
|
+
memberLines = memberLines.map((x, idx) => ` ${applyFnName}(() => { ${x.trim()}; }, '${memberDecorators[idx].decoratorName}', '${memberDecorators[idx].attrName}');`);
|
|
285
|
+
propDecorator_Lines = propDecorator_Lines.concat(memberLines.reverse().join('\n'));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// assemble file content
|
|
289
|
+
classContent.push(`\n//---- class ${ccclassName}`);
|
|
290
|
+
classContent.push(`interface ${contextArgType} {`); // argument type interface defination
|
|
291
|
+
if (decoratorCtx.identifiers.length > 0) {
|
|
292
|
+
for (const id of decoratorCtx.identifiers) {
|
|
293
|
+
classContent.push(` ${id}: any;`); // field for argument type
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
classContent.push(`}`);
|
|
298
|
+
classContent.push(`export function patch_${ccclassName}(ctx: ${contextArgType}, ${applyFnName} = defaultExec) {`);
|
|
299
|
+
for (const tp of decoratorCtx.declTypes) {
|
|
300
|
+
classContent.push(` type ${tp} = any;`); // type alias using in current funtion, set to any type.
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (decoratorCtx.identifiers.length > 0) {
|
|
304
|
+
const contextArgs = decoratorCtx.identifiers;
|
|
305
|
+
classContent.push(` const { ${contextArgs.join(', ')} } = { ...ctx };`); // unpack all variables from argument
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (decoratorCtx.descriptors.length > 0) {
|
|
309
|
+
// local variables for propert descriptors
|
|
310
|
+
classContent = classContent.concat(decoratorCtx.descriptors.map(d => ` ${d.decl}`).join('\n'));
|
|
311
|
+
}
|
|
312
|
+
classContent = classContent.concat(propDecorator_Lines); // property decorators
|
|
313
|
+
classContent = classContent.concat(classDecorator_Lines.reverse().join('\n')); // class decorators
|
|
314
|
+
classContent.push(`} // end of patch_${ccclassName}`);
|
|
315
|
+
writeLines(classContent, ccclassName);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
exports.default = recordDecorators;
|
|
321
|
+
const cppClassMap = new Map();
|
|
322
|
+
function getExportedClassesFromCppSourceCode() {
|
|
323
|
+
if (cppClassMap.size > 0) {
|
|
324
|
+
return cppClassMap;
|
|
325
|
+
}
|
|
326
|
+
const cppSourceFiles = [];
|
|
327
|
+
const toFullPath = prefix => filename => path_1.default.join(prefix, filename);
|
|
328
|
+
const findInDir = filterCb => dir => fs_1.default.readdirSync(dir).filter(filterCb).map(toFullPath(dir)).forEach(fp => cppSourceFiles.push(fp));
|
|
329
|
+
['native/cocos/bindings/manual', 'native/build/generated/cocos/bindings/auto'].map(toFullPath(enginePath)).forEach(findInDir(x => x.startsWith('jsb_') && x.endsWith('.cpp')));
|
|
330
|
+
const se_Class_create = /se::Class::create\((\{("\w+",\s*"\w+")+\}|("\w+"))/;
|
|
331
|
+
const skipChars = /["{}]/;
|
|
332
|
+
console.log('searching for exported classes');
|
|
333
|
+
function trimClassName(x) {
|
|
334
|
+
let start = 0;
|
|
335
|
+
let end = x.length - 1;
|
|
336
|
+
const len = x.length;
|
|
337
|
+
while (start < len && skipChars.test(x[start])) start++;
|
|
338
|
+
while (end > 0 && skipChars.test(x[end])) end--;
|
|
339
|
+
return start < end ? x.substring(start, end + 1) : '';
|
|
340
|
+
}
|
|
341
|
+
function tideClassName(str) {
|
|
342
|
+
return str.split(',').map(x => trimClassName(x.trim()));
|
|
343
|
+
}
|
|
344
|
+
for (const file of cppSourceFiles) {
|
|
345
|
+
fs_1.default.readFileSync(file, 'utf8').split('\n').map(x => x.trim()).filter(x => {
|
|
346
|
+
const createClassR = se_Class_create.exec(x);
|
|
347
|
+
if (createClassR) {
|
|
348
|
+
const pathComps = path_1.default.basename(file).split('_')[1];
|
|
349
|
+
if (pathComps.includes('dragonbone') || pathComps.includes('spine')) {
|
|
350
|
+
// filter #6, skip spine/dragonbones binding source files
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
const classNameComps = tideClassName(createClassR[1] ? createClassR[1] : createClassR[2]);
|
|
354
|
+
const className = classNameComps[classNameComps.length - 1];
|
|
355
|
+
let classItems = cppClassMap.get(className);
|
|
356
|
+
if (!classItems) {
|
|
357
|
+
classItems = [];
|
|
358
|
+
cppClassMap.set(classNameComps[0], classItems);
|
|
359
|
+
}
|
|
360
|
+
classItems.push({
|
|
361
|
+
file,
|
|
362
|
+
name: classNameComps.join('.'),
|
|
363
|
+
tip: pathComps
|
|
364
|
+
});
|
|
365
|
+
if (classItems.length > 1) {
|
|
366
|
+
console.error(`Multiple classes found: ${className} / ${classItems.map(x => `${path_1.default.basename(x.file)}:${x.name}`).join(', ')} . ${file}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return createClassR;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return cppClassMap;
|
|
373
|
+
}
|
|
374
|
+
function debugLog(...args) {
|
|
375
|
+
// console.log.apply(console, args);
|
|
376
|
+
}
|
|
377
|
+
class VisitContext {
|
|
378
|
+
constructor() {
|
|
379
|
+
this.identifiers = [];
|
|
380
|
+
this.types = [];
|
|
381
|
+
}
|
|
382
|
+
addIdentifier(identifier) {
|
|
383
|
+
if (this.identifiers.indexOf(identifier) === -1) {
|
|
384
|
+
this.identifiers.push(identifier);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
addType(type) {
|
|
388
|
+
if (this.types.indexOf(type) === -1) {
|
|
389
|
+
this.types.push(type);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
reset() {
|
|
393
|
+
this.identifiers.length = 0;
|
|
394
|
+
this.types.length = 0;
|
|
395
|
+
}
|
|
396
|
+
dump() {
|
|
397
|
+
if (this.types.length > 0 || this.identifiers.length > 0) {
|
|
398
|
+
console.log(`types: ${this.types.join(',')}`);
|
|
399
|
+
console.log(`identifiers: ${this.identifiers.join(',')}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const context = new VisitContext();
|
|
404
|
+
var p;
|
|
405
|
+
(function (p_1) {
|
|
406
|
+
function Identifier(np) {
|
|
407
|
+
if (np.typeAnnotation) {
|
|
408
|
+
// context.addType(np.typeAnnotation);
|
|
409
|
+
visitAstRecursive(np.typeAnnotation);
|
|
410
|
+
}
|
|
411
|
+
debugLog(`[${np.type}] ${np.name}`);
|
|
412
|
+
}
|
|
413
|
+
p_1.Identifier = Identifier;
|
|
414
|
+
function Import(np) {
|
|
415
|
+
debugLog(`[import]`);
|
|
416
|
+
}
|
|
417
|
+
p_1.Import = Import;
|
|
418
|
+
function StringLiteral(np) {
|
|
419
|
+
debugLog(`[${np.type}] "${np.value}"`);
|
|
420
|
+
}
|
|
421
|
+
p_1.StringLiteral = StringLiteral;
|
|
422
|
+
function SequenceExpression(np) {
|
|
423
|
+
debugLog(`[sequence expression]`);
|
|
424
|
+
for (const d of np.expressions) {
|
|
425
|
+
visitAstRecursive(d);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
p_1.SequenceExpression = SequenceExpression;
|
|
429
|
+
function ClassDeclaration(np) {
|
|
430
|
+
debugLog(`[class def] skipped`);
|
|
431
|
+
}
|
|
432
|
+
p_1.ClassDeclaration = ClassDeclaration;
|
|
433
|
+
function ObjectExpression(np) {
|
|
434
|
+
for (const p of np.properties) {
|
|
435
|
+
visitAstRecursive(p);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
p_1.ObjectExpression = ObjectExpression;
|
|
439
|
+
function ObjectMethod(np) {
|
|
440
|
+
debugLog(`[obj method] ${np.kind}`);
|
|
441
|
+
visitAstRecursive(np.key);
|
|
442
|
+
for (const p of np.params) {
|
|
443
|
+
visitAstRecursive(p);
|
|
444
|
+
}
|
|
445
|
+
visitAstRecursive(np.body);
|
|
446
|
+
if (np.returnType) visitAstRecursive(np.returnType);
|
|
447
|
+
if (np.typeParameters) visitAstRecursive(np.typeParameters);
|
|
448
|
+
}
|
|
449
|
+
p_1.ObjectMethod = ObjectMethod;
|
|
450
|
+
function ObjectProperty(np) {
|
|
451
|
+
debugLog(`[obj property]`);
|
|
452
|
+
visitAstRecursive(np.key);
|
|
453
|
+
visitAstRecursive(np.value);
|
|
454
|
+
}
|
|
455
|
+
p_1.ObjectProperty = ObjectProperty;
|
|
456
|
+
function ExportNamedDeclaration(np) {
|
|
457
|
+
console.error(`[export named] skipped`);
|
|
458
|
+
}
|
|
459
|
+
p_1.ExportNamedDeclaration = ExportNamedDeclaration;
|
|
460
|
+
function ExportDefaultDeclaration(np) {
|
|
461
|
+
console.error(`[export default] skipped`);
|
|
462
|
+
}
|
|
463
|
+
p_1.ExportDefaultDeclaration = ExportDefaultDeclaration;
|
|
464
|
+
function ExportAllDeclaration(np) {
|
|
465
|
+
console.error(`[export all] skipped`);
|
|
466
|
+
}
|
|
467
|
+
p_1.ExportAllDeclaration = ExportAllDeclaration;
|
|
468
|
+
function ExportSpecifier(np) {
|
|
469
|
+
console.error(`[export specifier] skipped`);
|
|
470
|
+
}
|
|
471
|
+
p_1.ExportSpecifier = ExportSpecifier;
|
|
472
|
+
function ImportDeclaration(np) {
|
|
473
|
+
console.error(`[import declaration] skipped`);
|
|
474
|
+
}
|
|
475
|
+
p_1.ImportDeclaration = ImportDeclaration;
|
|
476
|
+
function UpdateExpression(np) {
|
|
477
|
+
debugLog(`[update] ${np.operator}, prefix: ${np.prefix}`);
|
|
478
|
+
visitAstRecursive(np.argument);
|
|
479
|
+
}
|
|
480
|
+
p_1.UpdateExpression = UpdateExpression;
|
|
481
|
+
function ObjectPattern(np) {
|
|
482
|
+
debugLog(`[objectpattern]`);
|
|
483
|
+
for (const p of np.properties) {
|
|
484
|
+
visitAstRecursive(p);
|
|
485
|
+
}
|
|
486
|
+
if (np.typeAnnotation) {
|
|
487
|
+
visitAstRecursive(np.typeAnnotation);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
p_1.ObjectPattern = ObjectPattern;
|
|
491
|
+
function ArrayPattern(np) {
|
|
492
|
+
debugLog(`[arraypattern]`);
|
|
493
|
+
for (const p of np.elements) {
|
|
494
|
+
if (p) {
|
|
495
|
+
// TODO: handle null elements
|
|
496
|
+
visitAstRecursive(p);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (np.typeAnnotation) {
|
|
500
|
+
visitAstRecursive(np.typeAnnotation);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
p_1.ArrayPattern = ArrayPattern;
|
|
504
|
+
function ArrayExpression(np) {
|
|
505
|
+
for (const ele of np.elements) {
|
|
506
|
+
if (ele) visitAstRecursive(ele); // skip null elements?
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
p_1.ArrayExpression = ArrayExpression;
|
|
511
|
+
function ThisExpression(np) {
|
|
512
|
+
debugLog(`[this]`);
|
|
513
|
+
}
|
|
514
|
+
p_1.ThisExpression = ThisExpression;
|
|
515
|
+
function Super(np) {
|
|
516
|
+
debugLog(`[super]`);
|
|
517
|
+
}
|
|
518
|
+
p_1.Super = Super;
|
|
519
|
+
function TSTypeAssertion(np) {
|
|
520
|
+
debugLog(`[type assertion]`);
|
|
521
|
+
visitAstRecursive(np.typeAnnotation);
|
|
522
|
+
visitAstRecursive(np.expression);
|
|
523
|
+
}
|
|
524
|
+
p_1.TSTypeAssertion = TSTypeAssertion;
|
|
525
|
+
function TSPropertySignature(np) {
|
|
526
|
+
debugLog(`[ts prop]`);
|
|
527
|
+
visitAstRecursive(np.key);
|
|
528
|
+
if (np.initializer) visitAstRecursive(np.initializer);
|
|
529
|
+
if (np.typeAnnotation) visitAstRecursive(np.typeAnnotation);
|
|
530
|
+
}
|
|
531
|
+
p_1.TSPropertySignature = TSPropertySignature;
|
|
532
|
+
function TSMethodSignature(np) {
|
|
533
|
+
debugLog(`[ts method]`);
|
|
534
|
+
visitAstRecursive(np.key);
|
|
535
|
+
for (const p of np.parameters) {
|
|
536
|
+
visitAstRecursive(p);
|
|
537
|
+
}
|
|
538
|
+
if (np.typeParameters) visitAstRecursive(np.typeParameters);
|
|
539
|
+
if (np.typeAnnotation) visitAstRecursive(np.typeAnnotation);
|
|
540
|
+
}
|
|
541
|
+
p_1.TSMethodSignature = TSMethodSignature;
|
|
542
|
+
function TSIndexSignature(np) {
|
|
543
|
+
debugLog(`[ts index]`);
|
|
544
|
+
for (const p of np.parameters) {
|
|
545
|
+
visitAstRecursive(p);
|
|
546
|
+
}
|
|
547
|
+
if (np.typeAnnotation) visitAstRecursive(np.typeAnnotation);
|
|
548
|
+
}
|
|
549
|
+
p_1.TSIndexSignature = TSIndexSignature;
|
|
550
|
+
function MemberExpression(np) {
|
|
551
|
+
debugLog(`[member]: optional ${np.optional}`);
|
|
552
|
+
visitAstRecursive(np.object);
|
|
553
|
+
visitAstRecursive(np.property);
|
|
554
|
+
if (np.object.type === 'Identifier') {
|
|
555
|
+
context.addIdentifier(np.object.name);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
p_1.MemberExpression = MemberExpression;
|
|
559
|
+
function OptionalMemberExpression(np) {
|
|
560
|
+
debugLog(`[optional-member]: optional ${np.optional}`);
|
|
561
|
+
visitAstRecursive(np.object);
|
|
562
|
+
visitAstRecursive(np.property);
|
|
563
|
+
}
|
|
564
|
+
p_1.OptionalMemberExpression = OptionalMemberExpression;
|
|
565
|
+
function VariableDeclaration(np) {
|
|
566
|
+
debugLog(`[var] ${np.kind}`);
|
|
567
|
+
for (const v of np.declarations) {
|
|
568
|
+
visitAstRecursive(v);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
p_1.VariableDeclaration = VariableDeclaration;
|
|
572
|
+
function TSQualifiedName(np) {
|
|
573
|
+
debugLog(`[qualified]`);
|
|
574
|
+
visitAstRecursive(np.left);
|
|
575
|
+
visitAstRecursive(np.right);
|
|
576
|
+
}
|
|
577
|
+
p_1.TSQualifiedName = TSQualifiedName;
|
|
578
|
+
function VariableDeclarator(np) {
|
|
579
|
+
debugLog(`[var instant] definite ${np.definite}`);
|
|
580
|
+
visitAstRecursive(np.id);
|
|
581
|
+
if (np.init) visitAstRecursive(np.init);
|
|
582
|
+
}
|
|
583
|
+
p_1.VariableDeclarator = VariableDeclarator;
|
|
584
|
+
function FunctionExpression(np) {
|
|
585
|
+
debugLog(`[function]`);
|
|
586
|
+
if (np.id) {
|
|
587
|
+
visitAstRecursive(np.id);
|
|
588
|
+
}
|
|
589
|
+
// param
|
|
590
|
+
if (np.params) {
|
|
591
|
+
for (const p of np.params) {
|
|
592
|
+
visitAstRecursive(p);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
// body
|
|
596
|
+
if (np.body) {
|
|
597
|
+
visitAstRecursive(np.body);
|
|
598
|
+
}
|
|
599
|
+
if (np.returnType) {
|
|
600
|
+
visitAstRecursive(np.returnType);
|
|
601
|
+
}
|
|
602
|
+
if (np.typeParameters) {
|
|
603
|
+
visitAstRecursive(np.typeParameters);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
p_1.FunctionExpression = FunctionExpression;
|
|
607
|
+
function ArrowFunctionExpression(np) {
|
|
608
|
+
debugLog(`[arrow-function]`);
|
|
609
|
+
// param
|
|
610
|
+
for (const p of np.params) {
|
|
611
|
+
if (p) visitAstRecursive(p); // null should be acceptable
|
|
612
|
+
}
|
|
613
|
+
// body
|
|
614
|
+
visitAstRecursive(np.body);
|
|
615
|
+
if (np.returnType) {
|
|
616
|
+
visitAstRecursive(np.returnType);
|
|
617
|
+
}
|
|
618
|
+
if (np.typeParameters) {
|
|
619
|
+
visitAstRecursive(np.typeParameters);
|
|
620
|
+
}
|
|
621
|
+
if (np.predicate) {
|
|
622
|
+
visitAstRecursive(np.predicate);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
p_1.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
626
|
+
function NewExpression(np) {
|
|
627
|
+
debugLog(`[new]`);
|
|
628
|
+
visitAstRecursive(np.callee);
|
|
629
|
+
for (const p of np.arguments) {
|
|
630
|
+
visitAstRecursive(p);
|
|
631
|
+
}
|
|
632
|
+
if (np.typeArguments) {
|
|
633
|
+
visitAstRecursive(np.typeArguments);
|
|
634
|
+
}
|
|
635
|
+
if (np.typeParameters) {
|
|
636
|
+
visitAstRecursive(np.typeParameters);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
p_1.NewExpression = NewExpression;
|
|
640
|
+
function TryStatement(np) {
|
|
641
|
+
debugLog(`[TryStatement]`);
|
|
642
|
+
visitAstRecursive(np.block);
|
|
643
|
+
if (np.handler) visitAstRecursive(np.handler);
|
|
644
|
+
if (np.finalizer) visitAstRecursive(np.finalizer);
|
|
645
|
+
}
|
|
646
|
+
p_1.TryStatement = TryStatement;
|
|
647
|
+
function CatchClause(np) {
|
|
648
|
+
debugLog(`[CatchClause]`);
|
|
649
|
+
if (np.param) visitAstRecursive(np.param);
|
|
650
|
+
visitAstRecursive(np.body);
|
|
651
|
+
}
|
|
652
|
+
p_1.CatchClause = CatchClause;
|
|
653
|
+
function BlockStatement(np) {
|
|
654
|
+
debugLog(`[block]`);
|
|
655
|
+
for (const d of np.directives) {
|
|
656
|
+
visitAstRecursive(d);
|
|
657
|
+
}
|
|
658
|
+
for (const p of np.body) {
|
|
659
|
+
visitAstRecursive(p);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
p_1.BlockStatement = BlockStatement;
|
|
663
|
+
function ExpressionStatement(np) {
|
|
664
|
+
debugLog(`[expression]`);
|
|
665
|
+
visitAstRecursive(np.expression);
|
|
666
|
+
}
|
|
667
|
+
p_1.ExpressionStatement = ExpressionStatement;
|
|
668
|
+
function CallExpression(np) {
|
|
669
|
+
debugLog(`[call]`);
|
|
670
|
+
visitAstRecursive(np.callee);
|
|
671
|
+
for (const a of np.arguments) {
|
|
672
|
+
visitAstRecursive(a);
|
|
673
|
+
}
|
|
674
|
+
if (np.typeArguments) {
|
|
675
|
+
visitAstRecursive(np.typeArguments);
|
|
676
|
+
}
|
|
677
|
+
if (np.typeParameters) {
|
|
678
|
+
visitAstRecursive(np.typeParameters);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
p_1.CallExpression = CallExpression;
|
|
682
|
+
function OptionalCallExpression(np) {
|
|
683
|
+
debugLog(`[optional call?]`);
|
|
684
|
+
visitAstRecursive(np.callee);
|
|
685
|
+
for (const a of np.arguments) {
|
|
686
|
+
visitAstRecursive(a);
|
|
687
|
+
}
|
|
688
|
+
if (np.typeArguments) {
|
|
689
|
+
visitAstRecursive(np.typeArguments);
|
|
690
|
+
}
|
|
691
|
+
if (np.typeParameters) {
|
|
692
|
+
visitAstRecursive(np.typeParameters);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
p_1.OptionalCallExpression = OptionalCallExpression;
|
|
696
|
+
function AssignmentPattern(np) {
|
|
697
|
+
debugLog(`[assignment pattern] optional: ${np.optional}`);
|
|
698
|
+
visitAstRecursive(np.left);
|
|
699
|
+
visitAstRecursive(np.right);
|
|
700
|
+
if (np.typeAnnotation) {
|
|
701
|
+
visitAstRecursive(np.typeAnnotation);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
p_1.AssignmentPattern = AssignmentPattern;
|
|
705
|
+
function AssignmentExpression(np) {
|
|
706
|
+
debugLog(`[assignment] ${np.operator}`);
|
|
707
|
+
visitAstRecursive(np.left);
|
|
708
|
+
visitAstRecursive(np.right);
|
|
709
|
+
}
|
|
710
|
+
p_1.AssignmentExpression = AssignmentExpression;
|
|
711
|
+
function RestElement(np) {
|
|
712
|
+
debugLog(`[rest element] optional: ${np.optional}`);
|
|
713
|
+
visitAstRecursive(np.argument);
|
|
714
|
+
if (np.typeAnnotation) {
|
|
715
|
+
visitAstRecursive(np.typeAnnotation);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
p_1.RestElement = RestElement;
|
|
719
|
+
function SpreadElement(np) {
|
|
720
|
+
debugLog(`[spread]`);
|
|
721
|
+
visitAstRecursive(np.argument);
|
|
722
|
+
}
|
|
723
|
+
p_1.SpreadElement = SpreadElement;
|
|
724
|
+
function LogicalExpression(np) {
|
|
725
|
+
debugLog(`[logical] ${np.operator}`);
|
|
726
|
+
visitAstRecursive(np.left);
|
|
727
|
+
visitAstRecursive(np.right);
|
|
728
|
+
}
|
|
729
|
+
p_1.LogicalExpression = LogicalExpression;
|
|
730
|
+
function ConditionalExpression(np) {
|
|
731
|
+
debugLog(`[conditional] ${np.test}`);
|
|
732
|
+
visitAstRecursive(np.test);
|
|
733
|
+
visitAstRecursive(np.consequent);
|
|
734
|
+
visitAstRecursive(np.alternate);
|
|
735
|
+
}
|
|
736
|
+
p_1.ConditionalExpression = ConditionalExpression;
|
|
737
|
+
function BinaryExpression(np) {
|
|
738
|
+
debugLog(`[binary] ${np.operator}`);
|
|
739
|
+
visitAstRecursive(np.left);
|
|
740
|
+
visitAstRecursive(np.right);
|
|
741
|
+
}
|
|
742
|
+
p_1.BinaryExpression = BinaryExpression;
|
|
743
|
+
function SwitchStatement(np) {
|
|
744
|
+
debugLog(`[switch]`);
|
|
745
|
+
visitAstRecursive(np.discriminant);
|
|
746
|
+
for (const c of np.cases) {
|
|
747
|
+
visitAstRecursive(c);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
p_1.SwitchStatement = SwitchStatement;
|
|
751
|
+
function SwitchCase(np) {
|
|
752
|
+
debugLog(`[switch cast]`);
|
|
753
|
+
if (np.test) visitAstRecursive(np.test);
|
|
754
|
+
for (const c of np.consequent) {
|
|
755
|
+
visitAstRecursive(c);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
p_1.SwitchCase = SwitchCase;
|
|
759
|
+
function ThrowStatement(np) {
|
|
760
|
+
debugLog(`[throw]`);
|
|
761
|
+
visitAstRecursive(np.argument);
|
|
762
|
+
}
|
|
763
|
+
p_1.ThrowStatement = ThrowStatement;
|
|
764
|
+
function BreakStatement(np) {
|
|
765
|
+
debugLog(`[break]`);
|
|
766
|
+
if (np.label) visitAstRecursive(np.label);
|
|
767
|
+
}
|
|
768
|
+
p_1.BreakStatement = BreakStatement;
|
|
769
|
+
function ContinueStatement(np) {
|
|
770
|
+
debugLog(`[continue]`);
|
|
771
|
+
if (np.label) visitAstRecursive(np.label);
|
|
772
|
+
}
|
|
773
|
+
p_1.ContinueStatement = ContinueStatement;
|
|
774
|
+
function LabeledStatement(np) {
|
|
775
|
+
debugLog(`[label]`);
|
|
776
|
+
visitAstRecursive(np.label);
|
|
777
|
+
visitAstRecursive(np.body);
|
|
778
|
+
}
|
|
779
|
+
p_1.LabeledStatement = LabeledStatement;
|
|
780
|
+
function YieldExpression(np) {
|
|
781
|
+
debugLog(`[yield] delegate ${np.delegate}`);
|
|
782
|
+
if (np.argument) visitAstRecursive(np.argument);
|
|
783
|
+
}
|
|
784
|
+
p_1.YieldExpression = YieldExpression;
|
|
785
|
+
function AwaitExpression(np) {
|
|
786
|
+
debugLog(`[await]`);
|
|
787
|
+
visitAstRecursive(np.argument);
|
|
788
|
+
}
|
|
789
|
+
p_1.AwaitExpression = AwaitExpression;
|
|
790
|
+
function IfStatement(np) {
|
|
791
|
+
debugLog(`[if]`);
|
|
792
|
+
visitAstRecursive(np.test);
|
|
793
|
+
visitAstRecursive(np.consequent);
|
|
794
|
+
if (np.alternate) {
|
|
795
|
+
visitAstRecursive(np.alternate);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
p_1.IfStatement = IfStatement;
|
|
799
|
+
function DoWhileStatement(np) {
|
|
800
|
+
debugLog(`[do while]`);
|
|
801
|
+
visitAstRecursive(np.body);
|
|
802
|
+
visitAstRecursive(np.test);
|
|
803
|
+
}
|
|
804
|
+
p_1.DoWhileStatement = DoWhileStatement;
|
|
805
|
+
function WhileStatement(np) {
|
|
806
|
+
debugLog(`[while]`);
|
|
807
|
+
visitAstRecursive(np.test);
|
|
808
|
+
visitAstRecursive(np.body);
|
|
809
|
+
}
|
|
810
|
+
p_1.WhileStatement = WhileStatement;
|
|
811
|
+
function ForInStatement(np) {
|
|
812
|
+
debugLog(`[for in]`);
|
|
813
|
+
visitAstRecursive(np.left);
|
|
814
|
+
visitAstRecursive(np.right);
|
|
815
|
+
visitAstRecursive(np.body);
|
|
816
|
+
}
|
|
817
|
+
p_1.ForInStatement = ForInStatement;
|
|
818
|
+
function ForOfStatement(np) {
|
|
819
|
+
debugLog(`[for of]`);
|
|
820
|
+
visitAstRecursive(np.left);
|
|
821
|
+
visitAstRecursive(np.right);
|
|
822
|
+
visitAstRecursive(np.body);
|
|
823
|
+
}
|
|
824
|
+
p_1.ForOfStatement = ForOfStatement;
|
|
825
|
+
function ForStatement(np) {
|
|
826
|
+
debugLog(`[for]`);
|
|
827
|
+
if (np.init) visitAstRecursive(np.init);
|
|
828
|
+
if (np.test) visitAstRecursive(np.test);
|
|
829
|
+
if (np.update) visitAstRecursive(np.update);
|
|
830
|
+
visitAstRecursive(np.body);
|
|
831
|
+
}
|
|
832
|
+
p_1.ForStatement = ForStatement;
|
|
833
|
+
function ReturnStatement(np) {
|
|
834
|
+
debugLog(`[return]`);
|
|
835
|
+
if (np.argument) {
|
|
836
|
+
visitAstRecursive(np.argument);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
p_1.ReturnStatement = ReturnStatement;
|
|
840
|
+
function TSTypeParameterDeclaration(np) {
|
|
841
|
+
debugLog(`[parameter decl]`);
|
|
842
|
+
for (const p of np.params) {
|
|
843
|
+
visitAstRecursive(p);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
p_1.TSTypeParameterDeclaration = TSTypeParameterDeclaration;
|
|
847
|
+
function TSTypeParameter(np) {
|
|
848
|
+
debugLog(`[type parameter] ${np.name}, const ${np.const}, in: ${np.in}, out: ${np.out}`);
|
|
849
|
+
if (np.constraint) visitAstRecursive(np.constraint);
|
|
850
|
+
if (np.default) visitAstRecursive(np.default);
|
|
851
|
+
}
|
|
852
|
+
p_1.TSTypeParameter = TSTypeParameter;
|
|
853
|
+
function TSNonNullExpression(np) {
|
|
854
|
+
debugLog(`[non-null]`);
|
|
855
|
+
visitAstRecursive(np.expression);
|
|
856
|
+
}
|
|
857
|
+
p_1.TSNonNullExpression = TSNonNullExpression;
|
|
858
|
+
function FunctionDeclaration(np) {
|
|
859
|
+
debugLog(`[function-decl]`);
|
|
860
|
+
if (np.id) visitAstRecursive(np.id);
|
|
861
|
+
for (const p of np.params) {
|
|
862
|
+
visitAstRecursive(p);
|
|
863
|
+
}
|
|
864
|
+
visitAstRecursive(np.body);
|
|
865
|
+
if (np.returnType) {
|
|
866
|
+
visitAstRecursive(np.returnType);
|
|
867
|
+
}
|
|
868
|
+
if (np.typeParameters) {
|
|
869
|
+
visitAstRecursive(np.typeParameters);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
p_1.FunctionDeclaration = FunctionDeclaration;
|
|
873
|
+
function TSAsExpression(np) {
|
|
874
|
+
debugLog(`[as]`);
|
|
875
|
+
visitAstRecursive(np.expression);
|
|
876
|
+
visitAstRecursive(np.typeAnnotation);
|
|
877
|
+
}
|
|
878
|
+
p_1.TSAsExpression = TSAsExpression;
|
|
879
|
+
function TSTypeAnnotation(np) {
|
|
880
|
+
debugLog(`[typeAnnotation]`);
|
|
881
|
+
visitAstRecursive(np.typeAnnotation);
|
|
882
|
+
}
|
|
883
|
+
p_1.TSTypeAnnotation = TSTypeAnnotation;
|
|
884
|
+
function TSTypeParameterInstantiation(np) {
|
|
885
|
+
debugLog(`[type-instantiation]`);
|
|
886
|
+
for (const t of np.params) {
|
|
887
|
+
visitAstRecursive(t);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
p_1.TSTypeParameterInstantiation = TSTypeParameterInstantiation;
|
|
891
|
+
function TSType(np) {}
|
|
892
|
+
p_1.TSType = TSType;
|
|
893
|
+
function TSAnyKeyword(np) {
|
|
894
|
+
debugLog(`[TSType] any`);
|
|
895
|
+
}
|
|
896
|
+
p_1.TSAnyKeyword = TSAnyKeyword;
|
|
897
|
+
function TSBooleanKeyword(np) {
|
|
898
|
+
debugLog(`[TSType] boolean`);
|
|
899
|
+
}
|
|
900
|
+
p_1.TSBooleanKeyword = TSBooleanKeyword;
|
|
901
|
+
function TSBigIntKeyword(np) {
|
|
902
|
+
debugLog(`[TSType] BigInt`);
|
|
903
|
+
}
|
|
904
|
+
p_1.TSBigIntKeyword = TSBigIntKeyword;
|
|
905
|
+
function TSIntrinsicKeyword(np) {
|
|
906
|
+
debugLog(`[TSType] instrinsic`);
|
|
907
|
+
}
|
|
908
|
+
p_1.TSIntrinsicKeyword = TSIntrinsicKeyword;
|
|
909
|
+
function TSNeverKeyword(np) {
|
|
910
|
+
debugLog(`[TSType] never`);
|
|
911
|
+
}
|
|
912
|
+
p_1.TSNeverKeyword = TSNeverKeyword;
|
|
913
|
+
function TSNullKeyword(np) {
|
|
914
|
+
debugLog(`[TSType] null`);
|
|
915
|
+
}
|
|
916
|
+
p_1.TSNullKeyword = TSNullKeyword;
|
|
917
|
+
function TSNumberKeyword(np) {
|
|
918
|
+
debugLog(`[TSType] number`);
|
|
919
|
+
}
|
|
920
|
+
p_1.TSNumberKeyword = TSNumberKeyword;
|
|
921
|
+
function TSObjectKeyword(np) {
|
|
922
|
+
debugLog(`[TSType] object`);
|
|
923
|
+
}
|
|
924
|
+
p_1.TSObjectKeyword = TSObjectKeyword;
|
|
925
|
+
function TSStringKeyword(np) {
|
|
926
|
+
debugLog(`[TSType] string`);
|
|
927
|
+
}
|
|
928
|
+
p_1.TSStringKeyword = TSStringKeyword;
|
|
929
|
+
function TSSymbolKeyword(np) {
|
|
930
|
+
debugLog(`[TSType] symbol`);
|
|
931
|
+
}
|
|
932
|
+
p_1.TSSymbolKeyword = TSSymbolKeyword;
|
|
933
|
+
function TSUndefinedKeyword(np) {
|
|
934
|
+
debugLog(`[TSType] undefined`);
|
|
935
|
+
}
|
|
936
|
+
p_1.TSUndefinedKeyword = TSUndefinedKeyword;
|
|
937
|
+
function TSUnknownKeyword(np) {
|
|
938
|
+
debugLog(`[TSType] unknown`);
|
|
939
|
+
}
|
|
940
|
+
p_1.TSUnknownKeyword = TSUnknownKeyword;
|
|
941
|
+
function TSVoidKeyword(np) {
|
|
942
|
+
debugLog(`[TSType] void`);
|
|
943
|
+
}
|
|
944
|
+
p_1.TSVoidKeyword = TSVoidKeyword;
|
|
945
|
+
function TSThisType(np) {
|
|
946
|
+
debugLog(`[TSType] this`);
|
|
947
|
+
}
|
|
948
|
+
p_1.TSThisType = TSThisType;
|
|
949
|
+
function TSFunctionType(np) {
|
|
950
|
+
if (np.typeParameters) {
|
|
951
|
+
visitAstRecursive(np.typeParameters);
|
|
952
|
+
}
|
|
953
|
+
for (const p of np.parameters) {
|
|
954
|
+
visitAstRecursive(p);
|
|
955
|
+
}
|
|
956
|
+
if (np.typeAnnotation) {
|
|
957
|
+
visitAstRecursive(np.typeAnnotation);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
p_1.TSFunctionType = TSFunctionType;
|
|
961
|
+
function TSConstructorType(np) {
|
|
962
|
+
console.error(`[TSType] constructor not allowed`);
|
|
963
|
+
}
|
|
964
|
+
p_1.TSConstructorType = TSConstructorType;
|
|
965
|
+
function TSTypeReference(np) {
|
|
966
|
+
visitAstRecursive(np.typeName);
|
|
967
|
+
if (np.typeName.type === 'Identifier') {
|
|
968
|
+
context.addType(np.typeName.name);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
p_1.TSTypeReference = TSTypeReference;
|
|
972
|
+
function TSTypePredicate(np) {
|
|
973
|
+
visitAstRecursive(np.parameterName);
|
|
974
|
+
if (np.typeAnnotation) visitAstRecursive(np.typeAnnotation);
|
|
975
|
+
}
|
|
976
|
+
p_1.TSTypePredicate = TSTypePredicate;
|
|
977
|
+
function TSTypeQuery(np) {
|
|
978
|
+
visitAstRecursive(np.exprName);
|
|
979
|
+
if (np.typeParameters) {
|
|
980
|
+
visitAstRecursive(np.typeParameters);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
p_1.TSTypeQuery = TSTypeQuery;
|
|
984
|
+
function TemplateLiteral(np) {
|
|
985
|
+
debugLog(`[Template literal]`);
|
|
986
|
+
for (const e of np.quasis) {
|
|
987
|
+
visitAstRecursive(e);
|
|
988
|
+
}
|
|
989
|
+
for (const e of np.expressions) {
|
|
990
|
+
visitAstRecursive(e);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
p_1.TemplateLiteral = TemplateLiteral;
|
|
994
|
+
function TemplateElement(np) {
|
|
995
|
+
debugLog(`[templ element] raw: ${np.value.raw}, cooked: ${np.value.cooked}, tail: ${np.tail}`);
|
|
996
|
+
}
|
|
997
|
+
p_1.TemplateElement = TemplateElement;
|
|
998
|
+
function TSTypeLiteral(np) {
|
|
999
|
+
debugLog(`[TSType] type literal`);
|
|
1000
|
+
for (const p of np.members) {
|
|
1001
|
+
visitAstRecursive(p);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
p_1.TSTypeLiteral = TSTypeLiteral;
|
|
1005
|
+
function TSArrayType(np) {
|
|
1006
|
+
debugLog(`[TSType] array`);
|
|
1007
|
+
visitAstRecursive(np.elementType);
|
|
1008
|
+
}
|
|
1009
|
+
p_1.TSArrayType = TSArrayType;
|
|
1010
|
+
function TSTupleType(np) {
|
|
1011
|
+
debugLog(`[TSType] tuple`);
|
|
1012
|
+
for (const p of np.elementTypes) {
|
|
1013
|
+
visitAstRecursive(p);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
p_1.TSTupleType = TSTupleType;
|
|
1017
|
+
function TSOptionalType(np) {
|
|
1018
|
+
debugLog(`[TSType] optional`);
|
|
1019
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1020
|
+
}
|
|
1021
|
+
p_1.TSOptionalType = TSOptionalType;
|
|
1022
|
+
function TSRestType(np) {
|
|
1023
|
+
debugLog(`[TSType] rest`);
|
|
1024
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1025
|
+
}
|
|
1026
|
+
p_1.TSRestType = TSRestType;
|
|
1027
|
+
function TSUnionType(np) {
|
|
1028
|
+
debugLog(`[TSType] union`);
|
|
1029
|
+
for (const p of np.types) {
|
|
1030
|
+
visitAstRecursive(p);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
p_1.TSUnionType = TSUnionType;
|
|
1034
|
+
function TSIntersectionType(np) {
|
|
1035
|
+
debugLog(`[TSType] intersection`);
|
|
1036
|
+
for (const p of np.types) {
|
|
1037
|
+
visitAstRecursive(p);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
p_1.TSIntersectionType = TSIntersectionType;
|
|
1041
|
+
function TSConditionalType(np) {
|
|
1042
|
+
debugLog(`[TSType] conditonal`);
|
|
1043
|
+
visitAstRecursive(np.checkType);
|
|
1044
|
+
visitAstRecursive(np.extendsType);
|
|
1045
|
+
visitAstRecursive(np.trueType);
|
|
1046
|
+
visitAstRecursive(np.falseType);
|
|
1047
|
+
}
|
|
1048
|
+
p_1.TSConditionalType = TSConditionalType;
|
|
1049
|
+
function TSInferType(np) {
|
|
1050
|
+
debugLog(`[TSType] infer`);
|
|
1051
|
+
visitAstRecursive(np.typeParameter);
|
|
1052
|
+
}
|
|
1053
|
+
p_1.TSInferType = TSInferType;
|
|
1054
|
+
function TSParenthesizedType(np) {
|
|
1055
|
+
debugLog(`[TSType] parenthesized`);
|
|
1056
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1057
|
+
}
|
|
1058
|
+
p_1.TSParenthesizedType = TSParenthesizedType;
|
|
1059
|
+
function TSTypeOperator(np) {
|
|
1060
|
+
debugLog(`[TSType] operator ${np.operator}`);
|
|
1061
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1062
|
+
}
|
|
1063
|
+
p_1.TSTypeOperator = TSTypeOperator;
|
|
1064
|
+
function TSIndexedAccessType(np) {
|
|
1065
|
+
debugLog(`[TSType] index access`);
|
|
1066
|
+
visitAstRecursive(np.objectType);
|
|
1067
|
+
visitAstRecursive(np.indexType);
|
|
1068
|
+
}
|
|
1069
|
+
p_1.TSIndexedAccessType = TSIndexedAccessType;
|
|
1070
|
+
function TSMappedType(np) {
|
|
1071
|
+
debugLog(`[TSType] mapped`);
|
|
1072
|
+
visitAstRecursive(np.typeParameter);
|
|
1073
|
+
if (np.typeAnnotation) {
|
|
1074
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1075
|
+
}
|
|
1076
|
+
if (np.nameType) {
|
|
1077
|
+
visitAstRecursive(np.nameType);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
p_1.TSMappedType = TSMappedType;
|
|
1081
|
+
function TSLiteralType(np) {
|
|
1082
|
+
debugLog(`[TSType] literal`);
|
|
1083
|
+
visitAstRecursive(np.literal);
|
|
1084
|
+
}
|
|
1085
|
+
p_1.TSLiteralType = TSLiteralType;
|
|
1086
|
+
function TSExpressionWithTypeArguments(np) {
|
|
1087
|
+
debugLog(`[TSType] expression with type arguments`);
|
|
1088
|
+
visitAstRecursive(np.expression);
|
|
1089
|
+
if (np.typeParameters) {
|
|
1090
|
+
visitAstRecursive(np.typeParameters);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
p_1.TSExpressionWithTypeArguments = TSExpressionWithTypeArguments;
|
|
1094
|
+
function TSImportType(np) {
|
|
1095
|
+
console.error(`[TSType ] should skip import`);
|
|
1096
|
+
}
|
|
1097
|
+
p_1.TSImportType = TSImportType;
|
|
1098
|
+
function BooleanLiteral(np) {
|
|
1099
|
+
debugLog(`[bool] ${np.value}`);
|
|
1100
|
+
}
|
|
1101
|
+
p_1.BooleanLiteral = BooleanLiteral;
|
|
1102
|
+
function NumericLiteral(np) {
|
|
1103
|
+
debugLog(`[numberic] ${np.value}`);
|
|
1104
|
+
}
|
|
1105
|
+
p_1.NumericLiteral = NumericLiteral;
|
|
1106
|
+
function NullLiteral(np) {
|
|
1107
|
+
debugLog(`[null]`);
|
|
1108
|
+
}
|
|
1109
|
+
p_1.NullLiteral = NullLiteral;
|
|
1110
|
+
function RegExpLiteral(np) {
|
|
1111
|
+
debugLog(`[regexp] ${np.pattern} / ${np.flags}`);
|
|
1112
|
+
}
|
|
1113
|
+
p_1.RegExpLiteral = RegExpLiteral;
|
|
1114
|
+
function UnaryExpression(np) {
|
|
1115
|
+
debugLog(`[unary] ${np.operator}, prefix: ${np.prefix}`);
|
|
1116
|
+
visitAstRecursive(np.argument);
|
|
1117
|
+
}
|
|
1118
|
+
p_1.UnaryExpression = UnaryExpression;
|
|
1119
|
+
function Directive(np) {
|
|
1120
|
+
debugLog(`[directive] ${np.value}`);
|
|
1121
|
+
}
|
|
1122
|
+
p_1.Directive = Directive;
|
|
1123
|
+
function DirectiveLiteral(np) {
|
|
1124
|
+
debugLog(`[directive literal] ${np.value}`);
|
|
1125
|
+
}
|
|
1126
|
+
p_1.DirectiveLiteral = DirectiveLiteral;
|
|
1127
|
+
function EmptyStatement(np) {
|
|
1128
|
+
debugLog(`[empty]`);
|
|
1129
|
+
}
|
|
1130
|
+
p_1.EmptyStatement = EmptyStatement;
|
|
1131
|
+
function TSTypeAliasDeclaration(np) {
|
|
1132
|
+
debugLog(`[type alias] declare ${np.declare}`);
|
|
1133
|
+
visitAstRecursive(np.id);
|
|
1134
|
+
if (np.typeParameters) visitAstRecursive(np.typeParameters);
|
|
1135
|
+
visitAstRecursive(np.typeAnnotation);
|
|
1136
|
+
}
|
|
1137
|
+
p_1.TSTypeAliasDeclaration = TSTypeAliasDeclaration;
|
|
1138
|
+
function TSInterfaceDeclaration(np) {
|
|
1139
|
+
debugLog(`[ts interface declaration]`);
|
|
1140
|
+
visitAstRecursive(np.id);
|
|
1141
|
+
if (np.typeParameters) {
|
|
1142
|
+
visitAstRecursive(np.typeParameters);
|
|
1143
|
+
}
|
|
1144
|
+
visitAstRecursive(np.body);
|
|
1145
|
+
if (np.extends) {
|
|
1146
|
+
for (const p of np.extends) {
|
|
1147
|
+
visitAstRecursive(p);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
p_1.TSInterfaceDeclaration = TSInterfaceDeclaration;
|
|
1152
|
+
})(p || (p = {}));
|
|
1153
|
+
function visitAstRecursive(ast) {
|
|
1154
|
+
const node = ast.node ? ast.node : ast;
|
|
1155
|
+
const nodeVisitor = p[node.type];
|
|
1156
|
+
if (nodeVisitor) {
|
|
1157
|
+
try {
|
|
1158
|
+
nodeVisitor(node);
|
|
1159
|
+
} catch (e) {
|
|
1160
|
+
console.error(e);
|
|
1161
|
+
}
|
|
1162
|
+
} else {
|
|
1163
|
+
console.error(`Unsupported node type: ${node.type}`);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
function visitAst(ast) {
|
|
1167
|
+
context.reset();
|
|
1168
|
+
visitAstRecursive(ast);
|
|
1169
|
+
return context;
|
|
1170
|
+
}
|