environments.js 4.5 KB

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