保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = processResources;
exports.getOutput = void 0;
 
var _logger = _interopRequireDefault(require("./logger"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
 
// Matches opening and closing parenthesis across multiple lines
var multilineParenthesisRegex = '\\([\\s\\S]*?\\);?'; // Finds any @use statement
 
var useRegex = "^@use \\S*(?: with ".concat(multilineParenthesisRegex, "|.*)?\n?$"); // Same as above, but adds the m (multiline) flag
 
var useRegexTest = new RegExp(useRegex, 'm'); // Makes sure that only the last instance of `useRegex` variable is found
 
var useRegexReplace = new RegExp("".concat(useRegex, "(?![\\s\\S]*").concat(useRegex, ")"), 'gm');
 
var getOutput = function getOutput(source, resources, _ref) {
  var hoistUseStatements = _ref.hoistUseStatements;
 
  if (hoistUseStatements && useRegexTest.test(source)) {
    var output = source.replace(useRegexReplace, function (useStatements) {
      return "".concat(useStatements, "\n").concat(resources);
    }); // De-duplicate identical imports
 
    var importedResources = {};
    return output.replace(new RegExp(useRegex, 'mg'), function (importedResource) {
      if (importedResources[importedResource]) {
        return '';
      }
 
      importedResources[importedResource] = true;
      return importedResource;
    });
  }
 
  return "".concat(resources, "\n").concat(source);
};
 
exports.getOutput = getOutput;
 
function processResources(error, resources, source, options, module, callback) {
  if (error) {
    _logger["default"].debug('Resources: **not found**');
 
    return callback(error);
  }
 
  var stringifiedResources = Array.isArray(resources) ? resources.join('\n') : resources;
  var output = getOutput(source, stringifiedResources, options);
 
  _logger["default"].debug('Resources: \n', "/* ".concat(module, " */ \n"), output);
 
  return callback(null, output);
}