@@ -13435,32 +13435,38 @@ namespace ts {
13435
13435
mapType(types[unionIndex], t => getTemplateType(texts, casings, replaceElement(types, unionIndex, t))) :
13436
13436
errorType;
13437
13437
}
13438
- let i = 0;
13439
- while (i < types.length) {
13438
+ let newTypes = [];
13439
+ let newCasings = [];
13440
+ let newTexts = [];
13441
+ let text = texts[0];
13442
+ for (let i = 0; i < types.length; i++) {
13440
13443
const t = types[i];
13441
13444
const casingType = casings[i];
13442
13445
const isGeneric = isGenericIndexType(t);
13443
13446
const resolvable = (t.flags & TypeFlags.Literal) || (!isGeneric && casingType === TemplateCasing.TypeOf);
13444
13447
if (resolvable) {
13445
13448
const s = applyTemplateCasing(getTemplateStringForType(t, casingType) || "", casingType);
13446
- texts = [...texts.slice(0, i), texts[i] + s + texts[i + 1], ...texts.slice(i + 2)];
13447
- casings = [...casings.slice(0, i), ...casings.slice(i + 1)];
13448
- types = [...types.slice(0, i), ...types.slice(i + 1)];
13449
+ text += s;
13450
+ text += texts[i + 1];
13449
13451
}
13450
13452
else if (isGeneric) {
13451
- i++;
13453
+ newTypes.push(t);
13454
+ newCasings.push(casings[i]);
13455
+ newTexts.push(text);
13456
+ text = texts[i + 1];
13452
13457
}
13453
13458
else {
13454
13459
return stringType;
13455
13460
}
13456
13461
}
13457
- if (types .length === 0) {
13458
- return getLiteralType(texts[0] );
13462
+ if (newTypes .length === 0) {
13463
+ return getLiteralType(text );
13459
13464
}
13460
- const id = `${getTypeListId(types)}|${casings.join(",")}|${map(texts, t => t.length).join(",")}|${texts.join("")}`;
13465
+ newTexts.push(text);
13466
+ const id = `${getTypeListId(newTypes)}|${newCasings.join(",")}|${map(newTexts, t => t.length).join(",")}|${newTexts.join("")}`;
13461
13467
let type = templateTypes.get(id);
13462
13468
if (!type) {
13463
- templateTypes.set(id, type = createTemplateType(texts, casings, types ));
13469
+ templateTypes.set(id, type = createTemplateType(newTexts, newCasings, newTypes ));
13464
13470
}
13465
13471
return type;
13466
13472
}
0 commit comments