Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
7a5c0f88
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a5c0f88
编写于
10月 21, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): add bind:__l="__l"
上级
d6fadc26
变更
21
显示空白变更内容
内联
并排
Showing
21 changed file
with
193 addition
and
134 deletion
+193
-134
packages/uni-cli-shared/src/mp/event.ts
packages/uni-cli-shared/src/mp/event.ts
+3
-0
packages/uni-cli-shared/src/mp/template.ts
packages/uni-cli-shared/src/mp/template.ts
+49
-1
packages/uni-cli-shared/src/vite/index.ts
packages/uni-cli-shared/src/vite/index.ts
+2
-2
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+17
-0
packages/uni-mp-compiler/src/compile.ts
packages/uni-mp-compiler/src/compile.ts
+25
-6
packages/uni-mp-compiler/src/options.ts
packages/uni-mp-compiler/src/options.ts
+5
-23
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+19
-13
packages/uni-mp-compiler/src/transform.ts
packages/uni-mp-compiler/src/transform.ts
+4
-0
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+15
-8
packages/uni-mp-compiler/src/transforms/transformExpression.ts
...ges/uni-mp-compiler/src/transforms/transformExpression.ts
+14
-1
packages/uni-mp-compiler/src/transforms/vOn.ts
packages/uni-mp-compiler/src/transforms/vOn.ts
+5
-1
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+3
-0
packages/uni-mp-vite/src/plugin/uni/index.ts
packages/uni-mp-vite/src/plugin/uni/index.ts
+11
-13
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+3
-0
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+4
-1
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+4
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+2
-0
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+4
-1
packages/uni-shared/src/tags.ts
packages/uni-shared/src/tags.ts
+4
-0
packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
...ite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
+0
-18
packages/vite-plugin-uni/__tests__/__snapshots__/wxs.spec.ts.snap
.../vite-plugin-uni/__tests__/__snapshots__/wxs.spec.ts.snap
+0
-46
未找到文件。
packages/uni-cli-shared/src/mp/event.ts
浏览文件 @
7a5c0f88
...
...
@@ -25,6 +25,9 @@ export function formatMiniProgramEvent(
}
function
isSimpleExpr
(
name
:
string
)
{
if
(
name
.
startsWith
(
'
_
'
))
{
return
false
}
if
(
name
.
indexOf
(
'
-
'
)
>
-
1
)
{
return
false
}
...
...
packages/uni-cli-shared/src/mp/template.ts
浏览文件 @
7a5c0f88
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
),
})
}
}
packages/uni-cli-shared/src/vite/index.ts
浏览文件 @
7a5c0f88
import
type
{
Plugin
}
from
'
vite
'
import
type
{
Emitted
File
}
from
'
rollup
'
import
type
{
Emitted
Asset
}
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
:
Emitted
File
)
=>
string
emitFile
?:
(
emittedFile
:
Emitted
Asset
)
=>
string
}
isNativeTag
:
ParserOptions
[
'
isNativeTag
'
]
isCustomElement
:
ParserOptions
[
'
isCustomElement
'
]
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
0 → 100644
浏览文件 @
7a5c0f88
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
],
}
)
})
})
packages/uni-mp-compiler/src/compile.ts
浏览文件 @
7a5c0f88
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
.
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
))
{
...
...
packages/uni-mp-compiler/src/options.ts
浏览文件 @
7a5c0f88
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
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
7a5c0f88
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
:
Elemen
tNode
,
context
:
TemplateCodegenContext
)
{
function
genSlot
(
node
:
SlotOutle
tNode
,
context
:
TemplateCodegenContext
)
{
if
(
!
node
.
children
.
length
)
{
return
genElement
(
node
,
context
)
}
...
...
@@ -152,7 +154,7 @@ function findSlotName(node: ElementNode) {
}
}
function
genTemplate
(
node
:
Element
Node
,
context
:
TemplateCodegenContext
)
{
function
genTemplate
(
node
:
Template
Node
,
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
:
Elem
entNode
,
context
:
TemplateCodegenContext
)
{
function
genComponent
(
node
:
Compon
entNode
,
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
,
{
const
name
=
formatMiniProgramEvent
(
arg
,
{
isCatch
:
modifiers
.
includes
(
'
stop
'
)
||
modifiers
.
includes
(
'
prevent
'
),
isCapture
:
modifiers
.
includes
(
'
capture
'
),
isComponent
:
node
.
tagType
===
ElementTypes
.
COMPONENT
,
})}
="{{
${
exp
}
}}"`
)
})
if
(
exp
.
isStatic
)
{
push
(
`
${
name
}
="
${
exp
.
content
}
"`
)
}
else
{
push
(
`
${
name
}
="{{
${
exp
.
content
}
}}"`
)
}
}
function
genDirectiveNode
(
...
...
packages/uni-mp-compiler/src/transform.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
]
...
...
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
:
Elem
entNode
,
context
:
TransformContext
)
{
function
processComponent
(
node
:
Compon
entNode
,
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
'
}
packages/uni-mp-compiler/src/transforms/transformExpression.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
)
}
packages/uni-mp-compiler/src/transforms/vOn.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
,
...
...
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
{
...
...
packages/uni-mp-vite/src/plugin/uni/index.ts
浏览文件 @
7a5c0f88
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
,
},
}
}
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
7a5c0f88
...
...
@@ -124,6 +124,9 @@ ${filter.code}
},
extname
:
'
.wxml
'
,
directive
:
'
wx:
'
,
compilerOptions
:
{
nodeTransforms
:
[
uniCliShared
.
addComponentBindLink
],
},
},
style
:
{
extname
:
'
.wxss
'
,
...
...
packages/uni-mp-weixin/src/plugin/index.ts
浏览文件 @
7a5c0f88
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
'
,
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
7a5c0f88
...
...
@@ -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
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
;
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
7a5c0f88
...
...
@@ -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
,
isC
omponentTag
,
isC
ustomElement
,
isH5CustomElement
,
isH5NativeTag
,
isNativeTag
,
isRootHook
,
normalizeDataset
,
normalizeEventType
,
normalizeTarget
,
once
,
parseEventName
,
parseQuery
,
parseUrl
,
passive
,
plusReady
,
removeLeadingSlash
,
resolveOwnerEl
,
resolveOwnerVm
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/tags.ts
浏览文件 @
7a5c0f88
...
...
@@ -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
packages/vite-plugin-uni/__tests__/__snapshots__/block.spec.ts.snap
浏览文件 @
7a5c0f88
// 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>
...
...
packages/vite-plugin-uni/__tests__/__snapshots__/wxs.spec.ts.snap
浏览文件 @
7a5c0f88
// 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录