vue.cjs.js 2.7 KB

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