Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

normalize-file.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = normalizeFile;
  6. function _fs() {
  7. const data = require("fs");
  8. _fs = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _path() {
  14. const data = require("path");
  15. _path = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _debug() {
  21. const data = require("debug");
  22. _debug = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function t() {
  28. const data = require("@babel/types");
  29. t = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _convertSourceMap() {
  35. const data = require("convert-source-map");
  36. _convertSourceMap = function () {
  37. return data;
  38. };
  39. return data;
  40. }
  41. var _file = require("./file/file");
  42. var _parser = require("../parser");
  43. var _cloneDeep = require("./util/clone-deep");
  44. const debug = _debug()("babel:transform:file");
  45. const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1000000;
  46. function* normalizeFile(pluginPasses, options, code, ast) {
  47. code = `${code || ""}`;
  48. if (ast) {
  49. if (ast.type === "Program") {
  50. ast = t().file(ast, [], []);
  51. } else if (ast.type !== "File") {
  52. throw new Error("AST root must be a Program or File node");
  53. }
  54. if (options.cloneInputAst) {
  55. ast = (0, _cloneDeep.default)(ast);
  56. }
  57. } else {
  58. ast = yield* (0, _parser.default)(pluginPasses, options, code);
  59. }
  60. let inputMap = null;
  61. if (options.inputSourceMap !== false) {
  62. if (typeof options.inputSourceMap === "object") {
  63. inputMap = _convertSourceMap().fromObject(options.inputSourceMap);
  64. }
  65. if (!inputMap) {
  66. const lastComment = extractComments(INLINE_SOURCEMAP_REGEX, ast);
  67. if (lastComment) {
  68. try {
  69. inputMap = _convertSourceMap().fromComment(lastComment);
  70. } catch (err) {
  71. debug("discarding unknown inline input sourcemap", err);
  72. }
  73. }
  74. }
  75. if (!inputMap) {
  76. const lastComment = extractComments(EXTERNAL_SOURCEMAP_REGEX, ast);
  77. if (typeof options.filename === "string" && lastComment) {
  78. try {
  79. const match = EXTERNAL_SOURCEMAP_REGEX.exec(lastComment);
  80. const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1]));
  81. if (inputMapContent.length > LARGE_INPUT_SOURCEMAP_THRESHOLD) {
  82. debug("skip merging input map > 1 MB");
  83. } else {
  84. inputMap = _convertSourceMap().fromJSON(inputMapContent);
  85. }
  86. } catch (err) {
  87. debug("discarding unknown file input sourcemap", err);
  88. }
  89. } else if (lastComment) {
  90. debug("discarding un-loadable file input sourcemap");
  91. }
  92. }
  93. }
  94. return new _file.default(options, {
  95. code,
  96. ast,
  97. inputMap
  98. });
  99. }
  100. const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
  101. const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/;
  102. function extractCommentsFromList(regex, comments, lastComment) {
  103. if (comments) {
  104. comments = comments.filter(({
  105. value
  106. }) => {
  107. if (regex.test(value)) {
  108. lastComment = value;
  109. return false;
  110. }
  111. return true;
  112. });
  113. }
  114. return [comments, lastComment];
  115. }
  116. function extractComments(regex, ast) {
  117. let lastComment = null;
  118. t().traverseFast(ast, node => {
  119. [node.leadingComments, lastComment] = extractCommentsFromList(regex, node.leadingComments, lastComment);
  120. [node.innerComments, lastComment] = extractCommentsFromList(regex, node.innerComments, lastComment);
  121. [node.trailingComments, lastComment] = extractCommentsFromList(regex, node.trailingComments, lastComment);
  122. });
  123. return lastComment;
  124. }