aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/verify/parse.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-12-10 21:51:33 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-12-10 21:51:33 +0100
commit0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch)
treef9864d4a4148621378958794cbbfdc2393733283 /node_modules/tslint/lib/verify/parse.js
parent6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff)
upgrade dependencies
Diffstat (limited to 'node_modules/tslint/lib/verify/parse.js')
-rw-r--r--node_modules/tslint/lib/verify/parse.js53
1 files changed, 51 insertions, 2 deletions
diff --git a/node_modules/tslint/lib/verify/parse.js b/node_modules/tslint/lib/verify/parse.js
index 1d475efd3..528f68cc8 100644
--- a/node_modules/tslint/lib/verify/parse.js
+++ b/node_modules/tslint/lib/verify/parse.js
@@ -15,6 +15,7 @@
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
+var semver = require("semver");
var ts = require("typescript");
var util_1 = require("util");
var utils_1 = require("../utils");
@@ -30,6 +31,54 @@ function getTypescriptVersionRequirement(text) {
return undefined;
}
exports.getTypescriptVersionRequirement = getTypescriptVersionRequirement;
+function getNormalizedTypescriptVersion() {
+ var tsVersion = new semver.SemVer(ts.version);
+ // remove prerelease suffix when matching to allow testing with nightly builds
+ return tsVersion.major + "." + tsVersion.minor + "." + tsVersion.patch;
+}
+exports.getNormalizedTypescriptVersion = getNormalizedTypescriptVersion;
+function preprocessDirectives(text) {
+ if (!/^#(?:if|else|endif)\b/m.test(text)) {
+ return text; // If there are no directives, just return the input unchanged
+ }
+ var tsVersion = getNormalizedTypescriptVersion();
+ var lines = text.split(/\n/);
+ var result = [];
+ var collecting = true;
+ var state = 0 /* Initial */;
+ for (var _i = 0, lines_2 = lines; _i < lines_2.length; _i++) {
+ var line = lines_2[_i];
+ if (line.startsWith("#if typescript")) {
+ if (state !== 0 /* Initial */) {
+ throw lintError_1.lintSyntaxError("#if directives cannot be nested");
+ }
+ state = 1 /* If */;
+ collecting = semver.satisfies(tsVersion, line.slice("#if typescript".length).trim());
+ }
+ else if (/^#else\s*$/.test(line)) {
+ if (state !== 1 /* If */) {
+ throw lintError_1.lintSyntaxError("unexpected #else");
+ }
+ state = 2 /* Else */;
+ collecting = !collecting;
+ }
+ else if (/^#endif\s*$/.test(line)) {
+ if (state === 0 /* Initial */) {
+ throw lintError_1.lintSyntaxError("unexpected #endif");
+ }
+ state = 0 /* Initial */;
+ collecting = true;
+ }
+ else if (collecting) {
+ result.push(line);
+ }
+ }
+ if (state !== 0 /* Initial */) {
+ throw lintError_1.lintSyntaxError("expected #endif");
+ }
+ return result.join("\n");
+}
+exports.preprocessDirectives = preprocessDirectives;
/**
* Takes the full text of a .lint file and returns the contents of the file
* with all error markup removed
@@ -193,8 +242,8 @@ exports.createMarkupFromErrors = createMarkupFromErrors;
/* tslint:enable:object-literal-sort-keys */
function createCodeLineNoToErrorsMap(lines) {
var errorLinesForCodeLine = [];
- for (var _i = 0, lines_2 = lines; _i < lines_2.length; _i++) {
- var line = lines_2[_i];
+ for (var _i = 0, lines_3 = lines; _i < lines_3.length; _i++) {
+ var line = lines_3[_i];
if (line instanceof lines_1.CodeLine) {
errorLinesForCodeLine.push([]);
}