|
1 | 1 | /**
|
2 | 2 | * @fileoverview Parser that converts TypeScript into ESTree format.
|
3 | 3 | * @author Nicholas C. Zakas
|
| 4 | + * @author James Henry <https://github.com/JamesHenry> |
4 | 5 | * @copyright jQuery Foundation and other contributors, https://jquery.org/
|
5 | 6 | * MIT License
|
6 | 7 | */
|
@@ -45,11 +46,13 @@ function resetExtra() {
|
45 | 46 |
|
46 | 47 | /**
|
47 | 48 | * Parses the given source code to produce a valid AST
|
48 |
| - * @param {mixed} code TypeScript code |
49 |
| - * @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 |
50 | 52 | * @returns {Object} the AST
|
51 | 53 | */
|
52 |
| -function parse(code, options) { |
| 54 | +function generateAST(code, options, additionalParsingContext) { |
| 55 | + additionalParsingContext = additionalParsingContext || {}; |
53 | 56 |
|
54 | 57 | const toString = String;
|
55 | 58 |
|
@@ -104,6 +107,13 @@ function parse(code, options) {
|
104 | 107 | extra.log = Function.prototype;
|
105 | 108 | }
|
106 | 109 |
|
| 110 | + /** |
| 111 | + * Provide the context as to whether or not we are parsing for ESLint, |
| 112 | + * specifically |
| 113 | + */ |
| 114 | + if (additionalParsingContext.isParseForESLint) { |
| 115 | + extra.parseForESLint = true; |
| 116 | + } |
107 | 117 | }
|
108 | 118 |
|
109 | 119 | if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
|
@@ -175,7 +185,14 @@ function parse(code, options) {
|
175 | 185 |
|
176 | 186 | exports.version = require("./package.json").version;
|
177 | 187 |
|
178 |
| -exports.parse = parse; |
| 188 | +exports.parse = function parse(code, options) { |
| 189 | + return generateAST(code, options, { isParseForESLint: false }); |
| 190 | +}; |
| 191 | + |
| 192 | +exports.parseForESLint = function parseForESLint(code, options) { |
| 193 | + const ast = generateAST(code, options, { isParseForESLint: true }); |
| 194 | + return { ast }; |
| 195 | +}; |
179 | 196 |
|
180 | 197 | // Deep copy.
|
181 | 198 | /* istanbul ignore next */
|
|
0 commit comments