vue.cjs.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var runtimeDom = require('@vue/runtime-dom');
  4. var shared = require('@vue/shared');
  5. var compilerDom = require('@vue/compiler-dom');
  6. function _interopNamespace(e) {
  7. if (e && e.__esModule) return e;
  8. var n = Object.create(null);
  9. if (e) {
  10. Object.keys(e).forEach(function (k) {
  11. n[k] = e[k];
  12. });
  13. }
  14. n['default'] = e;
  15. return Object.freeze(n);
  16. }
  17. var runtimeDom__namespace = /*#__PURE__*/_interopNamespace(runtimeDom);
  18. function initDev() {
  19. const target = shared.getGlobalThis();
  20. target.__VUE__ = true;
  21. runtimeDom.setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__);
  22. }
  23. // This entry is the "full-build" that includes both the runtime
  24. {
  25. initDev();
  26. }
  27. const compileCache = Object.create(null);
  28. function compileToFunction(template, options) {
  29. if (!shared.isString(template)) {
  30. if (template.nodeType) {
  31. template = template.innerHTML;
  32. }
  33. else {
  34. runtimeDom.warn(`invalid template option: `, template);
  35. return shared.NOOP;
  36. }
  37. }
  38. const key = template;
  39. const cached = compileCache[key];
  40. if (cached) {
  41. return cached;
  42. }
  43. if (template[0] === '#') {
  44. const el = document.querySelector(template);
  45. if (!el) {
  46. runtimeDom.warn(`Template element not found or is empty: ${template}`);
  47. }
  48. // __UNSAFE__
  49. // Reason: potential execution of JS expressions in in-DOM template.
  50. // The user must make sure the in-DOM template is trusted. If it's rendered
  51. // by the server, the template should not contain any user data.
  52. template = el ? el.innerHTML : ``;
  53. }
  54. const { code } = compilerDom.compile(template, shared.extend({
  55. hoistStatic: true,
  56. onError(err) {
  57. {
  58. const message = `Template compilation error: ${err.message}`;
  59. const codeFrame = err.loc &&
  60. shared.generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  61. runtimeDom.warn(codeFrame ? `${message}\n${codeFrame}` : message);
  62. }
  63. }
  64. }, options));
  65. // The wildcard import results in a huge object with every export
  66. // with keys that cannot be mangled, and can be quite heavy size-wise.
  67. // In the global build we know `Vue` is available globally so we can avoid
  68. // the wildcard object.
  69. const render = (new Function('Vue', code)(runtimeDom__namespace));
  70. render._rc = true;
  71. return (compileCache[key] = render);
  72. }
  73. runtimeDom.registerRuntimeCompiler(compileToFunction);
  74. exports.compile = compileToFunction;
  75. Object.keys(runtimeDom).forEach(function (k) {
  76. if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = runtimeDom[k];
  77. });