Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incremental emit issue where dependency relations implied by synthesized imports would not be detected #41346

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,10 @@ namespace ts {
addEmitFlags(importDecl, EmitFlags.NeverApplyImportHelper);
setParent(externalHelpersModuleReference, importDecl);
setParent(importDecl, file);
// explicitly unset the synthesized flag on these declarations so the checker API will answer questions about them
// (which is required to build the dependency graph for incremental emit)
(externalHelpersModuleReference as Mutable<Node>).flags &= ~NodeFlags.Synthesized;
(importDecl as Mutable<Node>).flags &= ~NodeFlags.Synthesized;
return externalHelpersModuleReference;
}

Expand Down
46 changes: 46 additions & 0 deletions src/testRunner/unittests/tscWatch/incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,51 @@ export const Fragment: unique symbol;
],
modifyFs: host => host.writeFile(configFile.path, JSON.stringify({ compilerOptions: { ...jsxImportSourceOptions, jsxImportSource: "preact" } }))
});

verifyIncrementalWatchEmit({
subScenario: "jsxImportSource backing types added",
files: () => [
{ path: libFile.path, content: libContent },
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) }
],
modifyFs: host => {
host.createDirectory(`${project}/node_modules`);
host.createDirectory(`${project}/node_modules/react`);
host.createDirectory(`${project}/node_modules/react/jsx-runtime`);
host.writeFile(`${project}/node_modules/react/jsx-runtime/index.d.ts`, jsxLibraryContent);
host.writeFile(`${project}/node_modules/react/package.json`, JSON.stringify({ name: "react", version: "0.0.1" }));
}
});

verifyIncrementalWatchEmit({
subScenario: "jsxImportSource backing types removed",
files: () => [
{ path: libFile.path, content: libContent },
{ path: `${project}/node_modules/react/jsx-runtime/index.d.ts`, content: jsxLibraryContent },
{ path: `${project}/node_modules/react/package.json`, content: JSON.stringify({ name: "react", version: "0.0.1" }) },
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) }
],
modifyFs: host => {
host.deleteFile(`${project}/node_modules/react/jsx-runtime/index.d.ts`);
host.deleteFile(`${project}/node_modules/react/package.json`);
}
});

