Skip to content

Commit 2a2b573

Browse files
committed
Merge branch 'master' of github.com:Microsoft/TypeScript into shebang-comments
2 parents 6eb9165 + 8dff98d commit 2a2b573

File tree

8 files changed

+506
-367
lines changed

8 files changed

+506
-367
lines changed

src/compiler/builder.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,19 @@ namespace ts {
281281
}
282282

283283
// If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
284-
return !!forEachEntry(state.exportedModulesMap!, (exportedModules, exportedFromPath) =>
284+
if (forEachEntry(state.exportedModulesMap!, (exportedModules, exportedFromPath) =>
285285
!state.currentAffectedFilesExportedModulesMap!.has(exportedFromPath) && // If we already iterated this through cache, ignore it
286286
exportedModules.has(filePath) &&
287287
removeSemanticDiagnosticsOfFileAndExportsOfFile(state, exportedFromPath as Path, seenFileAndExportsOfFile)
288+
)) {
289+
return true;
290+
}
291+
292+
// Remove diagnostics of files that import this file (without going to exports of referencing files)
293+
return !!forEachEntry(state.referencedMap!, (referencesInFile, referencingFilePath) =>
294+
referencesInFile.has(filePath) &&
295+
!seenFileAndExportsOfFile.has(referencingFilePath) && // Not already removed diagnostic file
296+
removeSemanticDiagnosticsOf(state, referencingFilePath as Path) // Dont add to seen since this is not yet done with the export removal
288297
);
289298
}
290299

src/services/organizeImports.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ namespace ts.OrganizeImports {
2828
organizeImportsWorker(topLevelExportDecls, coalesceExports);
2929

3030
for (const ambientModule of sourceFile.statements.filter(isAmbientModule)) {
31-
const ambientModuleBody = getModuleBlock(ambientModule as ModuleDeclaration)!; // TODO: GH#18217
31+
if (!ambientModule.body) { continue; }
3232

33-
const ambientModuleImportDecls = ambientModuleBody.statements.filter(isImportDeclaration);
33+
const ambientModuleImportDecls = ambientModule.body.statements.filter(isImportDeclaration);
3434
organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports);
3535

36-
const ambientModuleExportDecls = ambientModuleBody.statements.filter(isExportDeclaration);
36+
const ambientModuleExportDecls = ambientModule.body.statements.filter(isExportDeclaration);
3737
organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
3838
}
3939

@@ -81,11 +81,6 @@ namespace ts.OrganizeImports {
8181
}
8282
}
8383

