renderjs.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.uniRenderjsPlugin = exports.getFiltersCache = void 0;
  7. const debug_1 = __importDefault(require("debug"));
  8. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  9. const debugRenderjs = (0, debug_1.default)('uni:mp-renderjs');
  10. const filtersCache = new Map();
  11. function getFiltersCache(resolvedConfig) {
  12. return filtersCache.get(resolvedConfig) || [];
  13. }
  14. exports.getFiltersCache = getFiltersCache;
  15. function uniRenderjsPlugin({ lang }) {
  16. let resolvedConfig;
  17. return {
  18. name: 'uni:mp-renderjs',
  19. configResolved(config) {
  20. resolvedConfig = config;
  21. filtersCache.set(resolvedConfig, []);
  22. },
  23. transform(code, id) {
  24. const { type, name } = (0, uni_cli_shared_1.parseRenderjs)(id);
  25. if (!type) {
  26. return null;
  27. }
  28. debugRenderjs(id);
  29. if (type !== lang) {
  30. return {
  31. code: 'export default {}',
  32. map: { mappings: '' },
  33. };
  34. }
  35. this.addWatchFile((0, uni_cli_shared_1.cleanUrl)(id));
  36. if (!name) {
  37. this.error((0, uni_cli_shared_1.missingModuleName)(type, code));
  38. }
  39. else {
  40. let cache = filtersCache.get(resolvedConfig);
  41. if (cache) {
  42. const index = cache.findIndex((item) => item.id === id);
  43. if (index > -1) {
  44. cache.splice(index, 1);
  45. }
  46. cache.push({
  47. id,
  48. type,
  49. name,
  50. code,
  51. });
  52. }
  53. }
  54. return {
  55. code: (0, uni_cli_shared_1.genWxsCallMethodsCode)(code),
  56. map: { mappings: '' },
  57. };
  58. },
  59. };
  60. }
  61. exports.uniRenderjsPlugin = uniRenderjsPlugin;