Skip to content
Permalink
Browse files

Core: Migrate from AMD to ES modules πŸŽ‰

Migrate all source AMD modules to ECMAScript modules. The final bundle
is compiled by a custom build process that uses Rollup under the hood.

Test files themselves are still loaded via RequireJS as that has to work in
IE 11.

Tests can now be run in "Load as modules" mode which replaces the previous
"Load with AMD" option. That option of running tests doesn't work in IE
and Edge as it requires support for dynamic imports.

Some of the changes required by the migration:
* check `typeof` of `noGlobal` instead of using the variable directly
  as it's not available when modules are used
* change the nonce module to be an object as ECMASscript module exports
  are immutable
* remove some unused exports
* import `./core/parseHTML.js` directly in `jquery.js` so that it's not
  being cut out when the `ajax` module is excluded in a custom compilation

Closes gh-4541
  • Loading branch information
mgol committed Nov 18, 2019
1 parent a612733 commit d0ce00cdfa680f1f0c38460bc51ea14079ae8b07
Showing with 801 additions and 1,324 deletions.
  1. +1 βˆ’3 .eslintrc-browser.json
  2. +1 βˆ’1 .eslintrc-node.json
  3. +10 βˆ’1 .eslintrc.json
  4. +3 βˆ’3 CONTRIBUTING.md
  5. +1 βˆ’1 Gruntfile.js
  6. +174 βˆ’207 build/tasks/build.js
  7. +11 βˆ’0 dist/.eslintrc.json
  8. +3 βˆ’1 package.json
  9. +32 βˆ’1 src/.eslintrc.json
  10. +15 βˆ’19 src/ajax.js
  11. +5 βˆ’10 src/ajax/jsonp.js
  12. +7 βˆ’12 src/ajax/load.js
  13. +2 βˆ’8 src/ajax/parseXML.js
  14. +3 βˆ’8 src/ajax/script.js
  15. +1 βˆ’5 src/ajax/var/location.js
  16. +1 βˆ’5 src/ajax/var/nonce.js
  17. +1 βˆ’5 src/ajax/var/rquery.js
  18. +2 βˆ’7 src/ajax/xhr.js
  19. +6 βˆ’10 src/attributes.js
  20. +6 βˆ’11 src/attributes/attr.js
  21. +5 βˆ’10 src/attributes/classes.js
  22. +4 βˆ’9 src/attributes/prop.js
  23. +6 βˆ’16 src/attributes/val.js
  24. +4 βˆ’9 src/callbacks.js
  25. +19 βˆ’28 src/core.js
  26. +30 βˆ’34 src/core/DOMEval.js
  27. +3 βˆ’9 src/core/access.js
  28. +1 βˆ’7 src/core/camelCase.js
  29. +5 βˆ’11 src/core/init.js
  30. +17 βˆ’20 src/core/isAttached.js
  31. +1 βˆ’7 src/core/nodeName.js
  32. +4 βˆ’12 src/core/parseHTML.js
  33. +2 βˆ’8 src/core/ready-no-deferred.js
  34. +4 βˆ’9 src/core/ready.js
  35. +1 βˆ’7 src/core/readyException.js
  36. +8 βˆ’12 src/core/stripAndCollapse.js
  37. +3 βˆ’8 src/core/toType.js
  38. +1 βˆ’7 src/core/var/rhtml.js
  39. +3 βˆ’7 src/core/var/rsingleTag.js
  40. +20 βˆ’26 src/css.js
  41. +4 βˆ’9 src/css/adjustCSS.js
  42. +2 βˆ’8 src/css/cssCamelCase.js
  43. +4 βˆ’9 src/css/curCSS.js
  44. +2 βˆ’8 src/css/finalPropName.js
  45. +2 βˆ’7 src/css/hiddenVisibleSelectors.js
  46. +1 βˆ’7 src/css/isAutoPx.js
  47. +4 βˆ’9 src/css/showHide.js
  48. +4 βˆ’10 src/css/support.js
  49. +1 βˆ’5 src/css/var/cssExpand.js
  50. +12 βˆ’16 src/css/var/getStyles.js
  51. +17 βˆ’23 src/css/var/isHiddenWithinTree.js
  52. +2 βˆ’6 src/css/var/rnumnonpx.js
  53. +1 βˆ’7 src/css/var/swap.js
  54. +6 βˆ’11 src/data.js
  55. +5 βˆ’10 src/data/Data.js
  56. +1 βˆ’7 src/data/var/acceptData.js
  57. +2 βˆ’6 src/data/var/dataPriv.js
  58. +2 βˆ’6 src/data/var/dataUser.js
  59. +4 βˆ’8 src/deferred.js
  60. +2 βˆ’7 src/deferred/exceptionHook.js
  61. +4 βˆ’8 src/deprecated.js
  62. +5 βˆ’9 src/dimensions.js
  63. +20 βˆ’29 src/effects.js
  64. +4 βˆ’10 src/effects/Tween.js
  65. +3 βˆ’8 src/effects/animatedSelector.js
  66. +12 βˆ’18 src/event.js
  67. +2 βˆ’7 src/event/ajax.js
  68. +3 βˆ’9 src/event/alias.js
  69. +9 βˆ’13 src/event/trigger.js
  70. +1 βˆ’7 src/exports/amd.js
  71. +2 βˆ’8 src/exports/global.js
  72. +33 βˆ’37 src/jquery.js
  73. +23 βˆ’31 src/manipulation.js
  74. +2 βˆ’8 src/manipulation/_evalUrl.js
  75. +9 βˆ’14 src/manipulation/buildFragment.js
  76. +3 βˆ’8 src/manipulation/getAll.js
  77. +2 βˆ’7 src/manipulation/setGlobalEval.js
  78. +1 βˆ’5 src/manipulation/var/rscriptType.js
  79. +4 βˆ’8 src/manipulation/var/rtagName.js
  80. +1 βˆ’6 src/manipulation/wrapMap.js
  81. +9 βˆ’13 src/offset.js
  82. +5 βˆ’9 src/queue.js
  83. +3 βˆ’9 src/queue/delay.js
  84. +14 βˆ’21 src/selector.js
  85. +1 βˆ’7 src/selector/contains.js
  86. +1 βˆ’7 src/selector/escapeSelector.js
  87. +3 βˆ’9 src/selector/rbuggyQSA.js
  88. +3 βˆ’9 src/selector/support.js
  89. +3 βˆ’9 src/selector/uniqueSort.js
  90. +7 βˆ’11 src/serialize.js
  91. +12 βˆ’17 src/traversing.js
  92. +4 βˆ’9 src/traversing/findFilter.js
  93. +2 βˆ’8 src/traversing/var/dir.js
  94. +4 βˆ’7 src/traversing/var/rneedsContext.js
  95. +1 βˆ’7 src/traversing/var/siblings.js
  96. +2 βˆ’6 src/var/ObjectFunctionString.js
  97. +1 βˆ’5 src/var/arr.js
  98. +2 βˆ’6 src/var/class2type.js
  99. +1 βˆ’5 src/var/document.js
  100. +2 βˆ’6 src/var/documentElement.js
  101. +2 βˆ’8 src/var/flat.js
  102. +2 βˆ’6 src/var/fnToString.js
  103. +1 βˆ’5 src/var/getProto.js
  104. +2 βˆ’6 src/var/hasOwn.js
  105. +2 βˆ’6 src/var/indexOf.js
  106. +2 βˆ’6 src/var/isIE.js
  107. +3 βˆ’8 src/var/isWindow.js
  108. +1 βˆ’5 src/var/pnum.js
  109. +2 βˆ’6 src/var/pop.js
  110. +2 βˆ’6 src/var/push.js
  111. +1 βˆ’5 src/var/rcheckableType.js
  112. +2 βˆ’8 src/var/rcssNum.js
  113. +4 βˆ’8 src/var/rnothtmlwhite.js
  114. +2 βˆ’6 src/var/slice.js
  115. +2 βˆ’6 src/var/sort.js
  116. +2 βˆ’6 src/var/support.js
  117. +2 βˆ’6 src/var/toString.js
  118. +1 βˆ’5 src/var/trim.js
  119. +5 βˆ’9 src/wrap.js
  120. +0 βˆ’1 src/wrapper.js
  121. +10 βˆ’0 test/.eslintrc.json
  122. +1 βˆ’1 test/data/testinit.js
  123. +2 βˆ’2 test/index.html
  124. +21 βˆ’16 test/jquery.js
