diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1cf4b9724d7ae..757ae3bba2501 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1241,6 +1241,18 @@ namespace ts { category: Diagnostics.Editor_Support, }, + { + name: "moduleDetection", + type: new Map(getEntries({ + auto: ModuleDetectionKind.Auto, + legacy: ModuleDetectionKind.Legacy, + force: ModuleDetectionKind.Force, + })), + affectsModuleResolution: true, + description: Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files, + category: Diagnostics.Language_and_Environment, + defaultValueDescription: Diagnostics.auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node12_as_modules, + } ]; /* @internal */ diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cceaa2abd50b3..b9adfb94fc837 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2156,14 +2156,16 @@ namespace ts { return (arg: T) => f(arg) && g(arg); } - export function or(...fs: ((...args: T) => boolean)[]): (...args: T) => boolean { + export function or(...fs: ((...args: T) => U)[]): (...args: T) => U { return (...args) => { + let lastResult: U; for (const f of fs) { - if (f(...args)) { - return true; + lastResult = f(...args); + if (lastResult) { + return lastResult; } } - return false; + return lastResult!; }; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f211d7aeb20fc..387d7123beb4b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1449,6 +1449,14 @@ "category": "Error", "code": 1474 }, + "Control what method is used to detect module-format JS files.": { + "category": "Message", + "code": 1475 + }, + "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node12+) as modules.": { + "category": "Message", + "code": 1476 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8266db7f40c21..898f50c475eff 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -60,6 +60,41 @@ namespace ts { text.charCodeAt(start + 3) !== CharacterCodes.slash; } + /*@internal*/ + export function isFileProbablyExternalModule(sourceFile: SourceFile) { + // Try to use the first top-level import/export when available, then + // fall back to looking for an 'import.meta' somewhere in the tree if necessary. + return forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) || + getImportMetaIfNecessary(sourceFile); + } + + function isAnExternalModuleIndicatorNode(node: Node) { + return hasModifierOfKind(node, SyntaxKind.ExportKeyword) + || isImportEqualsDeclaration(node) && isExternalModuleReference(node.moduleReference) + || isImportDeclaration(node) + || isExportAssignment(node) + || isExportDeclaration(node) ? node : undefined; + } + + function getImportMetaIfNecessary(sourceFile: SourceFile) { + return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ? + walkTreeForImportMeta(sourceFile) : + undefined; + } + + function walkTreeForImportMeta(node: Node): Node | undefined { + return isImportMeta(node) ? node : forEachChild(node, walkTreeForImportMeta); + } + + /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */ + function hasModifierOfKind(node: Node, kind: SyntaxKind) { + return some(node.modifiers, m => m.kind === kind); + } + + function isImportMeta(node: Node): boolean { + return isMetaProperty(node) && node.keywordToken === SyntaxKind.ImportKeyword && node.name.escapedText === "meta"; + } + /** * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, @@ -642,17 +677,46 @@ namespace ts { } } - export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false, scriptKind?: ScriptKind): SourceFile { + export interface CreateSourceFileOptions { + languageVersion: ScriptTarget; + /** + * Controls the format the file is detected as - this can be derived from only the path + * and files on disk, but needs to be done with a module resolution cache in scope to be performant. + * This is usually `undefined` for compilations that do not have `moduleResolution` values of `node12` or `nodenext`. + */ + impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS; + /** + * Controls how module-y-ness is set for the given file. Usually the result of calling + * `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default + * check specified by `isFileProbablyExternalModule` will be used to set the field. + */ + setExternalModuleIndicator?: (file: SourceFile) => void; + } + + function setExternalModuleIndicator(sourceFile: SourceFile) { + sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile); + } + + export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind): SourceFile { tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true); performance.mark("beforeParse"); let result: SourceFile; perfLogger.logStartParseSourceFile(fileName); + const { + languageVersion, + setExternalModuleIndicator: overrideSetExternalModuleIndicator, + impliedNodeFormat: format + } = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : ({ languageVersion: languageVersionOrOptions } as CreateSourceFileOptions); if (languageVersion === ScriptTarget.JSON) { - result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON); + result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, ScriptKind.JSON, noop); } else { - result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind); + const setIndicator = format === undefined ? overrideSetExternalModuleIndicator : (file: SourceFile) => { + file.impliedNodeFormat = format; + return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file); + }; + result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator); } perfLogger.logStopParseSourceFile(); @@ -851,7 +915,7 @@ namespace ts { // attached to the EOF token. let parseErrorBeforeNextFinishedNode = false; - export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor | undefined, setParentNodes = false, scriptKind?: ScriptKind): SourceFile { + export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor | undefined, setParentNodes = false, scriptKind?: ScriptKind, setExternalModuleIndicatorOverride?: (file: SourceFile) => void): SourceFile { scriptKind = ensureScriptKind(fileName, scriptKind); if (scriptKind === ScriptKind.JSON) { const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes); @@ -867,7 +931,7 @@ namespace ts { initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind); - const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind); + const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator); clearState(); @@ -955,7 +1019,7 @@ namespace ts { } // Set source file so that errors will be reported with this file name - const sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags); + const sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags, noop); if (setParentNodes) { fixupParentReferences(sourceFile); @@ -1039,7 +1103,7 @@ namespace ts { topLevel = true; } - function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind): SourceFile { + function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void): SourceFile { const isDeclarationFile = isDeclarationFileName(fileName); if (isDeclarationFile) { contextFlags |= NodeFlags.Ambient; @@ -1054,7 +1118,7 @@ namespace ts { Debug.assert(token() === SyntaxKind.EndOfFileToken); const endOfFileToken = addJSDocComment(parseTokenNode()); - const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags); + const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator); // A member of ReadonlyArray isn't assignable to a member of T[] (and prevents a direct cast) - but this is where we set up those members so they can be readonly in the future processCommentPragmas(sourceFile as {} as PragmaContext, sourceText); @@ -1213,28 +1277,42 @@ namespace ts { setParentRecursive(rootNode, /*incremental*/ true); } - function createSourceFile(fileName: string, languageVersion: ScriptTarget, scriptKind: ScriptKind, isDeclarationFile: boolean, statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile { + function createSourceFile( + fileName: string, + languageVersion: ScriptTarget, + scriptKind: ScriptKind, + isDeclarationFile: boolean, + statements: readonly Statement[], + endOfFileToken: EndOfFileToken, + flags: NodeFlags, + setExternalModuleIndicator: (sourceFile: SourceFile) => void): SourceFile { // code from createNode is inlined here so createNode won't have to deal with special case of creating source files // this is quite rare comparing to other nodes and createNode should be as fast as possible let sourceFile = factory.createSourceFile(statements, endOfFileToken, flags); setTextRangePosWidth(sourceFile, 0, sourceText.length); - setExternalModuleIndicator(sourceFile); + setFields(sourceFile); // If we parsed this as an external module, it may contain top-level await if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait) { sourceFile = reparseTopLevelAwait(sourceFile); + setFields(sourceFile); } - sourceFile.text = sourceText; - sourceFile.bindDiagnostics = []; - sourceFile.bindSuggestionDiagnostics = undefined; - sourceFile.languageVersion = languageVersion; - sourceFile.fileName = fileName; - sourceFile.languageVariant = getLanguageVariant(scriptKind); - sourceFile.isDeclarationFile = isDeclarationFile; - sourceFile.scriptKind = scriptKind; - return sourceFile; + + function setFields(sourceFile: SourceFile) { + sourceFile.text = sourceText; + sourceFile.bindDiagnostics = []; + sourceFile.bindSuggestionDiagnostics = undefined; + sourceFile.languageVersion = languageVersion; + sourceFile.fileName = fileName; + sourceFile.languageVariant = getLanguageVariant(scriptKind); + sourceFile.isDeclarationFile = isDeclarationFile; + sourceFile.scriptKind = scriptKind; + + setExternalModuleIndicator(sourceFile); + sourceFile.setExternalModuleIndicator = setExternalModuleIndicator; + } } function setContextFlag(val: boolean, flag: NodeFlags) { @@ -7575,41 +7653,6 @@ namespace ts { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function setExternalModuleIndicator(sourceFile: SourceFile) { - // Try to use the first top-level import/export when available, then - // fall back to looking for an 'import.meta' somewhere in the tree if necessary. - sourceFile.externalModuleIndicator = - forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) || - getImportMetaIfNecessary(sourceFile); - } - - function isAnExternalModuleIndicatorNode(node: Node) { - return hasModifierOfKind(node, SyntaxKind.ExportKeyword) - || isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference) - || isImportDeclaration(node) - || isExportAssignment(node) - || isExportDeclaration(node) ? node : undefined; - } - - function getImportMetaIfNecessary(sourceFile: SourceFile) { - return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ? - walkTreeForExternalModuleIndicators(sourceFile) : - undefined; - } - - function walkTreeForExternalModuleIndicators(node: Node): Node | undefined { - return isImportMeta(node) ? node : forEachChild(node, walkTreeForExternalModuleIndicators); - } - - /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */ - function hasModifierOfKind(node: Node, kind: SyntaxKind) { - return some(node.modifiers, m => m.kind === kind); - } - - function isImportMeta(node: Node): boolean { - return isMetaProperty(node) && node.keywordToken === SyntaxKind.ImportKeyword && node.name.escapedText === "meta"; - } - const enum ParsingContext { SourceElements, // Elements in source file BlockStatements, // Statements in block @@ -7652,7 +7695,7 @@ namespace ts { currentToken = scanner.scan(); const jsDocTypeExpression = parseJSDocTypeExpression(); - const sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS, /*isDeclarationFile*/ false, [], factory.createToken(SyntaxKind.EndOfFileToken), NodeFlags.None); + const sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS, /*isDeclarationFile*/ false, [], factory.createToken(SyntaxKind.EndOfFileToken), NodeFlags.None, noop); const diagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); if (jsDocDiagnostics) { sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile); @@ -8698,7 +8741,7 @@ namespace ts { if (sourceFile.statements.length === 0) { // If we don't have any statements in the current source file, then there's no real // way to incrementally parse. So just do a full parse instead. - return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind); + return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator); } // Make sure we're not trying to incrementally update a source file more than once. Once @@ -8762,7 +8805,7 @@ namespace ts { // inconsistent tree. Setting the parents on the new tree should be very fast. We // will immediately bail out of walking any subtrees when we can see that their parents // are already correct. - const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind); + const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator); result.commentDirectives = getNewCommentDirectives( sourceFile.commentDirectives, result.commentDirectives, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 22c38fa986a97..31885ec7f12e7 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -74,7 +74,7 @@ namespace ts { const existingDirectories = new Map(); const getCanonicalFileName = createGetCanonicalFileName(system.useCaseSensitiveFileNames); const computeHash = maybeBind(system, system.createHash) || generateDjb2Hash; - function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile | undefined { + function getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void): SourceFile | undefined { let text: string | undefined; try { performance.mark("beforeIORead"); @@ -88,7 +88,7 @@ namespace ts { } text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined; + return text !== undefined ? createSourceFile(fileName, text, languageVersionOrOptions, setParentNodes) : undefined; } function directoryExists(directoryPath: string): boolean { @@ -1695,8 +1695,8 @@ namespace ts { for (const oldSourceFile of oldSourceFiles) { let newSourceFile = host.getSourceFileByPath - ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile) - : host.getSourceFile(oldSourceFile.fileName, getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217 + ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile) + : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217 if (!newSourceFile) { return StructureIsReused.Not; @@ -1731,7 +1731,6 @@ namespace ts { newSourceFile.originalFileName = oldSourceFile.originalFileName; newSourceFile.resolvedPath = oldSourceFile.resolvedPath; newSourceFile.fileName = oldSourceFile.fileName; - newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat; const packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path); if (packageName !== undefined) { @@ -2780,6 +2779,18 @@ namespace ts { return result; } + function getCreateSourceFileOptions(fileName: string, moduleResolutionCache: ModuleResolutionCache | undefined, host: CompilerHost, options: CompilerOptions) { + // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache + // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way + // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. + const impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); + return { + languageVersion: getEmitScriptTarget(options), + impliedNodeFormat, + setExternalModuleIndicator: getSetExternalModuleIndicator(options) + }; + } + function findSourceFileWorker(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined { const path = toPath(fileName); if (useSourceOfProjectReferenceRedirect) { @@ -2872,7 +2883,7 @@ namespace ts { // We haven't looked for this file, do so now and cache result const file = host.getSourceFile( fileName, - getEmitScriptTarget(options), + getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options), hostErrorMessage => addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]), shouldCreateNewSourceFile ); @@ -2905,10 +2916,6 @@ namespace ts { file.path = path; file.resolvedPath = toPath(fileName); file.originalFileName = originalFileName; - // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache - // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way - // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - file.impliedNodeFormat = getImpliedNodeFormatForFile(file.resolvedPath, moduleResolutionCache?.getPackageJsonInfoCache(), host, options); addFileIncludeReason(file, reason); if (host.useCaseSensitiveFileNames()) { @@ -3501,7 +3508,7 @@ namespace ts { } else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet - const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator!); + const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator!); programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } @@ -3511,7 +3518,7 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module"); } else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) { - const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator!); + const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator!); programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); } } diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index c42d99c33c4b8..d6127fdc1c488 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -49,7 +49,7 @@ namespace ts { interface CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations extends ResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolutionWithFailedLookupLocations { } - export interface ResolutionCacheHost extends ModuleResolutionHost { + export interface ResolutionCacheHost extends MinimalResolutionCacheHost { toPath(fileName: string): Path; getCanonicalFileName: GetCanonicalFileName; getCompilationSettings(): CompilerOptions; @@ -65,7 +65,6 @@ namespace ts { writeLog(s: string): void; getCurrentProgram(): Program | undefined; fileIsOpen(filePath: Path): boolean; - getCompilerHost?(): CompilerHost | undefined; onDiscoveredSymlink?(): void; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 53bb25c459713..3fee2e6eac415 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3622,7 +3622,13 @@ namespace ts { * This is intended to be the first top-level import/export, * but could be arbitrarily nested (e.g. `import.meta`). */ - /* @internal */ externalModuleIndicator?: Node; + /* @internal */ externalModuleIndicator?: Node | true; + /** + * The callback used to set the external module indicator - this is saved to + * be later reused during incremental reparsing, which otherwise lacks the information + * to set this field + */ + /* @internal */ setExternalModuleIndicator?: (file: SourceFile) => void; // The first node that causes this file to be a CommonJS module /* @internal */ commonJsModuleIndicator?: Node; // JS identifier-declarations that are intended to merge with globals @@ -6029,6 +6035,21 @@ namespace ts { NodeNext = 99, // Not simply `Node12` so that compiled code linked against TS can use the `Next` value reliably (same as with `ModuleKind`) } + export enum ModuleDetectionKind { + /** + * Files with imports, exports and/or import.meta are considered modules + */ + Legacy = 1, + /** + * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+ + */ + Auto = 2, + /** + * Consider all non-declaration files modules, regardless of present syntax + */ + Force = 3, + } + export interface PluginImport { name: string; } @@ -6124,6 +6145,7 @@ namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; /*@internal*/noEmitForJsFiles?: boolean; @@ -6588,6 +6610,14 @@ namespace ts { useCaseSensitiveFileNames?: boolean | (() => boolean); } + /** + * Used by services to specify the minimum host area required to set up source files under any compilation settings + */ + export interface MinimalResolutionCacheHost extends ModuleResolutionHost { + getCompilationSettings(): CompilerOptions; + getCompilerHost?(): CompilerHost | undefined; + } + /** * Represents the result of module resolution. * Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off. @@ -6690,8 +6720,8 @@ namespace ts { export type HasChangedAutomaticTypeDirectiveNames = () => boolean; export interface CompilerHost extends ModuleResolutionHost { - getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; - getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFileByPath?(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index cd0ab1c658e36..53e8cf0a82c77 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6205,6 +6205,63 @@ namespace ts { return scriptKind === ScriptKind.TSX || scriptKind === ScriptKind.JSX || scriptKind === ScriptKind.JS || scriptKind === ScriptKind.JSON ? LanguageVariant.JSX : LanguageVariant.Standard; } + /** + * This is a somewhat unavoidable full tree walk to locate a JSX tag - `import.meta` requires the same, + * but we avoid that walk (or parts of it) if at all possible using the `PossiblyContainsImportMeta` node flag. + * Unfortunately, there's no `NodeFlag` space to do the same for JSX. + */ + function walkTreeForJSXTags(node: Node): Node | undefined { + if (!(node.transformFlags & TransformFlags.ContainsJsx)) return undefined; + return isJsxOpeningLikeElement(node) || isJsxFragment(node) ? node : forEachChild(node, walkTreeForJSXTags); + } + + function isFileModuleFromUsingJSXTag(file: SourceFile): Node | undefined { + // Excludes declaration files - they still require an explicit `export {}` or the like + // for back compat purposes. (not that declaration files should contain JSX tags!) + return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined; + } + + /** + * Note that this requires file.impliedNodeFormat be set already; meaning it must be set very early on + * in SourceFile construction. + */ + function isFileForcedToBeModuleByFormat(file: SourceFile): true | undefined { + // Excludes declaration files - they still require an explicit `export {}` or the like + // for back compat purposes. + return file.impliedNodeFormat === ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + } + + export function getSetExternalModuleIndicator(options: CompilerOptions): (file: SourceFile) => void { + // TODO: Should this callback be cached? + switch (getEmitModuleDetectionKind(options)) { + case ModuleDetectionKind.Force: + // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule + return (file: SourceFile) => { + file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file); + }; + case ModuleDetectionKind.Legacy: + // Files are modules if they have imports, exports, or import.meta + return (file: SourceFile) => { + file.externalModuleIndicator = isFileProbablyExternalModule(file); + }; + case ModuleDetectionKind.Auto: + // If module is nodenext or node12, all esm format files are modules + // If jsx is react-jsx or react-jsxdev then jsx tags force module-ness + // otherwise, the presence of import or export statments (or import.meta) implies module-ness + const checks: ((file: SourceFile) => Node | true | undefined)[] = [isFileProbablyExternalModule]; + if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) { + checks.push(isFileModuleFromUsingJSXTag); + } + const moduleKind = getEmitModuleKind(options); + if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) { + checks.push(isFileForcedToBeModuleByFormat); + } + const combined = or(...checks); + const callback = (file: SourceFile) => void (file.externalModuleIndicator = combined(file)); + return callback; + } + } + export function getEmitScriptTarget(compilerOptions: {module?: CompilerOptions["module"], target?: CompilerOptions["target"]}) { return compilerOptions.target || (compilerOptions.module === ModuleKind.Node12 && ScriptTarget.ES2020) || @@ -6239,6 +6296,10 @@ namespace ts { return moduleResolution; } + export function getEmitModuleDetectionKind(options: CompilerOptions) { + return options.moduleDetection || ModuleDetectionKind.Auto; + } + export function hasJsonModuleEmitEnabled(options: CompilerOptions) { switch (getEmitModuleKind(options)) { case ModuleKind.CommonJS: diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 5e8c950da4eee..b2f7a0a3bc540 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -539,7 +539,7 @@ namespace ts { const useCaseSensitiveFileNames = host.useCaseSensitiveFileNames(); const hostGetNewLine = memoize(() => host.getNewLine()); return { - getSourceFile: (fileName, languageVersion, onError) => { + getSourceFile: (fileName, languageVersionOrOptions, onError) => { let text: string | undefined; try { performance.mark("beforeIORead"); @@ -554,7 +554,7 @@ namespace ts { text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; + return text !== undefined ? createSourceFile(fileName, text, languageVersionOrOptions) : undefined; }, getDefaultLibLocation: maybeBind(host, host.getDefaultLibLocation), getDefaultLibFileName: options => host.getDefaultLibFileName(options), diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 1f6ec39df4ee9..095c0f69a1083 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -532,7 +532,7 @@ namespace ts { return directoryStructureHost.fileExists(fileName); } - function getVersionedSourceFileByPath(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined { + function getVersionedSourceFileByPath(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined { const hostSourceFile = sourceFilesCache.get(path); // No source file on the host if (isFileMissingOnHost(hostSourceFile)) { @@ -541,7 +541,7 @@ namespace ts { // Create new source file if requested or the versions dont match if (hostSourceFile === undefined || shouldCreateNewSourceFile || isFilePresenceUnknownOnHost(hostSourceFile)) { - const sourceFile = getNewSourceFile(fileName, languageVersion, onError); + const sourceFile = getNewSourceFile(fileName, languageVersionOrOptions, onError); if (hostSourceFile) { if (sourceFile) { // Set the source file and create file watcher now that file was present on the disk diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 47ed0e4a1aed8..b8513c3744297 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2293,8 +2293,18 @@ namespace FourSlash { // Check syntactic structure const content = this.getFileContent(this.activeFile.fileName); + const options: ts.CreateSourceFileOptions = { + languageVersion: ts.ScriptTarget.Latest, + impliedNodeFormat: ts.getImpliedNodeFormatForFile( + ts.toPath(this.activeFile.fileName, this.languageServiceAdapterHost.sys.getCurrentDirectory(), ts.hostGetCanonicalFileName(this.languageServiceAdapterHost)), + /*cache*/ undefined, + this.languageServiceAdapterHost, + this.languageService.getProgram()?.getCompilerOptions() || {} + ), + setExternalModuleIndicator: ts.getSetExternalModuleIndicator(this.languageService.getProgram()?.getCompilerOptions() || {}) + }; const referenceSourceFile = ts.createLanguageServiceSourceFile( - this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false); + this.activeFile.fileName, createScriptSnapShot(content), options, /*version:*/ "0", /*setNodeParents:*/ false); const referenceSyntaxDiagnostics = referenceSourceFile.parseDiagnostics; Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics); diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index dc41722f26cd7..be17bbdef0ef4 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -163,6 +163,24 @@ namespace Harness.LanguageService { } } + public fileExists(path: string): boolean { + try { + return this.vfs.existsSync(path); + } + catch { + return false; + } + } + + public readFile(path: string): string | undefined { + try { + return this.vfs.readFileSync(path).toString(); + } + catch { + return undefined; + } + } + public directoryExists(path: string) { return this.vfs.statSync(path).isDirectory(); } diff --git a/src/server/project.ts b/src/server/project.ts index b9ec87f411542..91bc1e639a355 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -1678,6 +1678,11 @@ namespace ts.server { return packageJsons; } + /* @internal */ + getPackageJsonCache() { + return this.projectService.packageJsonCache; + } + /*@internal*/ getCachedExportInfoMap() { return this.exportMapCache ||= createCacheableExportInfoMap(this); diff --git a/src/services/documentRegistry.ts b/src/services/documentRegistry.ts index ff440a84543a3..7446f895db244 100644 --- a/src/services/documentRegistry.ts +++ b/src/services/documentRegistry.ts @@ -21,9 +21,12 @@ namespace ts { * the SourceFile if was not found in the registry. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. Only used if the file was not found * in the registry and a new one was created. * @param version Current version of the file. Only used if the file was not found @@ -31,7 +34,7 @@ namespace ts { */ acquireDocument( fileName: string, - compilationSettings: CompilerOptions, + compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; @@ -39,7 +42,7 @@ namespace ts { acquireDocumentWithKey( fileName: string, path: Path, - compilationSettings: CompilerOptions, + compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, @@ -51,15 +54,18 @@ namespace ts { * to get an updated SourceFile. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. * @param version Current version of the file. */ updateDocument( fileName: string, - compilationSettings: CompilerOptions, + compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; @@ -67,7 +73,7 @@ namespace ts { updateDocumentWithKey( fileName: string, path: Path, - compilationSettings: CompilerOptions, + compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, @@ -165,24 +171,31 @@ namespace ts { return JSON.stringify(bucketInfoArray, undefined, 2); } - function acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { + function getCompilationSettings(settingsOrHost: CompilerOptions | MinimalResolutionCacheHost) { + if (typeof settingsOrHost.getCompilationSettings === "function") { + return (settingsOrHost as MinimalResolutionCacheHost).getCompilationSettings(); + } + return settingsOrHost as CompilerOptions; + } + + function acquireDocument(fileName: string, compilationSettings: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { const path = toPath(fileName, currentDirectory, getCanonicalFileName); - const key = getKeyForCompilationSettings(compilationSettings); + const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings)); return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind); } - function acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { + function acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind); } - function updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { + function updateDocument(fileName: string, compilationSettings: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { const path = toPath(fileName, currentDirectory, getCanonicalFileName); - const key = getKeyForCompilationSettings(compilationSettings); + const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings)); return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind); } - function updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { - return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ false, scriptKind); + function updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile { + return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind); } function getDocumentRegistryEntry(bucketEntry: BucketEntry, scriptKind: ScriptKind | undefined) { @@ -194,14 +207,21 @@ namespace ts { function acquireOrUpdateDocument( fileName: string, path: Path, - compilationSettings: CompilerOptions, + compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, acquiring: boolean, scriptKind?: ScriptKind): SourceFile { scriptKind = ensureScriptKind(fileName, scriptKind); + const compilationSettings = getCompilationSettings(compilationSettingsOrHost); + const host: MinimalResolutionCacheHost | undefined = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost as MinimalResolutionCacheHost; const scriptTarget = scriptKind === ScriptKind.JSON ? ScriptTarget.JSON : getEmitScriptTarget(compilationSettings); + const sourceFileOptions: CreateSourceFileOptions = { + languageVersion: scriptTarget, + impliedNodeFormat: host && getImpliedNodeFormatForFile(path, host.getCompilerHost?.()?.getModuleResolutionCache?.()?.getPackageJsonInfoCache(), host, compilationSettings), + setExternalModuleIndicator: getSetExternalModuleIndicator(compilationSettings) + }; const oldBucketCount = buckets.size; const bucket = getOrUpdate(buckets, key, () => new Map()); @@ -239,7 +259,7 @@ namespace ts { if (!entry) { // Have never seen this file with these settings. Create a new source file for it. - const sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind); + const sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind); if (externalCache) { externalCache.setDocument(key, path, sourceFile); } diff --git a/src/services/refactors/moveToNewFile.ts b/src/services/refactors/moveToNewFile.ts index 6e5d9c891e7f2..2e96d5aa95b4f 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -473,7 +473,7 @@ namespace ts.refactor { let newModuleName = moduleName; for (let i = 1; ; i++) { const name = combinePaths(inDirectory, newModuleName + extension); - if (!host.fileExists!(name)) return newModuleName; // TODO: GH#18217 + if (!host.fileExists(name)) return newModuleName; newModuleName = `${moduleName}.${i}`; } } diff --git a/src/services/services.ts b/src/services/services.ts index 6d144565dcc57..503482d63c7a8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1085,7 +1085,17 @@ namespace ts { if (this.currentFileName !== fileName) { // This is a new file, just parse it - sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, ScriptTarget.Latest, version, /*setNodeParents*/ true, scriptKind); + const options: CreateSourceFileOptions = { + languageVersion: ScriptTarget.Latest, + impliedNodeFormat: getImpliedNodeFormatForFile( + toPath(fileName, this.host.getCurrentDirectory(), this.host.getCompilerHost?.()?.getCanonicalFileName || hostGetCanonicalFileName(this.host)), + this.host.getCompilerHost?.()?.getModuleResolutionCache?.()?.getPackageJsonInfoCache(), + this.host, + this.host.getCompilationSettings() + ), + setExternalModuleIndicator: getSetExternalModuleIndicator(this.host.getCompilationSettings()) + }; + sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, scriptKind); } else if (this.currentFileVersion !== version) { // This is the same file, just a newer version. Incrementally parse the file. @@ -1110,8 +1120,8 @@ namespace ts { sourceFile.scriptSnapshot = scriptSnapshot; } - export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile { - const sourceFile = createSourceFile(fileName, getSnapshotText(scriptSnapshot), scriptTarget, setNodeParents, scriptKind); + export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile { + const sourceFile = createSourceFile(fileName, getSnapshotText(scriptSnapshot), scriptTargetOrOptions, setNodeParents, scriptKind); setSourceFileFields(sourceFile, scriptSnapshot, version); return sourceFile; } @@ -1167,8 +1177,13 @@ namespace ts { } } + const options: CreateSourceFileOptions = { + languageVersion: sourceFile.languageVersion, + impliedNodeFormat: sourceFile.impliedNodeFormat, + setExternalModuleIndicator: sourceFile.setExternalModuleIndicator, + }; // Otherwise, just create a new source file. - return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true, sourceFile.scriptKind); + return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, sourceFile.scriptKind); } const NoopCancellationToken: CancellationToken = { @@ -1551,7 +1566,7 @@ namespace ts { // file's script kind, i.e. in one project some file is treated as ".ts" // and in another as ".js" if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) { - return documentRegistry.updateDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind); + return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind); } else { // Release old source file and fall through to aquire new file with new script kind @@ -1563,7 +1578,7 @@ namespace ts { } // Could not find this file in the old program, create a new SourceFile for it. - return documentRegistry.acquireDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind); + return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind); } } diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index 314d4d485b8f6..7be5d210b36ea 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -27,7 +27,7 @@ namespace ts { if (!name) continue; const module = getResolvedModule(sourceFile, moduleSpecifier.text, getModeForUsageLocation(sourceFile, moduleSpecifier)); const resolvedFile = module && program.getSourceFile(module.resolvedFileName); - if (resolvedFile && resolvedFile.externalModuleIndicator && isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) { + if (resolvedFile && resolvedFile.externalModuleIndicator && resolvedFile.externalModuleIndicator !== true && isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) { diags.push(createDiagnosticForNode(name, Diagnostics.Import_may_be_converted_to_a_default_import)); } } diff --git a/src/services/transpile.ts b/src/services/transpile.ts index 5b73b91bd7f47..b2d8951e43b7e 100644 --- a/src/services/transpile.ts +++ b/src/services/transpile.ts @@ -46,23 +46,7 @@ namespace ts { // Filename can be non-ts file. options.allowNonTsExtensions = true; - // if jsx is specified then treat file as .tsx - const inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts"); - const sourceFile = createSourceFile(inputFileName, input, getEmitScriptTarget(options)); - if (transpileOptions.moduleName) { - sourceFile.moduleName = transpileOptions.moduleName; - } - - if (transpileOptions.renamedDependencies) { - sourceFile.renamedDependencies = new Map(getEntries(transpileOptions.renamedDependencies)); - } - const newLine = getNewLineCharacter(options); - - // Output - let outputText: string | undefined; - let sourceMapText: string | undefined; - // Create a compilerHost object to allow the compiler to read and write files const compilerHost: CompilerHost = { getSourceFile: (fileName) => fileName === normalizePath(inputFileName) ? sourceFile : undefined, @@ -87,6 +71,29 @@ namespace ts { getDirectories: () => [] }; + // if jsx is specified then treat file as .tsx + const inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts"); + const sourceFile = createSourceFile( + inputFileName, + input, + { + languageVersion: getEmitScriptTarget(options), + impliedNodeFormat: getImpliedNodeFormatForFile(toPath(inputFileName, "", compilerHost.getCanonicalFileName), /*cache*/ undefined, compilerHost, options), + setExternalModuleIndicator: getSetExternalModuleIndicator(options) + } + ); + if (transpileOptions.moduleName) { + sourceFile.moduleName = transpileOptions.moduleName; + } + + if (transpileOptions.renamedDependencies) { + sourceFile.renamedDependencies = new Map(getEntries(transpileOptions.renamedDependencies)); + } + + // Output + let outputText: string | undefined; + let sourceMapText: string | undefined; + const program = createProgram([inputFileName], options, compilerHost); if (transpileOptions.reportDiagnostics) { diff --git a/src/services/types.ts b/src/services/types.ts index 66730a23a5343..a32fa6599fa22 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -240,7 +240,7 @@ namespace ts { // // Public interface of the host of a language service instance. // - export interface LanguageServiceHost extends GetEffectiveTypeRootsHost { + export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -263,9 +263,14 @@ namespace ts { * Without these methods, only completions for ambient modules will be provided. */ readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; - readFile?(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + + /* + * Unlike `realpath and `readDirectory`, `readFile` and `fileExists` are now _required_ + * to properly acquire and setup source files under module: node12+ modes. + */ + readFile(path: string, encoding?: string): string | undefined; + fileExists(path: string): boolean; /* * LS host can optionally implement these methods to support automatic updating when new type libraries are installed diff --git a/src/services/utilities.ts b/src/services/utilities.ts index b3fcce814821d..88836f59c3428 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2941,7 +2941,7 @@ namespace ts { const packageJsons: PackageJsonInfo[] = []; forEachAncestorDirectory(getDirectoryPath(fileName), ancestor => { const packageJsonFileName = combinePaths(ancestor, "package.json"); - if (host.fileExists!(packageJsonFileName)) { + if (host.fileExists(packageJsonFileName)) { const info = createPackageJsonInfo(packageJsonFileName, host); if (info) { packageJsons.push(info); diff --git a/src/testRunner/compilerRunner.ts b/src/testRunner/compilerRunner.ts index 166ed164f77dd..1d320d667cf5f 100644 --- a/src/testRunner/compilerRunner.ts +++ b/src/testRunner/compilerRunner.ts @@ -118,6 +118,7 @@ namespace Harness { private static varyBy: readonly string[] = [ "module", "moduleResolution", + "moduleDetection", "target", "jsx", "removeComments", diff --git a/src/testRunner/unittests/services/extract/helpers.ts b/src/testRunner/unittests/services/extract/helpers.ts index b0fa383c96e03..660c903bd2bf3 100644 --- a/src/testRunner/unittests/services/extract/helpers.ts +++ b/src/testRunner/unittests/services/extract/helpers.ts @@ -72,6 +72,8 @@ namespace ts { getScriptSnapshot: notImplemented, getDefaultLibFileName: notImplemented, getCurrentDirectory: notImplemented, + readFile: notImplemented, + fileExists: notImplemented }; export function testExtractSymbol(caption: string, text: string, baselineFolder: string, description: DiagnosticMessage, includeLib?: boolean) { diff --git a/src/testRunner/unittests/services/hostNewLineSupport.ts b/src/testRunner/unittests/services/hostNewLineSupport.ts index 057cb60602a4b..762b8e3ddc159 100644 --- a/src/testRunner/unittests/services/hostNewLineSupport.ts +++ b/src/testRunner/unittests/services/hostNewLineSupport.ts @@ -15,6 +15,12 @@ namespace ts { getScriptSnapshot: name => snapFor(name), getDefaultLibFileName: () => "lib.d.ts", getCurrentDirectory: () => "", + readFile: name => { + const snap = snapFor(name); + if (!snap) return undefined; + return snap.getText(0, snap.getLength()); + }, + fileExists: name => !!snapFor(name), }; return createLanguageService(lshost); } diff --git a/src/testRunner/unittests/services/languageService.ts b/src/testRunner/unittests/services/languageService.ts index a1f7e5844b84d..c3f5f019541af 100644 --- a/src/testRunner/unittests/services/languageService.ts +++ b/src/testRunner/unittests/services/languageService.ts @@ -39,6 +39,8 @@ export function Component(x: Config): any;` getDefaultLibFileName(options) { return getDefaultLibFilePath(options); }, + fileExists: name => !!files[name], + readFile: name => files[name] }); } // Regression test for GH #18245 - bug in single line comment writer caused a debug assertion when attempting @@ -94,6 +96,7 @@ export function Component(x: Config): any;` useCaseSensitiveFileNames: returnTrue, getCompilationSettings: getDefaultCompilerOptions, fileExists: path => files.has(path), + readFile: path => files.get(path)?.text, getProjectVersion: !useProjectVersion ? undefined : () => projectVersion, getScriptFileNames: () => ["/project/root.ts"], getScriptVersion: path => files.get(path)?.version || "", @@ -189,6 +192,7 @@ export function Component(x: Config): any;` useSourceOfProjectReferenceRedirect, getCompilationSettings: () => result.options, fileExists: path => system.fileExists(path), + readFile: path => system.readFile(path), getScriptFileNames: () => result.fileNames, getScriptVersion: path => { const text = system.readFile(path); diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 8241222971b20..d86eb60e6777b 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -47,6 +47,8 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) { getCurrentDirectory: () => process.cwd(), getCompilationSettings: () => options, getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), + fileExists: fileName => fs.existsSync(fileName), + readFile: fileName => fs.readFileSync(fileName), }; // Create the language service files @@ -143,7 +145,9 @@ function watch(rootFileNames, options) { }, getCurrentDirectory: function () { return process.cwd(); }, getCompilationSettings: function () { return options; }, - getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(options); } + getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(options); }, + fileExists: function (fileName) { return fs.existsSync(fileName); }, + readFile: function (fileName) { return fs.readFileSync(fileName); } }; // Create the language service files var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9bddee3a01770..fcb78f56f6cc0 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2888,6 +2888,20 @@ declare namespace ts { Node12 = 3, NodeNext = 99 } + export enum ModuleDetectionKind { + /** + * Files with imports, exports and/or import.meta are considered modules + */ + Legacy = 1, + /** + * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+ + */ + Auto = 2, + /** + * Consider all non-declaration files modules, regardless of present syntax + */ + Force = 3 + } export interface PluginImport { name: string; } @@ -2959,6 +2973,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; @@ -3146,6 +3161,13 @@ declare namespace ts { getDirectories?(path: string): string[]; useCaseSensitiveFileNames?: boolean | (() => boolean); } + /** + * Used by services to specify the minimum host area required to set up source files under any compilation settings + */ + export interface MinimalResolutionCacheHost extends ModuleResolutionHost { + getCompilationSettings(): CompilerOptions; + getCompilerHost?(): CompilerHost | undefined; + } /** * Represents the result of module resolution. * Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off. @@ -3221,8 +3243,8 @@ declare namespace ts { readonly failedLookupLocations: string[]; } export interface CompilerHost extends ModuleResolutionHost { - getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; - getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFileByPath?(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; @@ -4776,7 +4798,22 @@ declare namespace ts { * that they appear in the source code. The language service depends on this property to locate nodes by position. */ export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined; - export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; + export interface CreateSourceFileOptions { + languageVersion: ScriptTarget; + /** + * Controls the format the file is detected as - this can be derived from only the path + * and files on disk, but needs to be done with a module resolution cache in scope to be performant. + * This is usually `undefined` for compilations that do not have `moduleResolution` values of `node12` or `nodenext`. + */ + impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS; + /** + * Controls how module-y-ness is set for the given file. Usually the result of calling + * `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default + * check specified by `isFileProbablyExternalModule` will be used to set the field. + */ + setExternalModuleIndicator?: (file: SourceFile) => void; + } + export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined; /** * Parse json text into SyntaxTree and return node and parse errors if any @@ -5676,7 +5713,7 @@ declare namespace ts { set(response: CompletionInfo): void; clear(): void; } - interface LanguageServiceHost extends GetEffectiveTypeRootsHost { + interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -5694,9 +5731,9 @@ declare namespace ts { error?(s: string): void; useCaseSensitiveFileNames?(): boolean; readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; - readFile?(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + readFile(path: string, encoding?: string): string | undefined; + fileExists(path: string): boolean; getTypeRootsVersion?(): number; resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; @@ -6748,30 +6785,36 @@ declare namespace ts { * the SourceFile if was not found in the registry. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. Only used if the file was not found * in the registry and a new one was created. * @param version Current version of the file. Only used if the file was not found * in the registry and a new one was created. */ - acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + acquireDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + acquireDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; /** * Request an updated version of an already existing SourceFile with a given fileName * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile * to get an updated SourceFile. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. * @param version Current version of the file. */ - updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + updateDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + updateDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey; /** * Informs the DocumentRegistry that a file is not needed any longer. @@ -6833,7 +6876,7 @@ declare namespace ts { function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string; function getDefaultCompilerOptions(): CompilerOptions; function getSupportedCodeFixes(): string[]; - function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile; function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnlyOrLanguageServiceMode?: boolean | LanguageServiceMode): LanguageService; /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0f71e03eef955..e78e7d779b831 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2888,6 +2888,20 @@ declare namespace ts { Node12 = 3, NodeNext = 99 } + export enum ModuleDetectionKind { + /** + * Files with imports, exports and/or import.meta are considered modules + */ + Legacy = 1, + /** + * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+ + */ + Auto = 2, + /** + * Consider all non-declaration files modules, regardless of present syntax + */ + Force = 3 + } export interface PluginImport { name: string; } @@ -2959,6 +2973,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; @@ -3146,6 +3161,13 @@ declare namespace ts { getDirectories?(path: string): string[]; useCaseSensitiveFileNames?: boolean | (() => boolean); } + /** + * Used by services to specify the minimum host area required to set up source files under any compilation settings + */ + export interface MinimalResolutionCacheHost extends ModuleResolutionHost { + getCompilationSettings(): CompilerOptions; + getCompilerHost?(): CompilerHost | undefined; + } /** * Represents the result of module resolution. * Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off. @@ -3221,8 +3243,8 @@ declare namespace ts { readonly failedLookupLocations: string[]; } export interface CompilerHost extends ModuleResolutionHost { - getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; - getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; + getSourceFileByPath?(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; @@ -4776,7 +4798,22 @@ declare namespace ts { * that they appear in the source code. The language service depends on this property to locate nodes by position. */ export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined; - export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; + export interface CreateSourceFileOptions { + languageVersion: ScriptTarget; + /** + * Controls the format the file is detected as - this can be derived from only the path + * and files on disk, but needs to be done with a module resolution cache in scope to be performant. + * This is usually `undefined` for compilations that do not have `moduleResolution` values of `node12` or `nodenext`. + */ + impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS; + /** + * Controls how module-y-ness is set for the given file. Usually the result of calling + * `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default + * check specified by `isFileProbablyExternalModule` will be used to set the field. + */ + setExternalModuleIndicator?: (file: SourceFile) => void; + } + export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined; /** * Parse json text into SyntaxTree and return node and parse errors if any @@ -5676,7 +5713,7 @@ declare namespace ts { set(response: CompletionInfo): void; clear(): void; } - interface LanguageServiceHost extends GetEffectiveTypeRootsHost { + interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -5694,9 +5731,9 @@ declare namespace ts { error?(s: string): void; useCaseSensitiveFileNames?(): boolean; readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; - readFile?(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + readFile(path: string, encoding?: string): string | undefined; + fileExists(path: string): boolean; getTypeRootsVersion?(): number; resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; @@ -6748,30 +6785,36 @@ declare namespace ts { * the SourceFile if was not found in the registry. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. Only used if the file was not found * in the registry and a new one was created. * @param version Current version of the file. Only used if the file was not found * in the registry and a new one was created. */ - acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + acquireDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + acquireDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; /** * Request an updated version of an already existing SourceFile with a given fileName * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile * to get an updated SourceFile. * * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the + * @param compilationSettingsOrHost Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. + * multiple copies of the same file for different compilation settings. A minimal + * resolution cache is needed to fully define a source file's shape when + * the compilation settings include `module: node12`+, so providing a cache host + * object should be preferred. A common host is a language service `ConfiguredProject`. * @param scriptSnapshot Text of the file. * @param version Current version of the file. */ - updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + updateDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; + updateDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey; /** * Informs the DocumentRegistry that a file is not needed any longer. @@ -6833,7 +6876,7 @@ declare namespace ts { function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string; function getDefaultCompilerOptions(): CompilerOptions; function getSupportedCodeFixes(): string[]; - function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile; function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnlyOrLanguageServiceMode?: boolean | LanguageServiceMode): LanguageService; /** diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).js new file mode 100644 index 0000000000000..758128360f884 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).js @@ -0,0 +1,46 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.jsx] +"use strict"; +exports.__esModule = true; +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return
+ {/* missing */} + {null /* preserved */} + { + // ??? 1 + } + {// ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */ } +
; + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).types new file mode 100644 index 0000000000000..113455cf53d6c --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: error +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).js new file mode 100644 index 0000000000000..f68279f3f58e7 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).js @@ -0,0 +1,44 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.jsx] +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return
+ {/* missing */} + {null /* preserved */} + { + // ??? 1 + } + {// ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */ } +
; + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).types new file mode 100644 index 0000000000000..113455cf53d6c --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: error +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).js new file mode 100644 index 0000000000000..ea4ff413244f4 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).js @@ -0,0 +1,54 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.jsx] +System.register([], function (exports_1, context_1) { + "use strict"; + var Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return
+ {/* missing */} + {null /* preserved */} + { + // ??? 1 + } + {// ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */ } +
; + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).types new file mode 100644 index 0000000000000..113455cf53d6c --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: error +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).js new file mode 100644 index 0000000000000..f68279f3f58e7 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).js @@ -0,0 +1,44 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.jsx] +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return
+ {/* missing */} + {null /* preserved */} + { + // ??? 1 + } + {// ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */ } +
; + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).types new file mode 100644 index 0000000000000..113455cf53d6c --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: error +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).js new file mode 100644 index 0000000000000..f271b199ed61d --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).js @@ -0,0 +1,33 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +"use strict"; +exports.__esModule = true; +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return React.createElement("div", null, null /* preserved */); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).symbols similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).symbols rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).symbols diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..388601f8ae848 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,17): error TS2304: Cannot find name 'React'. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).errors.txt new file mode 100644 index 0000000000000..388601f8ae848 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,17): error TS2304: Cannot find name 'React'. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).js new file mode 100644 index 0000000000000..5cc6523cd071d --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).js @@ -0,0 +1,31 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return React.createElement("div", null, null /* preserved */); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).errors.txt new file mode 100644 index 0000000000000..388601f8ae848 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,17): error TS2304: Cannot find name 'React'. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).js new file mode 100644 index 0000000000000..ca668d2af987f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).js @@ -0,0 +1,41 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return React.createElement("div", null, null /* preserved */); + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..388601f8ae848 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,17): error TS2304: Cannot find name 'React'. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).js new file mode 100644 index 0000000000000..5cc6523cd071d --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).js @@ -0,0 +1,31 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return React.createElement("div", null, null /* preserved */); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).types similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).types rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).types diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).js new file mode 100644 index 0000000000000..f7712f000b8e4 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).js @@ -0,0 +1,34 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +"use strict"; +exports.__esModule = true; +var jsx_runtime_1 = require("react/jsx-runtime"); +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return (0, jsx_runtime_1.jsx)("div", { children: null /* preserved */ }); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).errors.txt new file mode 100644 index 0000000000000..0f9a371c783da --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).js new file mode 100644 index 0000000000000..f7712f000b8e4 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).js @@ -0,0 +1,34 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +"use strict"; +exports.__esModule = true; +var jsx_runtime_1 = require("react/jsx-runtime"); +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return (0, jsx_runtime_1.jsx)("div", { children: null /* preserved */ }); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..0f9a371c783da --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).js new file mode 100644 index 0000000000000..223fb4a66ba4e --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).js @@ -0,0 +1,45 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +System.register(["react/jsx-runtime"], function (exports_1, context_1) { + "use strict"; + var jsx_runtime_1, Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (jsx_runtime_1_1) { + jsx_runtime_1 = jsx_runtime_1_1; + } + ], + execute: function () { + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return _jsx("div", { children: null /* preserved */ }); + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).errors.txt new file mode 100644 index 0000000000000..610a0fa29c506 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).js new file mode 100644 index 0000000000000..223fb4a66ba4e --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).js @@ -0,0 +1,45 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +System.register(["react/jsx-runtime"], function (exports_1, context_1) { + "use strict"; + var jsx_runtime_1, Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (jsx_runtime_1_1) { + jsx_runtime_1 = jsx_runtime_1_1; + } + ], + execute: function () { + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return _jsx("div", { children: null /* preserved */ }); + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..610a0fa29c506 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js new file mode 100644 index 0000000000000..810347d948d57 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js @@ -0,0 +1,35 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +"use strict"; +exports.__esModule = true; +var jsx_dev_runtime_1 = require("react/jsx-dev-runtime"); +var _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx"; +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return (0, jsx_dev_runtime_1.jsxDEV)("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).errors.txt new file mode 100644 index 0000000000000..7ecc135630b91 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js new file mode 100644 index 0000000000000..810347d948d57 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js @@ -0,0 +1,35 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +"use strict"; +exports.__esModule = true; +var jsx_dev_runtime_1 = require("react/jsx-dev-runtime"); +var _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx"; +var Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return (0, jsx_dev_runtime_1.jsxDEV)("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this); + }; + return Component; +}()); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..7ecc135630b91 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations. + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'react/jsx-dev-runtime' or its corresponding type declarations. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).errors.txt similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).errors.txt rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).errors.txt diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js new file mode 100644 index 0000000000000..dd74fc86a3c63 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js @@ -0,0 +1,46 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +System.register(["react/jsx-dev-runtime"], function (exports_1, context_1) { + "use strict"; + var jsx_dev_runtime_1, _jsxFileName, Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (jsx_dev_runtime_1_1) { + jsx_dev_runtime_1 = jsx_dev_runtime_1_1; + } + ], + execute: function () { + _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx"; + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return _jsxDEV("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this); + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).errors.txt new file mode 100644 index 0000000000000..072fbae9425eb --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js new file mode 100644 index 0000000000000..dd74fc86a3c63 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js @@ -0,0 +1,46 @@ +//// [commentsOnJSXExpressionsArePreserved.tsx] +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { + render() { + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} + +//// [commentsOnJSXExpressionsArePreserved.js] +System.register(["react/jsx-dev-runtime"], function (exports_1, context_1) { + "use strict"; + var jsx_dev_runtime_1, _jsxFileName, Component; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (jsx_dev_runtime_1_1) { + jsx_dev_runtime_1 = jsx_dev_runtime_1_1; + } + ], + execute: function () { + _jsxFileName = "tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx"; + Component = /** @class */ (function () { + function Component() { + } + Component.prototype.render = function () { + return _jsxDEV("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this); + }; + return Component; + }()); + } + }; +}); diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).errors.txt b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).errors.txt new file mode 100644 index 0000000000000..072fbae9425eb --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + + +==== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx (1 errors) ==== + // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs + namespace JSX {} + class Component { + render() { + return
+ ~~~~~ + {/* missing */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + {null/* preserved */} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 1 + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { // ??? 2 + ~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + {// ??? 3 + ~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + { + ~~~~~~~~~~~~~ + // ??? 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ + /* ??? 5 */} + ~~~~~~~~~~~~~~~~~~~~~~~~ +
; + ~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + } + } \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).js b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).js similarity index 100% rename from tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).js rename to tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).js diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).symbols b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).symbols new file mode 100644 index 0000000000000..95b7eeda0623f --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +>JSX : Symbol(JSX, Decl(commentsOnJSXExpressionsArePreserved.tsx, 0, 0)) + +class Component { +>Component : Symbol(Component, Decl(commentsOnJSXExpressionsArePreserved.tsx, 1, 16)) + + render() { +>render : Symbol(Component.render, Decl(commentsOnJSXExpressionsArePreserved.tsx, 2, 17)) + + return
+ {/* missing */} + {null/* preserved */} + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; + } +} diff --git a/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).types b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).types new file mode 100644 index 0000000000000..5acb76daa70c1 --- /dev/null +++ b/tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx === +// file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs +namespace JSX {} +class Component { +>Component : Component + + render() { +>render : () => any + + return
+>
{/* missing */} {null/* preserved */} { // ??? 1 } { // ??? 2 } {// ??? 3 } { // ??? 4 /* ??? 5 */}
: any +>div : any + + {/* missing */} + {null/* preserved */} +>null : null + { + // ??? 1 + } + { // ??? 2 + } + {// ??? 3 + } + { + // ??? 4 + /* ??? 5 */} +
; +>div : any + } +} diff --git a/tests/baselines/reference/moduleResolutionWithoutExtension5.js b/tests/baselines/reference/moduleResolutionWithoutExtension5.js index b79c4d0d548b0..8c2854da5f948 100644 --- a/tests/baselines/reference/moduleResolutionWithoutExtension5.js +++ b/tests/baselines/reference/moduleResolutionWithoutExtension5.js @@ -5,3 +5,4 @@ import("./foo").then(x => x); // should error, ask for extension //// [buzz.mjs] // Extensionless relative path dynamic import in an ES module import("./foo").then(x => x); // should error, ask for extension +export {}; diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleDetection/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleDetection/tsconfig.json new file mode 100644 index 0000000000000..1dfb65063cee2 --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleDetection/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "moduleDetection": "auto" + } +} diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 4bbabc7934aa7..e477a6d2d0fde 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index c7bdea6202652..79809e53b7f92 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 93bc4899b98f5..ec639ce04b553 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index f9da788b908d1..0870344d037ba 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index 17874b6315fef..eb7b0a8f38d5c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 8008a065b8eb4..8ebd3a89cb7cc 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 4bbabc7934aa7..e477a6d2d0fde 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 32e837555de6f..89fa7a41f9806 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 0d6d23dccbcc6..0d26d725aab75 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -22,6 +22,7 @@ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js index db8709deef51c..6726890d7f245 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js index 1a96cb834589d..4eb220350264a 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js index 2b40916780b0f..bb93a691e9717 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js index a460f97095fa7..bcfb9f12b5a10 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js index ed2364fbe4727..c123aec942b83 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js index daa4a50372c8d..346ddcce15a8d 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js @@ -43,6 +43,7 @@ interface Array { length: number; [n: number]: T; } // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "amd", /* Specify what module code is generated. */ diff --git a/tests/baselines/reference/tsxReactEmit8(jsx=react-jsx).js b/tests/baselines/reference/tsxReactEmit8(jsx=react-jsx).js index 4b2ad79559d76..7c5e74e00ee51 100644 --- a/tests/baselines/reference/tsxReactEmit8(jsx=react-jsx).js +++ b/tests/baselines/reference/tsxReactEmit8(jsx=react-jsx).js @@ -6,6 +6,7 @@ //// [tsxReactEmit8.js] +import { jsx as _jsx } from "react/jsx-runtime"; /// _jsx("div", { children: "1" }); _jsx("div", { children: "2" }, "key-attr"); diff --git a/tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js b/tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js index 898c4d9886243..12ac49d0452b6 100644 --- a/tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js +++ b/tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js @@ -6,6 +6,7 @@ //// [tsxReactEmit8.js] +import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime"; const _jsxFileName = "tests/cases/conformance/jsx/tsxReactEmit8.tsx"; /// _jsxDEV("div", { children: "1" }, void 0, false, { fileName: _jsxFileName, lineNumber: 1, columnNumber: 1 }, this); diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js index 9314082e933a4..dee4ee2ddfc47 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js @@ -33,6 +33,7 @@ let x: TodoListProps; //// [tsxSpreadChildrenInvalidType.js] +import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function Todo(prop) { return _jsx("div", { children: prop.key.toString() + prop.todo }); } diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).symbols b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).symbols index 5e41936f306e1..c3be731e55e8c 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).symbols +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).symbols @@ -38,7 +38,6 @@ function Todo(prop: { key: number, todo: string }) { >todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) return
{prop.key.toString() + prop.todo}
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) >prop.key.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) >prop.key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 21)) >prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14)) @@ -47,7 +46,6 @@ function Todo(prop: { key: number, todo: string }) { >prop.todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) >prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14)) >todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } function TodoList({ todos }: TodoListProps) { >TodoList : Symbol(TodoList, Decl(tsxSpreadChildrenInvalidType.tsx, 17, 1)) @@ -55,8 +53,6 @@ function TodoList({ todos }: TodoListProps) { >TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1)) return
->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) - {...} >Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1)) >key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 20, 17)) @@ -69,7 +65,6 @@ function TodoList({ todos }: TodoListProps) { >todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } function TodoListNoError({ todos }: TodoListProps) { >TodoListNoError : Symbol(TodoListNoError, Decl(tsxSpreadChildrenInvalidType.tsx, 22, 1)) @@ -78,8 +73,6 @@ function TodoListNoError({ todos }: TodoListProps) { // any is not checked return
->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) - {...( as any)} >Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1)) >key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 26, 18)) @@ -92,7 +85,6 @@ function TodoListNoError({ todos }: TodoListProps) { >todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } let x: TodoListProps; >x : Symbol(x, Decl(tsxSpreadChildrenInvalidType.tsx, 29, 3)) diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).types b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).types index b8eb048703703..542fa2c7fca11 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).types +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).types @@ -21,13 +21,13 @@ interface TodoListProps { >todos : TodoProp[] } function Todo(prop: { key: number, todo: string }) { ->Todo : (prop: { key: number; todo: string;}) => JSX.Element +>Todo : (prop: { key: number; todo: string;}) => any >prop : { key: number; todo: string; } >key : number >todo : string return
{prop.key.toString() + prop.todo}
; ->
{prop.key.toString() + prop.todo}
: JSX.Element +>
{prop.key.toString() + prop.todo}
: any >div : any >prop.key.toString() + prop.todo : string >prop.key.toString() : string @@ -42,16 +42,16 @@ function Todo(prop: { key: number, todo: string }) { >div : any } function TodoList({ todos }: TodoListProps) { ->TodoList : ({ todos }: TodoListProps) => JSX.Element +>TodoList : ({ todos }: TodoListProps) => any >todos : TodoProp[] return
->
{...}
: JSX.Element +>
{...}
: any >div : any {...} -> : JSX.Element ->Todo : (prop: { key: number; todo: string; }) => JSX.Element +> : any +>Todo : (prop: { key: number; todo: string; }) => any >key : number >todos[0].id : number >todos[0] : TodoProp @@ -69,19 +69,19 @@ function TodoList({ todos }: TodoListProps) { >div : any } function TodoListNoError({ todos }: TodoListProps) { ->TodoListNoError : ({ todos }: TodoListProps) => JSX.Element +>TodoListNoError : ({ todos }: TodoListProps) => any >todos : TodoProp[] // any is not checked return
->
{...( as any)}
: JSX.Element +>
{...( as any)}
: any >div : any {...( as any)} >( as any) : any > as any : any -> : JSX.Element ->Todo : (prop: { key: number; todo: string; }) => JSX.Element +> : any +>Todo : (prop: { key: number; todo: string; }) => any >key : number >todos[0].id : number >todos[0] : TodoProp @@ -102,7 +102,7 @@ let x: TodoListProps; >x : TodoListProps -> : JSX.Element ->TodoList : ({ todos }: TodoListProps) => JSX.Element +> : any +>TodoList : ({ todos }: TodoListProps) => any >x : TodoListProps diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).js b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).js index bf484ee6c15b1..8ebd589281c10 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).js +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).js @@ -33,6 +33,7 @@ let x: TodoListProps; //// [tsxSpreadChildrenInvalidType.js] +"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { @@ -53,17 +54,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { } return to.concat(ar || Array.prototype.slice.call(from)); }; +Object.defineProperty(exports, "__esModule", { value: true }); +var jsx_runtime_1 = require("react/jsx-runtime"); function Todo(prop) { - return (0, _a.jsx)("div", { children: prop.key.toString() + prop.todo }); + return (0, jsx_runtime_1.jsx)("div", { children: prop.key.toString() + prop.todo }); } function TodoList(_a) { var todos = _a.todos; - return (0, _b.jsxs)("div", { children: __spreadArray([], (0, _a.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }); + return (0, jsx_runtime_1.jsxs)("div", { children: __spreadArray([], (0, jsx_runtime_1.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }); } function TodoListNoError(_a) { var todos = _a.todos; // any is not checked - return (0, _b.jsxs)("div", { children: __spreadArray([], (0, _a.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }); + return (0, jsx_runtime_1.jsxs)("div", { children: __spreadArray([], (0, jsx_runtime_1.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }); } var x; -(0, _a.jsx)(TodoList, __assign({}, x)); +(0, jsx_runtime_1.jsx)(TodoList, __assign({}, x)); diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).symbols b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).symbols index 5e41936f306e1..c3be731e55e8c 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).symbols +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).symbols @@ -38,7 +38,6 @@ function Todo(prop: { key: number, todo: string }) { >todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) return
{prop.key.toString() + prop.todo}
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) >prop.key.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) >prop.key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 21)) >prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14)) @@ -47,7 +46,6 @@ function Todo(prop: { key: number, todo: string }) { >prop.todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) >prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14)) >todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34)) ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } function TodoList({ todos }: TodoListProps) { >TodoList : Symbol(TodoList, Decl(tsxSpreadChildrenInvalidType.tsx, 17, 1)) @@ -55,8 +53,6 @@ function TodoList({ todos }: TodoListProps) { >TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1)) return
->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) - {...} >Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1)) >key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 20, 17)) @@ -69,7 +65,6 @@ function TodoList({ todos }: TodoListProps) { >todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } function TodoListNoError({ todos }: TodoListProps) { >TodoListNoError : Symbol(TodoListNoError, Decl(tsxSpreadChildrenInvalidType.tsx, 22, 1)) @@ -78,8 +73,6 @@ function TodoListNoError({ todos }: TodoListProps) { // any is not checked return
->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) - {...( as any)} >Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1)) >key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 26, 18)) @@ -92,7 +85,6 @@ function TodoListNoError({ todos }: TodoListProps) { >todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
; ->div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22)) } let x: TodoListProps; >x : Symbol(x, Decl(tsxSpreadChildrenInvalidType.tsx, 29, 3)) diff --git a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).types b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).types index b8eb048703703..542fa2c7fca11 100644 --- a/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).types +++ b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es5).types @@ -21,13 +21,13 @@ interface TodoListProps { >todos : TodoProp[] } function Todo(prop: { key: number, todo: string }) { ->Todo : (prop: { key: number; todo: string;}) => JSX.Element +>Todo : (prop: { key: number; todo: string;}) => any >prop : { key: number; todo: string; } >key : number >todo : string return
{prop.key.toString() + prop.todo}
; ->
{prop.key.toString() + prop.todo}
: JSX.Element +>
{prop.key.toString() + prop.todo}
: any >div : any >prop.key.toString() + prop.todo : string >prop.key.toString() : string @@ -42,16 +42,16 @@ function Todo(prop: { key: number, todo: string }) { >div : any } function TodoList({ todos }: TodoListProps) { ->TodoList : ({ todos }: TodoListProps) => JSX.Element +>TodoList : ({ todos }: TodoListProps) => any >todos : TodoProp[] return
->
{...}
: JSX.Element +>
{...}
: any >div : any {...} -> : JSX.Element ->Todo : (prop: { key: number; todo: string; }) => JSX.Element +> : any +>Todo : (prop: { key: number; todo: string; }) => any >key : number >todos[0].id : number >todos[0] : TodoProp @@ -69,19 +69,19 @@ function TodoList({ todos }: TodoListProps) { >div : any } function TodoListNoError({ todos }: TodoListProps) { ->TodoListNoError : ({ todos }: TodoListProps) => JSX.Element +>TodoListNoError : ({ todos }: TodoListProps) => any >todos : TodoProp[] // any is not checked return
->
{...( as any)}
: JSX.Element +>
{...( as any)}
: any >div : any {...( as any)} >( as any) : any > as any : any -> : JSX.Element ->Todo : (prop: { key: number; todo: string; }) => JSX.Element +> : any +>Todo : (prop: { key: number; todo: string; }) => any >key : number >todos[0].id : number >todos[0] : TodoProp @@ -102,7 +102,7 @@ let x: TodoListProps; >x : TodoListProps -> : JSX.Element ->TodoList : ({ todos }: TodoListProps) => JSX.Element +> : any +>TodoList : ({ todos }: TodoListProps) => any >x : TodoListProps diff --git a/tests/cases/compiler/APISample_watcher.ts b/tests/cases/compiler/APISample_watcher.ts index 8b46979e09288..dfae23488c6e3 100644 --- a/tests/cases/compiler/APISample_watcher.ts +++ b/tests/cases/compiler/APISample_watcher.ts @@ -51,6 +51,8 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) { getCurrentDirectory: () => process.cwd(), getCompilationSettings: () => options, getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), + fileExists: fileName => fs.existsSync(fileName), + readFile: fileName => fs.readFileSync(fileName), }; // Create the language service files diff --git a/tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx b/tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx index 64e3f2b77f658..6830cf4fdcb54 100644 --- a/tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx +++ b/tests/cases/compiler/commentsOnJSXExpressionsArePreserved.tsx @@ -1,5 +1,6 @@ // @module: system,commonjs // @jsx: react,react-jsx,react-jsxdev,preserve +// @moduleDetection: legacy,auto,force // file is intentionally not a module - this tests for a crash in the module/system transforms alongside the `react-jsx` and `react-jsxdev` outputs namespace JSX {} class Component {