84-
function getModuleBlock(moduleDecl: ModuleDeclaration): ModuleBlock | undefined {
85-
const body = moduleDecl.body;
86-
return body && !isIdentifier(body) ? (isModuleBlock(body) ? body : getModuleBlock(body)) : undefined;
87-
}
88-
8984
function removeUnusedImports(oldImports: ReadonlyArray<ImportDeclaration>, sourceFile: SourceFile, program: Program) {
9085
const typeChecker = program.getTypeChecker();
9186
const jsxNamespace = typeChecker.getJsxNamespace();

src/testRunner/tsconfig.json

Lines changed: 145 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,145 @@
1-
{
2-
"extends": "../tsconfig-base",
3-
"compilerOptions": {
4-
"outFile": "../../built/local/run.js",
5-
"composite": false,
6-
"declaration": false,
7-
"declarationMap": false,
8-
"types": [
9-
"node", "mocha", "chai"
10-
],
11-
"lib": [
12-
"es6",
13-
"scripthost"
14-
]
15-
},
16-
"references": [
17-
{ "path": "../compiler", "prepend": true },
18-
{ "path": "../services", "prepend": true },
19-
{ "path": "../jsTyping", "prepend": true },
20-
{ "path": "../server", "prepend": true },
21-
{ "path": "../typingsInstallerCore", "prepend": true },
22-
{ "path": "../harness", "prepend": true }
23-
],
24-
25-
"files": [
26-
"fourslashRunner.ts",
27-
"compilerRunner.ts",
28-
"projectsRunner.ts",
29-
"rwcRunner.ts",
30-
"externalCompileRunner.ts",
31-
"test262Runner.ts",
32-
33-
"parallel/host.ts",
34-
"parallel/worker.ts",
35-
"parallel/shared.ts",
36-
37-
"runner.ts",
38-
39-
"unittests/services/extract/helpers.ts",
40-
"unittests/tscWatch/helpers.ts",
41-
"unittests/tsserver/helpers.ts",
42-
43-
"unittests/asserts.ts",
44-
"unittests/base64.ts",
45-
"unittests/builder.ts",
46-
"unittests/compilerCore.ts",
47-
"unittests/convertToBase64.ts",
48-
"unittests/customTransforms.ts",
49-
"unittests/factory.ts",
50-
"unittests/incrementalParser.ts",
51-
"unittests/jsDocParsing.ts",
52-
"unittests/moduleResolution.ts",
53-
"unittests/parsePseudoBigInt.ts",
54-
"unittests/paths.ts",
55-
"unittests/printer.ts",
56-
"unittests/programApi.ts",
57-
"unittests/publicApi.ts",
58-
"unittests/reuseProgramStructure.ts",
59-
"unittests/semver.ts",
60-
"unittests/transform.ts",
61-
"unittests/tsbuild.ts",
62-
"unittests/tsbuildWatchMode.ts",
63-
"unittests/config/commandLineParsing.ts",
64-
"unittests/config/configurationExtension.ts",
65-
"unittests/config/convertCompilerOptionsFromJson.ts",
66-
"unittests/config/convertTypeAcquisitionFromJson.ts",
67-
"unittests/config/initializeTSConfig.ts",
68-
"unittests/config/matchFiles.ts",
69-
"unittests/config/projectReferences.ts",
70-
"unittests/config/showConfig.ts",
71-
"unittests/config/tsconfigParsing.ts",
72-
"unittests/evaluation/asyncArrow.ts",
73-
"unittests/evaluation/asyncGenerator.ts",
74-
"unittests/evaluation/forAwaitOf.ts",
75-
"unittests/services/cancellableLanguageServiceOperations.ts",
76-
"unittests/services/colorization.ts",
77-
"unittests/services/convertToAsyncFunction.ts",
78-
"unittests/services/documentRegistry.ts",
79-
"unittests/services/extract/constants.ts",
80-
"unittests/services/extract/functions.ts",
81-
"unittests/services/extract/symbolWalker.ts",
82-
"unittests/services/extract/ranges.ts",
83-
"unittests/services/hostNewLineSupport.ts",
84-
"unittests/services/languageService.ts",
85-
"unittests/services/organizeImports.ts",
86-
"unittests/services/patternMatcher.ts",
87-
"unittests/services/preProcessFile.ts",
88-
"unittests/services/textChanges.ts",
89-
"unittests/services/transpile.ts",
90-
"unittests/tscWatch/consoleClearing.ts",
91-
"unittests/tscWatch/emit.ts",
92-
"unittests/tscWatch/programUpdates.ts",
93-
"unittests/tscWatch/resolutionCache.ts",
94-
"unittests/tscWatch/watchEnvironment.ts",
95-
"unittests/tscWatch/watchApi.ts",
96-
"unittests/tsserver/cachingFileSystemInformation.ts",
97-
"unittests/tsserver/cancellationToken.ts",
98-
"unittests/tsserver/compileOnSave.ts",
99-
"unittests/tsserver/completions.ts",
100-
"unittests/tsserver/configFileSearch.ts",
101-
"unittests/tsserver/configuredProjects.ts",
102-
"unittests/tsserver/declarationFileMaps.ts",
103-
"unittests/tsserver/documentRegistry.ts",
104-
"unittests/tsserver/duplicatePackages.ts",
105-
"unittests/tsserver/events/largeFileReferenced.ts",
106-
"unittests/tsserver/events/projectLanguageServiceState.ts",
107-
"unittests/tsserver/events/projectLoading.ts",
108-
"unittests/tsserver/events/projectUpdatedInBackground.ts",
109-
"unittests/tsserver/events/surveyReady.ts",
110-
"unittests/tsserver/externalProjects.ts",
111-
"unittests/tsserver/forceConsistentCasingInFileNames.ts",
112-
"unittests/tsserver/formatSettings.ts",
113-
"unittests/tsserver/getApplicableRefactors.ts",
114-
"unittests/tsserver/getEditsForFileRename.ts",
115-
"unittests/tsserver/importHelpers.ts",
116-
"unittests/tsserver/inferredProjects.ts",
117-
"unittests/tsserver/languageService.ts",
118-
"unittests/tsserver/maxNodeModuleJsDepth.ts",
119-
"unittests/tsserver/metadataInResponse.ts",
120-
"unittests/tsserver/navTo.ts",
121-
"unittests/tsserver/occurences.ts",
122-
"unittests/tsserver/openFile.ts",
123-
"unittests/tsserver/projectErrors.ts",
124-
"unittests/tsserver/projectReferences.ts",
125-
"unittests/tsserver/projects.ts",
126-
"unittests/tsserver/refactors.ts",
127-
"unittests/tsserver/reload.ts",
128-
"unittests/tsserver/rename.ts",
129-
"unittests/tsserver/resolutionCache.ts",
130-
"unittests/tsserver/session.ts",
131-
"unittests/tsserver/skipLibCheck.ts",
132-
"unittests/tsserver/symLinks.ts",
133-
"unittests/tsserver/syntaxOperations.ts",
134-
"unittests/tsserver/textStorage.ts",
135-
"unittests/tsserver/telemetry.ts",
136-
"unittests/tsserver/typeAquisition.ts",
137-
"unittests/tsserver/typeReferenceDirectives.ts",
138-
"unittests/tsserver/typingsInstaller.ts",
139-
"unittests/tsserver/untitledFiles.ts",
140-
"unittests/tsserver/versionCache.ts",
141-
"unittests/tsserver/watchEnvironment.ts"
142-
]
143-
}
1+
{
2+
"extends": "../tsconfig-base",
3+
"compilerOptions": {
4+
"outFile": "../../built/local/run.js",
5+
"composite": false,
6+
"declaration": false,
7+
"declarationMap": false,
8+
"types": [
9+
"node", "mocha", "chai"
10+
],
11+
"lib": [
12+
"es6",
13+
"scripthost"
14+
]
15+
},
16+
"references": [
17+
{ "path": "../compiler", "prepend": true },
18+
{ "path": "../services", "prepend": true },
19+
{ "path": "../jsTyping", "prepend": true },
20+
{ "path": "../server", "prepend": true },
21+
{ "path": "../typingsInstallerCore", "prepend": true },
22+
{ "path": "../harness", "prepend": true }
23+
],
24+
25+
"files": [
26+
"fourslashRunner.ts",
27+
"compilerRunner.ts",
28+
"projectsRunner.ts",
29+
"rwcRunner.ts",
30+
"externalCompileRunner.ts",
31+
"test262Runner.ts",
32+
33+
"parallel/host.ts",
34+
"parallel/worker.ts",
35+
"parallel/shared.ts",
36+
37+
"runner.ts",
38+
39+
"unittests/services/extract/helpers.ts",
40+
"unittests/tscWatch/helpers.ts",
41+
"unittests/tsserver/helpers.ts",
42+
43+
"unittests/asserts.ts",
44+
"unittests/base64.ts",
45+
"unittests/builder.ts",
46+
"unittests/comments.ts",
47+
"unittests/compilerCore.ts",
48+
"unittests/convertToBase64.ts",
49+
"unittests/customTransforms.ts",
50+
"unittests/factory.ts",
51+
"unittests/incrementalParser.ts",
52+
"unittests/jsDocParsing.ts",
53+
"unittests/moduleResolution.ts",
54+
"unittests/parsePseudoBigInt.ts",
55+
"unittests/paths.ts",
56+
"unittests/printer.ts",
57+
"unittests/programApi.ts",
58+
"unittests/publicApi.ts",
59+
"unittests/reuseProgramStructure.ts",
60+
"unittests/semver.ts",
61+
"unittests/transform.ts",
62+
"unittests/tsbuild.ts",
63+
"unittests/tsbuildWatchMode.ts",
64+
"unittests/config/commandLineParsing.ts",
65+
"unittests/config/configurationExtension.ts",
66+
"unittests/config/convertCompilerOptionsFromJson.ts",
67+
"unittests/config/convertTypeAcquisitionFromJson.ts",
68+
"unittests/config/initializeTSConfig.ts",
69+
"unittests/config/matchFiles.ts",
70+
"unittests/config/projectReferences.ts",
71+
"unittests/config/showConfig.ts",
72+
"unittests/config/tsconfigParsing.ts",
73+
"unittests/evaluation/asyncArrow.ts",
74+
"unittests/evaluation/asyncGenerator.ts",
75+
"unittests/evaluation/forAwaitOf.ts",
76+
"unittests/services/cancellableLanguageServiceOperations.ts",
77+
"unittests/services/colorization.ts",
78+
"unittests/services/convertToAsyncFunction.ts",
79+
"unittests/services/documentRegistry.ts",
80+
"unittests/services/extract/constants.ts",
81+
"unittests/services/extract/functions.ts",
82+
"unittests/services/extract/symbolWalker.ts",
83+
"unittests/services/extract/ranges.ts",
84+
"unittests/services/hostNewLineSupport.ts",
85+
"unittests/services/languageService.ts",
86+
"unittests/services/organizeImports.ts",
87+
"unittests/services/patternMatcher.ts",
88+
"unittests/services/preProcessFile.ts",
89+
"unittests/services/textChanges.ts",
90+
"unittests/services/transpile.ts",
91+
"unittests/tscWatch/consoleClearing.ts",
92+
"unittests/tscWatch/emit.ts",
93+
"unittests/tscWatch/emitAndErrorUpdates.ts",
94+
"unittests/tscWatch/programUpdates.ts",
95+
"unittests/tscWatch/resolutionCache.ts",
96+
"unittests/tscWatch/watchEnvironment.ts",
97+
"unittests/tscWatch/watchApi.ts",
98+
"unittests/tsserver/cachingFileSystemInformation.ts",
99+
"unittests/tsserver/cancellationToken.ts",
100+
"unittests/tsserver/compileOnSave.ts",
101+
"unittests/tsserver/completions.ts",
102+
"unittests/tsserver/configFileSearch.ts",
103+
"unittests/tsserver/configuredProjects.ts",
104+
"unittests/tsserver/declarationFileMaps.ts",
105+
"unittests/tsserver/documentRegistry.ts",
106+
"unittests/tsserver/duplicatePackages.ts",
107+
"unittests/tsserver/events/largeFileReferenced.ts",
108+
"unittests/tsserver/events/projectLanguageServiceState.ts",
109+
"unittests/tsserver/events/projectLoading.ts",
110+
"unittests/tsserver/events/projectUpdatedInBackground.ts",
111+
"unittests/tsserver/events/surveyReady.ts",
112+
"unittests/tsserver/externalProjects.ts",
113+
"unittests/tsserver/forceConsistentCasingInFileNames.ts",
114+
"unittests/tsserver/formatSettings.ts",
115+
"unittests/tsserver/getApplicableRefactors.ts",
116+
"unittests/tsserver/getEditsForFileRename.ts",
117+
"unittests/tsserver/importHelpers.ts",
118+
"unittests/tsserver/inferredProjects.ts",
119+
"unittests/tsserver/languageService.ts",
120+
"unittests/tsserver/maxNodeModuleJsDepth.ts",
121+
"unittests/tsserver/metadataInResponse.ts",
122+
"unittests/tsserver/navTo.ts",
123+
"unittests/tsserver/occurences.ts",
124+
"unittests/tsserver/openFile.ts",
125+
"unittests/tsserver/projectErrors.ts",
126+
"unittests/tsserver/projectReferences.ts",
127+
"unittests/tsserver/projects.ts",
128+
"unittests/tsserver/refactors.ts",
129+
"unittests/tsserver/reload.ts",
130+
"unittests/tsserver/rename.ts",
131+
"unittests/tsserver/resolutionCache.ts",
132+
"unittests/tsserver/session.ts",
133+
"unittests/tsserver/skipLibCheck.ts",
134+
"unittests/tsserver/symLinks.ts",
135+
"unittests/tsserver/syntaxOperations.ts",
136+
"unittests/tsserver/textStorage.ts",
137+
"unittests/tsserver/telemetry.ts",
138+
"unittests/tsserver/typeAquisition.ts",
139+
"unittests/tsserver/typeReferenceDirectives.ts",
140+
"unittests/tsserver/typingsInstaller.ts",
141+
"unittests/tsserver/untitledFiles.ts",
142+
"unittests/tsserver/versionCache.ts",
143+
"unittests/tsserver/watchEnvironment.ts"
144+
]
145+
}

src/testRunner/unittests/services/organizeImports.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ export const Other = 1;
274274
assert.isEmpty(changes);
275275
});
276276

