select.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.selectBlock = void 0;
  4. const resolveScript_1 = require("./resolveScript");
  5. function selectBlock(descriptor, scopeId, options, loaderContext, query, appendExtension) {
  6. // template
  7. if (query.type === `template`) {
  8. // if we are receiving a query with type it can only come from a *.vue file
  9. // that contains that block, so the block is guaranteed to exist.
  10. const template = descriptor.template;
  11. if (appendExtension) {
  12. loaderContext.resourcePath += '.' + (template.lang || 'html');
  13. }
  14. loaderContext.callback(null, template.content, template.map);
  15. return;
  16. }
  17. // script
  18. if (query.type === `script`) {
  19. const script = (0, resolveScript_1.resolveScript)(descriptor, scopeId, options, loaderContext);
  20. if (appendExtension) {
  21. loaderContext.resourcePath += '.' + (script.lang || 'js');
  22. }
  23. loaderContext.callback(null, script.content, script.map);
  24. return;
  25. }
  26. // styles
  27. if (query.type === `style` && query.index != null) {
  28. const style = descriptor.styles[Number(query.index)];
  29. if (appendExtension) {
  30. loaderContext.resourcePath += '.' + (style.lang || 'css');
  31. }
  32. loaderContext.callback(null, style.content, style.map);
  33. return;
  34. }
  35. // custom
  36. if (query.type === 'custom' && query.index != null) {
  37. const block = descriptor.customBlocks[Number(query.index)];
  38. loaderContext.callback(null, block.content, block.map);
  39. }
  40. }
  41. exports.selectBlock = selectBlock;