vue.cjs.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var compilerDom = require('@vue/compiler-dom');
  4. var runtimeDom = require('@vue/runtime-dom');
  5. var shared = require('@vue/shared');
  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. // This entry is the "full-build" that includes both the runtime
  19. const compileCache = Object.create(null);
  20. function compileToFunction(template, options) {
  21. if (!shared.isString(template)) {
  22. if (template.nodeType) {
  23. template = template.innerHTML;
  24. }
  25. else {
  26. runtimeDom.warn(`invalid template option: `, template);
  27. return shared.NOOP;
  28. }
  29. }
  30. const key = template;
  31. const cached = compileCache[key];
  32. if (cached) {
  33. return cached;
  34. }
  35. if (template[0] === '#') {
  36. const el = document.querySelector(template);
  37. if (!el) {
  38. runtimeDom.warn(`Template element not found or is empty: ${template}`);
  39. }
  40. // __UNSAFE__
  41. // Reason: potential execution of JS expressions in in-DOM template.
  42. // The user must make sure the in-DOM template is trusted. If it's rendered
  43. // by the server, the template should not contain any user data.
  44. template = el ? el.innerHTML : ``;
  45. }
  46. const opts = shared.extend({
  47. hoistStatic: true,
  48. onError: onError ,
  49. onWarn: e => onError(e, true)
  50. }, options);
  51. if (!opts.isCustomElement && typeof customElements !== 'undefined') {
  52. opts.isCustomElement = tag => !!customElements.get(tag);
  53. }
  54. const { code } = compilerDom.compile(template, opts);
  55. function onError(err, asWarning = false) {
  56. const message = asWarning
  57. ? err.message
  58. : `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. // The wildcard import results in a huge object with every export
  64. // with keys that cannot be mangled, and can be quite heavy size-wise.
  65. // In the global build we know `Vue` is available globally so we can avoid
  66. // the wildcard object.
  67. const render = (new Function('Vue', code)(runtimeDom__namespace));
  68. render._rc = true;
  69. return (compileCache[key] = render);
  70. }
  71. runtimeDom.registerRuntimeCompiler(compileToFunction);
  72. Object.keys(runtimeDom).forEach(function (k) {
  73. if (k !== 'default') exports[k] = runtimeDom[k];
  74. });
  75. exports.compile = compileToFunction;