Skip to content

Commit

Permalink
fix(typescript-estree): persisted parse and module none (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 3, 2020
1 parent 159b16e commit 7c70323
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
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();
});
}
});
}
});
});

0 comments on commit 7c70323

Please sign in to comment.