@mpxjs/webpack-plugin 2.7.0-alpha.0 → 2.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +13 -6
- package/lib/dependencies/DynamicEntryDependency.js +85 -41
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +11 -6
- package/lib/extractor.js +17 -7
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +6 -12
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +595 -304
- package/lib/json-compiler/helper.js +36 -32
- package/lib/json-compiler/index.js +119 -66
- package/lib/json-compiler/plugin.js +23 -7
- package/lib/loader.js +135 -90
- package/lib/native-loader.js +37 -69
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +8 -3
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +17 -5
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +4 -0
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +149 -3
- package/lib/record-loader.js +2 -2
- package/lib/resolve-loader.js +4 -1
- package/lib/resolver/AddEnvPlugin.js +4 -3
- package/lib/resolver/AddModePlugin.js +4 -3
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +23 -36
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/components/web/getInnerListeners.js +51 -45
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +37 -8
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/runtime/optionProcessor.js +50 -20
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/runtime/stringify.wxs +6 -4
- package/lib/selector.js +23 -5
- package/lib/style-compiler/index.js +12 -13
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/style-compiler/plugins/rpx.js +43 -37
- package/lib/style-compiler/plugins/scope-id.js +79 -72
- package/lib/style-compiler/plugins/trans-special.js +25 -18
- package/lib/style-compiler/plugins/trim.js +13 -7
- package/lib/style-compiler/plugins/vw.js +19 -12
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +172 -62
- package/lib/template-compiler/index.js +8 -9
- package/lib/template-compiler/trans-dynamic-class-expr.js +32 -22
- package/lib/tenon/index.js +105 -0
- package/lib/tenon/processJSON.js +356 -0
- package/lib/tenon/processScript.js +261 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/utils/const.js +6 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +3 -3
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -2
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +45 -38
- package/lib/web/processTemplate.js +56 -41
- package/lib/wxml/loader.js +1 -6
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxs/i18n-loader.js +5 -4
- package/lib/wxs/loader.js +87 -56
- package/lib/wxs/pre-loader.js +30 -10
- package/lib/wxss/loader.js +3 -3
- package/lib/wxss/processCss.js +135 -131
- package/package.json +23 -17
- package/lib/built-in-loader.js +0 -49
- package/lib/dependencies/RecordStaticResourceDependency.js +0 -47
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
const JSON5 = require('json5')
|
|
2
2
|
const he = require('he')
|
|
3
3
|
const config = require('../config')
|
|
4
|
+
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
4
5
|
const normalize = require('../utils/normalize')
|
|
5
6
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
6
7
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
7
|
-
const mpxJSON = require('../utils/mpx-json')
|
|
8
8
|
const getRulesRunner = require('../platform/index')
|
|
9
9
|
const addQuery = require('../utils/add-query')
|
|
10
10
|
const transDynamicClassExpr = require('./trans-dynamic-class-expr')
|
|
11
11
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
12
12
|
const { inBrowser } = require('../utils/env')
|
|
13
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Make a map and return a function for checking if a key
|
|
@@ -496,7 +497,6 @@ function parseHTML (html, options) {
|
|
|
496
497
|
|
|
497
498
|
function parseComponent (content, options) {
|
|
498
499
|
mode = options.mode || 'wx'
|
|
499
|
-
defs = options.defs || {}
|
|
500
500
|
env = options.env
|
|
501
501
|
filePath = options.filePath
|
|
502
502
|
|
|
@@ -548,6 +548,9 @@ function parseComponent (content, options) {
|
|
|
548
548
|
if (/^application\/json/.test(currentBlock.type) || currentBlock.name === 'json') {
|
|
549
549
|
tag = 'json'
|
|
550
550
|
}
|
|
551
|
+
if (currentBlock.name === 'json') {
|
|
552
|
+
currentBlock.useJSONJS = true
|
|
553
|
+
}
|
|
551
554
|
}
|
|
552
555
|
if (currentBlock.mode && currentBlock.env) {
|
|
553
556
|
if (currentBlock.mode === mode && currentBlock.env === env) {
|
|
@@ -606,20 +609,15 @@ function parseComponent (content, options) {
|
|
|
606
609
|
}
|
|
607
610
|
}
|
|
608
611
|
|
|
609
|
-
function end (tag, start
|
|
612
|
+
function end (tag, start) {
|
|
610
613
|
if (depth === 1 && currentBlock) {
|
|
611
614
|
currentBlock.end = start
|
|
612
615
|
let text = content.slice(currentBlock.start, currentBlock.end)
|
|
613
616
|
// pad content so that linters and pre-processors can output correct
|
|
614
617
|
// line numbers in errors and warnings
|
|
615
|
-
if (
|
|
618
|
+
if (options.pad) {
|
|
616
619
|
text = padContent(currentBlock, options.pad) + text
|
|
617
620
|
}
|
|
618
|
-
|
|
619
|
-
// 对于<script name="json">的标签,传参调用函数,其返回结果作为json的内容
|
|
620
|
-
if (currentBlock.tag === 'script' && !/^application\/json/.test(currentBlock.type) && currentBlock.name === 'json') {
|
|
621
|
-
text = mpxJSON.compileMPXJSONText({ source: text, defs, filePath })
|
|
622
|
-
}
|
|
623
621
|
currentBlock.content = text
|
|
624
622
|
currentBlock = null
|
|
625
623
|
}
|
|
@@ -740,7 +738,6 @@ function parse (template, options) {
|
|
|
740
738
|
|
|
741
739
|
currentParent.children.push(element)
|
|
742
740
|
element.parent = currentParent
|
|
743
|
-
|
|
744
741
|
processElement(element, root, options, meta)
|
|
745
742
|
tagNames.add(element.tag)
|
|
746
743
|
|
|
@@ -907,6 +904,19 @@ function modifyAttr (el, name, val) {
|
|
|
907
904
|
}
|
|
908
905
|
}
|
|
909
906
|
|
|
907
|
+
function moveBaseDirective (target, from, isDelete = true) {
|
|
908
|
+
target.for = from.for
|
|
909
|
+
target.if = from.if
|
|
910
|
+
target.elseif = from.elseif
|
|
911
|
+
target.else = from.else
|
|
912
|
+
if (isDelete) {
|
|
913
|
+
delete from.for
|
|
914
|
+
delete from.if
|
|
915
|
+
delete from.elseif
|
|
916
|
+
delete from.else
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
910
920
|
function stringify (str) {
|
|
911
921
|
return JSON.stringify(str)
|
|
912
922
|
}
|
|
@@ -1622,7 +1632,9 @@ function processClass (el, meta) {
|
|
|
1622
1632
|
staticClass = staticClass.replace(/\s+/g, ' ')
|
|
1623
1633
|
if (dynamicClass) {
|
|
1624
1634
|
let staticClassExp = parseMustache(staticClass).result
|
|
1625
|
-
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result
|
|
1635
|
+
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
|
|
1636
|
+
error: error$1
|
|
1637
|
+
})
|
|
1626
1638
|
addAttrs(el, [{
|
|
1627
1639
|
name: targetType,
|
|
1628
1640
|
// swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效
|
|
@@ -1714,31 +1726,71 @@ function processAliExternalClassesHack (el, options) {
|
|
|
1714
1726
|
}
|
|
1715
1727
|
}
|
|
1716
1728
|
|
|
1729
|
+
// externalClasses只能模拟静态传递
|
|
1717
1730
|
function processWebExternalClassesHack (el, options) {
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
const externalClasses = []
|
|
1731
|
+
const staticClass = getAndRemoveAttr(el, 'class').val
|
|
1732
|
+
if (staticClass) {
|
|
1733
|
+
const classNames = staticClass.split(/\s+/)
|
|
1734
|
+
const replacements = []
|
|
1723
1735
|
options.externalClasses.forEach((className) => {
|
|
1724
|
-
const
|
|
1725
|
-
if (
|
|
1726
|
-
|
|
1736
|
+
const index = classNames.indexOf(className)
|
|
1737
|
+
if (index > -1) {
|
|
1738
|
+
replacements.push(`$attrs[${JSON.stringify(className)}]`)
|
|
1739
|
+
classNames.splice(index, 1)
|
|
1727
1740
|
}
|
|
1728
1741
|
})
|
|
1729
|
-
|
|
1742
|
+
|
|
1743
|
+
if (classNames.length) {
|
|
1744
|
+
addAttrs(el, [{
|
|
1745
|
+
name: 'class',
|
|
1746
|
+
value: classNames.join(' ')
|
|
1747
|
+
}])
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
if (replacements.length) {
|
|
1751
|
+
const dynamicClass = getAndRemoveAttr(el, ':class').val
|
|
1752
|
+
if (dynamicClass) replacements.push(dynamicClass)
|
|
1753
|
+
|
|
1730
1754
|
addAttrs(el, [{
|
|
1731
|
-
name: '
|
|
1732
|
-
value:
|
|
1755
|
+
name: ':class',
|
|
1756
|
+
value: `[${replacements.join(',')}]`
|
|
1733
1757
|
}])
|
|
1734
1758
|
}
|
|
1735
1759
|
}
|
|
1760
|
+
|
|
1761
|
+
// 处理externalClasses多层透传
|
|
1762
|
+
const isComponent = isComponentNode(el, options)
|
|
1763
|
+
if (isComponent) {
|
|
1764
|
+
options.externalClasses.forEach((classLikeAttrName) => {
|
|
1765
|
+
let classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
|
|
1766
|
+
if (classLikeAttrValue) {
|
|
1767
|
+
const classNames = classLikeAttrValue.split(/\s+/)
|
|
1768
|
+
const replacements = []
|
|
1769
|
+
options.externalClasses.forEach((className) => {
|
|
1770
|
+
const index = classNames.indexOf(className)
|
|
1771
|
+
if (index > -1) {
|
|
1772
|
+
replacements.push(`$attrs[${JSON.stringify(className)}]`)
|
|
1773
|
+
classNames.splice(index, 1)
|
|
1774
|
+
}
|
|
1775
|
+
})
|
|
1776
|
+
|
|
1777
|
+
if (classNames.length) {
|
|
1778
|
+
replacements.unshift(JSON.stringify(classNames.join(' ')))
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
addAttrs(el, [{
|
|
1782
|
+
name: ':' + classLikeAttrName,
|
|
1783
|
+
value: `[${replacements.join(',')}].join(' ')`
|
|
1784
|
+
}])
|
|
1785
|
+
}
|
|
1786
|
+
})
|
|
1787
|
+
}
|
|
1736
1788
|
}
|
|
1737
1789
|
|
|
1738
1790
|
function processScoped (el, options) {
|
|
1739
1791
|
if (options.hasScoped && isRealNode(el)) {
|
|
1740
1792
|
const moduleId = options.moduleId
|
|
1741
|
-
const rootModuleId = options.isComponent ? '' :
|
|
1793
|
+
const rootModuleId = options.isComponent ? '' : MPX_APP_MODULE_ID // 处理app全局样式对页面的影响
|
|
1742
1794
|
const staticClass = getAndRemoveAttr(el, 'class').val
|
|
1743
1795
|
addAttrs(el, [{
|
|
1744
1796
|
name: 'class',
|
|
@@ -1761,39 +1813,79 @@ function processBuiltInComponents (el, meta) {
|
|
|
1761
1813
|
}
|
|
1762
1814
|
}
|
|
1763
1815
|
|
|
1764
|
-
function
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1816
|
+
function processAliEventHack (el, options, root) {
|
|
1817
|
+
// 只处理组件根节点
|
|
1818
|
+
if (!(options.isComponent && el === root && isRealNode(el))) {
|
|
1819
|
+
return
|
|
1820
|
+
}
|
|
1821
|
+
const { proxyComponentEventsRules } = options
|
|
1822
|
+
let fallThroughEvents = ['onTap']
|
|
1823
|
+
// 判断当前文件是否在范围中
|
|
1824
|
+
const filePath = options.filePath
|
|
1825
|
+
for (let item of proxyComponentEventsRules) {
|
|
1826
|
+
const {
|
|
1827
|
+
include,
|
|
1828
|
+
exclude
|
|
1829
|
+
} = item || {}
|
|
1830
|
+
|
|
1831
|
+
if (matchCondition(filePath, {
|
|
1832
|
+
include,
|
|
1833
|
+
exclude
|
|
1834
|
+
})) {
|
|
1835
|
+
const eventsRaw = item.events
|
|
1836
|
+
const events = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
1837
|
+
fallThroughEvents = Array.from(new Set(fallThroughEvents.concat(events)))
|
|
1838
|
+
break
|
|
1776
1839
|
}
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
fallThroughEvents.forEach((type) => {
|
|
1843
|
+
addAttrs(el, [{
|
|
1844
|
+
name: type,
|
|
1845
|
+
value: '__proxyEvent'
|
|
1846
|
+
}])
|
|
1777
1847
|
})
|
|
1778
1848
|
}
|
|
1779
1849
|
|
|
1850
|
+
function processAliStyleClassHack (el, options, root) {
|
|
1851
|
+
// 处理组件根节点
|
|
1852
|
+
if (options.isComponent && el === root && isRealNode(el)) {
|
|
1853
|
+
['style', 'class'].forEach((type) => {
|
|
1854
|
+
let exp = getAndRemoveAttr(el, type).val
|
|
1855
|
+
let typeName = type === 'class' ? 'className' : type
|
|
1856
|
+
let sep = type === 'style' ? ';' : ' '
|
|
1857
|
+
let newValue = exp ? `{{${typeName}||''}}${sep}${exp}` : `{{${typeName}||''}}`
|
|
1858
|
+
|
|
1859
|
+
if (newValue !== undefined) {
|
|
1860
|
+
addAttrs(el, [{
|
|
1861
|
+
name: type,
|
|
1862
|
+
value: newValue
|
|
1863
|
+
}])
|
|
1864
|
+
}
|
|
1865
|
+
})
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1780
1869
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
1781
1870
|
function getVirtualHostRoot (options, meta) {
|
|
1782
|
-
if (
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1871
|
+
if (options.isComponent) {
|
|
1872
|
+
// 处理组件时
|
|
1873
|
+
if (mode === 'wx' && options.hasVirtualHost) {
|
|
1874
|
+
// wx组件注入virtualHost配置
|
|
1875
|
+
!meta.options && (meta.options = {})
|
|
1876
|
+
meta.options.virtualHost = true
|
|
1877
|
+
}
|
|
1878
|
+
if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1879
|
+
// ali组件根节点实体化
|
|
1880
|
+
let rootView = createASTElement('view', [
|
|
1881
|
+
{
|
|
1882
|
+
name: 'class',
|
|
1883
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1884
|
+
}
|
|
1885
|
+
])
|
|
1886
|
+
processElement(rootView, rootView, options, meta)
|
|
1887
|
+
return rootView
|
|
1888
|
+
}
|
|
1797
1889
|
}
|
|
1798
1890
|
return getTempNode()
|
|
1799
1891
|
}
|
|
@@ -1801,7 +1893,10 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1801
1893
|
function processShow (el, options, root) {
|
|
1802
1894
|
let show = getAndRemoveAttr(el, config[mode].directive.show).val
|
|
1803
1895
|
if (mode === 'swan') show = wrapMustache(show)
|
|
1804
|
-
|
|
1896
|
+
let processFlag = el.parent === root
|
|
1897
|
+
// 当ali且未开启virtualHost时,mpxShow打到根节点上
|
|
1898
|
+
if (mode === 'ali' && !options.hasVirtualHost) processFlag = el === root
|
|
1899
|
+
if (options.isComponent && processFlag && isRealNode(el)) {
|
|
1805
1900
|
if (show !== undefined) {
|
|
1806
1901
|
show = `{{${parseMustache(show).result}&&mpxShow}}`
|
|
1807
1902
|
} else {
|
|
@@ -1977,10 +2072,22 @@ function processElement (el, root, options, meta) {
|
|
|
1977
2072
|
processComponentGenericsForWeb(el, options, meta)
|
|
1978
2073
|
return
|
|
1979
2074
|
}
|
|
2075
|
+
if (mode === 'tenon') {
|
|
2076
|
+
// 收集内建组件
|
|
2077
|
+
processBuiltInComponents(el, meta)
|
|
2078
|
+
// 预处理代码维度条件编译
|
|
2079
|
+
processIfForWeb(el)
|
|
2080
|
+
// processWebExternalClassesHack(el, options)
|
|
2081
|
+
// processComponentGenericsForWeb(el, options, meta)
|
|
2082
|
+
return
|
|
2083
|
+
}
|
|
1980
2084
|
|
|
1981
2085
|
const pass = isNative || processTemplate(el) || processingTemplate
|
|
1982
2086
|
|
|
1983
|
-
|
|
2087
|
+
// 仅ali平台需要scoped模拟样式隔离
|
|
2088
|
+
if (mode === 'ali') {
|
|
2089
|
+
processScoped(el, options)
|
|
2090
|
+
}
|
|
1984
2091
|
|
|
1985
2092
|
if (transAli) {
|
|
1986
2093
|
processAliExternalClassesHack(el, options)
|
|
@@ -1996,9 +2103,9 @@ function processElement (el, root, options, meta) {
|
|
|
1996
2103
|
processShow(el, options, root)
|
|
1997
2104
|
}
|
|
1998
2105
|
|
|
1999
|
-
|
|
2000
|
-
if (mode === 'ali') {
|
|
2106
|
+
if (transAli) {
|
|
2001
2107
|
processAliStyleClassHack(el, options, root)
|
|
2108
|
+
processAliEventHack(el, options, root)
|
|
2002
2109
|
}
|
|
2003
2110
|
|
|
2004
2111
|
if (!pass) {
|
|
@@ -2011,7 +2118,7 @@ function processElement (el, root, options, meta) {
|
|
|
2011
2118
|
|
|
2012
2119
|
function closeElement (el, meta) {
|
|
2013
2120
|
postProcessAtMode(el)
|
|
2014
|
-
if (mode === 'web') {
|
|
2121
|
+
if (mode === 'web' || mode === 'tenon') {
|
|
2015
2122
|
postProcessWxs(el, meta)
|
|
2016
2123
|
// 处理代码维度条件编译移除死分支
|
|
2017
2124
|
postProcessIf(el)
|
|
@@ -2059,14 +2166,16 @@ function postProcessComponentIs (el) {
|
|
|
2059
2166
|
let tempNode
|
|
2060
2167
|
if (el.for || el.if || el.elseif || el.else) {
|
|
2061
2168
|
tempNode = createASTElement('block', [])
|
|
2062
|
-
tempNode
|
|
2063
|
-
tempNode.if = el.if
|
|
2064
|
-
tempNode.elseif = el.elseif
|
|
2065
|
-
tempNode.else = el.else
|
|
2169
|
+
moveBaseDirective(tempNode, el)
|
|
2066
2170
|
} else {
|
|
2067
2171
|
tempNode = getTempNode()
|
|
2068
2172
|
}
|
|
2173
|
+
let range = []
|
|
2174
|
+
if (el.attrsMap.range) {
|
|
2175
|
+
range = getAndRemoveAttr(el, 'range').val.split(',')
|
|
2176
|
+
}
|
|
2069
2177
|
el.components.forEach(function (component) {
|
|
2178
|
+
if (range.length > 0 && !range.includes(component)) return
|
|
2070
2179
|
let newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
|
|
2071
2180
|
newChild.if = {
|
|
2072
2181
|
raw: `{{${el.is} === ${stringify(component)}}}`,
|
|
@@ -2083,7 +2192,7 @@ function postProcessComponentIs (el) {
|
|
|
2083
2192
|
if (!el.parent) {
|
|
2084
2193
|
error$1('Dynamic component can not be the template root, considering wrapping it with <view> or <text> tag!')
|
|
2085
2194
|
} else {
|
|
2086
|
-
el = replaceNode(el, tempNode) || el
|
|
2195
|
+
el = replaceNode(el, tempNode, true) || el
|
|
2087
2196
|
}
|
|
2088
2197
|
}
|
|
2089
2198
|
return el
|
|
@@ -2118,7 +2227,7 @@ function serialize (root) {
|
|
|
2118
2227
|
result += node.text
|
|
2119
2228
|
}
|
|
2120
2229
|
}
|
|
2121
|
-
if (node.tag === 'wxs' && mode === 'web') {
|
|
2230
|
+
if (node.tag === 'wxs' && (mode === 'web' || mode === 'tenon')) {
|
|
2122
2231
|
return result
|
|
2123
2232
|
}
|
|
2124
2233
|
if (node.type === 1) {
|
|
@@ -2283,5 +2392,6 @@ module.exports = {
|
|
|
2283
2392
|
makeAttrsMap,
|
|
2284
2393
|
stringifyAttr,
|
|
2285
2394
|
parseMustache,
|
|
2286
|
-
stringifyWithResolveComputed
|
|
2395
|
+
stringifyWithResolveComputed,
|
|
2396
|
+
addAttrs
|
|
2287
2397
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const compiler = require('./compiler')
|
|
2
2
|
const bindThis = require('./bind-this').transform
|
|
3
3
|
const parseRequest = require('../utils/parse-request')
|
|
4
|
-
const matchCondition = require('../utils/match-condition')
|
|
4
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
5
5
|
const loaderUtils = require('loader-utils')
|
|
6
6
|
|
|
7
7
|
module.exports = function (raw) {
|
|
@@ -24,7 +24,7 @@ module.exports = function (raw) {
|
|
|
24
24
|
const hasComment = queryObj.hasComment
|
|
25
25
|
const isNative = queryObj.isNative
|
|
26
26
|
const hasScoped = queryObj.hasScoped
|
|
27
|
-
const moduleId = queryObj.moduleId
|
|
27
|
+
const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
|
|
28
28
|
|
|
29
29
|
const warn = (msg) => {
|
|
30
30
|
this.emitWarning(
|
|
@@ -38,7 +38,7 @@ module.exports = function (raw) {
|
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const { root: ast, meta } = compiler.parse(raw, {
|
|
42
42
|
warn,
|
|
43
43
|
error,
|
|
44
44
|
usingComponents,
|
|
@@ -53,17 +53,16 @@ module.exports = function (raw) {
|
|
|
53
53
|
externalClasses,
|
|
54
54
|
hasScoped,
|
|
55
55
|
moduleId,
|
|
56
|
-
|
|
56
|
+
// 这里需传递resourcePath和wxsContentMap保持一致
|
|
57
|
+
filePath: resourcePath,
|
|
57
58
|
i18n,
|
|
58
59
|
checkUsingComponents: mpx.checkUsingComponents,
|
|
59
60
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
60
|
-
forceProxyEvent: matchCondition(
|
|
61
|
-
hasVirtualHost: matchCondition(
|
|
61
|
+
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
|
|
62
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
|
|
63
|
+
proxyComponentEventsRules: mpx.proxyComponentEventsRules
|
|
62
64
|
})
|
|
63
65
|
|
|
64
|
-
let ast = parsed.root
|
|
65
|
-
let meta = parsed.meta
|
|
66
|
-
|
|
67
66
|
if (meta.wxsContentMap) {
|
|
68
67
|
for (let module in meta.wxsContentMap) {
|
|
69
68
|
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
const babylon = require('
|
|
2
|
-
const t = require('babel
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
const babylon = require('@babel/parser')
|
|
2
|
+
const t = require('@babel/types')
|
|
3
|
+
const traverse = require('@babel/traverse').default
|
|
4
|
+
const generate = require('@babel/generator').default
|
|
5
5
|
|
|
6
|
-
module.exports = function transDynamicClassExpr (expr) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
7
|
+
try {
|
|
8
|
+
const ast = babylon.parse(expr, {
|
|
9
|
+
plugins: [
|
|
10
|
+
'objectRestSpread'
|
|
11
|
+
]
|
|
12
|
+
})
|
|
13
|
+
traverse(ast, {
|
|
14
|
+
ObjectExpression (path) {
|
|
15
|
+
path.node.properties.forEach((property) => {
|
|
16
|
+
if (t.isObjectProperty(property) && !property.computed) {
|
|
17
|
+
const propertyName = property.key.name || property.key.value
|
|
18
|
+
if (/-/.test(propertyName)) {
|
|
19
|
+
if (/\$/.test(propertyName)) {
|
|
20
|
+
error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
21
|
+
} else {
|
|
22
|
+
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
property.key = t.identifier(propertyName)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
21
29
|
}
|
|
22
30
|
})
|
|
31
|
+
return generate(ast.program.body[0].expression, {
|
|
32
|
+
compact: true
|
|
33
|
+
}).code
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return expr
|
|
23
36
|
}
|
|
24
|
-
return generate(expr, {
|
|
25
|
-
compact: true
|
|
26
|
-
}).code
|
|
27
37
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const processJSON = require('./processJSON')
|
|
2
|
+
const processScript = require('./processScript')
|
|
3
|
+
const processStyles = require('./processStyles')
|
|
4
|
+
const processTemplate = require('./processTemplate')
|
|
5
|
+
|
|
6
|
+
const async = require('async')
|
|
7
|
+
|
|
8
|
+
module.exports = function ({
|
|
9
|
+
mpx,
|
|
10
|
+
loaderContext,
|
|
11
|
+
isProduction,
|
|
12
|
+
parts,
|
|
13
|
+
ctorType,
|
|
14
|
+
filePath,
|
|
15
|
+
queryObj,
|
|
16
|
+
autoScope,
|
|
17
|
+
componentsMap,
|
|
18
|
+
vueContentCache,
|
|
19
|
+
moduleId,
|
|
20
|
+
callback
|
|
21
|
+
}) {
|
|
22
|
+
const hasComment = parts.template && parts.template.attrs && parts.template.attrs.comments
|
|
23
|
+
const isNative = false
|
|
24
|
+
const mode = mpx.mode
|
|
25
|
+
const srcMode = mpx.srcMode
|
|
26
|
+
const env = mpx.env
|
|
27
|
+
const defs = mpx.defs
|
|
28
|
+
const resolveMode = mpx.resolveMode
|
|
29
|
+
const pagesMap = mpx.pagesMap
|
|
30
|
+
const projectRoot = mpx.projectRoot
|
|
31
|
+
|
|
32
|
+
let output = ''
|
|
33
|
+
let usingComponents = [].concat(Object.keys(mpx.usingComponents))
|
|
34
|
+
|
|
35
|
+
return async.waterfall([
|
|
36
|
+
(callback) => {
|
|
37
|
+
async.parallel([
|
|
38
|
+
(callback) => {
|
|
39
|
+
processTemplate(parts.template, {
|
|
40
|
+
hasComment,
|
|
41
|
+
isNative,
|
|
42
|
+
mode,
|
|
43
|
+
srcMode,
|
|
44
|
+
defs,
|
|
45
|
+
loaderContext,
|
|
46
|
+
moduleId,
|
|
47
|
+
ctorType,
|
|
48
|
+
usingComponents,
|
|
49
|
+
decodeHTMLText: mpx.decodeHTMLText,
|
|
50
|
+
externalClasses: mpx.externalClasses,
|
|
51
|
+
checkUsingComponents: mpx.checkUsingComponents
|
|
52
|
+
}, callback)
|
|
53
|
+
},
|
|
54
|
+
(callback) => {
|
|
55
|
+
processStyles(parts.styles, {
|
|
56
|
+
ctorType,
|
|
57
|
+
autoScope
|
|
58
|
+
}, callback)
|
|
59
|
+
},
|
|
60
|
+
(callback) => {
|
|
61
|
+
processJSON(parts.json, {
|
|
62
|
+
mode,
|
|
63
|
+
env,
|
|
64
|
+
defs,
|
|
65
|
+
resolveMode,
|
|
66
|
+
loaderContext,
|
|
67
|
+
pagesMap,
|
|
68
|
+
pathHash: mpx.pathHash,
|
|
69
|
+
componentsMap,
|
|
70
|
+
projectRoot
|
|
71
|
+
}, callback)
|
|
72
|
+
}
|
|
73
|
+
], (err, res) => {
|
|
74
|
+
callback(err, res)
|
|
75
|
+
})
|
|
76
|
+
},
|
|
77
|
+
([templateRes, stylesRes, jsonRes], callback) => {
|
|
78
|
+
output += templateRes.output
|
|
79
|
+
output += stylesRes.output
|
|
80
|
+
output += jsonRes.output
|
|
81
|
+
if (ctorType === 'app' && jsonRes.jsonObj.window && jsonRes.jsonObj.window.navigationBarTitleText) {
|
|
82
|
+
mpx.appTitle = jsonRes.jsonObj.window.navigationBarTitleText
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
processScript(parts.script, {
|
|
86
|
+
ctorType,
|
|
87
|
+
srcMode,
|
|
88
|
+
loaderContext,
|
|
89
|
+
isProduction,
|
|
90
|
+
projectRoot,
|
|
91
|
+
jsonConfig: jsonRes.jsonObj,
|
|
92
|
+
componentId: queryObj.componentId || '',
|
|
93
|
+
builtInComponentsMap: templateRes.builtInComponentsMap,
|
|
94
|
+
localComponentsMap: jsonRes.localComponentsMap,
|
|
95
|
+
localPagesMap: jsonRes.localPagesMap,
|
|
96
|
+
forceDisableBuiltInLoader: mpx.forceDisableBuiltInLoader
|
|
97
|
+
}, callback)
|
|
98
|
+
}
|
|
99
|
+
], (err, scriptRes) => {
|
|
100
|
+
if (err) return callback(err)
|
|
101
|
+
output += scriptRes.output
|
|
102
|
+
vueContentCache.set(filePath, output)
|
|
103
|
+
callback(null, output)
|
|
104
|
+
})
|
|
105
|
+
}
|