verifyIncrementalWatchEmit({
subScenario: "importHelpers backing types removed",
files: () => [
{ path: libFile.path, content: libContent },
{ path: `${project}/node_modules/tslib/index.d.ts`, content: "export function __assign(...args: any[]): any;" },
{ path: `${project}/node_modules/tslib/package.json`, content: JSON.stringify({ name: "tslib", version: "0.0.1" }) },
{ path: `${project}/index.tsx`, content: `export const x = {...{}};` },
{ path: configFile.path, content: JSON.stringify({ compilerOptions: { importHelpers: true } }) }
],
modifyFs: host => {
host.deleteFile(`${project}/node_modules/tslib/index.d.ts`);
host.deleteFile(`${project}/node_modules/tslib/package.json`);
}
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
Input::
//// [/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; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };

//// [/users/username/projects/project/node_modules/tslib/index.d.ts]
export function __assign(...args: any[]): any;

//// [/users/username/projects/project/node_modules/tslib/package.json]
{"name":"tslib","version":"0.0.1"}

//// [/users/username/projects/project/index.tsx]
export const x = {...{}};

//// [/users/username/projects/project/tsconfig.json]
{"compilerOptions":{"importHelpers":true}}


/a/lib/tsc.js -i
Output::


Program root files: ["/users/username/projects/project/index.tsx"]
Program options: {"importHelpers":true,"incremental":true,"configFilePath":"/users/username/projects/project/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/users/username/projects/project/node_modules/tslib/index.d.ts
/users/username/projects/project/index.tsx

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/users/username/projects/project/node_modules/tslib/index.d.ts
/users/username/projects/project/index.tsx

WatchedFiles::

FsWatches::

FsWatchesRecursive::

exitCode:: ExitStatus.Success

//// [/users/username/projects/project/index.js]
"use strict";
exports.__esModule = true;
exports.x = void 0;
var tslib_1 = require("tslib");
exports.x = tslib_1.__assign({});


//// [/users/username/projects/project/tsconfig.tsbuildinfo]
{
"program": {
"fileInfos": {
"../../../../a/lib/lib.d.ts": {
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true
},
"./node_modules/tslib/index.d.ts": {
"version": "1620578607-export function __assign(...args: any[]): any;",
"signature": "1620578607-export function __assign(...args: any[]): any;",
"affectsGlobalScope": false
},
"./index.tsx": {
"version": "-14168389096-export const x = {...{}};",
"signature": "-6508651827-export declare const x: {};\n",
"affectsGlobalScope": false
}
},
"options": {
"importHelpers": true,
"incremental": true,
"configFilePath": "./tsconfig.json"
},
"referencedMap": {
"./index.tsx": [
"./node_modules/tslib/index.d.ts"
]
},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../../../a/lib/lib.d.ts",
"./index.tsx",
"./node_modules/tslib/index.d.ts"
]
},
"version": "FakeTSVersion"
}


Change::

Input::
//// [/users/username/projects/project/node_modules/tslib/index.d.ts] deleted
//// [/users/username/projects/project/node_modules/tslib/package.json] deleted

Output::
index.tsx:1:19 - error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

1 export const x = {...{}};
   ~~~~~


Found 1 error.



Program root files: ["/users/username/projects/project/index.tsx"]
Program options: {"importHelpers":true,"incremental":true,"configFilePath":"/users/username/projects/project/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/users/username/projects/project/index.tsx

Semantic diagnostics in builder refreshed for::
/users/username/projects/project/index.tsx

WatchedFiles::

FsWatches::

FsWatchesRecursive::

exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated

//// [/users/username/projects/project/index.js] file written with same contents
//// [/users/username/projects/project/tsconfig.tsbuildinfo]
{
"program": {
"fileInfos": {
"../../../../a/lib/lib.d.ts": {
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true
},
"./index.tsx": {
"version": "-14168389096-export const x = {...{}};",
"signature": "-6508651827-export declare const x: {};\n",
"affectsGlobalScope": false
}
},
"options": {
"importHelpers": true,
"incremental": true,
"configFilePath": "./tsconfig.json"
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../../../a/lib/lib.d.ts",
[
"./index.tsx",
[
{
"file": "./index.tsx",
"start": 18,
"length": 5,
"messageText": "This syntax requires an imported helper but module 'tslib' cannot be found.",
"category": 1,
"code": 2354
}
]
]
]
},
"version": "FakeTSVersion"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
Input::
//// [/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; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };

//// [/users/username/projects/project/node_modules/tslib/index.d.ts]
export function __assign(...args: any[]): any;

//// [/users/username/projects/project/node_modules/tslib/package.json]
{"name":"tslib","version":"0.0.1"}

//// [/users/username/projects/project/index.tsx]
export const x = {...{}};

//// [/users/username/projects/project/tsconfig.json]
{"compilerOptions":{"importHelpers":true}}


/a/lib/tsc.js -w
Output::
>> Screen clear
[12:00:29 AM] Starting compilation in watch mode...

[12:00:32 AM] Found 0 errors. Watching for file changes.



Program root files: ["/users/username/projects/project/index.tsx"]
Program options: {"importHelpers":true,"watch":true,"configFilePath":"/users/username/projects/project/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/users/username/projects/project/node_modules/tslib/index.d.ts
/users/username/projects/project/index.tsx

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/users/username/projects/project/node_modules/tslib/index.d.ts
/users/username/projects/project/index.tsx

WatchedFiles::
/users/username/projects/project/tsconfig.json:
{"fileName":"/users/username/projects/project/tsconfig.json","pollingInterval":250}
/users/username/projects/project/index.tsx:
{"fileName":"/users/username/projects/project/index.tsx","pollingInterval":250}
/users/username/projects/project/node_modules/tslib/index.d.ts:
{"fileName":"/users/username/projects/project/node_modules/tslib/index.d.ts","pollingInterval":250}
/a/lib/lib.d.ts:
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/users/username/projects/project/node_modules:
{"directoryName":"/users/username/projects/project/node_modules","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/users/username/projects/project/node_modules/@types:
{"directoryName":"/users/username/projects/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/users/username/projects/project:
{"directoryName":"/users/username/projects/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined

//// [/users/username/projects/project/index.js]
"use strict";
exports.__esModule = true;
exports.x = void 0;
var tslib_1 = require("tslib");
exports.x = tslib_1.__assign({});



Change::

Input::
//// [/users/username/projects/project/node_modules/tslib/index.d.ts] deleted
//// [/users/username/projects/project/node_modules/tslib/package.json] deleted

Output::
>> Screen clear
[12:00:35 AM] Starting compilation in watch mode...

index.tsx:1:19 - error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

1 export const x = {...{}};
   ~~~~~

[12:00:39 AM] Found 1 error. Watching for file changes.



Program root files: ["/users/username/projects/project/index.tsx"]
Program options: {"importHelpers":true,"watch":true,"configFilePath":"/users/username/projects/project/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/users/username/projects/project/index.tsx

Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/users/username/projects/project/index.tsx

WatchedFiles::
/users/username/projects/project/tsconfig.json:
{"fileName":"/users/username/projects/project/tsconfig.json","pollingInterval":250}
/users/username/projects/project/index.tsx:
{"fileName":"/users/username/projects/project/index.tsx","pollingInterval":250}
/a/lib/lib.d.ts:
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}

FsWatches::

FsWatchesRecursive::
/users/username/projects/project/node_modules:
{"directoryName":"/users/username/projects/project/node_modules","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/users/username/projects/project/node_modules/@types:
{"directoryName":"/users/username/projects/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/users/username/projects/project:
{"directoryName":"/users/username/projects/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}

exitCode:: ExitStatus.undefined

//// [/users/username/projects/project/index.js] file written with same contents