1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Gengkun He @ahabhgk
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const WebpackError = require("./WebpackError");
|
---|
9 | const makeSerializable = require("./util/makeSerializable");
|
---|
10 |
|
---|
11 | /** @typedef {import("./Module")} Module */
|
---|
12 | /** @typedef {import("./Compilation")} Compilation */
|
---|
13 | /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
---|
14 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
15 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
16 | /** @typedef {"asyncWebAssembly" | "topLevelAwait" | "external promise" | "external script" | "external import" | "external module"} Feature */
|
---|
17 |
|
---|
18 | class EnvironmentNotSupportAsyncWarning extends WebpackError {
|
---|
19 | /**
|
---|
20 | * Creates an instance of EnvironmentNotSupportAsyncWarning.
|
---|
21 | * @param {Module} module module
|
---|
22 | * @param {Feature} feature feature
|
---|
23 | */
|
---|
24 | constructor(module, feature) {
|
---|
25 | const message = `The generated code contains 'async/await' because this module is using "${feature}".
|
---|
26 | However, your target environment does not appear to support 'async/await'.
|
---|
27 | As a result, the code may not run as expected or may cause runtime errors.`;
|
---|
28 | super(message);
|
---|
29 |
|
---|
30 | this.name = "EnvironmentNotSupportAsyncWarning";
|
---|
31 | this.module = module;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Creates an instance of EnvironmentNotSupportAsyncWarning.
|
---|
36 | * @param {Module} module module
|
---|
37 | * @param {RuntimeTemplate} runtimeTemplate compilation
|
---|
38 | * @param {Feature} feature feature
|
---|
39 | */
|
---|
40 | static check(module, runtimeTemplate, feature) {
|
---|
41 | if (!runtimeTemplate.supportsAsyncFunction()) {
|
---|
42 | module.addWarning(new EnvironmentNotSupportAsyncWarning(module, feature));
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | makeSerializable(
|
---|
48 | EnvironmentNotSupportAsyncWarning,
|
---|
49 | "webpack/lib/EnvironmentNotSupportAsyncWarning"
|
---|
50 | );
|
---|
51 |
|
---|
52 | module.exports = EnvironmentNotSupportAsyncWarning;
|
---|