vue.esm-bundler.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * vue v3.4.23
  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, extend, generateCodeFrame, EMPTY_OBJ } 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__ */ new WeakMap();
  20. function getCache(options) {
  21. let c = compileCache.get(options != null ? options : EMPTY_OBJ);
  22. if (!c) {
  23. c = /* @__PURE__ */ Object.create(null);
  24. compileCache.set(options != null ? options : EMPTY_OBJ, c);
  25. }
  26. return c;
  27. }
  28. function compileToFunction(template, options) {
  29. if (!isString(template)) {
  30. if (template.nodeType) {
  31. template = template.innerHTML;
  32. } else {
  33. !!(process.env.NODE_ENV !== "production") && warn(`invalid template option: `, template);
  34. return NOOP;
  35. }
  36. }
  37. const key = template;
  38. const cache = getCache(options);
  39. const cached = cache[key];
  40. if (cached) {
  41. return cached;
  42. }
  43. if (template[0] === "#") {
  44. const el = document.querySelector(template);
  45. if (!!(process.env.NODE_ENV !== "production") && !el) {
  46. warn(`Template element not found or is empty: ${template}`);
  47. }
  48. template = el ? el.innerHTML : ``;
  49. }
  50. const opts = extend(
  51. {
  52. hoistStatic: true,
  53. onError: !!(process.env.NODE_ENV !== "production") ? onError : void 0,
  54. onWarn: !!(process.env.NODE_ENV !== "production") ? (e) => onError(e, true) : NOOP
  55. },
  56. options
  57. );
  58. if (!opts.isCustomElement && typeof customElements !== "undefined") {
  59. opts.isCustomElement = (tag) => !!customElements.get(tag);
  60. }
  61. const { code } = compile(template, opts);
  62. function onError(err, asWarning = false) {
  63. const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
  64. const codeFrame = err.loc && generateCodeFrame(
  65. template,
  66. err.loc.start.offset,
  67. err.loc.end.offset
  68. );
  69. warn(codeFrame ? `${message}
  70. ${codeFrame}` : message);
  71. }
  72. const render = new Function("Vue", code)(runtimeDom);
  73. render._rc = true;
  74. return cache[key] = render;
  75. }
  76. registerRuntimeCompiler(compileToFunction);
  77. export { compileToFunction as compile };