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