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

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

上级 d6fadc26
...@@ -25,6 +25,9 @@ export function formatMiniProgramEvent( ...@@ -25,6 +25,9 @@ export function formatMiniProgramEvent(
} }
function isSimpleExpr(name: string) { function isSimpleExpr(name: string) {
if (name.startsWith('_')) {
return false
}
if (name.indexOf('-') > -1) { if (name.indexOf('-') > -1) {
return false 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 { export interface MiniProgramFilterOptions {
id: string id: string
type: 'wxs' type: 'wxs'
...@@ -65,3 +86,30 @@ export function addMiniProgramTemplateFilter( ...@@ -65,3 +86,30 @@ export function addMiniProgramTemplateFilter(
templateFiltersCache.set(filename, [filter]) 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 { Plugin } from 'vite'
import type { EmittedFile } from 'rollup' import type { EmittedAsset } from 'rollup'
import type { ParserOptions } from '@vue/compiler-core' import type { ParserOptions } from '@vue/compiler-core'
import type { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc' import type { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc'
import { UniViteCopyPluginOptions } from './plugins/copy' import { UniViteCopyPluginOptions } from './plugins/copy'
...@@ -16,7 +16,7 @@ interface UniVitePluginUniOptions { ...@@ -16,7 +16,7 @@ interface UniVitePluginUniOptions {
compiler?: TemplateCompiler compiler?: TemplateCompiler
compilerOptions?: { compilerOptions?: {
miniProgram?: { miniProgram?: {
emitFile?: (emittedFile: EmittedFile) => string emitFile?: (emittedFile: EmittedAsset) => string
} }
isNativeTag: ParserOptions['isNativeTag'] isNativeTag: ParserOptions['isNativeTag']
isCustomElement: ParserOptions['isCustomElement'] 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 fs from 'fs'
import { baseParse } from '@vue/compiler-core' import { baseParse } from '@vue/compiler-core'
import { isString, extend } from '@vue/shared' 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 { generate } from './codegen'
import { CompilerOptions } from './options' import { CompilerOptions } from './options'
import { DirectiveTransform, NodeTransform, transform } from './transform' import { DirectiveTransform, NodeTransform, transform } from './transform'
...@@ -45,12 +45,18 @@ export function baseCompile(template: string, options: CompilerOptions = {}) { ...@@ -45,12 +45,18 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
prefixIdentifiers, prefixIdentifiers,
skipTransformIdentifier: options.skipTransformIdentifier === true, skipTransformIdentifier: options.skipTransformIdentifier === true,
}) })
if (options.filename && !options.filters && options.miniProgram?.filter) {
options.vueId = genVueId(options)
if (options.filename) {
if (options.filters && options.miniProgram?.filter) {
options.filters = parseFilters( options.filters = parseFilters(
options.miniProgram.filter.lang, options.miniProgram.filter.lang,
options.filename options.filename
) )
} }
}
const context = transform( const context = transform(
ast, ast,
extend({}, options, { extend({}, options, {
...@@ -86,6 +92,19 @@ export function baseCompile(template: string, options: CompilerOptions = {}) { ...@@ -86,6 +92,19 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
return result 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) { function parseFilters(lang: string, filename: string) {
filename = filename.split('?')[0] filename = filename.split('?')[0]
if (fs.existsSync(filename)) { if (fs.existsSync(filename)) {
......
import { ParserPlugin } from '@babel/parser' import { ParserPlugin } from '@babel/parser'
import { Expression, ObjectProperty, SpreadElement } from '@babel/types' import { Expression, ObjectProperty, SpreadElement } from '@babel/types'
import { MiniProgramCompilerOptions } from '@dcloudio/uni-cli-shared'
import { BindingMetadata, CompilerError, RootNode } from '@vue/compiler-core' import { BindingMetadata, CompilerError, RootNode } from '@vue/compiler-core'
import IdentifierGenerator from './identifier' import IdentifierGenerator from './identifier'
import { import {
...@@ -45,6 +46,7 @@ interface SharedTransformCodegenOptions { ...@@ -45,6 +46,7 @@ interface SharedTransformCodegenOptions {
export interface TransformOptions export interface TransformOptions
extends SharedTransformCodegenOptions, extends SharedTransformCodegenOptions,
ErrorHandlingOptions { ErrorHandlingOptions {
vueId?: string | null
scopeId?: string | null scopeId?: string | null
filters?: string[] filters?: string[]
cacheHandlers?: boolean cacheHandlers?: boolean
...@@ -76,38 +78,18 @@ export interface CodegenVForScope ...@@ -76,38 +78,18 @@ export interface CodegenVForScope
export type CodegenScope = CodegenRootScope | CodegenVIfScope | CodegenVForScope export type CodegenScope = CodegenRootScope | CodegenVIfScope | CodegenVForScope
interface EmittedFile {
fileName?: string
name?: string
source?: string | Uint8Array
type: 'asset'
}
export interface CodegenOptions extends SharedTransformCodegenOptions { export interface CodegenOptions extends SharedTransformCodegenOptions {
mode?: 'module' | 'function' mode?: 'module' | 'function'
scopeId?: string | null scopeId?: string | null
runtimeModuleName?: string runtimeModuleName?: string
runtimeGlobalName?: string runtimeGlobalName?: string
miniProgram?: { miniProgram?: MiniProgramCompilerOptions
slot: {
fallback: boolean
}
filter?: {
lang: string
}
directive: string
emitFile?: (emittedFile: EmittedFile) => string
}
} }
export interface TemplateCodegenOptions { export interface TemplateCodegenOptions
slot: { extends Omit<MiniProgramCompilerOptions, 'filter'> {
fallback: boolean
}
scopeId?: string | null scopeId?: string | null
filename: string filename: string
directive: string
emitFile: (emittedFile: EmittedFile) => string
} }
export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions
import { hyphenate } from '@vue/shared' import { hyphenate } from '@vue/shared'
import { formatMiniProgramEvent } from '@dcloudio/uni-cli-shared' import { formatMiniProgramEvent } from '@dcloudio/uni-cli-shared'
import { import {
ComponentNode,
DirectiveNode, DirectiveNode,
ElementNode, ElementNode,
ElementTypes, ElementTypes,
...@@ -9,7 +10,9 @@ import { ...@@ -9,7 +10,9 @@ import {
NodeTypes, NodeTypes,
RootNode, RootNode,
SimpleExpressionNode, SimpleExpressionNode,
SlotOutletNode,
TemplateChildNode, TemplateChildNode,
TemplateNode,
TextNode, TextNode,
} from '@vue/compiler-core' } from '@vue/compiler-core'
import { TemplateCodegenOptions } from '../options' import { TemplateCodegenOptions } from '../options'
...@@ -43,7 +46,7 @@ export function generate( ...@@ -43,7 +46,7 @@ export function generate(
children.forEach((node) => { children.forEach((node) => {
genNode(node, context) genNode(node, context)
}) })
emitFile({ type: 'asset', fileName: filename, source: context.code }) emitFile!({ type: 'asset', fileName: filename, source: context.code })
} }
export function genNode( export function genNode(
...@@ -69,7 +72,6 @@ export function genNode( ...@@ -69,7 +72,6 @@ export function genNode(
} else if (isLazyElement(node)) { } else if (isLazyElement(node)) {
return genLazyElement(node, context) return genLazyElement(node, context)
} }
return genElement(node, context) return genElement(node, context)
} }
} }
...@@ -109,7 +111,7 @@ function genVFor( ...@@ -109,7 +111,7 @@ function genVFor(
} }
} }
function genSlot(node: ElementNode, context: TemplateCodegenContext) { function genSlot(node: SlotOutletNode, context: TemplateCodegenContext) {
if (!node.children.length) { if (!node.children.length) {
return genElement(node, context) return genElement(node, context)
} }
...@@ -152,7 +154,7 @@ function findSlotName(node: ElementNode) { ...@@ -152,7 +154,7 @@ function findSlotName(node: ElementNode) {
} }
} }
function genTemplate(node: ElementNode, context: TemplateCodegenContext) { function genTemplate(node: TemplateNode, context: TemplateCodegenContext) {
const slotName = findSlotName(node) const slotName = findSlotName(node)
if (slotName) { if (slotName) {
/** /**
...@@ -165,11 +167,12 @@ function genTemplate(node: ElementNode, context: TemplateCodegenContext) { ...@@ -165,11 +167,12 @@ function genTemplate(node: ElementNode, context: TemplateCodegenContext) {
// <template/> => <block/> // <template/> => <block/>
node.tag = 'block' node.tag = 'block'
} }
// @ts-ignore
node.tagType = ElementTypes.ELEMENT node.tagType = ElementTypes.ELEMENT
return genElement(node, context) return genElement(node, context)
} }
function genComponent(node: ElementNode, context: TemplateCodegenContext) { function genComponent(node: ComponentNode, context: TemplateCodegenContext) {
const slots = new Set<string>() const slots = new Set<string>()
if (!node.children.length) { if (!node.children.length) {
return genElement(node, context) return genElement(node, context)
...@@ -288,15 +291,18 @@ function genOn( ...@@ -288,15 +291,18 @@ function genOn(
{ push }: TemplateCodegenContext { push }: TemplateCodegenContext
) { ) {
const arg = (prop.arg as SimpleExpressionNode).content const arg = (prop.arg as SimpleExpressionNode).content
const exp = (prop.exp as SimpleExpressionNode).content const exp = prop.exp as SimpleExpressionNode
const modifiers = prop.modifiers const modifiers = prop.modifiers
push( const name = formatMiniProgramEvent(arg, {
`${formatMiniProgramEvent(arg, {
isCatch: modifiers.includes('stop') || modifiers.includes('prevent'), isCatch: modifiers.includes('stop') || modifiers.includes('prevent'),
isCapture: modifiers.includes('capture'), isCapture: modifiers.includes('capture'),
isComponent: node.tagType === ElementTypes.COMPONENT, isComponent: node.tagType === ElementTypes.COMPONENT,
})}="{{${exp}}}"` })
) if (exp.isStatic) {
push(`${name}="${exp.content}"`)
} else {
push(`${name}="{{${exp.content}}}"`)
}
} }
function genDirectiveNode( function genDirectiveNode(
......
...@@ -86,6 +86,7 @@ export interface TransformContext ...@@ -86,6 +86,7 @@ export interface TransformContext
cached: number cached: number
scopes: { scopes: {
vFor: number vFor: number
vueId: number
} }
scope: CodegenRootScope scope: CodegenRootScope
currentScope: CodegenScope currentScope: CodegenScope
...@@ -213,6 +214,7 @@ export function createTransformContext( ...@@ -213,6 +214,7 @@ export function createTransformContext(
filename = '', filename = '',
isTS = false, isTS = false,
inline = false, inline = false,
vueId = null,
scopeId = null, scopeId = null,
filters = [], filters = [],
bindingMetadata = EMPTY_OBJ, bindingMetadata = EMPTY_OBJ,
...@@ -270,6 +272,7 @@ export function createTransformContext( ...@@ -270,6 +272,7 @@ export function createTransformContext(
selfName: nameMatch && capitalize(camelize(nameMatch[1])), selfName: nameMatch && capitalize(camelize(nameMatch[1])),
isTS, isTS,
inline, inline,
vueId,
scopeId, scopeId,
filters, filters,
bindingMetadata, bindingMetadata,
...@@ -295,6 +298,7 @@ export function createTransformContext( ...@@ -295,6 +298,7 @@ export function createTransformContext(
scope: rootScope, scope: rootScope,
scopes: { scopes: {
vFor: 0, vFor: 0,
vueId: 0,
}, },
get currentScope() { get currentScope() {
return scopes[scopes.length - 1] return scopes[scopes.length - 1]
......
...@@ -17,7 +17,10 @@ import { ...@@ -17,7 +17,10 @@ import {
locStub, locStub,
AttributeNode, AttributeNode,
DirectiveNode, DirectiveNode,
ComponentNode,
} from '@vue/compiler-core' } from '@vue/compiler-core'
import { isComponentTag } from '@dcloudio/uni-shared'
import { createMPCompilerError, MPErrorCodes } from '../errors' import { createMPCompilerError, MPErrorCodes } from '../errors'
import { import {
...@@ -46,8 +49,7 @@ export const transformElement: NodeTransform = (node, context) => { ...@@ -46,8 +49,7 @@ export const transformElement: NodeTransform = (node, context) => {
) { ) {
return return
} }
const isComponent = node.tagType === ElementTypes.COMPONENT if (node.tagType === ElementTypes.COMPONENT) {
if (isComponent) {
processComponent(node, context) processComponent(node, context)
} }
if (context.scopeId) { if (context.scopeId) {
...@@ -87,14 +89,22 @@ function addScopeId(node: ElementNode, scopeId: string) { ...@@ -87,14 +89,22 @@ function addScopeId(node: ElementNode, scopeId: string) {
return addStaticClass(node, scopeId) 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( return addStaticClass(
node, node,
context.scopes.vFor ? 'vue-ref-in-for' : 'vue-ref' context.scopes.vFor ? 'vue-ref-in-for' : 'vue-ref'
) )
} }
function processComponent(node: ElementNode, context: TransformContext) { function processComponent(node: ComponentNode, context: TransformContext) {
const { tag } = node const { tag } = node
if (context.bindingComponents[tag]) { if (context.bindingComponents[tag]) {
return addVueRef(node, context) return addVueRef(node, context)
...@@ -126,6 +136,7 @@ function processComponent(node: ElementNode, context: TransformContext) { ...@@ -126,6 +136,7 @@ function processComponent(node: ElementNode, context: TransformContext) {
) )
} }
addVueId(node, context)
addVueRef(node, context) addVueRef(node, context)
// 3. user component (from setup bindings) // 3. user component (from setup bindings)
...@@ -301,7 +312,3 @@ function processVModel(node: ElementNode, context: TransformContext) { ...@@ -301,7 +312,3 @@ function processVModel(node: ElementNode, context: TransformContext) {
} }
props.push(...dirs) props.push(...dirs)
} }
function isComponentTag(tag: string) {
return tag[0].toLowerCase() + tag.slice(1) === 'component'
}
...@@ -186,12 +186,14 @@ export function processExpression( ...@@ -186,12 +186,14 @@ export function processExpression(
const isAllowedGlobal = isGloballyWhitelisted(rawExp) const isAllowedGlobal = isGloballyWhitelisted(rawExp)
const isLiteral = isLiteralWhitelisted(rawExp) const isLiteral = isLiteralWhitelisted(rawExp)
const isFilter = context.filters.includes(rawExp) const isFilter = context.filters.includes(rawExp)
const isBuiltIn = isBuiltInIdentifier(rawExp)
if ( if (
!asParams && !asParams &&
!isScopeVarReference && !isScopeVarReference &&
!isAllowedGlobal && !isAllowedGlobal &&
!isLiteral && !isLiteral &&
!isFilter !isFilter &&
!isBuiltIn
) { ) {
// const bindings exposed from setup can be skipped for patching but // const bindings exposed from setup can be skipped for patching but
// cannot be hoisted to module scope // cannot be hoisted to module scope
...@@ -343,3 +345,14 @@ function stringifyExpression(exp: ExpressionNode | string): string { ...@@ -343,3 +345,14 @@ function stringifyExpression(exp: ExpressionNode | string): string {
.join('') .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' ...@@ -17,7 +17,7 @@ import { camelize, toHandlerKey } from '@vue/shared'
import { V_ON } from '../runtimeHelpers' import { V_ON } from '../runtimeHelpers'
import { DirectiveTransform, TransformContext } from '../transform' import { DirectiveTransform, TransformContext } from '../transform'
import { DirectiveTransformResult } from './transformElement' import { DirectiveTransformResult } from './transformElement'
import { processExpression } from './transformExpression' import { isBuiltInIdentifier, processExpression } from './transformExpression'
const fnExpRE = const fnExpRE =
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/ /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
...@@ -191,10 +191,14 @@ function isFilterExpr(value: ExpressionNode, context: TransformContext) { ...@@ -191,10 +191,14 @@ function isFilterExpr(value: ExpressionNode, context: TransformContext) {
} }
export function wrapperVOn(value: ExpressionNode, context: TransformContext) { export function wrapperVOn(value: ExpressionNode, context: TransformContext) {
if (isBuiltInIdentifier(value)) {
return value
}
// wxs event // wxs event
if (isFilterExpr(value, context)) { if (isFilterExpr(value, context)) {
return value return value
} }
return createCompoundExpression([ return createCompoundExpression([
`${context.helperString(V_ON)}(`, `${context.helperString(V_ON)}(`,
value, value,
......
...@@ -12,6 +12,7 @@ import { uniOptions } from './uni' ...@@ -12,6 +12,7 @@ import { uniOptions } from './uni'
import { buildOptions } from './build' import { buildOptions } from './build'
import { createConfigResolved } from './configResolved' import { createConfigResolved } from './configResolved'
import { emitFile, getFilterFiles, getTemplateFiles } from './template' import { emitFile, getFilterFiles, getTemplateFiles } from './template'
import { CompilerOptions } from '@vue/compiler-core'
export interface UniMiniProgramPluginOptions { export interface UniMiniProgramPluginOptions {
vite: { vite: {
...@@ -42,6 +43,7 @@ export interface UniMiniProgramPluginOptions { ...@@ -42,6 +43,7 @@ export interface UniMiniProgramPluginOptions {
extname: string extname: string
generate: Parameters<typeof findMiniProgramTemplateFiles>[0] generate: Parameters<typeof findMiniProgramTemplateFiles>[0]
} }
compilerOptions?: CompilerOptions
} }
style: { style: {
extname: string extname: string
...@@ -76,6 +78,7 @@ export function uniMiniProgramPlugin( ...@@ -76,6 +78,7 @@ export function uniMiniProgramPlugin(
emitFile, emitFile,
slot: template.slot, slot: template.slot,
}, },
compilerOptions: template.compilerOptions,
}), }),
config() { config() {
return { return {
......
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared' import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import { EmittedFile } from 'rollup'
import { CopyOptions, UniVitePlugin } from '@dcloudio/uni-cli-shared' import {
import { TemplateCompiler } from '@vue/compiler-sfc' CopyOptions,
UniVitePlugin,
MiniProgramCompilerOptions,
} from '@dcloudio/uni-cli-shared'
import { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc'
import * as compiler from '@dcloudio/uni-mp-compiler' import * as compiler from '@dcloudio/uni-mp-compiler'
export function uniOptions({ export function uniOptions({
copyOptions, copyOptions,
miniProgram, miniProgram,
compilerOptions,
}: { }: {
copyOptions: CopyOptions copyOptions: CopyOptions
miniProgram: { miniProgram: MiniProgramCompilerOptions
slot: { compilerOptions?: CompilerOptions
fallback: boolean
}
filter?: {
lang: string
}
directive: string
emitFile?: (emittedFile: EmittedFile) => string
}
}): UniVitePlugin['uni'] { }): UniVitePlugin['uni'] {
return { return {
copyOptions, copyOptions,
...@@ -28,6 +25,7 @@ export function uniOptions({ ...@@ -28,6 +25,7 @@ export function uniOptions({
miniProgram, miniProgram,
isNativeTag, isNativeTag,
isCustomElement, isCustomElement,
...compilerOptions,
}, },
} }
} }
...@@ -124,6 +124,9 @@ ${filter.code} ...@@ -124,6 +124,9 @@ ${filter.code}
}, },
extname: '.wxml', extname: '.wxml',
directive: 'wx:', directive: 'wx:',
compilerOptions: {
nodeTransforms: [uniCliShared.addComponentBindLink],
},
}, },
style: { style: {
extname: '.wxss', extname: '.wxss',
......
import { Plugin } from 'vite' import { Plugin } from 'vite'
import { resolveBuiltIn } from '@dcloudio/uni-cli-shared' import { addComponentBindLink, resolveBuiltIn } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin, { import initMiniProgramPlugin, {
UniMiniProgramPluginOptions, UniMiniProgramPluginOptions,
} from '@dcloudio/uni-mp-vite' } from '@dcloudio/uni-mp-vite'
...@@ -78,6 +78,9 @@ ${filter.code} ...@@ -78,6 +78,9 @@ ${filter.code}
}, },
extname: '.wxml', extname: '.wxml',
directive: 'wx:', directive: 'wx:',
compilerOptions: {
nodeTransforms: [addComponentBindLink],
},
}, },
style: { style: {
extname: '.wxss', extname: '.wxss',
......
...@@ -84,6 +84,9 @@ function isNativeTag(tag) { ...@@ -84,6 +84,9 @@ function isNativeTag(tag) {
function isCustomElement(_tag) { function isCustomElement(_tag) {
return false; return false;
} }
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
}
const COMPONENT_SELECTOR_PREFIX = 'uni-'; const COMPONENT_SELECTOR_PREFIX = 'uni-';
const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX; const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX;
...@@ -1232,6 +1235,7 @@ exports.getValueByDataPath = getValueByDataPath; ...@@ -1232,6 +1235,7 @@ exports.getValueByDataPath = getValueByDataPath;
exports.initCustomDataset = initCustomDataset; exports.initCustomDataset = initCustomDataset;
exports.invokeArrayFns = invokeArrayFns; exports.invokeArrayFns = invokeArrayFns;
exports.isBuiltInComponent = isBuiltInComponent; exports.isBuiltInComponent = isBuiltInComponent;
exports.isComponentTag = isComponentTag;
exports.isCustomElement = isCustomElement; exports.isCustomElement = isCustomElement;
exports.isH5CustomElement = isH5CustomElement; exports.isH5CustomElement = isH5CustomElement;
exports.isH5NativeTag = isH5NativeTag; exports.isH5NativeTag = isH5NativeTag;
......
...@@ -206,6 +206,8 @@ export declare const invokeArrayFns: (fns: Function[], arg?: any) => any; ...@@ -206,6 +206,8 @@ export declare const invokeArrayFns: (fns: Function[], arg?: any) => any;
export declare function isBuiltInComponent(tag: string): boolean; export declare function isBuiltInComponent(tag: string): boolean;
export declare function isComponentTag(tag: string): boolean;
export declare function isCustomElement(_tag: string): boolean; export declare function isCustomElement(_tag: string): boolean;
export declare function isH5CustomElement(tag: string): boolean; export declare function isH5CustomElement(tag: string): boolean;
......
...@@ -80,6 +80,9 @@ function isNativeTag(tag) { ...@@ -80,6 +80,9 @@ function isNativeTag(tag) {
function isCustomElement(_tag) { function isCustomElement(_tag) {
return false; return false;
} }
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
}
const COMPONENT_SELECTOR_PREFIX = 'uni-'; const COMPONENT_SELECTOR_PREFIX = 'uni-';
const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX; const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX;
...@@ -1115,4 +1118,4 @@ function getEnvLocale() { ...@@ -1115,4 +1118,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en'; 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) { ...@@ -87,6 +87,10 @@ export function isCustomElement(_tag: string) {
return false return false
} }
export function isComponentTag(tag: string) {
return tag[0].toLowerCase() + tag.slice(1) === 'component'
}
export const COMPONENT_SELECTOR_PREFIX = 'uni-' export const COMPONENT_SELECTOR_PREFIX = 'uni-'
export const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX export const COMPONENT_PREFIX = 'v-' + COMPONENT_SELECTOR_PREFIX
// Jest Snapshot v1, https://goo.gl/fbAQLP // 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`] = ` exports[`block parseBlockCode 1`] = `
"<template><view><template></template></view></template> "<template><view><template></template></view></template>
<script> <script>
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // 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`] = ` exports[`wxs parseWxsCode 1`] = `
"<template><view></view><view></view></template> "<template><view></view><view></view></template>
<script> <script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册