astro-eslint-parser 0.5.0 → 0.6.1
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/lib/index.d.ts +345 -9
- package/lib/index.js +1745 -42
- package/lib/index.mjs +1719 -0
- package/package.json +12 -9
- package/lib/ast/astro.d.ts +0 -49
- package/lib/ast/astro.js +0 -2
- package/lib/ast/base.d.ts +0 -6
- package/lib/ast/base.js +0 -2
- package/lib/ast/index.d.ts +0 -8
- package/lib/ast/index.js +0 -18
- package/lib/ast/jsx.d.ts +0 -91
- package/lib/ast/jsx.js +0 -2
- package/lib/astro/index.d.ts +0 -56
- package/lib/astro/index.js +0 -357
- package/lib/astro-tools/index.d.ts +0 -21
- package/lib/astro-tools/index.js +0 -26
- package/lib/context/index.d.ts +0 -55
- package/lib/context/index.js +0 -158
- package/lib/context/parser-options.d.ts +0 -8
- package/lib/context/parser-options.js +0 -77
- package/lib/context/resolve-parser/espree.d.ts +0 -6
- package/lib/context/resolve-parser/espree.js +0 -41
- package/lib/context/resolve-parser/index.d.ts +0 -7
- package/lib/context/resolve-parser/index.js +0 -34
- package/lib/context/resolve-parser/parser-object.d.ts +0 -33
- package/lib/context/resolve-parser/parser-object.js +0 -27
- package/lib/context/script.d.ts +0 -34
- package/lib/context/script.js +0 -178
- package/lib/debug.d.ts +0 -2
- package/lib/debug.js +0 -8
- package/lib/errors.d.ts +0 -14
- package/lib/errors.js +0 -20
- package/lib/parser/astro-parser/astrojs-compiler-service.d.ts +0 -5
- package/lib/parser/astro-parser/astrojs-compiler-service.js +0 -12
- package/lib/parser/astro-parser/astrojs-compiler-worker.d.ts +0 -1
- package/lib/parser/astro-parser/astrojs-compiler-worker.js +0 -11
- package/lib/parser/astro-parser/parse.d.ts +0 -6
- package/lib/parser/astro-parser/parse.js +0 -270
- package/lib/parser/index.d.ts +0 -21
- package/lib/parser/index.js +0 -72
- package/lib/parser/lru-cache.d.ts +0 -7
- package/lib/parser/lru-cache.js +0 -32
- package/lib/parser/process-template.d.ts +0 -7
- package/lib/parser/process-template.js +0 -381
- package/lib/parser/script.d.ts +0 -7
- package/lib/parser/script.js +0 -44
- package/lib/parser/sort.d.ts +0 -6
- package/lib/parser/sort.js +0 -15
- package/lib/parser/template.d.ts +0 -10
- package/lib/parser/template.js +0 -102
- package/lib/parser/ts-patch.d.ts +0 -8
- package/lib/parser/ts-patch.js +0 -65
- package/lib/traverse.d.ts +0 -27
- package/lib/traverse.js +0 -93
- package/lib/types.d.ts +0 -17
- package/lib/types.js +0 -2
- package/lib/visitor-keys.d.ts +0 -2
- package/lib/visitor-keys.js +0 -14
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ParseResult } from "@astrojs/compiler";
|
|
2
|
-
import type { AttributeNode, Node, ParentNode } from "@astrojs/compiler/types";
|
|
3
|
-
export interface ParseTemplateResult {
|
|
4
|
-
result: ParseResult;
|
|
5
|
-
getEndOffset: (node: Node) => number;
|
|
6
|
-
calcAttributeValueStartOffset: (node: AttributeNode) => number;
|
|
7
|
-
calcAttributeEndOffset: (node: AttributeNode) => number;
|
|
8
|
-
walk: (parent: ParentNode, enter: (n: Node | AttributeNode, parents: ParentNode[]) => void, leave?: (n: Node | AttributeNode, parents: ParentNode[]) => void) => void;
|
|
9
|
-
getLocFromIndex: (index: number) => {
|
|
10
|
-
line: number;
|
|
11
|
-
column: number;
|
|
12
|
-
};
|
|
13
|
-
getIndexFromLoc: (loc: {
|
|
14
|
-
line: number;
|
|
15
|
-
column: number;
|
|
16
|
-
}) => number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Parse the astro component template.
|
|
20
|
-
*/
|
|
21
|
-
export declare function parseTemplate(code: string): ParseTemplateResult;
|
package/lib/astro-tools/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTemplate = void 0;
|
|
4
|
-
const template_1 = require("../parser/template");
|
|
5
|
-
const astro_1 = require("../astro");
|
|
6
|
-
/**
|
|
7
|
-
* Parse the astro component template.
|
|
8
|
-
*/
|
|
9
|
-
function parseTemplate(code) {
|
|
10
|
-
const parsed = (0, template_1.parseTemplate)(code);
|
|
11
|
-
return {
|
|
12
|
-
result: parsed.result,
|
|
13
|
-
getEndOffset: (node) => (0, astro_1.getEndOffset)(node, parsed.context),
|
|
14
|
-
calcAttributeValueStartOffset: (node) => (0, astro_1.calcAttributeValueStartOffset)(node, parsed.context),
|
|
15
|
-
calcAttributeEndOffset: (node) => (0, astro_1.calcAttributeEndOffset)(node, parsed.context),
|
|
16
|
-
walk(parent, enter, leave) {
|
|
17
|
-
(0, astro_1.walk)(parent, code, enter, leave ||
|
|
18
|
-
(() => {
|
|
19
|
-
/* noop */
|
|
20
|
-
}));
|
|
21
|
-
},
|
|
22
|
-
getLocFromIndex: (index) => parsed.context.getLocFromIndex(index),
|
|
23
|
-
getIndexFromLoc: (loc) => parsed.context.locs.getIndexFromLoc(loc),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
exports.parseTemplate = parseTemplate;
|
package/lib/context/index.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from "@typescript-eslint/types";
|
|
2
|
-
declare type RangeAndLoc = {
|
|
3
|
-
range: TSESTree.Range;
|
|
4
|
-
loc: TSESTree.SourceLocation;
|
|
5
|
-
};
|
|
6
|
-
export declare class Context {
|
|
7
|
-
readonly code: string;
|
|
8
|
-
readonly locs: LinesAndColumns;
|
|
9
|
-
private readonly locsMap;
|
|
10
|
-
private readonly state;
|
|
11
|
-
constructor(code: string);
|
|
12
|
-
getLocFromIndex(index: number): {
|
|
13
|
-
line: number;
|
|
14
|
-
column: number;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Get the location information of the given indexes.
|
|
18
|
-
*/
|
|
19
|
-
getLocations(start: number, end: number): RangeAndLoc;
|
|
20
|
-
/**
|
|
21
|
-
* Build token
|
|
22
|
-
*/
|
|
23
|
-
buildToken(type: TSESTree.Token["type"], range: TSESTree.Range): TSESTree.Token;
|
|
24
|
-
/**
|
|
25
|
-
* get text
|
|
26
|
-
*/
|
|
27
|
-
getText(range: TSESTree.Range): string;
|
|
28
|
-
get originalAST(): any;
|
|
29
|
-
set originalAST(originalAST: any);
|
|
30
|
-
}
|
|
31
|
-
export declare class LinesAndColumns {
|
|
32
|
-
private readonly lineStartIndices;
|
|
33
|
-
private readonly normalizedLineFeed;
|
|
34
|
-
constructor(origCode: string);
|
|
35
|
-
getLocFromIndex(index: number): {
|
|
36
|
-
line: number;
|
|
37
|
-
column: number;
|
|
38
|
-
};
|
|
39
|
-
getIndexFromLoc(loc: {
|
|
40
|
-
line: number;
|
|
41
|
-
column: number;
|
|
42
|
-
}): number;
|
|
43
|
-
getNormalizedLineFeed(): NormalizedLineFeed;
|
|
44
|
-
}
|
|
45
|
-
export declare class NormalizedLineFeed {
|
|
46
|
-
readonly code: string;
|
|
47
|
-
private readonly offsets;
|
|
48
|
-
get needRemap(): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Remap index
|
|
51
|
-
*/
|
|
52
|
-
readonly remapIndex: (index: number) => number;
|
|
53
|
-
constructor(code: string, offsets: number[]);
|
|
54
|
-
}
|
|
55
|
-
export {};
|
package/lib/context/index.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NormalizedLineFeed = exports.LinesAndColumns = exports.Context = void 0;
|
|
4
|
-
class Context {
|
|
5
|
-
constructor(code) {
|
|
6
|
-
this.locsMap = new Map();
|
|
7
|
-
this.state = {};
|
|
8
|
-
this.locs = new LinesAndColumns(code);
|
|
9
|
-
this.code = code;
|
|
10
|
-
}
|
|
11
|
-
getLocFromIndex(index) {
|
|
12
|
-
let loc = this.locsMap.get(index);
|
|
13
|
-
if (!loc) {
|
|
14
|
-
loc = this.locs.getLocFromIndex(index);
|
|
15
|
-
this.locsMap.set(index, loc);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
line: loc.line,
|
|
19
|
-
column: loc.column,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get the location information of the given indexes.
|
|
24
|
-
*/
|
|
25
|
-
getLocations(start, end) {
|
|
26
|
-
return {
|
|
27
|
-
range: [start, end],
|
|
28
|
-
loc: {
|
|
29
|
-
start: this.getLocFromIndex(start),
|
|
30
|
-
end: this.getLocFromIndex(end),
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Build token
|
|
36
|
-
*/
|
|
37
|
-
buildToken(type, range) {
|
|
38
|
-
return {
|
|
39
|
-
type,
|
|
40
|
-
value: this.getText(range),
|
|
41
|
-
...this.getLocations(...range),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* get text
|
|
46
|
-
*/
|
|
47
|
-
getText(range) {
|
|
48
|
-
return this.code.slice(range[0], range[1]);
|
|
49
|
-
}
|
|
50
|
-
get originalAST() {
|
|
51
|
-
return this.state.originalAST;
|
|
52
|
-
}
|
|
53
|
-
set originalAST(originalAST) {
|
|
54
|
-
this.state.originalAST = originalAST;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.Context = Context;
|
|
58
|
-
class LinesAndColumns {
|
|
59
|
-
constructor(origCode) {
|
|
60
|
-
const len = origCode.length;
|
|
61
|
-
const lineStartIndices = [0];
|
|
62
|
-
const crs = [];
|
|
63
|
-
let normalizedCode = "";
|
|
64
|
-
for (let index = 0; index < len;) {
|
|
65
|
-
const c = origCode[index++];
|
|
66
|
-
if (c === "\r") {
|
|
67
|
-
const next = origCode[index++] || "";
|
|
68
|
-
if (next === "\n") {
|
|
69
|
-
normalizedCode += next;
|
|
70
|
-
crs.push(index - 2);
|
|
71
|
-
lineStartIndices.push(index);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
normalizedCode += `\n${next}`;
|
|
75
|
-
lineStartIndices.push(index - 1);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
normalizedCode += c;
|
|
80
|
-
if (c === "\n") {
|
|
81
|
-
lineStartIndices.push(index);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
this.lineStartIndices = lineStartIndices;
|
|
86
|
-
//
|
|
87
|
-
this.normalizedLineFeed = new NormalizedLineFeed(normalizedCode, crs);
|
|
88
|
-
}
|
|
89
|
-
getLocFromIndex(index) {
|
|
90
|
-
const lineNumber = sortedLastIndex(this.lineStartIndices, index);
|
|
91
|
-
return {
|
|
92
|
-
line: lineNumber,
|
|
93
|
-
column: index - this.lineStartIndices[lineNumber - 1],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
getIndexFromLoc(loc) {
|
|
97
|
-
const lineStartIndex = this.lineStartIndices[loc.line - 1];
|
|
98
|
-
const positionIndex = lineStartIndex + loc.column;
|
|
99
|
-
return positionIndex;
|
|
100
|
-
}
|
|
101
|
-
getNormalizedLineFeed() {
|
|
102
|
-
return this.normalizedLineFeed;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.LinesAndColumns = LinesAndColumns;
|
|
106
|
-
class NormalizedLineFeed {
|
|
107
|
-
constructor(code, offsets) {
|
|
108
|
-
this.code = code;
|
|
109
|
-
this.offsets = offsets;
|
|
110
|
-
if (offsets.length) {
|
|
111
|
-
const cache = {};
|
|
112
|
-
this.remapIndex = (index) => {
|
|
113
|
-
let result = cache[index];
|
|
114
|
-
if (result != null) {
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
result = index;
|
|
118
|
-
for (const offset of offsets) {
|
|
119
|
-
if (offset < result) {
|
|
120
|
-
result++;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return (cache[index] = result);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
this.remapIndex = (i) => i;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
get needRemap() {
|
|
134
|
-
return this.offsets.length > 0;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.NormalizedLineFeed = NormalizedLineFeed;
|
|
138
|
-
/**
|
|
139
|
-
* Uses a binary search to determine the highest index at which value should be inserted into array in order to maintain its sort order.
|
|
140
|
-
*/
|
|
141
|
-
function sortedLastIndex(array, value) {
|
|
142
|
-
let lower = 0;
|
|
143
|
-
let upper = array.length;
|
|
144
|
-
while (lower < upper) {
|
|
145
|
-
const mid = Math.floor(lower + (upper - lower) / 2);
|
|
146
|
-
const target = array[mid];
|
|
147
|
-
if (target < value) {
|
|
148
|
-
lower = mid + 1;
|
|
149
|
-
}
|
|
150
|
-
else if (target > value) {
|
|
151
|
-
upper = mid;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
return mid + 1;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return upper;
|
|
158
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ParserOptionsContext = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const resolve_parser_1 = require("./resolve-parser");
|
|
10
|
-
const parser_object_1 = require("./resolve-parser/parser-object");
|
|
11
|
-
class ParserOptionsContext {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.state = {};
|
|
14
|
-
const parserOptions = {
|
|
15
|
-
ecmaVersion: 2020,
|
|
16
|
-
sourceType: "module",
|
|
17
|
-
loc: true,
|
|
18
|
-
range: true,
|
|
19
|
-
raw: true,
|
|
20
|
-
tokens: true,
|
|
21
|
-
comment: true,
|
|
22
|
-
eslintVisitorKeys: true,
|
|
23
|
-
eslintScopeManager: true,
|
|
24
|
-
...(options || {}),
|
|
25
|
-
};
|
|
26
|
-
parserOptions.ecmaFeatures = {
|
|
27
|
-
...(parserOptions.ecmaFeatures || {}),
|
|
28
|
-
jsx: true,
|
|
29
|
-
};
|
|
30
|
-
parserOptions.sourceType = "module";
|
|
31
|
-
if (parserOptions.ecmaVersion <= 5 ||
|
|
32
|
-
parserOptions.ecmaVersion == null) {
|
|
33
|
-
parserOptions.ecmaVersion = 2015;
|
|
34
|
-
}
|
|
35
|
-
this.parserOptions = parserOptions;
|
|
36
|
-
}
|
|
37
|
-
getParser() {
|
|
38
|
-
return (0, resolve_parser_1.getParser)({}, this.parserOptions.parser);
|
|
39
|
-
}
|
|
40
|
-
isTypeScript() {
|
|
41
|
-
if (this.state.isTypeScript != null) {
|
|
42
|
-
return this.state.isTypeScript;
|
|
43
|
-
}
|
|
44
|
-
const parserValue = (0, resolve_parser_1.getParserForLang)({}, this.parserOptions?.parser);
|
|
45
|
-
if ((0, parser_object_1.maybeTSESLintParserObject)(parserValue) ||
|
|
46
|
-
parserValue === "@typescript-eslint/parser") {
|
|
47
|
-
return (this.state.isTypeScript = true);
|
|
48
|
-
}
|
|
49
|
-
if (typeof parserValue !== "string") {
|
|
50
|
-
return (this.state.isTypeScript = false);
|
|
51
|
-
}
|
|
52
|
-
const parserName = parserValue;
|
|
53
|
-
if (parserName.includes("@typescript-eslint/parser")) {
|
|
54
|
-
let targetPath = parserName;
|
|
55
|
-
while (targetPath) {
|
|
56
|
-
const pkgPath = path_1.default.join(targetPath, "package.json");
|
|
57
|
-
if (fs_1.default.existsSync(pkgPath)) {
|
|
58
|
-
try {
|
|
59
|
-
return (this.state.isTypeScript =
|
|
60
|
-
JSON.parse(fs_1.default.readFileSync(pkgPath, "utf-8"))
|
|
61
|
-
?.name === "@typescript-eslint/parser");
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return (this.state.isTypeScript = false);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const parent = path_1.default.dirname(targetPath);
|
|
68
|
-
if (targetPath === parent) {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
targetPath = parent;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return (this.state.isTypeScript = false);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.ParserOptionsContext = ParserOptionsContext;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getEspree = void 0;
|
|
7
|
-
const module_1 = require("module");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
let espreeCache = null;
|
|
10
|
-
/** Checks if given path is linter path */
|
|
11
|
-
function isLinterPath(p) {
|
|
12
|
-
return (
|
|
13
|
-
// ESLint 6 and above
|
|
14
|
-
p.includes(`eslint${path_1.default.sep}lib${path_1.default.sep}linter${path_1.default.sep}linter.js`) ||
|
|
15
|
-
// ESLint 5
|
|
16
|
-
p.includes(`eslint${path_1.default.sep}lib${path_1.default.sep}linter.js`));
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Load `espree` from the loaded ESLint.
|
|
20
|
-
* If the loaded ESLint was not found, just returns `require("espree")`.
|
|
21
|
-
*/
|
|
22
|
-
function getEspree() {
|
|
23
|
-
if (!espreeCache) {
|
|
24
|
-
// Lookup the loaded eslint
|
|
25
|
-
const linterPath = Object.keys(require.cache || {}).find(isLinterPath);
|
|
26
|
-
if (linterPath) {
|
|
27
|
-
try {
|
|
28
|
-
espreeCache = (0, module_1.createRequire)(linterPath)("espree");
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
// ignore
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (!espreeCache) {
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
|
|
36
|
-
espreeCache = require("espree");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return espreeCache;
|
|
40
|
-
}
|
|
41
|
-
exports.getEspree = getEspree;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ParserObject } from "./parser-object";
|
|
2
|
-
declare type UserOptionParser = string | ParserObject | Record<string, string | ParserObject | undefined> | undefined;
|
|
3
|
-
/** Get parser for script lang */
|
|
4
|
-
export declare function getParserForLang(attrs: Record<string, string | undefined>, parser: UserOptionParser): string | ParserObject;
|
|
5
|
-
/** Get parser */
|
|
6
|
-
export declare function getParser(attrs: Record<string, string | undefined>, parser: any): ParserObject;
|
|
7
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getParser = exports.getParserForLang = void 0;
|
|
4
|
-
const espree_1 = require("./espree");
|
|
5
|
-
const parser_object_1 = require("./parser-object");
|
|
6
|
-
/** Get parser for script lang */
|
|
7
|
-
function getParserForLang(attrs, parser) {
|
|
8
|
-
if (parser) {
|
|
9
|
-
if (typeof parser === "string" || (0, parser_object_1.isParserObject)(parser)) {
|
|
10
|
-
return parser;
|
|
11
|
-
}
|
|
12
|
-
if (typeof parser === "object") {
|
|
13
|
-
const value = parser[attrs.lang || "js"];
|
|
14
|
-
if (typeof value === "string" || (0, parser_object_1.isParserObject)(value)) {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return "espree";
|
|
20
|
-
}
|
|
21
|
-
exports.getParserForLang = getParserForLang;
|
|
22
|
-
/** Get parser */
|
|
23
|
-
function getParser(attrs, parser) {
|
|
24
|
-
const parserValue = getParserForLang(attrs, parser);
|
|
25
|
-
if ((0, parser_object_1.isParserObject)(parserValue)) {
|
|
26
|
-
return parserValue;
|
|
27
|
-
}
|
|
28
|
-
if (parserValue !== "espree") {
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
|
|
30
|
-
return require(parserValue);
|
|
31
|
-
}
|
|
32
|
-
return (0, espree_1.getEspree)();
|
|
33
|
-
}
|
|
34
|
-
exports.getParser = getParser;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from "@typescript-eslint/types";
|
|
2
|
-
import type { ESLintExtendedProgram } from "../../types";
|
|
3
|
-
import type * as tsESLintParser from "@typescript-eslint/parser";
|
|
4
|
-
declare type TSESLintParser = typeof tsESLintParser;
|
|
5
|
-
/**
|
|
6
|
-
* The type of basic ESLint custom parser.
|
|
7
|
-
* e.g. espree
|
|
8
|
-
*/
|
|
9
|
-
export declare type BasicParserObject = {
|
|
10
|
-
parse(code: string, options: any): TSESTree.Program;
|
|
11
|
-
parseForESLint: undefined;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* The type of ESLint custom parser enhanced for ESLint.
|
|
15
|
-
* e.g. @babel/eslint-parser, @typescript-eslint/parser
|
|
16
|
-
*/
|
|
17
|
-
export declare type EnhancedParserObject = {
|
|
18
|
-
parseForESLint(code: string, options: any): ESLintExtendedProgram;
|
|
19
|
-
parse: undefined;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* The type of ESLint (custom) parsers.
|
|
23
|
-
*/
|
|
24
|
-
export declare type ParserObject = EnhancedParserObject | BasicParserObject;
|
|
25
|
-
/** Checks whether given object is ParserObject */
|
|
26
|
-
export declare function isParserObject(value: unknown): value is ParserObject;
|
|
27
|
-
/** Checks whether given object is EnhancedParserObject */
|
|
28
|
-
export declare function isEnhancedParserObject(value: unknown): value is EnhancedParserObject;
|
|
29
|
-
/** Checks whether given object is BasicParserObject */
|
|
30
|
-
export declare function isBasicParserObject(value: unknown): value is BasicParserObject;
|
|
31
|
-
/** Checks whether given object is "@typescript-eslint/parser" */
|
|
32
|
-
export declare function maybeTSESLintParserObject(value: unknown): value is TSESLintParser;
|
|
33
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.maybeTSESLintParserObject = exports.isBasicParserObject = exports.isEnhancedParserObject = exports.isParserObject = void 0;
|
|
4
|
-
/** Checks whether given object is ParserObject */
|
|
5
|
-
function isParserObject(value) {
|
|
6
|
-
return isEnhancedParserObject(value) || isBasicParserObject(value);
|
|
7
|
-
}
|
|
8
|
-
exports.isParserObject = isParserObject;
|
|
9
|
-
/** Checks whether given object is EnhancedParserObject */
|
|
10
|
-
function isEnhancedParserObject(value) {
|
|
11
|
-
return Boolean(value && typeof value.parseForESLint === "function");
|
|
12
|
-
}
|
|
13
|
-
exports.isEnhancedParserObject = isEnhancedParserObject;
|
|
14
|
-
/** Checks whether given object is BasicParserObject */
|
|
15
|
-
function isBasicParserObject(value) {
|
|
16
|
-
return Boolean(value && typeof value.parse === "function");
|
|
17
|
-
}
|
|
18
|
-
exports.isBasicParserObject = isBasicParserObject;
|
|
19
|
-
/** Checks whether given object is "@typescript-eslint/parser" */
|
|
20
|
-
function maybeTSESLintParserObject(value) {
|
|
21
|
-
return (isEnhancedParserObject(value) &&
|
|
22
|
-
isBasicParserObject(value) &&
|
|
23
|
-
typeof value.createProgram === "function" &&
|
|
24
|
-
typeof value.clearCaches === "function" &&
|
|
25
|
-
typeof value.version === "string");
|
|
26
|
-
}
|
|
27
|
-
exports.maybeTSESLintParserObject = maybeTSESLintParserObject;
|
package/lib/context/script.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Context } from ".";
|
|
2
|
-
import type { TSESTree } from "@typescript-eslint/types";
|
|
3
|
-
import type { ESLintExtendedProgram } from "../types";
|
|
4
|
-
declare class RestoreNodeProcessContext {
|
|
5
|
-
readonly result: ESLintExtendedProgram;
|
|
6
|
-
readonly removeTokens: Set<(token: TSESTree.Token) => boolean>;
|
|
7
|
-
private readonly parentMap;
|
|
8
|
-
constructor(result: ESLintExtendedProgram, parentMap: Map<TSESTree.Node, TSESTree.Node | null>);
|
|
9
|
-
addRemoveToken(test: (token: TSESTree.Token) => boolean): void;
|
|
10
|
-
getParent(node: TSESTree.Node): TSESTree.Node | null;
|
|
11
|
-
}
|
|
12
|
-
export declare class ScriptContext {
|
|
13
|
-
private readonly ctx;
|
|
14
|
-
script: string;
|
|
15
|
-
private consumedIndex;
|
|
16
|
-
private readonly offsets;
|
|
17
|
-
private readonly fragments;
|
|
18
|
-
private readonly tokens;
|
|
19
|
-
private readonly restoreNodeProcesses;
|
|
20
|
-
constructor(ctx: Context);
|
|
21
|
-
get originalCode(): string;
|
|
22
|
-
skipOriginalOffset(offset: number): void;
|
|
23
|
-
appendOriginal(index: number): void;
|
|
24
|
-
appendScript(fragment: string): void;
|
|
25
|
-
addToken(type: TSESTree.Token["type"], range: TSESTree.Range): void;
|
|
26
|
-
addRestoreNodeProcess(process: (node: TSESTree.Node, context: RestoreNodeProcessContext) => boolean): void;
|
|
27
|
-
/**
|
|
28
|
-
* Restore AST nodes
|
|
29
|
-
*/
|
|
30
|
-
restore(result: ESLintExtendedProgram): void;
|
|
31
|
-
private remapLocation;
|
|
32
|
-
private getRemapRange;
|
|
33
|
-
}
|
|
34
|
-
export {};
|