-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathlegacy-module-mappings.js
101 lines (91 loc) · 2.41 KB
/
legacy-module-mappings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* eslint-disable prettier/prettier */
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import legacyMappings from 'ember-rfc176-data/mappings.json';
const LOCALNAME_CONVERSIONS = {
Object: 'EmberObject',
Array: 'EmberArray',
Error: 'EmberError',
};
export default class LegacyModuleMappingsService extends Service {
@tracked mappings;
legacyMappings = legacyMappings;
async initMappings() {
try {
let newMappings = this.buildMappings(legacyMappings);
this.mappings = newMappings;
} catch (e) {
this.mappings = [];
}
}
buildMappings(mappings) {
return mappings.map((item) => {
let newItem = Object.assign({}, item);
if (LOCALNAME_CONVERSIONS[newItem.localName]) {
newItem.localName = LOCALNAME_CONVERSIONS[newItem.localName];
}
return newItem;
});
}
getModule(name, documentedModule) {
if (!this.mappings) {
return '';
}
let matches = this.mappings.filter((element) => element.localName === name);
return matches.length > 0 ? matches[0].module : documentedModule;
}
getNewClassFromOld(oldClassName, mappings) {
let matches = mappings.filter((element) => element.global === oldClassName);
if (matches.length > 0) {
if (matches[0].localName) {
return {
itemType: 'class',
newModule: matches[0].module,
newName: matches[0].localName,
};
} else {
return {
itemType: 'function',
newModule: matches[0].module,
newName: matches[0].export,
};
}
} else {
return {
itemType: 'class',
newName: oldClassName,
};
}
}
getNewModuleFromOld(oldModuleName, mappings) {
let matches = mappings.filter(
(element) => element.module === oldModuleName
);
if (matches.length > 0) {
return {
module: matches[0].replacement.module,
};
} else {
return {
module: oldModuleName,
};
}
}
hasFunctionMapping(name, module) {
if (!this.mappings) {
return false;
}
let filtered = this.mappings.filter(
(element) => element.export === name && element.module === module
);
return filtered.length > 0;
}
hasClassMapping(name) {
if (!this.mappings) {
return false;
}
return (
this.mappings.filter((element) => element.localName === name).length > 0
);
}
}