@dcloudio/vue-cli-plugin-uni 2.0.0 → 2.0.1-32920211122002

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 (269) hide show
  1. package/commands/build.js +64 -33
  2. package/commands/serve.js +12 -17
  3. package/generator.js +6 -2
  4. package/index.js +5 -3
  5. package/lib/chain-webpack.js +8 -1
  6. package/lib/check-update.js +56 -0
  7. package/lib/commands/custom.js +7 -4
  8. package/lib/commands/invoke.js +5 -4
  9. package/lib/configure-webpack.js +35 -5
  10. package/lib/copy-webpack-options.js +60 -20
  11. package/lib/env.js +99 -51
  12. package/lib/error-reporting.js +9 -3
  13. package/lib/mp/index.js +31 -16
  14. package/lib/options.js +6 -3
  15. package/lib/util.js +5 -6
  16. package/package.json +3 -3
  17. package/packages/@vue/component-compiler-utils/MODIFY.md +5 -0
  18. package/packages/@vue/component-compiler-utils/dist/compileStyle.js +11 -0
  19. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/API.md +873 -0
  20. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/CHANGELOG.md +466 -0
  21. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/LICENSE-MIT +22 -0
  22. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/README.md +49 -0
  23. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/index.js +26 -0
  24. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/parser.js +1088 -0
  25. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/processor.js +185 -0
  26. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/attribute.js +468 -0
  27. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/className.js +67 -0
  28. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/combinator.js +35 -0
  29. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/comment.js +35 -0
  30. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/constructors.js +91 -0
  31. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/container.js +392 -0
  32. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/guards.js +54 -0
  33. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/id.js +39 -0
  34. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/index.js +39 -0
  35. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/namespace.js +98 -0
  36. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/nesting.js +36 -0
  37. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/node.js +216 -0
  38. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/pseudo.js +40 -0
  39. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/root.js +60 -0
  40. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/selector.js +35 -0
  41. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/string.js +35 -0
  42. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/tag.js +35 -0
  43. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/types.js +15 -0
  44. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/selectors/universal.js +36 -0
  45. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/sortAscending.js +10 -0
  46. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/tokenTypes.js +39 -0
  47. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/tokenize.js +271 -0
  48. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/ensureObject.js +20 -0
  49. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/getProp.js +22 -0
  50. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/index.js +41 -0
  51. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/stripComments.js +21 -0
  52. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/dist/util/unesc.js +18 -0
  53. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/package.json +76 -0
  54. package/packages/@vue/component-compiler-utils/node_modules/postcss-selector-parser/postcss-selector-parser.d.ts +499 -0
  55. package/packages/@vue/devtools-api/lib/cjs/api/api.d.ts +90 -0
  56. package/packages/@vue/devtools-api/lib/cjs/api/api.js +2 -0
  57. package/packages/@vue/devtools-api/lib/cjs/api/app.d.ts +1 -0
  58. package/packages/@vue/devtools-api/lib/cjs/api/app.js +2 -0
  59. package/packages/@vue/devtools-api/lib/cjs/api/component.d.ts +76 -0
  60. package/packages/@vue/devtools-api/lib/cjs/api/component.js +2 -0
  61. package/packages/@vue/devtools-api/lib/cjs/api/context.d.ts +5 -0
  62. package/packages/@vue/devtools-api/lib/cjs/api/context.js +2 -0
  63. package/packages/@vue/devtools-api/lib/cjs/api/hooks.d.ts +169 -0
  64. package/packages/@vue/devtools-api/lib/cjs/api/hooks.js +2 -0
  65. package/packages/@vue/devtools-api/lib/cjs/api/index.d.ts +6 -0
  66. package/packages/@vue/devtools-api/lib/cjs/api/index.js +18 -0
  67. package/packages/@vue/devtools-api/lib/cjs/api/util.d.ts +4 -0
  68. package/packages/@vue/devtools-api/lib/cjs/api/util.js +2 -0
  69. package/packages/@vue/devtools-api/lib/cjs/const.d.ts +1 -0
  70. package/packages/@vue/devtools-api/lib/cjs/const.js +4 -0
  71. package/packages/@vue/devtools-api/lib/cjs/env.d.ts +10 -0
  72. package/packages/@vue/devtools-api/lib/cjs/env.js +16 -0
  73. package/packages/@vue/devtools-api/lib/cjs/index.d.ts +14 -0
  74. package/packages/@vue/devtools-api/lib/cjs/index.js +31 -0
  75. package/packages/@vue/devtools-api/lib/esm/api/api.js +0 -0
  76. package/packages/@vue/devtools-api/lib/esm/api/app.js +0 -0
  77. package/packages/@vue/devtools-api/lib/esm/api/component.js +0 -0
  78. package/packages/@vue/devtools-api/lib/esm/api/context.js +0 -0
  79. package/packages/@vue/devtools-api/lib/esm/api/hooks.js +0 -0
  80. package/packages/@vue/devtools-api/lib/esm/api/index.js +6 -0
  81. package/packages/@vue/devtools-api/lib/esm/api/util.js +0 -0
  82. package/packages/@vue/devtools-api/lib/esm/const.js +1 -0
  83. package/packages/@vue/devtools-api/lib/esm/env.js +11 -0
  84. package/packages/@vue/devtools-api/lib/esm/index.js +17 -0
  85. package/packages/@vue/devtools-api/package.json +38 -0
  86. package/packages/app-vue-style-loader/lib/addStylesClient.js +1 -1
  87. package/packages/h5-vue-style-loader/lib/addStylesClient.js +1 -1
  88. package/packages/mp-vue/dist/mp.runtime.esm.js +3 -2
  89. package/packages/mp-vue/package.json +1 -0
  90. package/packages/uni-app/LICENSE +202 -0
  91. package/packages/uni-app/dist/uni-app.cjs.js +165 -0
  92. package/packages/uni-app/dist/uni-app.d.ts +61 -0
  93. package/packages/uni-app/dist/uni-app.es.js +108 -0
  94. package/packages/uni-app/package.json +22 -0
  95. package/packages/uni-cloud/dist/index.js +1 -1
  96. package/packages/uni-stat/dist/uni-stat.cjs.js +961 -0
  97. package/packages/uni-stat/dist/uni-stat.es.js +959 -0
  98. package/packages/uni-stat/lib/uni.plugin.js +68 -0
  99. package/packages/uni-stat/package.json +25 -0
  100. package/packages/vue3/node_modules/.yarn-integrity +27 -0
  101. package/packages/vue3/node_modules/@intlify/core-base/LICENSE +20 -0
  102. package/packages/vue3/node_modules/@intlify/core-base/README.md +7 -0
  103. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.cjs.js +989 -0
  104. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.cjs.prod.js +735 -0
  105. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.d.ts +576 -0
  106. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-browser.js +2771 -0
  107. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-browser.prod.js +6 -0
  108. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.esm-bundler.js +965 -0
  109. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.global.js +2814 -0
  110. package/packages/vue3/node_modules/@intlify/core-base/dist/core-base.global.prod.js +6 -0
  111. package/packages/vue3/node_modules/@intlify/core-base/index.js +7 -0
  112. package/packages/vue3/node_modules/@intlify/core-base/package.json +59 -0
  113. package/packages/vue3/node_modules/@intlify/devtools-if/LICENSE +20 -0
  114. package/packages/vue3/node_modules/@intlify/devtools-if/README.md +13 -0
  115. package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.cjs.js +15 -0
  116. package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.cjs.prod.js +15 -0
  117. package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.d.ts +43 -0
  118. package/packages/vue3/node_modules/@intlify/devtools-if/dist/devtools-if.esm-bundler.js +11 -0
  119. package/packages/vue3/node_modules/@intlify/devtools-if/index.js +7 -0
  120. package/packages/vue3/node_modules/@intlify/devtools-if/package.json +49 -0
  121. package/packages/vue3/node_modules/@intlify/message-compiler/LICENSE +20 -0
  122. package/packages/vue3/node_modules/@intlify/message-compiler/README.md +7 -0
  123. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js +1400 -0
  124. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js +1395 -0
  125. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.d.ts +197 -0
  126. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-browser.js +1348 -0
  127. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-browser.prod.js +6 -0
  128. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.esm-bundler.js +1329 -0
  129. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.global.js +1365 -0
  130. package/packages/vue3/node_modules/@intlify/message-compiler/dist/message-compiler.global.prod.js +6 -0
  131. package/packages/vue3/node_modules/@intlify/message-compiler/index.js +7 -0
  132. package/packages/vue3/node_modules/@intlify/message-compiler/package.json +56 -0
  133. package/packages/vue3/node_modules/@intlify/message-resolver/LICENSE +20 -0
  134. package/packages/vue3/node_modules/@intlify/message-resolver/README.md +7 -0
  135. package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.cjs.js +302 -0
  136. package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.cjs.prod.js +302 -0
  137. package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.d.ts +21 -0
  138. package/packages/vue3/node_modules/@intlify/message-resolver/dist/message-resolver.esm-bundler.js +297 -0
  139. package/packages/vue3/node_modules/@intlify/message-resolver/index.js +7 -0
  140. package/packages/vue3/node_modules/@intlify/message-resolver/package.json +46 -0
  141. package/packages/vue3/node_modules/@intlify/runtime/LICENSE +20 -0
  142. package/packages/vue3/node_modules/@intlify/runtime/README.md +7 -0
  143. package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.cjs.js +116 -0
  144. package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.cjs.prod.js +116 -0
  145. package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.d.ts +95 -0
  146. package/packages/vue3/node_modules/@intlify/runtime/dist/runtime.esm-bundler.js +111 -0
  147. package/packages/vue3/node_modules/@intlify/runtime/index.js +7 -0
  148. package/packages/vue3/node_modules/@intlify/runtime/package.json +51 -0
  149. package/packages/vue3/node_modules/@intlify/shared/LICENSE +20 -0
  150. package/packages/vue3/node_modules/@intlify/shared/README.md +18 -0
  151. package/packages/vue3/node_modules/@intlify/shared/dist/shared.cjs.js +222 -0
  152. package/packages/vue3/node_modules/@intlify/shared/dist/shared.cjs.prod.js +209 -0
  153. package/packages/vue3/node_modules/@intlify/shared/dist/shared.d.ts +145 -0
  154. package/packages/vue3/node_modules/@intlify/shared/dist/shared.esm-bundler.js +192 -0
  155. package/packages/vue3/node_modules/@intlify/shared/index.js +7 -0
  156. package/packages/vue3/node_modules/@intlify/shared/package.json +46 -0
  157. package/packages/vue3/node_modules/@intlify/vue-devtools/LICENSE +20 -0
  158. package/packages/vue3/node_modules/@intlify/vue-devtools/README.md +7 -0
  159. package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.cjs.js +24 -0
  160. package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.cjs.prod.js +24 -0
  161. package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.d.ts +81 -0
  162. package/packages/vue3/node_modules/@intlify/vue-devtools/dist/vue-devtools.esm-bundler.js +18 -0
  163. package/packages/vue3/node_modules/@intlify/vue-devtools/index.js +7 -0
  164. package/packages/vue3/node_modules/@intlify/vue-devtools/package.json +51 -0
  165. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/api.d.ts +90 -0
  166. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/api.js +2 -0
  167. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/app.d.ts +1 -0
  168. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/app.js +2 -0
  169. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/component.d.ts +76 -0
  170. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/component.js +2 -0
  171. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/context.d.ts +5 -0
  172. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/context.js +2 -0
  173. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/hooks.d.ts +169 -0
  174. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/hooks.js +2 -0
  175. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/index.d.ts +6 -0
  176. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/index.js +18 -0
  177. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/util.d.ts +4 -0
  178. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/api/util.js +2 -0
  179. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/const.d.ts +1 -0
  180. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/const.js +4 -0
  181. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/env.d.ts +10 -0
  182. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/env.js +16 -0
  183. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/index.d.ts +14 -0
  184. package/packages/vue3/node_modules/@vue/devtools-api/lib/cjs/index.js +31 -0
  185. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/api.js +0 -0
  186. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/app.js +0 -0
  187. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/component.js +0 -0
  188. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/context.js +0 -0
  189. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/hooks.js +0 -0
  190. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/index.js +6 -0
  191. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/api/util.js +0 -0
  192. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/const.js +1 -0
  193. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/env.js +11 -0
  194. package/packages/vue3/node_modules/@vue/devtools-api/lib/esm/index.js +17 -0
  195. package/packages/vue3/node_modules/@vue/devtools-api/package.json +38 -0
  196. package/packages/vue3/node_modules/source-map/CHANGELOG.md +301 -0
  197. package/packages/vue3/node_modules/source-map/LICENSE +28 -0
  198. package/packages/vue3/node_modules/source-map/README.md +742 -0
  199. package/packages/vue3/node_modules/source-map/dist/source-map.debug.js +3234 -0
  200. package/packages/vue3/node_modules/source-map/dist/source-map.js +3233 -0
  201. package/packages/vue3/node_modules/source-map/dist/source-map.min.js +2 -0
  202. package/packages/vue3/node_modules/source-map/dist/source-map.min.js.map +1 -0
  203. package/packages/vue3/node_modules/source-map/lib/array-set.js +121 -0
  204. package/packages/vue3/node_modules/source-map/lib/base64-vlq.js +140 -0
  205. package/packages/vue3/node_modules/source-map/lib/base64.js +67 -0
  206. package/packages/vue3/node_modules/source-map/lib/binary-search.js +111 -0
  207. package/packages/vue3/node_modules/source-map/lib/mapping-list.js +79 -0
  208. package/packages/vue3/node_modules/source-map/lib/quick-sort.js +114 -0
  209. package/packages/vue3/node_modules/source-map/lib/source-map-consumer.js +1145 -0
  210. package/packages/vue3/node_modules/source-map/lib/source-map-generator.js +425 -0
  211. package/packages/vue3/node_modules/source-map/lib/source-node.js +413 -0
  212. package/packages/vue3/node_modules/source-map/lib/util.js +488 -0
  213. package/packages/vue3/node_modules/source-map/package.json +73 -0
  214. package/packages/vue3/node_modules/source-map/source-map.d.ts +98 -0
  215. package/packages/vue3/node_modules/source-map/source-map.js +8 -0
  216. package/packages/vue3/node_modules/vue-i18n/LICENSE +20 -0
  217. package/packages/vue3/node_modules/vue-i18n/README.md +74 -0
  218. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.cjs.js +1801 -0
  219. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.cjs.prod.js +1685 -0
  220. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.d.ts +3302 -0
  221. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-browser.js +5052 -0
  222. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-browser.prod.js +6 -0
  223. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.esm-bundler.js +2226 -0
  224. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.global.js +5065 -0
  225. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.global.prod.js +6 -0
  226. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-browser.js +3724 -0
  227. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-browser.prod.js +6 -0
  228. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +2224 -0
  229. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.global.js +3737 -0
  230. package/packages/vue3/node_modules/vue-i18n/dist/vue-i18n.runtime.global.prod.js +6 -0
  231. package/packages/vue3/node_modules/vue-i18n/index.js +7 -0
  232. package/packages/vue3/node_modules/vue-i18n/package.json +69 -0
  233. package/packages/vue3/node_modules/vue-i18n/vetur/attributes.json +62 -0
  234. package/packages/vue3/node_modules/vue-i18n/vetur/tags.json +14 -0
  235. package/packages/vue3/package.json +15 -0
  236. package/packages/vue3/yarn.lock +79 -0
  237. package/packages/vuex/CHANGELOG.md +604 -0
  238. package/packages/vuex/LICENSE +21 -0
  239. package/packages/vuex/README.md +55 -0
  240. package/packages/vuex/dist/vuex.cjs.js +1474 -0
  241. package/packages/vuex/dist/vuex.esm-browser.js +1472 -0
  242. package/packages/vuex/dist/vuex.esm-browser.prod.js +1307 -0
  243. package/packages/vuex/dist/vuex.esm-bundler.js +1473 -0
  244. package/packages/vuex/dist/vuex.global.js +1499 -0
  245. package/packages/vuex/dist/vuex.global.prod.js +6 -0
  246. package/packages/vuex/dist/vuex.mjs +32 -0
  247. package/packages/vuex/package.json +99 -0
  248. package/packages/vuex/types/helpers.d.ts +86 -0
  249. package/packages/vuex/types/index.d.ts +167 -0
  250. package/packages/vuex/types/logger.d.ts +20 -0
  251. package/packages/vuex/types/vue.d.ts +12 -0
  252. package/packages/vuex3/CHANGELOG.md +356 -0
  253. package/packages/vuex3/LICENSE +21 -0
  254. package/packages/vuex3/README.md +59 -0
  255. package/packages/vuex3/dist/logger.js +155 -0
  256. package/packages/vuex3/dist/vuex.common.js +1244 -0
  257. package/packages/vuex3/dist/vuex.esm.browser.js +1200 -0
  258. package/packages/vuex3/dist/vuex.esm.browser.min.js +6 -0
  259. package/packages/vuex3/dist/vuex.esm.js +1243 -0
  260. package/packages/vuex3/dist/vuex.js +1250 -0
  261. package/packages/vuex3/dist/vuex.min.js +6 -0
  262. package/packages/vuex3/dist/vuex.mjs +26 -0
  263. package/packages/vuex3/package.json +96 -0
  264. package/packages/vuex3/types/helpers.d.ts +86 -0
  265. package/packages/vuex3/types/index.d.ts +164 -0
  266. package/packages/vuex3/types/logger.d.ts +20 -0
  267. package/packages/vuex3/types/vue.d.ts +18 -0
  268. package/packages/webpack-uni-app-loader/plugin/index.js +8 -2
  269. package/packages/webpack-uni-app-loader/view/main.js +12 -0
