@cocojs/typescript-transformer-autowired 0.0.1 → 0.0.3
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 +39 -22
- package/package.json +11 -4
    
        package/dist/index.js
    CHANGED
    
    | @@ -1,6 +1,39 @@ | |
| 1 1 | 
             
            "use strict";
         | 
| 2 | 
            +
            var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
         | 
| 3 | 
            +
                if (k2 === undefined) k2 = k;
         | 
| 4 | 
            +
                var desc = Object.getOwnPropertyDescriptor(m, k);
         | 
| 5 | 
            +
                if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
         | 
| 6 | 
            +
                  desc = { enumerable: true, get: function() { return m[k]; } };
         | 
| 7 | 
            +
                }
         | 
| 8 | 
            +
                Object.defineProperty(o, k2, desc);
         | 
| 9 | 
            +
            }) : (function(o, m, k, k2) {
         | 
| 10 | 
            +
                if (k2 === undefined) k2 = k;
         | 
| 11 | 
            +
                o[k2] = m[k];
         | 
| 12 | 
            +
            }));
         | 
| 13 | 
            +
            var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
         | 
| 14 | 
            +
                Object.defineProperty(o, "default", { enumerable: true, value: v });
         | 
| 15 | 
            +
            }) : function(o, v) {
         | 
| 16 | 
            +
                o["default"] = v;
         | 
| 17 | 
            +
            });
         | 
| 18 | 
            +
            var __importStar = (this && this.__importStar) || (function () {
         | 
| 19 | 
            +
                var ownKeys = function(o) {
         | 
| 20 | 
            +
                    ownKeys = Object.getOwnPropertyNames || function (o) {
         | 
| 21 | 
            +
                        var ar = [];
         | 
| 22 | 
            +
                        for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
         | 
| 23 | 
            +
                        return ar;
         | 
| 24 | 
            +
                    };
         | 
| 25 | 
            +
                    return ownKeys(o);
         | 
| 26 | 
            +
                };
         | 
| 27 | 
            +
                return function (mod) {
         | 
| 28 | 
            +
                    if (mod && mod.__esModule) return mod;
         | 
| 29 | 
            +
                    var result = {};
         | 
| 30 | 
            +
                    if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
         | 
| 31 | 
            +
                    __setModuleDefault(result, mod);
         | 
| 32 | 
            +
                    return result;
         | 
| 33 | 
            +
                };
         | 
| 34 | 
            +
            })();
         | 
| 2 35 | 
             
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 3 | 
            -
             | 
| 36 | 
            +
            const ts = __importStar(require("typescript"));
         | 
