Add new option "noUncheckedSideEffectImports" (#58941)

This commit is contained in:
Jake Bailey 2024-07-19 17:35:02 -07:00 коммит произвёл GitHub
Родитель 79bd844d9b
Коммит 85d6bb6fe6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
78 изменённых файлов: 985 добавлений и 1 удалений

Просмотреть файл

@ -720,6 +720,7 @@ import {
isSetAccessorDeclaration,
isShorthandAmbientModuleSymbol,
isShorthandPropertyAssignment,
isSideEffectImport,
isSingleOrDoubleQuote,
isSourceFile,
isSourceFileJS,
@ -1505,6 +1506,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
var useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
var noUncheckedSideEffectImports = !!compilerOptions.noUncheckedSideEffectImports;
var checkBinaryExpression = createCheckBinaryExpression();
var emitResolver = createResolver();
@ -4660,7 +4662,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// merged symbol is module declaration symbol combined with all augmentations
return getMergedSymbol(sourceFile.symbol);
}
if (errorNode && moduleNotFoundError) {
if (errorNode && moduleNotFoundError && !isSideEffectImport(errorNode)) {
// report errors only if it was requested
error(errorNode, Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
}
@ -4765,6 +4767,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, sourceFile: SourceFile, mode: ResolutionMode, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void {
if (isSideEffectImport(errorNode)) {
return;
}
let errorInfo: DiagnosticMessageChain | undefined;
if (!isExternalModuleNameRelative(moduleReference) && packageId) {
errorInfo = createModuleNotFoundChain(sourceFile, host, moduleReference, mode, packageId.name);
@ -47246,6 +47252,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
}
else if (noUncheckedSideEffectImports && !importClause) {
void resolveExternalModuleName(node, node.moduleSpecifier);
}
}
checkImportAttributes(node);
}

Просмотреть файл

@ -1202,6 +1202,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
category: Diagnostics.Modules,
description: Diagnostics.Conditions_to_set_in_addition_to_the_resolver_specific_defaults_when_resolving_imports,
},
{
name: "noUncheckedSideEffectImports",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
category: Diagnostics.Modules,
description: Diagnostics.Check_side_effect_imports,
defaultValueDescription: false,
},
// Source Maps
{

Просмотреть файл

@ -6388,6 +6388,10 @@
"category": "Message",
"code": 6805
},
"Check side effect imports.": {
"category": "Message",
"code": 6806
},
"one of:": {
"category": "Message",

Просмотреть файл

@ -7418,6 +7418,7 @@ export interface CompilerOptions {
target?: ScriptTarget;
traceResolution?: boolean;
useUnknownInCatchVariables?: boolean;
noUncheckedSideEffectImports?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to compute primary types search locations */

Просмотреть файл

@ -287,6 +287,7 @@ import {
isIdentifier,
isIdentifierStart,
isIdentifierText,
isImportDeclaration,
isImportTypeNode,
isInterfaceDeclaration,
isJSDoc,
@ -11758,3 +11759,9 @@ export function hasInferredType(node: Node): node is HasInferredType {
return false;
}
}
/** @internal */
export function isSideEffectImport(node: Node): boolean {
const ancestor = findAncestor(node, isImportDeclaration);
return !!ancestor && !ancestor.importClause;
}

Просмотреть файл

@ -2245,4 +2245,40 @@ import { x } from "../b";`,
},
],
});
verifyTscWatch({
scenario,
subScenario: "when changing noUncheckedSideEffectImports of config file",
commandLineArgs: ["-w", "-p", ".", "--extendedDiagnostics"],
sys: () => {
const module1: File = {
path: `/user/username/projects/myproject/a.ts`,
content: `import "does-not-exist";`,
};
const config: File = {
path: `/user/username/projects/myproject/tsconfig.json`,
content: jsonToReadableText({
compilerOptions: {
noUncheckedSideEffectImports: false,
},
}),
};
return createWatchedSystem([module1, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
},
edits: [
{
caption: "Change noUncheckedSideEffectImports to true",
edit: sys =>
sys.writeFile(
`/user/username/projects/myproject/tsconfig.json`,
jsonToReadableText({
compilerOptions: {
noUncheckedSideEffectImports: true,
},
}),
),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
});
});

Просмотреть файл

@ -7017,6 +7017,7 @@ declare namespace ts {
target?: ScriptTarget;
traceResolution?: boolean;
useUnknownInCatchVariables?: boolean;
noUncheckedSideEffectImports?: boolean;
resolveJsonModule?: boolean;
types?: string[];
/** Paths used to compute primary types search locations */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -39,6 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Просмотреть файл

@ -0,0 +1,5 @@
{
"compilerOptions": {
"noUncheckedSideEffectImports": true
}
}

Просмотреть файл

@ -0,0 +1,14 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("does-not-exist");
require("./does-not-exist-either");
require("./does-not-exist-either.js");

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,16 @@
sideEffectImports1.ts(1,8): error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
sideEffectImports1.ts(2,8): error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
sideEffectImports1.ts(3,8): error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
==== sideEffectImports1.ts (3 errors) ====
import "does-not-exist";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
import "./does-not-exist-either";
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
import "./does-not-exist-either.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.

Просмотреть файл

@ -0,0 +1,14 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("does-not-exist");
require("./does-not-exist-either");
require("./does-not-exist-either.js");

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,14 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("does-not-exist");
require("./does-not-exist-either");
require("./does-not-exist-either.js");

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,16 @@
sideEffectImports1.ts(1,8): error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
sideEffectImports1.ts(2,8): error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
sideEffectImports1.ts(3,8): error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
==== sideEffectImports1.ts (3 errors) ====
import "does-not-exist";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
import "./does-not-exist-either";
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
import "./does-not-exist-either.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.

Просмотреть файл

@ -0,0 +1,14 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("does-not-exist");
require("./does-not-exist-either");
require("./does-not-exist-either.js");

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,16 @@
sideEffectImports1.ts(1,8): error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
sideEffectImports1.ts(2,8): error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
sideEffectImports1.ts(3,8): error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
==== sideEffectImports1.ts (3 errors) ====
import "does-not-exist";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
import "./does-not-exist-either";
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
import "./does-not-exist-either.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
//// [sideEffectImports1.ts]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";
//// [sideEffectImports1.js]
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,8 @@
//// [tests/cases/compiler/sideEffectImports1.ts] ////
=== sideEffectImports1.ts ===
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports2.ts] ////
=== index.ts ===
import "source-map-support/register";

Просмотреть файл

@ -0,0 +1,15 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,15 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,17 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,17 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,15 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,15 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
//// [index.ts]
import "./not-a-module";
//// [not-a-module.ts]
console.log("Hello, world!");
//// [not-a-module.js]
console.log("Hello, world!");
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./not-a-module");

Просмотреть файл

@ -0,0 +1,12 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -0,0 +1,19 @@
//// [tests/cases/compiler/sideEffectImports3.ts] ////
=== index.ts ===
import "./not-a-module";
=== not-a-module.ts ===
console.log("Hello, world!");
>console.log("Hello, world!") : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>"Hello, world!" : "Hello, world!"
> : ^^^^^^^^^^^^^^^

Просмотреть файл

@ -0,0 +1,33 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
//// [package.json]
{
"name": "server-only",
"version": "0.0.1",
"main": "index.js",
"exports": {
".": {
"react-server": "./empty.js",
"default": "./index.js"
}
}
}
//// [index.js]
throw new Error();
//// [empty.js]
// Empty
//// [package.json]
{
"name": "root",
"type": "module"
}
//// [index.ts]
import "server-only";
//// [index.js]
import "server-only";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
=== index.ts ===
import "server-only";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
=== index.ts ===
import "server-only";

Просмотреть файл

@ -0,0 +1,33 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
//// [package.json]
{
"name": "server-only",
"version": "0.0.1",
"main": "index.js",
"exports": {
".": {
"react-server": "./empty.js",
"default": "./index.js"
}
}
}
//// [index.js]
throw new Error();
//// [empty.js]
// Empty
//// [package.json]
{
"name": "root",
"type": "module"
}
//// [index.ts]
import "server-only";
//// [index.js]
import "server-only";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
=== index.ts ===
import "server-only";

Просмотреть файл

@ -0,0 +1,6 @@
//// [tests/cases/compiler/sideEffectImports4.ts] ////
=== index.ts ===
import "server-only";

Просмотреть файл

@ -0,0 +1,172 @@
currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false
Input::
//// [/user/username/projects/myproject/a.ts]
import "does-not-exist";
//// [/user/username/projects/myproject/tsconfig.json]
{
"compilerOptions": {
"noUncheckedSideEffectImports": false
}
}
//// [/a/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
/a/lib/tsc.js -w -p . --extendedDiagnostics
Output::
[HH:MM:SS AM] Starting compilation in watch mode...
Current directory: /user/username/projects/myproject CaseSensitiveFileNames: false
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file
Synchronizing program
CreatingProgramWith::
roots: ["/user/username/projects/myproject/a.ts"]
options: {"noUncheckedSideEffectImports":false,"watch":true,"project":"/user/username/projects/myproject","extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/a.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 undefined Source file
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined Failed Lookup Locations
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined Failed Lookup Locations
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules 1 undefined Failed Lookup Locations
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules 1 undefined Failed Lookup Locations
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots
[HH:MM:SS AM] Found 0 errors. Watching for file changes.
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory
//// [/user/username/projects/myproject/a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("does-not-exist");
PolledWatches::
/user/username/projects/myproject/node_modules: *new*
{"pollingInterval":500}
/user/username/projects/myproject/node_modules/@types: *new*
{"pollingInterval":500}
/user/username/projects/node_modules: *new*
{"pollingInterval":500}
/user/username/projects/node_modules/@types: *new*
{"pollingInterval":500}
FsWatches::
/a/lib/lib.d.ts: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/tsconfig.json: *new*
{}
FsWatchesRecursive::
/user/username/projects/myproject: *new*
{}
Program root files: [
"/user/username/projects/myproject/a.ts"
]
Program options: {
"noUncheckedSideEffectImports": false,
"watch": true,
"project": "/user/username/projects/myproject",
"extendedDiagnostics": true,
"configFilePath": "/user/username/projects/myproject/tsconfig.json"
}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
Shape signatures in builder refreshed for::
/a/lib/lib.d.ts (used version)
/user/username/projects/myproject/a.ts (used version)
exitCode:: ExitStatus.undefined
Change:: Change noUncheckedSideEffectImports to true
Input::
//// [/user/username/projects/myproject/tsconfig.json]
{
"compilerOptions": {
"noUncheckedSideEffectImports": true
}
}
Output::
FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file
Scheduling update
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file
Timeout callback:: count: 1
1: timerToUpdateProgram *new*
Before running Timeout callback:: count: 1
1: timerToUpdateProgram
Host is moving to new time
After running Timeout callback:: count: 0
Output::
Reloading config file: /user/username/projects/myproject/tsconfig.json
Synchronizing program
[HH:MM:SS AM] File change detected. Starting incremental compilation...
CreatingProgramWith::
roots: ["/user/username/projects/myproject/a.ts"]
options: {"noUncheckedSideEffectImports":true,"watch":true,"project":"/user/username/projects/myproject","extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
a.ts:1:8 - error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
1 import "does-not-exist";
   ~~~~~~~~~~~~~~~~
[HH:MM:SS AM] Found 1 error. Watching for file changes.
Program root files: [
"/user/username/projects/myproject/a.ts"
]
Program options: {
"noUncheckedSideEffectImports": true,
"watch": true,
"project": "/user/username/projects/myproject",
"extendedDiagnostics": true,
"configFilePath": "/user/username/projects/myproject/tsconfig.json"
}
Program structureReused: Completely
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
No shapes updated in the builder::
exitCode:: ExitStatus.undefined

Просмотреть файл

@ -0,0 +1,6 @@
// @noUncheckedSideEffectImports: true,false
// @module: commonjs,nodenext,preserve
import "does-not-exist";
import "./does-not-exist-either";
import "./does-not-exist-either.js";

Просмотреть файл

@ -0,0 +1,17 @@
// @noUncheckedSideEffectImports: true,false
// @module: nodenext
// @noImplicitAny: true,false
// @noEmit: true
// @filename: tsconfig.json
{
"include": ["index.ts"],
}
// @filename: index.ts
import "source-map-support/register";
// @filename: node_modules/source-map-support/register.js
module.exports = {};

Просмотреть файл

@ -0,0 +1,9 @@
// @noUncheckedSideEffectImports: true,false
// @module: nodenext
// @moduleDetection: legacy,auto,force
// @filename: index.ts
import "./not-a-module";
// @filename: not-a-module.ts
console.log("Hello, world!");

Просмотреть файл

@ -0,0 +1,36 @@
// @noUncheckedSideEffectImports: true,false
// @strict: true
// @noImplicitReferences: true
// @module: esnext
// @moduleResolution: bundler
// @moduleDetection: force
// @allowJs: true
// @checkJs: true
// @filename: node_modules/server-only/package.json
{
"name": "server-only",
"version": "0.0.1",
"main": "index.js",
"exports": {
".": {
"react-server": "./empty.js",
"default": "./index.js"
}
}
}
// @filename: node_modules/server-only/index.js
throw new Error();
// @filename: node_modules/server-only/empty.js
// Empty
// @filename: package.json
{
"name": "root",
"type": "module"
}
// @filename: index.ts
import "server-only";

Просмотреть файл

@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @noEmit: true
// @module: commonjs
// @noUncheckedSideEffectImports: true
// @filename: moduleA/a.js
//// import "b";
//// import "c";
// @filename: node_modules/b.ts
//// var a = 10;
// @filename: node_modules/c.js
//// exports.a = 10;
//// c = 10;
verify.getSuggestionDiagnostics([]);