MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PACKAGE_IMPORTS_EXPORTS_RESOLVE

Method PACKAGE_IMPORTS_EXPORTS_RESOLVE

tools/mcpack.js:842–866  ·  view source on GitHub ↗
(matchKey, matchObj, packageURL, isImports, conditions)

Source from the content-addressed store, hash-verified

840 this.throwInvalidModuleSpecifierError();
841 }
842 PACKAGE_IMPORTS_EXPORTS_RESOLVE(matchKey, matchObj, packageURL, isImports, conditions) {
843 if ((matchKey in matchObj) && (matchKey.indexOf('*') < 0)) {
844 let target = matchObj[matchKey];
845 return this.PACKAGE_TARGET_RESOLVE(packageURL, target, null, isImports, conditions);
846 }
847 let expansionKeys = [];
848 for (let key in matchObj) {
849 let star = key.indexOf('*');
850 if ((star >= 0) && (star == key.lastIndexOf('*')))
851 expansionKeys.push(key);
852 }
853 expansionKeys.sort(this.PATTERN_KEY_COMPARE);
854 for (let expansionKey of expansionKeys) {
855 let star = expansionKey.indexOf('*');
856 let patternBase = expansionKey.slice(0, star);
857 if (matchKey.startsWith(patternBase) && (matchKey !== patternBase)) {
858 let patternTrailer = expansionKey.slice(star + 1);
859 if ((patternTrailer.length == 0) || (matchKey.endsWith(patternTrailer) && (matchKey.length >= expansionKey.length))) {
860 let target = matchObj[expansionKey];
861 let patternMatch = matchKey.slice(patternBase.length, matchKey.length - patternTrailer.length);
862 return PACKAGE_TARGET_RESOLVE(packageURL, target, patternMatch, isImports, conditions);
863 }
864 }
865 }
866 }
867 PATTERN_KEY_COMPARE(keyA, keyB) {
868 let lengthA = keyA.length;
869 let lengthB = keyB.length;

Callers 2

Calls 3

sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected