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

wip(uts): compiler

上级 7b218e79
......@@ -31,7 +31,7 @@ export default {
'uts.android.compiler.server':
'项目使用了uts插件,正在安装 uts Android 运行扩展...',
'uts.ios.windows.tips':
'iOS手机在windows上真机运行时uts插件代码修改需提交云端打包自定义基座才能生效',
'iOS手机在windows上使用标准基座真机运行无法使用uts插件,如需使用uts插件请提交云端打包自定义基座',
'uts.ios.standard.tips':
'iOS手机在标准基座真机运行暂不支持uts插件,如需调用uts插件请使用自定义基座',
} as const
......@@ -67,7 +67,7 @@ function useI18n() {
let locale;
{
{
locale = window.localStorage && localStorage[UNI_STORAGE_LOCALE] || __uniConfig.locale || navigator.language;
locale = navigator.cookieEnabled && window.localStorage && localStorage[UNI_STORAGE_LOCALE] || __uniConfig.locale || navigator.language;
}
}
i18n = initVueI18n(locale);
......@@ -5086,7 +5086,7 @@ const setLocale = /* @__PURE__ */ defineSyncApi(
if (oldLocale !== locale) {
app.$vm.$locale = locale;
{
window.localStorage && (localStorage[UNI_STORAGE_LOCALE] = locale);
navigator.cookieEnabled && window.localStorage && (localStorage[UNI_STORAGE_LOCALE] = locale);
}
UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale });
return true;
......@@ -15622,7 +15622,7 @@ function setupApp(comp) {
const route = usePageRoute();
const onLaunch = () => {
injectAppHooks(instance2);
const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2 } = instance2;
const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2, onError: onError2 } = instance2;
const path = route.path.slice(1);
const launchOptions2 = initLaunchOptions({
path: path || __uniRoutes[0].meta.route,
......@@ -15642,6 +15642,11 @@ function setupApp(comp) {
onPageNotFound2 && invokeArrayFns$1(onPageNotFound2, pageNotFoundOptions);
}
}
if (onError2) {
instance2.appContext.config.errorHandler = (err) => {
invokeArrayFns$1(onError2, err);
};
}
};
if (__UNI_FEATURE_PAGES__) {
useRouter().isReady().then(onLaunch);
......@@ -17915,7 +17920,7 @@ const makePhoneCall = /* @__PURE__ */ defineAsyncApi(
MakePhoneCallProtocol
);
const UUID_KEY = "__DC_STAT_UUID";
const storage = window.localStorage || window.sessionStorage || {};
const storage = navigator.cookieEnabled && (window.localStorage || window.sessionStorage) || {};
let deviceId;
function deviceId$1() {
deviceId = deviceId || storage[UUID_KEY];
......
......@@ -16,13 +16,13 @@ var uniad_app_json = function (appJson) {
}
if (!appJson.plugins['uni-ad']) {
appJson.plugins['uni-ad'] = {
version: '1.0.1',
version: '1.1.1',
provider: 'wxf72d316417b6767f',
};
}
if (!appJson.plugins['coral-adv']) {
appJson.plugins['coral-adv'] = {
version: '1.0.9',
version: '1.0.15',
provider: 'wx0e203209e27b1e66',
};
}
......
import fs from 'fs'
import path from 'path'
import { camelize, capitalize, isArray } from '@vue/shared'
import { camelize, capitalize, hasOwn, isArray } from '@vue/shared'
import type {
ArrowFunctionExpression,
......@@ -16,6 +16,7 @@ import type {
Param,
Span,
TsFnParameter,
TsType,
TsTypeAnnotation,
VariableDeclaration,
VariableDeclarationKind,
......@@ -470,17 +471,19 @@ function parseAst(
switch (decl.type) {
case 'FunctionDeclaration':
decls.push(
genFunctionDeclaration(decl, resolveTypeReferenceName, false)
genFunctionDeclaration(types, decl, resolveTypeReferenceName, false)
)
break
case 'ClassDeclaration':
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, false))
decls.push(
genClassDeclaration(types, decl, resolveTypeReferenceName, false)
)
break
case 'VariableDeclaration':
const varDecl = genVariableDeclaration(
types,
decl,
resolveTypeReferenceName,
types
resolveTypeReferenceName
)
if (varDecl) {
decls.push(varDecl)
......@@ -492,12 +495,14 @@ function parseAst(
if (decl.type === 'ClassExpression') {
if (decl.identifier) {
// export default class test{}
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, true))
decls.push(
genClassDeclaration(types, decl, resolveTypeReferenceName, true)
)
}
} else if (decl.type === 'FunctionExpression') {
if (decl.identifier) {
decls.push(
genFunctionDeclaration(decl, resolveTypeReferenceName, true)
genFunctionDeclaration(types, decl, resolveTypeReferenceName, true)
)
}
}
......@@ -571,47 +576,57 @@ function resolveIdentifierDefaultValue(ident: Expression) {
return null
}
function resolveType(
types: Types,
typeAnnotation: TsType,
resolveTypeReferenceName: ResolveTypeReferenceName
): string {
if (typeAnnotation.type === 'TsKeywordType') {
return typeAnnotation.kind
} else if (typeAnnotation.type === 'TsFunctionType') {
return 'UTSCallback'
} else if (
typeAnnotation.type === 'TsTypeReference' &&
typeAnnotation.typeName.type === 'Identifier'
) {
if (hasOwn(types.fn, typeAnnotation.typeName.value)) {
return 'UTSCallback'
}
return resolveTypeReferenceName(typeAnnotation.typeName.value)
} else if (typeAnnotation.type === 'TsParenthesizedType') {
return resolveType(
types,
typeAnnotation.typeAnnotation,
resolveTypeReferenceName
)
} else if (typeAnnotation.type === 'TsUnionType') {
for (const type of typeAnnotation.types) {
if (type.type === 'TsKeywordType') {
continue
}
return resolveType(types, type, resolveTypeReferenceName)
}
}
return ''
}
function resolveIdentifierType(
types: Types,
ident: BindingIdentifier,
resolveTypeReferenceName: ResolveTypeReferenceName
) {
if (ident.typeAnnotation) {
const { typeAnnotation } = ident.typeAnnotation
if (typeAnnotation.type === 'TsKeywordType') {
return typeAnnotation.kind
} else if (typeAnnotation.type === 'TsFunctionType') {
return 'UTSCallback'
} else if (
typeAnnotation.type === 'TsTypeReference' &&
typeAnnotation.typeName.type === 'Identifier'
) {
return resolveTypeReferenceName(typeAnnotation.typeName.value)
} else if (typeAnnotation.type === 'TsUnionType') {
if (typeAnnotation.types.length === 2) {
const [type1, type2] = typeAnnotation.types
if (type1.type === 'TsKeywordType' && type1.kind === 'null') {
if (
type2.type === 'TsParenthesizedType' &&
type2.typeAnnotation.type === 'TsFunctionType'
) {
return 'UTSCallback'
}
}
if (type2.type === 'TsKeywordType' && type2.kind === 'null') {
if (
type1.type === 'TsParenthesizedType' &&
type1.typeAnnotation.type === 'TsFunctionType'
) {
return 'UTSCallback'
}
}
}
}
return resolveType(
types,
ident.typeAnnotation.typeAnnotation,
resolveTypeReferenceName
)
}
return ''
}
function resolveFunctionParams(
types: Types,
params: Param[],
resolveTypeReferenceName: ResolveTypeReferenceName
) {
......@@ -621,6 +636,7 @@ function resolveFunctionParams(
result.push({
name: pat.value,
type: resolveIdentifierType(
types,
pat as BindingIdentifier,
resolveTypeReferenceName
),
......@@ -630,6 +646,7 @@ function resolveFunctionParams(
const param: Parameter = {
name: pat.left.value,
type: resolveIdentifierType(
types,
pat.left as BindingIdentifier,
resolveTypeReferenceName
),
......@@ -648,6 +665,7 @@ function resolveFunctionParams(
}
function genFunctionDeclaration(
types: Types,
decl: FunctionDeclaration | FunctionExpression,
resolveTypeReferenceName: ResolveTypeReferenceName,
isDefault: boolean = false,
......@@ -656,13 +674,14 @@ function genFunctionDeclaration(
return genProxyFunction(
decl.identifier!.value,
decl.async || isReturnPromise(decl.returnType),
resolveFunctionParams(decl.params, resolveTypeReferenceName),
resolveFunctionParams(types, decl.params, resolveTypeReferenceName),
isDefault,
isVar
)
}
function genClassDeclaration(
types: Types,
decl: ClassDeclaration | ClassExpression,
resolveTypeReferenceName: ResolveTypeReferenceName,
isDefault: boolean = false
......@@ -679,6 +698,7 @@ function genClassDeclaration(
decl.body.forEach((item) => {
if (item.type === 'Constructor') {
constructor.params = resolveFunctionParams(
types,
item.params as Param[],
resolveTypeReferenceName
)
......@@ -689,6 +709,7 @@ function genClassDeclaration(
async:
item.function.async || isReturnPromise(item.function.returnType),
params: resolveFunctionParams(
types,
item.function.params,
resolveTypeReferenceName
),
......@@ -729,9 +750,9 @@ function genInitCode(expr: Expression) {
}
function genVariableDeclaration(
types: Types,
decl: VariableDeclaration,
resolveTypeReferenceName: ResolveTypeReferenceName,
types: Types
resolveTypeReferenceName: ResolveTypeReferenceName
): VariableDeclaration | ProxyFunctionDeclaration | undefined {
// 目前仅支持 const 的 boolean,number,string
const lits = ['BooleanLiteral', 'NumericLiteral', 'StringLiteral']
......@@ -775,6 +796,7 @@ function genVariableDeclaration(
}
}
return genFunctionDeclaration(
types,
createFunctionDeclaration(id.value, init, params),
resolveTypeReferenceName,
false,
......
......@@ -212,7 +212,7 @@ export async function compile(
// iOS windows 平台,标准基座不编译
if (utsPlatform === 'app-ios') {
if (isWindows) {
process.env.UNI_UTS_TIPS = `iOS手机在windows上真机运行时uts插件代码修改需提交云端打包自定义基座才能生效`
process.env.UNI_UTS_ERRORS = `iOS手机在windows上使用标准基座真机运行无法使用uts插件,如需使用uts插件请提交云端打包自定义基座`
return createResult(outputPluginDir, errMsg, code, deps, meta)
}
// ios 模拟器不支持
......
......@@ -54,6 +54,9 @@ export async function runDev(options: CliOptions & ServerOptions) {
isFirstEnd = false
output('log', M['dev.watching.end'])
printStartupDuration(createLogger(options.logLevel), false)
if (process.env.UNI_UTS_ERRORS) {
console.error(process.env.UNI_UTS_ERRORS)
}
if (process.env.UNI_UTS_TIPS) {
console.warn(process.env.UNI_UTS_TIPS)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册