From e0ce95a640629a6f6581e4990779e3107c5c35c3 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 2 Jan 2017 19:18:19 +0000 Subject: [PATCH] Breaking: Updated supported TypeScript version to ~2.2.1 (fixes #149) --- README.md | 4 ++-- lib/ast-converter.js | 23 ++++++----------------- package.json | 4 ++-- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 11cfae6..91e3cd3 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ A parser that converts TypeScript into an [ESTree](https://github.com/estree/est ## Supported TypeScript Version -The version of TypeScript supported by this parser is `2.0.x`. Please ensure that you are using this version before submitting any issues. +The version of TypeScript supported by this parser is `~2.2.1`. This is reflected in the `peerDependency` requirement within the package.json file. -Due to a bug in the TypeScript Compiler it was not possible to officially support TypeScript `2.1.x`, please see this issue for more details on using `2.1.x`: https://github.com/eslint/typescript-eslint-parser/issues/149 +**Please ensure that you are using this version before submitting any issues.** ## Usage diff --git a/lib/ast-converter.js b/lib/ast-converter.js index bedc205..d80831b 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -261,17 +261,6 @@ function fixExports(node, result, ast) { * @returns {boolean} is a token */ function isToken(node) { - /** - * Note: We treat JsxText like a token (TypeScript doesn't classify it as one), - * to prevent traversing into it and creating unintended addiontal tokens from - * its contents. - * - * It looks like this has been addressed in the master branch of TypeScript, so we can - * look to remove this extra check as part of the 2.2.x support - */ - if (node.kind === ts.SyntaxKind.JsxText) { - return true; - } return node.kind >= ts.SyntaxKind.FirstToken && node.kind <= ts.SyntaxKind.LastToken; } @@ -680,7 +669,7 @@ module.exports = function(ast, extra) { function deeplyCopy() { result.type = "TS" + SyntaxKind[node.kind]; Object.keys(node).filter(function(key) { - return !(/^(?:kind|parent|pos|end|flags)$/.test(key)); + return !(/^(?:kind|parent|pos|end|flags|modifierFlagsCache)$/.test(key)); }).forEach(function(key) { if (key === "type") { result.typeAnnotation = (node.type) ? convertTypeAnnotation(node.type) : null; @@ -1083,7 +1072,7 @@ module.exports = function(ast, extra) { key: convertChild(node.name), value: convertChild(node.initializer), computed: (node.name.kind === SyntaxKind.ComputedPropertyName), - static: Boolean(node.flags & ts.NodeFlags.Static), + static: Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static), accessibility: getTSNodeAccessibility(node), decorators: (node.decorators) ? node.decorators.map(function(d) { return convertChild(d.expression); @@ -1166,7 +1155,7 @@ module.exports = function(ast, extra) { key: convertChild(node.name), value: method, computed: isMethodNameComputed, - static: Boolean(node.flags & ts.NodeFlags.Static), + static: Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static), kind: "method", accessibility: getTSNodeAccessibility(node), decorators: (node.decorators) ? node.decorators.map(function(d) { @@ -1188,7 +1177,7 @@ module.exports = function(ast, extra) { // TypeScript uses this even for static methods named "constructor" case SyntaxKind.Constructor: - var constructorIsStatic = Boolean(node.flags & ts.NodeFlags.Static), + var constructorIsStatic = Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static), firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(), constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1), constructor = { @@ -1441,8 +1430,8 @@ module.exports = function(ast, extra) { // Patterns - // Note: TypeScript uses this for both spread and rest expressions - case SyntaxKind.SpreadElementExpression: + case SyntaxKind.SpreadElement: + case SyntaxKind.SpreadAssignment: assign(result, { type: "SpreadElement", argument: convertChild(node.expression) diff --git a/package.json b/package.json index 887fef7..251944a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "semver": "^4.1.1", "shelljs": "^0.3.0", "shelljs-nodecli": "^0.1.1", - "typescript": "~2.0.3" + "typescript": "~2.2.1" }, "keywords": [ "ast", @@ -55,6 +55,6 @@ "object-assign": "^4.0.1" }, "peerDependencies": { - "typescript": "~2.0.3" + "typescript": "~2.2.1" } }