eslint-plugin-jsdoc 39.3.6 → 39.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -52
- package/dist/WarnSettings.js +0 -5
- package/dist/WarnSettings.js.map +1 -1
- package/dist/alignTransform.js +69 -61
- package/dist/alignTransform.js.map +1 -1
- package/dist/bin/generateRule.js +7 -26
- package/dist/bin/generateRule.js.map +1 -1
- package/dist/defaultTagOrder.js +30 -14
- package/dist/defaultTagOrder.js.map +1 -1
- package/dist/exportParser.js +34 -143
- package/dist/exportParser.js.map +1 -1
- package/dist/generateRule.js +7 -26
- package/dist/generateRule.js.map +1 -1
- package/dist/getDefaultTagStructureForMode.js +189 -93
- package/dist/getDefaultTagStructureForMode.js.map +1 -1
- package/dist/index.js +0 -51
- package/dist/index.js.map +1 -1
- package/dist/iterateJsdoc.js +43 -206
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/jsdocUtils.js +71 -220
- package/dist/jsdocUtils.js.map +1 -1
- package/dist/rules/checkAccess.js +0 -8
- package/dist/rules/checkAccess.js.map +1 -1
- package/dist/rules/checkAlignment.js +0 -8
- package/dist/rules/checkAlignment.js.map +1 -1
- package/dist/rules/checkExamples.js +25 -63
- package/dist/rules/checkExamples.js.map +1 -1
- package/dist/rules/checkIndentation.js +0 -7
- package/dist/rules/checkIndentation.js.map +1 -1
- package/dist/rules/checkLineAlignment.js +9 -30
- package/dist/rules/checkLineAlignment.js.map +1 -1
- package/dist/rules/checkParamNames.js +9 -47
- package/dist/rules/checkParamNames.js.map +1 -1
- package/dist/rules/checkPropertyNames.js +1 -18
- package/dist/rules/checkPropertyNames.js.map +1 -1
- package/dist/rules/checkSyntax.js +2 -5
- package/dist/rules/checkSyntax.js.map +1 -1
- package/dist/rules/checkTagNames.js +0 -18
- package/dist/rules/checkTagNames.js.map +1 -1
- package/dist/rules/checkTypes.js +17 -46
- package/dist/rules/checkTypes.js.map +1 -1
- package/dist/rules/checkValues.js +0 -18
- package/dist/rules/checkValues.js.map +1 -1
- package/dist/rules/emptyTags.js +6 -11
- package/dist/rules/emptyTags.js.map +1 -1
- package/dist/rules/implementsOnClasses.js +0 -6
- package/dist/rules/implementsOnClasses.js.map +1 -1
- package/dist/rules/matchDescription.js +0 -20
- package/dist/rules/matchDescription.js.map +1 -1
- package/dist/rules/matchName.js +2 -17
- package/dist/rules/matchName.js.map +1 -1
- package/dist/rules/multilineBlocks.js +10 -34
- package/dist/rules/multilineBlocks.js.map +1 -1
- package/dist/rules/newlineAfterDescription.js +0 -8
- package/dist/rules/newlineAfterDescription.js.map +1 -1
- package/dist/rules/noBadBlocks.js +2 -16
- package/dist/rules/noBadBlocks.js.map +1 -1
- package/dist/rules/noDefaults.js +0 -7
- package/dist/rules/noDefaults.js.map +1 -1
- package/dist/rules/noMissingSyntax.js +2 -16
- package/dist/rules/noMissingSyntax.js.map +1 -1
- package/dist/rules/noMultiAsterisks.js +2 -16
- package/dist/rules/noMultiAsterisks.js.map +1 -1
- package/dist/rules/noRestrictedSyntax.js +3 -9
- package/dist/rules/noRestrictedSyntax.js.map +1 -1
- package/dist/rules/noTypes.js +0 -7
- package/dist/rules/noTypes.js.map +1 -1
- package/dist/rules/noUndefinedTypes.js +13 -34
- package/dist/rules/noUndefinedTypes.js.map +1 -1
- package/dist/rules/requireAsteriskPrefix.js +2 -26
- package/dist/rules/requireAsteriskPrefix.js.map +1 -1
- package/dist/rules/requireDescription.js +0 -17
- package/dist/rules/requireDescription.js.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +13 -34
- package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
- package/dist/rules/requireExample.js +0 -9
- package/dist/rules/requireExample.js.map +1 -1
- package/dist/rules/requireFileOverview.js +0 -16
- package/dist/rules/requireFileOverview.js.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +2 -16
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
- package/dist/rules/requireJsdoc.js +13 -58
- package/dist/rules/requireJsdoc.js.map +1 -1
- package/dist/rules/requireParam.js +6 -53
- package/dist/rules/requireParam.js.map +1 -1
- package/dist/rules/requireParamDescription.js +0 -4
- package/dist/rules/requireParamDescription.js.map +1 -1
- package/dist/rules/requireParamName.js +0 -4
- package/dist/rules/requireParamName.js.map +1 -1
- package/dist/rules/requireParamType.js +0 -4
- package/dist/rules/requireParamType.js.map +1 -1
- package/dist/rules/requireProperty.js +0 -9
- package/dist/rules/requireProperty.js.map +1 -1
- package/dist/rules/requirePropertyDescription.js +0 -4
- package/dist/rules/requirePropertyDescription.js.map +1 -1
- package/dist/rules/requirePropertyName.js +0 -4
- package/dist/rules/requirePropertyName.js.map +1 -1
- package/dist/rules/requirePropertyType.js +0 -4
- package/dist/rules/requirePropertyType.js.map +1 -1
- package/dist/rules/requireReturns.js +13 -23
- package/dist/rules/requireReturns.js.map +1 -1
- package/dist/rules/requireReturnsCheck.js +12 -20
- package/dist/rules/requireReturnsCheck.js.map +1 -1
- package/dist/rules/requireReturnsDescription.js +0 -6
- package/dist/rules/requireReturnsDescription.js.map +1 -1
- package/dist/rules/requireReturnsType.js +0 -4
- package/dist/rules/requireReturnsType.js.map +1 -1
- package/dist/rules/requireThrows.js +6 -15
- package/dist/rules/requireThrows.js.map +1 -1
- package/dist/rules/requireYields.js +13 -29
- package/dist/rules/requireYields.js.map +1 -1
- package/dist/rules/requireYieldsCheck.js +8 -29
- package/dist/rules/requireYieldsCheck.js.map +1 -1
- package/dist/rules/sortTags.js +17 -30
- package/dist/rules/sortTags.js.map +1 -1
- package/dist/rules/tagLines.js +0 -26
- package/dist/rules/tagLines.js.map +1 -1
- package/dist/rules/validTypes.js +22 -53
- package/dist/rules/validTypes.js.map +1 -1
- package/dist/tagNames.js +7 -4
- package/dist/tagNames.js.map +1 -1
- package/dist/utils/hasReturnValue.js +22 -66
- package/dist/utils/hasReturnValue.js.map +1 -1
- package/package.json +16 -16
package/dist/exportParser.js
CHANGED
|
@@ -4,39 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
9
|
-
|
|
10
8
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const debug = (0, _debug.default)('requireExportJsdoc');
|
|
15
|
-
|
|
16
11
|
const createNode = function () {
|
|
17
12
|
return {
|
|
18
13
|
props: {}
|
|
19
14
|
};
|
|
20
15
|
};
|
|
21
|
-
|
|
22
16
|
const getSymbolValue = function (symbol) {
|
|
23
17
|
/* istanbul ignore next */
|
|
24
18
|
if (!symbol) {
|
|
25
19
|
/* istanbul ignore next */
|
|
26
20
|
return null;
|
|
27
21
|
}
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
|
|
30
22
|
|
|
23
|
+
/* istanbul ignore next */
|
|
31
24
|
if (symbol.type === 'literal') {
|
|
32
25
|
return symbol.value.value;
|
|
33
26
|
}
|
|
34
|
-
/* istanbul ignore next */
|
|
35
|
-
|
|
36
27
|
|
|
28
|
+
/* istanbul ignore next */
|
|
37
29
|
return null;
|
|
38
30
|
};
|
|
39
|
-
|
|
40
31
|
const getIdentifier = function (node, globals, scope, opts) {
|
|
41
32
|
if (opts.simpleIdentifier) {
|
|
42
33
|
// Type is Identier for noncomputed properties
|
|
@@ -47,38 +38,34 @@ const getIdentifier = function (node, globals, scope, opts) {
|
|
|
47
38
|
};
|
|
48
39
|
return identifierLiteral;
|
|
49
40
|
}
|
|
50
|
-
/* istanbul ignore next */
|
|
51
|
-
|
|
52
41
|
|
|
53
|
-
|
|
42
|
+
/* istanbul ignore next */
|
|
43
|
+
const block = scope || globals;
|
|
54
44
|
|
|
45
|
+
// As scopes are not currently supported, they are not traversed upwards recursively
|
|
55
46
|
if (block.props[node.name]) {
|
|
56
47
|
return block.props[node.name];
|
|
57
|
-
}
|
|
48
|
+
}
|
|
58
49
|
|
|
50
|
+
// Seems this will only be entered once scopes added and entered
|
|
59
51
|
/* istanbul ignore next */
|
|
60
|
-
|
|
61
|
-
|
|
62
52
|
if (globals.props[node.name]) {
|
|
63
53
|
return globals.props[node.name];
|
|
64
54
|
}
|
|
65
|
-
|
|
66
55
|
return null;
|
|
67
56
|
};
|
|
57
|
+
let createSymbol = null;
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
// eslint-disable-next-line complexity
|
|
71
60
|
const getSymbol = function (node, globals, scope, opt) {
|
|
72
61
|
const opts = opt || {};
|
|
73
62
|
/* istanbul ignore next */
|
|
74
63
|
// eslint-disable-next-line default-case
|
|
75
|
-
|
|
76
64
|
switch (node.type) {
|
|
77
65
|
case 'Identifier':
|
|
78
66
|
{
|
|
79
67
|
return getIdentifier(node, globals, scope, opts);
|
|
80
68
|
}
|
|
81
|
-
|
|
82
69
|
case 'MemberExpression':
|
|
83
70
|
{
|
|
84
71
|
const obj = getSymbol(node.object, globals, scope, opts);
|
|
@@ -86,33 +73,29 @@ const getSymbol = function (node, globals, scope, opt) {
|
|
|
86
73
|
simpleIdentifier: !node.computed
|
|
87
74
|
});
|
|
88
75
|
const propertyValue = getSymbolValue(propertySymbol);
|
|
89
|
-
/* istanbul ignore next */
|
|
90
76
|
|
|
77
|
+
/* istanbul ignore next */
|
|
91
78
|
if (obj && propertyValue && obj.props[propertyValue]) {
|
|
92
79
|
const block = obj.props[propertyValue];
|
|
93
80
|
return block;
|
|
94
81
|
}
|
|
82
|
+
|
|
95
83
|
/*
|
|
96
84
|
if (opts.createMissingProps && propertyValue) {
|
|
97
85
|
obj.props[propertyValue] = createNode();
|
|
98
86
|
return obj.props[propertyValue];
|
|
99
87
|
}
|
|
100
88
|
*/
|
|
101
|
-
|
|
102
89
|
/* istanbul ignore next */
|
|
103
|
-
|
|
104
|
-
|
|
105
90
|
debug(`MemberExpression: Missing property ${node.property.name}`);
|
|
106
|
-
/* istanbul ignore next */
|
|
107
91
|
|
|
92
|
+
/* istanbul ignore next */
|
|
108
93
|
return null;
|
|
109
94
|
}
|
|
110
|
-
|
|
111
95
|
case 'ClassExpression':
|
|
112
96
|
{
|
|
113
97
|
return getSymbol(node.body, globals, scope, opts);
|
|
114
98
|
}
|
|
115
|
-
|
|
116
99
|
case 'TSTypeAliasDeclaration':
|
|
117
100
|
case 'TSEnumDeclaration':
|
|
118
101
|
case 'TSInterfaceDeclaration':
|
|
@@ -128,50 +111,42 @@ const getSymbol = function (node, globals, scope, opt) {
|
|
|
128
111
|
val.value = node;
|
|
129
112
|
return val;
|
|
130
113
|
}
|
|
131
|
-
|
|
132
114
|
case 'AssignmentExpression':
|
|
133
115
|
{
|
|
134
116
|
return createSymbol(node.left, globals, node.right, scope, opts);
|
|
135
117
|
}
|
|
136
|
-
|
|
137
118
|
case 'ClassBody':
|
|
138
119
|
{
|
|
139
120
|
const val = createNode();
|
|
140
|
-
|
|
141
121
|
for (const method of node.body) {
|
|
142
122
|
val.props[method.key.name] = createNode();
|
|
143
123
|
val.props[method.key.name].type = 'object';
|
|
144
124
|
val.props[method.key.name].value = method.value;
|
|
145
125
|
}
|
|
146
|
-
|
|
147
126
|
val.type = 'object';
|
|
148
127
|
val.value = node.parent;
|
|
149
128
|
return val;
|
|
150
129
|
}
|
|
151
|
-
|
|
152
130
|
case 'ObjectExpression':
|
|
153
131
|
{
|
|
154
132
|
const val = createNode();
|
|
155
133
|
val.type = 'object';
|
|
156
|
-
|
|
157
134
|
for (const prop of node.properties) {
|
|
158
|
-
if ([
|
|
159
|
-
|
|
135
|
+
if ([
|
|
136
|
+
// @typescript-eslint/parser, espree, acorn, etc.
|
|
137
|
+
'SpreadElement',
|
|
138
|
+
// @babel/eslint-parser
|
|
160
139
|
'ExperimentalSpreadProperty'].includes(prop.type)) {
|
|
161
140
|
continue;
|
|
162
141
|
}
|
|
163
|
-
|
|
164
142
|
const propVal = getSymbol(prop.value, globals, scope, opts);
|
|
165
143
|
/* istanbul ignore next */
|
|
166
|
-
|
|
167
144
|
if (propVal) {
|
|
168
145
|
val.props[prop.key.name] = propVal;
|
|
169
146
|
}
|
|
170
147
|
}
|
|
171
|
-
|
|
172
148
|
return val;
|
|
173
149
|
}
|
|
174
|
-
|
|
175
150
|
case 'Literal':
|
|
176
151
|
{
|
|
177
152
|
const val = createNode();
|
|
@@ -180,34 +155,28 @@ const getSymbol = function (node, globals, scope, opt) {
|
|
|
180
155
|
return val;
|
|
181
156
|
}
|
|
182
157
|
}
|
|
183
|
-
/* istanbul ignore next */
|
|
184
|
-
|
|
185
158
|
|
|
159
|
+
/* istanbul ignore next */
|
|
186
160
|
return null;
|
|
187
161
|
};
|
|
188
|
-
|
|
189
162
|
const createBlockSymbol = function (block, name, value, globals, isGlobal) {
|
|
190
163
|
block.props[name] = value;
|
|
191
|
-
|
|
192
164
|
if (isGlobal && globals.props.window && globals.props.window.special) {
|
|
193
165
|
globals.props.window.props[name] = value;
|
|
194
166
|
}
|
|
195
167
|
};
|
|
196
|
-
|
|
197
168
|
createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
198
169
|
const block = scope || globals;
|
|
199
|
-
let symbol;
|
|
200
|
-
|
|
170
|
+
let symbol;
|
|
171
|
+
// eslint-disable-next-line default-case
|
|
201
172
|
switch (node.type) {
|
|
202
173
|
case 'FunctionDeclaration':
|
|
203
174
|
/* istanbul ignore next */
|
|
204
175
|
// Fall through
|
|
205
|
-
|
|
206
176
|
case 'TSEnumDeclaration':
|
|
207
177
|
case 'TSInterfaceDeclaration':
|
|
208
178
|
/* istanbul ignore next */
|
|
209
179
|
// Fall through
|
|
210
|
-
|
|
211
180
|
case 'TSTypeAliasDeclaration':
|
|
212
181
|
case 'ClassDeclaration':
|
|
213
182
|
{
|
|
@@ -215,36 +184,30 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
|
215
184
|
if (node.id && node.id.type === 'Identifier') {
|
|
216
185
|
return createSymbol(node.id, globals, node, globals);
|
|
217
186
|
}
|
|
218
|
-
/* istanbul ignore next */
|
|
219
|
-
|
|
220
187
|
|
|
188
|
+
/* istanbul ignore next */
|
|
221
189
|
break;
|
|
222
190
|
}
|
|
223
|
-
|
|
224
191
|
case 'Identifier':
|
|
225
192
|
{
|
|
226
193
|
if (value) {
|
|
227
194
|
const valueSymbol = getSymbol(value, globals, block);
|
|
228
195
|
/* istanbul ignore next */
|
|
229
|
-
|
|
230
196
|
if (valueSymbol) {
|
|
231
197
|
createBlockSymbol(block, node.name, valueSymbol, globals, isGlobal);
|
|
232
198
|
return block.props[node.name];
|
|
233
199
|
}
|
|
234
|
-
/* istanbul ignore next */
|
|
235
|
-
|
|
236
200
|
|
|
201
|
+
/* istanbul ignore next */
|
|
237
202
|
debug('Identifier: Missing value symbol for %s', node.name);
|
|
238
203
|
} else {
|
|
239
204
|
createBlockSymbol(block, node.name, createNode(), globals, isGlobal);
|
|
240
205
|
return block.props[node.name];
|
|
241
206
|
}
|
|
242
|
-
/* istanbul ignore next */
|
|
243
|
-
|
|
244
207
|
|
|
208
|
+
/* istanbul ignore next */
|
|
245
209
|
break;
|
|
246
210
|
}
|
|
247
|
-
|
|
248
211
|
case 'MemberExpression':
|
|
249
212
|
{
|
|
250
213
|
symbol = getSymbol(node.object, globals, block);
|
|
@@ -252,23 +215,20 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
|
252
215
|
simpleIdentifier: !node.computed
|
|
253
216
|
});
|
|
254
217
|
const propertyValue = getSymbolValue(propertySymbol);
|
|
255
|
-
|
|
256
218
|
if (symbol && propertyValue) {
|
|
257
219
|
createBlockSymbol(symbol, propertyValue, getSymbol(value, globals, block), globals, isGlobal);
|
|
258
220
|
return symbol.props[propertyValue];
|
|
259
221
|
}
|
|
260
|
-
/* istanbul ignore next */
|
|
261
|
-
|
|
262
222
|
|
|
223
|
+
/* istanbul ignore next */
|
|
263
224
|
debug('MemberExpression: Missing symbol: %s', node.property.name);
|
|
264
225
|
break;
|
|
265
226
|
}
|
|
266
227
|
}
|
|
267
|
-
|
|
268
228
|
return null;
|
|
269
|
-
};
|
|
270
|
-
|
|
229
|
+
};
|
|
271
230
|
|
|
231
|
+
// Creates variables from variable definitions
|
|
272
232
|
const initVariables = function (node, globals, opts) {
|
|
273
233
|
// eslint-disable-next-line default-case
|
|
274
234
|
switch (node.type) {
|
|
@@ -277,112 +237,91 @@ const initVariables = function (node, globals, opts) {
|
|
|
277
237
|
for (const childNode of node.body) {
|
|
278
238
|
initVariables(childNode, globals, opts);
|
|
279
239
|
}
|
|
280
|
-
|
|
281
240
|
break;
|
|
282
241
|
}
|
|
283
|
-
|
|
284
242
|
case 'ExpressionStatement':
|
|
285
243
|
{
|
|
286
244
|
initVariables(node.expression, globals, opts);
|
|
287
245
|
break;
|
|
288
246
|
}
|
|
289
|
-
|
|
290
247
|
case 'VariableDeclaration':
|
|
291
248
|
{
|
|
292
249
|
for (const declaration of node.declarations) {
|
|
293
250
|
// let and const
|
|
294
251
|
const symbol = createSymbol(declaration.id, globals, null, globals);
|
|
295
|
-
|
|
296
252
|
if (opts.initWindow && node.kind === 'var' && globals.props.window) {
|
|
297
253
|
// If var, also add to window
|
|
298
254
|
globals.props.window.props[declaration.id.name] = symbol;
|
|
299
255
|
}
|
|
300
256
|
}
|
|
301
|
-
|
|
302
257
|
break;
|
|
303
258
|
}
|
|
304
|
-
|
|
305
259
|
case 'ExportNamedDeclaration':
|
|
306
260
|
{
|
|
307
261
|
if (node.declaration) {
|
|
308
262
|
initVariables(node.declaration, globals, opts);
|
|
309
263
|
}
|
|
310
|
-
|
|
311
264
|
break;
|
|
312
265
|
}
|
|
313
266
|
}
|
|
314
|
-
};
|
|
315
|
-
// eslint-disable-next-line complexity
|
|
316
|
-
|
|
267
|
+
};
|
|
317
268
|
|
|
269
|
+
// Populates variable maps using AST
|
|
270
|
+
// eslint-disable-next-line complexity
|
|
318
271
|
const mapVariables = function (node, globals, opt, isExport) {
|
|
319
272
|
/* istanbul ignore next */
|
|
320
273
|
const opts = opt || {};
|
|
321
274
|
/* istanbul ignore next */
|
|
322
|
-
|
|
323
275
|
switch (node.type) {
|
|
324
276
|
case 'Program':
|
|
325
277
|
{
|
|
326
278
|
if (opts.ancestorsOnly) {
|
|
327
279
|
return false;
|
|
328
280
|
}
|
|
329
|
-
|
|
330
281
|
for (const childNode of node.body) {
|
|
331
282
|
mapVariables(childNode, globals, opts);
|
|
332
283
|
}
|
|
333
|
-
|
|
334
284
|
break;
|
|
335
285
|
}
|
|
336
|
-
|
|
337
286
|
case 'ExpressionStatement':
|
|
338
287
|
{
|
|
339
288
|
mapVariables(node.expression, globals, opts);
|
|
340
289
|
break;
|
|
341
290
|
}
|
|
342
|
-
|
|
343
291
|
case 'AssignmentExpression':
|
|
344
292
|
{
|
|
345
293
|
createSymbol(node.left, globals, node.right);
|
|
346
294
|
break;
|
|
347
295
|
}
|
|
348
|
-
|
|
349
296
|
case 'VariableDeclaration':
|
|
350
297
|
{
|
|
351
298
|
for (const declaration of node.declarations) {
|
|
352
299
|
const isGlobal = opts.initWindow && node.kind === 'var' && globals.props.window;
|
|
353
300
|
const symbol = createSymbol(declaration.id, globals, declaration.init, globals, isGlobal);
|
|
354
|
-
|
|
355
301
|
if (symbol && isExport) {
|
|
356
302
|
symbol.exported = true;
|
|
357
303
|
}
|
|
358
304
|
}
|
|
359
|
-
|
|
360
305
|
break;
|
|
361
306
|
}
|
|
362
|
-
|
|
363
307
|
case 'FunctionDeclaration':
|
|
364
308
|
{
|
|
365
309
|
/* istanbul ignore next */
|
|
366
310
|
if (node.id.type === 'Identifier') {
|
|
367
311
|
createSymbol(node.id, globals, node, globals, true);
|
|
368
312
|
}
|
|
369
|
-
|
|
370
313
|
break;
|
|
371
314
|
}
|
|
372
|
-
|
|
373
315
|
case 'ExportDefaultDeclaration':
|
|
374
316
|
{
|
|
375
317
|
const symbol = createSymbol(node.declaration, globals, node.declaration);
|
|
376
|
-
|
|
377
318
|
if (symbol) {
|
|
378
319
|
symbol.exported = true;
|
|
379
320
|
} else if (!node.id) {
|
|
380
321
|
globals.ANONYMOUS_DEFAULT = node.declaration;
|
|
381
322
|
}
|
|
382
|
-
|
|
383
323
|
break;
|
|
384
324
|
}
|
|
385
|
-
|
|
386
325
|
case 'ExportNamedDeclaration':
|
|
387
326
|
{
|
|
388
327
|
if (node.declaration) {
|
|
@@ -391,67 +330,52 @@ const mapVariables = function (node, globals, opt, isExport) {
|
|
|
391
330
|
} else {
|
|
392
331
|
const symbol = createSymbol(node.declaration, globals, node.declaration);
|
|
393
332
|
/* istanbul ignore next */
|
|
394
|
-
|
|
395
333
|
if (symbol) {
|
|
396
334
|
symbol.exported = true;
|
|
397
335
|
}
|
|
398
336
|
}
|
|
399
337
|
}
|
|
400
|
-
|
|
401
338
|
for (const specifier of node.specifiers) {
|
|
402
339
|
mapVariables(specifier, globals, opts);
|
|
403
340
|
}
|
|
404
|
-
|
|
405
341
|
break;
|
|
406
342
|
}
|
|
407
|
-
|
|
408
343
|
case 'ExportSpecifier':
|
|
409
344
|
{
|
|
410
345
|
const symbol = getSymbol(node.local, globals, globals);
|
|
411
346
|
/* istanbul ignore next */
|
|
412
|
-
|
|
413
347
|
if (symbol) {
|
|
414
348
|
symbol.exported = true;
|
|
415
349
|
}
|
|
416
|
-
|
|
417
350
|
break;
|
|
418
351
|
}
|
|
419
|
-
|
|
420
352
|
case 'ClassDeclaration':
|
|
421
353
|
{
|
|
422
354
|
createSymbol(node.id, globals, node.body, globals);
|
|
423
355
|
break;
|
|
424
356
|
}
|
|
425
|
-
|
|
426
357
|
default:
|
|
427
358
|
{
|
|
428
359
|
/* istanbul ignore next */
|
|
429
360
|
return false;
|
|
430
361
|
}
|
|
431
362
|
}
|
|
432
|
-
|
|
433
363
|
return true;
|
|
434
364
|
};
|
|
435
|
-
|
|
436
365
|
const findNode = function (node, block, cache) {
|
|
437
366
|
let blockCache = cache || [];
|
|
438
367
|
/* istanbul ignore next */
|
|
439
|
-
|
|
440
368
|
if (!block || blockCache.includes(block)) {
|
|
441
369
|
return false;
|
|
442
370
|
}
|
|
443
|
-
|
|
444
371
|
blockCache = blockCache.slice();
|
|
445
372
|
blockCache.push(block);
|
|
446
|
-
|
|
447
373
|
if ((block.type === 'object' || block.type === 'MethodDefinition') && block.value === node) {
|
|
448
374
|
return true;
|
|
449
375
|
}
|
|
450
|
-
|
|
451
376
|
const {
|
|
452
377
|
props = block.body
|
|
453
378
|
} = block;
|
|
454
|
-
|
|
455
379
|
for (const propval of Object.values(props || {})) {
|
|
456
380
|
if (Array.isArray(propval)) {
|
|
457
381
|
/* istanbul ignore if */
|
|
@@ -464,113 +388,87 @@ const findNode = function (node, block, cache) {
|
|
|
464
388
|
return true;
|
|
465
389
|
}
|
|
466
390
|
}
|
|
467
|
-
|
|
468
391
|
return false;
|
|
469
392
|
};
|
|
470
|
-
|
|
471
393
|
const exportTypes = new Set(['ExportNamedDeclaration', 'ExportDefaultDeclaration']);
|
|
472
394
|
const ignorableNestedTypes = new Set(['FunctionDeclaration', 'ArrowFunctionExpression', 'FunctionExpression']);
|
|
473
|
-
|
|
474
395
|
const getExportAncestor = function (nde) {
|
|
475
396
|
let node = nde;
|
|
476
397
|
let idx = 0;
|
|
477
398
|
const ignorableIfDeep = ignorableNestedTypes.has(nde === null || nde === void 0 ? void 0 : nde.type);
|
|
478
|
-
|
|
479
399
|
while (node) {
|
|
480
400
|
// Ignore functions nested more deeply than say `export default function () {}`
|
|
481
401
|
if (idx >= 2 && ignorableIfDeep) {
|
|
482
402
|
break;
|
|
483
403
|
}
|
|
484
|
-
|
|
485
404
|
if (exportTypes.has(node.type)) {
|
|
486
405
|
return node;
|
|
487
406
|
}
|
|
488
|
-
|
|
489
407
|
node = node.parent;
|
|
490
408
|
idx++;
|
|
491
409
|
}
|
|
492
|
-
|
|
493
410
|
return false;
|
|
494
411
|
};
|
|
495
|
-
|
|
496
412
|
const canBeExportedByAncestorType = new Set(['TSPropertySignature', 'TSMethodSignature', 'ClassProperty', 'PropertyDefinition', 'Method']);
|
|
497
413
|
const canExportChildrenType = new Set(['TSInterfaceBody', 'TSInterfaceDeclaration', 'TSTypeLiteral', 'TSTypeAliasDeclaration', 'ClassDeclaration', 'ClassBody', 'ClassDefinition', 'ClassExpression', 'Program']);
|
|
498
|
-
|
|
499
414
|
const isExportByAncestor = function (nde) {
|
|
500
415
|
if (!canBeExportedByAncestorType.has(nde.type)) {
|
|
501
416
|
return false;
|
|
502
417
|
}
|
|
503
|
-
|
|
504
418
|
let node = nde.parent;
|
|
505
|
-
|
|
506
419
|
while (node) {
|
|
507
420
|
if (exportTypes.has(node.type)) {
|
|
508
421
|
return node;
|
|
509
422
|
}
|
|
510
|
-
|
|
511
423
|
if (!canExportChildrenType.has(node.type)) {
|
|
512
424
|
return false;
|
|
513
425
|
}
|
|
514
|
-
|
|
515
426
|
node = node.parent;
|
|
516
427
|
}
|
|
517
|
-
|
|
518
428
|
return false;
|
|
519
429
|
};
|
|
520
|
-
|
|
521
430
|
const findExportedNode = function (block, node, cache) {
|
|
522
431
|
/* istanbul ignore next */
|
|
523
432
|
if (block === null) {
|
|
524
433
|
return false;
|
|
525
434
|
}
|
|
526
|
-
|
|
527
435
|
const blockCache = cache || [];
|
|
528
436
|
const {
|
|
529
437
|
props
|
|
530
438
|
} = block;
|
|
531
|
-
|
|
532
439
|
for (const propval of Object.values(props)) {
|
|
533
440
|
blockCache.push(propval);
|
|
534
|
-
|
|
535
441
|
if (propval.exported && (node === propval.value || findNode(node, propval.value))) {
|
|
536
442
|
return true;
|
|
537
|
-
}
|
|
538
|
-
// exports are only global
|
|
443
|
+
}
|
|
539
444
|
|
|
445
|
+
// No need to check `propval` for exported nodes as ESM
|
|
446
|
+
// exports are only global
|
|
540
447
|
}
|
|
541
448
|
|
|
542
449
|
return false;
|
|
543
450
|
};
|
|
544
|
-
|
|
545
451
|
const isNodeExported = function (node, globals, opt) {
|
|
546
452
|
var _globals$props$module, _globals$props$module2;
|
|
547
|
-
|
|
548
453
|
const moduleExports = (_globals$props$module = globals.props.module) === null || _globals$props$module === void 0 ? void 0 : (_globals$props$module2 = _globals$props$module.props) === null || _globals$props$module2 === void 0 ? void 0 : _globals$props$module2.exports;
|
|
549
|
-
|
|
550
454
|
if (opt.initModuleExports && moduleExports && findNode(node, moduleExports)) {
|
|
551
455
|
return true;
|
|
552
456
|
}
|
|
553
|
-
|
|
554
457
|
if (opt.initWindow && globals.props.window && findNode(node, globals.props.window)) {
|
|
555
458
|
return true;
|
|
556
459
|
}
|
|
557
|
-
|
|
558
460
|
if (opt.esm && findExportedNode(globals, node)) {
|
|
559
461
|
return true;
|
|
560
462
|
}
|
|
561
|
-
|
|
562
463
|
return false;
|
|
563
464
|
};
|
|
564
|
-
|
|
565
465
|
const parseRecursive = function (node, globalVars, opts) {
|
|
566
466
|
// Iterate from top using recursion - stop at first processed node from top
|
|
567
467
|
if (node.parent && parseRecursive(node.parent, globalVars, opts)) {
|
|
568
468
|
return true;
|
|
569
469
|
}
|
|
570
|
-
|
|
571
470
|
return mapVariables(node, globalVars, opts);
|
|
572
471
|
};
|
|
573
|
-
|
|
574
472
|
const parse = function (ast, node, opt) {
|
|
575
473
|
/* istanbul ignore next */
|
|
576
474
|
const opts = opt || {
|
|
@@ -580,53 +478,46 @@ const parse = function (ast, node, opt) {
|
|
|
580
478
|
initWindow: true
|
|
581
479
|
};
|
|
582
480
|
const globalVars = createNode();
|
|
583
|
-
|
|
584
481
|
if (opts.initModuleExports) {
|
|
585
482
|
globalVars.props.module = createNode();
|
|
586
483
|
globalVars.props.module.props.exports = createNode();
|
|
587
484
|
globalVars.props.exports = globalVars.props.module.props.exports;
|
|
588
485
|
}
|
|
589
|
-
|
|
590
486
|
if (opts.initWindow) {
|
|
591
487
|
globalVars.props.window = createNode();
|
|
592
488
|
globalVars.props.window.special = true;
|
|
593
489
|
}
|
|
594
|
-
|
|
595
490
|
if (opts.ancestorsOnly) {
|
|
596
491
|
parseRecursive(node, globalVars, opts);
|
|
597
492
|
} else {
|
|
598
493
|
initVariables(ast, globalVars, opts);
|
|
599
494
|
mapVariables(ast, globalVars, opts);
|
|
600
495
|
}
|
|
601
|
-
|
|
602
496
|
return {
|
|
603
497
|
globalVars
|
|
604
498
|
};
|
|
605
499
|
};
|
|
606
|
-
|
|
607
500
|
const isUncommentedExport = function (node, sourceCode, opt, settings) {
|
|
608
501
|
// console.log({node});
|
|
609
502
|
// Optimize with ancestor check for esm
|
|
610
503
|
if (opt.esm) {
|
|
611
|
-
const exportNode = getExportAncestor(node);
|
|
504
|
+
const exportNode = getExportAncestor(node);
|
|
612
505
|
|
|
506
|
+
// Is export node comment
|
|
613
507
|
if (exportNode && !(0, _jsdoccomment.findJSDocComment)(exportNode, sourceCode, settings)) {
|
|
614
508
|
return true;
|
|
615
509
|
}
|
|
510
|
+
|
|
616
511
|
/**
|
|
617
512
|
* Some typescript types are not in variable map, but inherit exported (interface property and method)
|
|
618
513
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
514
|
if (isExportByAncestor(node) && !(0, _jsdoccomment.findJSDocComment)(node, sourceCode, settings)) {
|
|
622
515
|
return true;
|
|
623
516
|
}
|
|
624
517
|
}
|
|
625
|
-
|
|
626
518
|
const parseResult = parse(sourceCode.ast, node, opt);
|
|
627
519
|
return isNodeExported(node, parseResult.globalVars, opt);
|
|
628
520
|
};
|
|
629
|
-
|
|
630
521
|
var _default = {
|
|
631
522
|
isUncommentedExport,
|
|
632
523
|
parse
|