@@ -0,0 +1,2814 @@
1
+ /*!
2
+ * @intlify/core-base v9.1.7
3
+ * (c) 2021 kazuya kawaguchi
4
+ * Released under the MIT License.
5
+ */
6
+ var IntlifyCoreBase = (function (exports) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * Original Utilities
11
+ * written by kazuya kawaguchi
12
+ */
13
+ const inBrowser = typeof window !== 'undefined';
14
+ let mark;
15
+ let measure;
16
+ {
17
+ const perf = inBrowser && window.performance;
18
+ if (perf &&
19
+ perf.mark &&
20
+ perf.measure &&
21
+ perf.clearMarks &&
22
+ perf.clearMeasures) {
23
+ mark = (tag) => perf.mark(tag);
24
+ measure = (name, startTag, endTag) => {
25
+ perf.measure(name, startTag, endTag);
26
+ perf.clearMarks(startTag);
27
+ perf.clearMarks(endTag);
28
+ };
29
+ }
30
+ }
31
+ const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
32
+ /* eslint-disable */
33
+ function format(message, ...args) {
34
+ if (args.length === 1 && isObject(args[0])) {
35
+ args = args[0];
36
+ }
37
+ if (!args || !args.hasOwnProperty) {
38
+ args = {};
39
+ }
40
+ return message.replace(RE_ARGS, (match, identifier) => {
41
+ return args.hasOwnProperty(identifier) ? args[identifier] : '';
42
+ });
43
+ }
44
+ const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
45
+ const friendlyJSONstringify = (json) => JSON.stringify(json)
46
+ .replace(/\u2028/g, '\\u2028')
47
+ .replace(/\u2029/g, '\\u2029')
48
+ .replace(/\u0027/g, '\\u0027');
49
+ const isNumber = (val) => typeof val === 'number' && isFinite(val);
50
+ const isDate = (val) => toTypeString(val) === '[object Date]';
51
+ const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
+ const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
+ function warn(msg, err) {
54
+ if (typeof console !== 'undefined') {
55
+ console.warn(`[intlify] ` + msg);
56
+ /* istanbul ignore if */
57
+ if (err) {
58
+ console.warn(err.stack);
59
+ }
60
+ }
61
+ }
62
+ const assign = Object.assign;
63
+ function escapeHtml(rawText) {
64
+ return rawText
65
+ .replace(/</g, '&lt;')
66
+ .replace(/>/g, '&gt;')
67
+ .replace(/"/g, '&quot;')
68
+ .replace(/'/g, '&apos;');
69
+ }
70
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
71
+ function hasOwn(obj, key) {
72
+ return hasOwnProperty.call(obj, key);
73
+ }
74
+ /* eslint-enable */
75
+ /**
76
+ * Useful Utilities By Evan you
77
+ * Modified by kazuya kawaguchi
78
+ * MIT License
79
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
80
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
81
+ */
82
+ const isArray = Array.isArray;
83
+ const isFunction = (val) => typeof val === 'function';
84
+ const isString = (val) => typeof val === 'string';
85
+ const isBoolean = (val) => typeof val === 'boolean';
86
+ const isObject = (val) => // eslint-disable-line
87
+ val !== null && typeof val === 'object';
88
+ const objectToString = Object.prototype.toString;
89
+ const toTypeString = (value) => objectToString.call(value);
90
+ const isPlainObject = (val) => toTypeString(val) === '[object Object]';
91
+ // for converting list and named values to displayed strings.
92
+ const toDisplayString = (val) => {
93
+ return val == null
94
+ ? ''
95
+ : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
96
+ ? JSON.stringify(val, null, 2)
97
+ : String(val);
98
+ };
99
+ const RANGE = 2;
100
+ function generateCodeFrame(source, start = 0, end = source.length) {
101
+ const lines = source.split(/\r?\n/);
102
+ let count = 0;
103
+ const res = [];
104
+ for (let i = 0; i < lines.length; i++) {
105
+ count += lines[i].length + 1;
106
+ if (count >= start) {
107
+ for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
108
+ if (j < 0 || j >= lines.length)
109
+ continue;
110
+ const line = j + 1;
111
+ res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
112
+ const lineLength = lines[j].length;
113
+ if (j === i) {
114
+ // push underline
115
+ const pad = start - (count - lineLength) + 1;
116
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
117
+ res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
118
+ }
119
+ else if (j > i) {
120
+ if (end > count) {
121
+ const length = Math.max(Math.min(end - count, lineLength), 1);
122
+ res.push(` | ` + '^'.repeat(length));
123
+ }
124
+ count += lineLength + 1;
125
+ }
126
+ }
127
+ break;
128
+ }
129
+ }
130
+ return res.join('\n');
131
+ }
132
+
133
+ const pathStateMachine = [];
134
+ pathStateMachine[0 /* BEFORE_PATH */] = {
135
+ ["w" /* WORKSPACE */]: [0 /* BEFORE_PATH */],
136
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
137
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
138
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
139
+ };
140
+ pathStateMachine[1 /* IN_PATH */] = {
141
+ ["w" /* WORKSPACE */]: [1 /* IN_PATH */],
142
+ ["." /* DOT */]: [2 /* BEFORE_IDENT */],
143
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
144
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
145
+ };
146
+ pathStateMachine[2 /* BEFORE_IDENT */] = {
147
+ ["w" /* WORKSPACE */]: [2 /* BEFORE_IDENT */],
148
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
149
+ ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */]
150
+ };
151
+ pathStateMachine[3 /* IN_IDENT */] = {
152
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
153
+ ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */],
154
+ ["w" /* WORKSPACE */]: [1 /* IN_PATH */, 1 /* PUSH */],
155
+ ["." /* DOT */]: [2 /* BEFORE_IDENT */, 1 /* PUSH */],
156
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */, 1 /* PUSH */],
157
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */, 1 /* PUSH */]
158
+ };
159
+ pathStateMachine[4 /* IN_SUB_PATH */] = {
160
+ ["'" /* SINGLE_QUOTE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */],
161
+ ["\"" /* DOUBLE_QUOTE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */],
162
+ ["[" /* LEFT_BRACKET */]: [
163
+ 4 /* IN_SUB_PATH */,
164
+ 2 /* INC_SUB_PATH_DEPTH */
165
+ ],
166
+ ["]" /* RIGHT_BRACKET */]: [1 /* IN_PATH */, 3 /* PUSH_SUB_PATH */],
167
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
168
+ ["l" /* ELSE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */]
169
+ };
170
+ pathStateMachine[5 /* IN_SINGLE_QUOTE */] = {
171
+ ["'" /* SINGLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
172
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
173
+ ["l" /* ELSE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */]
174
+ };
175
+ pathStateMachine[6 /* IN_DOUBLE_QUOTE */] = {
176
+ ["\"" /* DOUBLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
177
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
178
+ ["l" /* ELSE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */]
179
+ };
180
+ /**
181
+ * Check if an expression is a literal value.
182
+ */
183
+ const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
184
+ function isLiteral(exp) {
185
+ return literalValueRE.test(exp);
186
+ }
187
+ /**
188
+ * Strip quotes from a string
189
+ */
190
+ function stripQuotes(str) {
191
+ const a = str.charCodeAt(0);
192
+ const b = str.charCodeAt(str.length - 1);
193
+ return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
194
+ }
195
+ /**
196
+ * Determine the type of a character in a keypath.
197
+ */
198
+ function getPathCharType(ch) {
199
+ if (ch === undefined || ch === null) {
200
+ return "o" /* END_OF_FAIL */;
201
+ }
202
+ const code = ch.charCodeAt(0);
203
+ switch (code) {
204
+ case 0x5b: // [
205
+ case 0x5d: // ]
206
+ case 0x2e: // .
207
+ case 0x22: // "
208
+ case 0x27: // '
209
+ return ch;
210
+ case 0x5f: // _
211
+ case 0x24: // $
212
+ case 0x2d: // -
213
+ return "i" /* IDENT */;
214
+ case 0x09: // Tab (HT)
215
+ case 0x0a: // Newline (LF)
216
+ case 0x0d: // Return (CR)
217
+ case 0xa0: // No-break space (NBSP)
218
+ case 0xfeff: // Byte Order Mark (BOM)
219
+ case 0x2028: // Line Separator (LS)
220
+ case 0x2029: // Paragraph Separator (PS)
221
+ return "w" /* WORKSPACE */;
222
+ }
223
+ return "i" /* IDENT */;
224
+ }
225
+ /**
226
+ * Format a subPath, return its plain form if it is
227
+ * a literal string or number. Otherwise prepend the
228
+ * dynamic indicator (*).
229
+ */
230
+ function formatSubPath(path) {
231
+ const trimmed = path.trim();
232
+ // invalid leading 0
233
+ if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
234
+ return false;
235
+ }
236
+ return isLiteral(trimmed)
237
+ ? stripQuotes(trimmed)
238
+ : "*" /* ASTARISK */ + trimmed;
239
+ }
240
+ /**
241
+ * Parse a string path into an array of segments
242
+ */
243
+ function parse(path) {
244
+ const keys = [];
245
+ let index = -1;
246
+ let mode = 0 /* BEFORE_PATH */;
247
+ let subPathDepth = 0;
248
+ let c;
249
+ let key; // eslint-disable-line
250
+ let newChar;
251
+ let type;
252
+ let transition;
253
+ let action;
254
+ let typeMap;
255
+ const actions = [];
256
+ actions[0 /* APPEND */] = () => {
257
+ if (key === undefined) {
258
+ key = newChar;
259
+ }
260
+ else {
261
+ key += newChar;
262
+ }
263
+ };
264
+ actions[1 /* PUSH */] = () => {
265
+ if (key !== undefined) {
266
+ keys.push(key);
267
+ key = undefined;
268
+ }
269
+ };
270
+ actions[2 /* INC_SUB_PATH_DEPTH */] = () => {
271
+ actions[0 /* APPEND */]();
272
+ subPathDepth++;
273
+ };
274
+ actions[3 /* PUSH_SUB_PATH */] = () => {
275
+ if (subPathDepth > 0) {
276
+ subPathDepth--;
277
+ mode = 4 /* IN_SUB_PATH */;
278
+ actions[0 /* APPEND */]();
279
+ }
280
+ else {
281
+ subPathDepth = 0;
282
+ if (key === undefined) {
283
+ return false;
284
+ }
285
+ key = formatSubPath(key);
286
+ if (key === false) {
287
+ return false;
288
+ }
289
+ else {
290
+ actions[1 /* PUSH */]();
291
+ }
292
+ }
293
+ };
294
+ function maybeUnescapeQuote() {
295
+ const nextChar = path[index + 1];
296
+ if ((mode === 5 /* IN_SINGLE_QUOTE */ &&
297
+ nextChar === "'" /* SINGLE_QUOTE */) ||
298
+ (mode === 6 /* IN_DOUBLE_QUOTE */ &&
299
+ nextChar === "\"" /* DOUBLE_QUOTE */)) {
300
+ index++;
301
+ newChar = '\\' + nextChar;
302
+ actions[0 /* APPEND */]();
303
+ return true;
304
+ }
305
+ }
306
+ while (mode !== null) {
307
+ index++;
308
+ c = path[index];
309
+ if (c === '\\' && maybeUnescapeQuote()) {
310
+ continue;
311
+ }
312
+ type = getPathCharType(c);
313
+ typeMap = pathStateMachine[mode];
314
+ transition = typeMap[type] || typeMap["l" /* ELSE */] || 8 /* ERROR */;
315
+ // check parse error
316
+ if (transition === 8 /* ERROR */) {
317
+ return;
318
+ }
319
+ mode = transition[0];
320
+ if (transition[1] !== undefined) {
321
+ action = actions[transition[1]];
322
+ if (action) {
323
+ newChar = c;
324
+ if (action() === false) {
325
+ return;
326
+ }
327
+ }
328
+ }
329
+ // check parse finish
330
+ if (mode === 7 /* AFTER_PATH */) {
331
+ return keys;
332
+ }
333
+ }
334
+ }
335
+ // path token cache
336
+ const cache = new Map();
337
+ function resolveValue(obj, path) {
338
+ // check object
339
+ if (!isObject(obj)) {
340
+ return null;
341
+ }
342
+ // parse path
343
+ let hit = cache.get(path);
344
+ if (!hit) {
345
+ hit = parse(path);
346
+ if (hit) {
347
+ cache.set(path, hit);
348
+ }
349
+ }
350
+ // check hit
351
+ if (!hit) {
352
+ return null;
353
+ }
354
+ // resolve path value
355
+ const len = hit.length;
356
+ let last = obj;
357
+ let i = 0;
358
+ while (i < len) {
359
+ const val = last[hit[i]];
360
+ if (val === undefined) {
361
+ return null;
362
+ }
363
+ last = val;
364
+ i++;
365
+ }
366
+ return last;
367
+ }
368
+ /**
369
+ * Transform flat json in obj to normal json in obj
370
+ */
371
+ function handleFlatJson(obj) {
372
+ // check obj
373
+ if (!isObject(obj)) {
374
+ return obj;
375
+ }
376
+ for (const key in obj) {
377
+ // check key
378
+ if (!hasOwn(obj, key)) {
379
+ continue;
380
+ }
381
+ // handle for normal json
382
+ if (!key.includes("." /* DOT */)) {
383
+ // recursive process value if value is also a object
384
+ if (isObject(obj[key])) {
385
+ handleFlatJson(obj[key]);
386
+ }
387
+ }
388
+ // handle for flat json, transform to normal json
389
+ else {
390
+ // go to the last object
391
+ const subKeys = key.split("." /* DOT */);
392
+ const lastIndex = subKeys.length - 1;
393
+ let currentObj = obj;
394
+ for (let i = 0; i < lastIndex; i++) {
395
+ if (!(subKeys[i] in currentObj)) {
396
+ currentObj[subKeys[i]] = {};
397
+ }
398
+ currentObj = currentObj[subKeys[i]];
399
+ }
400
+ // update last object value, delete old property
401
+ currentObj[subKeys[lastIndex]] = obj[key];
402
+ delete obj[key];
403
+ // recursive process value if value is also a object
404
+ if (isObject(currentObj[subKeys[lastIndex]])) {
405
+ handleFlatJson(currentObj[subKeys[lastIndex]]);
406
+ }
407
+ }
408
+ }
409
+ return obj;
410
+ }
411
+
412
+ const DEFAULT_MODIFIER = (str) => str;
413
+ const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
414
+ const DEFAULT_MESSAGE_DATA_TYPE = 'text';
415
+ const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
416
+ const DEFAULT_INTERPOLATE = toDisplayString;
417
+ function pluralDefault(choice, choicesLength) {
418
+ choice = Math.abs(choice);
419
+ if (choicesLength === 2) {
420
+ // prettier-ignore
421
+ return choice
422
+ ? choice > 1
423
+ ? 1
424
+ : 0
425
+ : 1;
426
+ }
427
+ return choice ? Math.min(choice, 2) : 0;
428
+ }
429
+ function getPluralIndex(options) {
430
+ // prettier-ignore
431
+ const index = isNumber(options.pluralIndex)
432
+ ? options.pluralIndex
433
+ : -1;
434
+ // prettier-ignore
435
+ return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
436
+ ? isNumber(options.named.count)
437
+ ? options.named.count
438
+ : isNumber(options.named.n)
439
+ ? options.named.n
440
+ : index
441
+ : index;
442
+ }
443
+ function normalizeNamed(pluralIndex, props) {
444
+ if (!props.count) {
445
+ props.count = pluralIndex;
446
+ }
447
+ if (!props.n) {
448
+ props.n = pluralIndex;
449
+ }
450
+ }
451
+ function createMessageContext(options = {}) {
452
+ const locale = options.locale;
453
+ const pluralIndex = getPluralIndex(options);
454
+ const pluralRule = isObject(options.pluralRules) &&
455
+ isString(locale) &&
456
+ isFunction(options.pluralRules[locale])
457
+ ? options.pluralRules[locale]
458
+ : pluralDefault;
459
+ const orgPluralRule = isObject(options.pluralRules) &&
460
+ isString(locale) &&
461
+ isFunction(options.pluralRules[locale])
462
+ ? pluralDefault
463
+ : undefined;
464
+ const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
465
+ const _list = options.list || [];
466
+ const list = (index) => _list[index];
467
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
468
+ const _named = options.named || {};
469
+ isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
470
+ const named = (key) => _named[key];
471
+ // TODO: need to design resolve message function?
472
+ function message(key) {
473
+ // prettier-ignore
474
+ const msg = isFunction(options.messages)
475
+ ? options.messages(key)
476
+ : isObject(options.messages)
477
+ ? options.messages[key]
478
+ : false;
479
+ return !msg
480
+ ? options.parent
481
+ ? options.parent.message(key) // resolve from parent messages
482
+ : DEFAULT_MESSAGE
483
+ : msg;
484
+ }
485
+ const _modifier = (name) => options.modifiers
486
+ ? options.modifiers[name]
487
+ : DEFAULT_MODIFIER;
488
+ const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
489
+ ? options.processor.normalize
490
+ : DEFAULT_NORMALIZE;
491
+ const interpolate = isPlainObject(options.processor) &&
492
+ isFunction(options.processor.interpolate)
493
+ ? options.processor.interpolate
494
+ : DEFAULT_INTERPOLATE;
495
+ const type = isPlainObject(options.processor) && isString(options.processor.type)
496
+ ? options.processor.type
497
+ : DEFAULT_MESSAGE_DATA_TYPE;
498
+ const ctx = {
499
+ ["list" /* LIST */]: list,
500
+ ["named" /* NAMED */]: named,
501
+ ["plural" /* PLURAL */]: plural,
502
+ ["linked" /* LINKED */]: (key, modifier) => {
503
+ // TODO: should check `key`
504
+ const msg = message(key)(ctx);
505
+ return isString(modifier) ? _modifier(modifier)(msg) : msg;
506
+ },
507
+ ["message" /* MESSAGE */]: message,
508
+ ["type" /* TYPE */]: type,
509
+ ["interpolate" /* INTERPOLATE */]: interpolate,
510
+ ["normalize" /* NORMALIZE */]: normalize
511
+ };
512
+ return ctx;
513
+ }
514
+
515
+ /** @internal */
516
+ const errorMessages$1 = {
517
+ // tokenizer error messages
518
+ [0 /* EXPECTED_TOKEN */]: `Expected token: '{0}'`,
519
+ [1 /* INVALID_TOKEN_IN_PLACEHOLDER */]: `Invalid token in placeholder: '{0}'`,
520
+ [2 /* UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER */]: `Unterminated single quote in placeholder`,
521
+ [3 /* UNKNOWN_ESCAPE_SEQUENCE */]: `Unknown escape sequence: \\{0}`,
522
+ [4 /* INVALID_UNICODE_ESCAPE_SEQUENCE */]: `Invalid unicode escape sequence: {0}`,
523
+ [5 /* UNBALANCED_CLOSING_BRACE */]: `Unbalanced closing brace`,
524
+ [6 /* UNTERMINATED_CLOSING_BRACE */]: `Unterminated closing brace`,
525
+ [7 /* EMPTY_PLACEHOLDER */]: `Empty placeholder`,
526
+ [8 /* NOT_ALLOW_NEST_PLACEHOLDER */]: `Not allowed nest placeholder`,
527
+ [9 /* INVALID_LINKED_FORMAT */]: `Invalid linked format`,
528
+ // parser error messages
529
+ [10 /* MUST_HAVE_MESSAGES_IN_PLURAL */]: `Plural must have messages`,
530
+ [11 /* UNEXPECTED_EMPTY_LINKED_MODIFIER */]: `Unexpected empty linked modifier`,
531
+ [12 /* UNEXPECTED_EMPTY_LINKED_KEY */]: `Unexpected empty linked key`,
532
+ [13 /* UNEXPECTED_LEXICAL_ANALYSIS */]: `Unexpected lexical analysis in token: '{0}'`
533
+ };
534
+ function createCompileError(code, loc, options = {}) {
535
+ const { domain, messages, args } = options;
536
+ const msg = format((messages || errorMessages$1)[code] || '', ...(args || []))
537
+ ;
538
+ const error = new SyntaxError(String(msg));
539
+ error.code = code;
540
+ if (loc) {
541
+ error.location = loc;
542
+ }
543
+ error.domain = domain;
544
+ return error;
545
+ }
546
+ /** @internal */
547
+ function defaultOnError(error) {
548
+ throw error;
549
+ }
550
+
551
+ function createPosition(line, column, offset) {
552
+ return { line, column, offset };
553
+ }
554
+ function createLocation(start, end, source) {
555
+ const loc = { start, end };
556
+ if (source != null) {
557
+ loc.source = source;
558
+ }
559
+ return loc;
560
+ }
561
+
562
+ const CHAR_SP = ' ';
563
+ const CHAR_CR = '\r';
564
+ const CHAR_LF = '\n';
565
+ const CHAR_LS = String.fromCharCode(0x2028);
566
+ const CHAR_PS = String.fromCharCode(0x2029);
567
+ function createScanner(str) {
568
+ const _buf = str;
569
+ let _index = 0;
570
+ let _line = 1;
571
+ let _column = 1;
572
+ let _peekOffset = 0;
573
+ const isCRLF = (index) => _buf[index] === CHAR_CR && _buf[index + 1] === CHAR_LF;
574
+ const isLF = (index) => _buf[index] === CHAR_LF;
575
+ const isPS = (index) => _buf[index] === CHAR_PS;
576
+ const isLS = (index) => _buf[index] === CHAR_LS;
577
+ const isLineEnd = (index) => isCRLF(index) || isLF(index) || isPS(index) || isLS(index);
578
+ const index = () => _index;
579
+ const line = () => _line;
580
+ const column = () => _column;
581
+ const peekOffset = () => _peekOffset;
582
+ const charAt = (offset) => isCRLF(offset) || isPS(offset) || isLS(offset) ? CHAR_LF : _buf[offset];
583
+ const currentChar = () => charAt(_index);
584
+ const currentPeek = () => charAt(_index + _peekOffset);
585
+ function next() {
586
+ _peekOffset = 0;
587
+ if (isLineEnd(_index)) {
588
+ _line++;
589
+ _column = 0;
590
+ }
591
+ if (isCRLF(_index)) {
592
+ _index++;
593
+ }
594
+ _index++;
595
+ _column++;
596
+ return _buf[_index];
597
+ }
598
+ function peek() {
599
+ if (isCRLF(_index + _peekOffset)) {
600
+ _peekOffset++;
601
+ }
602
+ _peekOffset++;
603
+ return _buf[_index + _peekOffset];
604
+ }
605
+ function reset() {
606
+ _index = 0;
607
+ _line = 1;
608
+ _column = 1;
609
+ _peekOffset = 0;
610
+ }
611
+ function resetPeek(offset = 0) {
612
+ _peekOffset = offset;
613
+ }
614
+ function skipToPeek() {
615
+ const target = _index + _peekOffset;
616
+ // eslint-disable-next-line no-unmodified-loop-condition
617
+ while (target !== _index) {
618
+ next();
619
+ }
620
+ _peekOffset = 0;
621
+ }
622
+ return {
623
+ index,
624
+ line,
625
+ column,
626
+ peekOffset,
627
+ charAt,
628
+ currentChar,
629
+ currentPeek,
630
+ next,
631
+ peek,
632
+ reset,
633
+ resetPeek,
634
+ skipToPeek
635
+ };
636
+ }
637
+
638
+ const EOF = undefined;
639
+ const LITERAL_DELIMITER = "'";
640
+ const ERROR_DOMAIN$1 = 'tokenizer';
641
+ function createTokenizer(source, options = {}) {
642
+ const location = options.location !== false;
643
+ const _scnr = createScanner(source);
644
+ const currentOffset = () => _scnr.index();
645
+ const currentPosition = () => createPosition(_scnr.line(), _scnr.column(), _scnr.index());
646
+ const _initLoc = currentPosition();
647
+ const _initOffset = currentOffset();
648
+ const _context = {
649
+ currentType: 14 /* EOF */,
650
+ offset: _initOffset,
651
+ startLoc: _initLoc,
652
+ endLoc: _initLoc,
653
+ lastType: 14 /* EOF */,
654
+ lastOffset: _initOffset,
655
+ lastStartLoc: _initLoc,
656
+ lastEndLoc: _initLoc,
657
+ braceNest: 0,
658
+ inLinked: false,
659
+ text: ''
660
+ };
661
+ const context = () => _context;
662
+ const { onError } = options;
663
+ function emitError(code, pos, offset, ...args) {
664
+ const ctx = context();
665
+ pos.column += offset;
666
+ pos.offset += offset;
667
+ if (onError) {
668
+ const loc = createLocation(ctx.startLoc, pos);
669
+ const err = createCompileError(code, loc, {
670
+ domain: ERROR_DOMAIN$1,
671
+ args
672
+ });
673
+ onError(err);
674
+ }
675
+ }
676
+ function getToken(context, type, value) {
677
+ context.endLoc = currentPosition();
678
+ context.currentType = type;
679
+ const token = { type };
680
+ if (location) {
681
+ token.loc = createLocation(context.startLoc, context.endLoc);
682
+ }
683
+ if (value != null) {
684
+ token.value = value;
685
+ }
686
+ return token;
687
+ }
688
+ const getEndToken = (context) => getToken(context, 14 /* EOF */);
689
+ function eat(scnr, ch) {
690
+ if (scnr.currentChar() === ch) {
691
+ scnr.next();
692
+ return ch;
693
+ }
694
+ else {
695
+ emitError(0 /* EXPECTED_TOKEN */, currentPosition(), 0, ch);
696
+ return '';
697
+ }
698
+ }
699
+ function peekSpaces(scnr) {
700
+ let buf = '';
701
+ while (scnr.currentPeek() === CHAR_SP || scnr.currentPeek() === CHAR_LF) {
702
+ buf += scnr.currentPeek();
703
+ scnr.peek();
704
+ }
705
+ return buf;
706
+ }
707
+ function skipSpaces(scnr) {
708
+ const buf = peekSpaces(scnr);
709
+ scnr.skipToPeek();
710
+ return buf;
711
+ }
712
+ function isIdentifierStart(ch) {
713
+ if (ch === EOF) {
714
+ return false;
715
+ }
716
+ const cc = ch.charCodeAt(0);
717
+ return ((cc >= 97 && cc <= 122) || // a-z
718
+ (cc >= 65 && cc <= 90) || // A-Z
719
+ cc === 95 // _
720
+ );
721
+ }
722
+ function isNumberStart(ch) {
723
+ if (ch === EOF) {
724
+ return false;
725
+ }
726
+ const cc = ch.charCodeAt(0);
727
+ return cc >= 48 && cc <= 57; // 0-9
728
+ }
729
+ function isNamedIdentifierStart(scnr, context) {
730
+ const { currentType } = context;
731
+ if (currentType !== 2 /* BraceLeft */) {
732
+ return false;
733
+ }
734
+ peekSpaces(scnr);
735
+ const ret = isIdentifierStart(scnr.currentPeek());
736
+ scnr.resetPeek();
737
+ return ret;
738
+ }
739
+ function isListIdentifierStart(scnr, context) {
740
+ const { currentType } = context;
741
+ if (currentType !== 2 /* BraceLeft */) {
742
+ return false;
743
+ }
744
+ peekSpaces(scnr);
745
+ const ch = scnr.currentPeek() === '-' ? scnr.peek() : scnr.currentPeek();
746
+ const ret = isNumberStart(ch);
747
+ scnr.resetPeek();
748
+ return ret;
749
+ }
750
+ function isLiteralStart(scnr, context) {
751
+ const { currentType } = context;
752
+ if (currentType !== 2 /* BraceLeft */) {
753
+ return false;
754
+ }
755
+ peekSpaces(scnr);
756
+ const ret = scnr.currentPeek() === LITERAL_DELIMITER;
757
+ scnr.resetPeek();
758
+ return ret;
759
+ }
760
+ function isLinkedDotStart(scnr, context) {
761
+ const { currentType } = context;
762
+ if (currentType !== 8 /* LinkedAlias */) {
763
+ return false;
764
+ }
765
+ peekSpaces(scnr);
766
+ const ret = scnr.currentPeek() === "." /* LinkedDot */;
767
+ scnr.resetPeek();
768
+ return ret;
769
+ }
770
+ function isLinkedModifierStart(scnr, context) {
771
+ const { currentType } = context;
772
+ if (currentType !== 9 /* LinkedDot */) {
773
+ return false;
774
+ }
775
+ peekSpaces(scnr);
776
+ const ret = isIdentifierStart(scnr.currentPeek());
777
+ scnr.resetPeek();
778
+ return ret;
779
+ }
780
+ function isLinkedDelimiterStart(scnr, context) {
781
+ const { currentType } = context;
782
+ if (!(currentType === 8 /* LinkedAlias */ ||
783
+ currentType === 12 /* LinkedModifier */)) {
784
+ return false;
785
+ }
786
+ peekSpaces(scnr);
787
+ const ret = scnr.currentPeek() === ":" /* LinkedDelimiter */;
788
+ scnr.resetPeek();
789
+ return ret;
790
+ }
791
+ function isLinkedReferStart(scnr, context) {
792
+ const { currentType } = context;
793
+ if (currentType !== 10 /* LinkedDelimiter */) {
794
+ return false;
795
+ }
796
+ const fn = () => {
797
+ const ch = scnr.currentPeek();
798
+ if (ch === "{" /* BraceLeft */) {
799
+ return isIdentifierStart(scnr.peek());
800
+ }
801
+ else if (ch === "@" /* LinkedAlias */ ||
802
+ ch === "%" /* Modulo */ ||
803
+ ch === "|" /* Pipe */ ||
804
+ ch === ":" /* LinkedDelimiter */ ||
805
+ ch === "." /* LinkedDot */ ||
806
+ ch === CHAR_SP ||
807
+ !ch) {
808
+ return false;
809
+ }
810
+ else if (ch === CHAR_LF) {
811
+ scnr.peek();
812
+ return fn();
813
+ }
814
+ else {
815
+ // other characters
816
+ return isIdentifierStart(ch);
817
+ }
818
+ };
819
+ const ret = fn();
820
+ scnr.resetPeek();
821
+ return ret;
822
+ }
823
+ function isPluralStart(scnr) {
824
+ peekSpaces(scnr);
825
+ const ret = scnr.currentPeek() === "|" /* Pipe */;
826
+ scnr.resetPeek();
827
+ return ret;
828
+ }
829
+ function isTextStart(scnr, reset = true) {
830
+ const fn = (hasSpace = false, prev = '', detectModulo = false) => {
831
+ const ch = scnr.currentPeek();
832
+ if (ch === "{" /* BraceLeft */) {
833
+ return prev === "%" /* Modulo */ ? false : hasSpace;
834
+ }
835
+ else if (ch === "@" /* LinkedAlias */ || !ch) {
836
+ return prev === "%" /* Modulo */ ? true : hasSpace;
837
+ }
838
+ else if (ch === "%" /* Modulo */) {
839
+ scnr.peek();
840
+ return fn(hasSpace, "%" /* Modulo */, true);
841
+ }
842
+ else if (ch === "|" /* Pipe */) {
843
+ return prev === "%" /* Modulo */ || detectModulo
844
+ ? true
845
+ : !(prev === CHAR_SP || prev === CHAR_LF);
846
+ }
847
+ else if (ch === CHAR_SP) {
848
+ scnr.peek();
849
+ return fn(true, CHAR_SP, detectModulo);
850
+ }
851
+ else if (ch === CHAR_LF) {
852
+ scnr.peek();
853
+ return fn(true, CHAR_LF, detectModulo);
854
+ }
855
+ else {
856
+ return true;
857
+ }
858
+ };
859
+ const ret = fn();
860
+ reset && scnr.resetPeek();
861
+ return ret;
862
+ }
863
+ function takeChar(scnr, fn) {
864
+ const ch = scnr.currentChar();
865
+ if (ch === EOF) {
866
+ return EOF;
867
+ }
868
+ if (fn(ch)) {
869
+ scnr.next();
870
+ return ch;
871
+ }
872
+ return null;
873
+ }
874
+ function takeIdentifierChar(scnr) {
875
+ const closure = (ch) => {
876
+ const cc = ch.charCodeAt(0);
877
+ return ((cc >= 97 && cc <= 122) || // a-z
878
+ (cc >= 65 && cc <= 90) || // A-Z
879
+ (cc >= 48 && cc <= 57) || // 0-9
880
+ cc === 95 || // _
881
+ cc === 36 // $
882
+ );
883
+ };
884
+ return takeChar(scnr, closure);
885
+ }
886
+ function takeDigit(scnr) {
887
+ const closure = (ch) => {
888
+ const cc = ch.charCodeAt(0);
889
+ return cc >= 48 && cc <= 57; // 0-9
890
+ };
891
+ return takeChar(scnr, closure);
892
+ }
893
+ function takeHexDigit(scnr) {
894
+ const closure = (ch) => {
895
+ const cc = ch.charCodeAt(0);
896
+ return ((cc >= 48 && cc <= 57) || // 0-9
897
+ (cc >= 65 && cc <= 70) || // A-F
898
+ (cc >= 97 && cc <= 102)); // a-f
899
+ };
900
+ return takeChar(scnr, closure);
901
+ }
902
+ function getDigits(scnr) {
903
+ let ch = '';
904
+ let num = '';
905
+ while ((ch = takeDigit(scnr))) {
906
+ num += ch;
907
+ }
908
+ return num;
909
+ }
910
+ function readText(scnr) {
911
+ const fn = (buf) => {
912
+ const ch = scnr.currentChar();
913
+ if (ch === "{" /* BraceLeft */ ||
914
+ ch === "}" /* BraceRight */ ||
915
+ ch === "@" /* LinkedAlias */ ||
916
+ !ch) {
917
+ return buf;
918
+ }
919
+ else if (ch === "%" /* Modulo */) {
920
+ if (isTextStart(scnr)) {
921
+ buf += ch;
922
+ scnr.next();
923
+ return fn(buf);
924
+ }
925
+ else {
926
+ return buf;
927
+ }
928
+ }
929
+ else if (ch === "|" /* Pipe */) {
930
+ return buf;
931
+ }
932
+ else if (ch === CHAR_SP || ch === CHAR_LF) {
933
+ if (isTextStart(scnr)) {
934
+ buf += ch;
935
+ scnr.next();
936
+ return fn(buf);
937
+ }
938
+ else if (isPluralStart(scnr)) {
939
+ return buf;
940
+ }
941
+ else {
942
+ buf += ch;
943
+ scnr.next();
944
+ return fn(buf);
945
+ }
946
+ }
947
+ else {
948
+ buf += ch;
949
+ scnr.next();
950
+ return fn(buf);
951
+ }
952
+ };
953
+ return fn('');
954
+ }
955
+ function readNamedIdentifier(scnr) {
956
+ skipSpaces(scnr);
957
+ let ch = '';
958
+ let name = '';
959
+ while ((ch = takeIdentifierChar(scnr))) {
960
+ name += ch;
961
+ }
962
+ if (scnr.currentChar() === EOF) {
963
+ emitError(6 /* UNTERMINATED_CLOSING_BRACE */, currentPosition(), 0);
964
+ }
965
+ return name;
966
+ }
967
+ function readListIdentifier(scnr) {
968
+ skipSpaces(scnr);
969
+ let value = '';
970
+ if (scnr.currentChar() === '-') {
971
+ scnr.next();
972
+ value += `-${getDigits(scnr)}`;
973
+ }
974
+ else {
975
+ value += getDigits(scnr);
976
+ }
977
+ if (scnr.currentChar() === EOF) {
978
+ emitError(6 /* UNTERMINATED_CLOSING_BRACE */, currentPosition(), 0);
979
+ }
980
+ return value;
981
+ }
982
+ function readLiteral(scnr) {
983
+ skipSpaces(scnr);
984
+ eat(scnr, `\'`);
985
+ let ch = '';
986
+ let literal = '';
987
+ const fn = (x) => x !== LITERAL_DELIMITER && x !== CHAR_LF;
988
+ while ((ch = takeChar(scnr, fn))) {
989
+ if (ch === '\\') {
990
+ literal += readEscapeSequence(scnr);
991
+ }
992
+ else {
993
+ literal += ch;
994
+ }
995
+ }
996
+ const current = scnr.currentChar();
997
+ if (current === CHAR_LF || current === EOF) {
998
+ emitError(2 /* UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER */, currentPosition(), 0);
999
+ // TODO: Is it correct really?
1000
+ if (current === CHAR_LF) {
1001
+ scnr.next();
1002
+ eat(scnr, `\'`);
1003
+ }
1004
+ return literal;
1005
+ }
1006
+ eat(scnr, `\'`);
1007
+ return literal;
1008
+ }
1009
+ function readEscapeSequence(scnr) {
1010
+ const ch = scnr.currentChar();
1011
+ switch (ch) {
1012
+ case '\\':
1013
+ case `\'`:
1014
+ scnr.next();
1015
+ return `\\${ch}`;
1016
+ case 'u':
1017
+ return readUnicodeEscapeSequence(scnr, ch, 4);
1018
+ case 'U':
1019
+ return readUnicodeEscapeSequence(scnr, ch, 6);
1020
+ default:
1021
+ emitError(3 /* UNKNOWN_ESCAPE_SEQUENCE */, currentPosition(), 0, ch);
1022
+ return '';
1023
+ }
1024
+ }
1025
+ function readUnicodeEscapeSequence(scnr, unicode, digits) {
1026
+ eat(scnr, unicode);
1027
+ let sequence = '';
1028
+ for (let i = 0; i < digits; i++) {
1029
+ const ch = takeHexDigit(scnr);
1030
+ if (!ch) {
1031
+ emitError(4 /* INVALID_UNICODE_ESCAPE_SEQUENCE */, currentPosition(), 0, `\\${unicode}${sequence}${scnr.currentChar()}`);
1032
+ break;
1033
+ }
1034
+ sequence += ch;
1035
+ }
1036
+ return `\\${unicode}${sequence}`;
1037
+ }
1038
+ function readInvalidIdentifier(scnr) {
1039
+ skipSpaces(scnr);
1040
+ let ch = '';
1041
+ let identifiers = '';
1042
+ const closure = (ch) => ch !== "{" /* BraceLeft */ &&
1043
+ ch !== "}" /* BraceRight */ &&
1044
+ ch !== CHAR_SP &&
1045
+ ch !== CHAR_LF;
1046
+ while ((ch = takeChar(scnr, closure))) {
1047
+ identifiers += ch;
1048
+ }
1049
+ return identifiers;
1050
+ }
1051
+ function readLinkedModifier(scnr) {
1052
+ let ch = '';
1053
+ let name = '';
1054
+ while ((ch = takeIdentifierChar(scnr))) {
1055
+ name += ch;
1056
+ }
1057
+ return name;
1058
+ }
1059
+ function readLinkedRefer(scnr) {
1060
+ const fn = (detect = false, buf) => {
1061
+ const ch = scnr.currentChar();
1062
+ if (ch === "{" /* BraceLeft */ ||
1063
+ ch === "%" /* Modulo */ ||
1064
+ ch === "@" /* LinkedAlias */ ||
1065
+ ch === "|" /* Pipe */ ||
1066
+ !ch) {
1067
+ return buf;
1068
+ }
1069
+ else if (ch === CHAR_SP) {
1070
+ return buf;
1071
+ }
1072
+ else if (ch === CHAR_LF) {
1073
+ buf += ch;
1074
+ scnr.next();
1075
+ return fn(detect, buf);
1076
+ }
1077
+ else {
1078
+ buf += ch;
1079
+ scnr.next();
1080
+ return fn(true, buf);
1081
+ }
1082
+ };
1083
+ return fn(false, '');
1084
+ }
1085
+ function readPlural(scnr) {
1086
+ skipSpaces(scnr);
1087
+ const plural = eat(scnr, "|" /* Pipe */);
1088
+ skipSpaces(scnr);
1089
+ return plural;
1090
+ }
1091
+ // TODO: We need refactoring of token parsing ...
1092
+ function readTokenInPlaceholder(scnr, context) {
1093
+ let token = null;
1094
+ const ch = scnr.currentChar();
1095
+ switch (ch) {
1096
+ case "{" /* BraceLeft */:
1097
+ if (context.braceNest >= 1) {
1098
+ emitError(8 /* NOT_ALLOW_NEST_PLACEHOLDER */, currentPosition(), 0);
1099
+ }
1100
+ scnr.next();
1101
+ token = getToken(context, 2 /* BraceLeft */, "{" /* BraceLeft */);
1102
+ skipSpaces(scnr);
1103
+ context.braceNest++;
1104
+ return token;
1105
+ case "}" /* BraceRight */:
1106
+ if (context.braceNest > 0 &&
1107
+ context.currentType === 2 /* BraceLeft */) {
1108
+ emitError(7 /* EMPTY_PLACEHOLDER */, currentPosition(), 0);
1109
+ }
1110
+ scnr.next();
1111
+ token = getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
1112
+ context.braceNest--;
1113
+ context.braceNest > 0 && skipSpaces(scnr);
1114
+ if (context.inLinked && context.braceNest === 0) {
1115
+ context.inLinked = false;
1116
+ }
1117
+ return token;
1118
+ case "@" /* LinkedAlias */:
1119
+ if (context.braceNest > 0) {
1120
+ emitError(6 /* UNTERMINATED_CLOSING_BRACE */, currentPosition(), 0);
1121
+ }
1122
+ token = readTokenInLinked(scnr, context) || getEndToken(context);
1123
+ context.braceNest = 0;
1124
+ return token;
1125
+ default:
1126
+ let validNamedIdentifier = true;
1127
+ let validListIdentifier = true;
1128
+ let validLiteral = true;
1129
+ if (isPluralStart(scnr)) {
1130
+ if (context.braceNest > 0) {
1131
+ emitError(6 /* UNTERMINATED_CLOSING_BRACE */, currentPosition(), 0);
1132
+ }
1133
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
1134
+ // reset
1135
+ context.braceNest = 0;
1136
+ context.inLinked = false;
1137
+ return token;
1138
+ }
1139
+ if (context.braceNest > 0 &&
1140
+ (context.currentType === 5 /* Named */ ||
1141
+ context.currentType === 6 /* List */ ||
1142
+ context.currentType === 7 /* Literal */)) {
1143
+ emitError(6 /* UNTERMINATED_CLOSING_BRACE */, currentPosition(), 0);
1144
+ context.braceNest = 0;
1145
+ return readToken(scnr, context);
1146
+ }
1147
+ if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
1148
+ token = getToken(context, 5 /* Named */, readNamedIdentifier(scnr));
1149
+ skipSpaces(scnr);
1150
+ return token;
1151
+ }
1152
+ if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
1153
+ token = getToken(context, 6 /* List */, readListIdentifier(scnr));
1154
+ skipSpaces(scnr);
1155
+ return token;
1156
+ }
1157
+ if ((validLiteral = isLiteralStart(scnr, context))) {
1158
+ token = getToken(context, 7 /* Literal */, readLiteral(scnr));
1159
+ skipSpaces(scnr);
1160
+ return token;
1161
+ }
1162
+ if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
1163
+ // TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
1164
+ token = getToken(context, 13 /* InvalidPlace */, readInvalidIdentifier(scnr));
1165
+ emitError(1 /* INVALID_TOKEN_IN_PLACEHOLDER */, currentPosition(), 0, token.value);
1166
+ skipSpaces(scnr);
1167
+ return token;
1168
+ }
1169
+ break;
1170
+ }
1171
+ return token;
1172
+ }
1173
+ // TODO: We need refactoring of token parsing ...
1174
+ function readTokenInLinked(scnr, context) {
1175
+ const { currentType } = context;
1176
+ let token = null;
1177
+ const ch = scnr.currentChar();
1178
+ if ((currentType === 8 /* LinkedAlias */ ||
1179
+ currentType === 9 /* LinkedDot */ ||
1180
+ currentType === 12 /* LinkedModifier */ ||
1181
+ currentType === 10 /* LinkedDelimiter */) &&
1182
+ (ch === CHAR_LF || ch === CHAR_SP)) {
1183
+ emitError(9 /* INVALID_LINKED_FORMAT */, currentPosition(), 0);
1184
+ }
1185
+ switch (ch) {
1186
+ case "@" /* LinkedAlias */:
1187
+ scnr.next();
1188
+ token = getToken(context, 8 /* LinkedAlias */, "@" /* LinkedAlias */);
1189
+ context.inLinked = true;
1190
+ return token;
1191
+ case "." /* LinkedDot */:
1192
+ skipSpaces(scnr);
1193
+ scnr.next();
1194
+ return getToken(context, 9 /* LinkedDot */, "." /* LinkedDot */);
1195
+ case ":" /* LinkedDelimiter */:
1196
+ skipSpaces(scnr);
1197
+ scnr.next();
1198
+ return getToken(context, 10 /* LinkedDelimiter */, ":" /* LinkedDelimiter */);
1199
+ default:
1200
+ if (isPluralStart(scnr)) {
1201
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
1202
+ // reset
1203
+ context.braceNest = 0;
1204
+ context.inLinked = false;
1205
+ return token;
1206
+ }
1207
+ if (isLinkedDotStart(scnr, context) ||
1208
+ isLinkedDelimiterStart(scnr, context)) {
1209
+ skipSpaces(scnr);
1210
+ return readTokenInLinked(scnr, context);
1211
+ }
1212
+ if (isLinkedModifierStart(scnr, context)) {
1213
+ skipSpaces(scnr);
1214
+ return getToken(context, 12 /* LinkedModifier */, readLinkedModifier(scnr));
1215
+ }
1216
+ if (isLinkedReferStart(scnr, context)) {
1217
+ skipSpaces(scnr);
1218
+ if (ch === "{" /* BraceLeft */) {
1219
+ // scan the placeholder
1220
+ return readTokenInPlaceholder(scnr, context) || token;
1221
+ }
1222
+ else {
1223
+ return getToken(context, 11 /* LinkedKey */, readLinkedRefer(scnr));
1224
+ }
1225
+ }
1226
+ if (currentType === 8 /* LinkedAlias */) {
1227
+ emitError(9 /* INVALID_LINKED_FORMAT */, currentPosition(), 0);
1228
+ }
1229
+ context.braceNest = 0;
1230
+ context.inLinked = false;
1231
+ return readToken(scnr, context);
1232
+ }
1233
+ }
1234
+ // TODO: We need refactoring of token parsing ...
1235
+ function readToken(scnr, context) {
1236
+ let token = { type: 14 /* EOF */ };
1237
+ if (context.braceNest > 0) {
1238
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
1239
+ }
1240
+ if (context.inLinked) {
1241
+ return readTokenInLinked(scnr, context) || getEndToken(context);
1242
+ }
1243
+ const ch = scnr.currentChar();
1244
+ switch (ch) {
1245
+ case "{" /* BraceLeft */:
1246
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
1247
+ case "}" /* BraceRight */:
1248
+ emitError(5 /* UNBALANCED_CLOSING_BRACE */, currentPosition(), 0);
1249
+ scnr.next();
1250
+ return getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
1251
+ case "@" /* LinkedAlias */:
1252
+ return readTokenInLinked(scnr, context) || getEndToken(context);
1253
+ default:
1254
+ if (isPluralStart(scnr)) {
1255
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
1256
+ // reset
1257
+ context.braceNest = 0;
1258
+ context.inLinked = false;
1259
+ return token;
1260
+ }
1261
+ if (isTextStart(scnr)) {
1262
+ return getToken(context, 0 /* Text */, readText(scnr));
1263
+ }
1264
+ if (ch === "%" /* Modulo */) {
1265
+ scnr.next();
1266
+ return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
1267
+ }
1268
+ break;
1269
+ }
1270
+ return token;
1271
+ }
1272
+ function nextToken() {
1273
+ const { currentType, offset, startLoc, endLoc } = _context;
1274
+ _context.lastType = currentType;
1275
+ _context.lastOffset = offset;
1276
+ _context.lastStartLoc = startLoc;
1277
+ _context.lastEndLoc = endLoc;
1278
+ _context.offset = currentOffset();
1279
+ _context.startLoc = currentPosition();
1280
+ if (_scnr.currentChar() === EOF) {
1281
+ return getToken(_context, 14 /* EOF */);
1282
+ }
1283
+ return readToken(_scnr, _context);
1284
+ }
1285
+ return {
1286
+ nextToken,
1287
+ currentOffset,
1288
+ currentPosition,
1289
+ context
1290
+ };
1291
+ }
1292
+
1293
+ const ERROR_DOMAIN = 'parser';
1294
+ // Backslash backslash, backslash quote, uHHHH, UHHHHHH.
1295
+ const KNOWN_ESCAPES = /(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;
1296
+ function fromEscapeSequence(match, codePoint4, codePoint6) {
1297
+ switch (match) {
1298
+ case `\\\\`:
1299
+ return `\\`;
1300
+ case `\\\'`:
1301
+ return `\'`;
1302
+ default: {
1303
+ const codePoint = parseInt(codePoint4 || codePoint6, 16);
1304
+ if (codePoint <= 0xd7ff || codePoint >= 0xe000) {
1305
+ return String.fromCodePoint(codePoint);
1306
+ }
1307
+ // invalid ...
1308
+ // Replace them with U+FFFD REPLACEMENT CHARACTER.
1309
+ return '�';
1310
+ }
1311
+ }
1312
+ }
1313
+ function createParser(options = {}) {
1314
+ const location = options.location !== false;
1315
+ const { onError } = options;
1316
+ function emitError(tokenzer, code, start, offset, ...args) {
1317
+ const end = tokenzer.currentPosition();
1318
+ end.offset += offset;
1319
+ end.column += offset;
1320
+ if (onError) {
1321
+ const loc = createLocation(start, end);
1322
+ const err = createCompileError(code, loc, {
1323
+ domain: ERROR_DOMAIN,
1324
+ args
1325
+ });
1326
+ onError(err);
1327
+ }
1328
+ }
1329
+ function startNode(type, offset, loc) {
1330
+ const node = {
1331
+ type,
1332
+ start: offset,
1333
+ end: offset
1334
+ };
1335
+ if (location) {
1336
+ node.loc = { start: loc, end: loc };
1337
+ }
1338
+ return node;
1339
+ }
1340
+ function endNode(node, offset, pos, type) {
1341
+ node.end = offset;
1342
+ if (type) {
1343
+ node.type = type;
1344
+ }
1345
+ if (location && node.loc) {
1346
+ node.loc.end = pos;
1347
+ }
1348
+ }
1349
+ function parseText(tokenizer, value) {
1350
+ const context = tokenizer.context();
1351
+ const node = startNode(3 /* Text */, context.offset, context.startLoc);
1352
+ node.value = value;
1353
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1354
+ return node;
1355
+ }
1356
+ function parseList(tokenizer, index) {
1357
+ const context = tokenizer.context();
1358
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
1359
+ const node = startNode(5 /* List */, offset, loc);
1360
+ node.index = parseInt(index, 10);
1361
+ tokenizer.nextToken(); // skip brach right
1362
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1363
+ return node;
1364
+ }
1365
+ function parseNamed(tokenizer, key) {
1366
+ const context = tokenizer.context();
1367
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
1368
+ const node = startNode(4 /* Named */, offset, loc);
1369
+ node.key = key;
1370
+ tokenizer.nextToken(); // skip brach right
1371
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1372
+ return node;
1373
+ }
1374
+ function parseLiteral(tokenizer, value) {
1375
+ const context = tokenizer.context();
1376
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
1377
+ const node = startNode(9 /* Literal */, offset, loc);
1378
+ node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);
1379
+ tokenizer.nextToken(); // skip brach right
1380
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1381
+ return node;
1382
+ }
1383
+ function parseLinkedModifier(tokenizer) {
1384
+ const token = tokenizer.nextToken();
1385
+ const context = tokenizer.context();
1386
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
1387
+ const node = startNode(8 /* LinkedModifier */, offset, loc);
1388
+ if (token.type !== 12 /* LinkedModifier */) {
1389
+ // empty modifier
1390
+ emitError(tokenizer, 11 /* UNEXPECTED_EMPTY_LINKED_MODIFIER */, context.lastStartLoc, 0);
1391
+ node.value = '';
1392
+ endNode(node, offset, loc);
1393
+ return {
1394
+ nextConsumeToken: token,
1395
+ node
1396
+ };
1397
+ }
1398
+ // check token
1399
+ if (token.value == null) {
1400
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1401
+ }
1402
+ node.value = token.value || '';
1403
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1404
+ return {
1405
+ node
1406
+ };
1407
+ }
1408
+ function parseLinkedKey(tokenizer, value) {
1409
+ const context = tokenizer.context();
1410
+ const node = startNode(7 /* LinkedKey */, context.offset, context.startLoc);
1411
+ node.value = value;
1412
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1413
+ return node;
1414
+ }
1415
+ function parseLinked(tokenizer) {
1416
+ const context = tokenizer.context();
1417
+ const linkedNode = startNode(6 /* Linked */, context.offset, context.startLoc);
1418
+ let token = tokenizer.nextToken();
1419
+ if (token.type === 9 /* LinkedDot */) {
1420
+ const parsed = parseLinkedModifier(tokenizer);
1421
+ linkedNode.modifier = parsed.node;
1422
+ token = parsed.nextConsumeToken || tokenizer.nextToken();
1423
+ }
1424
+ // asset check token
1425
+ if (token.type !== 10 /* LinkedDelimiter */) {
1426
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1427
+ }
1428
+ token = tokenizer.nextToken();
1429
+ // skip brace left
1430
+ if (token.type === 2 /* BraceLeft */) {
1431
+ token = tokenizer.nextToken();
1432
+ }
1433
+ switch (token.type) {
1434
+ case 11 /* LinkedKey */:
1435
+ if (token.value == null) {
1436
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1437
+ }
1438
+ linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
1439
+ break;
1440
+ case 5 /* Named */:
1441
+ if (token.value == null) {
1442
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1443
+ }
1444
+ linkedNode.key = parseNamed(tokenizer, token.value || '');
1445
+ break;
1446
+ case 6 /* List */:
1447
+ if (token.value == null) {
1448
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1449
+ }
1450
+ linkedNode.key = parseList(tokenizer, token.value || '');
1451
+ break;
1452
+ case 7 /* Literal */:
1453
+ if (token.value == null) {
1454
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1455
+ }
1456
+ linkedNode.key = parseLiteral(tokenizer, token.value || '');
1457
+ break;
1458
+ default:
1459
+ // empty key
1460
+ emitError(tokenizer, 12 /* UNEXPECTED_EMPTY_LINKED_KEY */, context.lastStartLoc, 0);
1461
+ const nextContext = tokenizer.context();
1462
+ const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc);
1463
+ emptyLinkedKeyNode.value = '';
1464
+ endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
1465
+ linkedNode.key = emptyLinkedKeyNode;
1466
+ endNode(linkedNode, nextContext.offset, nextContext.startLoc);
1467
+ return {
1468
+ nextConsumeToken: token,
1469
+ node: linkedNode
1470
+ };
1471
+ }
1472
+ endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
1473
+ return {
1474
+ node: linkedNode
1475
+ };
1476
+ }
1477
+ function parseMessage(tokenizer) {
1478
+ const context = tokenizer.context();
1479
+ const startOffset = context.currentType === 1 /* Pipe */
1480
+ ? tokenizer.currentOffset()
1481
+ : context.offset;
1482
+ const startLoc = context.currentType === 1 /* Pipe */
1483
+ ? context.endLoc
1484
+ : context.startLoc;
1485
+ const node = startNode(2 /* Message */, startOffset, startLoc);
1486
+ node.items = [];
1487
+ let nextToken = null;
1488
+ do {
1489
+ const token = nextToken || tokenizer.nextToken();
1490
+ nextToken = null;
1491
+ switch (token.type) {
1492
+ case 0 /* Text */:
1493
+ if (token.value == null) {
1494
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1495
+ }
1496
+ node.items.push(parseText(tokenizer, token.value || ''));
1497
+ break;
1498
+ case 6 /* List */:
1499
+ if (token.value == null) {
1500
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1501
+ }
1502
+ node.items.push(parseList(tokenizer, token.value || ''));
1503
+ break;
1504
+ case 5 /* Named */:
1505
+ if (token.value == null) {
1506
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1507
+ }
1508
+ node.items.push(parseNamed(tokenizer, token.value || ''));
1509
+ break;
1510
+ case 7 /* Literal */:
1511
+ if (token.value == null) {
1512
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, getTokenCaption(token));
1513
+ }
1514
+ node.items.push(parseLiteral(tokenizer, token.value || ''));
1515
+ break;
1516
+ case 8 /* LinkedAlias */:
1517
+ const parsed = parseLinked(tokenizer);
1518
+ node.items.push(parsed.node);
1519
+ nextToken = parsed.nextConsumeToken || null;
1520
+ break;
1521
+ }
1522
+ } while (context.currentType !== 14 /* EOF */ &&
1523
+ context.currentType !== 1 /* Pipe */);
1524
+ // adjust message node loc
1525
+ const endOffset = context.currentType === 1 /* Pipe */
1526
+ ? context.lastOffset
1527
+ : tokenizer.currentOffset();
1528
+ const endLoc = context.currentType === 1 /* Pipe */
1529
+ ? context.lastEndLoc
1530
+ : tokenizer.currentPosition();
1531
+ endNode(node, endOffset, endLoc);
1532
+ return node;
1533
+ }
1534
+ function parsePlural(tokenizer, offset, loc, msgNode) {
1535
+ const context = tokenizer.context();
1536
+ let hasEmptyMessage = msgNode.items.length === 0;
1537
+ const node = startNode(1 /* Plural */, offset, loc);
1538
+ node.cases = [];
1539
+ node.cases.push(msgNode);
1540
+ do {
1541
+ const msg = parseMessage(tokenizer);
1542
+ if (!hasEmptyMessage) {
1543
+ hasEmptyMessage = msg.items.length === 0;
1544
+ }
1545
+ node.cases.push(msg);
1546
+ } while (context.currentType !== 14 /* EOF */);
1547
+ if (hasEmptyMessage) {
1548
+ emitError(tokenizer, 10 /* MUST_HAVE_MESSAGES_IN_PLURAL */, loc, 0);
1549
+ }
1550
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1551
+ return node;
1552
+ }
1553
+ function parseResource(tokenizer) {
1554
+ const context = tokenizer.context();
1555
+ const { offset, startLoc } = context;
1556
+ const msgNode = parseMessage(tokenizer);
1557
+ if (context.currentType === 14 /* EOF */) {
1558
+ return msgNode;
1559
+ }
1560
+ else {
1561
+ return parsePlural(tokenizer, offset, startLoc, msgNode);
1562
+ }
1563
+ }
1564
+ function parse(source) {
1565
+ const tokenizer = createTokenizer(source, assign({}, options));
1566
+ const context = tokenizer.context();
1567
+ const node = startNode(0 /* Resource */, context.offset, context.startLoc);
1568
+ if (location && node.loc) {
1569
+ node.loc.source = source;
1570
+ }
1571
+ node.body = parseResource(tokenizer);
1572
+ // assert whether achieved to EOF
1573
+ if (context.currentType !== 14 /* EOF */) {
1574
+ emitError(tokenizer, 13 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, source[context.offset] || '');
1575
+ }
1576
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1577
+ return node;
1578
+ }
1579
+ return { parse };
1580
+ }
1581
+ function getTokenCaption(token) {
1582
+ if (token.type === 14 /* EOF */) {
1583
+ return 'EOF';
1584
+ }
1585
+ const name = (token.value || '').replace(/\r?\n/gu, '\\n');
1586
+ return name.length > 10 ? name.slice(0, 9) + '…' : name;
1587
+ }
1588
+
1589
+ function createTransformer(ast, options = {} // eslint-disable-line
1590
+ ) {
1591
+ const _context = {
1592
+ ast,
1593
+ helpers: new Set()
1594
+ };
1595
+ const context = () => _context;
1596
+ const helper = (name) => {
1597
+ _context.helpers.add(name);
1598
+ return name;
1599
+ };
1600
+ return { context, helper };
1601
+ }
1602
+ function traverseNodes(nodes, transformer) {
1603
+ for (let i = 0; i < nodes.length; i++) {
1604
+ traverseNode(nodes[i], transformer);
1605
+ }
1606
+ }
1607
+ function traverseNode(node, transformer) {
1608
+ // TODO: if we need pre-hook of transform, should be implemented to here
1609
+ switch (node.type) {
1610
+ case 1 /* Plural */:
1611
+ traverseNodes(node.cases, transformer);
1612
+ transformer.helper("plural" /* PLURAL */);
1613
+ break;
1614
+ case 2 /* Message */:
1615
+ traverseNodes(node.items, transformer);
1616
+ break;
1617
+ case 6 /* Linked */:
1618
+ const linked = node;
1619
+ traverseNode(linked.key, transformer);
1620
+ transformer.helper("linked" /* LINKED */);
1621
+ break;
1622
+ case 5 /* List */:
1623
+ transformer.helper("interpolate" /* INTERPOLATE */);
1624
+ transformer.helper("list" /* LIST */);
1625
+ break;
1626
+ case 4 /* Named */:
1627
+ transformer.helper("interpolate" /* INTERPOLATE */);
1628
+ transformer.helper("named" /* NAMED */);
1629
+ break;
1630
+ }
1631
+ // TODO: if we need post-hook of transform, should be implemented to here
1632
+ }
1633
+ // transform AST
1634
+ function transform(ast, options = {} // eslint-disable-line
1635
+ ) {
1636
+ const transformer = createTransformer(ast);
1637
+ transformer.helper("normalize" /* NORMALIZE */);
1638
+ // traverse
1639
+ ast.body && traverseNode(ast.body, transformer);
1640
+ // set meta information
1641
+ const context = transformer.context();
1642
+ ast.helpers = Array.from(context.helpers);
1643
+ }
1644
+
1645
+ function createCodeGenerator(ast, options) {
1646
+ const { sourceMap, filename, breakLineCode, needIndent: _needIndent } = options;
1647
+ const _context = {
1648
+ source: ast.loc.source,
1649
+ filename,
1650
+ code: '',
1651
+ column: 1,
1652
+ line: 1,
1653
+ offset: 0,
1654
+ map: undefined,
1655
+ breakLineCode,
1656
+ needIndent: _needIndent,
1657
+ indentLevel: 0
1658
+ };
1659
+ const context = () => _context;
1660
+ function push(code, node) {
1661
+ _context.code += code;
1662
+ }
1663
+ function _newline(n, withBreakLine = true) {
1664
+ const _breakLineCode = withBreakLine ? breakLineCode : '';
1665
+ push(_needIndent ? _breakLineCode + ` `.repeat(n) : _breakLineCode);
1666
+ }
1667
+ function indent(withNewLine = true) {
1668
+ const level = ++_context.indentLevel;
1669
+ withNewLine && _newline(level);
1670
+ }
1671
+ function deindent(withNewLine = true) {
1672
+ const level = --_context.indentLevel;
1673
+ withNewLine && _newline(level);
1674
+ }
1675
+ function newline() {
1676
+ _newline(_context.indentLevel);
1677
+ }
1678
+ const helper = (key) => `_${key}`;
1679
+ const needIndent = () => _context.needIndent;
1680
+ return {
1681
+ context,
1682
+ push,
1683
+ indent,
1684
+ deindent,
1685
+ newline,
1686
+ helper,
1687
+ needIndent
1688
+ };
1689
+ }
1690
+ function generateLinkedNode(generator, node) {
1691
+ const { helper } = generator;
1692
+ generator.push(`${helper("linked" /* LINKED */)}(`);
1693
+ generateNode(generator, node.key);
1694
+ if (node.modifier) {
1695
+ generator.push(`, `);
1696
+ generateNode(generator, node.modifier);
1697
+ }
1698
+ generator.push(`)`);
1699
+ }
1700
+ function generateMessageNode(generator, node) {
1701
+ const { helper, needIndent } = generator;
1702
+ generator.push(`${helper("normalize" /* NORMALIZE */)}([`);
1703
+ generator.indent(needIndent());
1704
+ const length = node.items.length;
1705
+ for (let i = 0; i < length; i++) {
1706
+ generateNode(generator, node.items[i]);
1707
+ if (i === length - 1) {
1708
+ break;
1709
+ }
1710
+ generator.push(', ');
1711
+ }
1712
+ generator.deindent(needIndent());
1713
+ generator.push('])');
1714
+ }
1715
+ function generatePluralNode(generator, node) {
1716
+ const { helper, needIndent } = generator;
1717
+ if (node.cases.length > 1) {
1718
+ generator.push(`${helper("plural" /* PLURAL */)}([`);
1719
+ generator.indent(needIndent());
1720
+ const length = node.cases.length;
1721
+ for (let i = 0; i < length; i++) {
1722
+ generateNode(generator, node.cases[i]);
1723
+ if (i === length - 1) {
1724
+ break;
1725
+ }
1726
+ generator.push(', ');
1727
+ }
1728
+ generator.deindent(needIndent());
1729
+ generator.push(`])`);
1730
+ }
1731
+ }
1732
+ function generateResource(generator, node) {
1733
+ if (node.body) {
1734
+ generateNode(generator, node.body);
1735
+ }
1736
+ else {
1737
+ generator.push('null');
1738
+ }
1739
+ }
1740
+ function generateNode(generator, node) {
1741
+ const { helper } = generator;
1742
+ switch (node.type) {
1743
+ case 0 /* Resource */:
1744
+ generateResource(generator, node);
1745
+ break;
1746
+ case 1 /* Plural */:
1747
+ generatePluralNode(generator, node);
1748
+ break;
1749
+ case 2 /* Message */:
1750
+ generateMessageNode(generator, node);
1751
+ break;
1752
+ case 6 /* Linked */:
1753
+ generateLinkedNode(generator, node);
1754
+ break;
1755
+ case 8 /* LinkedModifier */:
1756
+ generator.push(JSON.stringify(node.value), node);
1757
+ break;
1758
+ case 7 /* LinkedKey */:
1759
+ generator.push(JSON.stringify(node.value), node);
1760
+ break;
1761
+ case 5 /* List */:
1762
+ generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("list" /* LIST */)}(${node.index}))`, node);
1763
+ break;
1764
+ case 4 /* Named */:
1765
+ generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("named" /* NAMED */)}(${JSON.stringify(node.key)}))`, node);
1766
+ break;
1767
+ case 9 /* Literal */:
1768
+ generator.push(JSON.stringify(node.value), node);
1769
+ break;
1770
+ case 3 /* Text */:
1771
+ generator.push(JSON.stringify(node.value), node);
1772
+ break;
1773
+ default:
1774
+ {
1775
+ throw new Error(`unhandled codegen node type: ${node.type}`);
1776
+ }
1777
+ }
1778
+ }
1779
+ // generate code from AST
1780
+ const generate = (ast, options = {} // eslint-disable-line
1781
+ ) => {
1782
+ const mode = isString(options.mode) ? options.mode : 'normal';
1783
+ const filename = isString(options.filename)
1784
+ ? options.filename
1785
+ : 'message.intl';
1786
+ const sourceMap = !!options.sourceMap;
1787
+ // prettier-ignore
1788
+ const breakLineCode = options.breakLineCode != null
1789
+ ? options.breakLineCode
1790
+ : mode === 'arrow'
1791
+ ? ';'
1792
+ : '\n';
1793
+ const needIndent = options.needIndent ? options.needIndent : mode !== 'arrow';
1794
+ const helpers = ast.helpers || [];
1795
+ const generator = createCodeGenerator(ast, {
1796
+ mode,
1797
+ filename,
1798
+ sourceMap,
1799
+ breakLineCode,
1800
+ needIndent
1801
+ });
1802
+ generator.push(mode === 'normal' ? `function __msg__ (ctx) {` : `(ctx) => {`);
1803
+ generator.indent(needIndent);
1804
+ if (helpers.length > 0) {
1805
+ generator.push(`const { ${helpers.map(s => `${s}: _${s}`).join(', ')} } = ctx`);
1806
+ generator.newline();
1807
+ }
1808
+ generator.push(`return `);
1809
+ generateNode(generator, ast);
1810
+ generator.deindent(needIndent);
1811
+ generator.push(`}`);
1812
+ const { code, map } = generator.context();
1813
+ return {
1814
+ ast,
1815
+ code,
1816
+ map: map ? map.toJSON() : undefined // eslint-disable-line @typescript-eslint/no-explicit-any
1817
+ };
1818
+ };
1819
+
1820
+ function baseCompile(source, options = {}) {
1821
+ const assignedOptions = assign({}, options);
1822
+ // parse source codes
1823
+ const parser = createParser(assignedOptions);
1824
+ const ast = parser.parse(source);
1825
+ // transform ASTs
1826
+ transform(ast, assignedOptions);
1827
+ // generate javascript codes
1828
+ return generate(ast, assignedOptions);
1829
+ }
1830
+
1831
+ const IntlifyDevToolsHooks = {
1832
+ I18nInit: 'i18n:init',
1833
+ FunctionTranslate: 'function:translate'
1834
+ };
1835
+
1836
+ let devtools = null;
1837
+ function setDevToolsHook(hook) {
1838
+ devtools = hook;
1839
+ }
1840
+ function getDevToolsHook() {
1841
+ return devtools;
1842
+ }
1843
+ function initI18nDevTools(i18n, version, meta) {
1844
+ // TODO: queue if devtools is undefined
1845
+ devtools &&
1846
+ devtools.emit(IntlifyDevToolsHooks.I18nInit, {
1847
+ timestamp: Date.now(),
1848
+ i18n,
1849
+ version,
1850
+ meta
1851
+ });
1852
+ }
1853
+ const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
1854
+ function createDevToolsHook(hook) {
1855
+ return (payloads) => devtools && devtools.emit(hook, payloads);
1856
+ }
1857
+
1858
+ /** @internal */
1859
+ const warnMessages = {
1860
+ [0 /* NOT_FOUND_KEY */]: `Not found '{key}' key in '{locale}' locale messages.`,
1861
+ [1 /* FALLBACK_TO_TRANSLATE */]: `Fall back to translate '{key}' key with '{target}' locale.`,
1862
+ [2 /* CANNOT_FORMAT_NUMBER */]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
1863
+ [3 /* FALLBACK_TO_NUMBER_FORMAT */]: `Fall back to number format '{key}' key with '{target}' locale.`,
1864
+ [4 /* CANNOT_FORMAT_DATE */]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
1865
+ [5 /* FALLBACK_TO_DATE_FORMAT */]: `Fall back to datetime format '{key}' key with '{target}' locale.`
1866
+ };
1867
+ function getWarnMessage(code, ...args) {
1868
+ return format(warnMessages[code], ...args);
1869
+ }
1870
+
1871
+ /**
1872
+ * Intlify core-base version
1873
+ * @internal
1874
+ */
1875
+ const VERSION = '9.1.7';
1876
+ const NOT_REOSLVED = -1;
1877
+ const MISSING_RESOLVE_VALUE = '';
1878
+ function getDefaultLinkedModifiers() {
1879
+ return {
1880
+ upper: (val) => (isString(val) ? val.toUpperCase() : val),
1881
+ lower: (val) => (isString(val) ? val.toLowerCase() : val),
1882
+ // prettier-ignore
1883
+ capitalize: (val) => (isString(val)
1884
+ ? `${val.charAt(0).toLocaleUpperCase()}${val.substr(1)}`
1885
+ : val)
1886
+ };
1887
+ }
1888
+ let _compiler;
1889
+ function registerMessageCompiler(compiler) {
1890
+ _compiler = compiler;
1891
+ }
1892
+ // Additional Meta for Intlify DevTools
1893
+ let _additionalMeta = null;
1894
+ const setAdditionalMeta = /* #__PURE__*/ (meta) => {
1895
+ _additionalMeta = meta;
1896
+ };
1897
+ const getAdditionalMeta = /* #__PURE__*/ () => _additionalMeta;
1898
+ // ID for CoreContext
1899
+ let _cid = 0;
1900
+ function createCoreContext(options = {}) {
1901
+ // setup options
1902
+ const version = isString(options.version) ? options.version : VERSION;
1903
+ const locale = isString(options.locale) ? options.locale : 'en-US';
1904
+ const fallbackLocale = isArray(options.fallbackLocale) ||
1905
+ isPlainObject(options.fallbackLocale) ||
1906
+ isString(options.fallbackLocale) ||
1907
+ options.fallbackLocale === false
1908
+ ? options.fallbackLocale
1909
+ : locale;
1910
+ const messages = isPlainObject(options.messages)
1911
+ ? options.messages
1912
+ : { [locale]: {} };
1913
+ const datetimeFormats = isPlainObject(options.datetimeFormats)
1914
+ ? options.datetimeFormats
1915
+ : { [locale]: {} };
1916
+ const numberFormats = isPlainObject(options.numberFormats)
1917
+ ? options.numberFormats
1918
+ : { [locale]: {} };
1919
+ const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
1920
+ const pluralRules = options.pluralRules || {};
1921
+ const missing = isFunction(options.missing) ? options.missing : null;
1922
+ const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
1923
+ ? options.missingWarn
1924
+ : true;
1925
+ const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
1926
+ ? options.fallbackWarn
1927
+ : true;
1928
+ const fallbackFormat = !!options.fallbackFormat;
1929
+ const unresolving = !!options.unresolving;
1930
+ const postTranslation = isFunction(options.postTranslation)
1931
+ ? options.postTranslation
1932
+ : null;
1933
+ const processor = isPlainObject(options.processor) ? options.processor : null;
1934
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
1935
+ ? options.warnHtmlMessage
1936
+ : true;
1937
+ const escapeParameter = !!options.escapeParameter;
1938
+ const messageCompiler = isFunction(options.messageCompiler)
1939
+ ? options.messageCompiler
1940
+ : _compiler;
1941
+ const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
1942
+ // setup internal options
1943
+ const internalOptions = options;
1944
+ const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
1945
+ ? internalOptions.__datetimeFormatters
1946
+ : new Map();
1947
+ const __numberFormatters = isObject(internalOptions.__numberFormatters)
1948
+ ? internalOptions.__numberFormatters
1949
+ : new Map();
1950
+ const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
1951
+ _cid++;
1952
+ const context = {
1953
+ version,
1954
+ cid: _cid,
1955
+ locale,
1956
+ fallbackLocale,
1957
+ messages,
1958
+ datetimeFormats,
1959
+ numberFormats,
1960
+ modifiers,
1961
+ pluralRules,
1962
+ missing,
1963
+ missingWarn,
1964
+ fallbackWarn,
1965
+ fallbackFormat,
1966
+ unresolving,
1967
+ postTranslation,
1968
+ processor,
1969
+ warnHtmlMessage,
1970
+ escapeParameter,
1971
+ messageCompiler,
1972
+ onWarn,
1973
+ __datetimeFormatters,
1974
+ __numberFormatters,
1975
+ __meta
1976
+ };
1977
+ // for vue-devtools timeline event
1978
+ {
1979
+ context.__v_emitter =
1980
+ internalOptions.__v_emitter != null
1981
+ ? internalOptions.__v_emitter
1982
+ : undefined;
1983
+ }
1984
+ // NOTE: experimental !!
1985
+ {
1986
+ initI18nDevTools(context, version, __meta);
1987
+ }
1988
+ return context;
1989
+ }
1990
+ /** @internal */
1991
+ function isTranslateFallbackWarn(fallback, key) {
1992
+ return fallback instanceof RegExp ? fallback.test(key) : fallback;
1993
+ }
1994
+ /** @internal */
1995
+ function isTranslateMissingWarn(missing, key) {
1996
+ return missing instanceof RegExp ? missing.test(key) : missing;
1997
+ }
1998
+ /** @internal */
1999
+ function handleMissing(context, key, locale, missingWarn, type) {
2000
+ const { missing, onWarn } = context;
2001
+ // for vue-devtools timeline event
2002
+ {
2003
+ const emitter = context.__v_emitter;
2004
+ if (emitter) {
2005
+ emitter.emit("missing" /* MISSING */, {
2006
+ locale,
2007
+ key,
2008
+ type,
2009
+ groupId: `${type}:${key}`
2010
+ });
2011
+ }
2012
+ }
2013
+ if (missing !== null) {
2014
+ const ret = missing(context, locale, key, type);
2015
+ return isString(ret) ? ret : key;
2016
+ }
2017
+ else {
2018
+ if (isTranslateMissingWarn(missingWarn, key)) {
2019
+ onWarn(getWarnMessage(0 /* NOT_FOUND_KEY */, { key, locale }));
2020
+ }
2021
+ return key;
2022
+ }
2023
+ }
2024
+ /** @internal */
2025
+ function getLocaleChain(ctx, fallback, start) {
2026
+ const context = ctx;
2027
+ if (!context.__localeChainCache) {
2028
+ context.__localeChainCache = new Map();
2029
+ }
2030
+ let chain = context.__localeChainCache.get(start);
2031
+ if (!chain) {
2032
+ chain = [];
2033
+ // first block defined by start
2034
+ let block = [start];
2035
+ // while any intervening block found
2036
+ while (isArray(block)) {
2037
+ block = appendBlockToChain(chain, block, fallback);
2038
+ }
2039
+ // prettier-ignore
2040
+ // last block defined by default
2041
+ const defaults = isArray(fallback)
2042
+ ? fallback
2043
+ : isPlainObject(fallback)
2044
+ ? fallback['default']
2045
+ ? fallback['default']
2046
+ : null
2047
+ : fallback;
2048
+ // convert defaults to array
2049
+ block = isString(defaults) ? [defaults] : defaults;
2050
+ if (isArray(block)) {
2051
+ appendBlockToChain(chain, block, false);
2052
+ }
2053
+ context.__localeChainCache.set(start, chain);
2054
+ }
2055
+ return chain;
2056
+ }
2057
+ function appendBlockToChain(chain, block, blocks) {
2058
+ let follow = true;
2059
+ for (let i = 0; i < block.length && isBoolean(follow); i++) {
2060
+ const locale = block[i];
2061
+ if (isString(locale)) {
2062
+ follow = appendLocaleToChain(chain, block[i], blocks);
2063
+ }
2064
+ }
2065
+ return follow;
2066
+ }
2067
+ function appendLocaleToChain(chain, locale, blocks) {
2068
+ let follow;
2069
+ const tokens = locale.split('-');
2070
+ do {
2071
+ const target = tokens.join('-');
2072
+ follow = appendItemToChain(chain, target, blocks);
2073
+ tokens.splice(-1, 1);
2074
+ } while (tokens.length && follow === true);
2075
+ return follow;
2076
+ }
2077
+ function appendItemToChain(chain, target, blocks) {
2078
+ let follow = false;
2079
+ if (!chain.includes(target)) {
2080
+ follow = true;
2081
+ if (target) {
2082
+ follow = target[target.length - 1] !== '!';
2083
+ const locale = target.replace(/!/g, '');
2084
+ chain.push(locale);
2085
+ if ((isArray(blocks) || isPlainObject(blocks)) &&
2086
+ blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
2087
+ ) {
2088
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2089
+ follow = blocks[locale];
2090
+ }
2091
+ }
2092
+ }
2093
+ return follow;
2094
+ }
2095
+ /** @internal */
2096
+ function updateFallbackLocale(ctx, locale, fallback) {
2097
+ const context = ctx;
2098
+ context.__localeChainCache = new Map();
2099
+ getLocaleChain(ctx, fallback, locale);
2100
+ }
2101
+
2102
+ const RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
2103
+ const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
2104
+ function checkHtmlMessage(source, options) {
2105
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
2106
+ ? options.warnHtmlMessage
2107
+ : true;
2108
+ if (warnHtmlMessage && RE_HTML_TAG.test(source)) {
2109
+ warn(format(WARN_MESSAGE, { source }));
2110
+ }
2111
+ }
2112
+ const defaultOnCacheKey = (source) => source;
2113
+ let compileCache = Object.create(null);
2114
+ function clearCompileCache() {
2115
+ compileCache = Object.create(null);
2116
+ }
2117
+ function compileToFunction(source, options = {}) {
2118
+ {
2119
+ // check HTML message
2120
+ checkHtmlMessage(source, options);
2121
+ // check caches
2122
+ const onCacheKey = options.onCacheKey || defaultOnCacheKey;
2123
+ const key = onCacheKey(source);
2124
+ const cached = compileCache[key];
2125
+ if (cached) {
2126
+ return cached;
2127
+ }
2128
+ // compile error detecting
2129
+ let occurred = false;
2130
+ const onError = options.onError || defaultOnError;
2131
+ options.onError = (err) => {
2132
+ occurred = true;
2133
+ onError(err);
2134
+ };
2135
+ // compile
2136
+ const { code } = baseCompile(source, options);
2137
+ // evaluate function
2138
+ const msg = new Function(`return ${code}`)();
2139
+ // if occurred compile error, don't cache
2140
+ return !occurred ? (compileCache[key] = msg) : msg;
2141
+ }
2142
+ }
2143
+
2144
+ function createCoreError(code) {
2145
+ return createCompileError(code, null, { messages: errorMessages } );
2146
+ }
2147
+ /** @internal */
2148
+ const errorMessages = {
2149
+ [14 /* INVALID_ARGUMENT */]: 'Invalid arguments',
2150
+ [15 /* INVALID_DATE_ARGUMENT */]: 'The date provided is an invalid Date object.' +
2151
+ 'Make sure your Date represents a valid date.',
2152
+ [16 /* INVALID_ISO_DATE_ARGUMENT */]: 'The argument provided is not a valid ISO date string'
2153
+ };
2154
+
2155
+ const NOOP_MESSAGE_FUNCTION = () => '';
2156
+ const isMessageFunction = (val) => isFunction(val);
2157
+ // implementation of `translate` function
2158
+ function translate(context, ...args) {
2159
+ const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
2160
+ const [key, options] = parseTranslateArgs(...args);
2161
+ const missingWarn = isBoolean(options.missingWarn)
2162
+ ? options.missingWarn
2163
+ : context.missingWarn;
2164
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2165
+ ? options.fallbackWarn
2166
+ : context.fallbackWarn;
2167
+ const escapeParameter = isBoolean(options.escapeParameter)
2168
+ ? options.escapeParameter
2169
+ : context.escapeParameter;
2170
+ const resolvedMessage = !!options.resolvedMessage;
2171
+ // prettier-ignore
2172
+ const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
2173
+ ? !isBoolean(options.default)
2174
+ ? options.default
2175
+ : key
2176
+ : fallbackFormat // default by `fallbackFormat` option
2177
+ ? key
2178
+ : '';
2179
+ const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
2180
+ const locale = isString(options.locale) ? options.locale : context.locale;
2181
+ // escape params
2182
+ escapeParameter && escapeParams(options);
2183
+ // resolve message format
2184
+ // eslint-disable-next-line prefer-const
2185
+ let [format, targetLocale, message] = !resolvedMessage
2186
+ ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
2187
+ : [
2188
+ key,
2189
+ locale,
2190
+ messages[locale] || {}
2191
+ ];
2192
+ // if you use default message, set it as message format!
2193
+ let cacheBaseKey = key;
2194
+ if (!resolvedMessage &&
2195
+ !(isString(format) || isMessageFunction(format))) {
2196
+ if (enableDefaultMsg) {
2197
+ format = defaultMsgOrKey;
2198
+ cacheBaseKey = format;
2199
+ }
2200
+ }
2201
+ // checking message format and target locale
2202
+ if (!resolvedMessage &&
2203
+ (!(isString(format) || isMessageFunction(format)) ||
2204
+ !isString(targetLocale))) {
2205
+ return unresolving ? NOT_REOSLVED : key;
2206
+ }
2207
+ if (isString(format) && context.messageCompiler == null) {
2208
+ warn(`The message format compilation is not supported in this build. ` +
2209
+ `Because message compiler isn't included. ` +
2210
+ `You need to pre-compilation all message format. ` +
2211
+ `So translate function return '${key}'.`);
2212
+ return key;
2213
+ }
2214
+ // setup compile error detecting
2215
+ let occurred = false;
2216
+ const errorDetector = () => {
2217
+ occurred = true;
2218
+ };
2219
+ // compile message format
2220
+ const msg = !isMessageFunction(format)
2221
+ ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
2222
+ : format;
2223
+ // if occurred compile error, return the message format
2224
+ if (occurred) {
2225
+ return format;
2226
+ }
2227
+ // evaluate message with context
2228
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
2229
+ const msgContext = createMessageContext(ctxOptions);
2230
+ const messaged = evaluateMessage(context, msg, msgContext);
2231
+ // if use post translation option, proceed it with handler
2232
+ const ret = postTranslation ? postTranslation(messaged) : messaged;
2233
+ // NOTE: experimental !!
2234
+ {
2235
+ // prettier-ignore
2236
+ const payloads = {
2237
+ timestamp: Date.now(),
2238
+ key: isString(key)
2239
+ ? key
2240
+ : isMessageFunction(format)
2241
+ ? format.key
2242
+ : '',
2243
+ locale: targetLocale || (isMessageFunction(format)
2244
+ ? format.locale
2245
+ : ''),
2246
+ format: isString(format)
2247
+ ? format
2248
+ : isMessageFunction(format)
2249
+ ? format.source
2250
+ : '',
2251
+ message: ret
2252
+ };
2253
+ payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
2254
+ translateDevTools(payloads);
2255
+ }
2256
+ return ret;
2257
+ }
2258
+ function escapeParams(options) {
2259
+ if (isArray(options.list)) {
2260
+ options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
2261
+ }
2262
+ else if (isObject(options.named)) {
2263
+ Object.keys(options.named).forEach(key => {
2264
+ if (isString(options.named[key])) {
2265
+ options.named[key] = escapeHtml(options.named[key]);
2266
+ }
2267
+ });
2268
+ }
2269
+ }
2270
+ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
2271
+ const { messages, onWarn } = context;
2272
+ const locales = getLocaleChain(context, fallbackLocale, locale);
2273
+ let message = {};
2274
+ let targetLocale;
2275
+ let format = null;
2276
+ let from = locale;
2277
+ let to = null;
2278
+ const type = 'translate';
2279
+ for (let i = 0; i < locales.length; i++) {
2280
+ targetLocale = to = locales[i];
2281
+ if (locale !== targetLocale &&
2282
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2283
+ onWarn(getWarnMessage(1 /* FALLBACK_TO_TRANSLATE */, {
2284
+ key,
2285
+ target: targetLocale
2286
+ }));
2287
+ }
2288
+ // for vue-devtools timeline event
2289
+ if (locale !== targetLocale) {
2290
+ const emitter = context.__v_emitter;
2291
+ if (emitter) {
2292
+ emitter.emit("fallback" /* FALBACK */, {
2293
+ type,
2294
+ key,
2295
+ from,
2296
+ to,
2297
+ groupId: `${type}:${key}`
2298
+ });
2299
+ }
2300
+ }
2301
+ message =
2302
+ messages[targetLocale] || {};
2303
+ // for vue-devtools timeline event
2304
+ let start = null;
2305
+ let startTag;
2306
+ let endTag;
2307
+ if (inBrowser) {
2308
+ start = window.performance.now();
2309
+ startTag = 'intlify-message-resolve-start';
2310
+ endTag = 'intlify-message-resolve-end';
2311
+ mark && mark(startTag);
2312
+ }
2313
+ if ((format = resolveValue(message, key)) === null) {
2314
+ // if null, resolve with object key path
2315
+ format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
2316
+ }
2317
+ // for vue-devtools timeline event
2318
+ if (inBrowser) {
2319
+ const end = window.performance.now();
2320
+ const emitter = context.__v_emitter;
2321
+ if (emitter && start && format) {
2322
+ emitter.emit("message-resolve" /* MESSAGE_RESOLVE */, {
2323
+ type: "message-resolve" /* MESSAGE_RESOLVE */,
2324
+ key,
2325
+ message: format,
2326
+ time: end - start,
2327
+ groupId: `${type}:${key}`
2328
+ });
2329
+ }
2330
+ if (startTag && endTag && mark && measure) {
2331
+ mark(endTag);
2332
+ measure('intlify message resolve', startTag, endTag);
2333
+ }
2334
+ }
2335
+ if (isString(format) || isFunction(format))
2336
+ break;
2337
+ const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
2338
+ if (missingRet !== key) {
2339
+ format = missingRet;
2340
+ }
2341
+ from = to;
2342
+ }
2343
+ return [format, targetLocale, message];
2344
+ }
2345
+ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
2346
+ const { messageCompiler, warnHtmlMessage } = context;
2347
+ if (isMessageFunction(format)) {
2348
+ const msg = format;
2349
+ msg.locale = msg.locale || targetLocale;
2350
+ msg.key = msg.key || key;
2351
+ return msg;
2352
+ }
2353
+ // for vue-devtools timeline event
2354
+ let start = null;
2355
+ let startTag;
2356
+ let endTag;
2357
+ if (inBrowser) {
2358
+ start = window.performance.now();
2359
+ startTag = 'intlify-message-compilation-start';
2360
+ endTag = 'intlify-message-compilation-end';
2361
+ mark && mark(startTag);
2362
+ }
2363
+ const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
2364
+ // for vue-devtools timeline event
2365
+ if (inBrowser) {
2366
+ const end = window.performance.now();
2367
+ const emitter = context.__v_emitter;
2368
+ if (emitter && start) {
2369
+ emitter.emit("message-compilation" /* MESSAGE_COMPILATION */, {
2370
+ type: "message-compilation" /* MESSAGE_COMPILATION */,
2371
+ message: format,
2372
+ time: end - start,
2373
+ groupId: `${'translate'}:${key}`
2374
+ });
2375
+ }
2376
+ if (startTag && endTag && mark && measure) {
2377
+ mark(endTag);
2378
+ measure('intlify message compilation', startTag, endTag);
2379
+ }
2380
+ }
2381
+ msg.locale = targetLocale;
2382
+ msg.key = key;
2383
+ msg.source = format;
2384
+ return msg;
2385
+ }
2386
+ function evaluateMessage(context, msg, msgCtx) {
2387
+ // for vue-devtools timeline event
2388
+ let start = null;
2389
+ let startTag;
2390
+ let endTag;
2391
+ if (inBrowser) {
2392
+ start = window.performance.now();
2393
+ startTag = 'intlify-message-evaluation-start';
2394
+ endTag = 'intlify-message-evaluation-end';
2395
+ mark && mark(startTag);
2396
+ }
2397
+ const messaged = msg(msgCtx);
2398
+ // for vue-devtools timeline event
2399
+ if (inBrowser) {
2400
+ const end = window.performance.now();
2401
+ const emitter = context.__v_emitter;
2402
+ if (emitter && start) {
2403
+ emitter.emit("message-evaluation" /* MESSAGE_EVALUATION */, {
2404
+ type: "message-evaluation" /* MESSAGE_EVALUATION */,
2405
+ value: messaged,
2406
+ time: end - start,
2407
+ groupId: `${'translate'}:${msg.key}`
2408
+ });
2409
+ }
2410
+ if (startTag && endTag && mark && measure) {
2411
+ mark(endTag);
2412
+ measure('intlify message evaluation', startTag, endTag);
2413
+ }
2414
+ }
2415
+ return messaged;
2416
+ }
2417
+ /** @internal */
2418
+ function parseTranslateArgs(...args) {
2419
+ const [arg1, arg2, arg3] = args;
2420
+ const options = {};
2421
+ if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
2422
+ throw createCoreError(14 /* INVALID_ARGUMENT */);
2423
+ }
2424
+ // prettier-ignore
2425
+ const key = isNumber(arg1)
2426
+ ? String(arg1)
2427
+ : isMessageFunction(arg1)
2428
+ ? arg1
2429
+ : arg1;
2430
+ if (isNumber(arg2)) {
2431
+ options.plural = arg2;
2432
+ }
2433
+ else if (isString(arg2)) {
2434
+ options.default = arg2;
2435
+ }
2436
+ else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
2437
+ options.named = arg2;
2438
+ }
2439
+ else if (isArray(arg2)) {
2440
+ options.list = arg2;
2441
+ }
2442
+ if (isNumber(arg3)) {
2443
+ options.plural = arg3;
2444
+ }
2445
+ else if (isString(arg3)) {
2446
+ options.default = arg3;
2447
+ }
2448
+ else if (isPlainObject(arg3)) {
2449
+ assign(options, arg3);
2450
+ }
2451
+ return [key, options];
2452
+ }
2453
+ function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
2454
+ return {
2455
+ warnHtmlMessage,
2456
+ onError: (err) => {
2457
+ errorDetector && errorDetector(err);
2458
+ {
2459
+ const message = `Message compilation error: ${err.message}`;
2460
+ const codeFrame = err.location &&
2461
+ generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
2462
+ const emitter = context
2463
+ .__v_emitter;
2464
+ if (emitter) {
2465
+ emitter.emit("compile-error" /* COMPILE_ERROR */, {
2466
+ message: source,
2467
+ error: err.message,
2468
+ start: err.location && err.location.start.offset,
2469
+ end: err.location && err.location.end.offset,
2470
+ groupId: `${'translate'}:${key}`
2471
+ });
2472
+ }
2473
+ console.error(codeFrame ? `${message}\n${codeFrame}` : message);
2474
+ }
2475
+ },
2476
+ onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
2477
+ };
2478
+ }
2479
+ function getMessageContextOptions(context, locale, message, options) {
2480
+ const { modifiers, pluralRules } = context;
2481
+ const resolveMessage = (key) => {
2482
+ const val = resolveValue(message, key);
2483
+ if (isString(val)) {
2484
+ let occurred = false;
2485
+ const errorDetector = () => {
2486
+ occurred = true;
2487
+ };
2488
+ const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
2489
+ return !occurred
2490
+ ? msg
2491
+ : NOOP_MESSAGE_FUNCTION;
2492
+ }
2493
+ else if (isMessageFunction(val)) {
2494
+ return val;
2495
+ }
2496
+ else {
2497
+ // TODO: should be implemented warning message
2498
+ return NOOP_MESSAGE_FUNCTION;
2499
+ }
2500
+ };
2501
+ const ctxOptions = {
2502
+ locale,
2503
+ modifiers,
2504
+ pluralRules,
2505
+ messages: resolveMessage
2506
+ };
2507
+ if (context.processor) {
2508
+ ctxOptions.processor = context.processor;
2509
+ }
2510
+ if (options.list) {
2511
+ ctxOptions.list = options.list;
2512
+ }
2513
+ if (options.named) {
2514
+ ctxOptions.named = options.named;
2515
+ }
2516
+ if (isNumber(options.plural)) {
2517
+ ctxOptions.pluralIndex = options.plural;
2518
+ }
2519
+ return ctxOptions;
2520
+ }
2521
+
2522
+ const intlDefined = typeof Intl !== 'undefined';
2523
+ const Availabilities = {
2524
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
2525
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
2526
+ };
2527
+
2528
+ // implementation of `datetime` function
2529
+ function datetime(context, ...args) {
2530
+ const { datetimeFormats, unresolving, fallbackLocale, onWarn } = context;
2531
+ const { __datetimeFormatters } = context;
2532
+ if (!Availabilities.dateTimeFormat) {
2533
+ onWarn(getWarnMessage(4 /* CANNOT_FORMAT_DATE */));
2534
+ return MISSING_RESOLVE_VALUE;
2535
+ }
2536
+ const [key, value, options, overrides] = parseDateTimeArgs(...args);
2537
+ const missingWarn = isBoolean(options.missingWarn)
2538
+ ? options.missingWarn
2539
+ : context.missingWarn;
2540
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2541
+ ? options.fallbackWarn
2542
+ : context.fallbackWarn;
2543
+ const part = !!options.part;
2544
+ const locale = isString(options.locale) ? options.locale : context.locale;
2545
+ const locales = getLocaleChain(context, fallbackLocale, locale);
2546
+ if (!isString(key) || key === '') {
2547
+ return new Intl.DateTimeFormat(locale).format(value);
2548
+ }
2549
+ // resolve format
2550
+ let datetimeFormat = {};
2551
+ let targetLocale;
2552
+ let format = null;
2553
+ let from = locale;
2554
+ let to = null;
2555
+ const type = 'datetime format';
2556
+ for (let i = 0; i < locales.length; i++) {
2557
+ targetLocale = to = locales[i];
2558
+ if (locale !== targetLocale &&
2559
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2560
+ onWarn(getWarnMessage(5 /* FALLBACK_TO_DATE_FORMAT */, {
2561
+ key,
2562
+ target: targetLocale
2563
+ }));
2564
+ }
2565
+ // for vue-devtools timeline event
2566
+ if (locale !== targetLocale) {
2567
+ const emitter = context.__v_emitter;
2568
+ if (emitter) {
2569
+ emitter.emit("fallback" /* FALBACK */, {
2570
+ type,
2571
+ key,
2572
+ from,
2573
+ to,
2574
+ groupId: `${type}:${key}`
2575
+ });
2576
+ }
2577
+ }
2578
+ datetimeFormat =
2579
+ datetimeFormats[targetLocale] || {};
2580
+ format = datetimeFormat[key];
2581
+ if (isPlainObject(format))
2582
+ break;
2583
+ handleMissing(context, key, targetLocale, missingWarn, type);
2584
+ from = to;
2585
+ }
2586
+ // checking format and target locale
2587
+ if (!isPlainObject(format) || !isString(targetLocale)) {
2588
+ return unresolving ? NOT_REOSLVED : key;
2589
+ }
2590
+ let id = `${targetLocale}__${key}`;
2591
+ if (!isEmptyObject(overrides)) {
2592
+ id = `${id}__${JSON.stringify(overrides)}`;
2593
+ }
2594
+ let formatter = __datetimeFormatters.get(id);
2595
+ if (!formatter) {
2596
+ formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
2597
+ __datetimeFormatters.set(id, formatter);
2598
+ }
2599
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2600
+ }
2601
+ /** @internal */
2602
+ function parseDateTimeArgs(...args) {
2603
+ const [arg1, arg2, arg3, arg4] = args;
2604
+ let options = {};
2605
+ let overrides = {};
2606
+ let value;
2607
+ if (isString(arg1)) {
2608
+ // Only allow ISO strings - other date formats are often supported,
2609
+ // but may cause different results in different browsers.
2610
+ if (!/\d{4}-\d{2}-\d{2}(T.*)?/.test(arg1)) {
2611
+ throw createCoreError(16 /* INVALID_ISO_DATE_ARGUMENT */);
2612
+ }
2613
+ value = new Date(arg1);
2614
+ try {
2615
+ // This will fail if the date is not valid
2616
+ value.toISOString();
2617
+ }
2618
+ catch (e) {
2619
+ throw createCoreError(16 /* INVALID_ISO_DATE_ARGUMENT */);
2620
+ }
2621
+ }
2622
+ else if (isDate(arg1)) {
2623
+ if (isNaN(arg1.getTime())) {
2624
+ throw createCoreError(15 /* INVALID_DATE_ARGUMENT */);
2625
+ }
2626
+ value = arg1;
2627
+ }
2628
+ else if (isNumber(arg1)) {
2629
+ value = arg1;
2630
+ }
2631
+ else {
2632
+ throw createCoreError(14 /* INVALID_ARGUMENT */);
2633
+ }
2634
+ if (isString(arg2)) {
2635
+ options.key = arg2;
2636
+ }
2637
+ else if (isPlainObject(arg2)) {
2638
+ options = arg2;
2639
+ }
2640
+ if (isString(arg3)) {
2641
+ options.locale = arg3;
2642
+ }
2643
+ else if (isPlainObject(arg3)) {
2644
+ overrides = arg3;
2645
+ }
2646
+ if (isPlainObject(arg4)) {
2647
+ overrides = arg4;
2648
+ }
2649
+ return [options.key || '', value, options, overrides];
2650
+ }
2651
+ /** @internal */
2652
+ function clearDateTimeFormat(ctx, locale, format) {
2653
+ const context = ctx;
2654
+ for (const key in format) {
2655
+ const id = `${locale}__${key}`;
2656
+ if (!context.__datetimeFormatters.has(id)) {
2657
+ continue;
2658
+ }
2659
+ context.__datetimeFormatters.delete(id);
2660
+ }
2661
+ }
2662
+
2663
+ // implementation of `number` function
2664
+ function number(context, ...args) {
2665
+ const { numberFormats, unresolving, fallbackLocale, onWarn } = context;
2666
+ const { __numberFormatters } = context;
2667
+ if (!Availabilities.numberFormat) {
2668
+ onWarn(getWarnMessage(2 /* CANNOT_FORMAT_NUMBER */));
2669
+ return MISSING_RESOLVE_VALUE;
2670
+ }
2671
+ const [key, value, options, overrides] = parseNumberArgs(...args);
2672
+ const missingWarn = isBoolean(options.missingWarn)
2673
+ ? options.missingWarn
2674
+ : context.missingWarn;
2675
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2676
+ ? options.fallbackWarn
2677
+ : context.fallbackWarn;
2678
+ const part = !!options.part;
2679
+ const locale = isString(options.locale) ? options.locale : context.locale;
2680
+ const locales = getLocaleChain(context, fallbackLocale, locale);
2681
+ if (!isString(key) || key === '') {
2682
+ return new Intl.NumberFormat(locale).format(value);
2683
+ }
2684
+ // resolve format
2685
+ let numberFormat = {};
2686
+ let targetLocale;
2687
+ let format = null;
2688
+ let from = locale;
2689
+ let to = null;
2690
+ const type = 'number format';
2691
+ for (let i = 0; i < locales.length; i++) {
2692
+ targetLocale = to = locales[i];
2693
+ if (locale !== targetLocale &&
2694
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2695
+ onWarn(getWarnMessage(3 /* FALLBACK_TO_NUMBER_FORMAT */, {
2696
+ key,
2697
+ target: targetLocale
2698
+ }));
2699
+ }
2700
+ // for vue-devtools timeline event
2701
+ if (locale !== targetLocale) {
2702
+ const emitter = context.__v_emitter;
2703
+ if (emitter) {
2704
+ emitter.emit("fallback" /* FALBACK */, {
2705
+ type,
2706
+ key,
2707
+ from,
2708
+ to,
2709
+ groupId: `${type}:${key}`
2710
+ });
2711
+ }
2712
+ }
2713
+ numberFormat =
2714
+ numberFormats[targetLocale] || {};
2715
+ format = numberFormat[key];
2716
+ if (isPlainObject(format))
2717
+ break;
2718
+ handleMissing(context, key, targetLocale, missingWarn, type);
2719
+ from = to;
2720
+ }
2721
+ // checking format and target locale
2722
+ if (!isPlainObject(format) || !isString(targetLocale)) {
2723
+ return unresolving ? NOT_REOSLVED : key;
2724
+ }
2725
+ let id = `${targetLocale}__${key}`;
2726
+ if (!isEmptyObject(overrides)) {
2727
+ id = `${id}__${JSON.stringify(overrides)}`;
2728
+ }
2729
+ let formatter = __numberFormatters.get(id);
2730
+ if (!formatter) {
2731
+ formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
2732
+ __numberFormatters.set(id, formatter);
2733
+ }
2734
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2735
+ }
2736
+ /** @internal */
2737
+ function parseNumberArgs(...args) {
2738
+ const [arg1, arg2, arg3, arg4] = args;
2739
+ let options = {};
2740
+ let overrides = {};
2741
+ if (!isNumber(arg1)) {
2742
+ throw createCoreError(14 /* INVALID_ARGUMENT */);
2743
+ }
2744
+ const value = arg1;
2745
+ if (isString(arg2)) {
2746
+ options.key = arg2;
2747
+ }
2748
+ else if (isPlainObject(arg2)) {
2749
+ options = arg2;
2750
+ }
2751
+ if (isString(arg3)) {
2752
+ options.locale = arg3;
2753
+ }
2754
+ else if (isPlainObject(arg3)) {
2755
+ overrides = arg3;
2756
+ }
2757
+ if (isPlainObject(arg4)) {
2758
+ overrides = arg4;
2759
+ }
2760
+ return [options.key || '', value, options, overrides];
2761
+ }
2762
+ /** @internal */
2763
+ function clearNumberFormat(ctx, locale, format) {
2764
+ const context = ctx;
2765
+ for (const key in format) {
2766
+ const id = `${locale}__${key}`;
2767
+ if (!context.__numberFormatters.has(id)) {
2768
+ continue;
2769
+ }
2770
+ context.__numberFormatters.delete(id);
2771
+ }
2772
+ }
2773
+
2774
+ exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
2775
+ exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
2776
+ exports.NOT_REOSLVED = NOT_REOSLVED;
2777
+ exports.VERSION = VERSION;
2778
+ exports.clearCompileCache = clearCompileCache;
2779
+ exports.clearDateTimeFormat = clearDateTimeFormat;
2780
+ exports.clearNumberFormat = clearNumberFormat;
2781
+ exports.compileToFunction = compileToFunction;
2782
+ exports.createCompileError = createCompileError;
2783
+ exports.createCoreContext = createCoreContext;
2784
+ exports.createCoreError = createCoreError;
2785
+ exports.createMessageContext = createMessageContext;
2786
+ exports.datetime = datetime;
2787
+ exports.getAdditionalMeta = getAdditionalMeta;
2788
+ exports.getDevToolsHook = getDevToolsHook;
2789
+ exports.getLocaleChain = getLocaleChain;
2790
+ exports.getWarnMessage = getWarnMessage;
2791
+ exports.handleFlatJson = handleFlatJson;
2792
+ exports.handleMissing = handleMissing;
2793
+ exports.initI18nDevTools = initI18nDevTools;
2794
+ exports.isMessageFunction = isMessageFunction;
2795
+ exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
2796
+ exports.isTranslateMissingWarn = isTranslateMissingWarn;
2797
+ exports.number = number;
2798
+ exports.parse = parse;
2799
+ exports.parseDateTimeArgs = parseDateTimeArgs;
2800
+ exports.parseNumberArgs = parseNumberArgs;
2801
+ exports.parseTranslateArgs = parseTranslateArgs;
2802
+ exports.registerMessageCompiler = registerMessageCompiler;
2803
+ exports.resolveValue = resolveValue;
2804
+ exports.setAdditionalMeta = setAdditionalMeta;
2805
+ exports.setDevToolsHook = setDevToolsHook;
2806
+ exports.translate = translate;
2807
+ exports.translateDevTools = translateDevTools;
2808
+ exports.updateFallbackLocale = updateFallbackLocale;
2809
+
2810
+ Object.defineProperty(exports, '__esModule', { value: true });
2811
+
2812
+ return exports;
2813
+
2814
+ }({}));