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

wip(x-android): tsc

上级 1c19012e
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`compiler: v-for codegen basic v-for 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return createElementVNode("text")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen keyed template v-for 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return createElementVNode(Fragment, utsMapOf({ key: item }), [
"hello",
createElementVNode("text")
......@@ -16,31 +16,31 @@ exports[`compiler: v-for codegen keyed template v-for 1`] = `
`;
exports[`compiler: v-for codegen keyed v-for 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return createElementVNode("text", utsMapOf({ key: item }))
}), 128 /* KEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen skipped key 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, index, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, index, _cached): VNode => {
return createElementVNode("text")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen skipped value & key 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (_, _, index, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (__value, __key, index, _cached): VNode => {
return createElementVNode("text")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen skipped value 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (_, key, index, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (__value, key, index, _cached): VNode => {
return createElementVNode("text")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen template v-for 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return createElementVNode(Fragment, null, [
"hello",
createElementVNode("text")
......@@ -49,7 +49,7 @@ exports[`compiler: v-for codegen template v-for 1`] = `
`;
exports[`compiler: v-for codegen template v-for key injection with single child 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return createElementVNode("text", utsMapOf({
key: item.id,
id: item.id
......@@ -58,19 +58,19 @@ exports[`compiler: v-for codegen template v-for key injection with single child
`;
exports[`compiler: v-for codegen template v-for w/ <slot/> 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return renderSlot($slots, "default")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen v-for on <slot/> 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, __key, __index, _cached): VNode => {
return renderSlot($slots, "default")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
exports[`compiler: v-for codegen v-for on element with custom directive 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(list, (i, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(list, (i, __key, __index, _cached): VNode => {
return withDirectives(createElementVNode("view", null, null, 512 /* NEED_PATCH */), [
[_directive_foo]
])
......@@ -78,14 +78,14 @@ exports[`compiler: v-for codegen v-for on element with custom directive 1`] = `
`;
exports[`compiler: v-for codegen v-for with constant expression 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(10, (item, _, _, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(10, (item, __key, __index, _cached): VNode => {
return createElementVNode("p", null, toDisplayString(item), 1 /* TEXT */)
}), 64 /* STABLE_FRAGMENT */)"
`;
exports[`compiler: v-for codegen v-if + v-for 1`] = `
"isTrue(ok)
? createElementVNode(Fragment, utsMapOf({ key: 0 }), RenderHelpers.renderList(list, (i, _, _, _): VNode => {
? createElementVNode(Fragment, utsMapOf({ key: 0 }), RenderHelpers.renderList(list, (i, __key, __index, _cached): VNode => {
return createElementVNode("view")
}), 256 /* UNKEYED_FRAGMENT */)
: createCommentVNode("v-if", true)"
......@@ -93,14 +93,14 @@ exports[`compiler: v-for codegen v-if + v-for 1`] = `
exports[`compiler: v-for codegen v-if + v-for on <template> 1`] = `
"isTrue(ok)
? createElementVNode(Fragment, utsMapOf({ key: 0 }), RenderHelpers.renderList(list, (i, _, _, _): VNode => {
? createElementVNode(Fragment, utsMapOf({ key: 0 }), RenderHelpers.renderList(list, (i, __key, __index, _cached): VNode => {
return createElementVNode(Fragment, null, [], 64 /* STABLE_FRAGMENT */)
}), 256 /* UNKEYED_FRAGMENT */)
: createCommentVNode("v-if", true)"
`;
exports[`compiler: v-for codegen value + key + index 1`] = `
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, key, index, _): VNode => {
"createElementVNode(Fragment, null, RenderHelpers.renderList(items, (item, key, index, _cached): VNode => {
return createElementVNode("text")
}), 256 /* UNKEYED_FRAGMENT */)"
`;
......@@ -39,7 +39,7 @@ function Render(): any | null {
const _ctx = this
const _cache = this.$.renderCache
return createElementVNode("view", null, [
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, _, _, _cached): VNode => {
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, __key, __index, _cached): VNode => {
const _memo: Array<any | null> = ([x, y === _ctx.z])
if (_cached != null && _cached.key === x && isMemoSame(_cached, _memo)) return _cached
const _item = createElementVNode("text", utsMapOf({ key: x }), "foobar")
......@@ -56,7 +56,7 @@ function Render(): any | null {
const _ctx = this
const _cache = this.$.renderCache
return createElementVNode("view", null, [
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, _, _, _cached): VNode => {
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, __key, __index, _cached): VNode => {
const _memo: Array<any | null> = ([x, y === _ctx.z])
if (_cached != null && _cached.key === x && isMemoSame(_cached, _memo)) return _cached
const _item = createElementVNode("view", utsMapOf({ key: x }), [
......
......@@ -100,7 +100,7 @@ export class UniAppConfig extends io.dcloud.uniapp.appframe.AppConfig {
process.env.UNI_COMPILER_VERSION || ''
}"
${codes}
constructor() {}
constructor() { super() }
}
`
}
......
......@@ -209,9 +209,10 @@ export const transformFor = createStructuralDirectiveTransform(
if (memo) {
const loop = createFunctionExpression(
createForLoopParams(forNode.parseResult, [
createSimpleExpression(`_cached`),
])
createForLoopParams(
forNode.parseResult,
createSimpleExpression(`_cached`)
)
)
loop.body = createBlockStatement([
createCompoundExpression([
......@@ -238,9 +239,10 @@ export const transformFor = createStructuralDirectiveTransform(
} else {
renderExp.arguments.push(
createFunctionExpression(
createForLoopParams(forNode.parseResult, [
createSimpleExpression(`_`),
]),
createForLoopParams(
forNode.parseResult,
createSimpleExpression(`_cached`)
),
childBlock,
true /* force newline */
) as ForIteratorExpression
......@@ -285,7 +287,7 @@ export function processFor(
if (key === undefined) {
parseResult.key = {
constType: 2,
content: '_',
content: '__key',
isStatic: false,
loc: value?.loc!,
type: 4,
......@@ -295,7 +297,7 @@ export function processFor(
if (index === undefined) {
parseResult.index = {
constType: 2,
content: '_',
content: '__index',
isStatic: false,
loc: value?.loc!,
type: 4,
......@@ -473,13 +475,14 @@ function createAliasExpression(
)
}
export function createForLoopParams(
function createForLoopParams(
{ value, key, index }: ForParseResult,
memoArgs: ExpressionNode[] = []
memoArgs: ExpressionNode
): ExpressionNode[] {
return createParamsList([value, key, index, ...memoArgs])
return createParamsList([value, key, index, memoArgs])
}
const paramNames = ['__value', '__key', '__item', '_cached']
function createParamsList(
args: (ExpressionNode | undefined)[]
): ExpressionNode[] {
......@@ -489,5 +492,5 @@ function createParamsList(
}
return args
.slice(0, i + 1)
.map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false))
.map((arg, i) => arg || createSimpleExpression(paramNames[i], false))
}
import { defineComponent as defineComponentOrigin } from '@vue/runtime-core'
import {
defineApp as defineAppOrigin,
defineComponent as defineComponentOrigin
} from '@vue/runtime-core'
declare global {
const CSS_VAR_WINDOW_TOP: number
const CSS_VAR_WINDOW_BOTTOM: number
const CSS_VAR_STATUS_BAR_HEIGHT: number
const defineApp: typeof defineAppOrigin
const defineComponent: typeof defineComponentOrigin
const __uniConfig: UniConfig
const __uniRoutes: UniPageRoute[]
function utsMapOf(obj: Record<string, any>): Map<string, any | null>
function utsMapOf<K, V>(obj: Array<Array<any>>): Map<string, any | null>
function utsMapOf(obj?: Record<string, any>): Map<string, any | null>
function utsMapOf<K, V>(obj?: Array<Array<any>>): Map<string, any | null>
function padStyleMapOf(style: Map<string, any>): Map<string, Map<string, any>>
type UniPageMeta = {
......
......@@ -173,7 +173,7 @@ export function generatedPositionFor({
* @param generatedPosition
* @returns
*/
export function originalPositionFor(
export async function originalPositionFor(
generatedPosition: Omit<PositionFor, 'filename'> & { inputDir?: string }
): Promise<NullableMappedPosition & { sourceContent?: string }> {
return resolveSourceMapConsumer(generatedPosition.sourceMapFile).then(
......
......@@ -9,7 +9,8 @@ import {
SourceMapConsumer,
SourceMapGenerator,
} from 'source-map-js'
import { isInHBuilderX, normalizePath } from '../../shared'
import { normalizePath } from '../../shared'
import { originalPositionForSync } from '../../sourceMap'
export interface UTS2KotlinOptions {
typescript?: typeof import('typescript')
......@@ -33,7 +34,7 @@ export function runUTS2Kotlin(
): {
watcher?: WatchProgramHelper
} {
const pluginPath = isInHBuilderX()
const pluginPath = process.env.UNI_HBUILDERX_PLUGINS
? process.env.UNI_HBUILDERX_PLUGINS
: path.resolve(process.cwd(), '../')
......@@ -43,6 +44,10 @@ export function runUTS2Kotlin(
)
const kotlinTypesPath = path.resolve(__dirname, '../../../lib/kotlin/types')
const rootFiles: string[] = [
path.resolve(
hbxLanguageServicePath,
'uniappx/node_modules/@dcloudio/uni-app-x/types/shim-uts-basic.d.ts'
),
path.resolve(kotlinTypesPath, 'global.d.ts'),
path.resolve(hbxLanguageServicePath, 'uts-types/common/index.d.ts'),
//path.resolve(hbxLanguageServicePath, 'uts-types/app-android/index.d.ts'),
......@@ -98,6 +103,7 @@ export function runUTS2Kotlin(
type RunDevOptions = Required<
UTS2KotlinOptions & {
originalPositionForSync?: typeof originalPositionForSync
sourceMapCallback?: (
id: string,
map: string,
......@@ -117,6 +123,7 @@ export function runUTS2Kotlin(
rootFiles,
hxLanguageServiceDir: hbxLanguageServicePath,
compilerOptions,
originalPositionForSync,
normalizeFileName: options.normalizeFileName,
sourceMapCallback: (fileName, text, writeFile) => {
const relativeFileName = normalizePath(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册