@cocojs/typescript-transformer-autowired 0.0.2 → 0.0.4
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/dist/index.js +20 -30
- package/package.json +18 -5
package/dist/index.js
CHANGED
@@ -1,53 +1,43 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
6
|
+
const typescript_1 = __importDefault(require("typescript"));
|
4
7
|
function transformer(program) {
|
5
8
|
return function (context) {
|
6
9
|
return function (sourceFile) {
|
7
10
|
function visit(node) {
|
8
11
|
// 检查是否是属性声明节点
|
9
|
-
if (
|
12
|
+
if (typescript_1.default.isPropertyDeclaration(node)) {
|
10
13
|
// 遍历修饰符(包括装饰器)
|
11
|
-
const decorators = (node.modifiers || []).map(modifier => {
|
14
|
+
const decorators = (node.modifiers || []).map((modifier) => {
|
12
15
|
// 检查是否是装饰器
|
13
|
-
if (
|
16
|
+
if (typescript_1.default.isDecorator(modifier)) {
|
14
17
|
const decoratorExpression = modifier.expression;
|
15
18
|
// 检查是否是装饰器调用(如 @a())
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
let type;
|
20
|
+
if (typescript_1.default.isCallExpression(decoratorExpression) &&
|
21
|
+
typescript_1.default.isIdentifier(decoratorExpression.expression) &&
|
22
|
+
(decoratorExpression.expression.text === 'autowired' || decoratorExpression.expression.text === 'reactiveAutowired') &&
|
23
|
+
node.type &&
|
24
|
+
typescript_1.default.isTypeReferenceNode(node.type) &&
|
25
|
+
(type = node.type.getText(sourceFile)) &&
|
26
|
+
['String', "Number", "Boolean", "Object", "Array", "Function", "Symbol"].indexOf(type) === -1) {
|
21
27
|
// 创建类型字符串字面量节点
|
22
|
-
const
|
28
|
+
const args = type ? [typescript_1.default.factory.createIdentifier(type)] : [];
|
23
29
|
// 修改装饰器调用,将类型作为参数传递
|
24
|
-
return
|
25
|
-
modifier,
|
26
|
-
ts.factory.updateCallExpression(
|
27
|
-
decoratorExpression,
|
28
|
-
decoratorExpression.expression,
|
29
|
-
undefined,
|
30
|
-
[typeNode]
|
31
|
-
)
|
32
|
-
);
|
30
|
+
return typescript_1.default.factory.updateDecorator(modifier, typescript_1.default.factory.updateCallExpression(decoratorExpression, decoratorExpression.expression, undefined, args));
|
33
31
|
}
|
34
32
|
}
|
35
33
|
return modifier;
|
36
34
|
});
|
37
|
-
|
38
35
|
// 更新属性声明节点
|
39
|
-
return
|
40
|
-
node,
|
41
|
-
decorators,
|
42
|
-
node.name,
|
43
|
-
node.questionToken,
|
44
|
-
node.type,
|
45
|
-
node.initializer
|
46
|
-
);
|
36
|
+
return typescript_1.default.factory.updatePropertyDeclaration(node, decorators, node.name, node.questionToken, node.type, node.initializer);
|
47
37
|
}
|
48
|
-
return
|
38
|
+
return typescript_1.default.visitEachChild(node, visit, context);
|
49
39
|
}
|
50
|
-
return
|
40
|
+
return typescript_1.default.visitNode(sourceFile, visit);
|
51
41
|
};
|
52
42
|
};
|
53
43
|
}
|
package/package.json
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocojs/typescript-transformer-autowired",
|
3
|
-
"version": "0.0.
|
4
|
-
"description": "",
|
3
|
+
"version": "0.0.4",
|
4
|
+
"description": "补充autowired装饰器的参数",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"files": [
|
7
7
|
"dist"
|
8
8
|
],
|
9
9
|
"scripts": {
|
10
|
-
"
|
10
|
+
"build": "tsc",
|
11
|
+
"jest": "jest",
|
12
|
+
"test": "pnpm run build && pnpm run jest",
|
13
|
+
"prepare": "ts-patch install -s"
|
11
14
|
},
|
12
15
|
"keywords": [],
|
13
|
-
"author": "",
|
14
|
-
"license": "MIT"
|
16
|
+
"author": "jiangchenguang",
|
17
|
+
"license": "MIT",
|
18
|
+
"devDependencies": {
|
19
|
+
"@types/jest": "^29.5.14",
|
20
|
+
"@types/node": "^22.13.1",
|
21
|
+
"jest": "^29.7.0",
|
22
|
+
"ts-patch": "^3.3.0",
|
23
|
+
"typescript": "^5.7.3"
|
24
|
+
},
|
25
|
+
"peerDependencies": {
|
26
|
+
"typescript": "^5.7.3"
|
27
|
+
}
|
15
28
|
}
|