Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Chameleon
提交
a48d508d
C
Chameleon
项目概览
DiDi
/
Chameleon
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Chameleon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a48d508d
编写于
2月 21, 2019
作者:
J
JiM-W
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成cml和vue语法严格校验
上级
4b2cdf40
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
72 addition
and
19 deletion
+72
-19
packages/chameleon-template-parse/package.json
packages/chameleon-template-parse/package.json
+1
-0
packages/chameleon-template-parse/src/common/process-template.js
...s/chameleon-template-parse/src/common/process-template.js
+51
-8
packages/chameleon-template-parse/src/compile-template-cml.js
...ages/chameleon-template-parse/src/compile-template-cml.js
+3
-1
packages/chameleon-template-parse/src/compile-template-vue.js
...ages/chameleon-template-parse/src/compile-template-vue.js
+3
-1
packages/chameleon-template-parse/src/parser/parse-class.js
packages/chameleon-template-parse/src/parser/parse-class.js
+6
-2
packages/chameleon-template-parse/test/index.js
packages/chameleon-template-parse/test/index.js
+8
-7
未找到文件。
packages/chameleon-template-parse/package.json
浏览文件 @
a48d508d
...
...
@@ -25,6 +25,7 @@
"chai"
:
"^4.2.0"
,
"chameleon-css-loader"
:
"0.1.0-alpha.2"
,
"chameleon-mixins"
:
"0.1.0-alpha.2"
,
"chameleon-tool-utils"
:
"0.0.29"
,
"clean-webpack-plugin"
:
"^0.1.19"
,
"coveralls"
:
"^2.11.9"
,
"eslint"
:
"^5.9.0"
,
...
...
packages/chameleon-template-parse/src/common/process-template.js
浏览文件 @
a48d508d
...
...
@@ -411,18 +411,26 @@ exports.preCheckTemplateSyntax = function(source, type, options) {
errorInfo
=
exports
.
preCheckTemplateSyntaxForVue
(
source
,
type
,
options
)
}
catch
(
e
)
{
console
.
log
(
'
catch
'
,
e
)
errorInfo
=
'
vue syntax error
'
}
}
if
(
lang
===
'
cml
'
)
{
try
{
errorInfo
=
exports
.
preCheckTemplateSyntaxForCml
(
source
,
type
,
options
)
}
catch
(
e
)
{
errorInfo
=
'
cml syntax error
'
}
}
return
errorInfo
}
exports
.
preCheckTemplateSyntaxForVue
=
function
(
source
,
type
,
options
)
{
debugger
;
let
{
lang
}
=
options
;
if
(
lang
===
'
vue
'
)
{
let
callbacks
=
[
'
preDisappearAnnotation
'
,
'
preParseEventSyntax
'
,
'
preParseGtLt
'
,
'
preParseBindAttr
'
,
'
preParseMustache
'
,
'
postParseLtGt
'
]
source
=
exports
.
preParseTemplateToSatisfactoryJSX
(
source
,
callbacks
);
let
errorInfo
=
''
;
let
directiveError
,
twoWayBindError
,
eventBindingError
;
let
disabledPropsInVueSyntax
=
[
'
c-if
'
,
'
c-else-if
'
,
'
c-else
'
,
'
c-show
'
,
'
c-text
'
,
'
c-model
'
,
'
c-animation
'
,
'
c-for
'
]
const
ast
=
babylon
.
parse
(
source
,
{
plugins
:
[
'
jsx
'
]
...
...
@@ -430,14 +438,49 @@ exports.preCheckTemplateSyntaxForVue = function(source, type, options) {
traverse
(
ast
,
{
enter
(
path
)
{
let
node
=
path
.
node
;
if
(
t
.
isJSXAttribute
(
node
)
&&
disabledPropsInVueSyntax
.
includes
(
node
.
name
.
name
))
{
errorInfo
+=
`vue 语法下不能使用
${
node
.
name
.
name
}
`
if
(
!
directiveError
&&
t
.
isJSXAttribute
(
node
)
&&
disabledPropsInVueSyntax
.
includes
(
node
.
name
.
name
))
{
errorInfo
+=
`vue 语法下不能使用
${
node
.
name
.
name
}
;`
directiveError
=
true
}
if
(
!
twoWayBindError
&&
t
.
isJSXAttribute
(
node
)
&&
utils
.
isMustacheReactive
(
node
.
value
.
value
))
{
errorInfo
+=
'
vue 语法下不能用 id={{value}},请使用 v-bind:id="value" 或者 :id="value" 进行响应式值的绑定;
'
twoWayBindError
=
true
;
}
if
(
!
eventBindingError
&&
t
.
isJSXNamespacedName
(
node
.
name
)
&&
node
.
name
.
namespace
.
name
===
'
c-bind
'
)
{
errorInfo
+=
'
vue 语法下不能用 c-bind 进行事件绑定,请使用 @ 或者v-on进行事件绑定;
'
eventBindingError
=
true
}
}
});
return
errorInfo
}
}
exports
.
preCheckTemplateSyntaxForCml
=
function
(
source
,
type
,
options
)
{
let
{
lang
}
=
options
;
if
(
lang
===
'
cml
'
)
{
let
callbacks
=
[
'
preDisappearAnnotation
'
,
'
preParseEventSyntax
'
,
'
preParseGtLt
'
,
'
preParseBindAttr
'
,
'
preParseMustache
'
,
'
postParseLtGt
'
]
source
=
exports
.
preParseTemplateToSatisfactoryJSX
(
source
,
callbacks
);
let
errorInfo
=
''
;
let
directiveError
,
twoWayBindError
,
eventBindingError
;
let
disabledPropsInVueSyntax
=
[
'
v-if
'
,
'
v-else-if
'
,
'
v-else
'
,
'
v-show
'
,
'
v-text
'
,
'
v-model
'
,
'
v-animation
'
,
'
v-for
'
]
const
ast
=
babylon
.
parse
(
source
,
{
plugins
:
[
'
jsx
'
]
})
traverse
(
ast
,
{
enter
(
path
)
{
let
node
=
path
.
node
;
if
(
!
directiveError
&&
t
.
isJSXAttribute
(
node
)
&&
disabledPropsInVueSyntax
.
includes
(
node
.
name
.
name
))
{
errorInfo
+=
`cml 语法下不能使用
${
node
.
name
.
name
}
;`
directiveError
=
true
;
}
if
(
t
.
isJSXAttribute
(
node
)
&&
utils
.
isMustacheReactive
(
node
.
value
.
value
))
{
errorInfo
+=
'
vue 语法下属性值不能用 {{}}
'
if
(
!
twoWayBindError
&&
t
.
isJSXNamespacedName
(
node
.
name
)
&&
node
.
name
.
namespace
.
name
===
'
v-bind
'
)
{
errorInfo
+=
'
cml 语法下不能用 :id="value" 或者 v-bind:id="value"进行响应式的值得双向绑定,请使用 id={{value}} ;
'
twoWayBindError
=
true
;
}
if
(
t
.
isJSXNamespacedName
(
node
.
name
)
&&
node
.
name
.
namespace
.
name
===
'
c-bind
'
)
{
errorInfo
+=
'
vue 语法下事件绑定不能用 c-bind,请使用 @ 或者v-on进行事件绑定
'
if
(
!
eventBindingError
&&
t
.
isJSXNamespacedName
(
node
.
name
)
&&
node
.
name
.
namespace
.
name
===
'
v-on
'
)
{
errorInfo
+=
'
cml 语法下不能用 @ 或者 v-on 进行事件绑定,请使用 c-bind进行事件绑定;
'
eventBindingError
=
true
;
}
}
});
...
...
packages/chameleon-template-parse/src/compile-template-cml.js
浏览文件 @
a48d508d
...
...
@@ -7,10 +7,12 @@ const parseTemplate = require('./parser/index.js');
// 对于模板的预处理 - 后置处理 - 等正则的一些替换;
const
processTemplate
=
require
(
'
./common/process-template.js
'
)
// 目前事件的处理有两处:第一,c-bind,第二c-model,两者互相不影响;借鉴于此,需要新增处理事件支持传参的形式,而此时就需要处理c-bind;
const
cliUtils
=
require
(
'
chameleon-tool-utils
'
);
exports
.
compileTemplateForCml
=
function
(
source
,
type
,
options
)
{
let
errorInfo
=
processTemplate
.
preCheckTemplateSyntax
(
source
,
type
,
options
)
if
(
errorInfo
)
{
throw
new
Error
(
errorInfo
)
// throw new Error(`${errorInfo} in ${options.filePath}`)
cliUtils
.
log
.
warn
(
`
${
errorInfo
}
in
${
options
.
filePath
}
`
);
}
// source
// 预处理html模板中的注释,jsx不支持,这个需要优先处理,防止解析 < > 的时候出现问题;
...
...
packages/chameleon-template-parse/src/compile-template-vue.js
浏览文件 @
a48d508d
...
...
@@ -7,10 +7,12 @@ const parseTemplate = require('./parser/index.js');
// 对于模板的预处理 - 后置处理 - 等正则的一些替换;
const
processTemplate
=
require
(
'
./common/process-template.js
'
)
// 目前事件的处理有两处:第一,c-bind,第二c-model,两者互相不影响;借鉴于此,需要新增处理事件支持传参的形式,而此时就需要处理c-bind;
const
cliUtils
=
require
(
'
chameleon-tool-utils
'
);
exports
.
compileTemplateForVue
=
function
(
source
,
type
,
options
)
{
let
errorInfo
=
processTemplate
.
preCheckTemplateSyntax
(
source
,
type
,
options
)
if
(
errorInfo
)
{
throw
new
Error
(
errorInfo
)
// throw new Error(`${errorInfo} in ${options.filePath}`)
cliUtils
.
log
.
warn
(
`
${
errorInfo
}
in
${
options
.
filePath
}
`
);
}
// source
// 预处理html模板中的注释,将其删除;这个需要优先处理,防止解析 < > 的时候出现问题;
...
...
packages/chameleon-template-parse/src/parser/parse-class.js
浏览文件 @
a48d508d
...
...
@@ -132,7 +132,7 @@ parseClass.tap('weex-vue', (args) => {
})
parseClass
.
tap
(
'
wx-alipay-baidu-vue
'
,
(
args
)
=>
{
let
{
node
,
type
,
options
:
{
lang
}
}
=
args
;
let
{
node
,
type
,
options
:
{
lang
,
filePath
}
}
=
args
;
if
(
lang
===
'
vue
'
&&
(
type
===
'
wx
'
||
type
===
'
alipay
'
||
type
===
'
baidu
'
))
{
let
tagName
=
node
.
openingElement
.
name
.
name
;
let
attributes
=
node
.
openingElement
.
attributes
;
...
...
@@ -140,7 +140,11 @@ parseClass.tap('wx-alipay-baidu-vue', (args) => {
attr
.
name
.
name
===
'
class
'
||
attr
.
name
.
name
.
name
===
'
class
'
);
let
extraClass
=
` cml-base cml-
${
tagName
}
`
;
if
(
type
===
'
alipay
'
)
{
let
num
=
32
;
let
randomClassName
=
fnv
.
hash
(
filePath
,
num
).
str
();
extraClass
=
`
${
extraClass
}
cml-
${
randomClassName
}
`
}
utils
.
handleVUEClassNodes
({
classNodes
,
attributes
,
extraClass
,
lang
,
type
:
'
miniapp
'
})
}
...
...
packages/chameleon-template-parse/test/index.js
浏览文件 @
a48d508d
const
compileTemplate
=
require
(
'
../src/index.js
'
);
const
source
=
`<
view
>
<
cube-button @tap="handleClick"></cube-button
>
<
thirdComp2 c-bind:tap="handleClick"></thirdComp2
>
</
view>
`
const
source
=
`<
scroller height="{{-1}}"
>
<
view v-if="false"> v-if</view
>
<
view > v-if</view
>
</
scroller>
`
// <view><text :class="{{true? 'bg-green':''}}" >fafafa</text></view>
// <view><text :class="true? 'bg-green':''" >fafafa</text></view>
//
// let result = compileTemplate(source,'web');
let
options
=
{
lang
:
'
vue
'
,
let
options
=
{
lang
:
'
cml
'
,
filePath
:
'
/Users/didi/components
'
,
buildInComponents
:
{
button
:
"
cml-buildin-button
"
},
cmss
:
{
rem
:
true
,
...
...
@@ -36,11 +37,11 @@ let options = {lang: 'vue',
};
console
.
log
(
'
before-compile
'
,
source
);
let
result_web
=
compileTemplate
(
source
,
'
web
'
,
options
);
//
let result_wx = compileTemplate(source, 'wx', options);
let
result_wx
=
compileTemplate
(
source
,
'
wx
'
,
options
);
// let result_baidu = compileTemplate(source, 'wx', options);
// let result_alipay = compileTemplate(source, 'alipay', options);
// let result_alipay = compileTemplate(source,'alipay',{lang:'cml'});
console
.
log
(
'
result_web
'
,
result_web
)
//
console.log('result_wx', result_wx)
console
.
log
(
'
result_wx
'
,
result_wx
)
// console.log('result_alipay', result_alipay)
// console.log('result_baidu', result_baidu)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录