vue.cjs.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 { code } = compilerDom.compile(template, shared.extend({
  47. hoistStatic: true,
  48. onError: onError ,
  49. onWarn: e => onError(e, true)
  50. }, options));
  51. function onError(err, asWarning = false) {
  52. const message = asWarning
  53. ? err.message
  54. : `Template compilation error: ${err.message}`;
  55. const codeFrame = err.loc &&
  56. shared.generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  57. runtimeDom.warn(codeFrame ? `${message}\n${codeFrame}` : message);
  58. }
  59. // The wildcard import results in a huge object with every export
  60. // with keys that cannot be mangled, and can be quite heavy size-wise.
  61. // In the global build we know `Vue` is available globally so we can avoid
  62. // the wildcard object.
  63. const render = (new Function('Vue', code)(runtimeDom__namespace));
  64. render._rc = true;
  65. return (compileCache[key] = render);
  66. }
  67. runtimeDom.registerRuntimeCompiler(compileToFunction);
  68. Object.keys(runtimeDom).forEach(function (k) {
  69. if (k !== 'default') exports[k] = runtimeDom[k];
  70. });
  71. exports.compile = compileToFunction;