Skip to content
This repository has been archived by the owner. It is now read-only.

feat: typed parser return value #33

Merged
merged 5 commits into from Nov 26, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

refactor: extract code for computing file name

  • Loading branch information...
g-plane committed Nov 26, 2018
commit ba65937fbaebbcb9f8ccaa744d01efd8387d5a08
@@ -30,6 +30,15 @@ const isRunningSupportedTypeScriptVersion = semver.satisfies(
let extra: Extra;
let warnedAboutTSVersion = false;

/**
* Compute the filename based on the parser options
*
* @param options Parser options
*/
function getFileName({ jsx }: { jsx?: boolean }) {
return jsx ? 'estree.tsx' : 'estree.ts';
}

/**
* Resets the extra config object
* @returns {void}
@@ -61,12 +70,12 @@ function getASTFromProject(code: string, options: ParserOptions) {
return util.firstDefined(
calculateProjectParserOptions(
code,
options.filePath || (options.jsx ? 'estree.ts' : 'estree.tsx'),
options.filePath || getFileName(options),
extra
),
(currentProgram: ts.Program) => {
const ast = currentProgram.getSourceFile(
options.filePath || (options.jsx ? 'estree.ts' : 'estree.tsx')
options.filePath || getFileName(options)
);
return ast && { ast, program: currentProgram };
}
@@ -80,7 +89,7 @@ function getASTFromProject(code: string, options: ParserOptions) {
function createNewProgram(code: string) {
// Even if jsx option is set in typescript compiler, filename still has to
// contain .tsx file extension
const FILENAME = extra.jsx ? 'estree.tsx' : 'estree.ts';
const FILENAME = getFileName(extra);

const compilerHost = {
fileExists() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.