1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
22 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
23 | };
|
24 | Object.defineProperty(exports, "__esModule", { value: true });
|
25 | exports.forEachReturnStatement = exports.getNameLocationInGlobalDirectiveComment = void 0;
|
26 | const escapeRegExp_1 = require("./escapeRegExp");
|
27 | const ts = __importStar(require("typescript"));
|
28 |
|
29 | __exportStar(require("@typescript-eslint/utils/dist/ast-utils"), exports);
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function getNameLocationInGlobalDirectiveComment(sourceCode, comment, name) {
|
41 | const namePattern = new RegExp(`[\\s,]${(0, escapeRegExp_1.escapeRegExp)(name)}(?:$|[\\s,:])`, 'gu');
|
42 |
|
43 | namePattern.lastIndex = comment.value.indexOf('global') + 6;
|
44 |
|
45 | const match = namePattern.exec(comment.value);
|
46 |
|
47 | const start = sourceCode.getLocFromIndex(comment.range[0] + '/*'.length + (match ? match.index + 1 : 0));
|
48 | const end = {
|
49 | line: start.line,
|
50 | column: start.column + (match ? name.length : 1),
|
51 | };
|
52 | return { start, end };
|
53 | }
|
54 | exports.getNameLocationInGlobalDirectiveComment = getNameLocationInGlobalDirectiveComment;
|
55 |
|
56 |
|
57 |
|
58 | function forEachReturnStatement(body, visitor) {
|
59 | return traverse(body);
|
60 | function traverse(node) {
|
61 | switch (node.kind) {
|
62 | case ts.SyntaxKind.ReturnStatement:
|
63 | return visitor(node);
|
64 | case ts.SyntaxKind.CaseBlock:
|
65 | case ts.SyntaxKind.Block:
|
66 | case ts.SyntaxKind.IfStatement:
|
67 | case ts.SyntaxKind.DoStatement:
|
68 | case ts.SyntaxKind.WhileStatement:
|
69 | case ts.SyntaxKind.ForStatement:
|
70 | case ts.SyntaxKind.ForInStatement:
|
71 | case ts.SyntaxKind.ForOfStatement:
|
72 | case ts.SyntaxKind.WithStatement:
|
73 | case ts.SyntaxKind.SwitchStatement:
|
74 | case ts.SyntaxKind.CaseClause:
|
75 | case ts.SyntaxKind.DefaultClause:
|
76 | case ts.SyntaxKind.LabeledStatement:
|
77 | case ts.SyntaxKind.TryStatement:
|
78 | case ts.SyntaxKind.CatchClause:
|
79 | return ts.forEachChild(node, traverse);
|
80 | }
|
81 | return undefined;
|
82 | }
|
83 | }
|
84 | exports.forEachReturnStatement = forEachReturnStatement;
|
85 |
|
\ | No newline at end of file |