source: imaps-frontend/node_modules/webpack/lib/async-modules/AwaitDependenciesInitFragment.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[79a0317]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const InitFragment = require("../InitFragment");
9const RuntimeGlobals = require("../RuntimeGlobals");
10const Template = require("../Template");
11
12/** @typedef {import("webpack-sources").Source} Source */
13/** @typedef {import("../Generator").GenerateContext} GenerateContext */
14
15/**
16 * @extends {InitFragment<GenerateContext>}
17 */
18class AwaitDependenciesInitFragment extends InitFragment {
19 /**
20 * @param {Set<string>} promises the promises that should be awaited
21 */
22 constructor(promises) {
23 super(
24 undefined,
25 InitFragment.STAGE_ASYNC_DEPENDENCIES,
26 0,
27 "await-dependencies"
28 );
29 this.promises = promises;
30 }
31
32 /**
33 * @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
34 * @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
35 */
36 merge(other) {
37 const promises = new Set(other.promises);
38 for (const p of this.promises) {
39 promises.add(p);
40 }
41 return new AwaitDependenciesInitFragment(promises);
42 }
43
44 /**
45 * @param {GenerateContext} context context
46 * @returns {string | Source | undefined} the source code that will be included as initialization code
47 */
48 getContent({ runtimeRequirements }) {
49 runtimeRequirements.add(RuntimeGlobals.module);
50 const promises = this.promises;
51 if (promises.size === 0) {
52 return "";
53 }
54 if (promises.size === 1) {
55 const [p] = promises;
56 return Template.asString([
57 `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${p}]);`,
58 `${p} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];`,
59 ""
60 ]);
61 }
62 const sepPromises = Array.from(promises).join(", ");
63 // TODO check if destructuring is supported
64 return Template.asString([
65 `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${sepPromises}]);`,
66 `([${sepPromises}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`,
67 ""
68 ]);
69 }
70}
71
72module.exports = AwaitDependenciesInitFragment;
Note: See TracBrowser for help on using the repository browser.