Remove IIFEs for several JS files - Part 1
What does this MR do?
removes the IIFEs wrapping several JS files... this is a necessary step toward moving to ES module exports because export default Foo
is statically analyzed and cannot exist within an IIFE.
I've just started going through scripts alphabetically starting with abuse_reports.js
and going through header.js
. I'll open other MRs for additional segments of the frontend codebase.
Are there points in the code the reviewer needs to double check?
Keep in mind no code was changed here, only indentation level and IIFE removal. The diffs may look complicated because sometimes our diff method doesn't understand indentation changes. Occasionally, I need to change this
to window
or global
to window.gl
where appropriate, but that's about it.
Why was this MR needed?
In order to enable code splitting, we first need to get all of our script dependencies into statically analyzable chunks and IIFEs make that difficult.
Screenshots (if relevant)
Does this MR meet the acceptance criteria?
-
Changelog entry added -
Documentation created/updated -
API support added - Tests
-
Added for this feature/bug -
All builds are passing
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Branch has no merge conflicts with master
(if it does - rebase it please) -
Squashed related commits together
What are the relevant issue numbers?
related to #27486 (moved)
Merge request reports
Activity
assigned to @mikegreiling
added 1 commit
- 1af817c0 - remove IIFEs in preparation for ES module refactor
I was working on this in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9827. I'll close my MR in favor of this one. Probably you should link https://gitlab.com/gitlab-org/gitlab-ce/issues/29219 in the description.
mentioned in merge request !9827 (closed)
Ah crap, sorry @alfredo1 I didn't see the issue
... I was just working off the webpack meta issue. I'll edit the description to include the issue number.Perhaps we can take a divide-and-conquor approach to this. I've started work on scripts starting with the letter A through H here, maybe others can take on other chunks.
added 69 commits
-
1af817c0...1585608b - 68 commits from branch
master
- 1ae02e1c - remove IIFEs in preparation for ES module refactor
-
1af817c0...1585608b - 68 commits from branch
I've reverted the changes to
dispatcher.js
as there are some unreconciled changes between CE and EE at the moment and I didn't want to make things overly difficult for people in charge of the next ce-to-ee merge. I'll open another MR for this later.I've created an ee-branch for this here: gitlab-ee!1415
mentioned in issue #29219 (moved)
49 }; 50 51 Autosave.prototype.reset = function() { 52 if (window.localStorage == null) { 53 return; 54 } 55 try { 56 return window.localStorage.removeItem(this.key); 57 } catch (error) {} 58 }; 59 59 60 return Autosave; 61 })(); 62 }).call(window); 60 return Autosave; 61 })(); That's true, but in this case it is due to the class definition implementation generated by coffeescript. When we come back and refactor this one in another pass it will be a simple matter of changing:
window.Autosave = (function() { function Autosave(field, key) { /* ... */ } Autosave.prototype.restore = function() { /* ... */ }; Autosave.prototype.save = function() { /* ... */ }; Autosave.prototype.reset = function() { /* ... */ }; return Autosave; })();
to
class Autosave { constructor(field, key) { /* ... */ } restore() { /* ... */ } save() { /* ... */ } reset() { /* ... */ } }
and all the indentation will be the same. Again this is just to make the future changes easier to review...
Edited by username-removed-636429
33 return this.field.trigger("input"); 34 }; 3 window.Autosave = (function() { 4 function Autosave(field, key) { 5 this.field = field; 6 if (key.join != null) { 7 key = key.join("/"); 8 } 9 this.key = "autosave/" + key; 10 this.field.data("autosave", this); 11 this.restore(); 12 this.field.on("input", (function(_this) { 13 return function() { 14 return _this.save(); 15 }; 16 })(this)); what about IIFEs like this one? In my MR I was replacing them with
function(){ ... }.bind(this)
Edited by username-removed-408881It can probably just be simplified even further with
this.field.on('input', () => this.save());
. But that is out of the scope of this MR.To make things easy to review, I'm only tackling the IIFEs that wrap the entire script. I don't want to get into refactoring
_this
bind hacks,class
definition IIFEs, or other coffeescript-generated junk just yet.My reasoning for this is due to the way that our MR diff view has such a hard time with changes in indentation. These other two types of IIFEs don't require me to un-indent the entire file, so I want the reviewer to be able to trust that I didn't make any changes other than the indentation and not need to scan the entire file for other changes I may have made...
marked the task Conform by the merge request performance guides as completed
marked the task Conform by the style guides as completed
marked the task Squashed related commits together as completed
@mikegreiling LGTM
mentioned in commit 302d0453
changed milestone to %9.1