vue.cjs.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. initDev();
  25. const compileCache = Object.create(null);
  26. function compileToFunction(template, options) {
  27. if (!shared.isString(template)) {
  28. if (template.nodeType) {
  29. template = template.innerHTML;
  30. }
  31. else {
  32. runtimeDom.warn(`invalid template option: `, template);
  33. return shared.NOOP;
  34. }
  35. }
  36. const key = template;
  37. const cached = compileCache[key];
  38. if (cached) {
  39. return cached;
  40. }
  41. if (template[0] === '#') {
  42. const el = document.querySelector(template);
  43. if ( !el) {
  44. runtimeDom.warn(`Template element not found or is empty: ${template}`);
  45. }
  46. // __UNSAFE__
  47. // Reason: potential execution of JS expressions in in-DOM template.
  48. // The user must make sure the in-DOM template is trusted. If it's rendered
  49. // by the server, the template should not contain any user data.
  50. template = el ? el.innerHTML : ``;
  51. }
  52. const { code } = compilerDom.compile(template, shared.extend({
  53. hoistStatic: true,
  54. onError(err) {
  55. {
  56. const message = `Template compilation error: ${err.message}`;
  57. const codeFrame = err.loc &&
  58. shared.generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  59. runtimeDom.warn(codeFrame ? `${message}\n${codeFrame}` : message);
  60. }
  61. }
  62. }, options));
  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;