UNPKG

726 BJavaScriptView Raw
1export const mergeTwoImportMap = (leftImportMap, rightImportMap) => {
2 return {
3 imports: mergeImports(leftImportMap.imports, rightImportMap.imports),
4 scopes: mergeScopes(leftImportMap.scopes, rightImportMap.scopes),
5 }
6}
7
8const mergeImports = (leftImports = {}, rightImports = {}) => {
9 return { ...leftImports, ...rightImports }
10}
11
12const mergeScopes = (leftScopes = {}, rightScopes = {}) => {
13 const scopes = { ...leftScopes }
14 Object.keys(rightScopes).forEach((pathPattern) => {
15 if (scopes.hasOwnProperty(pathPattern)) {
16 scopes[pathPattern] = { ...scopes[pathPattern], ...rightScopes[pathPattern] }
17 } else {
18 scopes[pathPattern] = { ...rightScopes[pathPattern] }
19 }
20 })
21 return scopes
22}