source: frontend/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyGenerator.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const { RawSource } = require("webpack-sources");
9const Generator = require("../Generator");
10const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypeConstants");
11
12/** @typedef {import("webpack-sources").Source} Source */
13/** @typedef {import("../Generator").GenerateContext} GenerateContext */
14/** @typedef {import("../Module").SourceType} SourceType */
15/** @typedef {import("../Module").SourceTypes} SourceTypes */
16/** @typedef {import("../NormalModule")} NormalModule */
17
18/**
19 * Represents the async web assembly generator runtime component.
20 * @typedef {object} AsyncWebAssemblyGeneratorOptions
21 * @property {boolean=} mangleImports mangle imports
22 */
23
24class AsyncWebAssemblyGenerator extends Generator {
25 /**
26 * Creates an instance of AsyncWebAssemblyGenerator.
27 * @param {AsyncWebAssemblyGeneratorOptions} options options
28 */
29 constructor(options) {
30 super();
31 /** @type {AsyncWebAssemblyGeneratorOptions} */
32 this.options = options;
33 }
34
35 /**
36 * Returns the source types available for this module.
37 * @param {NormalModule} module fresh module
38 * @returns {SourceTypes} available types (do not mutate)
39 */
40 getTypes(module) {
41 return WEBASSEMBLY_TYPES;
42 }
43
44 /**
45 * Returns the estimated size for the requested source type.
46 * @param {NormalModule} module the module
47 * @param {SourceType=} type source type
48 * @returns {number} estimate size of the module
49 */
50 getSize(module, type) {
51 const originalSource = module.originalSource();
52 if (!originalSource) {
53 return 0;
54 }
55 return originalSource.size();
56 }
57
58 /**
59 * Generates generated code for this runtime module.
60 * @param {NormalModule} module module for which the code should be generated
61 * @param {GenerateContext} generateContext context for generate
62 * @returns {Source | null} generated code
63 */
64 generate(module, generateContext) {
65 return /** @type {Source} */ (module.originalSource());
66 }
67
68 /**
69 * Generates fallback output for the provided error condition.
70 * @param {Error} error the error
71 * @param {NormalModule} module module for which the code should be generated
72 * @param {GenerateContext} generateContext context for generate
73 * @returns {Source | null} generated code
74 */
75 generateError(error, module, generateContext) {
76 return new RawSource(error.message);
77 }
78}
79
80module.exports = AsyncWebAssemblyGenerator;
Note: See TracBrowser for help on using the repository browser.