get-source-map-url.js 902 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. /*
  3. Copyright 2022 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. Object.defineProperty(exports, "__esModule", { value: true });
  9. exports.getSourceMapURL = void 0;
  10. // Adapted from https://github.com/lydell/source-map-url/blob/master/source-map-url.js
  11. // See https://github.com/GoogleChrome/workbox/issues/3019
  12. const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/;
  13. const regex = RegExp('(?:' +
  14. '/\\*' +
  15. '(?:\\s*\r?\n(?://)?)?' +
  16. '(?:' +
  17. innerRegex.source +
  18. ')' +
  19. '\\s*' +
  20. '\\*/' +
  21. '|' +
  22. '//(?:' +
  23. innerRegex.source +
  24. ')' +
  25. ')' +
  26. '\\s*');
  27. function getSourceMapURL(srcContents) {
  28. const match = srcContents.match(regex);
  29. return match ? match[1] || match[2] || '' : null;
  30. }
  31. exports.getSourceMapURL = getSourceMapURL;