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

wip(mp): add bind:__l="__l"

上级 d6fadc26
......@@ -25,6 +25,9 @@ export function formatMiniProgramEvent(
}
function isSimpleExpr(name: string) {
if (name.startsWith('_')) {
return false
}
if (name.indexOf('-') > -1) {
return false
}
......
import { LINEFEED } from '@dcloudio/uni-shared'
import { EmittedAsset } from 'rollup'
import { isComponentTag, LINEFEED } from '@dcloudio/uni-shared'
import {
createSimpleExpression,
ElementTypes,
isCoreComponent,
locStub,
NodeTypes,
RootNode,
TemplateChildNode,
TransformContext,
} from '@vue/compiler-core'
export interface MiniProgramCompilerOptions {
slot: {
fallback: boolean
}
filter?: {
lang: string
}
directive: string
emitFile?: (emittedFile: EmittedAsset) => string
}
export interface MiniProgramFilterOptions {
id: string
type: 'wxs'
......@@ -65,3 +86,30 @@ export function addMiniProgramTemplateFilter(
templateFiltersCache.set(filename, [filter])
}
}
export function addComponentBindLink(
node: RootNode | TemplateChildNode,
context: TransformContext
) {
if (
node.type === NodeTypes.ELEMENT &&
node.tagType === ElementTypes.COMPONENT
) {
const { tag } = node
if (
isComponentTag(tag) ||
isCoreComponent(tag) ||
context.isBuiltInComponent(tag)
) {
return
}
node.props.push({
type: NodeTypes.DIRECTIVE,
name: 'on',
modifiers: [],
loc: locStub,
arg: createSimpleExpression('__l', true),
exp: createSimpleExpression('__l', true),
})
}
}
import type { Plugin } from 'vite'
import type { EmittedFile } from 'rollup'
import type { EmittedAsset } from 'rollup'
import type { ParserOptions } from '@vue/compiler-core'
import type { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc'
import { UniViteCopyPluginOptions } from './plugins/copy'
......@@ -16,7 +16,7 @@ interface UniVitePluginUniOptions {
compiler?: TemplateCompiler
compilerOptions?: {
miniProgram?: {
emitFile?: (emittedFile: EmittedFile) => string
emitFile?: (emittedFile: EmittedAsset) => string
}
isNativeTag: ParserOptions['isNativeTag']
isCustomElement: ParserOptions['isCustomElement']
......
import { addComponentBindLink } from '@dcloudio/uni-cli-shared'
import { assert } from './testUtils'
describe('compiler: transform component', () => {
test('basic', () => {
assert(
`<custom/>`,
`<custom class="vue-ref" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return {}
}`,
{
nodeTransforms: [addComponentBindLink as any],
}
)
})
})
import fs from 'fs'
import { baseParse } from '@vue/compiler-core'
import { isString, extend } from '@vue/shared'
import { parseFilterNames } from '@dcloudio/uni-cli-shared'
import { hash, parseFilterNames } from '@dcloudio/uni-cli-shared'
import { generate } from './codegen'
import { CompilerOptions } from './options'
import { DirectiveTransform, NodeTransform, transform } from './transform'
......@@ -45,12 +45,18 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
prefixIdentifiers,
skipTransformIdentifier: options.skipTransformIdentifier === true,
})
if (options.filename && !options.filters && options.miniProgram?.filter) {
options.filters = parseFilters(
options.miniProgram.filter.lang,
options.filename
)
options.vueId = genVueId(options)
if (options.filename) {
if (options.filters && options.miniProgram?.filter) {
options.filters = parseFilters(
options.miniProgram.filter.lang,
options.filename
)
}
}
const context = transform(
ast,
extend({}, options, {
......@@ -86,6 +92,19 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
return result
}
function genVueId(options: CompilerOptions) {
if (options.vueId) {
return options.vueId
}
if (options.scopeId) {
return options.scopeId.replace('data-v-', '')
}
if (options.filename) {
return hash(options.filename)
}
return ''
}
function parseFilters(lang: string, filename: string) {
filename = filename.split('?')[0]
if (fs.existsSync(filename)) {
......
import { ParserPlugin } from '@babel/parser'
import { Expression, ObjectProperty, SpreadElement } from '@babel/types'
import { MiniProgramCompilerOptions } from '@dcloudio/uni-cli-shared'
import { BindingMetadata, CompilerError, RootNode } from '@vue/compiler-core'
import IdentifierGenerator from './identifier'
import {
......@@ -45,6 +46,7 @@ interface SharedTransformCodegenOptions {
export interface TransformOptions
extends SharedTransformCodegenOptions,
ErrorHandlingOptions {
vueId?: string | null
scopeId?: string | null
filters?: string[]
cacheHandlers?: boolean
......@@ -76,38 +78,18 @@ export interface CodegenVForScope
export type CodegenScope = CodegenRootScope | CodegenVIfScope | CodegenVForScope
interface EmittedFile {
fileName?: string
name?: string
source?: string | Uint8Array
type: 'asset'
}
export interface CodegenOptions extends SharedTransformCodegenOptions {
mode?: 'module' | 'function'
scopeId?: string | null
runtimeModuleName?: string
runtimeGlobalName?: string
miniProgram?: {
slot: {
fallback: boolean
}
filter?: {
lang: string
}
directive: string
emitFile?: (emittedFile: EmittedFile) => string
}
miniProgram?: MiniProgramCompilerOptions
}
export interface TemplateCodegenOptions {
slot: {
fallback: boolean
}
export interface TemplateCodegenOptions
extends Omit<MiniProgramCompilerOptions, 'filter'> {
scopeId?: string | null
filename: string
directive: string
emitFile: (emittedFile: EmittedFile) => string
}
export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions
import { hyphenate } from '@vue/shared'
import { formatMiniProgramEvent } from '@dcloudio/uni-cli-shared'
import {
ComponentNode,
DirectiveNode,
ElementNode,
ElementTypes,
......@@ -9,7 +10,9 @@ import {
NodeTypes,
RootNode,
SimpleExpressionNode,
SlotOutletNode,
TemplateChildNode,
TemplateNode,
TextNode,
} from '@vue/compiler-core'
import { TemplateCodegenOptions } from '../options'
......@@ -43,7 +46,7 @@ export function generate(
children.forEach((node) => {
genNode(node, context)
})
emitFile({ type: 'asset', fileName: filename, source: context.code })
emitFile!({ type: 'asset', fileName: filename, source: context.code })
}
export function genNode(
......@@ -69,7 +72,6 @@ export function genNode(
} else if (isLazyElement(node)) {
return genLazyElement(node, context)
}
return genElement(node, context)
}
}
......@@ -109,7 +111,7 @@ function genVFor(
}
}
function genSlot(node: ElementNode, context: TemplateCodegenContext) {
function genSlot(node: SlotOutletNode, context: TemplateCodegenContext) {
if (!node.children.length) {
return genElement(node, context)
}
......@@ -152,7 +154,7 @@ function findSlotName(node: ElementNode) {
}
}
function genTemplate(node: ElementNode, context: TemplateCodegenContext) {
function genTemplate(node: TemplateNode, context: TemplateCodegenContext) {
const slotName = findSlotName(node)
if (slotName) {
/**
......@@ -165,11 +167,12 @@ function genTemplate(node: ElementNode, context: TemplateCodegenContext) {
// <template/> => <block/>
node.tag = 'block'
}
// @ts-ignore
node.tagType = ElementTypes.ELEMENT
return genElement(node, context)
}
function genComponent(node: ElementNode, context: TemplateCodegenContext) {
function genComponent(node: ComponentNode, context: TemplateCodegenContext) {
const slots = new Set<string>()
if (!node.children.length) {
return genElement(node, context)
......@@ -288,15 +291,18 @@ function genOn(
{ push }: TemplateCodegenContext
) {
const arg = (prop.arg as SimpleExpressionNode).content
const exp = (prop.exp as SimpleExpressionNode).content
const exp = prop.exp as SimpleExpressionNode
const modifiers = prop.modifiers
push(
`${formatMiniProgramEvent(arg, {
isCatch: modifiers.includes('stop') || modifiers.includes('prevent'),
isCapture: modifiers.includes('capture'),
isComponent: node.tagType === ElementTypes.COMPONENT,
})}="{{${exp}}}"`
)
const name = formatMiniProgramEvent(arg, {
isCatch: modifiers.includes('stop') || modifiers.includes('prevent'),
isCapture: modifiers.includes('capture'),
isComponent: node.tagType === ElementTypes.COMPONENT,
})
if (exp.isStatic) {
push(`${name}="${exp.content}"`)
} else {
push(`${name}="{{${exp.content}}}"`)
}
}
function genDirectiveNode(
......
......@@ -86,6 +86,7 @@ export interface TransformContext
cached: number
scopes: {
vFor: number
vueId: number
}
scope: CodegenRootScope
currentScope: CodegenScope
......@@ -213,6 +214,7 @@ export function createTransformContext(
filename = '',
isTS = false,
inline = false,
vueId = null,
scopeId = null,
filters = [],
bindingMetadata = EMPTY_OBJ,
......@@ -270,6 +272,7 @@ export function createTransformContext(
selfName: nameMatch && capitalize(camelize(nameMatch[1])),
isTS,
inline,
vueId,
scopeId,
filters,
bindingMetadata,
......@@ -295,6 +298,7 @@ export function createTransformContext(
scope: rootScope,
scopes: {
vFor: 0,
vueId: 0,
},
get currentScope() {
return scopes[scopes.length - 1]
......
......@@ -17,7 +17,10 @@ import {
locStub,
AttributeNode,
DirectiveNode,
ComponentNode,
} from '@vue/compiler-core'
import { isComponentTag } from '@dcloudio/uni-shared'
import { createMPCompilerError, MPErrorCodes } from '../errors'
import {
......@@ -46,8 +49,7 @@ export const transformElement: NodeTransform = (node, context) => {
) {
return
}
const isComponent = node.tagType === ElementTypes.COMPONENT
if (isComponent) {
if (node.tagType === ElementTypes.COMPONENT) {
processComponent(node, context)
}
if (context.scopeId) {
......@@ -87,14 +89,22 @@ function addScopeId(node: ElementNode, scopeId: string) {
return addStaticClass(node, scopeId)
}
function addVueRef(node: ElementNode, context: TransformContext) {
function addVueId(node: ComponentNode, context: TransformContext) {
let { vueId, scopes } = context
if (!vueId) {
return
}
return vueId + '-' + scopes.vueId++
}
function addVueRef(node: ComponentNode, context: TransformContext) {
return addStaticClass(
node,
context.scopes.vFor ? 'vue-ref-in-for' : 'vue-ref'
)
}
function processComponent(node: ElementNode, context: TransformContext) {
function processComponent(node: ComponentNode, context: TransformContext) {
const { tag } = node
if (context.bindingComponents[tag]) {
return addVueRef(node, context)
......@@ -126,6 +136,7 @@ function processComponent(node: ElementNode, context: TransformContext) {
)
}
addVueId(node, context)
addVueRef(node, context)
// 3. user component (from setup bindings)
......@@ -301,7 +312,3 @@ function processVModel(node: ElementNode, context: TransformContext) {
}
props.push(...dirs)
}
function isComponentTag(tag: string) {
return tag[0].toLowerCase() + tag.slice(1) === 'component'
}
......@@ -186,12 +186,14 @@ export function processExpression(
const isAllowedGlobal = isGloballyWhitelisted(rawExp)
const isLiteral = isLiteralWhitelisted(rawExp)
const isFilter = context.filters.includes(rawExp)
const isBuiltIn = isBuiltInIdentifier(rawExp)
if (
!asParams &&
!isScopeVarReference &&
!isAllowedGlobal &&
!isLiteral &&
!isFilter
!isFilter &&
!isBuiltIn
) {
// const bindings exposed from setup can be skipped for patching but
// cannot be hoisted to module scope
......@@ -343,3 +345,14 @@ function stringifyExpression(exp: ExpressionNode | string): string {
.join('')
}
}
const builtInIdentifiers = ['__l']
export function isBuiltInIdentifier(id: string | ExpressionNode) {
if (!isString(id)) {
if (id.type !== NodeTypes.SIMPLE_EXPRESSION) {
return false
}
id = id.content
}
return builtInIdentifiers.includes(id)
}
......@@ -17,7 +17,7 @@ import { camelize, toHandlerKey } from '@vue/shared'
import { V_ON } from '../runtimeHelpers'
import { DirectiveTransform, TransformContext } from '../transform'
import { DirectiveTransformResult } from './transformElement'
import { processExpression } from './transformExpression'
import { isBuiltInIdentifier, processExpression } from './transformExpression'
const fnExpRE =
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
......@@ -191,10 +191,14 @@ function isFilterExpr(value: ExpressionNode, context: TransformContext) {
}
export function wrapperVOn(value: ExpressionNode, context: TransformContext) {
if (isBuiltInIdentifier(value)) {
return value
}
// wxs event
if (isFilterExpr(value, context)) {
return value
}
return createCompoundExpression([
`${context.helperString(V_ON)}(`,
value,
......
......@@ -12,6 +12,7 @@ import { uniOptions } from './uni'
import { buildOptions } from './build'
import { createConfigResolved } from './configResolved'
import { emitFile, getFilterFiles, getTemplateFiles } from './template'
import { CompilerOptions } from '@vue/compiler-core'
export interface UniMiniProgramPluginOptions {
vite: {
......@@ -42,6 +43,7 @@ export interface UniMiniProgramPluginOptions {
extname: string
generate: Parameters<typeof findMiniProgramTemplateFiles>[0]
}
compilerOptions?: CompilerOptions
}
style: {
extname: string
......@@ -76,6 +78,7 @@ export function uniMiniProgramPlugin(
emitFile,
slot: template.slot,
},
compilerOptions: template.compilerOptions,
}),
config() {
return {
......
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import { EmittedFile } from 'rollup'
import { CopyOptions, UniVitePlugin } from '@dcloudio/uni-cli-shared'
import { TemplateCompiler } from '@vue/compiler-sfc'
import {
CopyOptions,
UniVitePlugin,
MiniProgramCompilerOptions,
} from '@dcloudio/uni-cli-shared'
import { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc'
import * as compiler from '@dcloudio/uni-mp-compiler'
export function uniOptions({
copyOptions,
miniProgram,
compilerOptions,
}: {
copyOptions: CopyOptions
miniProgram: {
slot: {
fallback: boolean
}
filter?: {
lang: string
}
directive: string
emitFile?: (emittedFile: EmittedFile) => string
}
miniProgram: MiniProgramCompilerOptions
compilerOptions?: CompilerOptions
}): UniVitePlugin['uni'] {
return {
copyOptions,
......@@ -28,6 +25,7 @@ export function uniOptions({
miniProgram,
isNativeTag,
isCustomElement,
...compilerOptions,
},
}
}
......@@ -124,6 +124,9 @@ ${filter.code}
},
extname: '.wxml',
directive: 'wx:',
compilerOptions: {
nodeTransforms: [uniCliShared.addComponentBindLink],
},
},
style: {
extname: '.wxss',
......
import { Plugin } from 'vite'
import { resolveBuiltIn } from '@dcloudio/uni-cli-shared'
import { addComponentBindLink, resolveBuiltIn } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin, {
UniMiniProgramPluginOptions,
} from '@dcloudio/uni-mp-vite'
......@@ -78,6 +78,9 @@ ${filter.code}
},
extname: '.wxml',
directive: 'wx:',
compilerOptions: {
nodeTransforms: [addComponentBindLink],
},
},
style: {
extname: '.wxss',
......
......@@ -84,6 +84,9 @@ function isNativeTag(tag) {
function isCustomElement(_tag) {
return false;
}
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
}
const COMPONENT_SELECTOR_PREFIX = 'uni-';
const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX;
......@@ -1232,6 +1235,7 @@ exports.getValueByDataPath = getValueByDataPath;
exports.initCustomDataset = initCustomDataset;
exports.invokeArrayFns = invokeArrayFns;
exports.isBuiltInComponent = isBuiltInComponent;
exports.isComponentTag = isComponentTag;
exports.isCustomElement = isCustomElement;
exports.isH5CustomElement = isH5CustomElement;
exports.isH5NativeTag = isH5NativeTag;
......
......@@ -206,6 +206,8 @@ export declare const invokeArrayFns: (fns: Function[], arg?: any) => any;
export declare function isBuiltInComponent(tag: string): boolean;
export declare function isComponentTag(tag: string): boolean;
export declare function isCustomElement(_tag: string): boolean;
export declare function isH5CustomElement(tag: string): boolean;
......
......@@ -80,6 +80,9 @@ function isNativeTag(tag) {
function isCustomElement(_tag) {
return false;
}
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
}
const COMPONENT_SELECTOR_PREFIX = 'uni-';
const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX;
......@@ -1115,4 +1118,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, formatAppLog, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isCustomElement, isH5CustomElement, isH5NativeTag, isNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, formatAppLog, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isComponentTag, isCustomElement, isH5CustomElement, isH5NativeTag, isNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
......@@ -87,6 +87,10 @@ export function isCustomElement(_tag: string) {
return false
}
export function isComponentTag(tag: string) {
return tag[0].toLowerCase() + tag.slice(1) === 'component'
}
export const COMPONENT_SELECTOR_PREFIX = 'uni-'
export const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`block normalizeBlockCode 1`] = `
"<template><view><template></template></view></template>
<script>
export default {}
</script>
<style></style>
"
`;
exports[`block normalizeBlockCode 2`] = `
"<template><view><template v-if=\\"a\\">a</template><template v-else>b</template></view></template>
<script>
export default {}
</script>
<style></style>
"
`;
exports[`block parseBlockCode 1`] = `
"<template><view><template></template></view></template>
<script>
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`wxs normalizeWxsCode 1`] = `
"<template><view></view><view></view></template>
<script>
export default {}
</script>
<renderjs name=\\"echarts\\">
export default{
mounted(){
console.log('mounted')
}
}
</renderjs>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
"
`;
exports[`wxs normalizeWxsCode 2`] = `
"<template><view></view><view></view></template>
<script>
export default {}
</script>
<wxs name=\\"echarts\\">
export default{
mounted(){
console.log('mounted')
}
}
</wxs>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
"
`;
exports[`wxs parseWxsCode 1`] = `
"<template><view></view><view></view></template>
<script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册