UNPKG

1.27 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const Generator = require("../Generator");
9
10/** @typedef {import("webpack-sources").Source} Source */
11/** @typedef {import("../Generator").GenerateContext} GenerateContext */
12/** @typedef {import("../NormalModule")} NormalModule */
13
14const TYPES = new Set(["webassembly"]);
15
16class AsyncWebAssemblyGenerator extends Generator {
17 constructor(options) {
18 super();
19 this.options = options;
20 }
21
22 /**
23 * @param {NormalModule} module fresh module
24 * @returns {Set<string>} available types (do not mutate)
25 */
26 getTypes(module) {
27 return TYPES;
28 }
29
30 /**
31 * @param {NormalModule} module the module
32 * @param {string=} type source type
33 * @returns {number} estimate size of the module
34 */
35 getSize(module, type) {
36 const originalSource = module.originalSource();
37 if (!originalSource) {
38 return 0;
39 }
40 return originalSource.size();
41 }
42
43 /**
44 * @param {NormalModule} module module for which the code should be generated
45 * @param {GenerateContext} generateContext context for generate
46 * @returns {Source} generated code
47 */
48 generate(module, generateContext) {
49 return module.originalSource();
50 }
51}
52
53module.exports = AsyncWebAssemblyGenerator;