diff --git a/tsc/internal/compiler/filesparser.go b/tsc/internal/compiler/filesparser.go index 4b317b5a51dec..9ba3d4f47ecea 100644 --- a/tsc/internal/compiler/filesparser.go +++ b/tsc/internal/compiler/filesparser.go @@ -272,7 +272,8 @@ func (w *filesParser) start(loader *fileLoader, tasks []*parseTask, depth int) { } currentDepth := core.IfElse(task.increaseDepth, depth+1, depth) - if currentDepth < data.lowestDepth { + lowered := currentDepth < data.lowestDepth + if lowered { // If we're seeing this task at a lower depth than before, // reprocess its subtasks to ensure they are loaded. data.lowestDepth = currentDepth @@ -294,7 +295,7 @@ func (w *filesParser) start(loader *fileLoader, tasks []*parseTask, depth int) { data.startedSubTasks = true } } - if !taskByFileName.startedSubTasks && loadSubTasks { + if loadSubTasks && (lowered || !taskByFileName.startedSubTasks) { taskByFileName.startedSubTasks = true w.start(loader, taskByFileName.subTasks, data.lowestDepth) } diff --git a/tsc/testdata/baselines/reference/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.js b/tsc/testdata/baselines/reference/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.js new file mode 100644 index 0000000000000..0129b214e47bc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.ts] //// + +//// [package.json] +{ "name": "lib", "types": "index.ts" } + +//// [index.ts] +export { util } from "./util"; + +//// [util.ts] +export const util = 1; + +//// [a.ts] +import { util } from "./lib/index"; +export const a = util; + +//// [b.ts] +import { util } from "lib"; +export const b = util; + + +//// [util.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.util = void 0; +exports.util = 1; +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.util = void 0; +var util_1 = require("./util"); +Object.defineProperty(exports, "util", { enumerable: true, get: function () { return util_1.util; } }); +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +const index_1 = require("./lib/index"); +exports.a = index_1.util; +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = void 0; +const lib_1 = require("lib"); +exports.b = lib_1.util; diff --git a/tsc/testdata/tests/cases/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.ts b/tsc/testdata/tests/cases/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.ts new file mode 100644 index 0000000000000..eaaea09be8cc3 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/symlinkedPackageReachedRelativelyIsNotExternalLibrary.ts @@ -0,0 +1,27 @@ +// @noTypesAndSymbols: true + +// @filename: /src/tsconfig.json +{ + "compilerOptions": { "outDir": "out", "module": "commonjs", "target": "es2015" }, + "files": ["a.ts", "b.ts"] +} + +// @filename: /src/a.ts +import { util } from "./lib/index"; +export const a = util; + +// @filename: /src/b.ts +import { util } from "lib"; +export const b = util; + +// @filename: /src/lib/package.json +// @symlink: /src/node_modules/lib/package.json +{ "name": "lib", "types": "index.ts" } + +// @filename: /src/lib/index.ts +// @symlink: /src/node_modules/lib/index.ts +export { util } from "./util"; + +// @filename: /src/lib/util.ts +// @symlink: /src/node_modules/lib/util.ts +export const util = 1;