async-browser-context 0.2.4 → 0.3.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 (140) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +45 -30
  3. package/dist/babel/async-generator-helpers.d.ts +6 -6
  4. package/dist/babel/async-generator-helpers.d.ts.map +1 -1
  5. package/dist/babel/async-generator-helpers.js +33 -22
  6. package/dist/babel/async-generator-helpers.js.map +1 -1
  7. package/dist/babel/async-generator-resources.d.ts +14 -0
  8. package/dist/babel/async-generator-resources.d.ts.map +1 -0
  9. package/dist/babel/async-generator-resources.js +38 -0
  10. package/dist/babel/async-generator-resources.js.map +1 -0
  11. package/dist/babel/bind-generators.d.ts +1 -1
  12. package/dist/babel/bind-generators.d.ts.map +1 -1
  13. package/dist/babel/bind-generators.js +88 -44
  14. package/dist/babel/bind-generators.js.map +1 -1
  15. package/dist/babel/name-coroutines.d.ts +14 -8
  16. package/dist/babel/name-coroutines.d.ts.map +1 -1
  17. package/dist/babel/name-coroutines.js +160 -39
  18. package/dist/babel/name-coroutines.js.map +1 -1
  19. package/dist/babel/preset.d.ts +24 -13
  20. package/dist/babel/preset.d.ts.map +1 -1
  21. package/dist/babel/preset.js +37 -9
  22. package/dist/babel/preset.js.map +1 -1
  23. package/dist/babel/runtime-calls.d.ts +22 -0
  24. package/dist/babel/runtime-calls.d.ts.map +1 -0
  25. package/dist/babel/runtime-calls.js +69 -0
  26. package/dist/babel/runtime-calls.js.map +1 -0
  27. package/dist/babel/skip-runtime.d.ts +18 -11
  28. package/dist/babel/skip-runtime.d.ts.map +1 -1
  29. package/dist/babel/skip-runtime.js +52 -16
  30. package/dist/babel/skip-runtime.js.map +1 -1
  31. package/dist/babel/static-members.d.ts +4 -0
  32. package/dist/babel/static-members.d.ts.map +1 -0
  33. package/dist/babel/static-members.js +112 -0
  34. package/dist/babel/static-members.js.map +1 -0
  35. package/dist/core/async-generator.d.ts +26 -8
  36. package/dist/core/async-generator.d.ts.map +1 -1
  37. package/dist/core/async-generator.js +162 -44
  38. package/dist/core/async-generator.js.map +1 -1
  39. package/dist/core/async-local-storage.d.ts +3 -0
  40. package/dist/core/async-local-storage.d.ts.map +1 -1
  41. package/dist/core/async-local-storage.js +3 -0
  42. package/dist/core/async-local-storage.js.map +1 -1
  43. package/dist/core/callback-hook.d.ts +3 -3
  44. package/dist/core/coroutine.d.ts +6 -2
  45. package/dist/core/coroutine.d.ts.map +1 -1
  46. package/dist/core/coroutine.js +35 -21
  47. package/dist/core/coroutine.js.map +1 -1
  48. package/dist/core/function-name.d.ts +9 -0
  49. package/dist/core/function-name.d.ts.map +1 -0
  50. package/dist/core/function-name.js +12 -0
  51. package/dist/core/function-name.js.map +1 -0
  52. package/dist/core/hooks.d.ts +2 -1
  53. package/dist/core/hooks.d.ts.map +1 -1
  54. package/dist/core/hooks.js +21 -6
  55. package/dist/core/hooks.js.map +1 -1
  56. package/dist/core/snapshot.d.ts +2 -1
  57. package/dist/core/snapshot.d.ts.map +1 -1
  58. package/dist/core/snapshot.js +7 -3
  59. package/dist/core/snapshot.js.map +1 -1
  60. package/dist/core/store.d.ts +28 -0
  61. package/dist/core/store.d.ts.map +1 -1
  62. package/dist/core/store.js +90 -20
  63. package/dist/core/store.js.map +1 -1
  64. package/dist/core/variable.d.ts +2 -1
  65. package/dist/core/variable.d.ts.map +1 -1
  66. package/dist/core/variable.js +5 -2
  67. package/dist/core/variable.js.map +1 -1
  68. package/dist/node/index.d.ts +10 -4
  69. package/dist/node/index.d.ts.map +1 -1
  70. package/dist/node/index.js +51 -16
  71. package/dist/node/index.js.map +1 -1
  72. package/dist/node/runtime.d.ts +7 -6
  73. package/dist/node/runtime.d.ts.map +1 -1
  74. package/dist/node/runtime.js +29 -16
  75. package/dist/node/runtime.js.map +1 -1
  76. package/dist/opentelemetry/context-manager.d.ts.map +1 -1
  77. package/dist/opentelemetry/context-manager.js +172 -13
  78. package/dist/opentelemetry/context-manager.js.map +1 -1
  79. package/dist/patches/callbacks.d.ts.map +1 -1
  80. package/dist/patches/callbacks.js +84 -29
  81. package/dist/patches/callbacks.js.map +1 -1
  82. package/dist/patches/events.d.ts.map +1 -1
  83. package/dist/patches/events.js +203 -91
  84. package/dist/patches/events.js.map +1 -1
  85. package/dist/patches/handler-interfaces.d.ts +3 -2
  86. package/dist/patches/handler-interfaces.d.ts.map +1 -1
  87. package/dist/patches/handler-interfaces.js +3 -2
  88. package/dist/patches/handler-interfaces.js.map +1 -1
  89. package/dist/patches/promise.d.ts +3 -0
  90. package/dist/patches/promise.d.ts.map +1 -1
  91. package/dist/patches/promise.js +13 -5
  92. package/dist/patches/promise.js.map +1 -1
  93. package/dist/patches/streams.d.ts.map +1 -1
  94. package/dist/patches/streams.js +36 -16
  95. package/dist/patches/streams.js.map +1 -1
  96. package/dist/patches/timers.d.ts.map +1 -1
  97. package/dist/patches/timers.js +17 -5
  98. package/dist/patches/timers.js.map +1 -1
  99. package/dist/patches/to-string.d.ts +4 -0
  100. package/dist/patches/to-string.d.ts.map +1 -1
  101. package/dist/patches/to-string.js +12 -6
  102. package/dist/patches/to-string.js.map +1 -1
  103. package/dist/runtime.d.ts +3 -3
  104. package/dist/runtime.d.ts.map +1 -1
  105. package/dist/runtime.js +3 -3
  106. package/dist/runtime.js.map +1 -1
  107. package/dist/vite/plugin.d.ts +7 -2
  108. package/dist/vite/plugin.d.ts.map +1 -1
  109. package/dist/vite/plugin.js +30 -6
  110. package/dist/vite/plugin.js.map +1 -1
  111. package/package.json +49 -25
  112. package/src/babel/async-generator-helpers.ts +34 -23
  113. package/src/babel/async-generator-resources.ts +40 -0
  114. package/src/babel/bind-generators.ts +91 -47
  115. package/src/babel/name-coroutines.ts +170 -41
  116. package/src/babel/preset.ts +47 -15
  117. package/src/babel/runtime-calls.ts +73 -0
  118. package/src/babel/skip-runtime.ts +58 -18
  119. package/src/babel/static-members.ts +117 -0
  120. package/src/core/async-generator.ts +169 -46
  121. package/src/core/async-local-storage.ts +3 -0
  122. package/src/core/callback-hook.ts +3 -3
  123. package/src/core/coroutine.ts +35 -21
  124. package/src/core/function-name.ts +11 -0
  125. package/src/core/hooks.ts +23 -6
  126. package/src/core/snapshot.ts +8 -3
  127. package/src/core/store.ts +107 -21
  128. package/src/core/variable.ts +6 -2
  129. package/src/node/index.ts +62 -19
  130. package/src/node/runtime.ts +33 -15
  131. package/src/opentelemetry/context-manager.ts +188 -13
  132. package/src/patches/callbacks.ts +87 -30
  133. package/src/patches/events.ts +249 -103
  134. package/src/patches/handler-interfaces.ts +3 -2
  135. package/src/patches/promise.ts +17 -13
  136. package/src/patches/streams.ts +36 -16
  137. package/src/patches/timers.ts +17 -5
  138. package/src/patches/to-string.ts +12 -6
  139. package/src/runtime.ts +3 -3
  140. package/src/vite/plugin.ts +38 -8
