Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

New: Provider loggerFn option to configure logging (fixes #323) #324

Merged
merged 1 commit into from
Jun 14, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,8 @@ const astNodeTypes = require("./lib/ast-node-types"),

const SUPPORTED_TYPESCRIPT_VERSIONS = require("./package.json").devDependencies.typescript;
const ACTIVE_TYPESCRIPT_VERSION = ts.version;

const isRunningSupportedTypeScriptVersion = semver.satisfies(ACTIVE_TYPESCRIPT_VERSION, SUPPORTED_TYPESCRIPT_VERSIONS);

if (!isRunningSupportedTypeScriptVersion) {
const border = "=============";
const versionWarning = [
border,
"WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.",
"You may find that it works just fine, or you may not.",
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
"Please only submit bug reports when using the officially supported version.",
border
];

console.warn(versionWarning.join("\n\n")); // eslint-disable-line no-console
}

let extra;

/**
Expand All @@ -49,7 +33,8 @@ function resetExtra() {
errors: [],
strict: false,
ecmaFeatures: {},
useJSXTextNode: false
useJSXTextNode: false,
log: console.log // eslint-disable-line no-console
};
}

Expand Down Expand Up @@ -109,6 +94,27 @@ function parse(code, options) {
extra.useJSXTextNode = true;
}

/**
* Allow the user to override the function used for logging
*/
if (typeof options.loggerFn === "function") {
extra.log = options.loggerFn;
}

}

if (!isRunningSupportedTypeScriptVersion) {
const border = "=============";
const versionWarning = [
border,
"WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.",
"You may find that it works just fine, or you may not.",
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
"Please only submit bug reports when using the officially supported version.",
border
];
extra.log(versionWarning.join("\n\n"));
}

// Even if jsx option is set in typescript compiler, filename still has to
Expand Down
Loading