Skip to content

Commit 4e6586d

Browse files
committed
PR feedback
1 parent 15f9ea3 commit 4e6586d

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

src/compiler/checker.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4719,8 +4719,7 @@ namespace ts {
47194719
}
47204720
// Handle export default expressions
47214721
if (isSourceFile(declaration)) {
4722-
Debug.assert(isJsonSourceFile(declaration));
4723-
const jsonSourceFile = <JsonSourceFile>declaration;
4722+
const jsonSourceFile = cast(declaration, isJsonSourceFile);
47244723
return links.type = jsonSourceFile.statements.length ? checkExpression(jsonSourceFile.statements[0].expression) : emptyObjectType;
47254724
}
47264725
if (declaration.kind === SyntaxKind.ExportAssignment) {

src/compiler/commandLineParser.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ namespace ts {
10761076

10771077
/**
10781078
* Convert the json syntax tree into the json value and report errors
1079+
* This returns the json value (apart from checking errors) only if returnValue provided is true.
1080+
* Otherwise it just checks the errors and returns undefined
10791081
*/
10801082
/*@internal*/
10811083
export function convertToObjectWorker(

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ namespace ts {
24332433
switch (extension) {
24342434
case Extension.Ts:
24352435
case Extension.Dts:
2436-
case Extension.Json:
2436+
case Extension.Json: // Since module is resolved to json file only when --resolveJsonModule, we dont need further check
24372437
// These are always allowed.
24382438
return undefined;
24392439
case Extension.Tsx:

src/compiler/utilities.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1076,26 +1076,20 @@ namespace ts {
10761076
});
10771077
}
10781078

1079-
export function getTsConfigObjectLiteralExpression(tsConfigSourceFile: TsConfigSourceFile) {
1079+
export function getTsConfigObjectLiteralExpression(tsConfigSourceFile: TsConfigSourceFile | undefined) {
10801080
if (tsConfigSourceFile && tsConfigSourceFile.statements.length) {
10811081
const expression = tsConfigSourceFile.statements[0].expression;
10821082
return isObjectLiteralExpression(expression) && expression;
10831083
}
10841084
}
10851085

1086-
export function getTsConfigPropArrayElementValue(tsConfigSourceFile: TsConfigSourceFile, propKey: string, elementValue: string): StringLiteral {
1086+
export function getTsConfigPropArrayElementValue(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string, elementValue: string): StringLiteral | undefined {
10871087
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(tsConfigSourceFile);
1088-
if (jsonObjectLiteral) {
1089-
for (const property of getPropertyAssignment(jsonObjectLiteral, propKey)) {
1090-
if (isArrayLiteralExpression(property.initializer)) {
1091-
for (const element of property.initializer.elements) {
1092-
if (isStringLiteral(element) && element.text === elementValue) {
1093-
return element;
1094-
}
1095-
}
1096-
}
1097-
}
1098-
}
1088+
return jsonObjectLiteral &&
1089+
firstDefined(getPropertyAssignment(jsonObjectLiteral, propKey), property =>
1090+
isArrayLiteralExpression(property.initializer) ?
1091+
find(property.initializer.elements, (element): element is StringLiteral => isStringLiteral(element) && element.text === elementValue) :
1092+
undefined);
10991093
}
11001094

11011095
export function getContainingFunction(node: Node): SignatureDeclaration {

0 commit comments

Comments
 (0)