Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into noinfer
  • Loading branch information
andrewbranch committed Dec 7, 2023
commit 989fa509451bfd23ab646b98214bc94ae2eb09f8
26 changes: 17 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ const stringMappingTypeKinds: ReadonlyMap<string, StringMappingTypeKind> = new M
Uppercase: StringMappingTypeKind.Uppercase,
Lowercase: StringMappingTypeKind.Lowercase,
Capitalize: StringMappingTypeKind.Capitalize,
Uncapitalize: StringMappingTypeKind.Uncapitalize
Uncapitalize: StringMappingTypeKind.Uncapitalize,
}));

const SymbolLinks = class implements SymbolLinks {
Expand Down Expand Up @@ -17909,20 +17909,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function applyStringMapping(symbol: Symbol, str: string) {
switch (stringMappingTypeKinds.get(symbol.escapedName as string)) {
case StringMappingTypeKind.Uppercase: return str.toUpperCase();
case StringMappingTypeKind.Lowercase: return str.toLowerCase();
case StringMappingTypeKind.Capitalize: return str.charAt(0).toUpperCase() + str.slice(1);
case StringMappingTypeKind.Uncapitalize: return str.charAt(0).toLowerCase() + str.slice(1);
case StringMappingTypeKind.Uppercase:
return str.toUpperCase();
case StringMappingTypeKind.Lowercase:
return str.toLowerCase();
case StringMappingTypeKind.Capitalize:
return str.charAt(0).toUpperCase() + str.slice(1);
case StringMappingTypeKind.Uncapitalize:
return str.charAt(0).toLowerCase() + str.slice(1);
}
return str;
}

function applyTemplateStringMapping(symbol: Symbol, texts: readonly string[], types: readonly Type[]): [texts: readonly string[], types: readonly Type[]] {
switch (stringMappingTypeKinds.get(symbol.escapedName as string)) {
case StringMappingTypeKind.Uppercase: return [texts.map(t => t.toUpperCase()), types.map(t => getStringMappingType(symbol, t))];
case StringMappingTypeKind.Lowercase: return [texts.map(t => t.toLowerCase()), types.map(t => getStringMappingType(symbol, t))];
case StringMappingTypeKind.Capitalize: return [texts[0] === "" ? texts : [texts[0].charAt(0).toUpperCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types];
case StringMappingTypeKind.Uncapitalize: return [texts[0] === "" ? texts : [texts[0].charAt(0).toLowerCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types];
case StringMappingTypeKind.Uppercase:
return [texts.map(t => t.toUpperCase()), types.map(t => getStringMappingType(symbol, t))];
case StringMappingTypeKind.Lowercase:
return [texts.map(t => t.toLowerCase()), types.map(t => getStringMappingType(symbol, t))];
case StringMappingTypeKind.Capitalize:
return [texts[0] === "" ? texts : [texts[0].charAt(0).toUpperCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types];
case StringMappingTypeKind.Uncapitalize:
return [texts[0] === "" ? texts : [texts[0].charAt(0).toLowerCase() + texts[0].slice(1), ...texts.slice(1)], texts[0] === "" ? [getStringMappingType(symbol, types[0]), ...types.slice(1)] : types];
}
return [texts, types];
}
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.