environments.js 3.7 KB

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