@@ -1,41 +1,22 @@
1
1
  import { types } from "@babel/core";
2
2
  import { addNamed } from "@babel/helper-module-imports";
3
+ import { isRuntimeCallee, isRuntimeFunction } from "./runtime-calls.js";
3
4
  /** The key of the file metadata that tells if the preset changed the file. */
4
5
  export const METADATA_KEY = "asyncBrowserContext";
5
6
  /**
6
- * The local names of the async generator helper: `wrapAsyncGenerator` of
7
- * `@babel/plugin-transform-async-generator-functions`, or `asyncGenerator` of the runtime,
8
- * which the preset gives in its place. Babel gives them an underscore.
7
+ * This function gives `true` if `path` is the generator that a driver of the runtime operates:
8
+ * the argument of `coroutine` or `asyncGenerator`. The driver keeps the context itself, so the
9
+ * plugin does not bind it. This is the case when the preset transforms its own output again.
10
+ * The generator of a Babel helper, for example `_wrapAsyncGenerator`, gets a binding.
9
11
  */
10
- const ASYNC_GENERATOR_HELPER = /^_(wrapAsyncGenerator|asyncGenerator)\d*$/;
11
- /** The local names that `addNamed` gives to `bindGenerator`. */
12
- const BIND_GENERATOR_NAME = /^_bindGenerator\d*$/;
13
- /** This function gives `true` if `path` is the generator that Babel gives to its async generator helper. */
14
- function isAsyncGeneratorHelperArgument(path) {
15
- const parent = path.parent;
16
- if (!types.isCallExpression(parent)) {
12
+ function isDriverArgument(path, runtime) {
13
+ // A function always has a parent path: at least the program
14
+ const call = path.parentPath;
15
+ if (!call.isCallExpression() || call.node.arguments[0] !== path.node) {
17
16
  return false;
18
17
  }
19
- if (types.isIdentifier(parent.callee)) {
20
- return ASYNC_GENERATOR_HELPER.test(parent.callee.name);
21
- }
22
- // CommonJS output of the preset: _runtime.asyncGenerator or (0, _runtime.asyncGenerator)
23
- const member = types.isSequenceExpression(parent.callee) ? parent.callee.expressions.at(-1) : parent.callee;
24
- return types.isMemberExpression(member) && types.isIdentifier(member.property, { name: "asyncGenerator" });
25
- }
26
- /**
27
- * This function gives `true` if `callee` is the `bindGenerator` function of
28
- * the runtime: an import, or `_runtime.bindGenerator` in CommonJS output,
29
- * also in the form `(0, _runtime.bindGenerator)`.
30
- */
31
- function isBindGeneratorCallee(callee, path, runtime) {
32
- if (types.isIdentifier(callee)) {
33
- // Stryker disable next-line StringLiteral: referencesImport with an empty name accepts each import of the runtime, which gives the same result here
34
- return BIND_GENERATOR_NAME.test(callee.name) || path.referencesImport(runtime, "bindGenerator");
35
- }
36
- // Stryker disable next-line UnaryOperator: the sequence (0, _runtime.bindGenerator) has two expressions, so at(1) gives the same expression
37
- const member = types.isSequenceExpression(callee) ? callee.expressions.at(-1) : callee;
38
- return types.isMemberExpression(member) && types.isIdentifier(member.property, { name: "bindGenerator" });
18
+ const callee = call.get("callee");
19
+ return isRuntimeCallee(callee, runtime, "coroutine") || isRuntimeCallee(callee, runtime, "asyncGenerator");
39
20
  }
40
21
  /** This function gives `true` if this plugin already changed the generator: `bindGenerator((function* () {...})())`. */
41
22
  function isAlreadyBound(path, runtime) {
@@ -43,13 +24,53 @@ function isAlreadyBound(path, runtime) {
43
24
  const call = path.parentPath;
44
25
  const outer = call.parentPath;
45
26
  return call.isCallExpression() && call.node.callee === path.node
46
- && outer.isCallExpression() && isBindGeneratorCallee(outer.node.callee, outer.get("callee"), runtime);
27
+ && outer.isCallExpression() && isRuntimeCallee(outer.get("callee"), runtime, "bindGenerator");
47
28
  }
48
29
  /**
49
- * This function changes one generator function. The function stays the same kind of
50
- * function, with the same name and parameters, so declarations stay hoisted
51
- * and `length` does not change. The body moves into an inner generator, and
52
- * the function gives `bindGenerator(inner())`:
30
+ * This function gives the names of the parameters that the body declares again with `var` or
31
+ * with a function declaration. In the original function, such a variable starts with the value
32
+ * of the parameter. A function declaration in a block of sloppy code is not hoisted over it. The inner
33
+ * function gets these names as its parameters, so the values stay the same.
34
+ */
35
+ function redeclaredParameters(path) {
36
+ const parameters = new Set();
37
+ for (const parameter of path.node.params) {
38
+ for (const name of Object.keys(types.getBindingIdentifiers(parameter))) {
39
+ parameters.add(name);
40
+ }
41
+ }
42
+ const redeclared = new Set();
43
+ path.get("body").traverse({
44
+ Function(inner) {
45
+ // A function declaration in a block of sloppy code is hoisted (Annex B.3.3), but not
46
+ // over a parameter with the same name. In the inner generator, the name is no parameter.
47
+ if (inner.isFunctionDeclaration()) {
48
+ // A function declaration in a body always has a name
49
+ const { name } = inner.node.id;
50
+ if (parameters.has(name)) {
51
+ redeclared.add(name);
52
+ }
53
+ }
54
+ inner.skip();
55
+ },
56
+ VariableDeclaration(declaration) {
57
+ if (declaration.node.kind !== "var") {
58
+ return;
59
+ }
60
+ for (const name of Object.keys(declaration.getBindingIdentifiers())) {
61
+ if (parameters.has(name)) {
62
+ redeclared.add(name);
63
+ }
64
+ }
65
+ },
66
+ });
67
+ return [...redeclared];
68
+ }
69
+ /**
70
+ * This function changes one generator function. The function keeps its name and its
71
+ * parameters, so a declaration stays hoisted and `length` does not change. It becomes a plain
72
+ * function: `fn.constructor` is `Function`, not `GeneratorFunction`. The body moves into an
73
+ * inner generator, and the function gives `bindGenerator(inner())`:
53
74
  *
54
75
  * ```js
55
76
  * function* numbers(limit) { ...body... }
@@ -64,15 +85,36 @@ function bindGeneratorFunction(path, bindGenerator) {
64
85
  const node = path.node;
65
86
  // A generator function always has a block body: an arrow function cannot be a generator
66
87
  const body = node.body;
67
- const inner = types.functionExpression(null, [], types.blockStatement(body.body), true, node.async);
68
- node.body = types.blockStatement([types.returnStatement(types.callExpression(bindGenerator, [types.callExpression(inner, [])]))], body.directives);
88
+ const passed = redeclaredParameters(path);
89
+ const inner = types.functionExpression(null, passed.map((name) => types.identifier(name)), types.blockStatement(body.body), true, node.async);
90
+ node.body = types.blockStatement([types.returnStatement(types.callExpression(bindGenerator, [types.callExpression(inner, passed.map((name) => types.identifier(name)))]))], body.directives);
69
91
  node.generator = false;
70
92
  node.async = false;
71
93
  const innerPath = path.get("body.body.0.argument.arguments.0.callee");
72
94
  innerPath.unwrapFunctionEnvironment();
73
95
  }
74
96
  /**
75
- * The Babel plugin that binds generators to the context of their creation
97
+ * A generator declaration in a block of a script (sloppy mode) is not hoisted out of the block,
98
+ * but a plain function declaration is (Annex B.3.3). The changed declaration thus becomes a
99
+ * `let` at the start of its block, with the same name.
100
+ */
101
+ function keepBlockScope(path) {
102
+ // A function and a block always have a parent path: at least the program
103
+ const block = path.parentPath;
104
+ if (!block.isBlockStatement() || block.parentPath.isFunction() || path.isInStrictMode()) {
105
+ return;
106
+ }
107
+ // Only a function declaration is a statement of a block, and it always has a name
108
+ const { id, params, body } = path.node;
109
+ const name = id.name;
110
+ const declaration = types.variableDeclaration("let", [
111
+ types.variableDeclarator(types.identifier(name), types.functionExpression(types.identifier(name), params, body)),
112
+ ]);
113
+ path.remove();
114
+ block.unshiftContainer("body", declaration);
115
+ }
116
+ /**
117
+ * The Babel plugin that binds sync generators to the context of their creation
76
118
  * (rule C5). It changes the code in `Program` enter, before the async
77
119
  * generator transform changes the async generators.
78
120
  */
@@ -91,20 +133,22 @@ export function bindGeneratorsPlugin(_api, options) {
91
133
  programPath.traverse({
92
134
  Function(path) {
93
135
  const node = path.node;
136
+ if (isRuntimeFunction(node)) {
137
+ // The native async functions of the runtime stay native (skip-runtime.ts)
138
+ path.skip();
139
+ return;
140
+ }
94
141
  if (node.async) {
142
+ // The async transforms change this function
95
143
  changed = true;
96
144
  }
97
145
  // The driver of the runtime keeps the context of an async generator (asyncGenerator)
98
- if (!node.generator || node.async || isAsyncGeneratorHelperArgument(path) || isAlreadyBound(path, runtime)) {
146
+ if (!node.generator || node.async || isDriverArgument(path, runtime) || isAlreadyBound(path, runtime)) {
99
147
  return;
100
148
  }
101
149
  changed = true;
102
150
  bindGeneratorFunction(path, bindGenerator());
103
- },
104
- ForOfStatement(path) {
105
- if (path.node.await) {
106
- changed = true;
107
- }
151
+ keepBlockScope(path);
108
152
  },
109
153
  });
110
154
  if (changed) {
@@ -1 +1 @@
1
- {"version":3,"file":"bind-generators.js","sourceRoot":"","sources":["../../src/babel/bind-generators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqD,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAQxD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAElD;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,2CAA2C,CAAC;AAC3E,gEAAgE;AAChE,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAIlD,4GAA4G;AAC5G,SAAS,8BAA8B,CAAC,IAAmB;IACvD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,OAAO,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IACD,yFAAyF;IACzF,MAAM,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,WA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B,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;4BACpG,OAAO;wBACX,CAAC;wBACD,OAAO,GAAG,IAAI,CAAC;wBACf,qBAAqB,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;wBAC7C,cAAc,CAAC,IAAI,CAAC,CAAC;oBACzB,CAAC;iBACJ,CAAC,CAAC;gBACH,IAAI,OAAO,EAAE,CAAC;oBACT,KAAK,CAAC,IAAI,CAAC,QAA+C,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;gBACrF,CAAC;YACL,CAAC;SACJ;KACJ,CAAC;AACN,CAAC"}
@@ -1,9 +1,14 @@
1
1
  import { types, type NodePath, type PluginObject, type PluginPass } from "@babel/core";
2
2
  /** The options of the plugin. */
3
3
  export interface NameCoroutinesOptions {
4
- /** The module that exports `coroutine`. */
4
+ /** The module that exports `coroutine` and `asyncGenerator`. */
5
5
  readonly runtime: string;
6
6
  }
7
+ /**
8
+ * This function gives the name of a property key, or `undefined` if the name is known only at run time.
9
+ * The plugin of static members (static-members.ts) uses it too.
10
+ */
11
+ export declare function keyName(key: types.Node, computed: boolean): string | undefined;
7
12
  /**
8
13
  * This function gives the `name` that JavaScript gives to the function, or
9
14
  * `undefined` if the name is not known before run time.
@@ -11,15 +16,16 @@ export interface NameCoroutinesOptions {
11
16
  export declare function functionName(path: NodePath<types.Function>): string | undefined;
12
17
  /**
13
18
  * The Babel plugin that gives the name of each async function to `coroutine`:
14
- * `_coroutine(function* () {...}, "load")`. The generator function of
15
- * `@babel/plugin-transform-async-to-generator` has no name, and the callback
16
- * hooks of the runtime show the name of the async function.
19
+ * `_coroutine(function* () {...}, "load")`, and of each async generator to
20
+ * `asyncGenerator`. The generator function of the Babel transforms has no name,
21
+ * and the callback hooks of the runtime show the name of the function.
17
22
  *
18
- * In `Program` enter, before the async transform, the plugin records the
23
+ * In `Program` enter, before the async transforms, the plugin records the
19
24
  * name of each async function. In `Program` exit, it adds the name to each
20
- * `coroutine` call. For a plain function, the async transform keeps the
21
- * function node as the argument of `coroutine`. For a method, the call is in
22
- * the body of the method.
25
+ * call of `coroutine` or `asyncGenerator`. For a plain function, the async
26
+ * transform keeps the function node as the argument of the call. For a method,
27
+ * the call is in the body of the method. A different call, for example a call
28
+ * that another plugin adds to a method, gets no name.
23
29
  */
24
30
  export declare function nameCoroutinesPlugin(_api: unknown, options: object): PluginObject<PluginPass>;
25
31
  //# sourceMappingURL=name-coroutines.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"name-coroutines.d.ts","sourceRoot":"","sources":["../../src/babel/name-coroutines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvF,iCAAiC;AACjC,MAAM,WAAW,qBAAqB;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC;CAC7B;AAyBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAI,MAAM,GAAG,SAAS,CAsBjF;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAG,OAAO,EAAE,OAAO,EAAG,MAAM,GAAI,YAAY,CAAC,UAAU,CAAC,CA4ChG"}
1
+ {"version":3,"file":"name-coroutines.d.ts","sourceRoot":"","sources":["../../src/babel/name-coroutines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvF,iCAAiC;AACjC,MAAM,WAAW,qBAAqB;IAClC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC;CAC7B;AAKD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAG,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAG,OAAO,GAAI,MAAM,GAAG,SAAS,CAmBjF;AAmCD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAI,MAAM,GAAG,SAAS,CAgBjF;AAmGD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAG,OAAO,EAAE,OAAO,EAAG,MAAM,GAAI,YAAY,CAAC,UAAU,CAAC,CAsDhG"}
@@ -1,110 +1,231 @@
1
1
  import { types } from "@babel/core";
2
- /** The local names that Babel gives to the import of `coroutine`. */
3
- const COROUTINE_NAME = /^_coroutine\d*$/;
2
+ import { isRuntimeCallee, isRuntimeFunction } from "./runtime-calls.js";
4
3
  /** The assignment operators that give a name to an anonymous function, as in the specification (NamedEvaluation). */
5
4
  const NAMING_OPERATORS = new Set(["=", "&&=", "||=", "??="]);
6
- /** This function gives the name of a property key, or `undefined` if the name is known only at run time. */
7
- function keyName(key, computed) {
5
+ /**
6
+ * This function gives the name of a property key, or `undefined` if the name is known only at run time.
7
+ * The plugin of static members (static-members.ts) uses it too.
8
+ */
9
+ export function keyName(key, computed) {
8
10
  if (types.isStringLiteral(key)) {
9
11
  return key.value;
10
12
  }
11
13
  if (types.isNumericLiteral(key)) {
12
14
  return String(key.value);
13
15
  }
16
+ if (types.isBigIntLiteral(key)) {
17
+ // Babel 8 gives a bigint, and Babel 7 gives the text of the number, for example "0x10"
18
+ return String(BigInt(key.value));
19
+ }
14
20
  if (computed) {
15
21
  return undefined;
16
22
  }
17
23
  if (types.isIdentifier(key)) {
18
24
  return key.name;
19
25
  }
26
+ // A decimal literal of Babel 7 gets no name
20
27
  return types.isPrivateName(key) ? `#${key.id.name}` : undefined;
21
28
  }
29
+ /** This function gives `true` for a TypeScript or Flow wrapper of an expression, which does not change the name of a function. */
30
+ function isTypeWrapper(path) {
31
+ return path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression()
32
+ || path.isTSTypeAssertion() || path.isTypeCastExpression() || path.isParenthesizedExpression();
33
+ }
34
+ /** This function gives the name of an identifier, or `undefined` for a pattern or a member expression. */
35
+ function identifierName(node) {
36
+ return types.isIdentifier(node) ? node.name : undefined;
37
+ }
38
+ /**
39
+ * This function gives the name that `parent` gives to an anonymous function in it, or `undefined`.
40
+ * A function cannot be the target of a declarator or an assignment, so there it is the value. As a
41
+ * computed key, it gets no name from `keyName`.
42
+ */
43
+ function nameFromParent(parent) {
44
+ if (types.isVariableDeclarator(parent)) {
45
+ return identifierName(parent.id);
46
+ }
47
+ if (types.isAssignmentExpression(parent)) {
48
+ return NAMING_OPERATORS.has(parent.operator) ? identifierName(parent.left) : undefined;
49
+ }
50
+ if (types.isAssignmentPattern(parent)) {
51
+ return identifierName(parent.left);
52
+ }
53
+ if (types.isObjectProperty(parent) || types.isClassProperty(parent) || types.isClassPrivateProperty(parent) || types.isClassAccessorProperty(parent)) {
54
+ // A private property has no computed field
55
+ return keyName(parent.key, parent.computed === true);
56
+ }
57
+ return types.isExportDefaultDeclaration(parent) ? "default" : undefined;
58
+ }
22
59
  /**
23
60
  * This function gives the `name` that JavaScript gives to the function, or
24
61
  * `undefined` if the name is not known before run time.
25
62
  */
26
63
  export function functionName(path) {
27
64
  const node = path.node;
28
- if ((types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) && node.id) {
29
- return node.id.name;
65
+ // Only a function declaration or a function expression has an id. The parser gives null to the other functions.
66
+ const id = node.id;
67
+ if (id != null) {
68
+ return id.name;
30
69
  }
31
- if (types.isObjectMethod(node) || types.isClassMethod(node) || types.isClassPrivateMethod(node)) {
70
+ if (types.isMethod(node)) {
32
71
  return keyName(node.key, node.computed === true);
33
72
  }
34
- const parent = path.parent;
35
- if (types.isVariableDeclarator(parent) && parent.init === node && types.isIdentifier(parent.id)) {
36
- return parent.id.name;
73
+ // `const h = (async () => {}) as Handler` names the function `h`. A function and a wrapper always have a parent path.
74
+ let parentPath = path.parentPath;
75
+ while (isTypeWrapper(parentPath)) {
76
+ parentPath = parentPath.parentPath;
37
77
  }
38
- if (types.isAssignmentExpression(parent) && parent.right === node && NAMING_OPERATORS.has(parent.operator) && types.isIdentifier(parent.left)) {
39
- return parent.left.name;
78
+ return nameFromParent(parentPath.node);
79
+ }
80
+ /**
81
+ * Where the async transform has no name for the function, for example in a class field or as
82
+ * an argument, it gives an anonymous wrapper:
83
+ *
84
+ * ```js
85
+ * function () { var _ref = _coroutine(function* (value) {...}, "save"); return function (_x) { return _ref.apply(this, arguments); }; }()
86
+ * ```
87
+ *
88
+ * This function gives that wrapper the name of the source, so `fn.name` stays the same. The
89
+ * wrapper uses only `_ref`, `this` and `arguments`. The name of the function hides a `_ref` with
90
+ * the same name, for example for a field named `_ref`. Thus `_ref` then gets a new name first. A name that a function expression cannot have, for example `eval`,
91
+ * `arguments` or `"my-handler"`, goes to the `name` property with `Object.defineProperty`.
92
+ */
93
+ function nameReturnedWrapper(call, name) {
94
+ // A call is always in a statement, so it has a parent path and a grandparent path. In the other
95
+ // forms of the async transform, the next statement is not a return of a function expression,
96
+ // or there is no next statement, for example in a class field.
97
+ const declarator = call.parentPath;
98
+ const declaration = declarator.parentPath;
99
+ const next = declaration.getSibling(declaration.key + 1);
100
+ if (next.isFunctionDeclaration()) {
101
+ nameDeclaredWrapper(next, declaration.getSibling(declaration.key + 2), name);
102
+ return;
40
103
  }
41
- if (types.isAssignmentPattern(parent) && parent.right === node && types.isIdentifier(parent.left)) {
42
- return parent.left.name;
104
+ if (!next.isReturnStatement() || !next.get("argument").isFunctionExpression()) {
105
+ return;
43
106
  }
44
- if ((types.isObjectProperty(parent) || types.isClassProperty(parent) || types.isClassPrivateProperty(parent)) && parent.value === node) {
45
- return keyName(parent.key, "computed" in parent && parent.computed === true);
107
+ // A named function expression gets a wrapper with the same name, so a second name changes nothing
108
+ const returnedPath = next.get("argument");
109
+ const returned = returnedPath.node;
110
+ // A class body and a module are strict code, where a function cannot have the name eval or arguments
111
+ if (types.isValidIdentifier(name) && !STRICT_BIND_ONLY.has(name)) {
112
+ // Only a declarator gives `var _ref = <call>` before a returned function expression
113
+ const reference = declarator.node.id;
114
+ if (types.isIdentifier(reference, { name })) {
115
+ // `_ref` is a new name of Babel, so only its declaration and the wrapper use it
116
+ const renamed = declaration.scope.generateUidIdentifier(name).name;
117
+ reference.name = renamed;
118
+ renameIdentifiers(returned, name, renamed);
119
+ }
120
+ returned.id = types.identifier(name);
121
+ return;
46
122
  }
47
- return types.isExportDefaultDeclaration(parent) ? "default" : undefined;
123
+ if (next.scope.getBinding("Object") !== undefined) {
124
+ // The code has its own Object, so the global function is not available
125
+ return;
126
+ }
127
+ returnedPath.replaceWith(withName(returned, name));
48
128
  }
49
- /** This function gives `true` if `callee` is the `coroutine` function of the runtime, also in CommonJS output. */
50
- function isCoroutineCallee(callee, path, runtime) {
51
- if (types.isIdentifier(callee)) {
52
- return COROUTINE_NAME.test(callee.name) || path.referencesImport(runtime, "coroutine");
129
+ /**
130
+ * A key is not always a binding name, for example `"a b"`, `42` or `default`. For such a key,
131
+ * the async transform gives a wrapper declaration with a binding name that it makes from the key:
132
+ *
133
+ * ```js
134
+ * function () { var _a_b = _coroutine(function* () {...}, "a b"); function a_b() {...} return a_b; }()
135
+ * ```
136
+ *
137
+ * This function gives that wrapper the name of the source with `Object.defineProperty`, if the
138
+ * two names are not the same.
139
+ */
140
+ function nameDeclaredWrapper(wrapper, after, name) {
141
+ const id = wrapper.node.id;
142
+ if (id === null || id === undefined || id.name === name || !after.isReturnStatement()) {
143
+ return;
53
144
  }
54
- const member = types.isSequenceExpression(callee) ? callee.expressions.at(-1) : callee;
55
- return types.isMemberExpression(member) && types.isIdentifier(member.property, { name: "coroutine" });
145
+ const returned = after.node.argument;
146
+ if (!types.isIdentifier(returned, { name: id.name }) || after.scope.getBinding("Object") !== undefined) {
147
+ return;
148
+ }
149
+ after.get("argument").replaceWith(withName(returned, name));
150
+ }
151
+ /** This function gives `Object.defineProperty(fn, "name", { value : name, configurable : true })`, which gives `fn`. */
152
+ function withName(fn, name) {
153
+ const descriptor = types.objectExpression([
154
+ types.objectProperty(types.identifier("value"), types.stringLiteral(name)),
155
+ types.objectProperty(types.identifier("configurable"), types.booleanLiteral(true)),
156
+ ]);
157
+ return types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("defineProperty")), [fn, types.stringLiteral("name"), descriptor]);
158
+ }
159
+ /** The names that strict code cannot bind, also as the name of a function expression. */
160
+ const STRICT_BIND_ONLY = new Set(["eval", "arguments"]);
161
+ /** This function gives each identifier `from` in `node` the name `to`. */
162
+ function renameIdentifiers(node, from, to) {
163
+ types.traverseFast(node, (child) => {
164
+ if (types.isIdentifier(child) && child.name === from) {
165
+ child.name = to;
166
+ }
167
+ });
56
168
  }
57
- /** The key of the names of one file in the plugin state. */
58
- const NAMES_KEY = "async-browser-context/coroutine-names";
59
169
  /**
60
170
  * The Babel plugin that gives the name of each async function to `coroutine`:
61
- * `_coroutine(function* () {...}, "load")`. The generator function of
62
- * `@babel/plugin-transform-async-to-generator` has no name, and the callback
63
- * hooks of the runtime show the name of the async function.
171
+ * `_coroutine(function* () {...}, "load")`, and of each async generator to
172
+ * `asyncGenerator`. The generator function of the Babel transforms has no name,
173
+ * and the callback hooks of the runtime show the name of the function.
64
174
  *
65
- * In `Program` enter, before the async transform, the plugin records the
175
+ * In `Program` enter, before the async transforms, the plugin records the
66
176
  * name of each async function. In `Program` exit, it adds the name to each
67
- * `coroutine` call. For a plain function, the async transform keeps the
68
- * function node as the argument of `coroutine`. For a method, the call is in
69
- * the body of the method.
177
+ * call of `coroutine` or `asyncGenerator`. For a plain function, the async
178
+ * transform keeps the function node as the argument of the call. For a method,
179
+ * the call is in the body of the method. A different call, for example a call
180
+ * that another plugin adds to a method, gets no name.
70
181
  */
71
182
  export function nameCoroutinesPlugin(_api, options) {
72
183
  const { runtime } = options;
184
+ // The names of the async functions of each file, from Program enter to Program exit
185
+ const namesOfFile = new WeakMap();
73
186
  return {
74
187
  name: "async-browser-context/name-coroutines",
75
188
  visitor: {
76
189
  Program: {
77
190
  enter(programPath, state) {
78
191
  const names = new WeakMap();
192
+ namesOfFile.set(state, names);
79
193
  programPath.traverse({
80
194
  Function(path) {
81
- if (!path.node.async || path.node.generator) {
195
+ if (isRuntimeFunction(path.node)) {
196
+ // The native async functions of the runtime stay native (skip-runtime.ts)
197
+ path.skip();
198
+ return;
199
+ }
200
+ if (!path.node.async) {
82
201
  return;
83
202
  }
84
203
  const name = functionName(path);
85
- if (name !== undefined && name !== "") {
204
+ // The empty name, for example of the key "", is no name
205
+ if (name) {
86
206
  names.set(path.node, name);
87
207
  }
88
208
  },
89
209
  });
90
- state.set(NAMES_KEY, names);
91
210
  },
92
211
  exit(programPath, state) {
93
- const names = state.get(NAMES_KEY);
212
+ const names = namesOfFile.get(state);
94
213
  programPath.traverse({
95
214
  CallExpression(path) {
96
- const { callee, arguments: args } = path.node;
215
+ const { arguments: args } = path.node;
97
216
  const [body] = args;
98
- if (args.length !== 1 || !types.isFunctionExpression(body) || !body.generator) {
217
+ if (args.length !== 1 || !types.isFunctionExpression(body, { generator: true })) {
99
218
  return;
100
219
  }
101
- if (!isCoroutineCallee(callee, path.get("callee"), runtime)) {
220
+ const callee = path.get("callee");
221
+ if (!isRuntimeCallee(callee, runtime, "coroutine") && !isRuntimeCallee(callee, runtime, "asyncGenerator")) {
102
222
  return;
103
223
  }
104
224
  const parent = path.getFunctionParent()?.node;
105
225
  const name = names.get(body) ?? (types.isMethod(parent) ? names.get(parent) : undefined);
106
226
  if (name !== undefined) {
107
227
  args.push(types.stringLiteral(name));
228
+ nameReturnedWrapper(path, name);
108
229
  }
109
230
  },
110
231
  });
@@ -1 +1 @@
1
- {"version":3,"file":"name-coroutines.js","sourceRoot":"","sources":["../../src/babel/name-coroutines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqD,MAAM,aAAa,CAAC;AAQvF,qEAAqE;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