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

Commit

Permalink
Upgrade: typescript-estree to 8.1.0 and add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Dec 28, 2018
1 parent 18598d9 commit 34adb5d
Show file tree
Hide file tree
Showing 30 changed files with 1,897 additions and 22 deletions.
105 changes: 104 additions & 1 deletion analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,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 @@ -616,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
2 changes: 1 addition & 1 deletion 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": "^7.0.0"
"typescript-estree": "8.1.0"
},
"devDependencies": {
"eslint": "^4.19.1",
Expand Down
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
17 changes: 17 additions & 0 deletions tests/lib/__snapshots__/ecma-features.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-default-param-eval.sr
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -2730,6 +2731,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-dup-params.src 1`] =
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -3072,6 +3074,7 @@ Object {
"body": Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -3404,6 +3407,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-eval-return.src 1`] =
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -3669,6 +3673,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-octal.src 1`] = `
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -3952,6 +3957,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-arguments.src 1
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -4289,6 +4295,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-eval.src 1`] =
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -4626,6 +4633,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-names.src 1`] =
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -4963,6 +4971,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-no-paren-argume
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -5210,6 +5219,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-no-paren-eval.s
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -93424,6 +93434,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/error-proto-prop
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94125,6 +94136,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/error-proto-stri
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -94828,6 +94840,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/strict-duplicate
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -95350,6 +95363,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/strict-duplicate
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -99632,6 +99646,7 @@ exports[`ecmaFeatures fixtures/octalLiterals/strict-uppercase.src 1`] = `
Object {
"body": Array [
Object {
"directive": "use strict",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -107763,6 +107778,7 @@ exports[`ecmaFeatures fixtures/unicodeCodePointEscapes/basic-string-literal.src
Object {
"body": Array [
Object {
"directive": "\\\\u{714E}\\\\u{8336}",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -107861,6 +107877,7 @@ exports[`ecmaFeatures fixtures/unicodeCodePointEscapes/complex-string-literal.sr
Object {
"body": Array [
Object {
"directive": "\\\\u{20BB7}\\\\u{10FFFF}\\\\u{1}",
"expression": Object {
"loc": Object {
"end": Object {
Expand Down
Loading

0 comments on commit 34adb5d

Please sign in to comment.