@@ -15,9 +15,7 @@
"env": {},

"globals": {
"window": true,
"define": true,
"module": true
"window": true
},

"rules": {
@@ -4,7 +4,7 @@
"extends": "jquery",

"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},

"env": {
@@ -1,5 +1,14 @@
{
"root": true,

"extends": "./.eslintrc-node.json"
"extends": "./.eslintrc-node.json",

"overrides": [
{
"files": "rollup.config.js",
"parserOptions": {
"sourceType": "module"
}
}
]
}
@@ -129,14 +129,14 @@ Rather than rebuilding jQuery with `grunt` every time you make a change, you can
$ grunt watch
```

Alternatively, you can **load tests in AMD** to avoid the need for rebuilding altogether.
Alternatively, you can **load tests as ECMAScript modules** to avoid the need for rebuilding altogether.

Click "Load with AMD" after loading the test page.
Click "Load as modules" after loading the test page.


### Repo organization

The jQuery source is organized with AMD modules and then concatenated and compiled at build time.
The jQuery source is organized with ECMAScript modules and then compiled into one file at build time.

jQuery also contains some special modules we call "var modules", which are placed in folders named "var". At build time, these small modules are compiled to simple var statements. This makes it easy for us to share variables across modules. Browse the "src" folder for examples.

@@ -177,7 +177,7 @@ module.exports = function( grunt ) {
"test/unit/ready.js",

{ pattern: "dist/jquery.*", included: false, served: true },
{ pattern: "src/**", included: false, served: true },
{ pattern: "src/**", type: "module", included: false, served: true },
{ pattern: "node_modules/**", included: false, served: true },
{
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",

0 comments on commit d0ce00c

Please sign in to comment.
You can’t perform that action at this time.