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

wip(uts): compiler

上级 710eec64
......@@ -11,6 +11,8 @@ const is_uni_modules = false
const pkg = initUTSPackageName(name, is_uni_modules)
const cls = initUTSIndexClassName(name, is_uni_modules)
export const TestUtsComponent = {}
export const onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
export const offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
export default initUTSProxyClass(Object.assign({ moduleName, moduleType, errMsg, package: pkg, class: initUTSClassName(name, 'User', is_uni_modules) }, {"constructor":{"params":[]},"methods":{},"staticMethods":{},"props":[],"staticProps":[]} ))
......@@ -30,6 +32,9 @@ const pkg = initUTSPackageName(name, is_uni_modules)
const cls = initUTSIndexClassName(name, is_uni_modules)
const exports = { __esModule: true }
exports.TestUtsComponent = {}
exports.onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
exports.offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', 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":[]} ))
......
......@@ -16,6 +16,7 @@ describe('code', () => {
name: 'test-uts',
namespace: 'uts.sdk.testUts',
extname: '.uts',
androidComponents: { TestUts: '' },
})
).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot()
......@@ -31,6 +32,7 @@ describe('code', () => {
extname: '.uts',
format: FORMATS.CJS,
pluginRelativeDir: 'utssdk/test-uts',
androidComponents: { TestUts: '' },
})
).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot()
......
......@@ -16,6 +16,9 @@
"package.json": {
"md5": "2a19a08ee8a5d77c1e2dfcef55a8f1c1"
},
"utssdk/app-android/index.vue": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"utssdk/app-android/assets/test.json": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
}
......
......@@ -53,6 +53,7 @@ describe('manifest', () => {
'utssdk/index.uts',
'utssdk/common/utils.uts',
'utssdk/app-android/index.uts',
'utssdk/app-android/index.vue',
'utssdk/app-android/assets/test.json',
])
})
......@@ -109,7 +110,7 @@ describe('manifest', () => {
test('gen android manifest', async () => {
const res = await checkKotlinCompile('standard', pluginModuleOptions)
expect(res.expired).toBe(false)
expect(res.files.length).toBe(5)
expect(res.files.length).toBe(6)
expect(res.tips).toBeTruthy()
const res1 = await checkKotlinCompile('standard', pluginOptions)
......
......@@ -51,10 +51,19 @@ const errMsg = \`${ERR_MSG_PLACEHOLDER}\`
const is_uni_modules = ${is_uni_modules}
const pkg = initUTSPackageName(name, is_uni_modules)
const cls = initUTSIndexClassName(name, is_uni_modules)
${
format === FORMATS.CJS
? `
const exports = { __esModule: true }
`
: ''
}
${genComponentsCode(
format,
options.androidComponents || {},
options.iosComponents || {}
)}
${genModuleCode(
await parseModuleDecls(module, options),
format,
......@@ -64,13 +73,18 @@ ${genModuleCode(
}
export function genComponentsCode(
format: FORMATS = FORMATS.ES,
androidComponents: Record<string, string>,
iosComponents: Record<string, string>
) {
const codes: string[] = []
Object.keys(Object.assign({}, androidComponents, iosComponents)).forEach(
(name) => {
codes.push(`export const ${capitalize(camelize(name))}Component = {}`)
if (format === FORMATS.CJS) {
codes.push(`exports.${capitalize(camelize(name))}Component = {}`)
} else {
codes.push(`export const ${capitalize(camelize(name))}Component = {}`)
}
}
)
return codes.join('\n')
......@@ -124,9 +138,6 @@ function genModuleCode(
pluginRelativeDir: string
) {
const codes: string[] = []
if (format === FORMATS.CJS) {
codes.push(`const exports = { __esModule: true }`)
}
const exportDefault = exportDefaultCode(format)
const exportConst = exportVarCode(format, 'const')
decls.forEach((decl) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册