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.

import-builder.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _assert = require("assert");
  7. var t = require("@babel/types");
  8. class ImportBuilder {
  9. constructor(importedSource, scope, hub) {
  10. this._statements = [];
  11. this._resultName = null;
  12. this._scope = null;
  13. this._hub = null;
  14. this._importedSource = void 0;
  15. this._scope = scope;
  16. this._hub = hub;
  17. this._importedSource = importedSource;
  18. }
  19. done() {
  20. return {
  21. statements: this._statements,
  22. resultName: this._resultName
  23. };
  24. }
  25. import() {
  26. this._statements.push(t.importDeclaration([], t.stringLiteral(this._importedSource)));
  27. return this;
  28. }
  29. require() {
  30. this._statements.push(t.expressionStatement(t.callExpression(t.identifier("require"), [t.stringLiteral(this._importedSource)])));
  31. return this;
  32. }
  33. namespace(name = "namespace") {
  34. const local = this._scope.generateUidIdentifier(name);
  35. const statement = this._statements[this._statements.length - 1];
  36. _assert(statement.type === "ImportDeclaration");
  37. _assert(statement.specifiers.length === 0);
  38. statement.specifiers = [t.importNamespaceSpecifier(local)];
  39. this._resultName = t.cloneNode(local);
  40. return this;
  41. }
  42. default(name) {
  43. name = this._scope.generateUidIdentifier(name);
  44. const statement = this._statements[this._statements.length - 1];
  45. _assert(statement.type === "ImportDeclaration");
  46. _assert(statement.specifiers.length === 0);
  47. statement.specifiers = [t.importDefaultSpecifier(name)];
  48. this._resultName = t.cloneNode(name);
  49. return this;
  50. }
  51. named(name, importName) {
  52. if (importName === "default") return this.default(name);
  53. name = this._scope.generateUidIdentifier(name);
  54. const statement = this._statements[this._statements.length - 1];
  55. _assert(statement.type === "ImportDeclaration");
  56. _assert(statement.specifiers.length === 0);
  57. statement.specifiers = [t.importSpecifier(name, t.identifier(importName))];
  58. this._resultName = t.cloneNode(name);
  59. return this;
  60. }
  61. var(name) {
  62. name = this._scope.generateUidIdentifier(name);
  63. let statement = this._statements[this._statements.length - 1];
  64. if (statement.type !== "ExpressionStatement") {
  65. _assert(this._resultName);
  66. statement = t.expressionStatement(this._resultName);
  67. this._statements.push(statement);
  68. }
  69. this._statements[this._statements.length - 1] = t.variableDeclaration("var", [t.variableDeclarator(name, statement.expression)]);
  70. this._resultName = t.cloneNode(name);
  71. return this;
  72. }
  73. defaultInterop() {
  74. return this._interop(this._hub.addHelper("interopRequireDefault"));
  75. }
  76. wildcardInterop() {
  77. return this._interop(this._hub.addHelper("interopRequireWildcard"));
  78. }
  79. _interop(callee) {
  80. const statement = this._statements[this._statements.length - 1];
  81. if (statement.type === "ExpressionStatement") {
  82. statement.expression = t.callExpression(callee, [statement.expression]);
  83. } else if (statement.type === "VariableDeclaration") {
  84. _assert(statement.declarations.length === 1);
  85. statement.declarations[0].init = t.callExpression(callee, [statement.declarations[0].init]);
  86. } else {
  87. _assert.fail("Unexpected type.");
  88. }
  89. return this;
  90. }
  91. prop(name) {
  92. const statement = this._statements[this._statements.length - 1];
  93. if (statement.type === "ExpressionStatement") {
  94. statement.expression = t.memberExpression(statement.expression, t.identifier(name));
  95. } else if (statement.type === "VariableDeclaration") {
  96. _assert(statement.declarations.length === 1);
  97. statement.declarations[0].init = t.memberExpression(statement.declarations[0].init, t.identifier(name));
  98. } else {
  99. _assert.fail("Unexpected type:" + statement.type);
  100. }
  101. return this;
  102. }
  103. read(name) {
  104. this._resultName = t.memberExpression(this._resultName, t.identifier(name));
  105. }
  106. }
  107. exports.default = ImportBuilder;