ventojs 1.14.0 → 2.0.0-canary.0

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 (418) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +2 -0
  3. package/browser.js +19 -0
  4. package/{esm/src → core}/environment.js +30 -32
  5. package/{esm/src → core}/errors.js +0 -7
  6. package/core/js.js +191 -0
  7. package/core/reserved.js +63 -0
  8. package/core/tokenizer.js +86 -0
  9. package/highlightjs-vento.js +24 -0
  10. package/{esm/src/loader.node.js → loaders/file.js} +5 -2
  11. package/loaders/memory.js +24 -0
  12. package/loaders/url.js +28 -0
  13. package/{esm/bare.js → mod.js} +7 -2
  14. package/package.json +167 -29
  15. package/{esm/plugins → plugins}/auto_trim.js +0 -1
  16. package/plugins/echo.js +31 -0
  17. package/plugins/escape.js +17 -0
  18. package/plugins/export.js +68 -0
  19. package/{esm/plugins → plugins}/for.js +6 -10
  20. package/plugins/import.js +58 -0
  21. package/plugins/include.js +35 -0
  22. package/plugins/mod.js +30 -0
  23. package/{esm/plugins → plugins}/set.js +4 -3
  24. package/plugins/unescape.js +25 -0
  25. package/prism-vento.js +26 -0
  26. package/types/browser.d.ts +8 -0
  27. package/{esm/src → types/core}/environment.d.ts +4 -6
  28. package/{esm/src → types/core}/errors.d.ts +0 -5
  29. package/types/core/js.d.ts +11 -0
  30. package/types/core/reserved.d.ts +2 -0
  31. package/{esm/src → types/core}/tokenizer.d.ts +1 -8
  32. package/{esm/src/loader.node.d.ts → types/loaders/file.d.ts} +5 -4
  33. package/types/loaders/memory.d.ts +11 -0
  34. package/types/loaders/url.d.ts +11 -0
  35. package/{esm/bare.d.ts → types/mod.d.ts} +1 -3
  36. package/{esm → types}/plugins/auto_trim.d.ts +2 -4
  37. package/types/plugins/echo.d.ts +2 -0
  38. package/types/plugins/escape.d.ts +2 -0
  39. package/types/plugins/export.d.ts +2 -0
  40. package/types/plugins/for.d.ts +2 -0
  41. package/types/plugins/function.d.ts +2 -0
  42. package/types/plugins/if.d.ts +2 -0
  43. package/types/plugins/import.d.ts +2 -0
  44. package/types/plugins/include.d.ts +2 -0
  45. package/types/plugins/js.d.ts +2 -0
  46. package/types/plugins/layout.d.ts +2 -0
  47. package/types/plugins/mod.d.ts +2 -0
  48. package/types/plugins/set.d.ts +2 -0
  49. package/types/plugins/trim.d.ts +4 -0
  50. package/types/plugins/unescape.d.ts +2 -0
  51. package/esm/_dnt.polyfills.d.ts +0 -12
  52. package/esm/_dnt.polyfills.d.ts.map +0 -1
  53. package/esm/_dnt.polyfills.js +0 -15
  54. package/esm/_dnt.shims.d.ts +0 -2
  55. package/esm/_dnt.shims.d.ts.map +0 -1
  56. package/esm/_dnt.shims.js +0 -57
  57. package/esm/_dnt.test_polyfills.d.ts.map +0 -1
  58. package/esm/_dnt.test_shims.d.ts.map +0 -1
  59. package/esm/bare.d.ts.map +0 -1
  60. package/esm/deps/deno.land/std@0.224.0/assert/_constants.d.ts.map +0 -1
  61. package/esm/deps/deno.land/std@0.224.0/assert/assert_equals.d.ts.map +0 -1
  62. package/esm/deps/deno.land/std@0.224.0/assert/assert_is_error.d.ts.map +0 -1
  63. package/esm/deps/deno.land/std@0.224.0/assert/assert_throws.d.ts.map +0 -1
  64. package/esm/deps/deno.land/std@0.224.0/assert/assertion_error.d.ts.map +0 -1
  65. package/esm/deps/deno.land/std@0.224.0/assert/equal.d.ts.map +0 -1
  66. package/esm/deps/deno.land/std@0.224.0/collections/_utils.d.ts.map +0 -1
  67. package/esm/deps/deno.land/std@0.224.0/collections/deep_merge.d.ts.map +0 -1
  68. package/esm/deps/deno.land/std@0.224.0/fmt/colors.d.ts.map +0 -1
  69. package/esm/deps/deno.land/std@0.224.0/front_matter/_formats.d.ts.map +0 -1
  70. package/esm/deps/deno.land/std@0.224.0/front_matter/create_extractor.d.ts.map +0 -1
  71. package/esm/deps/deno.land/std@0.224.0/front_matter/json.d.ts.map +0 -1
  72. package/esm/deps/deno.land/std@0.224.0/front_matter/mod.d.ts.map +0 -1
  73. package/esm/deps/deno.land/std@0.224.0/front_matter/test.d.ts.map +0 -1
  74. package/esm/deps/deno.land/std@0.224.0/front_matter/toml.d.ts.map +0 -1
  75. package/esm/deps/deno.land/std@0.224.0/front_matter/yaml.d.ts.map +0 -1
  76. package/esm/deps/deno.land/std@0.224.0/internal/diff.d.ts.map +0 -1
  77. package/esm/deps/deno.land/std@0.224.0/internal/format.d.ts.map +0 -1
  78. package/esm/deps/deno.land/std@0.224.0/internal/mod.d.ts.map +0 -1
  79. package/esm/deps/deno.land/std@0.224.0/toml/_parser.d.ts.map +0 -1
  80. package/esm/deps/deno.land/std@0.224.0/toml/parse.d.ts.map +0 -1
  81. package/esm/deps/deno.land/std@0.224.0/yaml/_error.d.ts.map +0 -1
  82. package/esm/deps/deno.land/std@0.224.0/yaml/_loader/loader.d.ts.map +0 -1
  83. package/esm/deps/deno.land/std@0.224.0/yaml/_loader/loader_state.d.ts.map +0 -1
  84. package/esm/deps/deno.land/std@0.224.0/yaml/_mark.d.ts.map +0 -1
  85. package/esm/deps/deno.land/std@0.224.0/yaml/_state.d.ts.map +0 -1
  86. package/esm/deps/deno.land/std@0.224.0/yaml/_type/binary.d.ts.map +0 -1
  87. package/esm/deps/deno.land/std@0.224.0/yaml/_type/bool.d.ts.map +0 -1
  88. package/esm/deps/deno.land/std@0.224.0/yaml/_type/float.d.ts.map +0 -1
  89. package/esm/deps/deno.land/std@0.224.0/yaml/_type/function.d.ts.map +0 -1
  90. package/esm/deps/deno.land/std@0.224.0/yaml/_type/int.d.ts.map +0 -1
  91. package/esm/deps/deno.land/std@0.224.0/yaml/_type/map.d.ts.map +0 -1
  92. package/esm/deps/deno.land/std@0.224.0/yaml/_type/merge.d.ts.map +0 -1
  93. package/esm/deps/deno.land/std@0.224.0/yaml/_type/mod.d.ts.map +0 -1
  94. package/esm/deps/deno.land/std@0.224.0/yaml/_type/nil.d.ts.map +0 -1
  95. package/esm/deps/deno.land/std@0.224.0/yaml/_type/omap.d.ts.map +0 -1
  96. package/esm/deps/deno.land/std@0.224.0/yaml/_type/pairs.d.ts.map +0 -1
  97. package/esm/deps/deno.land/std@0.224.0/yaml/_type/regexp.d.ts.map +0 -1
  98. package/esm/deps/deno.land/std@0.224.0/yaml/_type/seq.d.ts.map +0 -1
  99. package/esm/deps/deno.land/std@0.224.0/yaml/_type/set.d.ts.map +0 -1
  100. package/esm/deps/deno.land/std@0.224.0/yaml/_type/str.d.ts.map +0 -1
  101. package/esm/deps/deno.land/std@0.224.0/yaml/_type/timestamp.d.ts.map +0 -1
  102. package/esm/deps/deno.land/std@0.224.0/yaml/_type/undefined.d.ts.map +0 -1
  103. package/esm/deps/deno.land/std@0.224.0/yaml/_utils.d.ts.map +0 -1
  104. package/esm/deps/deno.land/std@0.224.0/yaml/parse.d.ts.map +0 -1
  105. package/esm/deps/deno.land/std@0.224.0/yaml/schema/core.d.ts.map +0 -1
  106. package/esm/deps/deno.land/std@0.224.0/yaml/schema/default.d.ts.map +0 -1
  107. package/esm/deps/deno.land/std@0.224.0/yaml/schema/extended.d.ts.map +0 -1
  108. package/esm/deps/deno.land/std@0.224.0/yaml/schema/failsafe.d.ts.map +0 -1
  109. package/esm/deps/deno.land/std@0.224.0/yaml/schema/json.d.ts.map +0 -1
  110. package/esm/deps/deno.land/std@0.224.0/yaml/schema/mod.d.ts.map +0 -1
  111. package/esm/deps/deno.land/std@0.224.0/yaml/schema.d.ts.map +0 -1
  112. package/esm/deps/deno.land/std@0.224.0/yaml/type.d.ts.map +0 -1
  113. package/esm/deps/jsr.io/@davidbonnet/astring/1.8.6/src/astring.d.ts +0 -110
  114. package/esm/deps/jsr.io/@davidbonnet/astring/1.8.6/src/astring.d.ts.map +0 -1
  115. package/esm/deps/jsr.io/@davidbonnet/astring/1.8.6/src/astring.js +0 -1159
  116. package/esm/deps/jsr.io/@std/html/1.0.3/entities.d.ts +0 -57
  117. package/esm/deps/jsr.io/@std/html/1.0.3/entities.d.ts.map +0 -1
  118. package/esm/deps/jsr.io/@std/html/1.0.3/entities.js +0 -92
  119. package/esm/deps/jsr.io/@std/html/1.0.3/mod.d.ts +0 -15
  120. package/esm/deps/jsr.io/@std/html/1.0.3/mod.d.ts.map +0 -1
  121. package/esm/deps/jsr.io/@std/html/1.0.3/mod.js +0 -16
  122. package/esm/deps/jsr.io/@std/path/1.0.8/_common/assert_path.d.ts +0 -2
  123. package/esm/deps/jsr.io/@std/path/1.0.8/_common/assert_path.d.ts.map +0 -1
  124. package/esm/deps/jsr.io/@std/path/1.0.8/_common/assert_path.js +0 -7
  125. package/esm/deps/jsr.io/@std/path/1.0.8/_common/basename.d.ts +0 -4
  126. package/esm/deps/jsr.io/@std/path/1.0.8/_common/basename.d.ts.map +0 -1
  127. package/esm/deps/jsr.io/@std/path/1.0.8/_common/basename.js +0 -40
  128. package/esm/deps/jsr.io/@std/path/1.0.8/_common/common.d.ts +0 -2
  129. package/esm/deps/jsr.io/@std/path/1.0.8/_common/common.d.ts.map +0 -1
  130. package/esm/deps/jsr.io/@std/path/1.0.8/_common/common.js +0 -23
  131. package/esm/deps/jsr.io/@std/path/1.0.8/_common/constants.d.ts +0 -40
  132. package/esm/deps/jsr.io/@std/path/1.0.8/_common/constants.d.ts.map +0 -1
  133. package/esm/deps/jsr.io/@std/path/1.0.8/_common/constants.js +0 -46
  134. package/esm/deps/jsr.io/@std/path/1.0.8/_common/dirname.d.ts +0 -2
  135. package/esm/deps/jsr.io/@std/path/1.0.8/_common/dirname.d.ts.map +0 -1
  136. package/esm/deps/jsr.io/@std/path/1.0.8/_common/dirname.js +0 -8
  137. package/esm/deps/jsr.io/@std/path/1.0.8/_common/format.d.ts +0 -4
  138. package/esm/deps/jsr.io/@std/path/1.0.8/_common/format.d.ts.map +0 -1
  139. package/esm/deps/jsr.io/@std/path/1.0.8/_common/format.js +0 -19
  140. package/esm/deps/jsr.io/@std/path/1.0.8/_common/from_file_url.d.ts +0 -3
  141. package/esm/deps/jsr.io/@std/path/1.0.8/_common/from_file_url.d.ts.map +0 -1
  142. package/esm/deps/jsr.io/@std/path/1.0.8/_common/from_file_url.js +0 -9
  143. package/esm/deps/jsr.io/@std/path/1.0.8/_common/glob_to_reg_exp.d.ts +0 -35
  144. package/esm/deps/jsr.io/@std/path/1.0.8/_common/glob_to_reg_exp.d.ts.map +0 -1
  145. package/esm/deps/jsr.io/@std/path/1.0.8/_common/glob_to_reg_exp.js +0 -234
  146. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize.d.ts +0 -2
  147. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize.d.ts.map +0 -1
  148. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize.js +0 -8
  149. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize_string.d.ts +0 -2
  150. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize_string.d.ts.map +0 -1
  151. package/esm/deps/jsr.io/@std/path/1.0.8/_common/normalize_string.js +0 -77
  152. package/esm/deps/jsr.io/@std/path/1.0.8/_common/relative.d.ts +0 -2
  153. package/esm/deps/jsr.io/@std/path/1.0.8/_common/relative.d.ts.map +0 -1
  154. package/esm/deps/jsr.io/@std/path/1.0.8/_common/relative.js +0 -9
  155. package/esm/deps/jsr.io/@std/path/1.0.8/_common/strip_trailing_separators.d.ts +0 -2
  156. package/esm/deps/jsr.io/@std/path/1.0.8/_common/strip_trailing_separators.d.ts.map +0 -1
  157. package/esm/deps/jsr.io/@std/path/1.0.8/_common/strip_trailing_separators.js +0 -19
  158. package/esm/deps/jsr.io/@std/path/1.0.8/_common/to_file_url.d.ts +0 -2
  159. package/esm/deps/jsr.io/@std/path/1.0.8/_common/to_file_url.d.ts.map +0 -1
  160. package/esm/deps/jsr.io/@std/path/1.0.8/_common/to_file_url.js +0 -15
  161. package/esm/deps/jsr.io/@std/path/1.0.8/_os.d.ts +0 -2
  162. package/esm/deps/jsr.io/@std/path/1.0.8/_os.d.ts.map +0 -1
  163. package/esm/deps/jsr.io/@std/path/1.0.8/_os.js +0 -9
  164. package/esm/deps/jsr.io/@std/path/1.0.8/basename.d.ts +0 -28
  165. package/esm/deps/jsr.io/@std/path/1.0.8/basename.d.ts.map +0 -1
  166. package/esm/deps/jsr.io/@std/path/1.0.8/basename.js +0 -36
  167. package/esm/deps/jsr.io/@std/path/1.0.8/common.d.ts +0 -28
  168. package/esm/deps/jsr.io/@std/path/1.0.8/common.d.ts.map +0 -1
  169. package/esm/deps/jsr.io/@std/path/1.0.8/common.js +0 -33
  170. package/esm/deps/jsr.io/@std/path/1.0.8/constants.d.ts +0 -15
  171. package/esm/deps/jsr.io/@std/path/1.0.8/constants.d.ts.map +0 -1
  172. package/esm/deps/jsr.io/@std/path/1.0.8/constants.js +0 -17
  173. package/esm/deps/jsr.io/@std/path/1.0.8/dirname.d.ts +0 -23
  174. package/esm/deps/jsr.io/@std/path/1.0.8/dirname.d.ts.map +0 -1
  175. package/esm/deps/jsr.io/@std/path/1.0.8/dirname.js +0 -29
  176. package/esm/deps/jsr.io/@std/path/1.0.8/extname.d.ts +0 -23
  177. package/esm/deps/jsr.io/@std/path/1.0.8/extname.d.ts.map +0 -1
  178. package/esm/deps/jsr.io/@std/path/1.0.8/extname.js +0 -29
  179. package/esm/deps/jsr.io/@std/path/1.0.8/format.d.ts +0 -22
  180. package/esm/deps/jsr.io/@std/path/1.0.8/format.d.ts.map +0 -1
  181. package/esm/deps/jsr.io/@std/path/1.0.8/format.js +0 -27
  182. package/esm/deps/jsr.io/@std/path/1.0.8/from_file_url.d.ts +0 -23
  183. package/esm/deps/jsr.io/@std/path/1.0.8/from_file_url.d.ts.map +0 -1
  184. package/esm/deps/jsr.io/@std/path/1.0.8/from_file_url.js +0 -28
  185. package/esm/deps/jsr.io/@std/path/1.0.8/glob_to_regexp.d.ts +0 -77
  186. package/esm/deps/jsr.io/@std/path/1.0.8/glob_to_regexp.d.ts.map +0 -1
  187. package/esm/deps/jsr.io/@std/path/1.0.8/glob_to_regexp.js +0 -83
  188. package/esm/deps/jsr.io/@std/path/1.0.8/is_absolute.d.ts +0 -22
  189. package/esm/deps/jsr.io/@std/path/1.0.8/is_absolute.d.ts.map +0 -1
  190. package/esm/deps/jsr.io/@std/path/1.0.8/is_absolute.js +0 -28
  191. package/esm/deps/jsr.io/@std/path/1.0.8/is_glob.d.ts +0 -17
  192. package/esm/deps/jsr.io/@std/path/1.0.8/is_glob.d.ts.map +0 -1
  193. package/esm/deps/jsr.io/@std/path/1.0.8/is_glob.js +0 -42
  194. package/esm/deps/jsr.io/@std/path/1.0.8/join.d.ts +0 -23
  195. package/esm/deps/jsr.io/@std/path/1.0.8/join.d.ts.map +0 -1
  196. package/esm/deps/jsr.io/@std/path/1.0.8/join.js +0 -29
  197. package/esm/deps/jsr.io/@std/path/1.0.8/join_globs.d.ts +0 -28
  198. package/esm/deps/jsr.io/@std/path/1.0.8/join_globs.d.ts.map +0 -1
  199. package/esm/deps/jsr.io/@std/path/1.0.8/join_globs.js +0 -34
  200. package/esm/deps/jsr.io/@std/path/1.0.8/mod.d.ts +0 -54
  201. package/esm/deps/jsr.io/@std/path/1.0.8/mod.d.ts.map +0 -1
  202. package/esm/deps/jsr.io/@std/path/1.0.8/mod.js +0 -57
  203. package/esm/deps/jsr.io/@std/path/1.0.8/normalize.d.ts +0 -27
  204. package/esm/deps/jsr.io/@std/path/1.0.8/normalize.d.ts.map +0 -1
  205. package/esm/deps/jsr.io/@std/path/1.0.8/normalize.js +0 -33
  206. package/esm/deps/jsr.io/@std/path/1.0.8/normalize_glob.d.ts +0 -29
  207. package/esm/deps/jsr.io/@std/path/1.0.8/normalize_glob.d.ts.map +0 -1
  208. package/esm/deps/jsr.io/@std/path/1.0.8/normalize_glob.js +0 -35
  209. package/esm/deps/jsr.io/@std/path/1.0.8/parse.d.ts +0 -35
  210. package/esm/deps/jsr.io/@std/path/1.0.8/parse.d.ts.map +0 -1
  211. package/esm/deps/jsr.io/@std/path/1.0.8/parse.js +0 -39
  212. package/esm/deps/jsr.io/@std/path/1.0.8/posix/_util.d.ts +0 -2
  213. package/esm/deps/jsr.io/@std/path/1.0.8/posix/_util.d.ts.map +0 -1
  214. package/esm/deps/jsr.io/@std/path/1.0.8/posix/_util.js +0 -8
  215. package/esm/deps/jsr.io/@std/path/1.0.8/posix/basename.d.ts +0 -40
  216. package/esm/deps/jsr.io/@std/path/1.0.8/posix/basename.d.ts.map +0 -1
  217. package/esm/deps/jsr.io/@std/path/1.0.8/posix/basename.js +0 -49
  218. package/esm/deps/jsr.io/@std/path/1.0.8/posix/common.d.ts +0 -19
  219. package/esm/deps/jsr.io/@std/path/1.0.8/posix/common.d.ts.map +0 -1
  220. package/esm/deps/jsr.io/@std/path/1.0.8/posix/common.js +0 -24
  221. package/esm/deps/jsr.io/@std/path/1.0.8/posix/constants.d.ts +0 -13
  222. package/esm/deps/jsr.io/@std/path/1.0.8/posix/constants.d.ts.map +0 -1
  223. package/esm/deps/jsr.io/@std/path/1.0.8/posix/constants.js +0 -14
  224. package/esm/deps/jsr.io/@std/path/1.0.8/posix/dirname.d.ts +0 -32
  225. package/esm/deps/jsr.io/@std/path/1.0.8/posix/dirname.d.ts.map +0 -1
  226. package/esm/deps/jsr.io/@std/path/1.0.8/posix/dirname.js +0 -62
  227. package/esm/deps/jsr.io/@std/path/1.0.8/posix/extname.d.ts +0 -37
  228. package/esm/deps/jsr.io/@std/path/1.0.8/posix/extname.d.ts.map +0 -1
  229. package/esm/deps/jsr.io/@std/path/1.0.8/posix/extname.js +0 -89
  230. package/esm/deps/jsr.io/@std/path/1.0.8/posix/format.d.ts +0 -24
  231. package/esm/deps/jsr.io/@std/path/1.0.8/posix/format.d.ts.map +0 -1
  232. package/esm/deps/jsr.io/@std/path/1.0.8/posix/format.js +0 -28
  233. package/esm/deps/jsr.io/@std/path/1.0.8/posix/from_file_url.d.ts +0 -17
  234. package/esm/deps/jsr.io/@std/path/1.0.8/posix/from_file_url.d.ts.map +0 -1
  235. package/esm/deps/jsr.io/@std/path/1.0.8/posix/from_file_url.js +0 -21
  236. package/esm/deps/jsr.io/@std/path/1.0.8/posix/glob_to_regexp.d.ts +0 -72
  237. package/esm/deps/jsr.io/@std/path/1.0.8/posix/glob_to_regexp.d.ts.map +0 -1
  238. package/esm/deps/jsr.io/@std/path/1.0.8/posix/glob_to_regexp.js +0 -82
  239. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_absolute.d.ts +0 -17
  240. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_absolute.d.ts.map +0 -1
  241. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_absolute.js +0 -23
  242. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_glob.d.ts +0 -2
  243. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_glob.d.ts.map +0 -1
  244. package/esm/deps/jsr.io/@std/path/1.0.8/posix/is_glob.js +0 -3
  245. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join.d.ts +0 -33
  246. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join.d.ts.map +0 -1
  247. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join.js +0 -42
  248. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join_globs.d.ts +0 -20
  249. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join_globs.d.ts.map +0 -1
  250. package/esm/deps/jsr.io/@std/path/1.0.8/posix/join_globs.js +0 -40
  251. package/esm/deps/jsr.io/@std/path/1.0.8/posix/mod.d.ts +0 -40
  252. package/esm/deps/jsr.io/@std/path/1.0.8/posix/mod.d.ts.map +0 -1
  253. package/esm/deps/jsr.io/@std/path/1.0.8/posix/mod.js +0 -43
  254. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize.d.ts +0 -40
  255. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize.d.ts.map +0 -1
  256. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize.js +0 -57
  257. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize_glob.d.ts +0 -20
  258. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize_glob.d.ts.map +0 -1
  259. package/esm/deps/jsr.io/@std/path/1.0.8/posix/normalize_glob.js +0 -32
  260. package/esm/deps/jsr.io/@std/path/1.0.8/posix/parse.d.ts +0 -25
  261. package/esm/deps/jsr.io/@std/path/1.0.8/posix/parse.d.ts.map +0 -1
  262. package/esm/deps/jsr.io/@std/path/1.0.8/posix/parse.js +0 -115
  263. package/esm/deps/jsr.io/@std/path/1.0.8/posix/relative.d.ts +0 -20
  264. package/esm/deps/jsr.io/@std/path/1.0.8/posix/relative.d.ts.map +0 -1
  265. package/esm/deps/jsr.io/@std/path/1.0.8/posix/relative.js +0 -106
  266. package/esm/deps/jsr.io/@std/path/1.0.8/posix/resolve.d.ts +0 -17
  267. package/esm/deps/jsr.io/@std/path/1.0.8/posix/resolve.d.ts.map +0 -1
  268. package/esm/deps/jsr.io/@std/path/1.0.8/posix/resolve.js +0 -59
  269. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_file_url.d.ts +0 -18
  270. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_file_url.d.ts.map +0 -1
  271. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_file_url.js +0 -27
  272. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_namespaced_path.d.ts +0 -16
  273. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_namespaced_path.d.ts.map +0 -1
  274. package/esm/deps/jsr.io/@std/path/1.0.8/posix/to_namespaced_path.js +0 -20
  275. package/esm/deps/jsr.io/@std/path/1.0.8/relative.d.ts +0 -24
  276. package/esm/deps/jsr.io/@std/path/1.0.8/relative.d.ts.map +0 -1
  277. package/esm/deps/jsr.io/@std/path/1.0.8/relative.js +0 -30
  278. package/esm/deps/jsr.io/@std/path/1.0.8/resolve.d.ts +0 -22
  279. package/esm/deps/jsr.io/@std/path/1.0.8/resolve.d.ts.map +0 -1
  280. package/esm/deps/jsr.io/@std/path/1.0.8/resolve.js +0 -30
  281. package/esm/deps/jsr.io/@std/path/1.0.8/to_file_url.d.ts +0 -23
  282. package/esm/deps/jsr.io/@std/path/1.0.8/to_file_url.d.ts.map +0 -1
  283. package/esm/deps/jsr.io/@std/path/1.0.8/to_file_url.js +0 -28
  284. package/esm/deps/jsr.io/@std/path/1.0.8/to_namespaced_path.d.ts +0 -21
  285. package/esm/deps/jsr.io/@std/path/1.0.8/to_namespaced_path.d.ts.map +0 -1
  286. package/esm/deps/jsr.io/@std/path/1.0.8/to_namespaced_path.js +0 -29
  287. package/esm/deps/jsr.io/@std/path/1.0.8/types.d.ts +0 -38
  288. package/esm/deps/jsr.io/@std/path/1.0.8/types.d.ts.map +0 -1
  289. package/esm/deps/jsr.io/@std/path/1.0.8/types.js +0 -3
  290. package/esm/deps/jsr.io/@std/path/1.0.8/windows/_util.d.ts +0 -4
  291. package/esm/deps/jsr.io/@std/path/1.0.8/windows/_util.d.ts.map +0 -1
  292. package/esm/deps/jsr.io/@std/path/1.0.8/windows/_util.js +0 -15
  293. package/esm/deps/jsr.io/@std/path/1.0.8/windows/basename.d.ts +0 -23
  294. package/esm/deps/jsr.io/@std/path/1.0.8/windows/basename.d.ts.map +0 -1
  295. package/esm/deps/jsr.io/@std/path/1.0.8/windows/basename.js +0 -44
  296. package/esm/deps/jsr.io/@std/path/1.0.8/windows/constants.d.ts +0 -13
  297. package/esm/deps/jsr.io/@std/path/1.0.8/windows/constants.d.ts.map +0 -1
  298. package/esm/deps/jsr.io/@std/path/1.0.8/windows/constants.js +0 -14
  299. package/esm/deps/jsr.io/@std/path/1.0.8/windows/dirname.d.ts +0 -20
  300. package/esm/deps/jsr.io/@std/path/1.0.8/windows/dirname.d.ts.map +0 -1
  301. package/esm/deps/jsr.io/@std/path/1.0.8/windows/dirname.js +0 -112
  302. package/esm/deps/jsr.io/@std/path/1.0.8/windows/extname.d.ts +0 -20
  303. package/esm/deps/jsr.io/@std/path/1.0.8/windows/extname.d.ts.map +0 -1
  304. package/esm/deps/jsr.io/@std/path/1.0.8/windows/extname.js +0 -81
  305. package/esm/deps/jsr.io/@std/path/1.0.8/windows/format.d.ts +0 -24
  306. package/esm/deps/jsr.io/@std/path/1.0.8/windows/format.d.ts.map +0 -1
  307. package/esm/deps/jsr.io/@std/path/1.0.8/windows/format.js +0 -28
  308. package/esm/deps/jsr.io/@std/path/1.0.8/windows/from_file_url.d.ts +0 -19
  309. package/esm/deps/jsr.io/@std/path/1.0.8/windows/from_file_url.d.ts.map +0 -1
  310. package/esm/deps/jsr.io/@std/path/1.0.8/windows/from_file_url.js +0 -30
  311. package/esm/deps/jsr.io/@std/path/1.0.8/windows/glob_to_regexp.d.ts +0 -71
  312. package/esm/deps/jsr.io/@std/path/1.0.8/windows/glob_to_regexp.d.ts.map +0 -1
  313. package/esm/deps/jsr.io/@std/path/1.0.8/windows/glob_to_regexp.js +0 -82
  314. package/esm/deps/jsr.io/@std/path/1.0.8/windows/is_absolute.d.ts +0 -17
  315. package/esm/deps/jsr.io/@std/path/1.0.8/windows/is_absolute.d.ts.map +0 -1
  316. package/esm/deps/jsr.io/@std/path/1.0.8/windows/is_absolute.js +0 -38
  317. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join.d.ts +0 -20
  318. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join.d.ts.map +0 -1
  319. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join.js +0 -74
  320. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join_globs.d.ts +0 -21
  321. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join_globs.d.ts.map +0 -1
  322. package/esm/deps/jsr.io/@std/path/1.0.8/windows/join_globs.js +0 -41
  323. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize.d.ts +0 -22
  324. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize.d.ts.map +0 -1
  325. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize.js +0 -134
  326. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize_glob.d.ts +0 -20
  327. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize_glob.d.ts.map +0 -1
  328. package/esm/deps/jsr.io/@std/path/1.0.8/windows/normalize_glob.js +0 -32
  329. package/esm/deps/jsr.io/@std/path/1.0.8/windows/parse.d.ts +0 -25
  330. package/esm/deps/jsr.io/@std/path/1.0.8/windows/parse.d.ts.map +0 -1
  331. package/esm/deps/jsr.io/@std/path/1.0.8/windows/parse.js +0 -176
  332. package/esm/deps/jsr.io/@std/path/1.0.8/windows/relative.d.ts +0 -23
  333. package/esm/deps/jsr.io/@std/path/1.0.8/windows/relative.d.ts.map +0 -1
  334. package/esm/deps/jsr.io/@std/path/1.0.8/windows/relative.js +0 -131
  335. package/esm/deps/jsr.io/@std/path/1.0.8/windows/resolve.d.ts +0 -17
  336. package/esm/deps/jsr.io/@std/path/1.0.8/windows/resolve.d.ts.map +0 -1
  337. package/esm/deps/jsr.io/@std/path/1.0.8/windows/resolve.js +0 -154
  338. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_file_url.d.ts +0 -18
  339. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_file_url.d.ts.map +0 -1
  340. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_file_url.js +0 -34
  341. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_namespaced_path.d.ts +0 -17
  342. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_namespaced_path.d.ts.map +0 -1
  343. package/esm/deps/jsr.io/@std/path/1.0.8/windows/to_namespaced_path.js +0 -49
  344. package/esm/deps.d.ts +0 -8
  345. package/esm/deps.d.ts.map +0 -1
  346. package/esm/deps.js +0 -6
  347. package/esm/mod.d.ts +0 -9
  348. package/esm/mod.d.ts.map +0 -1
  349. package/esm/mod.js +0 -36
  350. package/esm/package.json +0 -3
  351. package/esm/plugins/auto_trim.d.ts.map +0 -1
  352. package/esm/plugins/echo.d.ts +0 -3
  353. package/esm/plugins/echo.d.ts.map +0 -1
  354. package/esm/plugins/echo.js +0 -13
  355. package/esm/plugins/escape.d.ts +0 -3
  356. package/esm/plugins/escape.d.ts.map +0 -1
  357. package/esm/plugins/escape.js +0 -7
  358. package/esm/plugins/export.d.ts +0 -3
  359. package/esm/plugins/export.d.ts.map +0 -1
  360. package/esm/plugins/export.js +0 -47
  361. package/esm/plugins/for.d.ts +0 -3
  362. package/esm/plugins/for.d.ts.map +0 -1
  363. package/esm/plugins/function.d.ts +0 -3
  364. package/esm/plugins/function.d.ts.map +0 -1
  365. package/esm/plugins/if.d.ts +0 -3
  366. package/esm/plugins/if.d.ts.map +0 -1
  367. package/esm/plugins/import.d.ts +0 -3
  368. package/esm/plugins/import.d.ts.map +0 -1
  369. package/esm/plugins/import.js +0 -17
  370. package/esm/plugins/include.d.ts +0 -3
  371. package/esm/plugins/include.d.ts.map +0 -1
  372. package/esm/plugins/include.js +0 -31
  373. package/esm/plugins/js.d.ts +0 -3
  374. package/esm/plugins/js.d.ts.map +0 -1
  375. package/esm/plugins/layout.d.ts +0 -3
  376. package/esm/plugins/layout.d.ts.map +0 -1
  377. package/esm/plugins/set.d.ts +0 -3
  378. package/esm/plugins/set.d.ts.map +0 -1
  379. package/esm/plugins/trim.d.ts +0 -5
  380. package/esm/plugins/trim.d.ts.map +0 -1
  381. package/esm/plugins/unescape.d.ts +0 -3
  382. package/esm/plugins/unescape.d.ts.map +0 -1
  383. package/esm/plugins/unescape.js +0 -7
  384. package/esm/src/environment.d.ts.map +0 -1
  385. package/esm/src/errors.d.ts.map +0 -1
  386. package/esm/src/js.d.ts +0 -5
  387. package/esm/src/js.d.ts.map +0 -1
  388. package/esm/src/js.js +0 -197
  389. package/esm/src/loader.node.d.ts.map +0 -1
  390. package/esm/src/tokenizer.d.ts.map +0 -1
  391. package/esm/src/tokenizer.js +0 -93
  392. package/esm/src/transformer.d.ts +0 -2
  393. package/esm/src/transformer.d.ts.map +0 -1
  394. package/esm/src/transformer.js +0 -218
  395. package/esm/test/auto_trim.test.d.ts.map +0 -1
  396. package/esm/test/comment.test.d.ts.map +0 -1
  397. package/esm/test/compile.test.d.ts.map +0 -1
  398. package/esm/test/echo.test.d.ts.map +0 -1
  399. package/esm/test/escape.test.d.ts.map +0 -1
  400. package/esm/test/for.test.d.ts.map +0 -1
  401. package/esm/test/function.test.d.ts.map +0 -1
  402. package/esm/test/if.test.d.ts.map +0 -1
  403. package/esm/test/import.test.d.ts.map +0 -1
  404. package/esm/test/include.test.d.ts.map +0 -1
  405. package/esm/test/js.test.d.ts.map +0 -1
  406. package/esm/test/layout.test.d.ts.map +0 -1
  407. package/esm/test/print.test.d.ts.map +0 -1
  408. package/esm/test/safe.test.d.ts.map +0 -1
  409. package/esm/test/set.test.d.ts.map +0 -1
  410. package/esm/test/tokenizer.test.d.ts.map +0 -1
  411. package/esm/test/unescape.test.d.ts.map +0 -1
  412. package/esm/test/utils.d.ts.map +0 -1
  413. package/esm/test/with.test.d.ts.map +0 -1
  414. /package/{esm/plugins → plugins}/function.js +0 -0
  415. /package/{esm/plugins → plugins}/if.js +0 -0
  416. /package/{esm/plugins → plugins}/js.js +0 -0
  417. /package/{esm/plugins → plugins}/layout.js +0 -0
  418. /package/{esm/plugins → plugins}/trim.js +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## 2.0.0 - Unreleased
