Make traces where #50762 happens machine analyzable (#52602)

This commit is contained in:
Andrew Branch
2023-02-06 11:31:07 -08:00
committed by GitHub
parent 70d14f3de2
commit 7bfe6ac49a
17 changed files with 268 additions and 0 deletions

View File

@@ -5558,6 +5558,22 @@
"category": "Message",
"code": 6412
},
"Entering conditional exports.": {
"category": "Message",
"code": 6413
},
"Resolved under condition '{0}'.": {
"category": "Message",
"code": 6414
},
"Failed to resolve under condition '{0}'.": {
"category": "Message",
"code": 6415
},
"Exiting conditional exports.": {
"category": "Message",
"code": 6416
},
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",

View File

@@ -2584,19 +2584,26 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo
}
else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null
if (!Array.isArray(target)) {
traceIfEnabled(state, Diagnostics.Entering_conditional_exports);
for (const condition of getOwnKeys(target as MapLike<unknown>)) {
if (condition === "default" || state.conditions.indexOf(condition) >= 0 || isApplicableVersionedTypesKey(state.conditions, condition)) {
traceIfEnabled(state, Diagnostics.Matched_0_condition_1, isImports ? "imports" : "exports", condition);
const subTarget = (target as MapLike<unknown>)[condition];
const result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern, key);
if (result) {
traceIfEnabled(state, Diagnostics.Resolved_under_condition_0, condition);
traceIfEnabled(state, Diagnostics.Exiting_conditional_exports);
return result;
}
else {
traceIfEnabled(state, Diagnostics.Failed_to_resolve_under_condition_0, condition);
}
}
else {
traceIfEnabled(state, Diagnostics.Saw_non_matching_condition_0, condition);
}
}
traceIfEnabled(state, Diagnostics.Exiting_conditional_exports);
return undefined;
}
else {