vue.esm-bundler.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * vue v3.5.12
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. import * as runtimeDom from '@vue/runtime-dom';
  7. import { initCustomFormatter, registerRuntimeCompiler, warn } from '@vue/runtime-dom';
  8. export * from '@vue/runtime-dom';
  9. import { compile } from '@vue/compiler-dom';
  10. import { isString, NOOP, genCacheKey, extend, generateCodeFrame } from '@vue/shared';
  11. function initDev() {
  12. {
  13. initCustomFormatter();
  14. }
  15. }
  16. if (!!(process.env.NODE_ENV !== "production")) {
  17. initDev();
  18. }
  19. const compileCache = /* @__PURE__ */ Object.create(null);
  20. function compileToFunction(template, options) {
  21. if (!isString(template)) {
  22. if (template.nodeType) {
  23. template = template.innerHTML;
  24. } else {
  25. !!(process.env.NODE_ENV !== "production") && warn(`invalid template option: `, template);
  26. return NOOP;
  27. }
  28. }
  29. const key = genCacheKey(template, options);
  30. const cached = compileCache[key];
  31. if (cached) {
  32. return cached;
  33. }
  34. if (template[0] === "#") {
  35. const el = document.querySelector(template);
  36. if (!!(process.env.NODE_ENV !== "production") && !el) {
  37. warn(`Template element not found or is empty: ${template}`);
  38. }
  39. template = el ? el.innerHTML : ``;
  40. }
  41. const opts = extend(
  42. {
  43. hoistStatic: true,
  44. onError: !!(process.env.NODE_ENV !== "production") ? onError : void 0,
  45. onWarn: !!(process.env.NODE_ENV !== "production") ? (e) => onError(e, true) : NOOP
  46. },
  47. options
  48. );
  49. if (!opts.isCustomElement && typeof customElements !== "undefined") {
  50. opts.isCustomElement = (tag) => !!customElements.get(tag);
  51. }
  52. const { code } = compile(template, opts);
  53. function onError(err, asWarning = false) {
  54. const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
  55. const codeFrame = err.loc && generateCodeFrame(
  56. template,
  57. err.loc.start.offset,
  58. err.loc.end.offset
  59. );
  60. warn(codeFrame ? `${message}
  61. ${codeFrame}` : message);
  62. }
  63. const render = new Function("Vue", code)(runtimeDom);
  64. render._rc = true;
  65. return compileCache[key] = render;
  66. }
  67. registerRuntimeCompiler(compileToFunction);
  68. export { compileToFunction as compile };