8
+ Vento 2.0 is now dependency-free and compatible with browsers without requiring a build process.
9
+
10
+ ### Added
11
+ - Build-less browser support.
12
+ - `plugins/mod.ts` module to register all default plugins easily.
13
+
14
+ ### Changed
15
+ - Renamed `src` directory to `core`.
16
+ - Moved all loaders to the `loaders` root directory.
17
+ - Implemented a different approach to resolve the variables without using `meriyah` to analyze the code. [#128]
18
+
19
+ ### Removed
20
+ - Deprecated option `useWith`.
21
+ - All extenal dependencies (`meriyah`, `estree`, etc).
22
+ - `bare.ts` file since now it's useless.
23
+
24
+ [#128]: https://github.com/ventojs/vento/issues/128
package/README.md CHANGED
@@ -20,6 +20,8 @@ Nunjucks, Liquid, Mustache, and EJS.
20
20
  ## Features
21
21
 
22
22
  - Minimal, fast runtime. 🔥
23
+ - No dependencies.
24
+ - Compatible with browsers and JS runtimes (Deno, Node, Bun, etc).
23
25
  - Ergonomic by design. All tags and outputs are written with `{{` and `}}`.
24
26
  - Write JavaScript anywhere. `{{ await user.getName() }}` is real JS executed at
25
27
  runtime.
package/browser.js ADDED
@@ -0,0 +1,19 @@
1
+ import { Environment } from "./core/environment.js";
2
+ import { UrlLoader } from "./loaders/url.js";
3
+ import defaultPlugins from "./plugins/mod.js";
4
+ export default function (options) {
5
+ // Determine the loader based on the includes option
6
+ const loader = options.includes instanceof URL
7
+ ? new UrlLoader(options.includes)
8
+ : options.includes;
9
+ // Create a new Environment instance with the provided options
10
+ const env = new Environment({
11
+ loader,
12
+ dataVarname: options.dataVarname || "it",
13
+ autoescape: options.autoescape ?? false,
14
+ autoDataVarname: options.autoDataVarname ?? true,
15
+ });
16
+ // Register the default plugins
17
+ env.use(defaultPlugins());
18
+ return env;
19
+ }
@@ -1,8 +1,6 @@
1
- import "../_dnt.polyfills.js";
2
- import * as dntShim from "../_dnt.shims.js";
1
+ import iterateTopLevel from "./js.js";
3
2
  import tokenize from "./tokenizer.js";
4
- import { transformTemplateCode } from "./transformer.js";
5
- import { TemplateError, TransformError } from "./errors.js";
3
+ import { TemplateError } from "./errors.js";
6
4
  export class Environment {
7
5
  cache = new Map();
8
6
  options;
@@ -26,7 +24,7 @@ export class Environment {
26
24
  if (file) {
27
25
  const cached = this.cache.get(file);
28
26
  if (cached) {
29
- return await cached(data);
27
+ return (await cached)(data);
30
28
  }
31
29
  const template = this.compile(source, file);
32
30
  this.cache.set(file, template);
@@ -47,14 +45,16 @@ export class Environment {
47
45
  let code = this.compileTokens(tokens).join("\n");
48
46
  const { dataVarname, autoDataVarname } = this.options;
49
47
  if (autoDataVarname) {
50
- try {
51
- code = transformTemplateCode(code, dataVarname);
52
- }
53
- catch (cause) {
54
- if (cause instanceof TransformError) {
55
- throw new TemplateError(path, source, cause.position, cause);
56
- }
57
- throw new Error(`Unknown error while transforming ${path}`, { cause });
48
+ const generator = iterateTopLevel(code);
49
+ const [, , variables] = generator.next().value;
50
+ while (!generator.next().done)
51
+ ;
52
+ variables.delete(dataVarname);
53
+ if (variables.size > 0) {
54
+ code = `
55
+ var {${[...variables].join(",")}} = ${dataVarname};
56
+ {\n${code}\n}
57
+ `;
58
58
  }
59
59
  }
60
60
  const constructor = new Function("__file", "__env", "__defaults", "__err", `return${sync ? "" : " async"} function (${dataVarname}) {
@@ -65,7 +65,7 @@ export class Environment {
65
65
  ${code}
66
66
  return __exports;
67
67
  } catch (cause) {
68
- const template = __env.cache.get(__file);
68
+ const template = ${sync ? "" : "await"} __env.cache.get(__file);
69
69
  throw new __err(__file, template?.source, __pos, cause);
70
70
  }
71
71
  }
@@ -77,12 +77,7 @@ export class Environment {
77
77
  return template;
78
78
  }
79
79
  tokenize(source, path) {
80
- const result = tokenize(source);
81
- let { tokens } = result;
82
- const { position, error } = result;
83
- if (error) {
84
- throw new TemplateError(path, source, position, error);
85
- }
80
+ let tokens = tokenize(source);
86
81
  for (const tokenPreprocessor of this.tokenPreprocessors) {
87
82
  const result = tokenPreprocessor(this, tokens, path);
88
83
  if (result !== undefined) {
@@ -93,16 +88,18 @@ export class Environment {
93
88
  }
94
89
  async load(file, from) {
95
90
  const path = this.options.loader.resolve(from || "", file);
96
- if (!this.cache.has(path)) {
97
- // Remove query and hash params from path before loading
98
- const cleanPath = path
99
- .split("?")[0]
100
- .split("#")[0];
101
- const { source, data } = await this.options.loader.load(cleanPath);
102
- const template = this.compile(source, path, data);
103
- this.cache.set(path, template);
91
+ let cached = this.cache.get(path);
92
+ if (cached) {
93
+ return cached;
104
94
  }
105
- return this.cache.get(path);
95
+ // Remove query and hash params from path before loading
96
+ const cleanPath = path
97
+ .split("?")[0]
98
+ .split("#")[0];
99
+ cached = this.options.loader.load(cleanPath)
100
+ .then(({ source, data }) => this.compile(source, path, data));
101
+ this.cache.set(path, cached);
102
+ return await cached;
106
103
  }
107
104
  compileTokens(tokens, outputVar = "__exports.content", stopAt) {
108
105
  const compiled = [];
@@ -174,14 +171,15 @@ export class Environment {
174
171
  }
175
172
  }
176
173
  function isGlobal(name) {
177
- // @ts-ignore TS doesn't know about globalThis
178
- if (Object.hasOwn(dntShim.dntGlobalThis, name)) {
174
+ if (name == "name")
175
+ return false;
176
+ if (Object.hasOwn(globalThis, name)) {
179
177
  return true;
180
178
  }
181
179
  if (name.includes(".")) {
182
180
  const [obj, prop] = name.split(".");
183
181
  // @ts-ignore TS doesn't know about globalThis
184
- return Object.hasOwn(dntShim.dntGlobalThis[obj], prop);
182
+ return Object.hasOwn(globalThis[obj], prop);
185
183
  }
186
184
  }
187
185
  // deno-lint-ignore no-explicit-any
@@ -13,13 +13,6 @@ export class TemplateError extends VentoBaseError {
13
13
  this.position = position;
14
14
  }
15
15
  }
16
- export class TransformError extends VentoBaseError {
17
- position;
18
- constructor(message, position = 0, cause) {
19
- super(message, { cause });
20
- this.position = position;
21
- }
22
- }
23
16
  /** Returns the number and code of the errored line */
24
17
  export function errorLine(source, position) {
25
18
  let line = 1;
package/core/js.js ADDED
@@ -0,0 +1,191 @@
1
+ import reserved from "./reserved.js";
2
+ const TEMPLATE_PART = /[`}](?:\\?[^])*?(?:`|\${)/y;
3
+ const REGEX_LITERAL_START = /(?<=[(=:,?&!]\s*)\//y;
4
+ const STOPPING_POINT = /['"`{}[\]/|]|((?<!\.\??)\b[a-zA-Z_]\w+)/g;
5
+ /**
6
+ * This function iterates over the top-level scope of a JavaScript source code
7
+ * string. It yields pairs of the index and the type of each top-level element
8
+ * found.
9
+ *
10
+ * @example `{ foo: { bar: 1 } }` will yield:
11
+ * - [0, "{", Set[]] for the first opening brace
12
+ * - [18, "}", Set['foo', 'bar']] for the _second_ closing brace
13
+ * - [18, "", Set['foo', 'bar']] for the end of the string
14
+ */
15
+ export default function* iterateTopLevel(source, start = 0) {
16
+ const variables = new Set();
17
+ let cursor = start;
18
+ let depth = -1;
19
+ const brackets = [];
20
+ const max = source.length;
21
+ parsing: while (cursor < max) {
22
+ // Search for the next stopping point (e.g., a brace, quote, or regex).
23
+ STOPPING_POINT.lastIndex = cursor;
24
+ const match = STOPPING_POINT.exec(source);
25
+ // No stopping point found, stop parsing.
26
+ if (!match) {
27
+ break parsing;
28
+ }
29
+ cursor = match.index;
30
+ const [stop, variable] = match;
31
+ if (variable) {
32
+ cursor += variable.length;
33
+ if (!reserved.has(variable))
34
+ variables.add(variable);
35
+ continue;
36
+ }
37
+ // Check the type of the stopping point.
38
+ switch (stop) {
39
+ case "|": {
40
+ cursor++;
41
+ // It's a pipe `|>` in the top-level scope
42
+ if (depth < 0 && source[cursor] === ">") {
43
+ cursor++;
44
+ yield [cursor - 2, "|>", variables];
45
+ }
46
+ break;
47
+ }
48
+ case "'":
49
+ case `"`: {
50
+ // It's a quote or double-quote string: find the end.
51
+ let escapes = 0;
52
+ do {
53
+ cursor = source.indexOf(stop, cursor + 1);
54
+ if (cursor == -1) { // No closing quote found
55
+ break parsing;
56
+ }
57
+ escapes = 0;
58
+ // Handle escaped quotes
59
+ while (source[cursor - 1 - escapes] == "\\") {
60
+ escapes++;
61
+ }
62
+ } while (escapes % 2 != 0);
63
+ cursor++;
64
+ break;
65
+ }
66
+ case "{": {
67
+ // It's an opening brace: yield if it's in the top-level scope.
68
+ if (depth < 0)
69
+ yield [cursor, "{", variables];
70
+ cursor++;
71
+ // Handle `{}`
72
+ if (source[cursor] == "}")
73
+ cursor++;
74
+ // Push the opening brace onto the stack.
75
+ else
76
+ brackets[++depth] = "{";
77
+ break;
78
+ }
79
+ case "[": {
80
+ // It's an opening brace: yield if it's in the top-level scope.
81
+ if (depth < 0)
82
+ yield [cursor, "[", variables];
83
+ cursor++;
84
+ // Handle `[]`
85
+ if (source[cursor] == "]")
86
+ cursor++;
87
+ // Push the opening brace onto the stack.
88
+ else
89
+ brackets[++depth] = "[";
90
+ break;
91
+ }
92
+ case "]": {
93
+ // Close the last opened bracket if it matches.
94
+ if (brackets[depth] == "[")
95
+ depth--;
96
+ // Yield if it's in the top-level scope.
97
+ if (depth < 0)
98
+ yield [cursor, "]", variables];
99
+ cursor++;
100
+ break;
101
+ }
102
+ case "}": {
103
+ // Close the last opened brace if it matches.
104
+ if (brackets[depth] == "{") {
105
+ depth--;
106
+ // Yield if it's in the top-level scope.
107
+ if (depth < 0)
108
+ yield [cursor, "}", variables];
109
+ cursor++;
110
+ break;
111
+ }
112
+ // If it doesn't match, but we're in the top-level scope, yield anyway.
113
+ if (depth < 0) {
114
+ yield [cursor, "}", variables];
115
+ cursor++;
116
+ break;
117
+ }
118
+ // Break if we're not inside in a template literal.
119
+ // otherwise, continue parsing.
120
+ if (brackets[depth] != "`") {
121
+ cursor++;
122
+ break;
123
+ }
124
+ depth--;
125
+ } /* falls through */
126
+ case "`": {
127
+ // Search for template literal part or end.
128
+ TEMPLATE_PART.lastIndex = cursor;
129
+ const match = TEMPLATE_PART.exec(source);
130
+ // If we don't find anything, return end of the string.
131
+ if (!match)
132
+ return [max, ""];
133
+ const [part] = match;
134
+ cursor += part.length;
135
+ // We found the end of the template literal
136
+ if (source[cursor - 1] == "`")
137
+ break;
138
+ // Otherwise, we found a template literal part.
139
+ // Store the opening backtick in the stack.
140
+ brackets[++depth] = "`";
141
+ break;
142
+ }
143
+ case "/": {
144
+ // It's a line comment
145
+ if (source[cursor + 1] == "/") {
146
+ cursor = source.indexOf("\n", cursor + 2);
147
+ if (cursor == -1)
148
+ break parsing;
149
+ break;
150
+ }
151
+ // It's a block comment
152
+ if (source[cursor + 1] == "*") {
153
+ cursor = source.indexOf("*/", cursor + 2);
154
+ if (cursor == -1)
155
+ break parsing;
156
+ break;
157
+ }
158
+ // Check if it's a regex literal.
159
+ REGEX_LITERAL_START.lastIndex = cursor;
160
+ if (!REGEX_LITERAL_START.test(source)) {
161
+ cursor++;
162
+ break;
163
+ }
164
+ // It's a regex literal: find the end.
165
+ let inCharClass = false;
166
+ cursor++;
167
+ do {
168
+ const character = source[cursor];
169
+ cursor++;
170
+ switch (character) {
171
+ case "\\":
172
+ cursor++;
173
+ break;
174
+ case "[":
175
+ inCharClass = true;
176
+ break;
177
+ case "]":
178
+ inCharClass = false;
179
+ break;
180
+ case "/":
181
+ if (!inCharClass)
182
+ continue parsing;
183
+ break;
184
+ }
185
+ } while (cursor < max);
186
+ break parsing;
187
+ }
188
+ }
189
+ }
190
+ return [max, "", variables];
191
+ }
@@ -0,0 +1,63 @@
1
+ const variables = new Set([
2
+ // Words reserved by Vento, used internally. In general, don't use variable
3
+ // names starting with two underscores to be future-proof and avoid clashes.
4
+ "__file",
5
+ "__env",
6
+ "__defaults",
7
+ "__err",
8
+ "__exports",
9
+ "__pos",
10
+ "__tmp",
11
+ // JS reserved words, and some "dangerous" words like `let`, `async`, `of` or
12
+ // `undefined`, which aren't technically reserved but don't name your
13
+ // variables that.
14
+ "async",
15
+ "await",
16
+ "break",
17
+ "case",
18
+ "catch",
19
+ "class",
20
+ "const",
21
+ "continue",
22
+ "debugger",
23
+ "default",
24
+ "delete",
25
+ "do",
26
+ "else",
27
+ "enum",
28
+ "export",
29
+ "extends",
30
+ "false",
31
+ "finally",
32
+ "for",
33
+ "function",
34
+ "if",
35
+ "import",
36
+ "in",
37
+ "instanceof",
38
+ "let",
39
+ "new",
40
+ "null",
41
+ "of",
42
+ "return",
43
+ "super",
44
+ "switch",
45
+ "this",
46
+ "throw",
47
+ "true",
48
+ "try",
49
+ "typeof",
50
+ "undefined",
51
+ "var",
52
+ "void",
53
+ "while",
54
+ "with",
55
+ "yield",
56
+ // Variables that are already defined globally
57
+ ...Object.getOwnPropertyNames(globalThis),
58
+ ]);
59
+ // Remove `name` from the reserved variables
60
+ // because it's widely used in templates
61
+ // and it can cause issues if it's reserved.
62
+ variables.delete("name");
63
+ export default variables;
@@ -0,0 +1,86 @@
1
+ import iterateTopLevel from "./js.js";
2
+ export default function tokenize(source) {
3
+ const tokens = [];
4
+ let type = "string";
5
+ let position = 0;
6
+ while (source.length > 0) {
7
+ if (type === "string") {
8
+ const index = source.indexOf("{{");
9
+ const code = index === -1 ? source : source.slice(0, index);
10
+ tokens.push([type, code, position]);
11
+ if (index === -1) {
12
+ break;
13
+ }
14
+ position += index;
15
+ source = source.slice(index);
16
+ type = source.startsWith("{{#") ? "comment" : "tag";
17
+ continue;
18
+ }
19
+ if (type === "comment") {
20
+ source = source.slice(3);
21
+ const index = source.indexOf("#}}");
22
+ const comment = index === -1 ? source : source.slice(0, index);
23
+ tokens.push([type, comment, position]);
24
+ if (index === -1) {
25
+ break;
26
+ }
27
+ position += index + 3;
28
+ source = source.slice(index + 3);
29
+ type = "string";
30
+ continue;
31
+ }
32
+ if (type === "tag") {
33
+ const indexes = parseTag(source);
34
+ const lastIndex = indexes.length - 1;
35
+ let tag;
36
+ indexes.reduce((prev, curr, index) => {
37
+ const code = source.slice(prev, curr - 2);
38
+ // Tag
39
+ if (index === 1) {
40
+ tag = [type, code, position];
41
+ tokens.push(tag);
42
+ return curr;
43
+ }
44
+ // Filters
45
+ tokens.push(["filter", code]);
46
+ return curr;
47
+ });
48
+ position += indexes[lastIndex];
49
+ source = source.slice(indexes[lastIndex]);
50
+ type = "string";
51
+ // Search the closing echo tag {{ /echo }}
52
+ if (tag?.[1].match(/^\-?\s*echo\s*\-?$/)) {
53
+ const end = /{{\-?\s*\/echo\s*\-?}}/.exec(source);
54
+ if (!end) {
55
+ tokens.push(["string", source, position]);
56
+ return tokens;
57
+ }
58
+ tokens.push(["string", source.slice(0, end.index), position]);
59
+ position += end.index;
60
+ tokens.push(["tag", end[0].slice(2, -2), position]);
61
+ position += end[0].length;
62
+ source = source.slice(end.index + end[0].length);
63
+ }
64
+ continue;
65
+ }
66
+ }
67
+ return tokens;
68
+ }
69
+ /**
70
+ * Parse a tag and return the indexes of the start and end brackets, and the filters between.
71
+ * For example: {{ tag |> filter1 |> filter2 }} => [2, 9, 20, 31]
72
+ */
73
+ export function parseTag(source) {
74
+ const indexes = [2];
75
+ for (const [index, reason] of iterateTopLevel(source, 2)) {
76
+ if (reason == "|>") {
77
+ indexes.push(index + 2);
78
+ continue;
79
+ }
80
+ else if (!source.startsWith("}}", index))
81
+ continue;
82
+ indexes.push(index + 2);
83
+ return indexes;
84
+ }
85
+ throw new Error("Unclosed tag");
86
+ }
@@ -0,0 +1,24 @@
1
+ /** @type LanguageFn */
2
+ export default function (hljs) {
3
+ return {
4
+ name: "vento",
5
+ subLanguage: "xml",
6
+ contains: [
7
+ hljs.COMMENT("{{#", "#}}"),
8
+ {
9
+ begin: "{{[-]?",
10
+ end: "[-]?}}",
11
+ subLanguage: "javascript",
12
+ excludeBegin: true,
13
+ excludeEnd: true,
14
+ },
15
+ {
16
+ begin: "^---\n",
17
+ end: "\n---\n",
18
+ subLanguage: "yaml",
19
+ excludeBegin: true,
20
+ excludeEnd: true,
21
+ },
22
+ ],
23
+ };
24
+ }
@@ -1,7 +1,10 @@
1
- import "../_dnt.polyfills.js";
2
1
  import path from "node:path";
3
2
  import fs from "node:fs/promises";
4
3
  import process from "node:process";
4
+ /**
5
+ * Vento file loader for loading templates from the file system.
6
+ * Used by JS runtimes like Node, Deno, and Bun.
7
+ */
5
8
  export class FileLoader {
6
9
  #root;
7
10
  constructor(root = process.cwd()) {
@@ -9,7 +12,7 @@ export class FileLoader {
9
12
  }
10
13
  async load(file) {
11
14
  return {
12
- source: await fs.readFile(file, { encoding: "utf-8" }),
15
+ source: await fs.readFile(file, "utf-8"),
13
16
  };
14
17
  }
15
18
  resolve(from, file) {
@@ -0,0 +1,24 @@
1
+ import path from "node:path";
2
+ /**
3
+ * Vento loader for loading templates from an in-memory object.
4
+ * Used for testing or in-memory operations.
5
+ */
6
+ export class MemoryLoader {
7
+ files = {};
8
+ constructor(files) {
9
+ this.files = files;
10
+ }
11
+ load(file) {
12
+ if (!(file in this.files)) {
13
+ throw new Error(`File not found: ${file}`);
14
+ }
15
+ const source = this.files[file];
16
+ return Promise.resolve({ source });
17
+ }
18
+ resolve(from, file) {
19
+ if (file.startsWith(".")) {
20
+ return path.join(path.dirname(from), file).replace(/\\/g, "/");
21
+ }
22
+ return path.join("/", file).replace(/\\/g, "/");
23
+ }
24
+ }
package/loaders/url.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Vento URL loader for loading templates from a URL.
3
+ * Used by browser environments.
4
+ */
5
+ export class UrlLoader {
6
+ #root;
7
+ constructor(root) {
8
+ this.#root = root;
9
+ }
10
+ async load(file) {
11
+ const url = new URL(join(this.#root.pathname, file), this.#root);
12
+ const source = await (await fetch(url)).text();
13
+ return { source };
14
+ }
15
+ resolve(from, file) {
16
+ if (file.startsWith(".")) {
17
+ return join("/", dirname(from), file);
18
+ }
19
+ return join("/", file);
20
+ }
21
+ }
22
+ function join(...parts) {
23
+ return parts.join("/").replace(/\/+/g, "/");
24
+ }
25
+ function dirname(path) {
26
+ const lastSlash = path.lastIndexOf("/");
27
+ return lastSlash === -1 ? "." : path.slice(0, lastSlash);
28
+ }
@@ -1,14 +1,19 @@
1
- import { Environment } from "./src/environment.js";
2
- import { FileLoader } from "./src/loader.node.js";
1
+ import { Environment } from "./core/environment.js";
2
+ import { FileLoader } from "./loaders/file.js";
3
+ import defaultPlugins from "./plugins/mod.js";
3
4
  export default function (options = {}) {
5
+ // Determine the loader based on the includes option
4
6
  const loader = typeof options.includes === "object"
5
7
  ? options.includes
6
8
  : new FileLoader(options.includes);
9
+ // Create a new Environment instance with the provided options
7
10
  const env = new Environment({
8
11
  loader,
9
12
  dataVarname: options.dataVarname || "it",
10
13
  autoescape: options.autoescape ?? false,
11
14
  autoDataVarname: options.autoDataVarname ?? true,
12
15
  });
16
+ // Register the default plugins
17
+ env.use(defaultPlugins());
13
18
  return env;
14
19
  }