diff --git a/packages/uni-cli-shared/src/mp/event.ts b/packages/uni-cli-shared/src/mp/event.ts
index dcf17249254b8256451cd72029c8d30f53d29bdf..22fa8cc23067896d3db74c309802e22f0d113757 100644
--- a/packages/uni-cli-shared/src/mp/event.ts
+++ b/packages/uni-cli-shared/src/mp/event.ts
@@ -25,6 +25,9 @@ export function formatMiniProgramEvent(
}
function isSimpleExpr(name: string) {
+ if (name.startsWith('_')) {
+ return false
+ }
if (name.indexOf('-') > -1) {
return false
}
diff --git a/packages/uni-cli-shared/src/mp/template.ts b/packages/uni-cli-shared/src/mp/template.ts
index 6611fd74e88661861ab5ebc32f82a55c9322848c..1e125fe890cdccec8a0a879c5ecdf5cae5c60178 100644
--- a/packages/uni-cli-shared/src/mp/template.ts
+++ b/packages/uni-cli-shared/src/mp/template.ts
@@ -1,5 +1,26 @@
-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),
+ })
+ }
+}
diff --git a/packages/uni-cli-shared/src/vite/index.ts b/packages/uni-cli-shared/src/vite/index.ts
index 4a0a0b8e9f830631d629df02963b99b1ab0525b3..ef8f157366ee5d7fddf9e19b2dc5933dff90ef90 100644
--- a/packages/uni-cli-shared/src/vite/index.ts
+++ b/packages/uni-cli-shared/src/vite/index.ts
@@ -1,5 +1,5 @@
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']
diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts
new file mode 100644
index 0000000000000000000000000000000000000000..54190261d63e017d60ec49d238b1e9f531b8a698
--- /dev/null
+++ b/packages/uni-mp-compiler/__tests__/component.spec.ts
@@ -0,0 +1,17 @@
+import { addComponentBindLink } from '@dcloudio/uni-cli-shared'
+import { assert } from './testUtils'
+
+describe('compiler: transform component', () => {
+ test('basic', () => {
+ assert(
+ ``,
+ ``,
+ `(_ctx, _cache) => {
+ return {}
+}`,
+ {
+ nodeTransforms: [addComponentBindLink as any],
+ }
+ )
+ })
+})
diff --git a/packages/uni-mp-compiler/src/compile.ts b/packages/uni-mp-compiler/src/compile.ts
index 319735f7dd55ac5f6db7ba0490e5ca8df1ed09e8..46a68b7f83b5bd4ce67cba55f71269f48fec245b 100644
--- a/packages/uni-mp-compiler/src/compile.ts
+++ b/packages/uni-mp-compiler/src/compile.ts
@@ -1,7 +1,7 @@
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)) {
diff --git a/packages/uni-mp-compiler/src/options.ts b/packages/uni-mp-compiler/src/options.ts
index 8b9e4c514b094f9b1e2de11607e2dbd343fef8ac..02894e15aff5830383ea47055eea3fb4d70989b6 100644
--- a/packages/uni-mp-compiler/src/options.ts
+++ b/packages/uni-mp-compiler/src/options.ts
@@ -1,5 +1,6 @@
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 {
scopeId?: string | null
filename: string
- directive: string
- emitFile: (emittedFile: EmittedFile) => string
}
export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions
diff --git a/packages/uni-mp-compiler/src/template/codegen.ts b/packages/uni-mp-compiler/src/template/codegen.ts
index 874f31f4376c1c2b8d18a93f9f2ed9e35633bab9..04825f16cf53ae4ea334ae5ebdcf3d55e986fddb 100644
--- a/packages/uni-mp-compiler/src/template/codegen.ts
+++ b/packages/uni-mp-compiler/src/template/codegen.ts
@@ -1,6 +1,7 @@
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) {
// =>
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()
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(
diff --git a/packages/uni-mp-compiler/src/transform.ts b/packages/uni-mp-compiler/src/transform.ts
index 2c19ddbfe71da68efb402b5e20373d65a88bc9f4..c8e8a7dc4cb9ef7d55215d010709c43c03ca7f50 100644
--- a/packages/uni-mp-compiler/src/transform.ts
+++ b/packages/uni-mp-compiler/src/transform.ts
@@ -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]
diff --git a/packages/uni-mp-compiler/src/transforms/transformElement.ts b/packages/uni-mp-compiler/src/transforms/transformElement.ts
index be88d0c98e1d7334434a8e7c38d88e621c30b705..00240e3b1699352e960e917a2d9b0c0bcb1ad3bd 100644
--- a/packages/uni-mp-compiler/src/transforms/transformElement.ts
+++ b/packages/uni-mp-compiler/src/transforms/transformElement.ts
@@ -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'
-}
diff --git a/packages/uni-mp-compiler/src/transforms/transformExpression.ts b/packages/uni-mp-compiler/src/transforms/transformExpression.ts
index 28c242762856152533a31f4da4f1916dca577a39..25f5e7c4fae826c69298fdcc1bc5bac746b12c60 100644
--- a/packages/uni-mp-compiler/src/transforms/transformExpression.ts
+++ b/packages/uni-mp-compiler/src/transforms/transformExpression.ts
@@ -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)
+}
diff --git a/packages/uni-mp-compiler/src/transforms/vOn.ts b/packages/uni-mp-compiler/src/transforms/vOn.ts
index 5bebf084e115a827f37e6f160f0bac7eb81c5281..a01472c464283bac14b5cfb1c2299d2778c6b5e2 100644
--- a/packages/uni-mp-compiler/src/transforms/vOn.ts
+++ b/packages/uni-mp-compiler/src/transforms/vOn.ts
@@ -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,
diff --git a/packages/uni-mp-vite/src/plugin/index.ts b/packages/uni-mp-vite/src/plugin/index.ts
index e8ca676ac4fe91f4baf8f37cebc01db848684b3c..6a38a37b52f66d7da77e20e775fe50a9c4fb81f9 100644
--- a/packages/uni-mp-vite/src/plugin/index.ts
+++ b/packages/uni-mp-vite/src/plugin/index.ts
@@ -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[0]
}
+ compilerOptions?: CompilerOptions
}
style: {
extname: string
@@ -76,6 +78,7 @@ export function uniMiniProgramPlugin(
emitFile,
slot: template.slot,
},
+ compilerOptions: template.compilerOptions,
}),
config() {
return {
diff --git a/packages/uni-mp-vite/src/plugin/uni/index.ts b/packages/uni-mp-vite/src/plugin/uni/index.ts
index 1d8fa83976e5e3e95938f64416944ce74f88a750..5d0e9d7fdf69681e749d5b84b7923267a36e0c36 100644
--- a/packages/uni-mp-vite/src/plugin/uni/index.ts
+++ b/packages/uni-mp-vite/src/plugin/uni/index.ts
@@ -1,25 +1,22 @@
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,
},
}
}
diff --git a/packages/uni-mp-weixin/dist/uni.compiler.js b/packages/uni-mp-weixin/dist/uni.compiler.js
index dc87e273a18061e33cd26f145098412de6e8095a..66f285a557d0532d92c5f5106c50d7a6776efdf4 100644
--- a/packages/uni-mp-weixin/dist/uni.compiler.js
+++ b/packages/uni-mp-weixin/dist/uni.compiler.js
@@ -124,6 +124,9 @@ ${filter.code}
},
extname: '.wxml',
directive: 'wx:',
+ compilerOptions: {
+ nodeTransforms: [uniCliShared.addComponentBindLink],
+ },
},
style: {
extname: '.wxss',
diff --git a/packages/uni-mp-weixin/src/plugin/index.ts b/packages/uni-mp-weixin/src/plugin/index.ts
index 3ca93f2e56977fab31dcb3413e4f8eb21d5482f3..5a1af6710fb13ed904000ff0da7d22bfe97fdf2d 100644
--- a/packages/uni-mp-weixin/src/plugin/index.ts
+++ b/packages/uni-mp-weixin/src/plugin/index.ts
@@ -1,5 +1,5 @@
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',
diff --git a/packages/uni-shared/dist/uni-shared.cjs.js b/packages/uni-shared/dist/uni-shared.cjs.js
index f862e65807d69fb3e998eb3d0bc0a8669238aae5..c893711b8feb993455fa2744f0dd845df07d4d16 100644
--- a/packages/uni-shared/dist/uni-shared.cjs.js
+++ b/packages/uni-shared/dist/uni-shared.cjs.js
@@ -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;
diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts
index 6fb30a9a970b3d406f0793c909b064919a450413..df8f83c7280ace3953bea448e30d3bf9b470da59 100644
--- a/packages/uni-shared/dist/uni-shared.d.ts
+++ b/packages/uni-shared/dist/uni-shared.d.ts
@@ -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;
diff --git a/packages/uni-shared/dist/uni-shared.es.js b/packages/uni-shared/dist/uni-shared.es.js
index 2e07b0deac12088553075e93eeebc17d43353bc7..4f9b9d60df1829db2b8706bfc9942c0a977d17f4 100644
--- a/packages/uni-shared/dist/uni-shared.es.js
+++ b/packages/uni-shared/dist/uni-shared.es.js
@@ -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 };
diff --git a/packages/uni-shared/src/tags.ts b/packages/uni-shared/src/tags.ts
index b85cd1a5f15074c186bf1486d90162e2c76cf312..8b324dfd8963b939d81dce29b1d542194dcff80d 100644
--- a/packages/uni-shared/src/tags.ts
+++ b/packages/uni-shared/src/tags.ts
@@ -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
diff --git a/packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap b/packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
index c52e00cfe02d23c502626cc162cbbbd8bf38b6f7..97c744371aaf8c24375b37d432ca3bc6dca636e0 100644
--- a/packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
+++ b/packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
@@ -1,23 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`block normalizeBlockCode 1`] = `
-"
-
-
- "
-`;
-
-exports[`block normalizeBlockCode 2`] = `
-"ab
-
-
- "
-`;
-
exports[`block parseBlockCode 1`] = `
"
-
- export default{
- mounted(){
- console.log('mounted')
- }
- }
-
-
- "
-`;
-
-exports[`wxs normalizeWxsCode 2`] = `
-"
-
-
- export default{
- mounted(){
- console.log('mounted')
- }
- }
-
-
- "
-`;
-
exports[`wxs parseWxsCode 1`] = `
"