From dd7f00f20b4d34e8a374023a3286f05228ee295f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 10 Nov 2016 08:53:32 -0800 Subject: [PATCH] Parse the jsxFactory again in the checker instead of using cached value in the program --- src/compiler/checker.ts | 11 +++++++---- src/compiler/program.ts | 10 ++-------- src/compiler/transformers/jsx.ts | 2 +- src/compiler/types.ts | 3 +-- src/compiler/utilities.ts | 2 -- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d5cee0362e..d8d214674d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -336,6 +336,8 @@ namespace ts { let jsxElementType: Type; let _jsxNamespace: string; + let _jsxFactoryEntity: EntityName; + /** Things we lazy load from the JSX namespace */ const jsxTypes = createMap(); const JsxNames = { @@ -377,9 +379,9 @@ namespace ts { if (_jsxNamespace === undefined) { _jsxNamespace = "React"; if (compilerOptions.jsxFactory) { - const jsxEntity = host.getJsxFactoryEntity(); - if (jsxEntity) { - _jsxNamespace = getFirstIdentifier(jsxEntity).text; + _jsxFactoryEntity = parseIsolatedEntityName(compilerOptions.jsxFactory, languageVersion); + if (_jsxFactoryEntity) { + _jsxNamespace = getFirstIdentifier(_jsxFactoryEntity).text; } } else if (compilerOptions.reactNamespace) { @@ -19613,7 +19615,8 @@ namespace ts { getTypeReferenceDirectivesForEntityName, getTypeReferenceDirectivesForSymbol, isLiteralConstDeclaration, - writeLiteralConstValue + writeLiteralConstValue, + getJsxFactoryEntity: () => _jsxFactoryEntity }; // defined here to avoid outer scope pollution diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 90448d197d0..213e6a95ab1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -329,9 +329,6 @@ namespace ts { // Map storing if there is emit blocking diagnostics for given input const hasEmitBlockingDiagnostics = createFileMap(getCanonicalFileName); - // ReactNamespace and jsxFactory information - let jsxFactoryEntity: EntityName; - let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModuleFull[]; if (host.resolveModuleNames) { resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => { @@ -424,8 +421,7 @@ namespace ts { getFileProcessingDiagnostics: () => fileProcessingDiagnostics, getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives, isSourceFileFromExternalLibrary, - dropDiagnosticsProducingTypeChecker, - getJsxFactoryEntity: () => jsxFactoryEntity + dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -731,7 +727,6 @@ namespace ts { writeFile: writeFileCallback || ( (fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)), isEmitBlocked, - getJsxFactoryEntity: program.getJsxFactoryEntity, }; } @@ -1679,8 +1674,7 @@ namespace ts { if (options.reactNamespace) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory")); } - jsxFactoryEntity = parseIsolatedEntityName(options.jsxFactory, languageVersion); - if (!jsxFactoryEntity) { + if (!parseIsolatedEntityName(options.jsxFactory, languageVersion)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFactory)); } } diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 874f4f6862f..ba762cc5f12 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -114,7 +114,7 @@ namespace ts { } const element = createExpressionForJsxElement( - context.getEmitHost().getJsxFactoryEntity(), + context.getEmitResolver().getJsxFactoryEntity(), compilerOptions.reactNamespace, tagName, objectProperties, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 09d32ad817e..08e117d23e7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2177,7 +2177,6 @@ namespace ts { getTypeChecker(): TypeChecker; /* @internal */ getCommonSourceDirectory(): string; - /* @internal */ getJsxFactoryEntity(): EntityName; // For testing purposes only. Should not be used by any other consumers (including the // language service). @@ -2251,7 +2250,6 @@ namespace ts { /* @internal */ export interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getJsxFactoryEntity(): EntityName; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; @@ -2475,6 +2473,7 @@ namespace ts { getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[]; isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter): void; + getJsxFactoryEntity(): EntityName; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 826beccc7b1..299f91be662 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -34,8 +34,6 @@ namespace ts { /* @internal */ isSourceFileFromExternalLibrary(file: SourceFile): boolean; - /* @internal */ - getJsxFactoryEntity(): EntityName; getCommonSourceDirectory(): string; getCanonicalFileName(fileName: string): string; getNewLine(): string;