提交 b438a5a4 编写于 作者: fxy060608's avatar fxy060608

fix(uts): android、iOS 中相同interface、class支持属性,方法合并

上级 d4018255
......@@ -16,7 +16,7 @@ export const TestUTSComponent = {}
registerUTSInterface('RequestTaskOptions',Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'RequestTaskByJsProxy', is_uni_modules) }, {"methods":{"startByJs":{"async":false,"params":[],"return":{}},"abortByJs":{"async":false,"params":[],"return":{"type":"interface","options":"RequestTaskOptions"}}},"props":[]} ))
export const onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback"}], return: ""})
export const offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}], return: ""})
export default /*#__PURE__*/ initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'UserByJs', is_uni_modules) }, {"constructor":{"params":[]},"methods":{},"staticMethods":{},"props":[],"staticProps":[]} ))
export default /*#__PURE__*/ initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'UserByJs', is_uni_modules) }, {"constructor":{"params":[]},"methods":{"registerByJs":{"async":false,"params":[],"returnOptions":{}},"loginByJs":{"async":false,"params":[],"returnOptions":{}}},"staticMethods":{},"props":[],"staticProps":[]} ))
export const a = 1
export const showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1ByJs', params: [{"name":"msg","type":"string"}], return: ""})
export const showToast2 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast2ByJs', params: [{"name":"msg","type":"string"}], return: ""})
......@@ -329,7 +329,7 @@ exports.TestUTSComponent = {}
registerUTSInterface('RequestTaskOptions',Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'RequestTaskByJsProxy', is_uni_modules) }, {"methods":{"startByJs":{"async":false,"params":[],"return":{}},"abortByJs":{"async":false,"params":[],"return":{"type":"interface","options":"RequestTaskOptions"}}},"props":[]} ))
exports.onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback"}], return: ""})
exports.offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}], return: ""})
exports.default = initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'UserByJs', is_uni_modules) }, {"constructor":{"params":[]},"methods":{},"staticMethods":{},"props":[],"staticProps":[]} ))
exports.default = initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'UserByJs', is_uni_modules) }, {"constructor":{"params":[]},"methods":{"registerByJs":{"async":false,"params":[],"returnOptions":{}},"loginByJs":{"async":false,"params":[],"returnOptions":{}}},"staticMethods":{},"props":[],"staticProps":[]} ))
const a = 1
exports.a = a
exports.showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1ByJs', params: [{"name":"msg","type":"string"}], return: ""})
......
......@@ -4,15 +4,15 @@
"compilerVersion": "3.6.10"
},
"files": {
"app-android/index.uts": {
"md5": "6958ca9d5c365d041dd72dc46091b839"
},
"common/test/test.uts": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"common/utils.uts": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"index.uts": {
"md5": "719035aae84f58b2028f63d102c49887"
},
"interface.uts": {
"md5": "4821d45870be9af550787418f7a4c34c"
},
......
......@@ -4,15 +4,15 @@
"compilerVersion": "3.6.10"
},
"files": {
"app-ios/index.uts": {
"md5": "3134e94f54ea061ea2e6440ceec9cebf"
},
"common/test/test.uts": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"common/utils.uts": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"index.uts": {
"md5": "719035aae84f58b2028f63d102c49887"
},
"interface.uts": {
"md5": "4821d45870be9af550787418f7a4c34c"
},
......
import { ShowToast, RequestTask } from './interface.uts'
import { ShowToast, RequestTask } from '../interface.uts'
export function onMemoryWarning(callback: (level: number) => void) {}
export function offMemoryWarning(
callback: ((level: number) => void) | null = null
) {}
export default class User {}
export default class User {
login() {}
}
export const a = 1
export let b = 2,
c = 3
......
import { ShowToast, RequestTask } from '../interface.uts'
export function onMemoryWarning(callback: (level: number) => void) {}
export function offMemoryWarning(
callback: ((level: number) => void) | null = null
) {}
export default class User {
register() {}
}
export const a = 1
export let b = 2,
c = 3
export const showToast1: ShowToast = (msg) => {
console.log(msg)
}
export const showToast2: ShowToast = function showToast(msg) {
console.log(msg)
}
export function request(): RequestTask {}
export type User1 = {
name: string
}
export function addUsers1(users: User1[]) {}
export function addUsers2(users: Array<User1>) {}
export function addUsers3(user: User1, name: string[]) {}
export function addUsers4(user: User1, name: Array<string>) {}
......@@ -41,11 +41,11 @@ const pluginOptions = {
describe('manifest', () => {
test('resolve android files', async () => {
expect(await resolvePluginFiles('app-android', pluginDir, false)).toEqual([
'index.uts',
'interface.uts',
'package.json',
'common/utils.uts',
'common/test/test.uts',
'app-android/index.uts',
])
expect(
await resolvePluginFiles('app-android', pluginModuleDir, true)
......@@ -60,11 +60,11 @@ describe('manifest', () => {
})
test('resolve ios files', async () => {
expect(await resolvePluginFiles('app-ios', pluginDir, false)).toEqual([
'index.uts',
'interface.uts',
'package.json',
'common/utils.uts',
'common/test/test.uts',
'app-ios/index.uts',
])
expect(await resolvePluginFiles('app-ios', pluginModuleDir, true)).toEqual([
'package.json',
......
......@@ -549,27 +549,48 @@ async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
return decls
}
function mergeRecord(from: Record<string, any>, to: Record<string, any>) {
Object.keys(from).forEach((key) => {
if (!hasOwn(to, key)) {
to[key] = from[key]
}
})
}
function mergeArray(from: any[], to: any[]) {
from.forEach((item) => {
if (!to.includes(item)) {
to.push(item)
}
})
}
function mergeDecls(from: ProxyDecl[], to: ProxyDecl[]) {
from.forEach((item) => {
if (item.type === 'InterfaceDeclaration') {
if (
!to.find(
(toItem) =>
toItem.type === 'InterfaceDeclaration' && toItem.cls === item.cls
)
) {
const decl = to.find(
(toItem) =>
toItem.type === 'InterfaceDeclaration' && toItem.cls === item.cls
) as ProxyInterface | undefined
if (!decl) {
to.push(item)
} else {
mergeRecord(item.options.methods, decl.options.methods)
mergeArray(item.options.props, decl.options.props)
}
} else if (item.type === 'Class') {
if (
!to.find(
(toItem) =>
toItem.type === 'Class' &&
toItem.cls === item.cls &&
toItem.isDefault === item.isDefault
)
) {
const decl = to.find(
(toItem) =>
toItem.type === 'Class' &&
toItem.cls === item.cls &&
toItem.isDefault === item.isDefault
) as ProxyClass | undefined
if (!decl) {
to.push(item)
} else {
mergeRecord(item.options.methods, decl.options.methods)
mergeRecord(item.options.staticMethods, decl.options.staticMethods)
mergeArray(item.options.props, decl.options.props)
mergeArray(item.options.staticProps, decl.options.staticProps)
}
} else if (item.type === 'FunctionDeclaration') {
if (
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册