UNPKG

3.78 kBJavaScriptView Raw
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 differentce.
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};
45
46//------------------------------------------------------------------------------
47// Public Interface
48//------------------------------------------------------------------------------
49
50/** @type {Map<string, import("../lib/shared/types").Environment>} */
51module.exports = new Map(Object.entries({
52
53 // Language
54 builtin: {
55 globals: globals.es5
56 },
57 es6: {
58 globals: newGlobals2015,
59 parserOptions: {
60 ecmaVersion: 6
61 }
62 },
63 es2015: {
64 globals: newGlobals2015,
65 parserOptions: {
66 ecmaVersion: 6
67 }
68 },
69 es2017: {
70 globals: { ...newGlobals2015, ...newGlobals2017 },
71 parserOptions: {
72 ecmaVersion: 8
73 }
74 },
75 es2020: {
76 globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
77 parserOptions: {
78 ecmaVersion: 11
79 }
80 },
81
82 // Platforms
83 browser: {
84 globals: globals.browser
85 },
86 node: {
87 globals: globals.node,
88 parserOptions: {
89 ecmaFeatures: {
90 globalReturn: true
91 }
92 }
93 },
94 "shared-node-browser": {
95 globals: globals["shared-node-browser"]
96 },
97 worker: {
98 globals: globals.worker
99 },
100 serviceworker: {
101 globals: globals.serviceworker
102 },
103
104 // Frameworks
105 commonjs: {
106 globals: globals.commonjs,
107 parserOptions: {
108 ecmaFeatures: {
109 globalReturn: true
110 }
111 }
112 },
113 amd: {
114 globals: globals.amd
115 },
116 mocha: {
117 globals: globals.mocha
118 },
119 jasmine: {
120 globals: globals.jasmine
121 },
122 jest: {
123 globals: globals.jest
124 },
125 phantomjs: {
126 globals: globals.phantomjs
127 },
128 jquery: {
129 globals: globals.jquery
130 },
131 qunit: {
132 globals: globals.qunit
133 },
134 prototypejs: {
135 globals: globals.prototypejs
136 },
137 shelljs: {
138 globals: globals.shelljs
139 },
140 meteor: {
141 globals: globals.meteor
142 },
143 mongo: {
144 globals: globals.mongo
145 },
146 protractor: {
147 globals: globals.protractor
148 },
149 applescript: {
150 globals: globals.applescript
151 },
152 nashorn: {
153 globals: globals.nashorn
154 },
155 atomtest: {
156 globals: globals.atomtest
157 },
158 embertest: {
159 globals: globals.embertest
160 },
161 webextensions: {
162 globals: globals.webextensions
163 },
164 greasemonkey: {
165 globals: globals.greasemonkey
166 }
167}));