You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
4.0 KiB

4 years ago
  1. /**
  2. * @fileoverview Defines environment settings and globals.
  3. * @author Elan Shanker
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const globals = require("globals");
  10. //------------------------------------------------------------------------------
  11. // Helpers
  12. //------------------------------------------------------------------------------
  13. /**
  14. * Get the object that has difference.
  15. * @param {Record<string,boolean>} current The newer object.
  16. * @param {Record<string,boolean>} prev The older object.
  17. * @returns {Record<string,boolean>} The difference object.
  18. */
  19. function getDiff(current, prev) {
  20. const retv = {};
  21. for (const [key, value] of Object.entries(current)) {
  22. if (!Object.hasOwnProperty.call(prev, key)) {
  23. retv[key] = value;
  24. }
  25. }
  26. return retv;
  27. }
  28. const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ...
  29. const newGlobals2017 = {
  30. Atomics: false,
  31. SharedArrayBuffer: false
  32. };
  33. const newGlobals2020 = {
  34. BigInt: false,
  35. BigInt64Array: false,
  36. BigUint64Array: false,
  37. globalThis: false
  38. };
  39. const newGlobals2021 = {
  40. FinalizationRegistry: false,
  41. WeakRef: false
  42. };
  43. //------------------------------------------------------------------------------
  44. // Public Interface
  45. //------------------------------------------------------------------------------
  46. /** @type {Map<string, import("../lib/shared/types").Environment>} */
  47. module.exports = 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. es2017: {
  65. globals: { ...newGlobals2015, ...newGlobals2017 },
  66. parserOptions: {
  67. ecmaVersion: 8
  68. }
  69. },
  70. es2020: {
  71. globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
  72. parserOptions: {
  73. ecmaVersion: 11
  74. }
  75. },
  76. es2021: {
  77. globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
  78. parserOptions: {
  79. ecmaVersion: 12
  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. // Frameworks
  104. commonjs: {
  105. globals: globals.commonjs,
  106. parserOptions: {
  107. ecmaFeatures: {
  108. globalReturn: true
  109. }
  110. }
  111. },
  112. amd: {
  113. globals: globals.amd
  114. },
  115. mocha: {
  116. globals: globals.mocha
  117. },
  118. jasmine: {
  119. globals: globals.jasmine
  120. },
  121. jest: {
  122. globals: globals.jest
  123. },
  124. phantomjs: {
  125. globals: globals.phantomjs
  126. },
  127. jquery: {
  128. globals: globals.jquery
  129. },
  130. qunit: {
  131. globals: globals.qunit
  132. },
  133. prototypejs: {
  134. globals: globals.prototypejs
  135. },
  136. shelljs: {
  137. globals: globals.shelljs
  138. },
  139. meteor: {
  140. globals: globals.meteor
  141. },
  142. mongo: {
  143. globals: globals.mongo
  144. },
  145. protractor: {
  146. globals: globals.protractor
  147. },
  148. applescript: {
  149. globals: globals.applescript
  150. },
  151. nashorn: {
  152. globals: globals.nashorn
  153. },
  154. atomtest: {
  155. globals: globals.atomtest
  156. },
  157. embertest: {
  158. globals: globals.embertest
  159. },
  160. webextensions: {
  161. globals: globals.webextensions
  162. },
  163. greasemonkey: {
  164. globals: globals.greasemonkey
  165. }
  166. }));