| 4 37 | 
             
            function transformer(program) {
         | 
| 5 38 | 
             
                return function (context) {
         | 
| 6 39 | 
             
                    return function (sourceFile) {
         | 
| @@ -8,42 +41,26 @@ function transformer(program) { | |
| 8 41 | 
             
                            // 检查是否是属性声明节点
         | 
| 9 42 | 
             
                            if (ts.isPropertyDeclaration(node)) {
         | 
| 10 43 | 
             
                                // 遍历修饰符(包括装饰器)
         | 
| 11 | 
            -
                                const decorators = (node.modifiers || []).map(modifier => {
         | 
| 44 | 
            +
                                const decorators = (node.modifiers || []).map((modifier) => {
         | 
| 12 45 | 
             
                                    // 检查是否是装饰器
         | 
| 13 46 | 
             
                                    if (ts.isDecorator(modifier)) {
         | 
| 14 47 | 
             
                                        const decoratorExpression = modifier.expression;
         | 
| 15 48 | 
             
                                        // 检查是否是装饰器调用(如 @a())
         | 
| 16 49 | 
             
                                        if (ts.isCallExpression(decoratorExpression) &&
         | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 50 | 
            +
                                            ts.isIdentifier(decoratorExpression.expression) &&
         | 
| 51 | 
            +
                                            (decoratorExpression.expression.text === 'autowired' || decoratorExpression.expression.text === 'reactiveAutowired')) {
         | 
| 19 52 | 
             
                                            // 获取属性的类型
         | 
| 20 53 | 
             
                                            const type = node.type ? node.type.getText(sourceFile) : 'unknown';
         | 
| 21 54 | 
             
                                            // 创建类型字符串字面量节点
         | 
| 22 55 | 
             
                                            const typeNode = ts.factory.createIdentifier(type);
         | 
| 23 56 | 
             
                                            // 修改装饰器调用,将类型作为参数传递
         | 
| 24 | 
            -
                                            return ts.factory.updateDecorator(
         | 
| 25 | 
            -
                                              modifier,
         | 
| 26 | 
            -
                                              ts.factory.updateCallExpression(
         | 
| 27 | 
            -
                                                decoratorExpression,
         | 
| 28 | 
            -
                                                decoratorExpression.expression,
         | 
| 29 | 
            -
                                                undefined,
         | 
| 30 | 
            -
                                                [typeNode]
         | 
| 31 | 
            -
                                              )
         | 
| 32 | 
            -
                                            );
         | 
| 57 | 
            +
                                            return ts.factory.updateDecorator(modifier, ts.factory.updateCallExpression(decoratorExpression, decoratorExpression.expression, undefined, [typeNode]));
         | 
| 33 58 | 
             
                                        }
         | 
| 34 59 | 
             
                                    }
         | 
| 35 60 | 
             
                                    return modifier;
         | 
| 36 61 | 
             
                                });
         | 
| 37 | 
            -
             | 
| 38 62 | 
             
                                // 更新属性声明节点
         | 
| 39 | 
            -
                                return ts.factory.updatePropertyDeclaration(
         | 
| 40 | 
            -
                                  node,
         | 
| 41 | 
            -
                                  decorators,
         | 
| 42 | 
            -
                                  node.name,
         | 
| 43 | 
            -
                                  node.questionToken,
         | 
| 44 | 
            -
                                  node.type,
         | 
| 45 | 
            -
                                  node.initializer
         | 
| 46 | 
            -
                                );
         | 
| 63 | 
            +
                                return ts.factory.updatePropertyDeclaration(node, decorators, node.name, node.questionToken, node.type, node.initializer);
         | 
| 47 64 | 
             
                            }
         | 
| 48 65 | 
             
                            return ts.visitEachChild(node, visit, context);
         | 
| 49 66 | 
             
                        }
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,15 +1,22 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "@cocojs/typescript-transformer-autowired",
         | 
| 3 | 
            -
              "version": "0.0. | 
| 4 | 
            -
              "description": "",
         | 
| 3 | 
            +
              "version": "0.0.3",
         | 
| 4 | 
            +
              "description": "补充autowired装饰器的参数",
         | 
| 5 5 | 
             
              "main": "dist/index.js",
         | 
| 6 6 | 
             
              "files": [
         | 
| 7 7 | 
             
                "dist"
         | 
| 8 8 | 
             
              ],
         | 
| 9 9 | 
             
              "scripts": {
         | 
| 10 | 
            +
                "build": "tsc",
         | 
| 10 11 | 
             
                "test": "echo \"Error: no test specified\" && exit 1"
         | 
| 11 12 | 
             
              },
         | 
| 12 13 | 
             
              "keywords": [],
         | 
| 13 | 
            -
              "author": "",
         | 
| 14 | 
            -
              "license": " | 
| 14 | 
            +
              "author": "jiangchenguang",
         | 
| 15 | 
            +
              "license": "MIT",
         | 
| 16 | 
            +
              "devDependencies": {
         | 
| 17 | 
            +
                "typescript": "^5.7.3"
         | 
| 18 | 
            +
              },
         | 
| 19 | 
            +
              "peerDependencies": {
         | 
| 20 | 
            +
                "typescript": "^5.7.3"
         | 
| 21 | 
            +
              }
         | 
| 15 22 | 
             
            }
         |