• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Defines environment settings and globals.
3 * @author Elan Shanker
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Requirements
9//------------------------------------------------------------------------------
10
11const globals = require("globals");
12
13//------------------------------------------------------------------------------
14// Helpers
15//------------------------------------------------------------------------------
16
17/**
18 * Get the object that has difference.
19 * @param {Record<string,boolean>} current The newer object.
20 * @param {Record<string,boolean>} prev The older object.
21 * @returns {Record<string,boolean>} The difference object.
22 */
23function getDiff(current, prev) {
24    const retv = {};
25
26    for (const [key, value] of Object.entries(current)) {
27        if (!Object.hasOwnProperty.call(prev, key)) {
28            retv[key] = value;
29        }
30    }
31
32    return retv;
33}
34
35const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ...
36const newGlobals2017 = {
37    Atomics: false,
38    SharedArrayBuffer: false
39};
40const newGlobals2020 = {
41    BigInt: false,
42    BigInt64Array: false,
43    BigUint64Array: false,
44    globalThis: false
45};
46
47const newGlobals2021 = {
48    FinalizationRegistry: false,
49    WeakRef: false
50};
51
52//------------------------------------------------------------------------------
53// Public Interface
54//------------------------------------------------------------------------------
55
56/** @type {Map<string, import("../lib/shared/types").Environment>} */
57module.exports = 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    es2017: {
76        globals: { ...newGlobals2015, ...newGlobals2017 },
77        parserOptions: {
78            ecmaVersion: 8
79        }
80    },
81    es2020: {
82        globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
83        parserOptions: {
84            ecmaVersion: 11
85        }
86    },
87    es2021: {
88        globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
89        parserOptions: {
90            ecmaVersion: 12
91        }
92    },
93
94    // Platforms
95    browser: {
96        globals: globals.browser
97    },
98    node: {
99        globals: globals.node,
100        parserOptions: {
101            ecmaFeatures: {
102                globalReturn: true
103            }
104        }
105    },
106    "shared-node-browser": {
107        globals: globals["shared-node-browser"]
108    },
109    worker: {
110        globals: globals.worker
111    },
112    serviceworker: {
113        globals: globals.serviceworker
114    },
115
116    // Frameworks
117    commonjs: {
118        globals: globals.commonjs,
119        parserOptions: {
120            ecmaFeatures: {
121                globalReturn: true
122            }
123        }
124    },
125    amd: {
126        globals: globals.amd
127    },
128    mocha: {
129        globals: globals.mocha
130    },
131    jasmine: {
132        globals: globals.jasmine
133    },
134    jest: {
135        globals: globals.jest
136    },
137    phantomjs: {
138        globals: globals.phantomjs
139    },
140    jquery: {
141        globals: globals.jquery
142    },
143    qunit: {
144        globals: globals.qunit
145    },
146    prototypejs: {
147        globals: globals.prototypejs
148    },
149    shelljs: {
150        globals: globals.shelljs
151    },
152    meteor: {
153        globals: globals.meteor
154    },
155    mongo: {
156        globals: globals.mongo
157    },
158    protractor: {
159        globals: globals.protractor
160    },
161    applescript: {
162        globals: globals.applescript
163    },
164    nashorn: {
165        globals: globals.nashorn
166    },
167    atomtest: {
168        globals: globals.atomtest
169    },
170    embertest: {
171        globals: globals.embertest
172    },
173    webextensions: {
174        globals: globals.webextensions
175    },
176    greasemonkey: {
177        globals: globals.greasemonkey
178    }
179}));
180