Skip to content

Commit

Permalink
fix(typescript-estree): parsing of deeply nested new files in new fol…
Browse files Browse the repository at this point in the history
…der (#1412)

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
armano2 and bradzacher committed Jan 8, 2020
1 parent 6aa6bc7 commit 206c94b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Expand Up @@ -394,9 +394,10 @@ function maybeInvalidateProgram(
current = next;
const folderWatchCallbacks = folderWatchCallbackTrackingMap.get(current);
if (folderWatchCallbacks) {
folderWatchCallbacks.forEach(cb =>
cb(currentDir, ts.FileWatcherEventKind.Changed),
);
folderWatchCallbacks.forEach(cb => {
cb(currentDir, ts.FileWatcherEventKind.Changed);
cb(current!, ts.FileWatcherEventKind.Changed);
});
hasCallback = true;
break;
}
Expand Down
23 changes: 21 additions & 2 deletions packages/typescript-estree/tests/lib/persistentParse.ts
Expand Up @@ -7,6 +7,7 @@ const CONTENTS = {
foo: 'console.log("foo")',
bar: 'console.log("bar")',
'baz/bar': 'console.log("baz bar")',
'bat/baz/bar': 'console.log("bat/baz/bar")',
};

const tmpDirs = new Set<tmp.DirResult>();
Expand All @@ -22,7 +23,7 @@ afterEach(() => {
function writeTSConfig(dirName: string, config: Record<string, unknown>): void {
fs.writeFileSync(path.join(dirName, 'tsconfig.json'), JSON.stringify(config));
}
function writeFile(dirName: string, file: 'foo' | 'bar' | 'baz/bar'): void {
function writeFile(dirName: string, file: keyof typeof CONTENTS): void {
fs.writeFileSync(path.join(dirName, 'src', `${file}.ts`), CONTENTS[file]);
}
function renameFile(dirName: string, src: 'bar', dest: 'baz/bar'): void {
Expand Down Expand Up @@ -53,7 +54,7 @@ function setup(tsconfig: Record<string, unknown>, writeBar = true): string {
return tmpDir.name;
}

function parseFile(filename: 'foo' | 'bar' | 'baz/bar', tmpDir: string): void {
function parseFile(filename: keyof typeof CONTENTS, tmpDir: string): void {
parseAndGenerateServices(CONTENTS.foo, {
project: './tsconfig.json',
tsconfigRootDir: tmpDir,
Expand Down Expand Up @@ -112,6 +113,24 @@ function baseTests(
expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
});

it('allows parsing of deeply nested new files in new folder', () => {
const PROJECT_DIR = setup(tsConfigIncludeAll);

expect(() => parseFile('foo', PROJECT_DIR)).not.toThrow();

// Create deep folder structure after first parse (this is important step)
// context: https://github.com/typescript-eslint/typescript-eslint/issues/1394
fs.mkdirSync(path.join(PROJECT_DIR, 'src', 'bat'));
fs.mkdirSync(path.join(PROJECT_DIR, 'src', 'bat', 'baz'));

const bazSlashBar = path.join('bat', 'baz', 'bar') as 'bat/baz/bar';

// write a new file and attempt to parse it
writeFile(PROJECT_DIR, bazSlashBar);

expect(() => parseFile(bazSlashBar, PROJECT_DIR)).not.toThrow();
});

it('allows renaming of files', () => {
const PROJECT_DIR = setup(tsConfigIncludeAll, true);
const bazSlashBar = path.join('baz', 'bar') as 'baz/bar';
Expand Down

0 comments on commit 206c94b

Please sign in to comment.