File tree Expand file tree Collapse file tree
Open diff view settings
Expand file tree Collapse file tree
Open diff view settings
Original file line number Diff line number Diff 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) {
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments