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

wip(uts): compiler

上级 5ab59969
......@@ -11,7 +11,9 @@ export class User implements IUser {
Log.info('123')
Log.info(logo)
}
register(name: string) {
register(name: string, callback: () => void) {
Log.info(logo)
}
}
function login(name: string, callback: () => void) {}
export function register(name: string, callback: () => void) {}
......@@ -6,9 +6,9 @@ import android.util.Log;
interface IUser {
fun register(name: String): Unit;
}
fun login(name: String, pwd: String): UtsJSONObject {
fun login(name: String, pwd: String): UTSJSONObject {
console.log("login", "at uni_modules/test-uniplugin/app-android/login.uts:2");
return object : UtsJSONObject() {
return object : UTSJSONObject() {
var name = name
var pwd = pwd
};
......@@ -24,7 +24,9 @@ open class User : IUser {
Log.info("123");
Log.info(__default);
}
override fun register(name: String) {
override fun register(name: String, callback: UTSCallback) {
Log.info(__default);
}
}
fun login(name: String, callback: () -> Unit) {}
fun register(name: String, callback: UTSCallback) {}
{"version":3,"sources":["/Users/guoshengqiang/Documents/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/static/logo.png","/Users/guoshengqiang/Documents/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/index.uts","/Users/guoshengqiang/Documents/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/interface.uts","/Users/guoshengqiang/Documents/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/login.uts"],"sourcesContent":["import { getResourcePath } from 'io.dcloud.uts.android'\nexport default getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport { IUser } from './interface.uts'\nimport { login } from './login.uts'\nimport logo from '../static/logo.png'\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 Log.info('123')\n Log.info(logo)\n }\n register(name: string) {\n Log.info(logo)\n }\n}\n","export interface IUser {\n register(name: string): void\n}\n","export function login(name: string, pwd: string) {\n console.log('login')\n return { name, pwd }\n}\n"],"names":[],"mappings":";;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;UCAjB,KAAK;QACpB,QAAQ,CAAC,IAAY,EAAN,MAAM,GAAG,IAAI;;ACDvB,IAAS,KAAK,CAAC,IAAY,EAAN,MAAM,EAAE,GAAW,EAAN,MAAM,iBAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,0DAAC;IACpB,OAAO;QAAE,IAAA,IAAI,GAAJ,IAAI;QAAE,IAAA,GAAG,GAAH,GAAG;KAAE,CAAA;AACtB;gBHFe,eAAe,CAAC,4CAA4C,CAAC;ACGrE,WAAM,IAAI,GAAY,KAAK;qBAC1B,KAAK,CAAC,IAAY,EAAN,MAAM,EAAE,GAAW,EAAN,MAAM,8CAAE;QACrC,UAAU,CAAC,KAAM;YACf,OAAO,CAAC,GAAG,CAAC,SAAS,0DAAC;QACxB;QAAC,EAAE,IAAI,CAAC;QACR,MAAM,IAAI,EAAE,GAAG,CAAC;QAChB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;QACf,GAAG,CAAC,IAAI,WAAM;IAChB;iBACA,QAAQ,CAAC,IAAY,EAAN,MAAM,EAAE;QACrB,GAAG,CAAC,IAAI,WAAM;IAChB;CACD"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/static/logo.png","/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/index.uts","/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/interface.uts","/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/uni_modules/test-uniplugin/app-android/login.uts"],"sourcesContent":["import { getResourcePath } from 'io.dcloud.uts.android'\nexport default getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport { IUser } from './interface.uts'\nimport { login } from './login.uts'\nimport logo from '../static/logo.png'\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 Log.info('123')\n Log.info(logo)\n }\n register(name: string, callback: () => void) {\n Log.info(logo)\n }\n}\nfunction login(name: string, callback: () => void) {}\nexport function register(name: string, callback: () => void) {}\n","export interface IUser {\n register(name: string): void\n}\n","export function login(name: string, pwd: string) {\n console.log('login')\n return { name, pwd }\n}\n"],"names":[],"mappings":";;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;UCAjB,KAAK;QACpB,QAAQ,CAAC,IAAY,EAAN,MAAM,GAAG,IAAI;;ACDvB,IAAS,KAAK,CAAC,IAAY,EAAN,MAAM,EAAE,GAAW,EAAN,MAAM,iBAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,0DAAC;IACpB,OAAO;QAAE,IAAA,IAAI,GAAJ,IAAI;QAAE,IAAA,GAAG,GAAH,GAAG;KAAE,CAAA;AACtB;gBHFe,eAAe,CAAC,4CAA4C,CAAC;ACGrE,WAAM,IAAI,GAAY,KAAK;qBAC1B,KAAK,CAAC,IAAY,EAAN,MAAM,EAAE,GAAW,EAAN,MAAM,8CAAE;QACrC,UAAU,CAAC,KAAM;YACf,OAAO,CAAC,GAAG,CAAC,SAAS,0DAAC;QACxB;QAAC,EAAE,IAAI,CAAC;QACR,MAAM,IAAI,EAAE,GAAG,CAAC;QAChB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;QACf,GAAG,CAAC,IAAI,WAAM;IAChB;iBACA,QAAQ,CAAC,IAAY,EAAN,MAAM,EAAE,QAAoB,aAAA,EAAE;QAC3C,GAAG,CAAC,IAAI,WAAM;IAChB;CACD;AACD,UAAe,IAAY,EAAN,MAAM,EAAE,QAAoB,QAAJ,IAAI,EAAE,CAAC,CAAC;AAC9C,IAAS,QAAQ,CAAC,IAAY,EAAN,MAAM,EAAE,QAAoB,aAAA,EAAE,CAAC,CAAC"}
\ No newline at end of file
......@@ -5,6 +5,8 @@ const DEFAULT_KEYS = [
'APP_PLUS',
'APP_PLUS_NVUE',
'APP_VUE',
'APP_ANDROID',
'APP_IOS',
'H5',
'MP',
'MP_360',
......@@ -60,6 +62,15 @@ export function initPreContext(
nvueContext.APP_NVUE = true
nvueContext.APP_PLUS_NVUE = true
if (process.env.UNI_APP_PLATFORM === 'app-android') {
defaultContext.APP_ANDROID = true
} else if (process.env.UNI_APP_PLATFORM === 'app-ios') {
defaultContext.APP_IOS = true
} else {
defaultContext.APP_ANDROID = true
defaultContext.APP_IOS = true
}
} else if (platform.startsWith('mp-')) {
defaultContext.MP = true
} else if (platform.startsWith('quickapp-webview')) {
......
......@@ -50,31 +50,31 @@ at node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.
})
})
test('utsStracktraceyPreset local', () => {
stacktracey(utsErrorMsg, {
preset: utsStracktraceyPreset({
base: path.resolve(
__dirname,
'../test/nativeplugins-sourceMap/DCloud-UTSPlugin/'
),
sourceRoot: 'DCloud-UTSPlugin/android/src/',
}),
}).then((res: string) => {
expect(res)
.toEqual(`e: C:/Users/xianyang/Documents/HBuilderProjects/test-uni2/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.uts: (7, 0): Unresolved reference: logxxxxxxx
// test('utsStracktraceyPreset local', () => {
// stacktracey(utsErrorMsg, {
// preset: utsStracktraceyPreset({
// base: path.resolve(
// __dirname,
// '../test/nativeplugins-sourceMap/DCloud-UTSPlugin/'
// ),
// sourceRoot: 'DCloud-UTSPlugin/android/src/',
// }),
// }).then((res: string) => {
// expect(res)
// .toEqual(`e: C:/Users/xianyang/Documents/HBuilderProjects/test-uni2/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.uts: (7, 0): Unresolved reference: logxxxxxxx
FAILURE: Build failed with an exception.
// FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
> Compilation error. See log for more details
// * What went wrong:
// Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
// > Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
// * Try:
// Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
// * Get more help at https://help.gradle.org
BUILD FAILED in 2s`)
})
})
// BUILD FAILED in 2s`)
// })
// })
})
{"version":3,"sources":["C:/Users/xianyang/Documents/HBuilderProjects/test-uni2/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.uts"],"names":["logxxxxxxx","TestModule","UniModule","TAG","UniJSMethod","uiThread","testAsyncFunc","options","callback","log","data","JSONObject","invoke","testSyncFunc","onActivityResult","requestCode","resultCode","REQUEST_CODE","hasExtra","getStringExtra"],"mappings":";AAAA,OAAmB,sBAAwB,CAAC;AAC5C,OAAuB,+BAAiC,CAAC;AACzD,OAAsB,yCAA2C,CAAC;AAClE,OAAwB,+CAAiD,CAAC;AAC1E,OAA0B,6CAA+C,CAAC;AAC1E,OAAgB,2BAAO,CAAC;;IACxBA,UAAU;;AACK,WAAMC,UAAU,GAASC,SAAS,EAAE;IACjDC,SAAAA,GAAG,GAAG,YAAY,CAAC;IAGnB,CAACC,WAAW,CAAC,CAAEC,QAAQ,GAAE,IAAI,CAAE,CAAC;IAAA,SAChCC,aAAa,CAACC,OAAmB,EAAV,UAAU,EAAEC,QAAwB,EAAb,aAAa,CAAA,EAAE;QAC3DC,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,yBAAyB,CAAC,CAAC;QACzC,IAAIK,QAAQ,IAAI,IAAI,EAAE;YACpB,IAAME,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;YAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;YAC9BF,QAAQ,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;;;IAI1B,CAACN,WAAW,CAAC,CAAEC,QAAQ,GAAE,KAAK,CAAE,CAAC;IAAA,SACjCQ,YAAY,CAACN,OAAmB,EAAV,UAAU,GAAG,UAAU,CAAC;QAC5C,IAAMG,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;QAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QAC5B,OAAOA,IAAI,CAAC;;IAEd,kBAASI,gBAAgB,CAACC,WAAgB,EAAH,GAAG,EAAEC,UAAe,EAAH,GAAG,EAAEN,IAAY,EAAN,MAAM,EAAE;QACzE,IAAIK,WAAW,IAAId,UAAU,CAACgB,YAAY,IAAIP,IAAI,CAACQ,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtET,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,wBAAY,GAAGO,IAAI,CAACS,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;;QAC9D,MAAM;YACL,KAAK,CAACL,gBAAgB,CAACC,WAAW,EAAEC,UAAU,EAAEN,IAAI,CAAC,CAAC;;;;QAtB1D,IAAOO,YAAY,GAAG,IAAI,CAAC;;CAyB5B"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-battery/app-android/index.uts"],"sourcesContent":["import Context from \"android.content.Context\";\nimport BatteryManager from \"android.os.BatteryManager\";\nimport { getAppContext } from \"io.dcloud.uts.android\";\n\nexport default function getBatteryCapacity(): number {\n const context = getAppContext();\n if (context != null) {\n const manager = context.getSystemService(\n Context.BATTERY_SERVICE\n ) as BatteryManager;\n const currentLevel: number = manager.getIntProperty(\n BatteryManager.BATTERY_PROPERTY_CAPACITY\n );\n return currentLevel;\n }\n return 0;\n}"],"names":[],"mappings":";;;;;;AAAA,OAAoB,uBAAyB,CAAC;AAC9C,OAA2B,yBAA2B,CAAC;AACvD;AAEe,IAAS,kBAAkB,IAAI,MAAM,CAAC;IACnD,IAAM,OAAO,GAAG,aAAa,EAAE,AAAC;IAChC,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,IAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CACtC,OAAO,CAAC,eAAe,CACxB,IAAI,cAAc,AAAC;QACpB,IAAM,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CACjD,cAAc,CAAC,yBAAyB,CACzC,AAAC;QACF,OAAO,YAAY,CAAC;IACtB;IACA,OAAO,CAAC,CAAC;AACX"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-static/static/logo.png","/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-static/app-android/index.uts"],"sourcesContent":["import { getResourcePath } from 'io.dcloud.uts.android'\nexport default getResourcePath('uni_modules/test-uts-static/static/logo.png')\n ","import logo from \"../static/logo.png\";\nexport function getLogoPath(): string {\n return logo;\n}\n"],"names":[],"mappings":";;;;;;AAAA;gBACe,eAAe,CAAC,6CAA6C,CAAC;ACAtE,IAAS,WAAW,IAAI,MAAM,CAAC;IACpC,iBAAY;AACd"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts/app-android/utils.uts","/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts/app-android/index.uts"],"sourcesContent":["export function log(msg: string) {\n console.log(msg);\n}\n","import { log } from \"./utils.uts\";\ntype AsyncOptions = {\n type: string;\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\n/**\n * 导出一个属性\n */\nexport const MAX = 100;\n\n/**\n * 导出一个同步方法\n * @returns\n */\nexport function testSync(msg: string) {\n console.log(\"log test\");\n log(\"log test1\");\n return {\n msg: `hello ${msg}`,\n };\n}\n/**\n * 导出一个同步方法(触发了数组越界异常)\n */\nexport function testSyncError() {\n const arr: string[] = [];\n console.log(arr[1]);\n}\n/**\n * 导出一个带callback的同步方法\n * @param opts\n */\nexport function testSyncWithCallback(opts: AsyncOptions) {\n if (opts.type == \"success\") {\n opts.success(\"success\");\n } else {\n opts.fail(\"fail\");\n }\n opts.complete(\"complete\");\n return { name: \"testSyncWithCallback\" };\n}\n/**\n * 导出一个异步方法\n * @returns\n */\nexport async function testAsync(opts: AsyncOptions) {\n if (opts.type == \"success\") {\n opts.success(\"success\");\n } else {\n opts.fail(\"fail\");\n }\n opts.complete(\"complete\");\n return { name: \"testAsync\" };\n}\n\ntype TestOptions = {\n name: string;\n callback: (res: string) => void;\n};\n\nexport class Test {\n id: number;\n name: string;\n static type: string = \"Test\";\n constructor(id: number, options: TestOptions) {\n this.id = id;\n this.name = options.name;\n options.callback(\"Test.constructor\");\n }\n static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject {\n return testSyncWithCallback(opts);\n }\n static async testClassStaticAsync(opts: AsyncOptions): Promise<UTSJSONObject> {\n const res = await testAsync(opts);\n return res;\n }\n testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject {\n return testSyncWithCallback(opts);\n }\n async testClassAsync(opts: AsyncOptions): Promise<UtsJSONObject> {\n const res = await testAsync(opts);\n return res;\n }\n}\n"],"names":[],"mappings":";;;;;;AAAO,IAAS,GAAG,CAAC,GAAW,EAAN,MAAM,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,GAAG,oDAAC,CAAC;AACnB;ACDoB,WAAf,YAAY;IACf,kBAAA,IAAI,EAAE,MAAM,CAAC;IACb,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAIK,IAAM,GAAG,GAAG,GAAG,AAAC;AAMhB,IAAS,QAAQ,CAAC,GAAW,EAAN,MAAM,iBAAE;IACpC,OAAO,CAAC,GAAG,CAAC,UAAU,qDAAC,CAAC;IACxB,IAAI,WAAW,CAAC,CAAC;IACjB,OAAO;QACL,IAAA,GAAG,GAAE,GAAC,MAAM,EAAE,GAAG,CAAC,GAAC;KACpB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,CAAC;QAC3D,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACpC;qBACM,cAAc,CAAC,IAAkB,EAAZ,YAAY,GAAG,QAAO,CAAC,aAAa,8CAAE;QAC/D,IAAM,GAAG,GAAG,AAAM,SAAS,CAAC,IAAI,CAAC,QAAA,AAAC;QAClC,aAAO,GAAG,CAAC;IACb;;QAnBA,IAAO,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;YAMtB,+BAA+B,CAAC,IAAkB,EAAZ,YAAY,GAAG,aAAa,CAAC;YACxE,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACpC;oBACa,oBAAoB,CAAC,IAAkB,EAAZ,YAAY,GAAG,QAAO,CAAC,aAAa,8CAAE;YAC5E,IAAM,GAAG,GAAG,AAAM,SAAS,CAAC,IAAI,CAAC,QAAA,AAAC;YAClC,aAAO,GAAG,CAAC;QACb;;CAQD"}
\ No newline at end of file
......@@ -272,7 +272,7 @@ function genProxyCode({ body }: Module) {
}
} else if (decl.type === 'FunctionExpression') {
if (decl.identifier) {
code = genFunctionDeclarationCode(decl, false)
code = genFunctionDeclarationCode(decl, true)
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册