MCPcopy
hub / github.com/webpack/minimizer-webpack-plugin / getEcmaVersion

Function getEcmaVersion

src/utils.js:26–57  ·  view source on GitHub ↗

* Map a webpack `output.environment` configuration to the highest * ECMAScript version that the target is known to support. Returns `5` * when no ES2015+ features are flagged. * @param {NonNullable ["environment"]>} environment environment *

(environment)

Source from the content-addressed store, hash-verified

24 * @returns {number} ecma version (5, 2015, 2017 or 2020)
25 */
26function getEcmaVersion(environment) {
27 // ES2020 (11th edition)
28 if (
29 environment.bigIntLiteral ||
30 environment.dynamicImport ||
31 environment.dynamicImportInWorker ||
32 environment.globalThis ||
33 environment.optionalChaining
34 ) {
35 return 2020;
36 }
37
38 // ES2017 (8th edition)
39 if (environment.asyncFunction) {
40 return 2017;
41 }
42
43 // ES2015 (6th edition)
44 if (
45 environment.arrowFunction ||
46 environment.const ||
47 environment.destructuring ||
48 environment.forOf ||
49 environment.methodShorthand ||
50 environment.module ||
51 environment.templateLiteral
52 ) {
53 return 2015;
54 }
55
56 return 5;
57}
58
59const notSettled = Symbol("not-settled");
60

Callers 2

optimizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…