@opentf/web 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/components/Link.jsx +29 -0
  2. package/core/errors.js +48 -0
  3. package/core/signals.js +188 -0
  4. package/index.js +12 -0
  5. package/package.json +27 -18
  6. package/runtime/context.js +89 -0
  7. package/runtime/dom.js +280 -0
  8. package/runtime/error-boundary.js +109 -0
  9. package/runtime/events.js +17 -0
  10. package/runtime/index.js +16 -0
  11. package/runtime/lifecycle.js +9 -0
  12. package/runtime/mount.js +49 -0
  13. package/runtime/portal.js +59 -0
  14. package/runtime/router.js +246 -0
  15. package/server/builtins.js +11 -0
  16. package/server/index.js +7 -0
  17. package/server/render.js +76 -0
  18. package/server/ssg-runtime.js +109 -0
  19. package/README.md +0 -41
  20. package/dist/CHANGELOG.md +0 -49
  21. package/dist/README.md +0 -41
  22. package/dist/babel.config.cjs +0 -6
  23. package/dist/compiler/babel-plugin.cjs +0 -798
  24. package/dist/core/mount.js +0 -32
  25. package/dist/index.js +0 -7
  26. package/dist/node_modules/@babel/core/LICENSE +0 -22
  27. package/dist/node_modules/@babel/core/README.md +0 -19
  28. package/dist/node_modules/@babel/core/lib/config/cache-contexts.js +0 -5
  29. package/dist/node_modules/@babel/core/lib/config/cache-contexts.js.map +0 -1
  30. package/dist/node_modules/@babel/core/lib/config/caching.js +0 -261
  31. package/dist/node_modules/@babel/core/lib/config/caching.js.map +0 -1
  32. package/dist/node_modules/@babel/core/lib/config/config-chain.js +0 -469
  33. package/dist/node_modules/@babel/core/lib/config/config-chain.js.map +0 -1
  34. package/dist/node_modules/@babel/core/lib/config/config-descriptors.js +0 -190
  35. package/dist/node_modules/@babel/core/lib/config/config-descriptors.js.map +0 -1
  36. package/dist/node_modules/@babel/core/lib/config/files/configuration.js +0 -290
  37. package/dist/node_modules/@babel/core/lib/config/files/configuration.js.map +0 -1
  38. package/dist/node_modules/@babel/core/lib/config/files/import.cjs +0 -6
  39. package/dist/node_modules/@babel/core/lib/config/files/import.cjs.map +0 -1
  40. package/dist/node_modules/@babel/core/lib/config/files/index-browser.js +0 -58
  41. package/dist/node_modules/@babel/core/lib/config/files/index-browser.js.map +0 -1
  42. package/dist/node_modules/@babel/core/lib/config/files/index.js +0 -78
  43. package/dist/node_modules/@babel/core/lib/config/files/index.js.map +0 -1
  44. package/dist/node_modules/@babel/core/lib/config/files/module-types.js +0 -203
  45. package/dist/node_modules/@babel/core/lib/config/files/module-types.js.map +0 -1
  46. package/dist/node_modules/@babel/core/lib/config/files/package.js +0 -61
  47. package/dist/node_modules/@babel/core/lib/config/files/package.js.map +0 -1
  48. package/dist/node_modules/@babel/core/lib/config/files/plugins.js +0 -220
  49. package/dist/node_modules/@babel/core/lib/config/files/plugins.js.map +0 -1
  50. package/dist/node_modules/@babel/core/lib/config/files/types.js +0 -5
  51. package/dist/node_modules/@babel/core/lib/config/files/types.js.map +0 -1
  52. package/dist/node_modules/@babel/core/lib/config/files/utils.js +0 -36
  53. package/dist/node_modules/@babel/core/lib/config/files/utils.js.map +0 -1
  54. package/dist/node_modules/@babel/core/lib/config/full.js +0 -312
  55. package/dist/node_modules/@babel/core/lib/config/full.js.map +0 -1
  56. package/dist/node_modules/@babel/core/lib/config/helpers/config-api.js +0 -85
  57. package/dist/node_modules/@babel/core/lib/config/helpers/config-api.js.map +0 -1
  58. package/dist/node_modules/@babel/core/lib/config/helpers/deep-array.js +0 -23
  59. package/dist/node_modules/@babel/core/lib/config/helpers/deep-array.js.map +0 -1
  60. package/dist/node_modules/@babel/core/lib/config/helpers/environment.js +0 -12
  61. package/dist/node_modules/@babel/core/lib/config/helpers/environment.js.map +0 -1
  62. package/dist/node_modules/@babel/core/lib/config/index.js +0 -87
  63. package/dist/node_modules/@babel/core/lib/config/index.js.map +0 -1
  64. package/dist/node_modules/@babel/core/lib/config/item.js +0 -67
  65. package/dist/node_modules/@babel/core/lib/config/item.js.map +0 -1
  66. package/dist/node_modules/@babel/core/lib/config/partial.js +0 -158
  67. package/dist/node_modules/@babel/core/lib/config/partial.js.map +0 -1
  68. package/dist/node_modules/@babel/core/lib/config/pattern-to-regex.js +0 -38
  69. package/dist/node_modules/@babel/core/lib/config/pattern-to-regex.js.map +0 -1
  70. package/dist/node_modules/@babel/core/lib/config/plugin.js +0 -33
  71. package/dist/node_modules/@babel/core/lib/config/plugin.js.map +0 -1
  72. package/dist/node_modules/@babel/core/lib/config/printer.js +0 -113
  73. package/dist/node_modules/@babel/core/lib/config/printer.js.map +0 -1
  74. package/dist/node_modules/@babel/core/lib/config/resolve-targets-browser.js +0 -41
  75. package/dist/node_modules/@babel/core/lib/config/resolve-targets-browser.js.map +0 -1
  76. package/dist/node_modules/@babel/core/lib/config/resolve-targets.js +0 -61
  77. package/dist/node_modules/@babel/core/lib/config/resolve-targets.js.map +0 -1
  78. package/dist/node_modules/@babel/core/lib/config/util.js +0 -31
  79. package/dist/node_modules/@babel/core/lib/config/util.js.map +0 -1
  80. package/dist/node_modules/@babel/core/lib/config/validation/option-assertions.js +0 -277
  81. package/dist/node_modules/@babel/core/lib/config/validation/option-assertions.js.map +0 -1
  82. package/dist/node_modules/@babel/core/lib/config/validation/options.js +0 -187
  83. package/dist/node_modules/@babel/core/lib/config/validation/options.js.map +0 -1
  84. package/dist/node_modules/@babel/core/lib/config/validation/plugins.js +0 -67
  85. package/dist/node_modules/@babel/core/lib/config/validation/plugins.js.map +0 -1
  86. package/dist/node_modules/@babel/core/lib/config/validation/removed.js +0 -68
  87. package/dist/node_modules/@babel/core/lib/config/validation/removed.js.map +0 -1
  88. package/dist/node_modules/@babel/core/lib/errors/config-error.js +0 -18
  89. package/dist/node_modules/@babel/core/lib/errors/config-error.js.map +0 -1
  90. package/dist/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js +0 -98
  91. package/dist/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js.map +0 -1
  92. package/dist/node_modules/@babel/core/lib/gensync-utils/async.js +0 -90
  93. package/dist/node_modules/@babel/core/lib/gensync-utils/async.js.map +0 -1
  94. package/dist/node_modules/@babel/core/lib/gensync-utils/fs.js +0 -31
  95. package/dist/node_modules/@babel/core/lib/gensync-utils/fs.js.map +0 -1
  96. package/dist/node_modules/@babel/core/lib/gensync-utils/functional.js +0 -58
  97. package/dist/node_modules/@babel/core/lib/gensync-utils/functional.js.map +0 -1
  98. package/dist/node_modules/@babel/core/lib/index.js +0 -230
  99. package/dist/node_modules/@babel/core/lib/index.js.map +0 -1
  100. package/dist/node_modules/@babel/core/lib/parse.js +0 -45
  101. package/dist/node_modules/@babel/core/lib/parse.js.map +0 -1
  102. package/dist/node_modules/@babel/core/lib/parser/index.js +0 -85
  103. package/dist/node_modules/@babel/core/lib/parser/index.js.map +0 -1
  104. package/dist/node_modules/@babel/core/lib/parser/util/missing-plugin-helper.js +0 -337
  105. package/dist/node_modules/@babel/core/lib/parser/util/missing-plugin-helper.js.map +0 -1
  106. package/dist/node_modules/@babel/core/lib/tools/build-external-helpers.js +0 -144
  107. package/dist/node_modules/@babel/core/lib/tools/build-external-helpers.js.map +0 -1
  108. package/dist/node_modules/@babel/core/lib/transform-ast.js +0 -48
  109. package/dist/node_modules/@babel/core/lib/transform-ast.js.map +0 -1
  110. package/dist/node_modules/@babel/core/lib/transform-file-browser.js +0 -23
  111. package/dist/node_modules/@babel/core/lib/transform-file-browser.js.map +0 -1
  112. package/dist/node_modules/@babel/core/lib/transform-file.js +0 -40
  113. package/dist/node_modules/@babel/core/lib/transform-file.js.map +0 -1
  114. package/dist/node_modules/@babel/core/lib/transform.js +0 -47
  115. package/dist/node_modules/@babel/core/lib/transform.js.map +0 -1
  116. package/dist/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js +0 -84
  117. package/dist/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js.map +0 -1
  118. package/dist/node_modules/@babel/core/lib/transformation/file/babel-7-helpers.cjs +0 -4
  119. package/dist/node_modules/@babel/core/lib/transformation/file/babel-7-helpers.cjs.map +0 -1
  120. package/dist/node_modules/@babel/core/lib/transformation/file/file.js +0 -204
  121. package/dist/node_modules/@babel/core/lib/transformation/file/file.js.map +0 -1
  122. package/dist/node_modules/@babel/core/lib/transformation/file/generate.js +0 -84
  123. package/dist/node_modules/@babel/core/lib/transformation/file/generate.js.map +0 -1
  124. package/dist/node_modules/@babel/core/lib/transformation/file/merge-map.js +0 -37
  125. package/dist/node_modules/@babel/core/lib/transformation/file/merge-map.js.map +0 -1
  126. package/dist/node_modules/@babel/core/lib/transformation/index.js +0 -90
  127. package/dist/node_modules/@babel/core/lib/transformation/index.js.map +0 -1
  128. package/dist/node_modules/@babel/core/lib/transformation/normalize-file.js +0 -127
  129. package/dist/node_modules/@babel/core/lib/transformation/normalize-file.js.map +0 -1
  130. package/dist/node_modules/@babel/core/lib/transformation/normalize-opts.js +0 -59
  131. package/dist/node_modules/@babel/core/lib/transformation/normalize-opts.js.map +0 -1
  132. package/dist/node_modules/@babel/core/lib/transformation/plugin-pass.js +0 -48
  133. package/dist/node_modules/@babel/core/lib/transformation/plugin-pass.js.map +0 -1
  134. package/dist/node_modules/@babel/core/lib/transformation/util/clone-deep.js +0 -54
  135. package/dist/node_modules/@babel/core/lib/transformation/util/clone-deep.js.map +0 -1
  136. package/dist/node_modules/@babel/core/lib/vendor/import-meta-resolve.js +0 -1042
  137. package/dist/node_modules/@babel/core/lib/vendor/import-meta-resolve.js.map +0 -1
  138. package/dist/node_modules/@babel/core/package.json +0 -82
  139. package/dist/node_modules/@babel/core/src/config/files/index-browser.ts +0 -115
  140. package/dist/node_modules/@babel/core/src/config/files/index.ts +0 -30
  141. package/dist/node_modules/@babel/core/src/config/resolve-targets-browser.ts +0 -42
  142. package/dist/node_modules/@babel/core/src/config/resolve-targets.ts +0 -54
  143. package/dist/node_modules/@babel/core/src/transform-file-browser.ts +0 -33
  144. package/dist/node_modules/@babel/core/src/transform-file.ts +0 -56
  145. package/dist/node_modules/@babel/helper-module-imports/LICENSE +0 -22
  146. package/dist/node_modules/@babel/helper-module-imports/README.md +0 -19
  147. package/dist/node_modules/@babel/helper-module-imports/lib/import-builder.js +0 -122
  148. package/dist/node_modules/@babel/helper-module-imports/lib/import-builder.js.map +0 -1
  149. package/dist/node_modules/@babel/helper-module-imports/lib/import-injector.js +0 -304
  150. package/dist/node_modules/@babel/helper-module-imports/lib/import-injector.js.map +0 -1
  151. package/dist/node_modules/@babel/helper-module-imports/lib/index.js +0 -37
  152. package/dist/node_modules/@babel/helper-module-imports/lib/index.js.map +0 -1
  153. package/dist/node_modules/@babel/helper-module-imports/lib/is-module.js +0 -11
  154. package/dist/node_modules/@babel/helper-module-imports/lib/is-module.js.map +0 -1
  155. package/dist/node_modules/@babel/helper-module-imports/package.json +0 -28
  156. package/dist/node_modules/@babel/plugin-syntax-jsx/LICENSE +0 -22
  157. package/dist/node_modules/@babel/plugin-syntax-jsx/README.md +0 -19
  158. package/dist/node_modules/@babel/plugin-syntax-jsx/lib/index.js +0 -21
  159. package/dist/node_modules/@babel/plugin-syntax-jsx/lib/index.js.map +0 -1
  160. package/dist/node_modules/@babel/plugin-syntax-jsx/package.json +0 -33
  161. package/dist/node_modules/@preact/signals-core/CHANGELOG.md +0 -331
  162. package/dist/node_modules/@preact/signals-core/LICENSE +0 -21
  163. package/dist/node_modules/@preact/signals-core/README.md +0 -258
  164. package/dist/node_modules/@preact/signals-core/dist/signals-core.d.ts +0 -149
  165. package/dist/node_modules/@preact/signals-core/dist/signals-core.js +0 -1
  166. package/dist/node_modules/@preact/signals-core/dist/signals-core.js.map +0 -1
  167. package/dist/node_modules/@preact/signals-core/dist/signals-core.min.js +0 -1
  168. package/dist/node_modules/@preact/signals-core/dist/signals-core.min.js.map +0 -1
  169. package/dist/node_modules/@preact/signals-core/dist/signals-core.mjs +0 -1
  170. package/dist/node_modules/@preact/signals-core/dist/signals-core.mjs.map +0 -1
  171. package/dist/node_modules/@preact/signals-core/dist/signals-core.module.js +0 -1
  172. package/dist/node_modules/@preact/signals-core/dist/signals-core.module.js.map +0 -1
  173. package/dist/node_modules/@preact/signals-core/package.json +0 -48
  174. package/dist/node_modules/@preact/signals-core/src/index.ts +0 -1121
  175. package/dist/package.json +0 -30
  176. package/dist/router/Link.js +0 -73
  177. package/dist/router/index.js +0 -216
  178. package/dist/runtime/For.js +0 -16
  179. package/dist/runtime/dom.js +0 -73
  180. package/dist/runtime/lifecycle.js +0 -25
  181. package/dist/runtime/props.js +0 -103
