| 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 makeSerializable = require("../util/makeSerializable");
|
|---|
| 9 | const WebpackError = require("./WebpackError");
|
|---|
| 10 |
|
|---|
| 11 | /** @typedef {import("../Module")} Module */
|
|---|
| 12 | /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|---|
| 13 | /** @typedef {"asyncWebAssembly" | "topLevelAwait" | "external promise" | "external script" | "external import" | "external module"} Feature */
|
|---|
| 14 |
|
|---|
| 15 | class EnvironmentNotSupportAsyncWarning extends WebpackError {
|
|---|
| 16 | /**
|
|---|
| 17 | * Creates an instance of EnvironmentNotSupportAsyncWarning.
|
|---|
| 18 | * @param {Module} module module
|
|---|
| 19 | * @param {Feature} feature feature
|
|---|
| 20 | */
|
|---|
| 21 | constructor(module, feature) {
|
|---|
| 22 | const message = `The generated code contains 'async/await' because this module is using "${feature}".
|
|---|
| 23 | However, your target environment does not appear to support 'async/await'.
|
|---|
| 24 | As a result, the code may not run as expected or may cause runtime errors.`;
|
|---|
| 25 | super(message);
|
|---|
| 26 |
|
|---|
| 27 | /** @type {string} */
|
|---|
| 28 | this.name = "EnvironmentNotSupportAsyncWarning";
|
|---|
| 29 | /** @type {Module} */
|
|---|
| 30 | this.module = module;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * Creates an instance of EnvironmentNotSupportAsyncWarning.
|
|---|
| 35 | * @param {Module} module module
|
|---|
| 36 | * @param {RuntimeTemplate} runtimeTemplate compilation
|
|---|
| 37 | * @param {Feature} feature feature
|
|---|
| 38 | */
|
|---|
| 39 | static check(module, runtimeTemplate, feature) {
|
|---|
| 40 | if (!runtimeTemplate.supportsAsyncFunction()) {
|
|---|
| 41 | module.addWarning(new EnvironmentNotSupportAsyncWarning(module, feature));
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | makeSerializable(
|
|---|
| 47 | EnvironmentNotSupportAsyncWarning,
|
|---|
| 48 | "webpack/lib/errors/EnvironmentNotSupportAsyncWarning"
|
|---|
| 49 | );
|
|---|
| 50 |
|
|---|
| 51 | module.exports = EnvironmentNotSupportAsyncWarning;
|
|---|