vue 2.6.13 → 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.
Files changed (262) hide show
  1. package/README.md +17 -295
  2. package/compiler-sfc/index.d.ts +1 -0
  3. package/compiler-sfc/index.js +1 -0
  4. package/compiler-sfc/index.mjs +1 -0
  5. package/compiler-sfc/package.json +5 -0
  6. package/dist/vue.common.dev.js +11481 -11946
  7. package/dist/vue.common.prod.js +8 -3
  8. package/dist/vue.esm.browser.js +11321 -12011
  9. package/dist/vue.esm.browser.min.js +8 -3
  10. package/dist/vue.esm.js +11476 -11984
  11. package/dist/vue.js +11484 -11949
  12. package/dist/vue.min.js +8 -3
  13. package/dist/vue.runtime.common.dev.js +8427 -8421
  14. package/dist/vue.runtime.common.prod.js +8 -3
  15. package/dist/vue.runtime.esm.js +8436 -8454
  16. package/dist/vue.runtime.js +8430 -8424
  17. package/dist/vue.runtime.min.js +8 -3
  18. package/package.json +88 -111
  19. package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
  20. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  21. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  22. package/packages/compiler-sfc/package.json +30 -0
  23. package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
  24. package/src/compiler/codegen/{events.js → events.ts} +21 -41
  25. package/src/compiler/codegen/{index.js → index.ts} +146 -136
  26. package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
  27. package/src/compiler/directives/bind.ts +9 -0
  28. package/src/compiler/directives/{index.js → index.ts} +0 -2
  29. package/src/compiler/directives/{model.js → model.ts} +15 -18
  30. package/src/compiler/directives/{on.js → on.ts} +3 -4
  31. package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
  32. package/src/compiler/{helpers.js → helpers.ts} +73 -61
  33. package/src/compiler/{index.js → index.ts} +2 -3
  34. package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
  35. package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
  36. package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
  37. package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
  38. package/src/compiler/parser/{index.js → index.ts} +190 -172
  39. package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
  40. package/src/compiler/{to-function.js → to-function.ts} +27 -22
  41. package/src/core/components/{index.js → index.ts} +0 -0
  42. package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
  43. package/src/core/{config.js → config.ts} +28 -30
  44. package/src/core/global-api/{assets.js → assets.ts} +8 -7
  45. package/src/core/global-api/{extend.js → extend.ts} +10 -13
  46. package/src/core/global-api/{index.js → index.ts} +4 -5
  47. package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
  48. package/src/core/global-api/use.ts +23 -0
  49. package/src/core/{index.js → index.ts} +1 -1
  50. package/src/core/instance/{events.js → events.ts} +41 -24
  51. package/src/core/instance/{index.js → index.ts} +9 -5
  52. package/src/core/instance/{init.js → init.ts} +26 -15
  53. package/src/core/instance/inject.ts +72 -0
  54. package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
  55. package/src/core/instance/{proxy.js → proxy.ts} +29 -24
  56. package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
  57. package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
  58. package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
  59. package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
  60. package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
  61. package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
  62. package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
  63. package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
  64. package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
  65. package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
  66. package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
  67. package/src/core/instance/{render.js → render.ts} +66 -29
  68. package/src/core/instance/{state.js → state.ts} +100 -83
  69. package/src/core/observer/{array.js → array.ts} +11 -2
  70. package/src/core/observer/{dep.js → dep.ts} +37 -15
  71. package/src/core/observer/{index.js → index.ts} +137 -71
  72. package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
  73. package/src/core/observer/{traverse.js → traverse.ts} +10 -7
  74. package/src/core/observer/{watcher.js → watcher.ts} +88 -60
  75. package/src/core/util/{debug.js → debug.ts} +38 -34
  76. package/src/core/util/{env.js → env.ts} +27 -30
  77. package/src/core/util/{error.js → error.ts} +12 -14
  78. package/src/core/util/{index.js → index.ts} +0 -2
  79. package/src/core/util/{lang.js → lang.ts} +6 -7
  80. package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
  81. package/src/core/util/{options.js → options.ts} +119 -114
  82. package/src/core/util/{perf.js → perf.ts} +5 -1
  83. package/src/core/util/{props.js → props.ts} +54 -50
  84. package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
  85. package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
  86. package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
  87. package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
  88. package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
  89. package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
  90. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  91. package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
  92. package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
  93. package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
  94. package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
  95. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  96. package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
  97. package/src/core/vdom/modules/index.ts +4 -0
  98. package/src/core/vdom/modules/template-ref.ts +96 -0
  99. package/src/core/vdom/{patch.js → patch.ts} +239 -138
  100. package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
  101. package/src/global.d.ts +15 -0
  102. package/src/platforms/web/compiler/directives/html.ts +8 -0
  103. package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
  104. package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
  105. package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
  106. package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
  107. package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
  108. package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
  109. package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
  110. package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
  111. package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
  112. package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
  113. package/src/platforms/web/entry-compiler-sfc.ts +1 -0
  114. package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
  115. package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
  116. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  117. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  118. package/src/platforms/web/entry-runtime.ts +7 -0
  119. package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
  120. package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
  121. package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
  122. package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
  123. package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
  124. package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
  125. package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
  126. package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
  127. package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
  128. package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
  129. package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
  130. package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
  131. package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
  132. package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
  133. package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
  134. package/src/platforms/web/runtime/node-ops.ts +66 -0
  135. package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
  136. package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
  137. package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
  138. package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
  139. package/src/platforms/web/util/{class.js → class.ts} +23 -21
  140. package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
  141. package/src/platforms/web/util/{element.js → element.ts} +21 -22
  142. package/src/platforms/web/util/{index.js → index.ts} +2 -6
  143. package/src/platforms/web/util/{style.js → style.ts} +12 -12
  144. package/src/sfc/{parser.js → parser.ts} +18 -15
  145. package/src/shared/{constants.js → constants.ts} +2 -6
  146. package/src/shared/{util.js → util.ts} +78 -55
  147. package/src/types/compiler.ts +224 -0
  148. package/src/types/component.ts +209 -0
  149. package/src/types/global-api.ts +37 -0
  150. package/src/types/modules.d.ts +15 -0
  151. package/src/types/options.ts +120 -0
  152. package/src/types/ssr.ts +27 -0
  153. package/src/types/utils.ts +3 -0
  154. package/src/types/vnode.ts +127 -0
  155. package/src/v3/apiInject.ts +66 -0
  156. package/src/v3/apiLifecycle.ts +53 -0
  157. package/src/v3/apiSetup.ts +161 -0
  158. package/src/v3/apiWatch.ts +355 -0
  159. package/src/v3/currentInstance.ts +23 -0
  160. package/src/v3/debug.ts +21 -0
  161. package/src/v3/h.ts +18 -0
  162. package/src/v3/index.ts +77 -0
  163. package/src/v3/reactivity/computed.ts +100 -0
  164. package/src/v3/reactivity/effect.ts +20 -0
  165. package/src/v3/reactivity/effectScope.ts +134 -0
  166. package/src/v3/reactivity/operations.ts +14 -0
  167. package/src/v3/reactivity/reactive.ts +123 -0
  168. package/src/v3/reactivity/readonly.ts +121 -0
  169. package/src/v3/reactivity/ref.ts +249 -0
  170. package/types/index.d.ts +10 -13
  171. package/types/options.d.ts +265 -132
  172. package/types/plugin.d.ts +4 -4
  173. package/types/umd.d.ts +47 -27
  174. package/types/v3-generated.d.ts +389 -0
  175. package/types/v3.d.ts +16 -0
  176. package/types/vnode.d.ts +70 -57
  177. package/types/vue.d.ts +292 -88
  178. package/dist/README.md +0 -122
  179. package/src/compiler/directives/bind.js +0 -11
  180. package/src/core/global-api/use.js +0 -23
  181. package/src/core/instance/inject.js +0 -73
  182. package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
  183. package/src/core/vdom/helpers/update-listeners.js +0 -95
  184. package/src/core/vdom/modules/index.js +0 -7
  185. package/src/core/vdom/modules/ref.js +0 -45
  186. package/src/platforms/web/compiler/directives/html.js +0 -9
  187. package/src/platforms/web/entry-server-basic-renderer.js +0 -13
  188. package/src/platforms/web/entry-server-renderer.js +0 -27
  189. package/src/platforms/web/runtime/node-ops.js +0 -59
  190. package/src/platforms/web/server/compiler.js +0 -11
  191. package/src/platforms/web/server/directives/index.js +0 -7
  192. package/src/platforms/web/server/directives/model.js +0 -44
  193. package/src/platforms/web/server/directives/show.js +0 -12
  194. package/src/platforms/web/server/modules/attrs.js +0 -67
  195. package/src/platforms/web/server/modules/class.js +0 -11
  196. package/src/platforms/web/server/modules/dom-props.js +0 -50
  197. package/src/platforms/web/server/modules/index.js +0 -11
  198. package/src/platforms/web/server/modules/style.js +0 -41
  199. package/src/platforms/web/server/util.js +0 -101
  200. package/src/platforms/weex/compiler/directives/index.js +0 -5
  201. package/src/platforms/weex/compiler/directives/model.js +0 -33
  202. package/src/platforms/weex/compiler/index.js +0 -52
  203. package/src/platforms/weex/compiler/modules/append.js +0 -27
  204. package/src/platforms/weex/compiler/modules/class.js +0 -74
  205. package/src/platforms/weex/compiler/modules/index.js +0 -13
  206. package/src/platforms/weex/compiler/modules/props.js +0 -37
  207. package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
  208. package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
  209. package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
  210. package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
  211. package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
  212. package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
  213. package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
  214. package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
  215. package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
  216. package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
  217. package/src/platforms/weex/compiler/modules/style.js +0 -87
  218. package/src/platforms/weex/entry-compiler.js +0 -2
  219. package/src/platforms/weex/entry-framework.js +0 -187
  220. package/src/platforms/weex/entry-runtime-factory.js +0 -6
  221. package/src/platforms/weex/runtime/components/index.js +0 -9
  222. package/src/platforms/weex/runtime/components/richtext.js +0 -82
  223. package/src/platforms/weex/runtime/components/transition-group.js +0 -148
  224. package/src/platforms/weex/runtime/components/transition.js +0 -9
  225. package/src/platforms/weex/runtime/directives/index.js +0 -2
  226. package/src/platforms/weex/runtime/index.js +0 -42
  227. package/src/platforms/weex/runtime/modules/attrs.js +0 -44
  228. package/src/platforms/weex/runtime/modules/class.js +0 -76
  229. package/src/platforms/weex/runtime/modules/events.js +0 -54
  230. package/src/platforms/weex/runtime/modules/index.js +0 -13
  231. package/src/platforms/weex/runtime/modules/style.js +0 -84
  232. package/src/platforms/weex/runtime/modules/transition.js +0 -270
  233. package/src/platforms/weex/runtime/node-ops.js +0 -91
  234. package/src/platforms/weex/runtime/patch.js +0 -16
  235. package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
  236. package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
  237. package/src/platforms/weex/runtime/text-node.js +0 -9
  238. package/src/platforms/weex/util/element.js +0 -52
  239. package/src/platforms/weex/util/index.js +0 -40
  240. package/src/platforms/weex/util/parser.js +0 -60
  241. package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
  242. package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
  243. package/src/server/bundle-renderer/source-map-support.js +0 -45
  244. package/src/server/create-basic-renderer.js +0 -37
  245. package/src/server/create-renderer.js +0 -152
  246. package/src/server/optimizing-compiler/codegen.js +0 -264
  247. package/src/server/optimizing-compiler/index.js +0 -20
  248. package/src/server/optimizing-compiler/modules.js +0 -124
  249. package/src/server/optimizing-compiler/optimizer.js +0 -141
  250. package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
  251. package/src/server/render-context.js +0 -130
  252. package/src/server/render-stream.js +0 -95
  253. package/src/server/render.js +0 -437
  254. package/src/server/template-renderer/create-async-file-mapper.js +0 -57
  255. package/src/server/template-renderer/index.js +0 -277
  256. package/src/server/template-renderer/parse-template.js +0 -42
  257. package/src/server/template-renderer/template-stream.js +0 -82
  258. package/src/server/util.js +0 -18
  259. package/src/server/webpack-plugin/client.js +0 -65
  260. package/src/server/webpack-plugin/server.js +0 -66
  261. package/src/server/webpack-plugin/util.js +0 -34
  262. package/src/server/write.js +0 -50
