options.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import { createApp, h, reactive, ref } from 'vue'
  2. import type { CompilerOptions } from '@vue/compiler-vapor'
  3. import { BindingTypes } from '@vue/compiler-core'
  4. export const ssrMode = ref(false)
  5. export const vaporMode = ref(true)
  6. export const defaultOptions: CompilerOptions = {
  7. mode: 'module',
  8. filename: 'Foo.vue',
  9. prefixIdentifiers: false,
  10. hoistStatic: false,
  11. cacheHandlers: false,
  12. scopeId: null,
  13. inline: false,
  14. ssrCssVars: `{ color }`,
  15. compatConfig: { MODE: 3 },
  16. whitespace: 'condense',
  17. bindingMetadata: {
  18. TestComponent: BindingTypes.SETUP_CONST,
  19. setupRef: BindingTypes.SETUP_REF,
  20. setupConst: BindingTypes.SETUP_CONST,
  21. setupLet: BindingTypes.SETUP_LET,
  22. setupMaybeRef: BindingTypes.SETUP_MAYBE_REF,
  23. setupProp: BindingTypes.PROPS,
  24. vMySetupDir: BindingTypes.SETUP_CONST,
  25. },
  26. }
  27. export const compilerOptions: CompilerOptions = reactive(
  28. Object.assign({}, defaultOptions),
  29. )
  30. const App = {
  31. setup() {
  32. return () => {
  33. const isSSR = ssrMode.value
  34. const isModule = compilerOptions.mode === 'module'
  35. const usePrefix =
  36. compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
  37. return [
  38. h('h1', `Vue Template Explorer`),
  39. h(
  40. 'a',
  41. {
  42. href: `https://github.com/vuejs/core/tree/${__COMMIT__}`,
  43. target: `_blank`,
  44. },
  45. `@${__COMMIT__}`,
  46. ),
  47. ' | ',
  48. h(
  49. 'a',
  50. {
  51. href: 'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
  52. target: `_blank`,
  53. },
  54. 'History',
  55. ),
  56. h('div', { id: 'options-wrapper' }, [
  57. h('div', { id: 'options-label' }, 'Options ↘'),
  58. h('ul', { id: 'options' }, [
  59. // mode selection
  60. h('li', { id: 'mode' }, [
  61. h('span', { class: 'label' }, 'Mode: '),
  62. h('input', {
  63. type: 'radio',
  64. id: 'mode-module',
  65. name: 'mode',
  66. checked: isModule,
  67. onChange() {
  68. compilerOptions.mode = 'module'
  69. },
  70. }),
  71. h('label', { for: 'mode-module' }, 'module'),
  72. ' ',
  73. h('input', {
  74. type: 'radio',
  75. id: 'mode-function',
  76. name: 'mode',
  77. checked: !isModule,
  78. onChange() {
  79. compilerOptions.mode = 'function'
  80. },
  81. }),
  82. h('label', { for: 'mode-function' }, 'function'),
  83. ]),
  84. // whitespace handling
  85. h('li', { id: 'whitespace' }, [
  86. h('span', { class: 'label' }, 'whitespace: '),
  87. h('input', {
  88. type: 'radio',
  89. id: 'whitespace-condense',
  90. name: 'whitespace',
  91. checked: compilerOptions.whitespace === 'condense',
  92. onChange() {
  93. compilerOptions.whitespace = 'condense'
  94. },
  95. }),
  96. h('label', { for: 'whitespace-condense' }, 'condense'),
  97. ' ',
  98. h('input', {
  99. type: 'radio',
  100. id: 'whitespace-preserve',
  101. name: 'whitespace',
  102. checked: compilerOptions.whitespace === 'preserve',
  103. onChange() {
  104. compilerOptions.whitespace = 'preserve'
  105. },
  106. }),
  107. h('label', { for: 'whitespace-preserve' }, 'preserve'),
  108. ]),
  109. // SSR
  110. h('li', [
  111. h('input', {
  112. type: 'checkbox',
  113. id: 'ssr',
  114. name: 'ssr',
  115. checked: ssrMode.value,
  116. onChange(e: Event) {
  117. ssrMode.value = (e.target as HTMLInputElement).checked
  118. },
  119. }),
  120. h('label', { for: 'ssr' }, 'SSR'),
  121. ]),
  122. // toggle prefixIdentifiers
  123. h('li', [
  124. h('input', {
  125. type: 'checkbox',
  126. id: 'prefix',
  127. disabled: isModule || isSSR,
  128. checked: usePrefix || isSSR,
  129. onChange(e: Event) {
  130. compilerOptions.prefixIdentifiers =
  131. (e.target as HTMLInputElement).checked || isModule
  132. },
  133. }),
  134. h('label', { for: 'prefix' }, 'prefixIdentifiers'),
  135. ]),
  136. // toggle hoistStatic
  137. h('li', [
  138. h('input', {
  139. type: 'checkbox',
  140. id: 'hoist',
  141. checked: compilerOptions.hoistStatic && !isSSR,
  142. disabled: isSSR,
  143. onChange(e: Event) {
  144. compilerOptions.hoistStatic = (
  145. e.target as HTMLInputElement
  146. ).checked
  147. },
  148. }),
  149. h('label', { for: 'hoist' }, 'hoistStatic'),
  150. ]),
  151. // toggle cacheHandlers
  152. h('li', [
  153. h('input', {
  154. type: 'checkbox',
  155. id: 'cache',
  156. checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
  157. disabled: !usePrefix || isSSR,
  158. onChange(e: Event) {
  159. compilerOptions.cacheHandlers = (
  160. e.target as HTMLInputElement
  161. ).checked
  162. },
  163. }),
  164. h('label', { for: 'cache' }, 'cacheHandlers'),
  165. ]),
  166. // toggle scopeId
  167. h('li', [
  168. h('input', {
  169. type: 'checkbox',
  170. id: 'scope-id',
  171. disabled: !isModule,
  172. checked: isModule && compilerOptions.scopeId,
  173. onChange(e: Event) {
  174. compilerOptions.scopeId =
  175. isModule && (e.target as HTMLInputElement).checked
  176. ? 'scope-id'
  177. : null
  178. },
  179. }),
  180. h('label', { for: 'scope-id' }, 'scopeId'),
  181. ]),
  182. // inline mode
  183. h('li', [
  184. h('input', {
  185. type: 'checkbox',
  186. id: 'inline',
  187. checked: compilerOptions.inline,
  188. onChange(e: Event) {
  189. compilerOptions.inline = (
  190. e.target as HTMLInputElement
  191. ).checked
  192. },
  193. }),
  194. h('label', { for: 'inline' }, 'inline'),
  195. ]),
  196. // compat mode
  197. h('li', [
  198. h('input', {
  199. type: 'checkbox',
  200. id: 'compat',
  201. checked: compilerOptions.compatConfig!.MODE === 2,
  202. onChange(e: Event) {
  203. compilerOptions.compatConfig!.MODE = (
  204. e.target as HTMLInputElement
  205. ).checked
  206. ? 2
  207. : 3
  208. },
  209. }),
  210. h('label', { for: 'compat' }, 'v2 compat mode'),
  211. ]),
  212. h('li', [
  213. h('input', {
  214. type: 'checkbox',
  215. id: 'vapor',
  216. checked: vaporMode.value,
  217. onChange(e: Event) {
  218. vaporMode.value = (e.target as HTMLInputElement).checked
  219. },
  220. }),
  221. h('label', { for: 'vapor' }, 'vapor'),
  222. ]),
  223. ]),
  224. ]),
  225. ]
  226. }
  227. },
  228. }
  229. export function initOptions() {
  230. createApp(App).mount(document.getElementById('header')!)
  231. }