Skip to content

Commit 2cf0cf0

Browse files
authored
JS refactors (#22227)
- Replace all default exports with named exports, except for Vue SFCs - Remove names from Vue SFCs, they are automatically inferred from the filename - Misc whitespace-related tweaks
1 parent 71ca306 commit 2cf0cf0

35 files changed

+47
-89
lines changed

web_src/js/components/ActivityHeatmap.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import {CalendarHeatmap} from 'vue3-calendar-heatmap';
1919
2020
export default {
21-
name: 'ActivityHeatmap',
2221
components: {CalendarHeatmap},
2322
props: {
2423
values: {

web_src/js/components/ContextPopup.vue

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,13 @@ const luminance = (colorString) => {
4646
const luminanceThreshold = 0.179;
4747
4848
export default {
49-
name: 'ContextPopup',
50-
51-
components: {
52-
SvgIcon,
53-
},
54-
49+
components: {SvgIcon},
5550
data: () => ({
5651
loading: false,
5752
issue: null,
5853
i18nErrorOccurred: i18n.error_occurred,
5954
i18nErrorMessage: null,
6055
}),
61-
6256
computed: {
6357
createdAt() {
6458
return new Date(this.issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});
@@ -107,7 +101,6 @@ export default {
107101
});
108102
}
109103
},
110-
111104
mounted() {
112105
this.$refs.root.addEventListener('us-load-context-popup', (e) => {
113106
const data = e.detail;
@@ -116,7 +109,6 @@ export default {
116109
}
117110
});
118111
},
119-
120112
methods: {
121113
load(data) {
122114
this.loading = true;

web_src/js/components/DiffFileList.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ import {doLoadMoreFiles} from '../features/repo-diff.js';
2727
const {pageData} = window.config;
2828
2929
export default {
30-
name: 'DiffFileList',
31-
3230
data: () => {
3331
return pageData.diffFileInfo;
3432
},
35-
3633
watch: {
3734
fileListIsVisible(newValue) {
3835
if (newValue === true) {
@@ -44,15 +41,12 @@ export default {
4441
}
4542
}
4643
},
47-
4844
mounted() {
4945
document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
5046
},
51-
5247
unmounted() {
5348
document.getElementById('show-file-list-btn').removeEventListener('click', this.toggleFileList);
5449
},
55-
5650
methods: {
5751
toggleFileList() {
5852
this.fileListIsVisible = !this.fileListIsVisible;

web_src/js/components/DiffFileTree.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ const {pageData} = window.config;
2121
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
2222
2323
export default {
24-
name: 'DiffFileTree',
2524
components: {DiffFileTreeItem},
26-
2725
data: () => {
2826
const fileTreeIsVisible = localStorage.getItem(LOCAL_STORAGE_KEY) === 'true';
2927
pageData.diffFileInfo.fileTreeIsVisible = fileTreeIsVisible;
3028
return pageData.diffFileInfo;
3129
},
32-
3330
computed: {
3431
fileTree() {
3532
const result = [];
@@ -94,7 +91,6 @@ export default {
9491
return result;
9592
}
9693
},
97-
9894
mounted() {
9995
// ensure correct buttons when we are mounted to the dom
10096
this.adjustToggleButton(this.fileTreeIsVisible);
@@ -125,7 +121,7 @@ export default {
125121
doLoadMoreFiles(this.link, this.diffEnd, () => {
126122
this.isLoadingNewData = false;
127123
});
128-
}
124+
},
129125
},
130126
};
131127
</script>

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343
import {SvgIcon} from '../svg.js';
4444
4545
export default {
46-
name: 'DiffFileTreeItem',
47-
components: {
48-
SvgIcon,
49-
},
50-
46+
components: {SvgIcon},
5147
props: {
5248
item: {
5349
type: Object,
@@ -59,7 +55,6 @@ export default {
5955
default: true
6056
}
6157
},
62-
6358
data: () => ({
6459
collapsed: false,
6560
}),

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ import {SvgIcon} from '../svg.js';
111111
const {csrfToken, pageData} = window.config;
112112
113113
export default {
114-
name: 'PullRequestMergeForm',
115-
components: {
116-
SvgIcon,
117-
},
118-
114+
components: {SvgIcon},
119115
data: () => ({
120116
csrfToken,
121117
mergeForm: pageData.pullRequestMergeForm,
@@ -137,36 +133,30 @@ export default {
137133
showMergeStyleMenu: false,
138134
showActionForm: false,
139135
}),
140-
141136
computed: {
142137
mergeButtonStyleClass() {
143138
if (this.mergeForm.allOverridableChecksOk) return 'green';
144139
return this.autoMergeWhenSucceed ? 'blue' : 'red';
145140
}
146141
},
147-
148142
watch: {
149143
mergeStyle(val) {
150144
this.mergeStyleDetail = this.mergeForm.mergeStyles.find((e) => e.name === val);
151145
}
152146
},
153-
154147
created() {
155148
this.mergeStyleAllowedCount = this.mergeForm.mergeStyles.reduce((v, msd) => v + (msd.allowed ? 1 : 0), 0);
156149
157150
let mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed && e.name === this.mergeForm.defaultMergeStyle)?.name;
158151
if (!mergeStyle) mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed)?.name;
159152
this.switchMergeStyle(mergeStyle, !this.mergeForm.canMergeNow);
160153
},
161-
162154
mounted() {
163155
document.addEventListener('mouseup', this.hideMergeStyleMenu);
164156
},
165-
166157
unmounted() {
167158
document.removeEventListener('mouseup', this.hideMergeStyleMenu);
168159
},
169-
170160
methods: {
171161
hideMergeStyleMenu() {
172162
this.showMergeStyleMenu = false;

web_src/js/features/clipboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function fallbackCopyToClipboard(text) {
4444

4545
// For all DOM elements with [data-clipboard-target] or [data-clipboard-text],
4646
// this copy-to-clipboard will work for them
47-
export default function initGlobalCopyToClipboardListener() {
47+
export function initGlobalCopyToClipboardListener() {
4848
document.addEventListener('click', (e) => {
4949
let target = e.target;
5050
// in case <button data-clipboard-text><svg></button>, so we just search

web_src/js/features/colorpicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default async function createColorPicker($els) {
1+
export async function createColorPicker($els) {
22
if (!$els || !$els.length) return;
33

44
await Promise.all([

web_src/js/features/common-global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import $ from 'jquery';
22
import 'jquery.are-you-sure';
33
import {mqBinarySearch} from '../utils.js';
4-
import createDropzone from './dropzone.js';
4+
import {createDropzone} from './dropzone.js';
55
import {initCompColorPicker} from './comp/ColorPicker.js';
66
import {showGlobalErrorMessage} from '../bootstrap.js';
77
import {attachDropdownAria} from './aria.js';

web_src/js/features/comp/ColorPicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import createColorPicker from '../colorpicker.js';
2+
import {createColorPicker} from '../colorpicker.js';
33

44
export function initCompColorPicker() {
55
createColorPicker($('.color-picker'));

web_src/js/features/comp/EasyMDE.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import attachTribute from '../tribute.js';
2+
import {attachTribute} from '../tribute.js';
33
import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js';
44

55
/**

web_src/js/features/comp/SearchUserBox.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import $ from 'jquery';
22
import {htmlEscape} from 'escape-goat';
33

44
const {appSubUrl} = window.config;
5-
65
const looksLikeEmailAddressCheck = /^\S+@\S+$/;
76

87
export function initCompSearchUserBox() {

web_src/js/features/comp/WebHookEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import $ from 'jquery';
2+
23
const {csrfToken} = window.config;
34

45
export function initCompWebHookEditor() {

web_src/js/features/contextpopup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ContextPopup from '../components/ContextPopup.vue';
44
import {parseIssueHref} from '../utils.js';
55
import {createTippy} from '../modules/tippy.js';
66

7-
export default function initContextPopups() {
7+
export function initContextPopups() {
88
const refIssues = $('.ref-issue');
99
if (!refIssues.length) return;
1010

web_src/js/features/copycontent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {copyToClipboard} from './clipboard.js';
22
import {showTemporaryTooltip} from '../modules/tippy.js';
33
import {convertImage} from '../utils.js';
4+
45
const {i18n} = window.config;
56

67
async function doCopy(content, btn) {

web_src/js/features/dropzone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default async function createDropzone(el, opts) {
1+
export async function createDropzone(el, opts) {
22
const [{Dropzone}] = await Promise.all([
33
import(/* webpackChunkName: "dropzone" */'dropzone'),
44
import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'),

web_src/js/features/emoji.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import emojis from '../../../assets/emoji.json';
22

3-
const {assetUrlPrefix} = window.config;
4-
const {customEmojis} = window.config;
3+
const {assetUrlPrefix, customEmojis} = window.config;
54

65
const tempMap = {...customEmojis};
76
for (const {emoji, aliases} of emojis) {

web_src/js/features/file-fold.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {svg} from '../svg.js';
22

3-
43
// Hides the file if newFold is true, and shows it otherwise. The actual hiding is performed using CSS.
54
//
65
// The fold arrow is the icon displayed on the upper left of the file box, especially intended for components having the 'fold-file' class.

web_src/js/features/formatting.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {prettyNumber} from '../utils.js';
22

33
const {lang} = document.documentElement;
4-
54
const dateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'long', day: 'numeric'});
65
const shortDateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric'});
76
const dateTimeFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric'});

web_src/js/features/heatmap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {createApp} from 'vue';
22
import ActivityHeatmap from '../components/ActivityHeatmap.vue';
33
import {translateMonth, translateDay} from '../utils.js';
4-
export default function initHeatmap() {
4+
5+
export function initHeatmap() {
56
const el = document.getElementById('user-heatmap');
67
if (!el) return;
78

web_src/js/features/imagediff.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
3434
return null;
3535
}
3636

37-
export default function initImageDiff() {
37+
export function initImageDiff() {
3838
function createContext(image1, image2) {
3939
const size1 = {
4040
width: image1 && image1.width || 0,

web_src/js/features/repo-diff-filetree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {createApp} from 'vue';
22
import DiffFileTree from '../components/DiffFileTree.vue';
33
import DiffFileList from '../components/DiffFileList.vue';
44

5-
export default function initDiffFileTree() {
5+
export function initDiffFileTree() {
66
const el = document.getElementById('diff-file-tree');
77
if (!el) return;
88

web_src/js/features/repo-findfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
2-
32
import {svg} from '../svg.js';
3+
44
const {csrf} = window.config;
55

66
const threshold = 50;

web_src/js/features/repo-graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22

3-
export default function initRepoGraphGit() {
3+
export function initRepoGraphGit() {
44
const graphContainer = document.getElementById('git-graph-container');
55
if (!graphContainer) return;
66

web_src/js/features/repo-issue-pr-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {createApp} from 'vue';
22
import PullRequestMergeForm from '../components/PullRequestMergeForm.vue';
33

4-
export default function initPullRequestMergeForm() {
4+
export function initRepoPullRequestMergeForm() {
55
const el = document.getElementById('pull-request-merge-form');
66
if (!el) return;
77

web_src/js/features/repo-issue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import {htmlEscape} from 'escape-goat';
3-
import attachTribute from './tribute.js';
3+
import {attachTribute} from './tribute.js';
44
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
55
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
66
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';

web_src/js/features/repo-legacy.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,28 @@ import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
33
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
44
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
55
import {
6-
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel,
7-
initRepoIssueCommentDelete,
8-
initRepoIssueComments, initRepoIssueDependencyDelete,
9-
initRepoIssueReferenceIssue, initRepoIssueStatusButton,
10-
initRepoIssueTitleEdit,
11-
initRepoIssueWipToggle, initRepoPullRequestUpdate,
12-
updateIssuesMeta,
6+
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete,
7+
initRepoIssueComments, initRepoIssueDependencyDelete, initRepoIssueReferenceIssue,
8+
initRepoIssueStatusButton, initRepoIssueTitleEdit, initRepoIssueWipToggle,
9+
initRepoPullRequestUpdate, updateIssuesMeta,
1310
} from './repo-issue.js';
1411
import {initUnicodeEscapeButton} from './repo-unicode-escape.js';
1512
import {svg} from '../svg.js';
1613
import {htmlEscape} from 'escape-goat';
1714
import {initRepoBranchTagDropdown} from '../components/RepoBranchTagDropdown.js';
1815
import {
19-
initRepoCloneLink,
20-
initRepoCommonBranchOrTagDropdown,
21-
initRepoCommonFilterSearchDropdown,
16+
initRepoCloneLink, initRepoCommonBranchOrTagDropdown, initRepoCommonFilterSearchDropdown,
2217
initRepoCommonLanguageStats,
2318
} from './repo-common.js';
2419
import {initCitationFileCopyContent} from './citation.js';
2520
import {initCompLabelEdit} from './comp/LabelEdit.js';
2621
import {initRepoDiffConversationNav} from './repo-diff.js';
27-
import attachTribute from './tribute.js';
28-
import createDropzone from './dropzone.js';
22+
import {attachTribute} from './tribute.js';
23+
import {createDropzone} from './dropzone.js';
2924
import {initCommentContent, initMarkupContent} from '../markup/content.js';
3025
import {initCompReactionSelector} from './comp/ReactionSelector.js';
3126
import {initRepoSettingBranches} from './repo-settings.js';
32-
import initRepoPullRequestMergeForm from './repo-issue-pr-form.js';
27+
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js';
3328

3429
const {csrfToken} = window.config;
3530

web_src/js/features/repo-migration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const $lfsSettings = $('#lfs_settings');
1010
const $lfsEndpoint = $('#lfs_endpoint');
1111
const $items = $('#migrate_items').find('input[type=checkbox]');
1212

13-
export default function initRepoMigration() {
13+
export function initRepoMigration() {
1414
checkAuth();
1515
setLFSSettingsVisibility();
1616

web_src/js/features/repo-projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function initRepoProjectSortable() {
8484
}
8585
}
8686

87-
export default function initRepoProject() {
87+
export function initRepoProject() {
8888
if (!$('.repository.projects').length) {
8989
return;
9090
}

0 commit comments

Comments
 (0)