Skip to content

Commit 6e010d4

Browse files
authored
fix: fix relative path and node_modules path in widget (#106)
Signed-off-by: lileirjyb <lileirjyb@vivo.com>
1 parent c4a93df commit 6e010d4

File tree

16 files changed

+140
-111
lines changed

16 files changed

+140
-111
lines changed

packages/hap-compiler/src/template/index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ function traverse(node, output, previousNode, conditionList, options) {
7575
switch (name) {
7676
case 'id':
7777
// 保留checkId为兼容原有:新打的RPK包兼容原来的APK平台
78-
validator.checkId(value, output)
79-
validator.checkAttr(name, value, output, node.tagName, locationInfo)
78+
validator.checkId(value, output, options)
79+
validator.checkAttr(name, value, output, node.tagName, locationInfo, options)
8080
break
8181
case 'class':
82-
validator.checkClass(value, output)
82+
validator.checkClass(value, output, options)
8383
break
8484
case 'style':
8585
validator.checkStyle(value, output, locationInfo, options)
8686
break
8787
case 'if':
8888
if (!node._isroot) {
89-
validator.checkIf(value, output, false, locationInfo, conditionList)
89+
validator.checkIf(value, output, false, locationInfo, conditionList, options)
9090
}
9191
break
9292
case 'is':
93-
validator.checkIs(value, output, locationInfo)
93+
validator.checkIs(value, output, locationInfo, options)
9494
break
9595
case 'else':
9696
if (!node._isroot) {
9797
if (previousNode && previousNode.__cond__) {
98-
validator.checkElse(previousNode.__cond__, output, locationInfo, conditionList)
98+
validator.checkElse(previousNode.__cond__, output, locationInfo, conditionList, options)
9999
}
100100
}
101101
break
@@ -107,14 +107,15 @@ function traverse(node, output, previousNode, conditionList, options) {
107107
previousNode.__cond__,
108108
output,
109109
locationInfo,
110-
conditionList
110+
conditionList,
111+
options
111112
)
112113
}
113114
}
114115
break
115116
case 'for':
116117
if (!node._isroot) {
117-
validator.checkFor(value, output, locationInfo)
118+
validator.checkFor(value, output, locationInfo, options)
118119
}
119120
break
120121
case 'tree':
@@ -123,14 +124,14 @@ function traverse(node, output, previousNode, conditionList, options) {
123124
default:
124125
if (name.match(/^(on|@)/)) {
125126
// 事件以on或@开头
126-
validator.checkEvent(name, value, output)
127+
validator.checkEvent(name, value, output, options)
127128
} else {
128129
if (name.match(/^model:/)) {
129130
// 解析model指令,model指令格式:model:name="{{youName}}"
130131
validator.checkModel(name, value, output, node, locationInfo, options)
131132
} else if (name.match(/^dir:/)) {
132133
// 解析自定义指令,自定义指令格式:dir:指令名称="{{data}}"
133-
validator.checkCustomDirective(name, value, output, node)
134+
validator.checkCustomDirective(name, value, output, node, options)
134135
} else {
135136
// 其余为普通属性
136137
validator.checkAttr(name, value, output, node.tagName, locationInfo, options)
@@ -195,17 +196,17 @@ function traverse(node, output, previousNode, conditionList, options) {
195196
column: node.__location.col,
196197
reason: `WARN: 文本和span标签并行存在,编译时将文本节点:"${child.value}" 用span包裹(关于span嵌套的使用,请参考官方文档"span嵌套")`
197198
})
198-
validator.checkAttr('value', child.value, output)
199+
validator.checkAttr('value', child.value, output, null, null, options)
199200
}
200201

201202
// 如果父节点是option, 处理value和content属性
202203
if (node.tagName === 'option') {
203204
const tempResult = output.result
204205
output.result = originResult
205206
if (!originResult.attr.hasOwnProperty('value')) {
206-
validator.checkAttr('value', child.value, output)
207+
validator.checkAttr('value', child.value, output, null, null, options)
207208
}
208-
validator.checkAttr('content', child.value, output)
209+
validator.checkAttr('content', child.value, output, null, null, options)
209210
output.result = tempResult
210211
return
211212
}
@@ -217,7 +218,7 @@ function traverse(node, output, previousNode, conditionList, options) {
217218
) {
218219
const tempResult = output.result // 备份当前result
219220
output.result = originResult
220-
validator.checkAttr('value', child.value, output)
221+
validator.checkAttr('value', child.value, output, null, null, options)
221222
output.result = tempResult
222223
}
223224
}
@@ -365,9 +366,7 @@ function parse(source, options) {
365366
const output = {
366367
result: {},
367368
log: [],
368-
depFiles: [],
369-
isNewJSCard: !!options.newJSCard,
370-
isLite: !!options.lite
369+
depFiles: []
371370
}
372371

373372
// 模板为空或解析失败

packages/hap-compiler/src/template/model.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export default function model(name, value, output, node, locationInfo, options)
4848
/* eslint-disable no-eval */
4949
if (!isDynamicType) {
5050
if (tag === 'select') {
51-
genSelectModel(value, output)
51+
genSelectModel(value, output, options)
5252
} else if (tag === 'input' && type === 'checkbox') {
53-
genCheckboxModel(node, attrName, value, output)
53+
genCheckboxModel(node, attrName, value, output, options)
5454
} else if (tag === 'input' && type === 'radio') {
55-
genRadioModel(node, attrName, value, output)
55+
genRadioModel(node, attrName, value, output, options)
5656
} else if (tag === 'input' || tag === 'textarea') {
57-
genDefaultModel(attrName, value, output)
57+
genDefaultModel(attrName, value, output, options)
5858
} else if (
5959
tag === 'component' ||
6060
!validator.isReservedTag(tag) ||
@@ -64,7 +64,7 @@ export default function model(name, value, output, node, locationInfo, options)
6464
genComponentModel(node, attrName, value, output, locationInfo, options)
6565
}
6666
} else {
67-
genDynamicModel(node, attrName, value, output, type)
67+
genDynamicModel(node, attrName, value, output, type, options)
6868
}
6969
}
7070

@@ -76,7 +76,7 @@ export default function model(name, value, output, node, locationInfo, options)
7676
* @param {object} output 构建的输出结果
7777
* @returns {object} 构建过程中生成的代码字符串组成的对象,供 genDynamicModel 使用
7878
*/
79-
function genCheckboxModel(node, attrName, value, output) {
79+
function genCheckboxModel(node, attrName, value, output, options) {
8080
const expValue = exp(value, false)
8181
const valueBinding = getBindingAttr(node, 'value', true) || 'null'
8282
const trueValueBinding = getBindingAttr(node, 'true-value', true) || 'true'
@@ -102,7 +102,7 @@ function genCheckboxModel(node, attrName, value, output) {
102102
${expValue} = checked ? ${trueValueBinding} : ${falseValueBinding}
103103
}`
104104

105-
const isNewJSCard = output.isNewJSCard
105+
const isNewJSCard = options.newJSCard
106106
if (isNewJSCard) {
107107
addAttr(output.result, attrName, `(function() {${attrCheckedCode}})`)
108108
addAttr(output.result, attrName + 'Raw', value)
@@ -125,13 +125,13 @@ function genCheckboxModel(node, attrName, value, output) {
125125
* @param {object} output 构建的输出结果
126126
* @returns {object} 构建过程中生成的代码字符串组成的对象,供 genDynamicModel 使用
127127
*/
128-
function genRadioModel(node, attrName, value, output) {
128+
function genRadioModel(node, attrName, value, output, options) {
129129
const valueBinding = getBindingAttr(node, 'value', true) || 'null'
130130

131131
const attrCheckedCode = `return ${exp(value, false)} === ${valueBinding}`
132132
const eventChangeCode = `${exp(value, false)} = ${valueBinding}`
133133

134-
const isNewJSCard = output.isNewJSCard
134+
const isNewJSCard = options.newJSCard
135135
if (isNewJSCard) {
136136
addAttr(output.result, attrName, `(function() {${attrCheckedCode}})`)
137137
addAttr(output.result, attrName + 'Raw', value)
@@ -152,8 +152,8 @@ function genRadioModel(node, attrName, value, output) {
152152
* @param {string} value model 绑定的值
153153
* @param {object} output 构建的输出结果
154154
*/
155-
function genSelectModel(value, output) {
156-
const isNewJSCard = output.isNewJSCard
155+
function genSelectModel(value, output, options) {
156+
const isNewJSCard = options.newJSCard
157157
if (isNewJSCard) {
158158
addHandler(output.result, 'change', `function(evt) { ${exp(value, false)} = evt.newValue}`)
159159
} else {
@@ -172,10 +172,10 @@ function genSelectModel(value, output) {
172172
* @param {object} output 构建的输出结果
173173
* @returns {object} 构建过程中生成的代码字符串组成的对象,供 genDynamicModel 使用
174174
*/
175-
function genDefaultModel(attrName, value, output) {
175+
function genDefaultModel(attrName, value, output, options) {
176176
const eventChangeCode = `${exp(value, false)} = evt.target.value`
177-
const isNewJSCard = output.isNewJSCard
178-
const isLite = output.isLite
177+
const isNewJSCard = options.newJSCard
178+
const isLite = options.lite
179179
if (isNewJSCard) {
180180
addAttr(output.result, attrName, exp(value, true, isLite, isNewJSCard))
181181
addAttr(output.result, attrName + 'Raw', value)
@@ -200,7 +200,7 @@ function genComponentModel(node, attrName, value, output, locationInfo, options)
200200
// 自定义组件model指令绑定的属性,依然作为普通属性处理
201201
validator.checkAttr(attrName, value, output, node.tagName, locationInfo, options)
202202

203-
const isNewJSCard = output.isNewJSCard
203+
const isNewJSCard = options.newJSCard
204204
if (isNewJSCard) {
205205
addHandler(
206206
output.result,
@@ -225,12 +225,12 @@ function genComponentModel(node, attrName, value, output, locationInfo, options)
225225
* @param {object} output 构建的输出结果
226226
* @param {string} expType type 属性绑定的值
227227
*/
228-
function genDynamicModel(node, attrName, value, output, expType) {
229-
const checkboxCode = genCheckboxModel(node, attrName, value, output)
230-
const radioCode = genRadioModel(node, attrName, value, output)
231-
const textCode = genDefaultModel(attrName, value, output)
232-
const isNewJSCard = output.isNewJSCard
233-
const isLite = output.isLite
228+
function genDynamicModel(node, attrName, value, output, expType, options) {
229+
const checkboxCode = genCheckboxModel(node, attrName, value, output, options)
230+
const radioCode = genRadioModel(node, attrName, value, output, options)
231+
const textCode = genDefaultModel(attrName, value, output, options)
232+
const isNewJSCard = options.newJSCard
233+
const isLite = options.lite
234234
if (isNewJSCard) {
235235
addAttr(output.result, attrName, exp(value, true, isLite, isNewJSCard))
236236
addAttr(output.result, attrName + 'Raw', value)

0 commit comments

Comments
 (0)