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

wip(uts): compiler

上级 3f14d2d0
{"version":3,"sources":["uni_modules/test-uniplugin/static/logo.png","uni_modules/test-uniplugin/utssdk/app-android/index.uts","uni_modules/test-uniplugin/utssdk/app-android/utils.uts","uni_modules/test-uniplugin/utssdk/app-android/login.uts","uni_modules/test-uniplugin/utssdk/app-android/interface.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UTSAndroid } from 'io.dcloud.uts'\nexport default UTSAndroid.getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport FrameLayout from 'android.widget.FrameLayout'\nimport View from 'android.view.View'\nimport { login } from 'login'\nimport { IUser } from './interface'\nimport logo from '../../static/logo.png'\nimport { ShowToast } from '../interface.uts'\n\nconst test = arrayOf(1, 2, 3)\n\ntype GetBatteryInfoOptions = {\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\nexport class User implements IUser {\n async login(name: string, pwd: string) {\n setTimeout(() => {\n console.log('timeout')\n }, 1000)\n login(name, pwd)\n for (let i = 0; i < 10; i++) {\n console.log(i)\n }\n Log.info(logo)\n\n console.log('def android')\n\n\n\n\n\n\n\n\n console.log('ndef ios')\n\n\n console.log('def android || def ios')\n\n\n\n\n const a = -3\n console.log(~a)\n new XToast<XToast<unknown>>(getUniActivity())\n .setContentView(R.layout.toast_hint)\n .setDuration(1000)\n .setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)\n .setText(android.R.id.message, '点我消失')\n .show()\n }\n register(name: string, callback: () => void) {\n Log.info(logo as FrameLayout)\n }\n test(view: View) {\n console.log(new TestClass())\n }\n}\nfunction login(name: string, callback: () => void) { }\n\n@Suppress(\"DEPRECATION\")\n export function register(name: string, callback: () => void) { }\nexport function offMemoryWarning(\n callback: null | ((level: number) => void) = null\n) {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n}\nclass TestClass {\n\n}\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: ShowToast = function showToast(msg) { }\n","export function test(){\n console.log('test')\n}\n","import { test } from \"./utils.uts\"\nexport function login(name: string, pwd: string) {\n console.log('login')\n test()\n return { name, pwd }\n}\n","export interface IUser {\n register(name: string): void\n}\n","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;;;;;;;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;AAClC,OAAwB,0BAA4B,CAAA;AACpD,OAAiB,iBAAmB,CAAA;ACF7B,IAAS,OAAM;IAClB,QAAQ,GAAG,CAAC;AAChB;ACDO,IAAS,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,iBAAE;IAC/C,QAAQ,GAAG,CAAC;IACZ;IACA,OAAO;QAAE,IAAA,OAAA;QAAM,IAAA,MAAA;KAAK;AACtB;UCLiB;QACf,SAAS,MAAM,MAAM,GAAG,IAAI;;cJAf,WAAW,eAAe,CAAC;UKD9B,aAAa,KAAK,MAAM,KAAK,IAAI;AJQ7C,IAAM,QAAO,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAOrB,WAAM;IACX,iBAAM,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,8CAAE;QACrC,WAAW,KAAM;YACf,QAAQ,GAAG,CAAC;QACd;UAAG,IAAI;QACP,MAAM,MAAM;YACZ;YAAK,IAAI,IAAI,CAAC;YAAd,MAAgB,IAAI,EAAE;gBACpB,QAAQ,GAAG,CAAC;gBADU;;QAExB;QACA,IAAI,IAAI;QAER,QAAQ,GAAG,CAAC;QASZ,QAAQ,GAAG,CAAC;QAGZ,QAAQ,GAAG,CAAC;QAMZ,QAAQ,GAAG,CAAC,CADF,EAAE,KACE;QACV,OAAO,OAAO,CAAO,GAAG,kBACzB,cAAc,CAAC,EAAE,MAAM,CAAC,UAAU,EAClC,WAAW,CAAC,IAAI,EAChB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,oBAAoB,EACjE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,QAC9B,IAAI;IACT;IACA,aAAA,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE;QAC3C,IAAI,IAAI,YAAS;IACnB;IACA,SAAA,KAAK,MAAM,IAAI,EAAE;QACf,QAAQ,GAAG,CAAC,AAAI;IAClB;AACF;AACA,UAAe,MAAM,MAAM,EAAE,gBAAgB,IAAI,EAAE,CAAE;AAErD,CAAC,SAAS;AAAc,IACN,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE,CAAE;AAC1D,IAAS,iBACd,2BAA6C,IAAI,EACjD;IACI;IACA;IACA;AACN;AACA,WAAM;AAEN;AACO,IAAM,wBAAwB,IAAC,IAAQ,CAAE;AACzC,IAAM,wBAAwB,IAAU,GAAG,EAAE,CAAE;AAC/C,IAAM,wBAAwB,IAAmB,GAAG,EAAE,CAAE;iBAbpC,MAAM,MAAM,EAAE,qBAAoB;oBAAlC;QAAc;;;;yBAEvC,2BAA6C,IAAI;;;mBIhE1B,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB"}
\ No newline at end of file
{"version":3,"sources":["uni_modules/test-uniplugin/static/logo.png","uni_modules/test-uniplugin/utssdk/app-android/index.uts","uni_modules/test-uniplugin/utssdk/app-android/utils.uts","uni_modules/test-uniplugin/utssdk/app-android/login.uts","uni_modules/test-uniplugin/utssdk/app-android/interface.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UTSAndroid } from 'io.dcloud.uts'\nexport default UTSAndroid.getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport FrameLayout from 'android.widget.FrameLayout'\nimport View from 'android.view.View'\nimport { login } from 'login'\nimport { IUser } from './interface'\nimport logo from '../../static/logo.png'\nimport { ShowToast } from '../interface.uts'\n\nconst test = arrayOf(1, 2, 3)\n\ntype GetBatteryInfoOptions = {\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\nexport class User implements IUser {\n async login(name: string, pwd: string) {\n setTimeout(() => {\n console.log('timeout')\n }, 1000)\n login(name, pwd)\n for (let i = 0; i < 10; i++) {\n console.log(i)\n }\n Log.info(logo)\n\n console.log('def android')\n\n\n\n\n\n\n\n\n console.log('ndef ios')\n\n\n console.log('def android || def ios')\n\n\n\n\n const a = -3\n console.log(~a)\n new XToast<XToast<unknown>>(getUniActivity())\n .setContentView(R.layout.toast_hint)\n .setDuration(1000)\n .setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)\n .setText(android.R.id.message, '点我消失')\n .show()\n }\n register(name: string, callback: () => void) {\n Log.info(logo as FrameLayout)\n }\n test(view: View) {\n console.log(new TestClass())\n }\n}\nfunction login(name: string, callback: () => void) { }\n\n@Suppress(\"DEPRECATION\")\n export function register(name: string, callback: () => void) { }\nexport function offMemoryWarning(\n callback: null | ((level: number) => void) = null\n) {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n}\nclass TestClass {\n\n}\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: ShowToast = function showToast(msg) { }\n","export function test(){\n console.log('test')\n}\n","import { test } from \"./utils.uts\"\nexport function login(name: string, pwd: string) {\n console.log('login')\n test()\n return { name, pwd }\n}\n","export interface IUser {\n register(name: string): void\n}\n","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;;;;;;;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;AAClC,OAAwB,0BAA4B,CAAA;AACpD,OAAiB,iBAAmB,CAAA;ACF7B,IAAS,OAAM;IAClB,QAAQ,GAAG,CAAC;AAChB;ACDO,IAAS,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,iBAAE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AAI,KAAI,IAAI,EACjD;IACI;IACA;IACA;AACN;AACA,WAAM;AAEN;AACO,IAAM,wBAAwB,IAAC,IAAQ,CAAE;AACzC,IAAM,wBAAwB,IAAU,GAAG,EAAE,CAAE;AAC/C,IAAM,wBAAwB,IAAmB,GAAG,EAAE,CAAE;iBAbpC,MAAM,MAAM,EAAE;oBAAd;QAAc;;;;yBAEvC,YAAmB,OAAO,MAAM,KAAK,IAAI,KAAI,IAAI;;;mBIhE1B,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB"}
\ No newline at end of file
{"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,cAAxB;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;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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AG,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
{"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;;gBAJvC,MAAM,MAAM,EACZ,KAAK,QAAM,EACX,sBAAW,KAAK,kBAAkB,IAAI,GACtC,mBAAQ,KAAK,kBAAkB,IAAI,GACnC,uBAAY,KAAK,kBAAkB,IAAI;aAJvC,OAAA;aACA,MAAA;aACA,UAAA;aACA,OAAA;aACA,WAAA;;AACF;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,CA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M,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB"}
\ No newline at end of file
......@@ -58,8 +58,8 @@ open class User : IUser {
}
fun login(name: String, callback: () -> Unit) {}
@Suppress("DEPRECATION")
fun register(name: String, callback: UTSCallback) {}
fun offMemoryWarning(callback: (UTSCallback)? = null) {
fun register(name: String, callback: () -> Unit) {}
fun offMemoryWarning(callback: ((level: Number) -> Unit)? = null) {
uni_showToast();
uni_showToast();
uni_showModel();
......@@ -71,11 +71,11 @@ val showToast2: ShowToast = fun(msg) {};
val showToast3: ShowToast = fun(msg) {};
fun registerByJs(name: String, callback: UTSCallback) {
return register(name, fun(){
callback(res);
callback();
}
);
}
fun offMemoryWarningByJs(callback: (UTSCallback)? = null) {
fun offMemoryWarningByJs(callback: ((level: Number) -> Unit)? = null) {
return offMemoryWarning();
}
fun showToast1ByJs(msg: String): Unit {
......
......@@ -5,12 +5,20 @@ import CoreLocation;
public var uni_showToast = DCloudUTSExtAPI.showToast;
public var uni_showModel = DCloudUTSExtAPI.showModel;
public typealias ShowToast = (_ msg: String) -> Void;
public struct GetBatteryInfoOptions {
public class GetBatteryInfoOptions {
public var name: String!;
public var pwd: NSNumber!;
public var success: ((_ res: UTSJSONObject) -> Void)?;
public var fail: ((_ res: UTSJSONObject) -> Void)?;
public var complete: ((_ res: UTSJSONObject) -> Void)?;
public init() {}
public init(name: String, pwd: NSNumber, success:@escaping ((_ res: UTSJSONObject) -> Void), fail:@escaping ((_ res: UTSJSONObject) -> Void), complete:@escaping ((_ res: UTSJSONObject) -> Void)) {
self.name = name;
self.pwd = pwd;
self.success = success;
self.fail = fail;
self.complete = complete;
}
}
public func getBatteryInfo(_ options: GetBatteryInfoOptions) {
UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert);
......@@ -26,7 +34,7 @@ public func getBatteryInfo(_ options: GetBatteryInfoOptions) {
options.complete!(res);
}
}
public func test1(_ callback: UTSCallback) -> String {
public func test1(_ callback:@escaping () -> Void) -> String {
console.log(UTSJSONObject([
"a": "b"
]), " at uni_modules/test-uniplugin/utssdk/app-ios/index.uts:33");
......@@ -111,12 +119,14 @@ public func getBatteryInfoByJs(_ options: GetBatteryInfoOptionsJSONObject) {
}
public func test1ByJs(_ callback: UTSCallback) -> String {
return test1({
callback(res);
callback();
}
);
}
public func testAsyncByJs() {
return testAsync();
@available(iOS 13.0.0, *)
@available(iOS 13.0.0, *)
public func testAsyncByJs() async -> UTSJSONObject {
return await testAsync();
}
public func showToast1ByJs(_ msg: String) -> Void {
return showToast1(msg);
......@@ -136,8 +146,10 @@ public class IndexSwift : NSObject {
public static func s_test1ByJs(_ callback: UTSCallback) -> String {
return test1ByJs(callback);
}
public static func s_testAsyncByJs() {
return testAsyncByJs();
@available(iOS 13.0.0, *)
@available(iOS 13.0.0, *)
public static func s_testAsyncByJs() async -> UTSJSONObject {
return await testAsyncByJs();
}
public static func s_showToast1ByJs(_ msg: String) -> Void {
return showToast1ByJs(msg);
......
......@@ -13,12 +13,12 @@ const cls = /*#__PURE__*/ initUTSIndexClassName(name, is_uni_modules)
export const TestUTSComponent = {}
export const onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
export const offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
export const onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback"}]})
export const offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
export default /*#__PURE__*/ initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'User', is_uni_modules) }, {"constructor":{"params":[]},"methods":{},"staticMethods":{},"props":[],"staticProps":[]} ))
export const a = 1
export const showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1', params: [{"name":"msg","type":"string"}]})
export const showToast2 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast2', params: [{"name":"msg","type":"string"}]})
export const showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1ByJs', params: [{"name":"msg","type":"string"}]})
export const showToast2 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast2ByJs', params: [{"name":"msg","type":"string"}]})
"
`;
......@@ -37,13 +37,13 @@ const exports = { __esModule: true }
exports.TestUTSComponent = {}
exports.onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
exports.offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
exports.onMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback"}]})
exports.offMemoryWarning = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarningByJs', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
exports.default = initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'User', is_uni_modules) }, {"constructor":{"params":[]},"methods":{},"staticMethods":{},"props":[],"staticProps":[]} ))
const a = 1
exports.a = a
exports.showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1', params: [{"name":"msg","type":"string"}]})
exports.showToast2 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast2', params: [{"name":"msg","type":"string"}]})
exports.showToast1 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast1ByJs', params: [{"name":"msg","type":"string"}]})
exports.showToast2 = /*#__PURE__*/ initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'showToast2ByJs', params: [{"name":"msg","type":"string"}]})
uni.registerUTSPlugin('utssdk/test-uts', exports)
"
`;
......@@ -183,7 +183,7 @@ describe('uts:sourceMap', () => {
)
const { line, column, source } = await originalPositionFor({
sourceMapFile,
line: 17,
line: 25,
column: 0,
})
......
......@@ -31,6 +31,13 @@ export const enum FORMATS {
ES = 'es',
CJS = 'cjs',
}
type Types = { class: string[]; fn: Record<string, Param[]> }
interface Meta {
exports: Record<string, 'var' | 'function' | 'class'>
types: Record<string, 'function' | 'class'>
}
interface GenProxyCodeOptions {
is_uni_modules: boolean
id: string
......@@ -44,7 +51,7 @@ interface GenProxyCodeOptions {
moduleName?: string
moduleType?: string
types?: Types
exports?: Record<string, 'var' | 'function' | 'class'>
meta?: Meta
}
export async function genProxyCode(
......@@ -52,7 +59,13 @@ export async function genProxyCode(
options: GenProxyCodeOptions
) {
const { name, is_uni_modules, format, moduleName, moduleType } = options
if (!options.meta) {
options.meta = { exports: {}, types: {} }
}
options.types = await parseInterfaceTypes(module, options)
options.meta!.types = parseMetaTypes(options.types)
return `
const { initUTSProxyClass, initUTSProxyFunction, initUTSPackageName, initUTSIndexClassName, initUTSClassName } = uni
const name = '${name}'
......@@ -79,11 +92,22 @@ ${genModuleCode(
await parseModuleDecls(module, options),
format,
options.pluginRelativeDir!,
options.exports
options.meta!
)}
`
}
function parseMetaTypes(types: Types) {
let res: Meta['types'] = {}
types.class.forEach((n) => {
res[n] = 'class'
})
Object.keys(types.fn).forEach((n) => {
res[n] = 'function'
})
return res
}
export function genComponentsCode(
format: FORMATS = FORMATS.ES,
androidComponents: Record<string, string>,
......@@ -162,14 +186,14 @@ function genModuleCode(
decls: ProxyDecl[],
format: FORMATS = FORMATS.ES,
pluginRelativeDir: string,
exports: Record<string, 'var' | 'function' | 'class'> = {}
meta: Meta
) {
const codes: string[] = []
const exportDefault = exportDefaultCode(format)
const exportConst = exportVarCode(format, 'const')
decls.forEach((decl) => {
if (decl.type === 'Class') {
exports[decl.cls] = decl.isVar ? 'var' : 'class'
meta.exports[decl.cls] = decl.isVar ? 'var' : 'class'
if (decl.isDefault) {
codes.push(
......@@ -187,7 +211,7 @@ function genModuleCode(
)
}
} else if (decl.type === 'FunctionDeclaration') {
exports[decl.method] = decl.isVar ? 'var' : 'function'
meta.exports[decl.method] = decl.isVar ? 'var' : 'function'
if (decl.isDefault) {
codes.push(
......@@ -195,7 +219,7 @@ function genModuleCode(
decl.async
}, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: '${
decl.method
}', params: ${JSON.stringify(decl.params)}})`
}ByJs', params: ${JSON.stringify(decl.params)}})`
)
} else {
codes.push(
......@@ -203,12 +227,12 @@ function genModuleCode(
decl.async
}, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: '${
decl.method
}', params: ${JSON.stringify(decl.params)}})`
}ByJs', params: ${JSON.stringify(decl.params)}})`
)
}
} else if (decl.type === 'VariableDeclaration') {
decl.declarations.forEach((d) => {
exports[(d.id as Identifier).value] = 'var'
meta.exports[(d.id as Identifier).value] = 'var'
})
if (format === FORMATS.ES) {
......@@ -252,10 +276,13 @@ function genModuleCode(
async function parseInterfaceTypes(
module: string,
options: GenProxyCodeOptions
) {
): Promise<Types> {
const interfaceFilename = resolveRootInterface(module, options)
if (!interfaceFilename) {
return {}
return {
class: [],
fn: {},
}
}
// 懒加载 uts 编译器
// eslint-disable-next-line no-restricted-globals
......@@ -263,27 +290,33 @@ async function parseInterfaceTypes(
const ast: Module = await parse(fs.readFileSync(interfaceFilename, 'utf8'), {
noColor: !isColorSupported(),
})
const types: Record<string, Param[] | string> = {}
const classTypes: string[] = []
const fnTypes: Record<string, Param[]> = {}
ast.body.filter((node) => {
if (
node.type === 'ExportDeclaration' &&
node.declaration.type === 'TsTypeAliasDeclaration'
) {
switch (node.declaration.typeAnnotation.type) {
// export type ShowLoading = ()=>void
case 'TsFunctionType':
const params = createParams(node.declaration.typeAnnotation.params)
if (params.length) {
types[node.declaration.id.value] = params
fnTypes[node.declaration.id.value] = params
} else {
types[node.declaration.id.value] = []
fnTypes[node.declaration.id.value] = []
}
break
// export type ShowLoadingOptions = {}
case 'TsTypeLiteral':
types[node.declaration.id.value] = node.declaration.id.value
classTypes.push(node.declaration.id.value)
}
}
})
return types
return {
class: classTypes,
fn: fnTypes,
}
}
function createParams(tsParams: TsFnParameter[]) {
......@@ -300,7 +333,6 @@ function createParams(tsParams: TsFnParameter[]) {
return params
}
type Types = Awaited<ReturnType<typeof parseInterfaceTypes>>
async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
// 优先合并 ios + android,如果没有,查找根目录 index.uts
const iosDecls = await parseFile(
......@@ -393,7 +425,7 @@ async function parseCode(code: string, namespace: string, types: Types) {
const ast = await parse(code, { noColor: !isColorSupported() })
return parseAst(
ast,
createResolveTypeReferenceName(namespace, ast, types),
createResolveTypeReferenceName(namespace, ast, types.class),
types
)
}
......@@ -736,7 +768,7 @@ function genVariableDeclaration(
if (typeAnn && typeAnn.typeAnnotation.type === 'TsTypeReference') {
const { typeName } = typeAnn.typeAnnotation
if (typeName.type === 'Identifier') {
const value = types[typeName.value]
const value = types.fn[typeName.value]
if (isArray(value)) {
params = value
}
......
......@@ -82,14 +82,14 @@ function createResult(
errMsg: string,
code: string,
deps: string[],
exports: Record<string, 'var' | 'function' | 'class'>
meta: unknown
): CompileResult {
return {
dir,
code: parseErrMsg(code, errMsg),
deps,
encrypt: false,
meta: { exports },
meta,
}
}
......@@ -119,7 +119,12 @@ export async function compile(
const env = initCheckOptionsEnv()
const deps: string[] = []
const exports = {}
const meta = {
exports: {},
types: {},
}
const code = await genProxyCode(
pluginDir,
extend(
......@@ -134,7 +139,7 @@ export async function compile(
moduleName:
require(join(pluginDir, 'package.json')).displayName || pkg.id,
moduleType: process.env.UNI_UTS_MODULE_TYPE || '',
exports,
meta,
},
pkg
)
......@@ -208,7 +213,7 @@ export async function compile(
if (utsPlatform === 'app-ios') {
if (isWindows) {
process.env.UNI_UTS_TIPS = `iOS手机在windows上真机运行时uts插件代码修改需提交云端打包自定义基座才能生效`
return createResult(outputPluginDir, errMsg, code, deps, exports)
return createResult(outputPluginDir, errMsg, code, deps, meta)
}
// ios 模拟器不支持
if (process.env.HX_RUN_DEVICE_TYPE === 'ios_simulator') {
......@@ -218,7 +223,7 @@ export async function compile(
compileErrMsg(pkg.id),
code,
deps,
exports
meta
)
}
}
......@@ -286,7 +291,7 @@ export async function compile(
errMsg,
code,
res.files.map((name) => join(pluginDir, name)),
exports
meta
)
}
}
......@@ -402,7 +407,7 @@ export async function compile(
}
}
}
return createResult(outputPluginDir, errMsg, code, deps, exports)
return createResult(outputPluginDir, errMsg, code, deps, meta)
}
function getCompiler(type: 'kotlin' | 'swift') {
......
import path, { basename, resolve } from 'path'
import fs from 'fs-extra'
import type { parse, bundle, UTSTarget } from '@dcloudio/uts'
import { camelize, capitalize, extend, isString } from '@vue/shared'
import { camelize, capitalize, extend } from '@vue/shared'
import glob from 'fast-glob'
import { Module, ModuleItem } from '../types/types'
import {
......@@ -187,12 +187,12 @@ function resolveTypeAliasDeclNames(items: ModuleItem[]) {
export function createResolveTypeReferenceName(
namespace: string,
ast: Module,
types: Record<string, unknown>
interfaceTypes: string[]
) {
const names = resolveTypeAliasDeclNames(ast.body)
return (name: string) => {
if (names.includes(name) || isString(types[name])) {
return namespace + capitalize(name)
if (names.includes(name) || interfaceTypes.includes(name)) {
return namespace + capitalize(name) + 'JSONObject'
}
return name
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册