1 | /**
|
---|
2 | * @fileoverview Defines environment settings and globals.
|
---|
3 | * @author Elan Shanker
|
---|
4 | */
|
---|
5 |
|
---|
6 | //------------------------------------------------------------------------------
|
---|
7 | // Requirements
|
---|
8 | //------------------------------------------------------------------------------
|
---|
9 |
|
---|
10 | import globals from "globals";
|
---|
11 |
|
---|
12 | //------------------------------------------------------------------------------
|
---|
13 | // Helpers
|
---|
14 | //------------------------------------------------------------------------------
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Get the object that has difference.
|
---|
18 | * @param {Record<string,boolean>} current The newer object.
|
---|
19 | * @param {Record<string,boolean>} prev The older object.
|
---|
20 | * @returns {Record<string,boolean>} The difference object.
|
---|
21 | */
|
---|
22 | function getDiff(current, prev) {
|
---|
23 | const retv = {};
|
---|
24 |
|
---|
25 | for (const [key, value] of Object.entries(current)) {
|
---|
26 | if (!Object.hasOwnProperty.call(prev, key)) {
|
---|
27 | retv[key] = value;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | return retv;
|
---|
32 | }
|
---|
33 |
|
---|
34 | const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ...
|
---|
35 | const newGlobals2017 = {
|
---|
36 | Atomics: false,
|
---|
37 | SharedArrayBuffer: false
|
---|
38 | };
|
---|
39 | const newGlobals2020 = {
|
---|
40 | BigInt: false,
|
---|
41 | BigInt64Array: false,
|
---|
42 | BigUint64Array: false,
|
---|
43 | globalThis: false
|
---|
44 | };
|
---|
45 |
|
---|
46 | const newGlobals2021 = {
|
---|
47 | AggregateError: false,
|
---|
48 | FinalizationRegistry: false,
|
---|
49 | WeakRef: false
|
---|
50 | };
|
---|
51 |
|
---|
52 | //------------------------------------------------------------------------------
|
---|
53 | // Public Interface
|
---|
54 | //------------------------------------------------------------------------------
|
---|
55 |
|
---|
56 | /** @type {Map<string, import("../lib/shared/types").Environment>} */
|
---|
57 | export default new Map(Object.entries({
|
---|
58 |
|
---|
59 | // Language
|
---|
60 | builtin: {
|
---|
61 | globals: globals.es5
|
---|
62 | },
|
---|
63 | es6: {
|
---|
64 | globals: newGlobals2015,
|
---|
65 | parserOptions: {
|
---|
66 | ecmaVersion: 6
|
---|
67 | }
|
---|
68 | },
|
---|
69 | es2015: {
|
---|
70 | globals: newGlobals2015,
|
---|
71 | parserOptions: {
|
---|
72 | ecmaVersion: 6
|
---|
73 | }
|
---|
74 | },
|
---|
75 | es2016: {
|
---|
76 | globals: newGlobals2015,
|
---|
77 | parserOptions: {
|
---|
78 | ecmaVersion: 7
|
---|
79 | }
|
---|
80 | },
|
---|
81 | es2017: {
|
---|
82 | globals: { ...newGlobals2015, ...newGlobals2017 },
|
---|
83 | parserOptions: {
|
---|
84 | ecmaVersion: 8
|
---|
85 | }
|
---|
86 | },
|
---|
87 | es2018: {
|
---|
88 | globals: { ...newGlobals2015, ...newGlobals2017 },
|
---|
89 | parserOptions: {
|
---|
90 | ecmaVersion: 9
|
---|
91 | }
|
---|
92 | },
|
---|
93 | es2019: {
|
---|
94 | globals: { ...newGlobals2015, ...newGlobals2017 },
|
---|
95 | parserOptions: {
|
---|
96 | ecmaVersion: 10
|
---|
97 | }
|
---|
98 | },
|
---|
99 | es2020: {
|
---|
100 | globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
|
---|
101 | parserOptions: {
|
---|
102 | ecmaVersion: 11
|
---|
103 | }
|
---|
104 | },
|
---|
105 | es2021: {
|
---|
106 | globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
|
---|
107 | parserOptions: {
|
---|
108 | ecmaVersion: 12
|
---|
109 | }
|
---|
110 | },
|
---|
111 | es2022: {
|
---|
112 | globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
|
---|
113 | parserOptions: {
|
---|
114 | ecmaVersion: 13
|
---|
115 | }
|
---|
116 | },
|
---|
117 | es2023: {
|
---|
118 | globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
|
---|
119 | parserOptions: {
|
---|
120 | ecmaVersion: 14
|
---|
121 | }
|
---|
122 | },
|
---|
123 | es2024: {
|
---|
124 | globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
|
---|
125 | parserOptions: {
|
---|
126 | ecmaVersion: 15
|
---|
127 | }
|
---|
128 | },
|
---|
129 |
|
---|
130 | // Platforms
|
---|
131 | browser: {
|
---|
132 | globals: globals.browser
|
---|
133 | },
|
---|
134 | node: {
|
---|
135 | globals: globals.node,
|
---|
136 | parserOptions: {
|
---|
137 | ecmaFeatures: {
|
---|
138 | globalReturn: true
|
---|
139 | }
|
---|
140 | }
|
---|
141 | },
|
---|
142 | "shared-node-browser": {
|
---|
143 | globals: globals["shared-node-browser"]
|
---|
144 | },
|
---|
145 | worker: {
|
---|
146 | globals: globals.worker
|
---|
147 | },
|
---|
148 | serviceworker: {
|
---|
149 | globals: globals.serviceworker
|
---|
150 | },
|
---|
151 |
|
---|
152 | // Frameworks
|
---|
153 | commonjs: {
|
---|
154 | globals: globals.commonjs,
|
---|
155 | parserOptions: {
|
---|
156 | ecmaFeatures: {
|
---|
157 | globalReturn: true
|
---|
158 | }
|
---|
159 | }
|
---|
160 | },
|
---|
161 | amd: {
|
---|
162 | globals: globals.amd
|
---|
163 | },
|
---|
164 | mocha: {
|
---|
165 | globals: globals.mocha
|
---|
166 | },
|
---|
167 | jasmine: {
|
---|
168 | globals: globals.jasmine
|
---|
169 | },
|
---|
170 | jest: {
|
---|
171 | globals: globals.jest
|
---|
172 | },
|
---|
173 | phantomjs: {
|
---|
174 | globals: globals.phantomjs
|
---|
175 | },
|
---|
176 | jquery: {
|
---|
177 | globals: globals.jquery
|
---|
178 | },
|
---|
179 | qunit: {
|
---|
180 | globals: globals.qunit
|
---|
181 | },
|
---|
182 | prototypejs: {
|
---|
183 | globals: globals.prototypejs
|
---|
184 | },
|
---|
185 | shelljs: {
|
---|
186 | globals: globals.shelljs
|
---|
187 | },
|
---|
188 | meteor: {
|
---|
189 | globals: globals.meteor
|
---|
190 | },
|
---|
191 | mongo: {
|
---|
192 | globals: globals.mongo
|
---|
193 | },
|
---|
194 | protractor: {
|
---|
195 | globals: globals.protractor
|
---|
196 | },
|
---|
197 | applescript: {
|
---|
198 | globals: globals.applescript
|
---|
199 | },
|
---|
200 | nashorn: {
|
---|
201 | globals: globals.nashorn
|
---|
202 | },
|
---|
203 | atomtest: {
|
---|
204 | globals: globals.atomtest
|
---|
205 | },
|
---|
206 | embertest: {
|
---|
207 | globals: globals.embertest
|
---|
208 | },
|
---|
209 | webextensions: {
|
---|
210 | globals: globals.webextensions
|
---|
211 | },
|
---|
212 | greasemonkey: {
|
---|
213 | globals: globals.greasemonkey
|
---|
214 | }
|
---|
215 | }));
|
---|