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

Commit b273fca

Browse files
committed
Refactor application of isParseForESLint logic
1 parent a65c8ca commit b273fca

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

parser.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ function resetExtra() {
4646

4747
/**
4848
* Parses the given source code to produce a valid AST
49-
* @param {mixed} code TypeScript code
50-
* @param {Object} options configuration object for the parser
49+
* @param {mixed} code TypeScript code
50+
* @param {Object} options configuration object for the parser
51+
* @param {Object} additionalParsingContext additional internal configuration
5152
* @returns {Object} the AST
5253
*/
53-
function parse(code, options) {
54+
function generateAST(code, options, additionalParsingContext) {
55+
additionalParsingContext = additionalParsingContext || {};
5456

5557
const toString = String;
5658

@@ -109,7 +111,7 @@ function parse(code, options) {
109111
* Provide the context as to whether or not we are parsing for ESLint,
110112
* specifically
111113
*/
112-
if (options.parseForESLint) {
114+
if (additionalParsingContext.isParseForESLint) {
113115
extra.parseForESLint = true;
114116
}
115117
}
@@ -183,11 +185,12 @@ function parse(code, options) {
183185

184186
exports.version = require("./package.json").version;
185187

186-
exports.parse = parse;
188+
exports.parse = function parse(code, options) {
189+
return generateAST(code, options, { isParseForESLint: false });
190+
};
187191

188192
exports.parseForESLint = function parseForESLint(code, options) {
189-
options.parseForESLint = true;
190-
const ast = parse(code, options);
193+
const ast = generateAST(code, options, { isParseForESLint: true });
191194
return { ast };
192195
};
193196

0 commit comments

Comments
 (0)