@@ -1,52 +0,0 @@
1
- /* @flow */
2
-
3
- import { genStaticKeys } from 'shared/util'
4
- import { createCompiler } from 'compiler/index'
5
-
6
- import modules from './modules/index'
7
- import directives from './directives/index'
8
-
9
- import {
10
- isUnaryTag,
11
- mustUseProp,
12
- isReservedTag,
13
- canBeLeftOpenTag,
14
- getTagNamespace
15
- } from '../util/element'
16
-
17
- export const baseOptions: WeexCompilerOptions = {
18
- modules,
19
- directives,
20
- isUnaryTag,
21
- mustUseProp,
22
- canBeLeftOpenTag,
23
- isReservedTag,
24
- getTagNamespace,
25
- preserveWhitespace: false,
26
- recyclable: false,
27
- staticKeys: genStaticKeys(modules)
28
- }
29
-
30
- const compiler = createCompiler(baseOptions)
31
-
32
- export function compile (
33
- template: string,
34
- options?: WeexCompilerOptions
35
- ): WeexCompiledResult {
36
- let generateAltRender = false
37
- if (options && options.recyclable === true) {
38
- generateAltRender = true
39
- options.recyclable = false
40
- }
41
- const result = compiler.compile(template, options)
42
-
43
- // generate @render function for <recycle-list>
44
- if (options && generateAltRender) {
45
- options.recyclable = true
46
- // disable static optimizations
47
- options.optimize = false
48
- const { render } = compiler.compile(template, options)
49
- result['@render'] = render
50
- }
51
- return result
52
- }
@@ -1,27 +0,0 @@
1
- /* @flow */
2
-
3
- import { makeMap } from 'shared/util'
4
-
5
- // The "unitary tag" means that the tag node and its children
6
- // must be sent to the native together.
7
- const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true)
8
-
9
- function preTransformNode (el: ASTElement) {
10
- if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) {
11
- el.attrsMap.append = 'tree'
12
- el.attrsList.push({ name: 'append', value: 'tree' })
13
- }
14
- if (el.attrsMap.append === 'tree') {
15
- el.appendAsTree = true
16
- }
17
- }
18
-
19
- function genData (el: ASTElement): string {
20
- return el.appendAsTree ? `appendAsTree:true,` : ''
21
- }
22
-
23
- export default {
24
- staticKeys: ['appendAsTree'],
25
- preTransformNode,
26
- genData
27
- }
@@ -1,74 +0,0 @@
1
- /* @flow */
2
-
3
- import { parseText } from 'compiler/parser/text-parser'
4
- import {
5
- getAndRemoveAttr,
6
- getBindingAttr,
7
- baseWarn
8
- } from 'compiler/helpers'
9
-
10
- type StaticClassResult = {
11
- dynamic: boolean,
12
- classResult: string
13
- };
14
-
15
- function transformNode (el: ASTElement, options: CompilerOptions) {
16
- const warn = options.warn || baseWarn
17
- const staticClass = getAndRemoveAttr(el, 'class')
18
- const { dynamic, classResult } = parseStaticClass(staticClass, options)
19
- if (process.env.NODE_ENV !== 'production' && dynamic && staticClass) {
20
- warn(
21
- `class="${staticClass}": ` +
22
- 'Interpolation inside attributes has been deprecated. ' +
23
- 'Use v-bind or the colon shorthand instead.',
24
- el.rawAttrsMap['class']
25
- )
26
- }
27
- if (!dynamic && classResult) {
28
- el.staticClass = classResult
29
- }
30
- const classBinding = getBindingAttr(el, 'class', false /* getStatic */)
31
- if (classBinding) {
32
- el.classBinding = classBinding
33
- } else if (dynamic) {
34
- el.classBinding = classResult
35
- }
36
- }
37
-
38
- function genData (el: ASTElement): string {
39
- let data = ''
40
- if (el.staticClass) {
41
- data += `staticClass:${el.staticClass},`
42
- }
43
- if (el.classBinding) {
44
- data += `class:${el.classBinding},`
45
- }
46
- return data
47
- }
48
-
49
- function parseStaticClass (staticClass: ?string, options: CompilerOptions): StaticClassResult {
50
- // "a b c" -> ["a", "b", "c"] => staticClass: ["a", "b", "c"]
51
- // "a {{x}} c" -> ["a", x, "c"] => classBinding: '["a", x, "c"]'
52
- let dynamic = false
53
- let classResult = ''
54
- if (staticClass) {
55
- const classList = staticClass.trim().split(' ').map(name => {
56
- const result = parseText(name, options.delimiters)
57
- if (result) {
58
- dynamic = true
59
- return result.expression
60
- }
61
- return JSON.stringify(name)
62
- })
63
- if (classList.length) {
64
- classResult = '[' + classList.join(',') + ']'
65
- }
66
- }
67
- return { dynamic, classResult }
68
- }
69
-
70
- export default {
71
- staticKeys: ['staticClass'],
72
- transformNode,
73
- genData
74
- }
@@ -1,13 +0,0 @@
1
- import klass from './class'
2
- import style from './style'
3
- import props from './props'
4
- import append from './append'
5
- import recycleList from './recycle-list/index'
6
-
7
- export default [
8
- recycleList,
9
- klass,
10
- style,
11
- props,
12
- append
13
- ]
@@ -1,37 +0,0 @@
1
- /* @flow */
2
-
3
- import { cached, camelize } from 'shared/util'
4
-
5
- const normalize = cached(camelize)
6
-
7
- function normalizeKeyName (str: string): string {
8
- if (str.match(/^v\-/)) {
9
- return str.replace(/(v-[a-z\-]+\:)([a-z\-]+)$/i, ($, directive, prop) => {
10
- return directive + normalize(prop)
11
- })
12
- }
13
- return normalize(str)
14
- }
15
-
16
- function transformNode (el: ASTElement) {
17
- if (Array.isArray(el.attrsList)) {
18
- el.attrsList.forEach(attr => {
19
- if (attr.name && attr.name.match(/\-/)) {
20
- const realName = normalizeKeyName(attr.name)
21
- if (el.attrsMap) {
22
- el.attrsMap[realName] = el.attrsMap[attr.name]
23
- delete el.attrsMap[attr.name]
24
- }
25
- if (el.rawAttrsMap && el.rawAttrsMap[attr.name]) {
26
- el.rawAttrsMap[realName] = el.rawAttrsMap[attr.name]
27
- // $flow-disable-line
28
- delete el.rawAttrsMap[attr.name]
29
- }
30
- attr.name = realName
31
- }
32
- })
33
- }
34
- }
35
- export default {
36
- transformNode
37
- }
@@ -1,13 +0,0 @@
1
- /* @flow */
2
-
3
- import { addAttr } from 'compiler/helpers'
4
-
5
- // mark component root nodes as
6
- export function postTransformComponentRoot (el: ASTElement) {
7
- if (!el.parent) {
8
- // component root
9
- addAttr(el, '@isComponentRoot', 'true')
10
- addAttr(el, '@templateId', '_uid')
11
- addAttr(el, '@componentProps', '$props || {}')
12
- }
13
- }
@@ -1,16 +0,0 @@
1
- /* @flow */
2
-
3
- import { addAttr } from 'compiler/helpers'
4
- import { RECYCLE_LIST_MARKER } from 'weex/util/index'
5
-
6
- // mark components as inside recycle-list so that we know we need to invoke
7
- // their special @render function instead of render in create-component.js
8
- export function postTransformComponent (
9
- el: ASTElement,
10
- options: WeexCompilerOptions
11
- ) {
12
- // $flow-disable-line (we know isReservedTag is there)
13
- if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') {
14
- addAttr(el, RECYCLE_LIST_MARKER, 'true')
15
- }
16
- }
@@ -1,60 +0,0 @@
1
- /* @flow */
2
-
3
- import { preTransformRecycleList } from './recycle-list'
4
- import { postTransformComponent } from './component'
5
- import { postTransformComponentRoot } from './component-root'
6
- import { postTransformText } from './text'
7
- import { preTransformVBind } from './v-bind'
8
- import { preTransformVIf } from './v-if'
9
- import { preTransformVFor } from './v-for'
10
- import { postTransformVOn } from './v-on'
11
- import { preTransformVOnce } from './v-once'
12
-
13
- let currentRecycleList = null
14
-
15
- function shouldCompile (el: ASTElement, options: WeexCompilerOptions) {
16
- return options.recyclable ||
17
- (currentRecycleList && el !== currentRecycleList)
18
- }
19
-
20
- function preTransformNode (el: ASTElement, options: WeexCompilerOptions) {
21
- if (el.tag === 'recycle-list') {
22
- preTransformRecycleList(el, options)
23
- currentRecycleList = el
24
- }
25
- if (shouldCompile(el, options)) {
26
- preTransformVBind(el)
27
- preTransformVIf(el, options) // also v-else-if and v-else
28
- preTransformVFor(el, options)
29
- preTransformVOnce(el)
30
- }
31
- }
32
-
33
- function transformNode (el: ASTElement, options: WeexCompilerOptions) {
34
- if (shouldCompile(el, options)) {
35
- // do nothing yet
36
- }
37
- }
38
-
39
- function postTransformNode (el: ASTElement, options: WeexCompilerOptions) {
40
- if (shouldCompile(el, options)) {
41
- // mark child component in parent template
42
- postTransformComponent(el, options)
43
- // mark root in child component template
44
- postTransformComponentRoot(el)
45
- // <text>: transform children text into value attr
46
- if (el.tag === 'text') {
47
- postTransformText(el)
48
- }
49
- postTransformVOn(el)
50
- }
51
- if (el === currentRecycleList) {
52
- currentRecycleList = null
53
- }
54
- }
55
-
56
- export default {
57
- preTransformNode,
58
- transformNode,
59
- postTransformNode
60
- }
@@ -1,50 +0,0 @@
1
- /* @flow */
2
-
3
- import { parseFor } from 'compiler/parser/index'
4
- import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
5
-
6
- /**
7
- * Map the following syntax to corresponding attrs:
8
- *
9
- * <recycle-list for="(item, i) in longList" switch="cellType">
10
- * <cell-slot case="A"> ... </cell-slot>
11
- * <cell-slot case="B"> ... </cell-slot>
12
- * </recycle-list>
13
- */
14
-
15
- export function preTransformRecycleList (
16
- el: ASTElement,
17
- options: WeexCompilerOptions
18
- ) {
19
- const exp = getAndRemoveAttr(el, 'for')
20
- if (!exp) {
21
- if (options.warn) {
22
- options.warn(`Invalid <recycle-list> syntax: missing "for" expression.`)
23
- }
24
- return
25
- }
26
-
27
- const res = parseFor(exp)
28
- if (!res) {
29
- if (options.warn) {
30
- options.warn(`Invalid <recycle-list> syntax: ${exp}.`)
31
- }
32
- return
33
- }
34
-
35
- addRawAttr(el, ':list-data', res.for)
36
- addRawAttr(el, 'binding-expression', res.for)
37
- addRawAttr(el, 'alias', res.alias)
38
- if (res.iterator2) {
39
- // (item, key, index) for object iteration
40
- // is this even supported?
41
- addRawAttr(el, 'index', res.iterator2)
42
- } else if (res.iterator1) {
43
- addRawAttr(el, 'index', res.iterator1)
44
- }
45
-
46
- const switchKey = getAndRemoveAttr(el, 'switch')
47
- if (switchKey) {
48
- addRawAttr(el, 'switch', switchKey)
49
- }
50
- }
@@ -1,23 +0,0 @@
1
- /* @flow */
2
-
3
- import { addAttr } from 'compiler/helpers'
4
-
5
- function genText (node: ASTNode) {
6
- const value = node.type === 3
7
- ? node.text
8
- : node.type === 2
9
- ? node.tokens.length === 1
10
- ? node.tokens[0]
11
- : node.tokens
12
- : ''
13
- return JSON.stringify(value)
14
- }
15
-
16
- export function postTransformText (el: ASTElement) {
17
- // weex <text> can only contain text, so the parser
18
- // always generates a single child.
19
- if (el.children.length) {
20
- addAttr(el, 'value', genText(el.children[0]))
21
- el.children = []
22
- }
23
- }
@@ -1,21 +0,0 @@
1
- /* @flow */
2
-
3
- import { camelize } from 'shared/util'
4
- import { generateBinding } from 'weex/util/parser'
5
- import { bindRE } from 'compiler/parser/index'
6
- import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
7
-
8
- function parseAttrName (name: string): string {
9
- return camelize(name.replace(bindRE, ''))
10
- }
11
-
12
- export function preTransformVBind (el: ASTElement) {
13
- for (const attr in el.attrsMap) {
14
- if (bindRE.test(attr)) {
15
- const name: string = parseAttrName(attr)
16
- const value = generateBinding(getAndRemoveAttr(el, attr))
17
- delete el.attrsMap[attr]
18
- addRawAttr(el, name, value)
19
- }
20
- }
21
- }
@@ -1,33 +0,0 @@
1
- /* @flow */
2
-
3
- import { parseFor } from 'compiler/parser/index'
4
- import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
5
-
6
- export function preTransformVFor (el: ASTElement, options: WeexCompilerOptions) {
7
- const exp = getAndRemoveAttr(el, 'v-for')
8
- if (!exp) {
9
- return
10
- }
11
-
12
- const res = parseFor(exp)
13
- if (!res) {
14
- if (process.env.NODE_ENV !== 'production' && options.warn) {
15
- options.warn(`Invalid v-for expression: ${exp}`)
16
- }
17
- return
18
- }
19
-
20
- const desc: Object = {
21
- '@expression': res.for,
22
- '@alias': res.alias
23
- }
24
- if (res.iterator2) {
25
- desc['@key'] = res.iterator1
26
- desc['@index'] = res.iterator2
27
- } else {
28
- desc['@index'] = res.iterator1
29
- }
30
-
31
- delete el.attrsMap['v-for']
32
- addRawAttr(el, '[[repeat]]', desc)
33
- }
@@ -1,63 +0,0 @@
1
- /* @flow */
2
-
3
- import { addIfCondition } from 'compiler/parser/index'
4
- import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
5
-
6
- function hasConditionDirective (el: ASTElement): boolean {
7
- for (const attr in el.attrsMap) {
8
- if (/^v\-if|v\-else|v\-else\-if$/.test(attr)) {
9
- return true
10
- }
11
- }
12
- return false
13
- }
14
-
15
- function getPreviousConditions (el: ASTElement): Array<string> {
16
- const conditions = []
17
- if (el.parent && el.parent.children) {
18
- for (let c = 0, n = el.parent.children.length; c < n; ++c) {
19
- // $flow-disable-line
20
- const ifConditions = el.parent.children[c].ifConditions
21
- if (ifConditions) {
22
- for (let i = 0, l = ifConditions.length; i < l; ++i) {
23
- const condition = ifConditions[i]
24
- if (condition && condition.exp) {
25
- conditions.push(condition.exp)
26
- }
27
- }
28
- }
29
- }
30
- }
31
- return conditions
32
- }
33
-
34
- export function preTransformVIf (el: ASTElement, options: WeexCompilerOptions) {
35
- if (hasConditionDirective(el)) {
36
- let exp
37
- const ifExp = getAndRemoveAttr(el, 'v-if', true /* remove from attrsMap */)
38
- const elseifExp = getAndRemoveAttr(el, 'v-else-if', true)
39
- // don't need the value, but remove it to avoid being generated as a
40
- // custom directive
41
- getAndRemoveAttr(el, 'v-else', true)
42
- if (ifExp) {
43
- exp = ifExp
44
- addIfCondition(el, { exp: ifExp, block: el })
45
- } else {
46
- elseifExp && addIfCondition(el, { exp: elseifExp, block: el })
47
- const prevConditions = getPreviousConditions(el)
48
- if (prevConditions.length) {
49
- const prevMatch = prevConditions.join(' || ')
50
- exp = elseifExp
51
- ? `!(${prevMatch}) && (${elseifExp})` // v-else-if
52
- : `!(${prevMatch})` // v-else
53
- } else if (process.env.NODE_ENV !== 'production' && options.warn) {
54
- options.warn(
55
- `v-${elseifExp ? ('else-if="' + elseifExp + '"') : 'else'} ` +
56
- `used on element <${el.tag}> without corresponding v-if.`
57
- )
58
- return
59
- }
60
- }
61
- addRawAttr(el, '[[match]]', exp)
62
- }
63
- }
@@ -1,25 +0,0 @@
1
- /* @flow */
2
-
3
- const inlineStatementRE = /^\s*([A-Za-z_$0-9\['\."\]]+)*\s*\(\s*(([A-Za-z_$0-9\['\."\]]+)?(\s*,\s*([A-Za-z_$0-9\['\."\]]+))*)\s*\)$/
4
-
5
- function parseHandlerParams (handler: ASTElementHandler) {
6
- const res = inlineStatementRE.exec(handler.value)
7
- if (res && res[2]) {
8
- handler.params = res[2].split(/\s*,\s*/)
9
- }
10
- }
11
-
12
- export function postTransformVOn (el: ASTElement) {
13
- const events: ASTElementHandlers | void = el.events
14
- if (!events) {
15
- return
16
- }
17
- for (const name in events) {
18
- const handler: ASTElementHandler | Array<ASTElementHandler> = events[name]
19
- if (Array.isArray(handler)) {
20
- handler.map(fn => parseHandlerParams(fn))
21
- } else {
22
- parseHandlerParams(handler)
23
- }
24
- }
25
- }
@@ -1,19 +0,0 @@
1
- /* @flow */
2
-
3
- import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
4
-
5
- function containVOnce (el: ASTElement): boolean {
6
- for (const attr in el.attrsMap) {
7
- if (/^v\-once$/i.test(attr)) {
8
- return true
9
- }
10
- }
11
- return false
12
- }
13
-
14
- export function preTransformVOnce (el: ASTElement) {
15
- if (containVOnce(el)) {
16
- getAndRemoveAttr(el, 'v-once', true)
17
- addRawAttr(el, '[[once]]', true)
18
- }
19
- }
@@ -1,87 +0,0 @@
1
- /* @flow */
2
-
3
- import { cached, camelize, isPlainObject } from 'shared/util'
4
- import { parseText } from 'compiler/parser/text-parser'
5
- import {
6
- getAndRemoveAttr,
7
- getBindingAttr,
8
- baseWarn
9
- } from 'compiler/helpers'
10
-
11
- type StaticStyleResult = {
12
- dynamic: boolean,
13
- styleResult: string | Object | void
14
- };
15
-
16
- const normalize = cached(camelize)
17
-
18
- function transformNode (el: ASTElement, options: CompilerOptions) {
19
- const warn = options.warn || baseWarn
20
- const staticStyle = getAndRemoveAttr(el, 'style')
21
- const { dynamic, styleResult } = parseStaticStyle(staticStyle, options)
22
- if (process.env.NODE_ENV !== 'production' && dynamic) {
23
- warn(
24
- `style="${String(staticStyle)}": ` +
25
- 'Interpolation inside attributes has been deprecated. ' +
26
- 'Use v-bind or the colon shorthand instead.',
27
- el.rawAttrsMap['style']
28
- )
29
- }
30
- if (!dynamic && styleResult) {
31
- // $flow-disable-line
32
- el.staticStyle = styleResult
33
- }
34
- const styleBinding = getBindingAttr(el, 'style', false /* getStatic */)
35
- if (styleBinding) {
36
- el.styleBinding = styleBinding
37
- } else if (dynamic) {
38
- // $flow-disable-line
39
- el.styleBinding = styleResult
40
- }
41
- }
42
-
43
- function genData (el: ASTElement): string {
44
- let data = ''
45
- if (el.staticStyle) {
46
- data += `staticStyle:${el.staticStyle},`
47
- }
48
- if (el.styleBinding) {
49
- data += `style:${el.styleBinding},`
50
- }
51
- return data
52
- }
53
-
54
- function parseStaticStyle (staticStyle: ?string, options: CompilerOptions): StaticStyleResult {
55
- // "width: 200px; height: 200px;" -> {width: 200, height: 200}
56
- // "width: 200px; height: {{y}}" -> {width: 200, height: y}
57
- let dynamic = false
58
- let styleResult = ''
59
- if (typeof staticStyle === 'string') {
60
- const styleList = staticStyle.trim().split(';').map(style => {
61
- const result = style.trim().split(':')
62
- if (result.length !== 2) {
63
- return
64
- }
65
- const key = normalize(result[0].trim())
66
- const value = result[1].trim()
67
- const dynamicValue = parseText(value, options.delimiters)
68
- if (dynamicValue) {
69
- dynamic = true
70
- return key + ':' + dynamicValue.expression
71
- }
72
- return key + ':' + JSON.stringify(value)
73
- }).filter(result => result)
74
- if (styleList.length) {
75
- styleResult = '{' + styleList.join(',') + '}'
76
- }
77
- } else if (isPlainObject(staticStyle)) {
78
- styleResult = JSON.stringify(staticStyle) || ''
79
- }
80
- return { dynamic, styleResult }
81
- }
82
-
83
- export default {
84
- staticKeys: ['staticStyle'],
85
- transformNode,
86
- genData
87
- }
@@ -1,2 +0,0 @@
1
- export { compile } from 'weex/compiler/index'
2
- export { generateCodeFrame } from 'compiler/codeframe'