mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-27 10:40:37 +00:00
"modifile src/cli/dts2cpp/src/gen/analyze/interface.js 修改napi仓 js格式问题和重大告警"
Signed-off-by: huruitao <huruitao@kaihong.com>
This commit is contained in:
parent
e783b7ef7c
commit
5f972472ed
@ -24,7 +24,7 @@ function analyzeNoNameInterface(valueType, valueName, rsltInterface) {
|
||||
if (matchs) {
|
||||
let number = NumberIncrease.getAndIncrease();
|
||||
let interfaceTypeName = 'AUTO_INTERFACE_%s_%s'.format(valueName, number);
|
||||
let interfaceBody = valueType.substring(1, valueType.length-1);
|
||||
let interfaceBody = valueType.substring(1, valueType.length - 1);
|
||||
interfaceBody = re.replaceAll(interfaceBody, ',', ';\n');
|
||||
rsltInterface.push({
|
||||
name: interfaceTypeName,
|
||||
@ -38,12 +38,12 @@ function analyzeNoNameInterface(valueType, valueName, rsltInterface) {
|
||||
/* 去除单行注释// */
|
||||
function parseNotes(data) {
|
||||
let notes = data.indexOf('//') >= 0 ? data.substring(data.indexOf('//'), data.length) : '';
|
||||
while(notes != '') {
|
||||
while (notes !== '') {
|
||||
notes = notes.substring(0, notes.indexOf('\n'));
|
||||
data = data.replace(notes, '');
|
||||
notes = '';
|
||||
let st = data.indexOf('//');
|
||||
if(st >= 0) {
|
||||
if (st >= 0) {
|
||||
notes = data.substring(st, data.length);
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,7 @@ function parseNotes(data) {
|
||||
function analyzeInterface(data, rsltInterface = null, results, interfaceName = '') { // same as class
|
||||
let body = data;
|
||||
body = body.indexOf('//') < 0 ? body : parseNotes(body);
|
||||
let arr = [...body.matchAll(/;\s*\n+/g)];
|
||||
let arr = [...body.matchAll(/;\s*\n+/g)];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
let result = arr[i];
|
||||
body = re.replaceAll(body, result[0], ';\n');
|
||||
@ -67,15 +67,21 @@ function analyzeInterface(data, rsltInterface = null, results, interfaceName = '
|
||||
for (let i in body) {
|
||||
let t = body[i];
|
||||
t = re.replaceAll(t, '\n', '');
|
||||
while (t.length > 0 && t[0] === ' ') t = t.substring(1, t.length); // 去除前面的空格
|
||||
while (t.length > 0 && t[-1] === ' ') t = t.substring(0, t.length - 1); // 去除后面的空格
|
||||
if (t === '') break; // 如果t为空直接返回
|
||||
while (t.length > 0 && t[0] === ' ') {
|
||||
t = t.substring(1, t.length); // 去除前面的空格
|
||||
}
|
||||
while (t.length > 0 && t[-1] === ' ') {
|
||||
t = t.substring(0, t.length - 1); // 去除后面的空格
|
||||
}
|
||||
if (t === '') {
|
||||
break; // 如果t为空直接返回
|
||||
}
|
||||
let tt = re.match(' *([a-zA-Z0-9_]+)(\\?*)*: *([a-zA-Z_0-9<>,:{}[\\]| ]+)', t);
|
||||
if (tt && t.indexOf('=>') < 0) { // 接口成员变量, 但不包括带'=>'的成员,带'=>'的接口成员需要按函数处理
|
||||
analyzeInterfaceVariable(t, tt, rsltInterface, result);
|
||||
}
|
||||
tt = re.match("(static )* *(\\$*[A-Za-z0-9_]+) *[:]? *\\(([\n 'a-zA-Z\'\'\"\":;=,_0-9?<>{}()=>|[\\]]*)\\)"
|
||||
+ ' *(:|=>)? *([A-Za-z0-9_<>{}:;, .[\\]]+)?', t)
|
||||
tt = re.match("(static )* *(\\$*[A-Za-z0-9_]+) *[:]? *\\(([\n 'a-zA-Z\'\'\"\":;=,_0-9?<>{}()=>|[\\]]*)\\)" +
|
||||
' *(:|=>)? *([A-Za-z0-9_<>{}:;, .[\\]]+)?', t);
|
||||
if (tt) { // 接口函数成员
|
||||
analyzeInterfaceFunction(t, tt, data, results, interfaceName, result);
|
||||
}
|
||||
@ -86,7 +92,7 @@ function analyzeInterface(data, rsltInterface = null, results, interfaceName = '
|
||||
module.exports = {
|
||||
analyzeInterface,
|
||||
parseNotes
|
||||
}
|
||||
};
|
||||
|
||||
function analyzeInterfaceFunction(t, tt, data, results, interfaceName, result) {
|
||||
let ret = re.getReg(t, tt.regs[5]) === '' ? 'void' : re.getReg(t, tt.regs[5]);
|
||||
|
Loading…
Reference in New Issue
Block a user