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

wip(uts): compiler

上级 6bc41845
......@@ -62,6 +62,7 @@ function transformSwiper(node) {
}
}
const customElements = ['aweme-data'];
const projectConfigFilename = 'project.config.json';
const nodeTransforms = [
uniCliShared.transformRef,
......@@ -119,7 +120,7 @@ const options = {
config: ['project.tt.json'],
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
......
......@@ -62,9 +62,7 @@ function transformSwiper(node) {
}
}
const customElements = [
'aweme-data'
];
const customElements = ['aweme-data'];
const projectConfigFilename = 'project.config.json';
const nodeTransforms = [
uniCliShared.transformRef,
......
......@@ -2,6 +2,7 @@ import { resolve } from 'path'
import { FORMATS, genProxyCode } from '../src/code'
import { ERR_MSG_PLACEHOLDER } from '../src/utils'
const inputDir = resolve(__dirname, 'examples/uts')
const pluginDir = resolve(__dirname, 'examples/uts/utssdk/test-uts')
describe('code', () => {
......@@ -17,6 +18,7 @@ describe('code', () => {
namespace: 'uts.sdk.testUTS',
extname: '.uts',
androidComponents: { TestUTS: '' },
inputDir,
})
).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot()
......@@ -33,6 +35,7 @@ describe('code', () => {
format: FORMATS.CJS,
pluginRelativeDir: 'utssdk/test-uts',
androidComponents: { TestUTS: '' },
inputDir,
})
).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot()
......
......@@ -51,6 +51,7 @@ interface GenProxyCodeOptions {
androidComponents?: Record<string, string>
iosComponents?: Record<string, string>
format?: FORMATS
inputDir?: string
pluginRelativeDir?: string
moduleName?: string
moduleType?: string
......@@ -63,11 +64,10 @@ export async function genProxyCode(
options: GenProxyCodeOptions
) {
const { name, is_uni_modules, format, moduleName, moduleType } = options
options.inputDir = options.inputDir || process.env.UNI_INPUT_DIR
if (!options.meta) {
options.meta = { exports: {}, types: {} }
}
options.types = await parseInterfaceTypes(module, options)
options.meta!.types = parseMetaTypes(options.types)
return `
......@@ -294,11 +294,11 @@ async function parseInterfaceTypes(
let ast: Module | null = null
try {
ast = await parse(fs.readFileSync(interfaceFilename, 'utf8'), {
filename: relative(interfaceFilename, process.env.UNI_INPUT_DIR),
filename: relative(interfaceFilename, options.inputDir!),
noColor: !isColorSupported(),
})
} catch (e) {
console.error(parseUTSSyntaxError(e, process.env.UNI_INPUT_DIR))
console.error(parseUTSSyntaxError(e, options.inputDir!))
}
const classTypes: string[] = []
const fnTypes: Record<string, Param[]> = {}
......@@ -455,7 +455,8 @@ async function parseFile(
fs.readFileSync(filename, 'utf8'),
options.namespace,
options.types!,
filename
filename,
options.inputDir!
)
}
return []
......@@ -465,14 +466,15 @@ async function parseCode(
code: string,
namespace: string,
types: Types,
filename: string
filename: string,
inputDir: string
): Promise<ProxyDecl[]> {
// 懒加载 uts 编译器
// eslint-disable-next-line no-restricted-globals
const { parse } = require('@dcloudio/uts')
try {
const ast = await parse(code, {
filename: relative(filename, process.env.UNI_INPUT_DIR),
filename: relative(filename, inputDir),
noColor: !isColorSupported(),
})
return parseAst(
......@@ -481,7 +483,7 @@ async function parseCode(
types
)
} catch (e: any) {
console.error(parseUTSSyntaxError(e, process.env.UNI_INPUT_DIR))
console.error(parseUTSSyntaxError(e, inputDir))
}
return []
}
......
......@@ -140,6 +140,7 @@ export async function compile(
require(join(pluginDir, 'package.json')).displayName || pkg.id,
moduleType: process.env.UNI_UTS_MODULE_TYPE || '',
meta,
inputDir,
},
pkg
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册