Skip to content

Commit 095c33a

Browse files
committed
type check source files
1 parent 951db73 commit 095c33a

File tree

11 files changed

+108
-35
lines changed

11 files changed

+108
-35
lines changed

packages/eslint-scope/lib/definition.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424

2525
import Variable from "./variable.js";
2626

27+
/** @import * as types from "eslint-scope" */
28+
2729
/**
2830
* @constructor Definition
31+
* @implements {types.Definition}
2932
*/
3033
class Definition {
3134
constructor(type, name, node, parent, index, kind) {

packages/eslint-scope/lib/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import Variable from "./variable.js";
5555

5656
import eslintScopeVersion from "./version.js";
5757

58+
/** @import ESTree from "estree" */
59+
5860
/**
5961
* Set the default options
6062
* @returns {Object} options
@@ -73,9 +75,9 @@ function defaultOptions() {
7375

7476
/**
7577
* Preform deep update on option object
76-
* @param {Object} target Options
77-
* @param {Object} override Updates
78-
* @returns {Object} Updated options
78+
* @param {Record<string, any>} target Options
79+
* @param {Record<string, any>} override Updates
80+
* @returns {Record<string, any>} Updated options
7981
*/
8082
function updateDeeply(target, override) {
8183

@@ -110,7 +112,7 @@ function updateDeeply(target, override) {
110112
* Main interface function. Takes an Espree syntax tree and returns the
111113
* analyzed scopes.
112114
* @function analyze
113-
* @param {espree.Tree} tree Abstract Syntax Tree
115+
* @param {ESTree.Program} tree Abstract Syntax Tree
114116
* @param {Object} providedOptions Options that tailor the scope analysis
115117
* @param {boolean} [providedOptions.optimistic=false] the optimistic flag
116118
* @param {boolean} [providedOptions.ignoreEval=false] whether to check 'eval()' calls

packages/eslint-scope/lib/pattern-visitor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import estraverse from "estraverse";
2626
import esrecurse from "esrecurse";
2727

28+
/** @import * as types from "eslint-scope" */
29+
2830
const { Syntax } = estraverse;
2931

3032
/**
@@ -38,6 +40,7 @@ function getLast(xs) {
3840

3941
/**
4042
* Visitor for destructuring patterns.
43+
* @implements {types.PatternVisitor}
4144
*/
4245
class PatternVisitor extends esrecurse.Visitor {
4346
static isPattern(node) {

packages/eslint-scope/lib/reference.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2323
*/
2424

25+
/** @import * as types from "eslint-scope" */
26+
2527
const READ = 0x1;
2628
const WRITE = 0x2;
2729
const RW = READ | WRITE;
2830

2931
/**
3032
* A Reference represents a single occurrence of an identifier in code.
3133
* @constructor Reference
34+
* @implements {types.Reference}
3235
*/
3336
class Reference {
3437
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
@@ -62,7 +65,6 @@ class Reference {
6265
* The read-write mode of the reference. (Value is one of {@link
6366
* Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
6467
* @member {number} Reference#flag
65-
* @private
6668
*/
6769
this.flag = flag;
6870
if (this.isWrite()) {
@@ -94,7 +96,7 @@ class Reference {
9496
* @returns {boolean} static
9597
*/
9698
isStatic() {
97-
return !this.tainted && this.resolved && this.resolved.scope.isStatic();
99+
return !this.tainted && !!this.resolved && this.resolved.scope.isStatic();
98100
}
99101

100102
/**
@@ -145,19 +147,16 @@ class Reference {
145147

146148
/**
147149
* @constant Reference.READ
148-
* @private
149150
*/
150151
Reference.READ = READ;
151152

152153
/**
153154
* @constant Reference.WRITE
154-
* @private
155155
*/
156156
Reference.WRITE = WRITE;
157157

158158
/**
159159
* @constant Reference.RW
160-
* @private
161160
*/
162161
Reference.RW = RW;
163162

packages/eslint-scope/lib/referencer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ import PatternVisitor from "./pattern-visitor.js";
3030
import { Definition, ParameterDefinition } from "./definition.js";
3131
import { assert } from "./assert.js";
3232

33+
/** @import * as types from "eslint-scope" */
34+
/** @import ESTree from "estree" */
35+
3336
const { Syntax } = estraverse;
3437

3538
/**
3639
* Traverse identifier in pattern
3740
* @param {Object} options options
38-
* @param {pattern} rootPattern root pattern
39-
* @param {Refencer} referencer referencer
40-
* @param {callback} callback callback
41+
* @param {ESTree.Pattern} rootPattern root pattern
42+
* @param {?Referencer} referencer referencer
43+
* @param {types.PatternVisitorCallback} callback callback
4144
* @returns {void}
4245
*/
4346
function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
@@ -209,7 +212,7 @@ class Referencer extends esrecurse.Visitor {
209212

210213
/**
211214
* Visit pattern callback
212-
* @param {pattern} pattern pattern
215+
* @param {ESTree.Pattern} pattern pattern
213216
* @param {Object} info info
214217
* @returns {void}
215218
*/

packages/eslint-scope/lib/scope-manager.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ import {
3838
} from "./scope.js";
3939
import { assert } from "./assert.js";
4040

41+
/** @import * as types from "eslint-scope" */
42+
/** @import ESTree from "estree" */
43+
/** @import { Scope } from "./scope.js" */
44+
/** @import Variable from "./variable.js" */
45+
4146
/**
4247
* @constructor ScopeManager
48+
* @implements {types.ScopeManager}
4349
*/
4450
class ScopeManager {
4551
constructor(options) {
@@ -72,10 +78,12 @@ class ScopeManager {
7278
}
7379

7480
isImpliedStrict() {
75-
return this.__options.impliedStrict;
81+
return !!this.__options.impliedStrict;
7682
}
7783

7884
isStrictModeSupported() {
85+
86+
// @ts-ignore -- if ecmaVersion is undefined, the comparison returns false.
7987
return this.__options.ecmaVersion >= 5;
8088
}
8189

@@ -90,7 +98,7 @@ class ScopeManager {
9098
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
9199
* If the node declares nothing, this method returns an empty array.
92100
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
93-
* @param {Espree.Node} node a node to get.
101+
* @param {ESTree.Node} node a node to get.
94102
* @returns {Variable[]} variables that declared by the node.
95103
*/
96104
getDeclaredVariables(node) {
@@ -100,7 +108,7 @@ class ScopeManager {
100108
/**
101109
* acquire scope from node.
102110
* @function ScopeManager#acquire
103-
* @param {Espree.Node} node node for the acquired scope.
111+
* @param {ESTree.Node} node node for the acquired scope.
104112
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
105113
* @returns {Scope?} Scope from node
106114
*/
@@ -154,8 +162,8 @@ class ScopeManager {
154162
/**
155163
* acquire all scopes from node.
156164
* @function ScopeManager#acquireAll
157-
* @param {Espree.Node} node node for the acquired scope.
158-
* @returns {Scopes?} Scope array
165+
* @param {ESTree.Node} node node for the acquired scope.
166+
* @returns {Scope[]?} Scope array
159167
*/
160168
acquireAll(node) {
161169
return this.__get(node);
@@ -164,7 +172,7 @@ class ScopeManager {
164172
/**
165173
* release the node.
166174
* @function ScopeManager#release
167-
* @param {Espree.Node} node releasing node.
175+
* @param {ESTree.Node} node releasing node.
168176
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
169177
* @returns {Scope?} upper scope for the node.
170178
*/
@@ -189,6 +197,8 @@ class ScopeManager {
189197
* @returns {void}
190198
*/
191199
addGlobals(names) {
200+
201+
// @ts-ignore -- globalScope must be set before this method is called.
192202
this.globalScope.__addVariables(names);
193203
}
194204

@@ -254,6 +264,8 @@ class ScopeManager {
254264
}
255265

256266
__isES6() {
267+
268+
// @ts-ignore -- if ecmaVersion is undefined, the comparison returns false.
257269
return this.__options.ecmaVersion >= 6;
258270
}
259271
}

0 commit comments

Comments
 (0)