diff --git a/config/loaders/wxml-loader.js b/config/loaders/wxml-loader.js index 5e0db83..b3da525 100644 --- a/config/loaders/wxml-loader.js +++ b/config/loaders/wxml-loader.js @@ -119,7 +119,7 @@ function codeChunkIncludesT(text) { * @returns */ function transformCode(text, namespace, moduleName) { - const codeChunkRegex = /{{((\w|\W)*)}}/g; + const codeChunkRegex = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm; const matches = text.match(codeChunkRegex); if (!matches) { return text; diff --git a/test.js b/test.js index bb05262..d346ab2 100644 --- a/test.js +++ b/test.js @@ -9,7 +9,7 @@ function codeChunkIncludesT(text) { } function transformCode(text, namespace, moduleName) { - const codeChunkRegex = /{{((\w|\W)*)}}/g; + const codeChunkRegex = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm; const matches = text.match(codeChunkRegex); if (!matches) { return text; @@ -89,5 +89,5 @@ function getProjectPath(filepath) { } -console.log(transformCode('{{abc + t("abd")}}', 'ns', 'module')); +console.log(transformCode("只显示{{t('house')}}和{{t('house')}}", 'ns', 'module')); // console.log(getProjectPath('D:\\git\\taicang\\src\\pages\\home\\index.xml')); \ No newline at end of file