Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit ae7c4e6

Browse filesBrowse files
armano2mysticatea
authored andcommitted
Fix: missing visitor-keys (#554)
- typeParameters in TSInterfaceDeclaration - decorators in Identifier - parameters in TSFunctionType
1 parent 9ed21cb commit ae7c4e6
Copy full SHA for ae7c4e6

File tree

Expand file treeCollapse file tree

5 files changed

+334
-3
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+334
-3
lines changed

‎analyze-scope.js

Copy file name to clipboardExpand all lines: analyze-scope.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,29 @@ class EnumScope extends Scope {
6969
class PatternVisitor extends OriginalPatternVisitor {
7070
Identifier(node) {
7171
super.Identifier(node);
72+
if (node.decorators) {
73+
this.rightHandNodes.push(...node.decorators);
74+
}
7275
if (node.typeAnnotation) {
7376
this.rightHandNodes.push(node.typeAnnotation);
7477
}
7578
}
7679

7780
ArrayPattern(node) {
7881
node.elements.forEach(this.visit, this);
82+
if (node.decorators) {
83+
this.rightHandNodes.push(...node.decorators);
84+
}
7985
if (node.typeAnnotation) {
8086
this.rightHandNodes.push(node.typeAnnotation);
8187
}
8288
}
8389

8490
ObjectPattern(node) {
8591
node.properties.forEach(this.visit, this);
92+
if (node.decorators) {
93+
this.rightHandNodes.push(...node.decorators);
94+
}
8695
if (node.typeAnnotation) {
8796
this.rightHandNodes.push(node.typeAnnotation);
8897
}
@@ -216,9 +225,12 @@ class Referencer extends OriginalReferencer {
216225
* @returns {void}
217226
*/
218227
Identifier(node) {
228+
this.visitDecorators(node.decorators);
229+
219230
if (!this.typeMode) {
220231
super.Identifier(node);
221232
}
233+
222234
this.visit(node.typeAnnotation);
223235
}
224236

+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class Test {
2+
constructor(@Decorator config) {
3+
}
4+
}
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface C<T = any> {
2+
3+
}
4+
5+
interface R<T extends C> {
6+
foo: C
7+
}

‎tests/lib/__snapshots__/scope-analysis.js.snap

Copy file name to clipboardExpand all lines: tests/lib/__snapshots__/scope-analysis.js.snap
+308Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,289 @@ Object {
29272927
}
29282928
`;
29292929

2930+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/identifier-decorators.ts 1`] = `
2931+
Object {
2932+
"$id": 8,
2933+
"block": Object {
2934+
"range": Array [
2935+
0,
2936+
65,
2937+
],
2938+
"type": "Program",
2939+
},
2940+
"childScopes": Array [
2941+
Object {
2942+
"$id": 7,
2943+
"block": Object {
2944+
"range": Array [
2945+
0,
2946+
65,
2947+
],
2948+
"type": "Program",
2949+
},
2950+
"childScopes": Array [
2951+
Object {
2952+
"$id": 6,
2953+
"block": Object {
2954+
"range": Array [
2955+
7,
2956+
64,
2957+
],
2958+
"type": "ClassDeclaration",
2959+
},
2960+
"childScopes": Array [
2961+
Object {
2962+
"$id": 5,
2963+
"block": Object {
2964+
"range": Array [
2965+
35,
2966+
62,
2967+
],
2968+
"type": "FunctionExpression",
2969+
},
2970+
"childScopes": Array [],
2971+
"functionExpressionScope": false,
2972+
"isStrict": true,
2973+
"references": Array [
2974+
Object {
2975+
"$id": 4,
2976+
"from": Object {
2977+
"$ref": 5,
2978+
},
2979+
"identifier": Object {
2980+
"name": "Decorator",
2981+
"range": Array [
2982+
37,
2983+
46,
2984+
],
2985+
"type": "Identifier",
2986+
},
2987+
"kind": "r",
2988+
"resolved": null,
2989+
"writeExpr": undefined,
2990+
},
2991+
],
2992+
"throughReferences": Array [
2993+
Object {
2994+
"$ref": 4,
2995+
},
2996+
],
2997+
"type": "function",
2998+
"upperScope": Object {
2999+
"$ref": 6,
3000+
},
3001+
"variableMap": Object {
3002+
"arguments": Object {
3003+
"$ref": 2,
3004+
},
3005+
"config": Object {
3006+
"$ref": 3,
3007+
},
3008+
},
3009+
"variableScope": Object {
3010+
"$ref": 5,
3011+
},
3012+
"variables": Array [
3013+
Object {
3014+
"$id": 2,
3015+
"defs": Array [],
3016+
"eslintUsed": undefined,
3017+
"identifiers": Array [],
3018+
"name": "arguments",
3019+
"references": Array [],
3020+
"scope": Object {
3021+
"$ref": 5,
3022+
},
3023+
},
3024+
Object {
3025+
"$id": 3,
3026+
"defs": Array [
3027+
Object {
3028+
"name": Object {
3029+
"name": "config",
3030+
"range": Array [
3031+
47,
3032+
53,
3033+
],
3034+
"type": "Identifier",
3035+
},
3036+
"node": Object {
3037+
"range": Array [
3038+
35,
3039+
62,
3040+
],
3041+
"type": "FunctionExpression",
3042+
},
3043+
"parent": null,
3044+
"type": "Parameter",
3045+
},
3046+
],
3047+
"eslintUsed": undefined,
3048+
"identifiers": Array [
3049+
Object {
3050+
"name": "config",
3051+
"range": Array [
3052+
47,
3053+
53,
3054+
],
3055+
"type": "Identifier",
3056+
},
3057+
],
3058+
"name": "config",
3059+
"references": Array [],
3060+
"scope": Object {
3061+
"$ref": 5,
3062+
},
3063+
},
3064+
],
3065+
},
3066+
],
3067+
"functionExpressionScope": false,
3068+
"isStrict": true,
3069+
"references": Array [],
3070+
"throughReferences": Array [
3071+
Object {
3072+
"$ref": 4,
3073+
},
3074+
],
3075+
"type": "class",
3076+
"upperScope": Object {
3077+
"$ref": 7,
3078+
},
3079+
"variableMap": Object {
3080+
"Test": Object {
3081+
"$ref": 1,
3082+
},
3083+
},
3084+
"variableScope": Object {
3085+
"$ref": 7,
3086+
},
3087+
"variables": Array [
3088+
Object {
3089+
"$id": 1,
3090+
"defs": Array [
3091+
Object {
3092+
"name": Object {
3093+
"name": "Test",
3094+
"range": Array [
3095+
13,
3096+
17,
3097+
],
3098+
"type": "Identifier",
3099+
},
3100+
"node": Object {
3101+
"range": Array [
3102+
7,
3103+
64,
3104+
],
3105+
"type": "ClassDeclaration",
3106+
},
3107+
"parent": undefined,
3108+
"type": "ClassName",
3109+
},
3110+
],
3111+
"eslintUsed": undefined,
3112+
"identifiers": Array [
3113+
Object {
3114+
"name": "Test",
3115+
"range": Array [
3116+
13,
3117+
17,
3118+
],
3119+
"type": "Identifier",
3120+
},
3121+
],
3122+
"name": "Test",
3123+
"references": Array [],
3124+
"scope": Object {
3125+
"$ref": 6,
3126+
},
3127+
},
3128+
],
3129+
},
3130+
],
3131+
"functionExpressionScope": false,
3132+
"isStrict": true,
3133+
"references": Array [],
3134+
"throughReferences": Array [
3135+
Object {
3136+
"$ref": 4,
3137+
},
3138+
],
3139+
"type": "module",
3140+
"upperScope": Object {
3141+
"$ref": 8,
3142+
},
3143+
"variableMap": Object {
3144+
"Test": Object {
3145+
"$ref": 0,
3146+
},
3147+
},
3148+
"variableScope": Object {
3149+
"$ref": 7,
3150+
},
3151+
"variables": Array [
3152+
Object {
3153+
"$id": 0,
3154+
"defs": Array [
3155+
Object {
3156+
"name": Object {
3157+
"name": "Test",
3158+
"range": Array [
3159+
13,
3160+
17,
3161+
],
3162+
"type": "Identifier",
3163+
},
3164+
"node": Object {
3165+
"range": Array [
3166+
7,
3167+
64,
3168+
],
3169+
"type": "ClassDeclaration",
3170+
},
3171+
"parent": null,
3172+
"type": "ClassName",
3173+
},
3174+
],
3175+
"eslintUsed": undefined,
3176+
"identifiers": Array [
3177+
Object {
3178+
"name": "Test",
3179+
"range": Array [
3180+
13,
3181+
17,
3182+
],
3183+
"type": "Identifier",
3184+
},
3185+
],
3186+
"name": "Test",
3187+
"references": Array [],
3188+
"scope": Object {
3189+
"$ref": 7,
3190+
},
3191+
},
3192+
],
3193+
},
3194+
],
3195+
"functionExpressionScope": false,
3196+
"isStrict": false,
3197+
"references": Array [],
3198+
"throughReferences": Array [
3199+
Object {
3200+
"$ref": 4,
3201+
},
3202+
],
3203+
"type": "global",
3204+
"upperScope": null,
3205+
"variableMap": Object {},
3206+
"variableScope": Object {
3207+
"$ref": 8,
3208+
},
3209+
"variables": Array [],
3210+
}
3211+
`;
3212+
29303213
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/ignore-type-only-stuff.ts 1`] = `
29313214
Object {
29323215
"$id": 1,
@@ -3003,6 +3286,31 @@ Object {
30033286
}
30043287
`;
30053288

3289+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/interface-type.ts 1`] = `
3290+
Object {
3291+
"$id": 0,
3292+
"block": Object {
3293+
"range": Array [
3294+
0,
3295+
67,
3296+
],
3297+
"type": "Program",
3298+
},
3299+
"childScopes": Array [],
3300+
"functionExpressionScope": false,
3301+
"isStrict": false,
3302+
"references": Array [],
3303+
"throughReferences": Array [],
3304+
"type": "global",
3305+
"upperScope": null,
3306+
"variableMap": Object {},
3307+
"variableScope": Object {
3308+
"$ref": 0,
3309+
},
3310+
"variables": Array [],
3311+
}
3312+
`;
3313+
30063314
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/method-overload.ts 1`] = `
30073315
Object {
30083316
"$id": 10,

‎visitor-keys.js

Copy file name to clipboardExpand all lines: visitor-keys.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = Evk.unionWith({
1616
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "body"],
1717
FunctionDeclaration: ["id", "typeParameters", "params", "returnType", "body"],
1818
FunctionExpression: ["id", "typeParameters", "params", "returnType", "body"],
19-
Identifier: ["typeAnnotation"],
19+
Identifier: ["decorators", "typeAnnotation"],
2020
MethodDefinition: ["decorators", "key", "value"],
2121
ObjectPattern: ["properties", "typeAnnotation"],
2222

@@ -46,9 +46,9 @@ module.exports = Evk.unionWith({
4646
TSLiteralType: ["literal"],
4747
TSIndexSignature: ["typeAnnotation", "index"],
4848
TSInterfaceBody: ["body"],
49-
TSInterfaceDeclaration: ["body", "id", "heritage"],
49+
TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"],
5050
TSInterfaceHeritage: ["id", "typeParameters"],
51-
TSFunctionType: ["typeAnnotation"],
51+
TSFunctionType: ["parameters", "typeAnnotation"],
5252
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
5353
TSModuleBlock: ["body"],
5454
TSModuleDeclaration: ["id", "body"],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.