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(typescript-estree): parsing of deeply nested new files in new folder #1412

Merged
merged 6 commits into from Jan 8, 2020
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
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