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

Breaking: typescript-estree to 8.1.0 and typescript to 3.2.1 #589

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ _test.js
.vscode
yarn.lock
.eslint-release-info.json
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following additional configuration options are available by specifying them

We will always endeavor to support the latest stable version of TypeScript.

The version of TypeScript currently supported by this parser is `~3.1.1`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript.
The version of TypeScript currently supported by this parser is `~3.2.1`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript.

If you use a non-supported version of TypeScript, the parser will log a warning to the console.

Expand Down
131 changes: 111 additions & 20 deletions analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,6 @@ class Referencer extends OriginalReferencer {
super.MethodDefinition(node);
}

/**
* Override.
* Don't make variable if `kind === "type"`.
* It doesn't declare variables but declare types.
* @param {VariableDeclaration} node The VariableDeclaration node to visit.
* @returns {void}
*/
VariableDeclaration(node) {
if (node.kind !== "type") {
super.VariableDeclaration(node);
return;
}

// To detect typeof.
this.typeMode = true;
this.visitChildren(node);
this.typeMode = false;
}

/**
* Don't create the reference object for the key if not computed.
* @param {TSEmptyBodyFunctionDeclaration} node The TSEmptyBodyFunctionDeclaration node to visit.
Expand Down Expand Up @@ -337,6 +318,7 @@ class Referencer extends OriginalReferencer {
this.visit(returnType);
this.typeMode = upperTypeMode;
}

TSEmptyBodyDeclareFunction(node) {
this.TSEmptyBodyFunctionDeclaration(node);
}
Expand Down Expand Up @@ -418,9 +400,97 @@ class Referencer extends OriginalReferencer {
}
}

/**
* @param {TSTypeReference} node The TSTypeReference node to visit.
* @returns {void}
*/
TSTypeReference(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSTypeLiteral} node The TSTypeLiteral node to visit.
* @returns {void}
*/
TSTypeLiteral(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSLiteralType} node The TSLiteralType node to visit.
* @returns {void}
*/
TSLiteralType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSIntersectionType} node The TSIntersectionType node to visit.
* @returns {void}
*/
TSIntersectionType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSConditionalType} node The TSConditionalType node to visit.
* @returns {void}
*/
TSConditionalType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSIndexedAccessType} node The TSIndexedAccessType node to visit.
* @returns {void}
*/
TSIndexedAccessType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSMappedType} node The TSMappedType node to visit.
* @returns {void}
*/
TSMappedType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSOptionalType} node The TSOptionalType node to visit.
* @returns {void}
*/
TSOptionalType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSParenthesizedType} node The TSParenthesizedType node to visit.
* @returns {void}
*/
TSParenthesizedType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSRestType} node The TSRestType node to visit.
* @returns {void}
*/
TSRestType(node) {
this.visitTypeNodes(node);
}

/**
* @param {TSTupleType} node The TSTupleType node to visit.
* @returns {void}
*/
TSTupleType(node) {
this.visitTypeNodes(node);
}

/**
* Create reference objects for the object part. (This is `obj.prop`)
* @param {TSTypeQuery} node The TSTypeQuery node to visit.
* @param {TSQualifiedName} node The TSQualifiedName node to visit.
* @returns {void}
*/
TSQualifiedName(node) {
Expand Down Expand Up @@ -556,6 +626,12 @@ class Referencer extends OriginalReferencer {
this.visit(body);
}

TSTypeAliasDeclaration(node) {
this.typeMode = true;
this.visitChildren(node);
this.typeMode = false;
}

/**
* Process the module block.
* @param {TSModuleBlock} node The TSModuleBlock node to visit.
Expand Down Expand Up @@ -628,6 +704,21 @@ class Referencer extends OriginalReferencer {
decorators.forEach(this.visit, this);
}
}

/**
* Process all child of type nodes
* @param {any} node node to be processed
* @returns {void}
*/
visitTypeNodes(node) {
if (this.typeMode) {
this.visitChildren(node);
} else {
this.typeMode = true;
this.visitChildren(node);
this.typeMode = false;
}
}
}

module.exports = function(ast, parserOptions, extraOptions) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"eslint-scope": "^4.0.0",
"eslint-visitor-keys": "^1.0.0",
"typescript-estree": "5.3.0"
"typescript-estree": "8.1.0"
},
"devDependencies": {
"eslint": "^4.19.1",
Expand All @@ -57,7 +57,7 @@
"npm-license": "0.3.3",
"shelljs": "0.8.2",
"shelljs-nodecli": "0.1.1",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
},
"jest": {
"testEnvironment": "node",
Expand Down
4 changes: 2 additions & 2 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ exports.parseForESLint = function parseForESLint(code, options) {
enter: node => {
switch (node.type) {
// Just for backward compatibility.
case "DeclareFunction":
case "TSDeclareFunction":
if (!node.body) {
node.type = `TSEmptyBody${node.type}`;
node.type = "TSEmptyBodyDeclareFunction";
}
break;

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/bigIntLiterals/binary.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b1n;
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/bigIntLiterals/decimal.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1n;
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/bigIntLiterals/hex.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x1n;
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/bigIntLiterals/octal.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0o1n;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/type-alias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type foo = string
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-array-type.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Foo = string[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: number extends string ? boolean : null;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-conditional.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: number extends string ? boolean : string;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-indexed.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: T[K];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type LinkedList<T> = T & { next: LinkedList<T> };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let map: { -readonly [P in string]-?: number };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let map: { +readonly [P in string]+?: number; };
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-mapped-readonly.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let map: { readonly [P in string]?: number; };
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-mapped.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let map: { [P in string]: number; };
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-nested-types.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Foo = [number, string?, boolean?] | [{}, [number?] | null & boolean[]] & {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Foo = (string | number)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: Array<Array<number>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: Array<number>;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-reference.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: T;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-tuple-empty.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: [];
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-tuple-optional.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: [string, number?, (string | number)?]
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-tuple-rest.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: [string, ...number[]]
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-tuple-type.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Foo = [string, string?]
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-tuple.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: [number, number, number];
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-type-literal.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let obj: { x: number };
2 changes: 2 additions & 0 deletions tests/fixtures/scope-analysis/types-type-operator.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x: keyof T;
let y: unique symbol;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-typeof.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: typeof y.z;
4 changes: 4 additions & 0 deletions tests/fixtures/scope-analysis/types-union-intersection.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let union: number | null | undefined;
let intersection: number & string;
let precedence1: number | string & boolean;
let precedence2: number & string | boolean;
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/types-union-type.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Foo = string & number
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"eslint": "4.19.1",
"jest": "23.1.0",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
}
}
}
4 changes: 2 additions & 2 deletions tests/integration/jsdoc-indent-issues-344-422/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"eslint": "4.19.1",
"jest": "23.1.0",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
}
}
}
4 changes: 2 additions & 2 deletions tests/integration/method-overloads-issue-389/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"eslint": "4.19.1",
"jest": "23.1.0",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"eslint": "4.19.1",
"jest": "23.1.0",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
}
}
}
4 changes: 2 additions & 2 deletions tests/integration/range-error-indent-issue-333/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"eslint": "4.19.1",
"jest": "23.1.0",
"typescript": "~3.1.1"
"typescript": "~3.2.1"
}
}
}
Loading