From f073cb67abb0903e25b792146a65773deb10c677 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 14 Jan 2022 11:05:27 -0800 Subject: [PATCH 1/6] Add moduleDetection compiler flag to allow for changing how modules are parsed The default setting is 'auto', where JSX containing files under react-jsx and react-jsxdev are always parsed as modules, and esm-format files under module: node12+ are always parsed as modules, in addition to the 'legacy' detection mode's conditions for other files. (Declaration files are exempt from these new conditions) The 'legacy' mode preserves TS's behavior prior to the introduction of this flag - a file is parsed as a module if it contains an import, export, or import.meta expression. In addition, there is a 'force' mode that forces all non-declaration files to be parsed as modules. (Declaration files are still only modules if they contain a top-level import or export.) This technically breaks the parser API, but it's kinda-sorta backwards compatible so long as you don't need the functionality associated with more recent compiler flags. --- src/compiler/commandLineParser.ts | 12 ++ src/compiler/core.ts | 10 +- src/compiler/diagnosticMessages.json | 8 + src/compiler/parser.ts | 152 +++++++++++------- src/compiler/program.ts | 31 ++-- src/compiler/resolutionCache.ts | 3 +- src/compiler/types.ts | 36 ++++- src/compiler/utilities.ts | 56 +++++++ src/compiler/watch.ts | 4 +- src/compiler/watchPublic.ts | 4 +- src/harness/fourslashImpl.ts | 12 +- src/harness/harnessLanguageService.ts | 18 +++ src/server/project.ts | 5 + src/services/documentRegistry.ts | 54 +++++-- src/services/services.ts | 27 +++- src/services/suggestionDiagnostics.ts | 2 +- src/services/transpile.ts | 31 ++-- src/services/types.ts | 8 +- src/services/utilities.ts | 2 +- src/testRunner/compilerRunner.ts | 1 + .../unittests/services/extract/helpers.ts | 2 + .../unittests/services/hostNewLineSupport.ts | 6 + .../unittests/services/languageService.ts | 4 + .../baselines/reference/APISample_watcher.js | 6 +- .../reference/api/tsserverlibrary.d.ts | 73 +++++++-- tests/baselines/reference/api/typescript.d.ts | 73 +++++++-- ...,module=commonjs,moduledetection=auto).js} | 0 ...le=commonjs,moduledetection=auto).symbols} | 0 ...dule=commonjs,moduledetection=auto).types} | 0 ...,module=commonjs,moduledetection=force).js | 46 ++++++ ...e=commonjs,moduledetection=force).symbols} | 0 ...ule=commonjs,moduledetection=force).types} | 0 ...odule=commonjs,moduledetection=legacy).js} | 0 ...=commonjs,moduledetection=legacy).symbols} | 0 ...ule=commonjs,moduledetection=legacy).types | 30 ++++ ...rve,module=system,moduledetection=auto).js | 44 +++++ ...dule=system,moduledetection=auto).symbols} | 0 ...,module=system,moduledetection=auto).types | 30 ++++ ...ve,module=system,moduledetection=force).js | 54 +++++++ ...ule=system,moduledetection=force).symbols} | 0 ...module=system,moduledetection=force).types | 30 ++++ ...e,module=system,moduledetection=legacy).js | 44 +++++ ...le=system,moduledetection=legacy).symbols} | 0 ...odule=system,moduledetection=legacy).types | 30 ++++ ...commonjs,moduledetection=auto).errors.txt} | 0 ...,module=commonjs,moduledetection=auto).js} | 0 ...le=commonjs,moduledetection=auto).symbols} | 0 ...dule=commonjs,moduledetection=auto).types} | 0 ...ommonjs,moduledetection=force).errors.txt} | 0 ...,module=commonjs,moduledetection=force).js | 33 ++++ ...e=commonjs,moduledetection=force).symbols} | 0 ...ule=commonjs,moduledetection=force).types} | 0 ...ommonjs,moduledetection=legacy).errors.txt | 26 +++ ...odule=commonjs,moduledetection=legacy).js} | 0 ...e=commonjs,moduledetection=legacy).symbols | 27 ++++ ...le=commonjs,moduledetection=legacy).types} | 0 ...le=system,moduledetection=auto).errors.txt | 26 +++ ...act,module=system,moduledetection=auto).js | 31 ++++ ...odule=system,moduledetection=auto).symbols | 27 ++++ ...module=system,moduledetection=auto).types} | 0 ...e=system,moduledetection=force).errors.txt | 26 +++ ...ct,module=system,moduledetection=force).js | 41 +++++ ...dule=system,moduledetection=force).symbols | 27 ++++ ...odule=system,moduledetection=force).types} | 0 ...=system,moduledetection=legacy).errors.txt | 26 +++ ...t,module=system,moduledetection=legacy).js | 31 ++++ ...ule=system,moduledetection=legacy).symbols | 27 ++++ ...dule=system,moduledetection=legacy).types} | 0 ...commonjs,moduledetection=auto).errors.txt} | 0 ...x,module=commonjs,moduledetection=auto).js | 34 ++++ ...ule=commonjs,moduledetection=auto).symbols | 27 ++++ ...odule=commonjs,moduledetection=auto).types | 30 ++++ ...commonjs,moduledetection=force).errors.txt | 39 +++++ ...,module=commonjs,moduledetection=force).js | 34 ++++ ...le=commonjs,moduledetection=force).symbols | 27 ++++ ...dule=commonjs,moduledetection=force).types | 30 ++++ ...ommonjs,moduledetection=legacy).errors.txt | 39 +++++ ...odule=commonjs,moduledetection=legacy).js} | 0 ...e=commonjs,moduledetection=legacy).symbols | 27 ++++ ...ule=commonjs,moduledetection=legacy).types | 30 ++++ ...e=system,moduledetection=auto).errors.txt} | 0 ...jsx,module=system,moduledetection=auto).js | 45 ++++++ ...odule=system,moduledetection=auto).symbols | 27 ++++ ...,module=system,moduledetection=auto).types | 30 ++++ ...e=system,moduledetection=force).errors.txt | 39 +++++ ...sx,module=system,moduledetection=force).js | 45 ++++++ ...dule=system,moduledetection=force).symbols | 27 ++++ ...module=system,moduledetection=force).types | 30 ++++ ...=system,moduledetection=legacy).errors.txt | 39 +++++ ...,module=system,moduledetection=legacy).js} | 0 ...ule=system,moduledetection=legacy).symbols | 27 ++++ ...odule=system,moduledetection=legacy).types | 30 ++++ ...commonjs,moduledetection=auto).errors.txt} | 0 ...v,module=commonjs,moduledetection=auto).js | 35 ++++ ...ule=commonjs,moduledetection=auto).symbols | 27 ++++ ...odule=commonjs,moduledetection=auto).types | 30 ++++ ...commonjs,moduledetection=force).errors.txt | 39 +++++ ...,module=commonjs,moduledetection=force).js | 35 ++++ ...le=commonjs,moduledetection=force).symbols | 27 ++++ ...dule=commonjs,moduledetection=force).types | 30 ++++ ...ommonjs,moduledetection=legacy).errors.txt | 39 +++++ ...odule=commonjs,moduledetection=legacy).js} | 0 ...e=commonjs,moduledetection=legacy).symbols | 27 ++++ ...ule=commonjs,moduledetection=legacy).types | 30 ++++ ...e=system,moduledetection=auto).errors.txt} | 0 ...dev,module=system,moduledetection=auto).js | 46 ++++++ ...odule=system,moduledetection=auto).symbols | 27 ++++ ...,module=system,moduledetection=auto).types | 30 ++++ ...e=system,moduledetection=force).errors.txt | 39 +++++ ...ev,module=system,moduledetection=force).js | 46 ++++++ ...dule=system,moduledetection=force).symbols | 27 ++++ ...module=system,moduledetection=force).types | 30 ++++ ...=system,moduledetection=legacy).errors.txt | 39 +++++ ...,module=system,moduledetection=legacy).js} | 0 ...ule=system,moduledetection=legacy).symbols | 27 ++++ ...odule=system,moduledetection=legacy).types | 30 ++++ .../moduleResolutionWithoutExtension5.js | 1 + .../moduleDetection/tsconfig.json | 5 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../declarationDir-is-specified.js | 1 + ...-outDir-and-declarationDir-is-specified.js | 1 + .../when-outDir-is-specified.js | 1 + .../with-outFile.js | 1 + ...e-is-specified-with-declaration-enabled.js | 1 + .../without-outDir-or-outFile-is-specified.js | 1 + ...nvalidType(jsx=react-jsx,target=es2015).js | 1 + ...dType(jsx=react-jsx,target=es2015).symbols | 8 - ...lidType(jsx=react-jsx,target=es2015).types | 24 +-- ...enInvalidType(jsx=react-jsx,target=es5).js | 11 +- ...alidType(jsx=react-jsx,target=es5).symbols | 8 - ...nvalidType(jsx=react-jsx,target=es5).types | 24 +-- tests/cases/compiler/APISample_watcher.ts | 2 + .../commentsOnJSXExpressionsArePreserved.tsx | 1 + 141 files changed, 2510 insertions(+), 202 deletions(-) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).js => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).js} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).symbols} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs).types => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=auto).types} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).js rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).symbols} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).types => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=force).types} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system).js => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).js} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).symbols} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=commonjs,moduledetection=legacy).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).js rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=system).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).symbols} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=auto).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).js rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).symbols} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=force).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).js rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).symbols => commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).symbols} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=preserve,module=system,moduledetection=legacy).types rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).errors.txt} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).js => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).js} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).symbols => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).symbols} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=auto).types} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=system).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).errors.txt} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).js rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).symbols => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).symbols} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=system).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=force).types} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).errors.txt rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react,module=system).js => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).js} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).symbols rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=commonjs,moduledetection=legacy).types} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).symbols rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=auto).types} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).symbols rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=force).types} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).symbols rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).types => commentsOnJSXExpressionsArePreserved(jsx=react,module=system,moduledetection=legacy).types} (100%) rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).errors.txt} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=auto).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=force).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).errors.txt rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).js => commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).js} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs,moduledetection=legacy).types rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).errors.txt} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=auto).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=force).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).errors.txt rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system).js => commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).js} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=system,moduledetection=legacy).types rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).errors.txt} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).errors.txt rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).js => commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).js} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).types rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).errors.txt => commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).errors.txt} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).errors.txt create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).types create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).errors.txt rename tests/baselines/reference/{commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system).js => commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).js} (100%) create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).symbols create mode 100644 tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).types create mode 100644 tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleDetection/tsconfig.json diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index df9ee17f32d9f..857fbfd28fcc5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1238,6 +1238,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_Assume_jsx_containing_under_react_jsx_or_esm_mode_under_module_Colon_node12_files_are_modules_along_with_files_with_imports_exports_or_import_meta, + } ]; /* @internal */ diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6bc89ae25eae5..7b0de0c586c29 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 778a9304aa75e..cda4a30c933ac 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1409,6 +1409,14 @@ "category": "Error", "code": 1471 }, + "Control what method is used to detect module-format JS files.": { + "category": "Message", + "code": 1472 + }, + "\"auto\": Assume jsx-containing (under react-jsx) or esm mode (under module: node12+) files are modules, along with files with imports, exports, or import.meta.": { + "category": "Message", + "code": 1473 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 420ae33d0b5cd..d500de4148e5c 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 ? + 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"; + } + /** * 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, @@ -638,17 +673,41 @@ 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 = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.languageVersion : languageVersionOrOptions; 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 overrideSetExternalModuleIndicator = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.setExternalModuleIndicator : undefined; + const format = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined; + const setIndicator = format !== undefined ? (file: SourceFile) => (file.impliedNodeFormat = format, void (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file)) : overrideSetExternalModuleIndicator; + result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator); } perfLogger.logStopParseSourceFile(); @@ -847,7 +906,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); @@ -863,7 +922,7 @@ namespace ts { initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind); - const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind); + const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator); clearState(); @@ -951,7 +1010,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); @@ -1035,7 +1094,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; @@ -1050,7 +1109,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); @@ -1209,28 +1268,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) { @@ -7551,41 +7624,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 @@ -7628,7 +7666,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); @@ -8672,7 +8710,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 @@ -8736,7 +8774,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 80115dbd35dab..b122f33225f61 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 { @@ -1636,8 +1636,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; @@ -1672,7 +1672,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) { @@ -2722,6 +2721,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) { @@ -2814,7 +2825,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 ); @@ -2847,10 +2858,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()) { @@ -3438,7 +3445,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)); } @@ -3448,7 +3455,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 e06d81ca4c9aa..49d98c696d536 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 dcea2e7e38526..e49b7bfe6e166 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3609,7 +3609,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 @@ -6005,6 +6011,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; } @@ -6100,6 +6121,7 @@ namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; /*@internal*/noEmitForJsFiles?: boolean; @@ -6564,6 +6586,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. @@ -6666,8 +6696,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 3024b8eba1567..5ca39531f7cad 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6126,6 +6126,58 @@ 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 { + 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 contian 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) => void (file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file)); + case ModuleDetectionKind.Legacy: + // Files are modules if they have imports, exports, or import.meta + return (file: SourceFile) => void (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) || @@ -6160,6 +6212,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 951b16a311893..2992de9b13001 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -525,7 +525,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"); @@ -540,7 +540,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 33220b03d2e43..2548d9cfca680 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -524,7 +524,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)) { @@ -533,7 +533,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 19b82ac6542a0..be153843651f5 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2280,8 +2280,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 22e88498203d1..a8265fcd09d09 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 e6170d086ce81..8a52f464a96c3 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -1674,6 +1674,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 719f219025929..ceb2564c11c43 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 bucket = getOrUpdate(buckets, key, () => new Map()); const bucketEntry = bucket.get(path); let entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind); @@ -219,7 +239,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/services.ts b/src/services/services.ts index c3b2056d09efe..9f912ca03e2db 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1054,7 +1054,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. @@ -1079,8 +1089,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; } @@ -1136,8 +1146,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 = { @@ -1520,7 +1535,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 @@ -1532,7 +1547,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..ce7ab8beaaf71 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,21 @@ 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 bc5e0d86d87fa..0a02133f8a74c 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -238,7 +238,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; @@ -259,11 +259,13 @@ namespace ts { /* * LS host can optionally implement these methods to support completions for module specifiers. * Without these methods, only completions for ambient modules will be provided. + * + * `readFile` and `fileExists` are now _required_ to properly acquire and setup source files under module: node12+ modes. */ readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; - readFile?(path: string, encoding?: string): string | undefined; + readFile(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + 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 a45fd3f441ecf..8f426706d6e84 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2927,7 +2927,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 9e86a96c617f2..c2bfd5f468c67 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 f822907cd1430..93837ef3029c7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2867,6 +2867,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; } @@ -2938,6 +2952,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; @@ -3125,6 +3140,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. @@ -3200,8 +3222,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; @@ -4744,7 +4766,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 @@ -5644,7 +5681,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; @@ -5662,9 +5699,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; + readFile(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + 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; @@ -6724,30 +6761,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. @@ -6809,7 +6852,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 0137fbeb78a75..a7d38de3a4ae8 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2867,6 +2867,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; } @@ -2938,6 +2952,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; @@ -3125,6 +3140,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. @@ -3200,8 +3222,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; @@ -4744,7 +4766,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 @@ -5644,7 +5681,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; @@ -5662,9 +5699,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; + readFile(path: string, encoding?: string): string | undefined; realpath?(path: string): string; - fileExists?(path: string): boolean; + 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; @@ -6724,30 +6761,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. @@ -6809,7 +6852,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..aa1cbf0e8740e --- /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 */ }, void 0); + }; + 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..aa1cbf0e8740e --- /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 */ }, void 0); + }; + 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..6b26a6b4a125e --- /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 */ }, void 0); + }; + 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..6b26a6b4a125e --- /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 */ }, void 0); + }; + 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 56794816baf82..8e6547740bded 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 72a3d537f7adc..551b83164da9c 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 df5bf12f3e9d9..10ac17f9aadab 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 9f8f66fa059c2..8f104b65739ee 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 9fb8f59be48cc..10782384b0f6a 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 5bb5a17baa7f3..7bf1d0d6f9dc0 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 56794816baf82..8e6547740bded 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 9cc8746737d98..6379e87ed106e 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 865e5f44b27f5..6bd0c81255a77 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 620e1d32717b5..93601b26e05b9 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 729c53bff01ef..40529da69e0da 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 818170668e7bf..f8faca7281dfe 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 8ffe44ddab395..9a19df57d9605 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 9850737466e93..acccd635f8a26 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 3e23fb6d13961..fc57795880643 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/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js b/tests/baselines/reference/tsxSpreadChildrenInvalidType(jsx=react-jsx,target=es2015).js index 75ff44138c806..7c507a0a61246 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 }, void 0); } 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 00f8cda36dd54..f67fd79f70c09 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 }, void 0); + return (0, jsx_runtime_1.jsx)("div", { children: prop.key.toString() + prop.todo }, void 0); } 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) }, void 0); + return (0, jsx_runtime_1.jsxs)("div", { children: __spreadArray([], (0, jsx_runtime_1.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }, void 0); } 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) }, void 0); + return (0, jsx_runtime_1.jsxs)("div", { children: __spreadArray([], (0, jsx_runtime_1.jsx)(Todo, { todo: todos[0].todo }, todos[0].id), true) }, void 0); } var x; -(0, _a.jsx)(TodoList, __assign({}, x), void 0); +(0, jsx_runtime_1.jsx)(TodoList, __assign({}, x), void 0); 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 { From 60f709b50897b1cc88db1f8238660b55e3c286ef Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 18 Jan 2022 13:45:10 -0800 Subject: [PATCH 2/6] Fix post-merge lint --- src/services/refactors/moveToNewFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}`; } } From 6215541dcc0333f7a9e9c1eaf88657764dae06a0 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 11 Feb 2022 15:27:46 -0800 Subject: [PATCH 3/6] Rename function --- src/compiler/parser.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 37eb37f1a5f0b..76fd7128b438b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -78,12 +78,12 @@ namespace ts { function getImportMetaIfNecessary(sourceFile: SourceFile) { return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ? - walkTreeForExternalModuleIndicators(sourceFile) : + walkTreeForImportMeta(sourceFile) : undefined; } - function walkTreeForExternalModuleIndicators(node: Node): Node | undefined { - return isImportMeta(node) ? node : forEachChild(node, walkTreeForExternalModuleIndicators); + 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. */ From ccb851ab3101cd5a57663b36f67656ab708cf56c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 9 Mar 2022 10:53:44 -0800 Subject: [PATCH 4/6] Update default value documentation --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b15e6433938a8..d9d95de553e6f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1251,7 +1251,7 @@ namespace ts { affectsModuleResolution: true, description: Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files, category: Diagnostics.Language_and_Environment, - defaultValueDescription: Diagnostics.auto_Colon_Assume_jsx_containing_under_react_jsx_or_esm_mode_under_module_Colon_node12_files_are_modules_along_with_files_with_imports_exports_or_import_meta, + defaultValueDescription: Diagnostics.auto_Colon_Treat_files_with_imports_exports_imporpt_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node12_as_modules, } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ed177857275d2..8dfc600328e05 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1453,7 +1453,7 @@ "category": "Message", "code": 1475 }, - "\"auto\": Assume jsx-containing (under react-jsx) or esm mode (under module: node12+) files are modules, along with files with imports, exports, or import.meta.": { + "\"auto\": Treat files with imports, exports, imporpt.meta, jsx (with jsx: react-jsx), or esm format (with module: node12+) as modules.": { "category": "Message", "code": 1476 }, From f9eb659f4f11e862b373f4782b04462245c3b541 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 9 Mar 2022 11:17:47 -0800 Subject: [PATCH 5/6] PR feedback --- src/compiler/parser.ts | 13 +++++++++---- src/compiler/utilities.ts | 7 ++++--- src/services/transpile.ts | 10 +++++++++- src/services/types.ts | 9 ++++++--- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 3b515ae624d9f..898f50c475eff 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -703,14 +703,19 @@ namespace ts { let result: SourceFile; perfLogger.logStartParseSourceFile(fileName); - const languageVersion = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.languageVersion : languageVersionOrOptions; + 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, noop); } else { - const overrideSetExternalModuleIndicator = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.setExternalModuleIndicator : undefined; - const format = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined; - const setIndicator = format !== undefined ? (file: SourceFile) => (file.impliedNodeFormat = format, void (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file)) : overrideSetExternalModuleIndicator; + 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(); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3856c6b14fa18..93a6dab9c68a3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6211,12 +6211,13 @@ namespace ts { * 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 contian JSX tags!) + // for back compat purposes. (not that declaration files should contain JSX tags!) return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined; } @@ -6235,10 +6236,10 @@ namespace ts { switch (getEmitModuleDetectionKind(options)) { case ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule - return (file: SourceFile) => void (file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file)); + 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) => void (file.externalModuleIndicator = isFileProbablyExternalModule(file)); + 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 diff --git a/src/services/transpile.ts b/src/services/transpile.ts index ce7ab8beaaf71..b2d8951e43b7e 100644 --- a/src/services/transpile.ts +++ b/src/services/transpile.ts @@ -73,7 +73,15 @@ namespace ts { // 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) }); + 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; } diff --git a/src/services/types.ts b/src/services/types.ts index c8fc3d0a3809e..a32fa6599fa22 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -261,12 +261,15 @@ namespace ts { /* * LS host can optionally implement these methods to support completions for module specifiers. * Without these methods, only completions for ambient modules will be provided. - * - * `readFile` and `fileExists` are now _required_ to properly acquire and setup source files under module: node12+ modes. */ 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; + + /* + * 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; /* diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 02c8453f7629b..fcb78f56f6cc0 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5731,8 +5731,8 @@ 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; + 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)[]; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 82cf1199c31ca..e78e7d779b831 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5731,8 +5731,8 @@ 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; + 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)[]; From e5c3dc0650dff55d7b1ac48e030e189fff2ec56c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 9 Mar 2022 12:44:01 -0800 Subject: [PATCH 6/6] Fix lint and typo --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/utilities.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d9d95de553e6f..757ae3bba2501 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1251,7 +1251,7 @@ namespace ts { 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_imporpt_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node12_as_modules, + 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, } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8dfc600328e05..387d7123beb4b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1453,7 +1453,7 @@ "category": "Message", "code": 1475 }, - "\"auto\": Treat files with imports, exports, imporpt.meta, jsx (with jsx: react-jsx), or esm format (with module: node12+) as modules.": { + "\"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 }, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 93a6dab9c68a3..53e8cf0a82c77 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6236,10 +6236,14 @@ namespace ts { 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); }; + 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); }; + 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