UNPKG

@alvin917/jsbridge-plugin

Version:
36 lines (35 loc) 1.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BridgePluginAnalyzer = void 0; const analyzer_plugin_1 = require("@alvin917/analyzer-plugin"); const typescript_1 = __importDefault(require("typescript")); class BridgePluginAnalyzer extends analyzer_plugin_1.BasePluginAnalyzer { resolveConstructorMethod(node) { super.resolveConstructorMethod(node); if (this.classAnalyzeResult.annotation === 'Bridge') { if (node.parameters.length > 0) { throw new Error(`不能有带参数的构造函数: ${this.sourcePath}`); } } } resolveParameter(node) { super.resolveParameter(node); if (this.analyzeResult.annotation === 'Handler') { const typeName = node.type?.typeName; let value; if (typescript_1.default.isIdentifier(typeName)) { value = typeName.text; } else if (typescript_1.default.isQualifiedName(typeName) && typescript_1.default.isIdentifier(typeName.right)) { value = typeName.right.text; } if (!(value === 'WebviewController' || value === 'BridgeRequest')) { throw new Error(`被Handler装饰的方法,参数类型只能是WebviewController和BridgeRequest: ${this.sourcePath}`); } } } } exports.BridgePluginAnalyzer = BridgePluginAnalyzer;