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): persisted parse and module none #1516

Merged
merged 4 commits into from Feb 3, 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 @@ -39,7 +39,10 @@ function createDefaultProgram(
return undefined;
}

const compilerHost = ts.createCompilerHost(commandLine.options, true);
const compilerHost = ts.createCompilerHost(
commandLine.options,
/* setParentNodes */ true,
);
const oldReadFile = compilerHost.readFile;
compilerHost.readFile = (fileName: string): string | undefined =>
path.normalize(fileName) === path.normalize(extra.filePath)
Expand Down
Expand Up @@ -46,7 +46,7 @@ function createIsolatedProgram(code: string, extra: Extra): ASTAndProgram {
filename,
code,
ts.ScriptTarget.Latest,
true,
/* setParentNodes */ true,
getScriptKind(extra, filename),
);
},
Expand Down
Expand Up @@ -218,6 +218,8 @@ function getProgramsForProjects(

// cache watch program and return current program
knownWatchProgramMap.set(tsconfigPath, programWatch);
// sets parent pointers in source files
program.getTypeChecker();
results.push(program);
}

Expand Down
34 changes: 34 additions & 0 deletions packages/typescript-estree/tests/lib/persistentParse.ts
Expand Up @@ -8,6 +8,9 @@ const CONTENTS = {
bar: 'console.log("bar")',
'baz/bar': 'console.log("baz bar")',
'bat/baz/bar': 'console.log("bat/baz/bar")',
number: 'const foo = 1;',
object: '(() => { })();',
string: 'let a: "a" | "b";',
};

const cwdCopy = process.cwd();
Expand Down Expand Up @@ -304,4 +307,35 @@ describe('persistent parse', () => {

baseTests(tsConfigExcludeBar, tsConfigIncludeAll);
});

describe('tsconfig with module set', () => {
const moduleTypes = [
'None',
'CommonJS',
'AMD',
'System',
'UMD',
'ES6',
'ES2015',
'ESNext',
];

for (const module of moduleTypes) {
describe(`module ${module}`, () => {
const tsConfigIncludeAll = {
compilerOptions: { module },
include: ['./**/*'],
};

const testNames = ['object', 'number', 'string', 'foo'] as const;
for (const name of testNames) {
it(`first parse of ${name} should not throw`, () => {
const PROJECT_DIR = setup(tsConfigIncludeAll);
writeFile(PROJECT_DIR, name);
expect(() => parseFile(name, PROJECT_DIR)).not.toThrow();
});
}
});
}
});
});