@@ -1,56 +0,0 @@
1
- import gensync, { type Handler } from "gensync";
2
-
3
- import loadConfig from "./config/index.ts";
4
- import type { InputOptions, ResolvedConfig } from "./config/index.ts";
5
- import { run } from "./transformation/index.ts";
6
- import type { FileResult, FileResultCallback } from "./transformation/index.ts";
7
- import * as fs from "./gensync-utils/fs.ts";
8
-
9
- type transformFileBrowserType = typeof import("./transform-file-browser");
10
- type transformFileType = typeof import("./transform-file");
11
-
12
- // Kind of gross, but essentially asserting that the exports of this module are the same as the
13
- // exports of transform-file-browser, since this file may be replaced at bundle time with
14
- // transform-file-browser.
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- ({}) as any as transformFileBrowserType as transformFileType;
17
-
18
- const transformFileRunner = gensync(function* (
19
- filename: string,
20
- opts?: InputOptions,
21
- ): Handler<FileResult | null> {
22
- const options = { ...opts, filename };
23
-
24
- const config: ResolvedConfig | null = yield* loadConfig(options);
25
- if (config === null) return null;
26
-
27
- const code = yield* fs.readFile(filename, "utf8");
28
- return yield* run(config, code);
29
- });
30
-
31
- // @ts-expect-error TS doesn't detect that this signature is compatible
32
- export function transformFile(
33
- filename: string,
34
- callback: FileResultCallback,
35
- ): void;
36
- export function transformFile(
37
- filename: string,
38
- opts: InputOptions | undefined | null,
39
- callback: FileResultCallback,
40
- ): void;
41
- export function transformFile(
42
- ...args: Parameters<typeof transformFileRunner.errback>
43
- ) {
44
- transformFileRunner.errback(...args);
45
- }
46
-
47
- export function transformFileSync(
48
- ...args: Parameters<typeof transformFileRunner.sync>
49
- ) {
50
- return transformFileRunner.sync(...args);
51
- }
52
- export function transformFileAsync(
53
- ...args: Parameters<typeof transformFileRunner.async>
54
- ) {
55
- return transformFileRunner.async(...args);
56
- }
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2014-present Sebastian McKenzie and other contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,19 +0,0 @@
1
- # @babel/helper-module-imports
2
-
3
- > Babel helper functions for inserting module loads
4
-
5
- See our website [@babel/helper-module-imports](https://babeljs.io/docs/babel-helper-module-imports) for more information.
6
-
7
- ## Install
8
-
9
- Using npm:
10
-
11
- ```sh
12
- npm install --save @babel/helper-module-imports
13
- ```
14
-
15
- or using yarn:
16
-
17
- ```sh
18
- yarn add @babel/helper-module-imports
19
- ```
@@ -1,122 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _assert = require("assert");
8
- var _t = require("@babel/types");
9
- const {
10
- callExpression,
11
- cloneNode,
12
- expressionStatement,
13
- identifier,
14
- importDeclaration,
15
- importDefaultSpecifier,
16
- importNamespaceSpecifier,
17
- importSpecifier,
18
- memberExpression,
19
- stringLiteral,
20
- variableDeclaration,
21
- variableDeclarator
22
- } = _t;
23
- class ImportBuilder {
24
- constructor(importedSource, scope, hub) {
25
- this._statements = [];
26
- this._resultName = null;
27
- this._importedSource = void 0;
28
- this._scope = scope;
29
- this._hub = hub;
30
- this._importedSource = importedSource;
31
- }
32
- done() {
33
- return {
34
- statements: this._statements,
35
- resultName: this._resultName
36
- };
37
- }
38
- import() {
39
- this._statements.push(importDeclaration([], stringLiteral(this._importedSource)));
40
- return this;
41
- }
42
- require() {
43
- this._statements.push(expressionStatement(callExpression(identifier("require"), [stringLiteral(this._importedSource)])));
44
- return this;
45
- }
46
- namespace(name = "namespace") {
47
- const local = this._scope.generateUidIdentifier(name);
48
- const statement = this._statements[this._statements.length - 1];
49
- _assert(statement.type === "ImportDeclaration");
50
- _assert(statement.specifiers.length === 0);
51
- statement.specifiers = [importNamespaceSpecifier(local)];
52
- this._resultName = cloneNode(local);
53
- return this;
54
- }
55
- default(name) {
56
- const id = this._scope.generateUidIdentifier(name);
57
- const statement = this._statements[this._statements.length - 1];
58
- _assert(statement.type === "ImportDeclaration");
59
- _assert(statement.specifiers.length === 0);
60
- statement.specifiers = [importDefaultSpecifier(id)];
61
- this._resultName = cloneNode(id);
62
- return this;
63
- }
64
- named(name, importName) {
65
- if (importName === "default") return this.default(name);
66
- const id = this._scope.generateUidIdentifier(name);
67
- const statement = this._statements[this._statements.length - 1];
68
- _assert(statement.type === "ImportDeclaration");
69
- _assert(statement.specifiers.length === 0);
70
- statement.specifiers = [importSpecifier(id, identifier(importName))];
71
- this._resultName = cloneNode(id);
72
- return this;
73
- }
74
- var(name) {
75
- const id = this._scope.generateUidIdentifier(name);
76
- let statement = this._statements[this._statements.length - 1];
77
- if (statement.type !== "ExpressionStatement") {
78
- _assert(this._resultName);
79
- statement = expressionStatement(this._resultName);
80
- this._statements.push(statement);
81
- }
82
- this._statements[this._statements.length - 1] = variableDeclaration("var", [variableDeclarator(id, statement.expression)]);
83
- this._resultName = cloneNode(id);
84
- return this;
85
- }
86
- defaultInterop() {
87
- return this._interop(this._hub.addHelper("interopRequireDefault"));
88
- }
89
- wildcardInterop() {
90
- return this._interop(this._hub.addHelper("interopRequireWildcard"));
91
- }
92
- _interop(callee) {
93
- const statement = this._statements[this._statements.length - 1];
94
- if (statement.type === "ExpressionStatement") {
95
- statement.expression = callExpression(callee, [statement.expression]);
96
- } else if (statement.type === "VariableDeclaration") {
97
- _assert(statement.declarations.length === 1);
98
- statement.declarations[0].init = callExpression(callee, [statement.declarations[0].init]);
99
- } else {
100
- _assert.fail("Unexpected type.");
101
- }
102
- return this;
103
- }
104
- prop(name) {
105
- const statement = this._statements[this._statements.length - 1];
106
- if (statement.type === "ExpressionStatement") {
107
- statement.expression = memberExpression(statement.expression, identifier(name));
108
- } else if (statement.type === "VariableDeclaration") {
109
- _assert(statement.declarations.length === 1);
110
- statement.declarations[0].init = memberExpression(statement.declarations[0].init, identifier(name));
111
- } else {
112
- _assert.fail("Unexpected type:" + statement.type);
113
- }
114
- return this;
115
- }
116
- read(name) {
117
- this._resultName = memberExpression(this._resultName, identifier(name));
118
- }
119
- }
120
- exports.default = ImportBuilder;
121
-
122
- //# sourceMappingURL=import-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_assert","require","_t","callExpression","cloneNode","expressionStatement","identifier","importDeclaration","importDefaultSpecifier","importNamespaceSpecifier","importSpecifier","memberExpression","stringLiteral","variableDeclaration","variableDeclarator","ImportBuilder","constructor","importedSource","scope","hub","_statements","_resultName","_importedSource","_scope","_hub","done","statements","resultName","import","push","namespace","name","local","generateUidIdentifier","statement","length","assert","type","specifiers","default","id","named","importName","var","expression","defaultInterop","_interop","addHelper","wildcardInterop","callee","declarations","init","fail","prop","read","exports"],"sources":["../src/import-builder.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport {\n callExpression,\n cloneNode,\n expressionStatement,\n identifier,\n importDeclaration,\n importDefaultSpecifier,\n importNamespaceSpecifier,\n importSpecifier,\n memberExpression,\n stringLiteral,\n variableDeclaration,\n variableDeclarator,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type { Scope, HubInterface } from \"@babel/traverse\";\n\n/**\n * A class to track and accumulate mutations to the AST that will eventually\n * output a new require/import statement list.\n */\nexport default class ImportBuilder {\n private _statements: t.Statement[] = [];\n private _resultName: t.Identifier | t.MemberExpression = null;\n\n declare _scope: Scope;\n declare _hub: HubInterface;\n private _importedSource: string;\n\n constructor(importedSource: string, scope: Scope, hub: HubInterface) {\n this._scope = scope;\n this._hub = hub;\n this._importedSource = importedSource;\n }\n\n done() {\n return {\n statements: this._statements,\n resultName: this._resultName,\n };\n }\n\n import() {\n this._statements.push(\n importDeclaration([], stringLiteral(this._importedSource)),\n );\n return this;\n }\n\n require() {\n this._statements.push(\n expressionStatement(\n callExpression(identifier(\"require\"), [\n stringLiteral(this._importedSource),\n ]),\n ),\n );\n return this;\n }\n\n namespace(name = \"namespace\") {\n const local = this._scope.generateUidIdentifier(name);\n\n const statement = this._statements[this._statements.length - 1];\n assert(statement.type === \"ImportDeclaration\");\n assert(statement.specifiers.length === 0);\n statement.specifiers = [importNamespaceSpecifier(local)];\n this._resultName = cloneNode(local);\n return this;\n }\n default(name: string) {\n const id = this._scope.generateUidIdentifier(name);\n const statement = this._statements[this._statements.length - 1];\n assert(statement.type === \"ImportDeclaration\");\n assert(statement.specifiers.length === 0);\n statement.specifiers = [importDefaultSpecifier(id)];\n this._resultName = cloneNode(id);\n return this;\n }\n named(name: string, importName: string) {\n if (importName === \"default\") return this.default(name);\n\n const id = this._scope.generateUidIdentifier(name);\n const statement = this._statements[this._statements.length - 1];\n assert(statement.type === \"ImportDeclaration\");\n assert(statement.specifiers.length === 0);\n statement.specifiers = [importSpecifier(id, identifier(importName))];\n this._resultName = cloneNode(id);\n return this;\n }\n\n var(name: string) {\n const id = this._scope.generateUidIdentifier(name);\n let statement = this._statements[this._statements.length - 1];\n if (statement.type !== \"ExpressionStatement\") {\n assert(this._resultName);\n statement = expressionStatement(this._resultName);\n this._statements.push(statement);\n }\n this._statements[this._statements.length - 1] = variableDeclaration(\"var\", [\n variableDeclarator(id, statement.expression),\n ]);\n this._resultName = cloneNode(id);\n return this;\n }\n\n defaultInterop() {\n return this._interop(this._hub.addHelper(\"interopRequireDefault\"));\n }\n wildcardInterop() {\n return this._interop(this._hub.addHelper(\"interopRequireWildcard\"));\n }\n\n _interop(callee: t.Expression) {\n const statement = this._statements[this._statements.length - 1];\n if (statement.type === \"ExpressionStatement\") {\n statement.expression = callExpression(callee, [statement.expression]);\n } else if (statement.type === \"VariableDeclaration\") {\n assert(statement.declarations.length === 1);\n statement.declarations[0].init = callExpression(callee, [\n statement.declarations[0].init,\n ]);\n } else {\n assert.fail(\"Unexpected type.\");\n }\n return this;\n }\n\n prop(name: string) {\n const statement = this._statements[this._statements.length - 1];\n if (statement.type === \"ExpressionStatement\") {\n statement.expression = memberExpression(\n statement.expression,\n identifier(name),\n );\n } else if (statement.type === \"VariableDeclaration\") {\n assert(statement.declarations.length === 1);\n statement.declarations[0].init = memberExpression(\n statement.declarations[0].init,\n identifier(name),\n );\n } else {\n assert.fail(\"Unexpected type:\" + statement.type);\n }\n return this;\n }\n\n read(name: string) {\n this._resultName = memberExpression(this._resultName, identifier(name));\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAD,OAAA;AAasB;EAZpBE,cAAc;EACdC,SAAS;EACTC,mBAAmB;EACnBC,UAAU;EACVC,iBAAiB;EACjBC,sBAAsB;EACtBC,wBAAwB;EACxBC,eAAe;EACfC,gBAAgB;EAChBC,aAAa;EACbC,mBAAmB;EACnBC;AAAkB,IAAAZ,EAAA;AASL,MAAMa,aAAa,CAAC;EAQjC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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _assert = require("assert");
8
- var _t = require("@babel/types");
9
- var _importBuilder = require("./import-builder.js");
10
- var _isModule = require("./is-module.js");
11
- const {
12
- identifier,
13
- importSpecifier,
14
- numericLiteral,
15
- sequenceExpression,
16
- isImportDeclaration
17
- } = _t;
18
- class ImportInjector {
19
- constructor(path, importedSource, opts) {
20
- this._defaultOpts = {
21
- importedSource: null,
22
- importedType: "commonjs",
23
- importedInterop: "babel",
24
- importingInterop: "babel",
25
- ensureLiveReference: false,
26
- ensureNoContext: false,
27
- importPosition: "before"
28
- };
29
- const programPath = path.find(p => p.isProgram());
30
- this._programPath = programPath;
31
- this._programScope = programPath.scope;
32
- this._hub = programPath.hub;
33
- this._defaultOpts = this._applyDefaults(importedSource, opts, true);
34
- }
35
- addDefault(importedSourceIn, opts) {
36
- return this.addNamed("default", importedSourceIn, opts);
37
- }
38
- addNamed(importName, importedSourceIn, opts) {
39
- _assert(typeof importName === "string");
40
- return this._generateImport(this._applyDefaults(importedSourceIn, opts), importName);
41
- }
42
- addNamespace(importedSourceIn, opts) {
43
- return this._generateImport(this._applyDefaults(importedSourceIn, opts), null);
44
- }
45
- addSideEffect(importedSourceIn, opts) {
46
- return this._generateImport(this._applyDefaults(importedSourceIn, opts), void 0);
47
- }
48
- _applyDefaults(importedSource, opts, isInit = false) {
49
- let newOpts;
50
- if (typeof importedSource === "string") {
51
- newOpts = Object.assign({}, this._defaultOpts, {
52
- importedSource
53
- }, opts);
54
- } else {
55
- _assert(!opts, "Unexpected secondary arguments.");
56
- newOpts = Object.assign({}, this._defaultOpts, importedSource);
57
- }
58
- if (!isInit && opts) {
59
- if (opts.nameHint !== undefined) newOpts.nameHint = opts.nameHint;
60
- if (opts.blockHoist !== undefined) newOpts.blockHoist = opts.blockHoist;
61
- }
62
- return newOpts;
63
- }
64
- _generateImport(opts, importName) {
65
- const isDefault = importName === "default";
66
- const isNamed = !!importName && !isDefault;
67
- const isNamespace = importName === null;
68
- const {
69
- importedSource,
70
- importedType,
71
- importedInterop,
72
- importingInterop,
73
- ensureLiveReference,
74
- ensureNoContext,
75
- nameHint,
76
- importPosition,
77
- blockHoist
78
- } = opts;
79
- let name = nameHint || importName;
80
- const isMod = (0, _isModule.default)(this._programPath);
81
- const isModuleForNode = isMod && importingInterop === "node";
82
- const isModuleForBabel = isMod && importingInterop === "babel";
83
- if (importPosition === "after" && !isMod) {
84
- throw new Error(`"importPosition": "after" is only supported in modules`);
85
- }
86
- const builder = new _importBuilder.default(importedSource, this._programScope, this._hub);
87
- if (importedType === "es6") {
88
- if (!isModuleForNode && !isModuleForBabel) {
89
- throw new Error("Cannot import an ES6 module from CommonJS");
90
- }
91
- builder.import();
92
- if (isNamespace) {
93
- builder.namespace(nameHint || importedSource);
94
- } else if (isDefault || isNamed) {
95
- builder.named(name, importName);
96
- }
97
- } else if (importedType !== "commonjs") {
98
- throw new Error(`Unexpected interopType "${importedType}"`);
99
- } else if (importedInterop === "babel") {
100
- if (isModuleForNode) {
101
- name = name !== "default" ? name : importedSource;
102
- const es6Default = `${importedSource}$es6Default`;
103
- builder.import();
104
- if (isNamespace) {
105
- builder.default(es6Default).var(name || importedSource).wildcardInterop();
106
- } else if (isDefault) {
107
- if (ensureLiveReference) {
108
- builder.default(es6Default).var(name || importedSource).defaultInterop().read("default");
109
- } else {
110
- builder.default(es6Default).var(name).defaultInterop().prop(importName);
111
- }
112
- } else if (isNamed) {
113
- builder.default(es6Default).read(importName);
114
- }
115
- } else if (isModuleForBabel) {
116
- builder.import();
117
- if (isNamespace) {
118
- builder.namespace(name || importedSource);
119
- } else if (isDefault || isNamed) {
120
- builder.named(name, importName);
121
- }
122
- } else {
123
- builder.require();
124
- if (isNamespace) {
125
- builder.var(name || importedSource).wildcardInterop();
126
- } else if ((isDefault || isNamed) && ensureLiveReference) {
127
- if (isDefault) {
128
- name = name !== "default" ? name : importedSource;
129
- builder.var(name).read(importName);
130
- builder.defaultInterop();
131
- } else {
132
- builder.var(importedSource).read(importName);
133
- }
134
- } else if (isDefault) {
135
- builder.var(name).defaultInterop().prop(importName);
136
- } else if (isNamed) {
137
- builder.var(name).prop(importName);
138
- }
139
- }
140
- } else if (importedInterop === "compiled") {
141
- if (isModuleForNode) {
142
- builder.import();
143
- if (isNamespace) {
144
- builder.default(name || importedSource);
145
- } else if (isDefault || isNamed) {
146
- builder.default(importedSource).read(name);
147
- }
148
- } else if (isModuleForBabel) {
149
- builder.import();
150
- if (isNamespace) {
151
- builder.namespace(name || importedSource);
152
- } else if (isDefault || isNamed) {
153
- builder.named(name, importName);
154
- }
155
- } else {
156
- builder.require();
157
- if (isNamespace) {
158
- builder.var(name || importedSource);
159
- } else if (isDefault || isNamed) {
160
- if (ensureLiveReference) {
161
- builder.var(importedSource).read(name);
162
- } else {
163
- builder.prop(importName).var(name);
164
- }
165
- }
166
- }
167
- } else if (importedInterop === "uncompiled") {
168
- if (isDefault && ensureLiveReference) {
169
- throw new Error("No live reference for commonjs default");
170
- }
171
- if (isModuleForNode) {
172
- builder.import();
173
- if (isNamespace) {
174
- builder.default(name || importedSource);
175
- } else if (isDefault) {
176
- builder.default(name);
177
- } else if (isNamed) {
178
- builder.default(importedSource).read(name);
179
- }
180
- } else if (isModuleForBabel) {
181
- builder.import();
182
- if (isNamespace) {
183
- builder.default(name || importedSource);
184
- } else if (isDefault) {
185
- builder.default(name);
186
- } else if (isNamed) {
187
- builder.named(name, importName);
188
- }
189
- } else {
190
- builder.require();
191
- if (isNamespace) {
192
- builder.var(name || importedSource);
193
- } else if (isDefault) {
194
- builder.var(name);
195
- } else if (isNamed) {
196
- if (ensureLiveReference) {
197
- builder.var(importedSource).read(name);
198
- } else {
199
- builder.var(name).prop(importName);
200
- }
201
- }
202
- }
203
- } else {
204
- throw new Error(`Unknown importedInterop "${importedInterop}".`);
205
- }
206
- const {
207
- statements,
208
- resultName
209
- } = builder.done();
210
- this._insertStatements(statements, importPosition, blockHoist);
211
- if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") {
212
- return sequenceExpression([numericLiteral(0), resultName]);
213
- }
214
- return resultName;
215
- }
216
- _insertStatements(statements, importPosition = "before", blockHoist = 3) {
217
- if (importPosition === "after") {
218
- if (this._insertStatementsAfter(statements)) return;
219
- } else {
220
- if (this._insertStatementsBefore(statements, blockHoist)) return;
221
- }
222
- this._programPath.unshiftContainer("body", statements);
223
- }
224
- _insertStatementsBefore(statements, blockHoist) {
225
- if (statements.length === 1 && isImportDeclaration(statements[0]) && isValueImport(statements[0])) {
226
- const firstImportDecl = this._programPath.get("body").find(p => {
227
- return p.isImportDeclaration() && isValueImport(p.node);
228
- });
229
- if ((firstImportDecl == null ? void 0 : firstImportDecl.node.source.value) === statements[0].source.value && maybeAppendImportSpecifiers(firstImportDecl.node, statements[0])) {
230
- return true;
231
- }
232
- }
233
- statements.forEach(node => {
234
- node._blockHoist = blockHoist;
235
- });
236
- const targetPath = this._programPath.get("body").find(p => {
237
- const val = p.node._blockHoist;
238
- return Number.isFinite(val) && val < 4;
239
- });
240
- if (targetPath) {
241
- targetPath.insertBefore(statements);
242
- return true;
243
- }
244
- return false;
245
- }
246
- _insertStatementsAfter(statements) {
247
- const statementsSet = new Set(statements);
248
- const importDeclarations = new Map();
249
- for (const statement of statements) {
250
- if (isImportDeclaration(statement) && isValueImport(statement)) {
251
- const source = statement.source.value;
252
- if (!importDeclarations.has(source)) importDeclarations.set(source, []);
253
- importDeclarations.get(source).push(statement);
254
- }
255
- }
256
- let lastImportPath = null;
257
- for (const bodyStmt of this._programPath.get("body")) {
258
- if (bodyStmt.isImportDeclaration() && isValueImport(bodyStmt.node)) {
259
- lastImportPath = bodyStmt;
260
- const source = bodyStmt.node.source.value;
261
- const newImports = importDeclarations.get(source);
262
- if (!newImports) continue;
263
- for (const decl of newImports) {
264
- if (!statementsSet.has(decl)) continue;
265
- if (maybeAppendImportSpecifiers(bodyStmt.node, decl)) {
266
- statementsSet.delete(decl);
267
- }
268
- }
269
- }
270
- }
271
- if (statementsSet.size === 0) return true;
272
- if (lastImportPath) lastImportPath.insertAfter(Array.from(statementsSet));
273
- return !!lastImportPath;
274
- }
275
- }
276
- exports.default = ImportInjector;
277
- function isValueImport(node) {
278
- return node.importKind !== "type" && node.importKind !== "typeof";
279
- }
280
- function hasNamespaceImport(node) {
281
- return node.specifiers.length === 1 && node.specifiers[0].type === "ImportNamespaceSpecifier" || node.specifiers.length === 2 && node.specifiers[1].type === "ImportNamespaceSpecifier";
282
- }
283
- function hasDefaultImport(node) {
284
- return node.specifiers.length > 0 && node.specifiers[0].type === "ImportDefaultSpecifier";
285
- }
286
- function maybeAppendImportSpecifiers(target, source) {
287
- if (!target.specifiers.length) {
288
- target.specifiers = source.specifiers;
289
- return true;
290
- }
291
- if (!source.specifiers.length) return true;
292
- if (hasNamespaceImport(target) || hasNamespaceImport(source)) return false;
293
- if (hasDefaultImport(source)) {
294
- if (hasDefaultImport(target)) {
295
- source.specifiers[0] = importSpecifier(source.specifiers[0].local, identifier("default"));
296
- } else {
297
- target.specifiers.unshift(source.specifiers.shift());
298
- }
299
- }
300
- target.specifiers.push(...source.specifiers);
301
- return true;
302
- }
303
-
304
- //# sourceMappingURL=import-injector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_assert","require","_t","_importBuilder","_isModule","identifier","importSpecifier","numericLiteral","sequenceExpression","isImportDeclaration","ImportInjector","constructor","path","importedSource","opts","_defaultOpts","importedType","importedInterop","importingInterop","ensureLiveReference","ensureNoContext","importPosition","programPath","find","p","isProgram","_programPath","_programScope","scope","_hub","hub","_applyDefaults","addDefault","importedSourceIn","addNamed","importName","assert","_generateImport","addNamespace","addSideEffect","isInit","newOpts","Object","assign","nameHint","undefined","blockHoist","isDefault","isNamed","isNamespace","name","isMod","isModule","isModuleForNode","isModuleForBabel","Error","builder","ImportBuilder","import","namespace","named","es6Default","default","var","wildcardInterop","defaultInterop","read","prop","statements","resultName","done","_insertStatements","type","_insertStatementsAfter","_insertStatementsBefore","unshiftContainer","length","isValueImport","firstImportDecl","get","node","source","value","maybeAppendImportSpecifiers","forEach","_blockHoist","targetPath","val","Number","isFinite","insertBefore","statementsSet","Set","importDeclarations","Map","statement","has","set","push","lastImportPath","bodyStmt","newImports","decl","delete","size","insertAfter","Array","from","exports","importKind","hasNamespaceImport","specifiers","hasDefaultImport","target","local","unshift","shift"],"sources":["../src/import-injector.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport {\n identifier,\n importSpecifier,\n numericLiteral,\n sequenceExpression,\n isImportDeclaration,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type { NodePath, Scope, HubInterface } from \"@babel/traverse\";\n\nimport ImportBuilder from \"./import-builder.ts\";\nimport isModule from \"./is-module.ts\";\n\nexport type ImportOptions = {\n /**\n * The module being referenced.\n */\n importedSource: string | null;\n /**\n * The type of module being imported:\n *\n * * 'es6' - An ES6 module.\n * * 'commonjs' - A CommonJS module. (Default)\n */\n importedType: \"es6\" | \"commonjs\";\n /**\n * The type of interop behavior for namespace/default/named when loading\n * CommonJS modules.\n *\n * ## 'babel' (Default)\n *\n * Load using Babel's interop.\n *\n * If '.__esModule' is true, treat as 'compiled', else:\n *\n * * Namespace: A copy of the module.exports with .default\n * populated by the module.exports object.\n * * Default: The module.exports value.\n * * Named: The .named property of module.exports.\n *\n * The 'ensureLiveReference' has no effect on the liveness of these.\n *\n * ## 'compiled'\n *\n * Assume the module is ES6 compiled to CommonJS. Useful to avoid injecting\n * interop logic if you are confident that the module is a certain format.\n *\n * * Namespace: The root module.exports object.\n * * Default: The .default property of the namespace.\n * * Named: The .named property of the namespace.\n *\n * Will return erroneous results if the imported module is _not_ compiled\n * from ES6 with Babel.\n *\n * ## 'uncompiled'\n *\n * Assume the module is _not_ ES6 compiled to CommonJS. Used a simplified\n * access pattern that doesn't require additional function calls.\n *\n * Will return erroneous results if the imported module _is_ compiled\n * from ES6 with Babel.\n *\n * * Namespace: The module.exports object.\n * * Default: The module.exports object.\n * * Named: The .named property of module.exports.\n */\n importedInterop: \"babel\" | \"node\" | \"compiled\" | \"uncompiled\";\n /**\n * The type of CommonJS interop included in the environment that will be\n * loading the output code.\n *\n * * 'babel' - CommonJS modules load with Babel's interop. (Default)\n * * 'node' - CommonJS modules load with Node's interop.\n *\n * See descriptions in 'importedInterop' for more details.\n */\n importingInterop: \"babel\" | \"node\";\n /**\n * Define whether we explicitly care that the import be a live reference.\n * Only applies when importing default and named imports, not the namespace.\n *\n * * true - Force imported values to be live references.\n * * false - No particular requirements. Keeps the code simplest. (Default)\n */\n ensureLiveReference: boolean;\n /**\n * Define if we explicitly care that the result not be a property reference.\n *\n * * true - Force calls to exclude context. Useful if the value is going to\n * be used as function callee.\n * * false - No particular requirements for context of the access. (Default)\n */\n ensureNoContext: boolean;\n /**\n * Define whether the import should be loaded before or after the existing imports.\n * \"after\" is only allowed inside ECMAScript modules, since it's not possible to\n * reliably pick the location _after_ require() calls but _before_ other code in CJS.\n */\n importPosition: \"before\" | \"after\";\n\n nameHint?: string;\n blockHoist?: number;\n};\n\n/**\n * A general helper classes add imports via transforms. See README for usage.\n */\nexport default class ImportInjector {\n /**\n * The path used for manipulation.\n */\n declare _programPath: NodePath<t.Program>;\n\n /**\n * The scope used to generate unique variable names.\n */\n declare _programScope: Scope;\n\n /**\n * The file used to inject helpers and resolve paths.\n */\n declare _hub: HubInterface;\n\n /**\n * The default options to use with this instance when imports are added.\n */\n _defaultOpts: ImportOptions = {\n importedSource: null,\n importedType: \"commonjs\",\n importedInterop: \"babel\",\n importingInterop: \"babel\",\n ensureLiveReference: false,\n ensureNoContext: false,\n importPosition: \"before\",\n };\n\n constructor(\n path: NodePath,\n importedSource?: string,\n opts?: Partial<ImportOptions>,\n ) {\n const programPath = path.find(p => p.isProgram()) as NodePath<t.Program>;\n\n this._programPath = programPath;\n this._programScope = programPath.scope;\n this._hub = programPath.hub;\n\n this._defaultOpts = this._applyDefaults(importedSource, opts, true);\n }\n\n addDefault(importedSourceIn: string, opts: Partial<ImportOptions>) {\n return this.addNamed(\"default\", importedSourceIn, opts);\n }\n\n addNamed(\n importName: string,\n importedSourceIn: string,\n opts: Partial<ImportOptions>,\n ) {\n assert(typeof importName === \"string\");\n\n return this._generateImport(\n this._applyDefaults(importedSourceIn, opts),\n importName,\n );\n }\n\n addNamespace(importedSourceIn: string, opts: Partial<ImportOptions>) {\n return this._generateImport(\n this._applyDefaults(importedSourceIn, opts),\n null,\n );\n }\n\n addSideEffect(importedSourceIn: string, opts: Partial<ImportOptions>) {\n return this._generateImport(\n this._applyDefaults(importedSourceIn, opts),\n void 0,\n );\n }\n\n _applyDefaults(\n importedSource: string | Partial<ImportOptions>,\n opts: Partial<ImportOptions> | undefined,\n isInit = false,\n ) {\n let newOpts: ImportOptions;\n if (typeof importedSource === \"string\") {\n newOpts = { ...this._defaultOpts, importedSource, ...opts };\n } else {\n assert(!opts, \"Unexpected secondary arguments.\");\n newOpts = { ...this._defaultOpts, ...importedSource };\n }\n\n if (!isInit && opts) {\n if (opts.nameHint !== undefined) newOpts.nameHint = opts.nameHint;\n if (opts.blockHoist !== undefined) newOpts.blockHoist = opts.blockHoist;\n }\n return newOpts;\n }\n\n _generateImport(\n opts: Partial<ImportOptions>,\n importName: string | null | undefined,\n ) {\n const isDefault = importName === \"default\";\n const isNamed = !!importName && !isDefault;\n const isNamespace = importName === null;\n\n const {\n importedSource,\n importedType,\n importedInterop,\n importingInterop,\n ensureLiveReference,\n ensureNoContext,\n nameHint,\n importPosition,\n\n // Not meant for public usage. Allows code that absolutely must control\n // ordering to set a specific hoist value on the import nodes.\n // This is ignored when \"importPosition\" is \"after\".\n blockHoist,\n } = opts;\n\n // Provide a hint for generateUidIdentifier for the local variable name\n // to use for the import, if the code will generate a simple assignment\n // to a variable.\n let name = nameHint || importName;\n\n const isMod = isModule(this._programPath);\n const isModuleForNode = isMod && importingInterop === \"node\";\n const isModuleForBabel = isMod && importingInterop === \"babel\";\n\n if (importPosition === \"after\" && !isMod) {\n throw new Error(`\"importPosition\": \"after\" is only supported in modules`);\n }\n\n const builder = new ImportBuilder(\n importedSource,\n this._programScope,\n this._hub,\n );\n\n if (importedType === \"es6\") {\n if (!isModuleForNode && !isModuleForBabel) {\n throw new Error(\"Cannot import an ES6 module from CommonJS\");\n }\n\n // import * as namespace from ''; namespace\n // import def from ''; def\n // import { named } from ''; named\n builder.import();\n if (isNamespace) {\n builder.namespace(nameHint || importedSource);\n } else if (isDefault || isNamed) {\n builder.named(name, importName);\n }\n } else if (importedType !== \"commonjs\") {\n throw new Error(`Unexpected interopType \"${importedType}\"`);\n } else if (importedInterop === \"babel\") {\n if (isModuleForNode) {\n // import _tmp from ''; var namespace = interopRequireWildcard(_tmp); namespace\n // import _tmp from ''; var def = interopRequireDefault(_tmp).default; def\n // import _tmp from ''; _tmp.named\n name = name !== \"default\" ? name : importedSource;\n const es6Default = `${importedSource}$es6Default`;\n\n builder.import();\n if (isNamespace) {\n builder\n .default(es6Default)\n .var(name || importedSource)\n .wildcardInterop();\n } else if (isDefault) {\n if (ensureLiveReference) {\n builder\n .default(es6Default)\n .var(name || importedSource)\n .defaultInterop()\n .read(\"default\");\n } else {\n builder\n .default(es6Default)\n .var(name)\n .defaultInterop()\n .prop(importName);\n }\n } else if (isNamed) {\n builder.default(es6Default).read(importName);\n }\n } else if (isModuleForBabel) {\n // import * as namespace from ''; namespace\n // import def from ''; def\n // import { named } from ''; named\n builder.import();\n if (isNamespace) {\n builder.namespace(name || importedSource);\n } else if (isDefault || isNamed) {\n builder.named(name, importName);\n }\n } else {\n // var namespace = interopRequireWildcard(require(''));\n // var def = interopRequireDefault(require('')).default; def\n // var named = require('').named; named\n builder.require();\n if (isNamespace) {\n builder.var(name || importedSource).wildcardInterop();\n } else if ((isDefault || isNamed) && ensureLiveReference) {\n if (isDefault) {\n name = name !== \"default\" ? name : importedSource;\n builder.var(name).read(importName);\n builder.defaultInterop();\n } else {\n builder.var(importedSource).read(importName);\n }\n } else if (isDefault) {\n builder.var(name).defaultInterop().prop(importName);\n } else if (isNamed) {\n builder.var(name).prop(importName);\n }\n }\n } else if (importedInterop === \"compiled\") {\n if (isModuleForNode) {\n // import namespace from ''; namespace\n // import namespace from ''; namespace.default\n // import namespace from ''; namespace.named\n\n builder.import();\n if (isNamespace) {\n builder.default(name || importedSource);\n } else if (isDefault || isNamed) {\n builder.default(importedSource).read(name);\n }\n } else if (isModuleForBabel) {\n // import * as namespace from ''; namespace\n // import def from ''; def\n // import { named } from ''; named\n // Note: These lookups will break if the module has no __esModule set,\n // hence the warning that 'compiled' will not work on standard CommonJS.\n\n builder.import();\n if (isNamespace) {\n builder.namespace(name || importedSource);\n } else if (isDefault || isNamed) {\n builder.named(name, importName);\n }\n } else {\n // var namespace = require(''); namespace\n // var namespace = require(''); namespace.default\n // var namespace = require(''); namespace.named\n // var named = require('').named;\n builder.require();\n if (isNamespace) {\n builder.var(name || importedSource);\n } else if (isDefault || isNamed) {\n if (ensureLiveReference) {\n builder.var(importedSource).read(name);\n } else {\n builder.prop(importName).var(name);\n }\n }\n }\n } else if (importedInterop === \"uncompiled\") {\n if (isDefault && ensureLiveReference) {\n throw new Error(\"No live reference for commonjs default\");\n }\n\n if (isModuleForNode) {\n // import namespace from ''; namespace\n // import def from ''; def;\n // import namespace from ''; namespace.named\n builder.import();\n if (isNamespace) {\n builder.default(name || importedSource);\n } else if (isDefault) {\n builder.default(name);\n } else if (isNamed) {\n builder.default(importedSource).read(name);\n }\n } else if (isModuleForBabel) {\n // import namespace from '';\n // import def from '';\n // import { named } from ''; named;\n // Note: These lookups will break if the module has __esModule set,\n // hence the warning that 'uncompiled' will not work on ES6 transpiled\n // to CommonJS.\n\n builder.import();\n if (isNamespace) {\n builder.default(name || importedSource);\n } else if (isDefault) {\n builder.default(name);\n } else if (isNamed) {\n builder.named(name, importName);\n }\n } else {\n // var namespace = require(''); namespace\n // var def = require(''); def\n // var namespace = require(''); namespace.named\n // var named = require('').named;\n builder.require();\n if (isNamespace) {\n builder.var(name || importedSource);\n } else if (isDefault) {\n builder.var(name);\n } else if (isNamed) {\n if (ensureLiveReference) {\n builder.var(importedSource).read(name);\n } else {\n builder.var(name).prop(importName);\n }\n }\n }\n } else {\n throw new Error(`Unknown importedInterop \"${importedInterop}\".`);\n }\n\n const { statements, resultName } = builder.done();\n\n this._insertStatements(statements, importPosition, blockHoist);\n\n if (\n (isDefault || isNamed) &&\n ensureNoContext &&\n resultName.type !== \"Identifier\"\n ) {\n return sequenceExpression([numericLiteral(0), resultName]);\n }\n return resultName;\n }\n\n _insertStatements(\n statements: t.Statement[],\n importPosition = \"before\",\n blockHoist = 3,\n ) {\n if (importPosition === \"after\") {\n if (this._insertStatementsAfter(statements)) return;\n } else {\n if (this._insertStatementsBefore(statements, blockHoist)) return;\n }\n\n this._programPath.unshiftContainer(\"body\", statements);\n }\n\n _insertStatementsBefore(statements: t.Statement[], blockHoist: number) {\n if (\n statements.length === 1 &&\n isImportDeclaration(statements[0]) &&\n isValueImport(statements[0])\n ) {\n const firstImportDecl = this._programPath\n .get(\"body\")\n .find((p): p is NodePath<t.ImportDeclaration> => {\n return p.isImportDeclaration() && isValueImport(p.node);\n });\n\n if (\n firstImportDecl?.node.source.value === statements[0].source.value &&\n maybeAppendImportSpecifiers(firstImportDecl.node, statements[0])\n ) {\n return true;\n }\n }\n\n statements.forEach(node => {\n // @ts-expect-error handle _blockHoist\n node._blockHoist = blockHoist;\n });\n\n const targetPath = this._programPath.get(\"body\").find(p => {\n // @ts-expect-error todo(flow->ts): avoid mutations\n const val = p.node._blockHoist;\n return Number.isFinite(val) && val < 4;\n });\n\n if (targetPath) {\n targetPath.insertBefore(statements);\n return true;\n }\n\n return false;\n }\n\n _insertStatementsAfter(statements: t.Statement[]): boolean {\n const statementsSet = new Set(statements);\n const importDeclarations = new Map<string, t.ImportDeclaration[]>();\n\n for (const statement of statements) {\n if (isImportDeclaration(statement) && isValueImport(statement)) {\n const source = statement.source.value;\n if (!importDeclarations.has(source)) importDeclarations.set(source, []);\n importDeclarations.get(source).push(statement);\n }\n }\n\n let lastImportPath = null;\n for (const bodyStmt of this._programPath.get(\"body\")) {\n if (bodyStmt.isImportDeclaration() && isValueImport(bodyStmt.node)) {\n lastImportPath = bodyStmt;\n\n const source = bodyStmt.node.source.value;\n const newImports = importDeclarations.get(source);\n if (!newImports) continue;\n\n for (const decl of newImports) {\n if (!statementsSet.has(decl)) continue;\n if (maybeAppendImportSpecifiers(bodyStmt.node, decl)) {\n statementsSet.delete(decl);\n }\n }\n }\n }\n\n if (statementsSet.size === 0) return true;\n\n if (lastImportPath) lastImportPath.insertAfter(Array.from(statementsSet));\n\n return !!lastImportPath;\n }\n}\n\nfunction isValueImport(node: t.ImportDeclaration) {\n return node.importKind !== \"type\" && node.importKind !== \"typeof\";\n}\n\nfunction hasNamespaceImport(node: t.ImportDeclaration) {\n return (\n (node.specifiers.length === 1 &&\n node.specifiers[0].type === \"ImportNamespaceSpecifier\") ||\n (node.specifiers.length === 2 &&\n node.specifiers[1].type === \"ImportNamespaceSpecifier\")\n );\n}\n\nfunction hasDefaultImport(node: t.ImportDeclaration) {\n return (\n node.specifiers.length > 0 &&\n node.specifiers[0].type === \"ImportDefaultSpecifier\"\n );\n}\n\nfunction maybeAppendImportSpecifiers(\n target: t.ImportDeclaration,\n source: t.ImportDeclaration,\n): boolean {\n if (!target.specifiers.length) {\n target.specifiers = source.specifiers;\n return true;\n }\n if (!source.specifiers.length) return true;\n\n if (hasNamespaceImport(target) || hasNamespaceImport(source)) return false;\n\n if (hasDefaultImport(source)) {\n if (hasDefaultImport(target)) {\n source.specifiers[0] = importSpecifier(\n source.specifiers[0].local,\n identifier(\"default\"),\n );\n } else {\n target.specifiers.unshift(source.specifiers.shift());\n }\n }\n\n target.specifiers.push(...source.specifiers);\n\n return true;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAD,OAAA;AAUA,IAAAE,cAAA,GAAAF,OAA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AAC,CAAC,GAAGzG,eAAe,CACpC2E,MAAM,CAAC8B,UAAU,CAAC,CAAC,CAAC,CAACG,KAAK,EAC1B7G,UAAU,CAAC,SAAS,CACtB,CAAC;IACH,CAAC,MAAM;MACL4G,MAAM,CAACF,UAAU,CAACI,OAAO,CAAClC,MAAM,CAAC8B,UAAU,CAACK,KAAK,CAAC,CAAC,CAAC;IACtD;EACF;EAEAH,MAAM,CAACF,UAAU,CAACb,IAAI,CAAC,GAAGjB,MAAM,CAAC8B,UAAU,CAAC;EAE5C,OAAO,IAAI;AACb","ignoreList":[]}
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ImportInjector", {
7
- enumerable: true,
8
- get: function () {
9
- return _importInjector.default;
10
- }
11
- });
12
- exports.addDefault = addDefault;
13
- exports.addNamed = addNamed;
14
- exports.addNamespace = addNamespace;
15
- exports.addSideEffect = addSideEffect;
16
- Object.defineProperty(exports, "isModule", {
17
- enumerable: true,
18
- get: function () {
19
- return _isModule.default;
20
- }
21
- });
22
- var _importInjector = require("./import-injector.js");
23
- var _isModule = require("./is-module.js");
24
- function addDefault(path, importedSource, opts) {
25
- return new _importInjector.default(path).addDefault(importedSource, opts);
26
- }
27
- function addNamed(path, name, importedSource, opts) {
28
- return new _importInjector.default(path).addNamed(name, importedSource, opts);
29
- }
30
- function addNamespace(path, importedSource, opts) {
31
- return new _importInjector.default(path).addNamespace(importedSource, opts);
32
- }
33
- function addSideEffect(path, importedSource, opts) {
34
- return new _importInjector.default(path).addSideEffect(importedSource, opts);
35
- }
36
-
37
- //# sourceMappingURL=index.js.map