Skip to content

Commit 78da46c

Browse files
authored
Merge pull request #9614 from Microsoft/port9607
Port9607
2 parents 87e9506 + 5f6eb5b commit 78da46c

File tree

21 files changed

+116
-32
lines changed

21 files changed

+116
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ internal/
5050
!**/.vscode/tasks.json
5151
!tests/cases/projects/projectOption/**/node_modules
5252
!tests/cases/projects/NodeModulesSearch/**/*
53+
!tests/baselines/reference/project/nodeModules*/**/*

src/compiler/program.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,13 +1095,13 @@ namespace ts {
10951095
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
10961096
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
10971097
const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2;
1098-
let currentNodeModulesJsDepth = 0;
1098+
let currentNodeModulesDepth = 0;
10991099

11001100
// If a module has some of its imports skipped due to being at the depth limit under node_modules, then track
11011101
// this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed.
11021102
const modulesWithElidedImports: Map<boolean> = {};
11031103

1104-
// Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled.
1104+
// Track source files that are source files found by searching under node_modules, as these shouldn't be compiled.
11051105
const sourceFilesFoundSearchingNodeModules: Map<boolean> = {};
11061106

11071107
const start = new Date().getTime();
@@ -1918,9 +1918,21 @@ namespace ts {
19181918
reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd);
19191919
}
19201920

1921+
// If the file was previously found via a node_modules search, but is now being processed as a root file,
1922+
// then everything it sucks in may also be marked incorrectly, and needs to be checked again.
1923+
if (file && lookUp(sourceFilesFoundSearchingNodeModules, file.path) && currentNodeModulesDepth == 0) {
1924+
sourceFilesFoundSearchingNodeModules[file.path] = false;
1925+
if (!options.noResolve) {
1926+
processReferencedFiles(file, getDirectoryPath(fileName), isDefaultLib);
1927+
processTypeReferenceDirectives(file);
1928+
}
1929+
1930+
modulesWithElidedImports[file.path] = false;
1931+
processImportedModules(file, getDirectoryPath(fileName));
1932+
}
19211933
// See if we need to reprocess the imports due to prior skipped imports
1922-
if (file && lookUp(modulesWithElidedImports, file.path)) {
1923-
if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) {
1934+
else if (file && lookUp(modulesWithElidedImports, file.path)) {
1935+
if (currentNodeModulesDepth < maxNodeModulesJsDepth) {
19241936
modulesWithElidedImports[file.path] = false;
19251937
processImportedModules(file, getDirectoryPath(fileName));
19261938
}
@@ -1942,6 +1954,7 @@ namespace ts {
19421954

19431955
filesByName.set(path, file);
19441956
if (file) {
1957+
sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0);
19451958
file.path = path;
19461959

19471960
if (host.useCaseSensitiveFileNames()) {
@@ -2075,13 +2088,10 @@ namespace ts {
20752088
const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension(resolution.resolvedFileName);
20762089

20772090
if (isFromNodeModulesSearch) {
2078-
sourceFilesFoundSearchingNodeModules[resolvedPath] = true;
2079-
}
2080-
if (isJsFileFromNodeModules) {
2081-
currentNodeModulesJsDepth++;
2091+
currentNodeModulesDepth++;
20822092
}
20832093

2084-
const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
2094+
const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth;
20852095
const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport;
20862096

20872097
if (elideImport) {
@@ -2096,8 +2106,8 @@ namespace ts {
20962106
file.imports[i].end);
20972107
}
20982108

2099-
if (isJsFileFromNodeModules) {
2100-
currentNodeModulesJsDepth--;
2109+
if (isFromNodeModulesSearch) {
2110+
currentNodeModulesDepth--;
21012111
}
21022112
}
21032113
}

src/harness/projectsRunner.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,27 @@ class ProjectRunner extends RunnerBase {
479479

480480
it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => {
481481
if (testCase.baselineCheck) {
482+
const errs: Error[] = [];
482483
ts.forEach(compilerResult.outputFiles, outputFile => {
483-
484-
Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
485-
try {
486-
return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
487-
}
488-
catch (e) {
489-
return undefined;
490-
}
491-
});
484+
// There may be multiple files with different baselines. Run all and report at the end, else
485+
// it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'.
486+
try {
487+
Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
488+
try {
489+
return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
490+
}
491+
catch (e) {
492+
return undefined;
493+
}
494+
});
495+
}
496+
catch (e) {
497+
errs.push(e);
498+
}
492499
});
500+
if (errs.length) {
501+
throw Error(errs.join("\n "));
502+
}
493503
}
494504
});
495505

tests/baselines/reference/moduleAugmentationInDependency2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export {};
88
//// [app.ts]
99
import "A"
1010

11+
//// [index.js]
12+
"use strict";
1113
//// [app.js]
1214
"use strict";
1315
require("A");

tests/baselines/reference/nodeResolution6.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ export declare var y;
1313
import y = require("a");
1414

1515

16-
//// [ref.js]
17-
var x = 1;
1816
//// [b.js]
1917
"use strict";

tests/baselines/reference/nodeResolution8.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ export declare var y;
1212
//// [b.ts]
1313
import y = require("a");
1414

15-
//// [ref.js]
16-
var x = 1;
1715
//// [b.js]
1816
"use strict";

tests/baselines/reference/pathMappingBasedModuleResolution5_node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ exports.x = 1;
3131
//// [file2.js]
3232
"use strict";
3333
exports.y = 1;
34+
//// [file4.js]
35+
"use strict";
36+
exports.z1 = 1;
3437
//// [file1.js]
3538
"use strict";
3639
var file1_1 = require("folder2/file1");

tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/index.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/relative.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js renamed to tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/root.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ define(["require", "exports", "m1"], function (require, exports, m1) {
22
"use strict";
33
m1.f1("test");
44
m1.f2.a = "10"; // Error: Should be number
5+
m1.rel = 42; // Error: Should be boolean
56
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".
67
});

0 commit comments

Comments
 (0)