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 4 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
46 changes: 44 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")',
'ui/components/file': 'console.log("ui/components")',
armano2 marked this conversation as resolved.
Show resolved Hide resolved
};

const tmpDirs = new Set<tmp.DirResult>();
Expand All @@ -22,7 +23,16 @@ 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 writeTSConfigExtend(
dirName: string,
config: Record<string, unknown>,
): void {
fs.writeFileSync(
path.join(dirName, 'tsconfig.extend.json'),
JSON.stringify(config),
);
}
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 +63,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 @@ -230,4 +240,36 @@ describe('persistent parse', () => {

baseTests(tsConfigExcludeBar, tsConfigIncludeAll);
});

describe('tsconfig with extends and nested folders', () => {
// https://github.com/typescript-eslint/typescript-eslint/issues/1394
it('parses both files successfully', () => {
const tsConfigExcludeBar = {
include: ['src'],
};
const tsConfigIncludeAll = {
extends: './tsconfig.extend.json',
include: ['./**/*'],
};

const PROJECT_DIR = setup(tsConfigIncludeAll, false);
writeTSConfigExtend(PROJECT_DIR, tsConfigExcludeBar);

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

fs.mkdirSync(path.join(PROJECT_DIR, 'src', 'ui'));
fs.mkdirSync(path.join(PROJECT_DIR, 'src', 'ui', 'components'));

const bazSlashBar = path.join(
'ui',
'components',
'file',
) as 'ui/components/file';

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

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