UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

64 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ruleAssignLocalVariableInPlayground = void 0; const nasl_language_server_core_1 = require("@lcap/nasl-language-server-core"); function resolveAssignmentTargetType(node) { if (!node) { return null; } // @ts-expect-error __v_raw 是 vue 的私有属性 const nd = node.__v_raw ?? node; if (nd.typeAnnotation) { return null; } // 非草稿区已经推导出来 if ((0, nasl_language_server_core_1.isResolvedUserTy)(nd.__TypeAnnotation)) { return null; } // @ts-expect-error __v_raw 是 vue 的私有属性 const app = nd.app?.__v_raw ?? nd.app; if (!app) { return null; } const candidateType = app.naslServer?.semEnv?.varCandidateTypes?.get(nd); if (!candidateType) { return null; } return candidateType; } exports.ruleAssignLocalVariableInPlayground = { title: '自动修复草稿区赋值给局部变量,局部变量缺少类型声明问题', disableForBatch: true, isFixable(diagnostic) { const message = diagnostic.message; if (!message) { return false; } // @ts-expect-error __v_raw 是 vue 的私有属性 const nd = diagnostic.node?.__v_raw ?? diagnostic.node; if (nd.typeAnnotation) { return false; } // 非草稿区已经推导出来 if ((0, nasl_language_server_core_1.isResolvedUserTy)(nd.__TypeAnnotation)) { return false; } // @ts-expect-error __v_raw 是 vue 的私有属性 const app = nd.app?.__v_raw ?? nd.app; if (!app) { return false; } const candidateType = app.naslServer?.semEnv?.varCandidateTypes?.get(nd); if (!candidateType) { return false; } return { hint: `一键设置为 “${candidateType.typeTitle}” 类型` }; }, commitFix(node) { const typeAnnotation = resolveAssignmentTargetType(node); if (typeAnnotation) { node.update({ typeAnnotation: typeAnnotation.toJSON() }); } }, }; //# sourceMappingURL=rule-assign-local-variable-in-playground.js.map