aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/verify
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/verify')
-rw-r--r--node_modules/tslint/lib/verify/lines.js8
-rw-r--r--node_modules/tslint/lib/verify/lintError.d.ts1
-rw-r--r--node_modules/tslint/lib/verify/lintError.js3
-rw-r--r--node_modules/tslint/lib/verify/parse.d.ts2
-rw-r--r--node_modules/tslint/lib/verify/parse.js53
5 files changed, 58 insertions, 9 deletions
diff --git a/node_modules/tslint/lib/verify/lines.js b/node_modules/tslint/lib/verify/lines.js
index 3b15c0875..9fb0f5ef2 100644
--- a/node_modules/tslint/lib/verify/lines.js
+++ b/node_modules/tslint/lib/verify/lines.js
@@ -86,12 +86,12 @@ exports.ZERO_LENGTH_ERROR = "~nil";
*/
function parseLine(text) {
var multilineErrorMatch = text.match(multilineErrorRegex);
- if (multilineErrorMatch != null) {
+ if (multilineErrorMatch !== null) {
var startErrorCol = text.indexOf("~");
return new MultilineErrorLine(startErrorCol);
}
var endErrorMatch = text.match(endErrorRegex);
- if (endErrorMatch != null) {
+ if (endErrorMatch !== null) {
var squiggles = endErrorMatch[1], message = endErrorMatch[2];
var startErrorCol = text.indexOf("~");
var zeroLengthError = (squiggles === exports.ZERO_LENGTH_ERROR);
@@ -99,7 +99,7 @@ function parseLine(text) {
return new EndErrorLine(startErrorCol, endErrorCol, message);
}
var messageSubstitutionMatch = text.match(messageSubstitutionRegex);
- if (messageSubstitutionMatch != null) {
+ if (messageSubstitutionMatch !== null) {
var key = messageSubstitutionMatch[1], message = messageSubstitutionMatch[2];
return new MessageSubstitutionLine(key, message);
}
@@ -117,7 +117,7 @@ exports.parseLine = parseLine;
*/
function printLine(line, code) {
if (line instanceof ErrorLine) {
- if (code == null) {
+ if (code === undefined) {
throw new Error("Must supply argument for code parameter when line is an ErrorLine");
}
var leadingSpaces = " ".repeat(line.startCol);
diff --git a/node_modules/tslint/lib/verify/lintError.d.ts b/node_modules/tslint/lib/verify/lintError.d.ts
index c00b4b535..a1b9f821a 100644
--- a/node_modules/tslint/lib/verify/lintError.d.ts
+++ b/node_modules/tslint/lib/verify/lintError.d.ts
@@ -1,4 +1,3 @@
-import { Error } from "../error";
export interface PositionInFile {
line: number;
col: number;
diff --git a/node_modules/tslint/lib/verify/lintError.js b/node_modules/tslint/lib/verify/lintError.js
index d784537c1..b57661299 100644
--- a/node_modules/tslint/lib/verify/lintError.js
+++ b/node_modules/tslint/lib/verify/lintError.js
@@ -15,7 +15,6 @@
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
-var error_1 = require("../error");
function errorComparator(err1, err2) {
if (err1.startPos.line !== err2.startPos.line) {
return err1.startPos.line - err2.startPos.line;
@@ -35,6 +34,6 @@ function errorComparator(err1, err2) {
}
exports.errorComparator = errorComparator;
function lintSyntaxError(message) {
- return new error_1.Error("Lint File Syntax Error: " + message);
+ return new Error("Lint File Syntax Error: " + message);
}
exports.lintSyntaxError = lintSyntaxError;
diff --git a/node_modules/tslint/lib/verify/parse.d.ts b/node_modules/tslint/lib/verify/parse.d.ts
index db31418a1..12e9535e8 100644
--- a/node_modules/tslint/lib/verify/parse.d.ts
+++ b/node_modules/tslint/lib/verify/parse.d.ts
@@ -1,5 +1,7 @@
import { LintError } from "./lintError";
export declare function getTypescriptVersionRequirement(text: string): string | undefined;
+export declare function getNormalizedTypescriptVersion(): string;
+export declare function preprocessDirectives(text: string): string;
/**
* Takes the full text of a .lint file and returns the contents of the file
* with all error markup removed
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([]);
}