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

wip(uts): compiler

上级 e47eb2b9
{"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,qBAAS;ACAT,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;;gBJAf,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,gBAAgB,IAAI,EAAE;QAC3C,IAAI,IAAI,cAAS;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,gBAAgB,IAAI,EAAE,CAAE;AAC1D,IAAS,iBACd,YAAmB,OAAO,MAAM,KAAK,IAAI,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;;;uBA3DjD,MAAM,MAAM,EAAE,KAAK,MAAM;qBAAzB,MAAc;;0BAoCjB,MAAM,MAAM,EAAE;wBAAd;YAAc;;;;sBAGlB,MAAM,IAAI;oBAAV;;;iBAOoB,MAAM,MAAM,EAAE;oBAAd;QAAc;;;;yBAEvC,yBAA6C,IAAI;gCAA9B,OAAO,MAAM;QAAhC,iBAAmB;;;;mBIhEI,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-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/static/logo.png","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["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 default UTSAndroid.getResourcePath('uni_modules/test-uniplugin/static/logo.png')","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;;;;;;AAAA,OAAgB,gBAAkB,CAA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e,MAAM,MAAM,EAAE,gBAAgB,IAAI,EAAE,CAAE;AAErD,CAAC,SAAS;AAAc,IACN,SAAS,MAAM,MAAM,EAAE,gBAAgB,IAAI,EAAE,CAAE;AAC1D,IAAS,iBACd,YAAmB,OAAO,MAAM,KAAK,IAAI,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;;;uBA3DjD,MAAM,MAAM,EAAE,KAAK,MAAM;qBAAzB,MAAc;;0BAoCjB,MAAM,MAAM,EAAE;wBAAd;YAAc;;;;sBAGlB,MAAM,IAAI;oBAAV;;;iBAOoB,MAAM,MAAM,EAAE;oBAAd;QAAc;;;;yBAEvC,yBAA6C,IAAI;gCAA9B,OAAO,MAAM;QAAhC,iBAAmB;;;;mBKhEI,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB;;mBAAA,KAAK,MAAM,GAAK,IAAI;sBAApB"}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers;
import io.dcloud.uts.Map;
import io.dcloud.uts.*;
import io.dcloud.uts.UTSAndroid;
import android.util.Log;
import android.widget.FrameLayout;
import android.view.View;
......
......@@ -15,7 +15,7 @@ describe('compiler:codegen', () => {
test(`function:kotlin`, () => {
assert(
`<view/>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {\n return createElementVNode("view")\n}`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\n return createElementVNode("view")\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......@@ -25,7 +25,7 @@ describe('compiler:codegen', () => {
test(`UTSComponents:kotlin`, () => {
assert(
`<view><uts-hello/><uts-hello/></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name)\n ])\n}`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name)\n ])\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......@@ -44,7 +44,7 @@ describe('compiler:codegen', () => {
test(`UTSComponents:kotlin`, () => {
assert(
`<view><custom/><custom/><custom1/></view>`,
`import _easycom_custom from '@/components/custom/custom.vue'\nimport _easycom_custom1 from '@/components/custom1/custom1.vue'\n@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {\nconst _component_custom = resolveEasyComponent("custom",_easycom_custom)\nconst _component_custom1 = resolveEasyComponent("custom1",_easycom_custom1)\n\n return createElementVNode("view", null, [\n createVNode(_component_custom),\n createVNode(_component_custom),\n createVNode(_component_custom1)\n ])\n}`,
`import _easycom_custom from '@/components/custom/custom.vue'\nimport _easycom_custom1 from '@/components/custom1/custom1.vue'\n@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _component_custom = resolveEasyComponent("custom",_easycom_custom)\nconst _component_custom1 = resolveEasyComponent("custom1",_easycom_custom1)\n\n return createElementVNode("view", null, [\n createVNode(_component_custom),\n createVNode(_component_custom),\n createVNode(_component_custom1)\n ])\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......
......@@ -4,7 +4,8 @@ describe('compiler: component', () => {
test('template component', () => {
assert(
`<view><Foo /></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......
......@@ -92,7 +92,8 @@ describe('compiler: slot', () => {
test('component with slot', () => {
assert(
`<view><slot data="data"></slot></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
return createElementVNode("view", null, [
renderSlot(_ctx.$slots, "default", new Map<string, any | null>([["data", "data"]]))
])
......@@ -107,7 +108,8 @@ describe('compiler: slot', () => {
test('template component with slot', () => {
assert(
`<view><Foo @click="test">test</Foo></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......@@ -129,7 +131,8 @@ const _component_Foo = resolveComponent("Foo")
test('slot in text', () => {
assert(
`<view><text><slot/></text></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
return createElementVNode("view", null, [
createElementVNode("text", null, [
renderSlot(_ctx.$slots, "default")
......@@ -146,7 +149,8 @@ const _component_Foo = resolveComponent("Foo")
test('scoped slots', () => {
assert(
`<view><Foo><template v-slot="props"><text>msg: {{props.msg}}</text></template></Foo></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......@@ -168,7 +172,8 @@ const _component_Foo = resolveComponent("Foo")
test('scoped slots shorthand', () => {
assert(
`<view><Foo><template #default="props"><text>msg: {{props.msg}}</text></template></Foo></view>`,
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(_ctx: PagesIndexIndex): VNode | null {
`@Suppress("UNUSED_PARAMETER") function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......
......@@ -170,6 +170,8 @@ export function generate(
if (mode === 'function') {
genEasyComImports(ast.components, context)
push(genRenderFunctionDecl(options) + ` {`)
newline()
push(`const _ctx = this`)
// generate asset resolution statements
if (ast.components.length) {
newline()
......
......@@ -12,7 +12,7 @@ export function genRenderFunctionDecl({
}: CompilerOptions): string {
return `${
targetLanguage === 'kotlin' ? '@Suppress("UNUSED_PARAMETER") ' : ''
}function ${filename}Render(_ctx: ${filename}): VNode | null`
}function ${filename}Render(): VNode | null`
}
export function expContentToMapString(exp: ExpressionNode): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册