Skip to content

Commit dd7f00f

Browse files
committed
Parse the jsxFactory again in the checker instead of using cached value in the program
1 parent a88c2ae commit dd7f00f

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

Diff for: src/compiler/checker.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ namespace ts {
336336

337337
let jsxElementType: Type;
338338
let _jsxNamespace: string;
339+
let _jsxFactoryEntity: EntityName;
340+
339341
/** Things we lazy load from the JSX namespace */
340342
const jsxTypes = createMap<Type>();
341343
const JsxNames = {
@@ -377,9 +379,9 @@ namespace ts {
377379
if (_jsxNamespace === undefined) {
378380
_jsxNamespace = "React";
379381
if (compilerOptions.jsxFactory) {
380-
const jsxEntity = host.getJsxFactoryEntity();
381-
if (jsxEntity) {
382-
_jsxNamespace = getFirstIdentifier(jsxEntity).text;
382+
_jsxFactoryEntity = parseIsolatedEntityName(compilerOptions.jsxFactory, languageVersion);
383+
if (_jsxFactoryEntity) {
384+
_jsxNamespace = getFirstIdentifier(_jsxFactoryEntity).text;
383385
}
384386
}
385387
else if (compilerOptions.reactNamespace) {
@@ -19613,7 +19615,8 @@ namespace ts {
1961319615
getTypeReferenceDirectivesForEntityName,
1961419616
getTypeReferenceDirectivesForSymbol,
1961519617
isLiteralConstDeclaration,
19616-
writeLiteralConstValue
19618+
writeLiteralConstValue,
19619+
getJsxFactoryEntity: () => _jsxFactoryEntity
1961719620
};
1961819621

1961919622
// defined here to avoid outer scope pollution

Diff for: src/compiler/program.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ namespace ts {
329329
// Map storing if there is emit blocking diagnostics for given input
330330
const hasEmitBlockingDiagnostics = createFileMap<boolean>(getCanonicalFileName);
331331

332-
// ReactNamespace and jsxFactory information
333-
let jsxFactoryEntity: EntityName;
334-
335332
let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModuleFull[];
336333
if (host.resolveModuleNames) {
337334
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => {
@@ -424,8 +421,7 @@ namespace ts {
424421
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
425422
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
426423
isSourceFileFromExternalLibrary,
427-
dropDiagnosticsProducingTypeChecker,
428-
getJsxFactoryEntity: () => jsxFactoryEntity
424+
dropDiagnosticsProducingTypeChecker
429425
};
430426

431427
verifyCompilerOptions();
@@ -731,7 +727,6 @@ namespace ts {
731727
writeFile: writeFileCallback || (
732728
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
733729
isEmitBlocked,
734-
getJsxFactoryEntity: program.getJsxFactoryEntity,
735730
};
736731
}
737732

@@ -1679,8 +1674,7 @@ namespace ts {
16791674
if (options.reactNamespace) {
16801675
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory"));
16811676
}
1682-
jsxFactoryEntity = parseIsolatedEntityName(options.jsxFactory, languageVersion);
1683-
if (!jsxFactoryEntity) {
1677+
if (!parseIsolatedEntityName(options.jsxFactory, languageVersion)) {
16841678
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFactory));
16851679
}
16861680
}

Diff for: src/compiler/transformers/jsx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace ts {
114114
}
115115

116116
const element = createExpressionForJsxElement(
117-
context.getEmitHost().getJsxFactoryEntity(),
117+
context.getEmitResolver().getJsxFactoryEntity(),
118118
compilerOptions.reactNamespace,
119119
tagName,
120120
objectProperties,

Diff for: src/compiler/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,6 @@ namespace ts {
21772177
getTypeChecker(): TypeChecker;
21782178

21792179
/* @internal */ getCommonSourceDirectory(): string;
2180-
/* @internal */ getJsxFactoryEntity(): EntityName;
21812180

21822181
// For testing purposes only. Should not be used by any other consumers (including the
21832182
// language service).
@@ -2251,7 +2250,6 @@ namespace ts {
22512250
/* @internal */
22522251
export interface TypeCheckerHost {
22532252
getCompilerOptions(): CompilerOptions;
2254-
getJsxFactoryEntity(): EntityName;
22552253

22562254
getSourceFiles(): SourceFile[];
22572255
getSourceFile(fileName: string): SourceFile;
@@ -2475,6 +2473,7 @@ namespace ts {
24752473
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[];
24762474
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
24772475
writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter): void;
2476+
getJsxFactoryEntity(): EntityName;
24782477
}
24792478

24802479
export const enum SymbolFlags {

Diff for: src/compiler/utilities.ts

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ namespace ts {
3434
/* @internal */
3535
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
3636

37-
/* @internal */
38-
getJsxFactoryEntity(): EntityName;
3937
getCommonSourceDirectory(): string;
4038
getCanonicalFileName(fileName: string): string;
4139
getNewLine(): string;

0 commit comments

Comments
 (0)