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

wip(uts): compiler

上级 67fa76e0
{"version":3,"sources":["uni_modules/test-uniplugin/utssdk/app-ios/index.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UIDevice } from 'UIKit'\nimport { CLLocationManager, CLAuthorizationStatus } from 'CoreLocation'\nimport { ShowToast } from '../interface.uts'\n\ntype GetBatteryInfoOptions = {\n name: string\n pwd: number\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\n\nexport default function getBatteryInfo(options: GetBatteryInfoOptions) {\n new UIAlertController(\n (title = title),\n (message = message),\n (preferredStyle = UIAlertController.Style.alert)\n )\n const res = {\n errMsg: 'getBatteryInfo:ok',\n level: UIDevice.current.batteryLevel * 100,\n isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,\n }\n if (options.success != null) {\n options.success!(res)\n }\n if (options.complete != null) {\n options.complete!(res)\n }\n}\n\nexport function test1(callback: () => void): string {\n console.log({ \"a\": \"b\" })\n console.log('test1')\n\n\n\n\n console.log('def ios')\n\n\n console.log('ndef android')\n\n\n\n\n\n console.log('def android || def ios')\n\n\n\n\n console.log(CLLocationManager, CLAuthorizationStatus)\n const a = -3\n console.log(~a)\n return 'test1'\n}\n\nclass Test1 { }\nexport class Test {\n constructor() {\n new Test1()\n }\n test(): string | null {\n if (UTSiOS.macros(\"swift(>=1)\")) {\n console.log(\"swift(>=1)\")\n }\n if (UTSiOS.macros(\"arch(i386) || arch(arm)\")) {\n console.log(\"arch(i386) || arch(arm)\")\n }\n if (UTSiOS.available(\"iOS 14, macOS 11.0, *\")) {\n console.log(\"iOS 14, macOS 11.0, *\")\n } else if (UTSiOS.available(\"iOS 13,*\")) {\n console.log(\"iOS 13,*\")\n } else if (UTSiOS.unavailable(\"tvOS 12\")) {\n console.log(\"tvOS 12\")\n }\n return null\n }\n}\n\nexport async function testAsync() {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n return { a: 1 }\n}\n\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: ShowToast = function showToast(msg) { }\n","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;AAAA,aAAgC;AAChC,oBAAuE;;;iBCD3D,eAAa,KAAK,MAAM,KAAK,IAAI;ADIhB;;aAAxB;IACH,WAAA,MAAM,MAAM,EAAA;IACZ,WAAA,KAAK,QAAM,EAAA;IACX,WAAA,aAAW,KAAK,kBAAkB,IAAI,GAAA;IACtC,WAAA,UAAQ,KAAK,kBAAkB,IAAI,GAAA;IACnC,WAAA,cAAY,KAAK,kBAAkB,IAAI,GAAA;;;;;QAJvC,uBAAM,MAAM;QACZ,qBAAK,QAAM;QACX,iCAAW,KAAK,kBAAkB,IAAI;QACtC,2BAAQ,KAAK,kBAAkB,IAAI;QACnC,mCAAY,KAAK,kBAAkB,IAAI;;AACzC;AAEe,YAAS,eAAe,EAAA,SAAS,qBAAqB,EAAE;IACjE,kBACD,OAAQ,OACR,SAAU,SACV,gBAAiB,kBAAkB,KAAK,CAAC,KAAK;IAEjD,IAAM,MAAM;QACV,CAAA,SAAQ;QACR,CAAA,QAAO,SAAS,OAAO,CAAC,YAAY,GAAG,GAAG;QAC1C,CAAA,aAAY,SAAS,OAAO,CAAC,YAAY,IAAI,SAAS,YAAY,CAAC,QAAQ;MAC5E;IACD,IAAI,QAAQ,OAAO,IAAI,GAAI;QACzB,QAAQ,OAAO,EAAE;;IAEnB,IAAI,QAAQ,QAAQ,IAAI,GAAI;QAC1B,QAAQ,QAAQ,EAAE;;AAEtB;AAEO,YAAS,MAAM,EAAA,yBAAgB,IAAI,KAAG,MAAM,CAAC;IAClD,QAAQ,GAAG,CAAC;QAAE,KAAK;MAAK;IACxB,QAAQ,GAAG,CAAC;IAKZ,QAAQ,GAAG,CAAC;IAGZ,QAAQ,GAAG,CAAC;IAMZ,QAAQ,GAAG,CAAC;IAKZ,QAAQ,GAA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dk/app-ios/index.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UIDevice } from 'UIKit'\nimport { CLLocationManager, CLAuthorizationStatus } from 'CoreLocation'\nimport { ShowToast } from '../interface.uts'\n\ntype GetBatteryInfoOptions = {\n name: string\n pwd: number\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\n\nexport default function getBatteryInfo(options: GetBatteryInfoOptions) {\n new UIAlertController(\n (title = title),\n (message = message),\n (preferredStyle = UIAlertController.Style.alert)\n )\n const res = {\n errMsg: 'getBatteryInfo:ok',\n level: UIDevice.current.batteryLevel * 100,\n isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,\n }\n if (options.success != null) {\n options.success!(res)\n }\n if (options.complete != null) {\n options.complete!(res)\n }\n}\n\nexport function test1(callback: () => void): string {\n console.log({ \"a\": \"b\" })\n console.log('test1')\n\n\n\n\n console.log('def ios')\n\n\n console.log('ndef android')\n\n\n\n\n\n console.log('def android || def ios')\n\n\n\n\n console.log(CLLocationManager, CLAuthorizationStatus)\n const a = -3\n console.log(~a)\n return 'test1'\n}\n\nclass Test1 { }\nexport class Test {\n constructor() {\n new Test1()\n }\n test(): string | null {\n if (UTSiOS.macros(\"swift(>=1)\")) {\n console.log(\"swift(>=1)\")\n }\n if (UTSiOS.macros(\"arch(i386) || arch(arm)\")) {\n console.log(\"arch(i386) || arch(arm)\")\n }\n if (UTSiOS.available(\"iOS 14, macOS 11.0, *\")) {\n console.log(\"iOS 14, macOS 11.0, *\")\n } else if (UTSiOS.available(\"iOS 13,*\")) {\n console.log(\"iOS 13,*\")\n } else if (UTSiOS.unavailable(\"tvOS 12\")) {\n console.log(\"tvOS 12\")\n }\n return null\n }\n}\n\nexport async function testAsync() {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n return { a: 1 }\n}\n\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: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;;aAAM;AAAQ;AACP;;aAAM;IACX,aAAc;QACR;IACN;IACA,YAAA,UAAQ,MAAM,EAAQ;QACpB;YACE,QAAQ,GAAG,CAAC;cACb;QACD;YACE,QAAQ,GAAG,CAAC;cACb;QACD;YACE,QAAQ,GAAG,CAAC;;YACP;gBACL,QAAQ,GAAG,CAAC;;gBACP;oBACL,QAAQ,GAAG,CAAC;;;;QAEd,OAAO,GAAI;IACb;AACF;AAEO;YAAe,mCAAY;IAC5B;IACA;IACA;IACJ,OAAO;QAAE,CAAA,IAAG,CAAC;MAAE;AACjB;AAEO,WAAM,wBAAwB;GAAC;;AAC/B,WAAM,wBAAwB;CAAU,EAAA,GAAG;;AAC3C,WAAM,wBAAwB;CAAmB,EAAA,GAAG;;AAtF9B;;;IAC3B,WAAA,MAAM,MAAM,EAAA;IACZ,WAAA,KAAK,QAAM,EAAA;IACX,WAAA,SAAQ,aAA8B;IACtC,WAAA,MAAK,aAA8B;IACnC,WAAA,UAAS,aAA8B;AACzC;+BAEuC,EAAA,SAAS,+BAAqB;;;;;SALxD,KAAK;yBAAL;;;SACH,KAAK;sBAAL;;;SACI,KAAK;0BAAL;;;;wBAsBQ,0BAAuB,MAAM;;QAA7B;;;;;;;8BAgCZ,MAAM;;;;;;;;6BC/DS,KAAK,MAAM,KAAK,IAAI;sBAApB;;6BAAA,KAAK,MAAM,KAAK,IAAI;sBAApB;;6BAAA,KAAK,MAAM,KAAK,IAAI;sBAApB;;;;;4CDYc,EAAA,SAAS,+BAAqB;kCAA9B;;qCAmBjB,0BAAuB,MAAM;yBAA7B;;;;;;0CC/BG,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB"}
\ No newline at end of file \ No newline at end of file
...@@ -136,9 +136,6 @@ public func test1ByJs(_ callback: UTSCallback) -> String { ...@@ -136,9 +136,6 @@ public func test1ByJs(_ callback: UTSCallback) -> String {
@objc(UTSSDKModulesTestUniPluginTestByJs) @objc(UTSSDKModulesTestUniPluginTestByJs)
@objcMembers @objcMembers
public class TestByJs : Test { public class TestByJs : Test {
override public init(){
super.init();
}
public func testByJs() -> String? { public func testByJs() -> String? {
return test(); return test();
} }
......
...@@ -17302,6 +17302,9 @@ function getProxy() { ...@@ -17302,6 +17302,9 @@ function getProxy() {
return proxy; return proxy;
} }
function resolveSyncResult(res) { function resolveSyncResult(res) {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeSync.result', res);
}
if (res.errMsg) { if (res.errMsg) {
throw new Error(res.errMsg); throw new Error(res.errMsg);
} }
...@@ -17312,6 +17315,9 @@ function invokePropGetter(args) { ...@@ -17312,6 +17315,9 @@ function invokePropGetter(args) {
throw new Error(args.errMsg); throw new Error(args.errMsg);
} }
delete args.errMsg; delete args.errMsg;
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokePropGetter.args', args);
}
return resolveSyncResult(getProxy().invokeSync(args, () => { })); return resolveSyncResult(getProxy().invokeSync(args, () => { }));
} }
function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) { function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) {
...@@ -17353,7 +17359,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: ...@@ -17353,7 +17359,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class:
}); });
if (async) { if (async) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeAsync.args', invokeArgs);
}
getProxy().invokeAsync(invokeArgs, (res) => { getProxy().invokeAsync(invokeArgs, (res) => {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeAsync.result', res);
}
if (res.type !== 'return') { if (res.type !== 'return') {
invokeCallback(res); invokeCallback(res);
} }
...@@ -17368,6 +17380,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: ...@@ -17368,6 +17380,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class:
}); });
}); });
} }
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeSync.args', invokeArgs);
}
return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)); return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback));
}; };
} }
...@@ -17380,6 +17395,12 @@ function initUTSStaticMethod(async, opts) { ...@@ -17380,6 +17395,12 @@ function initUTSStaticMethod(async, opts) {
return initProxyFunction(async, opts, 0); return initProxyFunction(async, opts, 0);
} }
const initUTSProxyFunction = initUTSStaticMethod; const initUTSProxyFunction = initUTSStaticMethod;
function parseClassMethodName(name, methods) {
if (hasOwn$1(methods, name + 'ByJs')) {
return name + 'ByJs';
}
return name;
}
function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) { function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) {
const baseOptions = { const baseOptions = {
moduleName, moduleName,
...@@ -17388,6 +17409,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -17388,6 +17409,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
class: cls, class: cls,
errMsg, errMsg,
}; };
// iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数
if (typeof plus !== 'undefined' && plus.os.name === 'iOS') {
if (constructorParams.find((p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0)) {
constructorParams.push({ name: '_byJs', type: 'boolean' });
}
}
const ProxyClass = class UTSClass { const ProxyClass = class UTSClass {
constructor(...params) { constructor(...params) {
if (errMsg) { if (errMsg) {
...@@ -17403,6 +17430,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -17403,6 +17430,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
get(_, name) { get(_, name) {
if (!target[name]) { if (!target[name]) {
//实例方法 //实例方法
name = parseClassMethodName(name, methods);
if (hasOwn$1(methods, name)) { if (hasOwn$1(methods, name)) {
const { async, params } = methods[name]; const { async, params } = methods[name];
target[name] = initUTSInstanceMethod(!!async, extend({ target[name] = initUTSInstanceMethod(!!async, extend({
...@@ -17429,6 +17457,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -17429,6 +17457,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
const staticMethodCache = {}; const staticMethodCache = {};
return new Proxy(ProxyClass, { return new Proxy(ProxyClass, {
get(target, name, receiver) { get(target, name, receiver) {
name = parseClassMethodName(name, staticMethods);
if (hasOwn$1(staticMethods, name)) { if (hasOwn$1(staticMethods, name)) {
if (!staticMethodCache[name]) { if (!staticMethodCache[name]) {
const { async, params } = staticMethods[name]; const { async, params } = staticMethods[name];
......
...@@ -28,6 +28,9 @@ function getProxy() { ...@@ -28,6 +28,9 @@ function getProxy() {
return proxy; return proxy;
} }
function resolveSyncResult(res) { function resolveSyncResult(res) {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeSync.result', res);
}
if (res.errMsg) { if (res.errMsg) {
throw new Error(res.errMsg); throw new Error(res.errMsg);
} }
...@@ -38,6 +41,9 @@ function invokePropGetter(args) { ...@@ -38,6 +41,9 @@ function invokePropGetter(args) {
throw new Error(args.errMsg); throw new Error(args.errMsg);
} }
delete args.errMsg; delete args.errMsg;
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokePropGetter.args', args);
}
return resolveSyncResult(getProxy().invokeSync(args, () => { })); return resolveSyncResult(getProxy().invokeSync(args, () => { }));
} }
function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) { function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) {
...@@ -79,7 +85,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: ...@@ -79,7 +85,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class:
}); });
if (async) { if (async) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeAsync.args', invokeArgs);
}
getProxy().invokeAsync(invokeArgs, (res) => { getProxy().invokeAsync(invokeArgs, (res) => {
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeAsync.result', res);
}
if (res.type !== 'return') { if (res.type !== 'return') {
invokeCallback(res); invokeCallback(res);
} }
...@@ -94,6 +106,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: ...@@ -94,6 +106,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class:
}); });
}); });
} }
if ((process.env.NODE_ENV !== 'production')) {
console.log('uts.invokeSync.args', invokeArgs);
}
return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)); return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback));
}; };
} }
...@@ -106,6 +121,12 @@ function initUTSStaticMethod(async, opts) { ...@@ -106,6 +121,12 @@ function initUTSStaticMethod(async, opts) {
return initProxyFunction(async, opts, 0); return initProxyFunction(async, opts, 0);
} }
const initUTSProxyFunction = initUTSStaticMethod; const initUTSProxyFunction = initUTSStaticMethod;
function parseClassMethodName(name, methods) {
if (hasOwn(methods, name + 'ByJs')) {
return name + 'ByJs';
}
return name;
}
function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) { function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) {
const baseOptions = { const baseOptions = {
moduleName, moduleName,
...@@ -114,6 +135,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -114,6 +135,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
class: cls, class: cls,
errMsg, errMsg,
}; };
// iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数
if (typeof plus !== 'undefined' && plus.os.name === 'iOS') {
if (constructorParams.find((p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0)) {
constructorParams.push({ name: '_byJs', type: 'boolean' });
}
}
const ProxyClass = class UTSClass { const ProxyClass = class UTSClass {
constructor(...params) { constructor(...params) {
if (errMsg) { if (errMsg) {
...@@ -129,6 +156,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -129,6 +156,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
get(_, name) { get(_, name) {
if (!target[name]) { if (!target[name]) {
//实例方法 //实例方法
name = parseClassMethodName(name, methods);
if (hasOwn(methods, name)) { if (hasOwn(methods, name)) {
const { async, params } = methods[name]; const { async, params } = methods[name];
target[name] = initUTSInstanceMethod(!!async, extend({ target[name] = initUTSInstanceMethod(!!async, extend({
...@@ -155,6 +183,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c ...@@ -155,6 +183,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c
const staticMethodCache = {}; const staticMethodCache = {};
return new Proxy(ProxyClass, { return new Proxy(ProxyClass, {
get(target, name, receiver) { get(target, name, receiver) {
name = parseClassMethodName(name, staticMethods);
if (hasOwn(staticMethods, name)) { if (hasOwn(staticMethods, name)) {
if (!staticMethodCache[name]) { if (!staticMethodCache[name]) {
const { async, params } = staticMethods[name]; const { async, params } = staticMethods[name];
......
...@@ -176,6 +176,9 @@ function getProxy(): { ...@@ -176,6 +176,9 @@ function getProxy(): {
} }
function resolveSyncResult(res: InvokeSyncRes) { function resolveSyncResult(res: InvokeSyncRes) {
if (__DEV__) {
console.log('uts.invokeSync.result', res)
}
if (res.errMsg) { if (res.errMsg) {
throw new Error(res.errMsg) throw new Error(res.errMsg)
} }
...@@ -187,6 +190,9 @@ function invokePropGetter(args: InvokeArgs) { ...@@ -187,6 +190,9 @@ function invokePropGetter(args: InvokeArgs) {
throw new Error(args.errMsg) throw new Error(args.errMsg)
} }
delete args.errMsg delete args.errMsg
if (__DEV__) {
console.log('uts.invokePropGetter.args', args)
}
return resolveSyncResult(getProxy().invokeSync(args, () => {})) return resolveSyncResult(getProxy().invokeSync(args, () => {}))
} }
...@@ -247,7 +253,13 @@ function initProxyFunction( ...@@ -247,7 +253,13 @@ function initProxyFunction(
}) })
if (async) { if (async) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (__DEV__) {
console.log('uts.invokeAsync.args', invokeArgs)
}
getProxy().invokeAsync(invokeArgs, (res) => { getProxy().invokeAsync(invokeArgs, (res) => {
if (__DEV__) {
console.log('uts.invokeAsync.result', res)
}
if (res.type !== 'return') { if (res.type !== 'return') {
invokeCallback(res) invokeCallback(res)
} else { } else {
...@@ -260,6 +272,9 @@ function initProxyFunction( ...@@ -260,6 +272,9 @@ function initProxyFunction(
}) })
}) })
} }
if (__DEV__) {
console.log('uts.invokeSync.args', invokeArgs)
}
return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)) return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback))
} }
} }
...@@ -275,6 +290,13 @@ function initUTSStaticMethod(async: boolean, opts: ProxyFunctionOptions) { ...@@ -275,6 +290,13 @@ function initUTSStaticMethod(async: boolean, opts: ProxyFunctionOptions) {
export const initUTSProxyFunction = initUTSStaticMethod export const initUTSProxyFunction = initUTSStaticMethod
function parseClassMethodName(name: string, methods: Record<string, unknown>) {
if (hasOwn(methods, name + 'ByJs')) {
return name + 'ByJs'
}
return name
}
export function initUTSProxyClass({ export function initUTSProxyClass({
moduleName, moduleName,
moduleType, moduleType,
...@@ -294,6 +316,16 @@ export function initUTSProxyClass({ ...@@ -294,6 +316,16 @@ export function initUTSProxyClass({
class: cls, class: cls,
errMsg, errMsg,
} }
// iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数
if (typeof plus !== 'undefined' && plus.os.name === 'iOS') {
if (
constructorParams.find(
(p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0
)
) {
constructorParams.push({ name: '_byJs', type: 'boolean' })
}
}
const ProxyClass = class UTSClass { const ProxyClass = class UTSClass {
constructor(...params: unknown[]) { constructor(...params: unknown[]) {
if (errMsg) { if (errMsg) {
...@@ -313,6 +345,7 @@ export function initUTSProxyClass({ ...@@ -313,6 +345,7 @@ export function initUTSProxyClass({
get(_, name) { get(_, name) {
if (!target[name as string]) { if (!target[name as string]) {
//实例方法 //实例方法
name = parseClassMethodName(name as string, methods)
if (hasOwn(methods, name)) { if (hasOwn(methods, name)) {
const { async, params } = methods[name] const { async, params } = methods[name]
target[name] = initUTSInstanceMethod( target[name] = initUTSInstanceMethod(
...@@ -345,6 +378,7 @@ export function initUTSProxyClass({ ...@@ -345,6 +378,7 @@ export function initUTSProxyClass({
const staticMethodCache: Record<string, Function> = {} const staticMethodCache: Record<string, Function> = {}
return new Proxy(ProxyClass, { return new Proxy(ProxyClass, {
get(target, name, receiver) { get(target, name, receiver) {
name = parseClassMethodName(name as string, staticMethods)
if (hasOwn(staticMethods, name)) { if (hasOwn(staticMethods, name)) {
if (!staticMethodCache[name as string]) { if (!staticMethodCache[name as string]) {
const { async, params } = staticMethods[name] const { async, params } = staticMethods[name]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册