diff --git a/packages/core/src/dynamic/vnode/render.js b/packages/core/src/dynamic/vnode/render.js index 20e3d5cca..0f119e012 100644 --- a/packages/core/src/dynamic/vnode/render.js +++ b/packages/core/src/dynamic/vnode/render.js @@ -144,7 +144,7 @@ export default function _genVnodeTree (astData, contextScope, options) { node.attrsList.forEach((attr) => { if (attr.name === 'class' || attr.name === 'style') { // class/style 的表达式为数组形式,class/style的计算过程需要放到逻辑层,主要是因为有逻辑匹配的过程去生成 vnodeTree - const helper = attr.name === 'class' ? stringify.stringifyClass : stringify.stringifyStyle + const helper = attr.name === 'class' ? stringify.c : stringify.s let value = '' if (attr.__exp) { let valueArr = evalExps(attr.__exp) diff --git a/packages/webpack-plugin/lib/runtime/stringify.wxs b/packages/webpack-plugin/lib/runtime/stringify.wxs index 64f722b99..7ea01623a 100644 --- a/packages/webpack-plugin/lib/runtime/stringify.wxs +++ b/packages/webpack-plugin/lib/runtime/stringify.wxs @@ -223,13 +223,13 @@ function normalizeDynamicStyle (value) { } module.exports = { - stringifyClass: function (staticClass, dynamicClass) { + c: function (staticClass, dynamicClass) { if (typeof staticClass !== 'string') { return console.log('Template attr class must be a string!') } return concat(staticClass, mpEscape(stringifyDynamicClass(dynamicClass))) }, - stringifyStyle: function (staticStyle, dynamicStyle) { + s: function (staticStyle, dynamicStyle) { var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle) var parsedStaticStyle = typeof staticStyle === 'string' ? parseStyleText(staticStyle) : {} return genStyleText(extend(parsedStaticStyle, normalizedDynamicStyle)) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index dbe300bf0..d01472ca2 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -176,7 +176,7 @@ const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js') const i18nWxsRequest = '~' + i18nWxsLoaderPath + '!' + i18nWxsPath const i18nModuleName = '__i18n__' const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs') -const stringifyModuleName = '__stringify__' +const stringifyModuleName = '__sm__' const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs') const optionalChainWxsName = '__oc__' @@ -2133,7 +2133,7 @@ function processClass (el, meta) { addAttrs(el, [{ name: targetType, // swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效 - value: mode === 'swan' && staticClass ? `${staticClass} {{${stringifyModuleName}.stringifyClass('', ${dynamicClassExp})}}` : `{{${stringifyModuleName}.stringifyClass(${staticClassExp}, ${dynamicClassExp})}}` + value: mode === 'swan' && staticClass ? `${staticClass} {{${stringifyModuleName}.c('', ${dynamicClassExp})}}` : `{{${stringifyModuleName}.c(${staticClassExp}, ${dynamicClassExp})}}` }]) injectWxs(meta, stringifyModuleName, stringifyWxsPath) } else if (staticClass) { @@ -2166,7 +2166,7 @@ function processStyle (el, meta) { const dynamicStyleExp = parseMustacheWithContext(dynamicStyle).result addAttrs(el, [{ name: targetType, - value: `{{${stringifyModuleName}.stringifyStyle(${staticStyleExp}, ${dynamicStyleExp})}}` + value: `{{${stringifyModuleName}.s(${staticStyleExp}, ${dynamicStyleExp})}}` }]) injectWxs(meta, stringifyModuleName, stringifyWxsPath) } else if (staticStyle) {