Replace usage of jsonObject on JsonSourceFile

This commit is contained in:
Sheetal Nandi
2018-02-23 13:59:47 -08:00
parent 5771adbbe7
commit ee2e267d38
7 changed files with 33 additions and 13 deletions
+4 -4
View File
@@ -1056,11 +1056,11 @@ namespace ts {
errors: Push<Diagnostic>,
knownRootOptions: Map<CommandLineOption> | undefined,
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
if (!sourceFile.jsonObject) {
if (!sourceFile.statements.length) {
return {};
}
return convertObjectLiteralExpressionToJson(sourceFile.jsonObject, knownRootOptions,
return convertObjectLiteralExpressionToJson(sourceFile.statements[0].expression, knownRootOptions,
/*extraKeyDiagnosticMessage*/ undefined, /*parentOption*/ undefined);
function convertObjectLiteralExpressionToJson(
@@ -2092,8 +2092,8 @@ namespace ts {
});
function createDiagnostic(message: DiagnosticMessage, spec: string): Diagnostic {
if (jsonSourceFile && jsonSourceFile.jsonObject) {
for (const property of getPropertyAssignment(jsonSourceFile.jsonObject, specKey)) {
if (jsonSourceFile && jsonSourceFile.statements.length) {
for (const property of getPropertyAssignment(jsonSourceFile.statements[0].expression, specKey)) {
if (isArrayLiteralExpression(property.initializer)) {
for (const element of property.initializer.elements) {
if (isStringLiteral(element) && element.text === spec) {
+10 -4
View File
@@ -260,7 +260,6 @@ namespace ts {
return visitNodes(cbNode, cbNodes, (<Block>node).statements);
case SyntaxKind.SourceFile:
return visitNodes(cbNode, cbNodes, (<SourceFile>node).statements) ||
visitNode(cbNode, (<JsonSourceFile>node).jsonObject) ||
visitNode(cbNode, (<SourceFile>node).endOfFileToken);
case SyntaxKind.VariableStatement:
return visitNodes(cbNode, cbNodes, node.decorators) ||
@@ -663,7 +662,6 @@ namespace ts {
scriptKind = ensureScriptKind(fileName, scriptKind);
if (scriptKind === ScriptKind.JSON) {
const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes);
result.statements = <any>emptyArray;
result.typeReferenceDirectives = emptyArray;
result.amdDependencies = emptyArray;
return result;
@@ -693,22 +691,30 @@ namespace ts {
initializeState(sourceText, languageVersion, syntaxCursor, ScriptKind.JSON);
// Set source file so that errors will be reported with this file name
sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false);
const result = <JsonSourceFile>sourceFile;
const result = sourceFile as JsonSourceFile;
// Prime the scanner.
nextToken();
const pos = getNodePos();
if (token() === SyntaxKind.EndOfFileToken) {
sourceFile.endOfFileToken = parseTokenNode<EndOfFileToken>();
}
else if (token() === SyntaxKind.OpenBraceToken ||
lookAhead(() => token() === SyntaxKind.StringLiteral)) {
result.jsonObject = parseObjectLiteralExpression();
const statement = createNode(SyntaxKind.ExpressionStatement) as JsonObjectLiteralExpressionStatement;
statement.expression = parseObjectLiteralExpression();
finishNode(statement);
sourceFile.statements = createNodeArray([statement], pos);
sourceFile.endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token);
}
else {
parseExpected(SyntaxKind.OpenBraceToken);
}
if (!sourceFile.statements) {
sourceFile.statements = createNodeArray([], pos, pos);
}
if (setParentNodes) {
fixupParentReferences(sourceFile);
}
+2 -2
View File
@@ -2333,8 +2333,8 @@ namespace ts {
function getCompilerOptionsObjectLiteralSyntax() {
if (_compilerOptionsObjectLiteralSyntax === undefined) {
_compilerOptionsObjectLiteralSyntax = null; // tslint:disable-line:no-null-keyword
if (options.configFile && options.configFile.jsonObject) {
for (const prop of getPropertyAssignment(options.configFile.jsonObject, "compilerOptions")) {
if (options.configFile && options.configFile.statements.length) {
for (const prop of getPropertyAssignment(options.configFile.statements[0].expression, "compilerOptions")) {
if (isObjectLiteralExpression(prop.initializer)) {
_compilerOptionsObjectLiteralSyntax = prop.initializer;
break;
+5 -1
View File
@@ -2576,10 +2576,14 @@ namespace ts {
}
export interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectLiteralExpressionStatement>;
extendedSourceFiles?: string[];
}
export interface JsonObjectLiteralExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression;
}
export interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
+4 -1
View File
@@ -1631,9 +1631,12 @@ declare namespace ts {
sourceFiles: ReadonlyArray<SourceFile>;
}
interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectLiteralExpressionStatement>;
extendedSourceFiles?: string[];
}
interface JsonObjectLiteralExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression;
}
interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
+4 -1
View File
@@ -1631,9 +1631,12 @@ declare namespace ts {
sourceFiles: ReadonlyArray<SourceFile>;
}
interface JsonSourceFile extends SourceFile {
jsonObject?: ObjectLiteralExpression;
statements: NodeArray<JsonObjectLiteralExpressionStatement>;
extendedSourceFiles?: string[];
}
interface JsonObjectLiteralExpressionStatement extends ExpressionStatement {
expression: ObjectLiteralExpression;
}
interface ScriptReferenceHost {
getCompilerOptions(): CompilerOptions;
getSourceFile(fileName: string): SourceFile | undefined;
@@ -16,6 +16,10 @@ if (x) {
}
//// [b.js]
{
"a": true,
"b": "hello"
};
//// [file1.js]
"use strict";
exports.__esModule = true;