277+
it("doesn't crash on shorthand ambient module", () => {
278+
const testFile = {
279+
path: "/a.ts",
280+
content: "declare module '*';",
281+
};
282+
const languageService = makeLanguageService(testFile);
283+
const changes = languageService.organizeImports({ type: "file", fileName: testFile.path }, testFormatSettings, emptyOptions);
284+
assert.isEmpty(changes);
285+
});
286+
277287
testOrganizeImports("Renamed_used",
278288
{
279289
path: "/test.ts",

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ let x: string = 10;`);
479479
const { host, solutionBuilder } = createSolutionOfProject(allFiles, currentDirectory, solutionBuilderconfig, getOutputFileStamps);
480480

481481
// Build in watch mode
482-
const watch = createWatchOfConfigFileReturningBuilder(watchConfig, host);
482+
const watch = createWatchOfConfigFile(watchConfig, host);
483483
checkOutputErrorsInitial(host, emptyArray);
484484

485485
return { host, solutionBuilder, watch };
@@ -505,10 +505,8 @@ let x: string = 10;`);
505505
projectSystem.checkProjectActualFiles(service.configuredProjects.get(configFile.toLowerCase())!, expectedFiles);
506506
}
507507

508-
type Watch = () => BuilderProgram;
509-
510508
function verifyDependencies(watch: Watch, filePath: string, expected: ReadonlyArray<string>) {
511-
checkArray(`${filePath} dependencies`, watch().getAllDependencies(watch().getSourceFile(filePath)!), expected);
509+
checkArray(`${filePath} dependencies`, watch.getBuilderProgram().getAllDependencies(watch().getSourceFile(filePath)!), expected);
512510
}
513511

514512
describe("on sample project", () => {
@@ -542,7 +540,7 @@ let x: string = 10;`);
542540

543541
host.checkTimeoutQueueLengthAndRun(1);
544542
checkOutputErrorsIncremental(host, emptyArray);
545-
checkProgramActualFiles(watch().getProgram(), expectedFilesAfterEdit);
543+
checkProgramActualFiles(watch(), expectedFilesAfterEdit);
546544

547545
});
548546

@@ -642,7 +640,7 @@ export function gfoo() {
642640
expectedWatchedDirectoriesRecursive: ReadonlyArray<string>,
643641
dependencies: ReadonlyArray<[string, ReadonlyArray<string>]>,
644642
expectedWatchedDirectories?: ReadonlyArray<string>) {
645-
checkProgramActualFiles(watch().getProgram(), expectedProgramFiles);
643+
checkProgramActualFiles(watch(), expectedProgramFiles);
646644
verifyWatchesOfProject(host, expectedWatchedFiles, expectedWatchedDirectoriesRecursive, expectedWatchedDirectories);
647645
for (const [file, deps] of dependencies) {
648646
verifyDependencies(watch, file, deps);

0 commit comments

Comments
 (0)