UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

116 lines 5.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.componentUniqueName = exports.uniqueName = void 0; const nasl_utils_1 = require("@lcap/nasl-utils"); class uniqueName { constructor() { this.NamesWeakMap = new Map(); } initAppUniqueNames(app, frontend) { const NamesWeakMap = this.NamesWeakMap; const defaultDS = app.dataSources.find((d) => d.name === 'defaultDS'); NamesWeakMap.set('defaultDS', new Set(defaultDS.getEntityExistingNames())); // NamesWeakMap.set('DataSource', new Set(app.getDataSourceExistingNames())); NamesWeakMap.set('Structure', new Set(app.getStructureExistingNames())); NamesWeakMap.set('Enum', new Set(app.getEnumExistingNames())); NamesWeakMap.set('Logic', new Set(app.getLogicExistingNames())); NamesWeakMap.set('Interface', new Set(app.getInterfaceExistingNames())); NamesWeakMap.set('View', new Set(frontend.getViewExistingNames())); NamesWeakMap.set('Process', new Set(app.getProcessExistingNames())); NamesWeakMap.set('Role', new Set(app.getRoleExistingNames())); NamesWeakMap.set('Variable', new Set(frontend.getVarExistingNames())); } getGenUniqNameFunctionName(item, concept) { if (item.name === null) item.name = undefined; const p = item.parentNode; const NamesWeakMap = this.NamesWeakMap; if (!p) { // 添加至顶层 App 的对象 if (concept === 'DataSource') { return item.name; } if (concept === 'Entity') { // Entity 是为了兼容 2.11 及之前的模板 concept = 'defaultDS'; } const nameSet = NamesWeakMap.get(concept); const n = (0, nasl_utils_1.unique)(item.name, nameSet, 1, true); nameSet.add(n); return n; } const f1 = p['get' + concept + 'UniqueName']; const f2 = p['get' + concept + 'ExistingNames']; if (f1 && f2) { const names = f2.call(p); const t = names.filter((n) => n === item.name); if (t.length > 1) { return f1.call(p, item.name); } } return item.name; } } exports.uniqueName = uniqueName; class componentUniqueName { constructor() { this.NamesWeakMap = new Map(); this.view = null; } initAppUniqueNames(app, frontend, view) { const NamesWeakMap = this.NamesWeakMap; this.view = view; NamesWeakMap.set('DataSource', new Set(app.getDataSourceExistingNames())); NamesWeakMap.set('Structure', new Set(app.getStructureExistingNames())); NamesWeakMap.set('Enum', new Set(app.getEnumExistingNames())); NamesWeakMap.set('Logic', new Set(app.getLogicExistingNames())); NamesWeakMap.set('Interface', new Set(app.getInterfaceExistingNames())); NamesWeakMap.set('View', new Set(frontend.getViewExistingNames())); NamesWeakMap.set('Process', new Set(app.getProcessExistingNames())); NamesWeakMap.set('Role', new Set(app.getRoleExistingNames())); // .... 这里要补一下 view 下面 variable, logics的名字 NamesWeakMap.set('Variable', new Set(view.getVarExistingNames())); NamesWeakMap.set('Logic', new Set(view.getLogicExistingNames())); } getGenUniqNameFunctionName(item, concept) { if (item.name === null) item.name = undefined; const p = concept === 'ViewElement' ? this.view : item.parentNode; const NamesWeakMap = this.NamesWeakMap; if (!p) { const nameSet = NamesWeakMap.get(concept); const n = (0, nasl_utils_1.unique)(item.name, nameSet, 1, true); nameSet.add(n); return n; } const f1 = p['get' + concept + 'UniqueName']; const f2 = p['get' + concept + 'ExistingNames']; if (f1 && f2) { const names = f2.call(p); const t = names.filter((n) => n === item.name); if (t.length > 1) { return f1.call(p, item.name); } if (concept === 'ViewElement' && t.length) return f1.call(p, item.name); } // 逻辑里面的变量也需要再判断 if (concept === 'Variable' && f1) { const variables = p.getVarExistingNames(); if (Array.isArray(this.view.params)) { variables.push(...this.view.params.map((item) => item.name)); } if (Array.isArray(this.view.variables)) { variables.push(...this.view.variables.map((item) => item.name)); } const t = variables.filter((n) => n === item.name); if (t.length > 1) { return f1.call(p, item.name); } } return item.name; } } exports.componentUniqueName = componentUniqueName; exports.default = uniqueName; //# sourceMappingURL=uniqueName.js.map