astro-eslint-parser 0.4.5 → 0.6.0
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 +8 -10
- package/lib/index.d.ts +345 -10
- package/lib/index.js +1744 -47
- package/lib/index.mjs +1719 -0
- package/package.json +22 -17
- 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 -71
- 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 -5
- package/lib/context/resolve-parser/index.js +0 -30
- 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/markdown/frontmatter.d.ts +0 -9
- package/lib/markdown/frontmatter.js +0 -53
- package/lib/markdown/index.d.ts +0 -19
- package/lib/markdown/index.js +0 -60
- package/lib/markdown/mdast-util-from-markdown-service.d.ts +0 -5
- package/lib/markdown/mdast-util-from-markdown-service.js +0 -12
- package/lib/markdown/mdast-util-from-markdown-worker.d.ts +0 -2
- package/lib/markdown/mdast-util-from-markdown-worker.js +0 -8
- package/lib/markdown/process-markdown.d.ts +0 -6
- package/lib/markdown/process-markdown.js +0 -82
- package/lib/markdown/yaml.d.ts +0 -9
- package/lib/markdown/yaml.js +0 -86
- 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 -267
- 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 -42
- 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 -21
- package/lib/types.js +0 -2
- package/lib/visitor-keys.d.ts +0 -2
- package/lib/visitor-keys.js +0 -14
|
@@ -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,5 +0,0 @@
|
|
|
1
|
-
import type { ESLintCustomParser } from "../../types";
|
|
2
|
-
/** Get parser name */
|
|
3
|
-
export declare function getParserName(attrs: Record<string, string | undefined>, parser: any): string;
|
|
4
|
-
/** Get parser */
|
|
5
|
-
export declare function getParser(attrs: Record<string, string | undefined>, parser: any): ESLintCustomParser;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getParser = exports.getParserName = void 0;
|
|
4
|
-
const espree_1 = require("./espree");
|
|
5
|
-
/** Get parser name */
|
|
6
|
-
function getParserName(attrs, parser) {
|
|
7
|
-
if (parser) {
|
|
8
|
-
if (typeof parser === "string" && parser !== "espree") {
|
|
9
|
-
return parser;
|
|
10
|
-
}
|
|
11
|
-
else if (typeof parser === "object") {
|
|
12
|
-
const name = parser[attrs.lang || "js"];
|
|
13
|
-
if (typeof name === "string") {
|
|
14
|
-
return getParserName(attrs, name);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return "espree";
|
|
19
|
-
}
|
|
20
|
-
exports.getParserName = getParserName;
|
|
21
|
-
/** Get parser */
|
|
22
|
-
function getParser(attrs, parser) {
|
|
23
|
-
const name = getParserName(attrs, parser);
|
|
24
|
-
if (name !== "espree") {
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
|
|
26
|
-
return require(name);
|
|
27
|
-
}
|
|
28
|
-
return (0, espree_1.getEspree)();
|
|
29
|
-
}
|
|
30
|
-
exports.getParser = getParser;
|
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 {};
|
package/lib/context/script.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScriptContext = void 0;
|
|
4
|
-
const traverse_1 = require("../traverse");
|
|
5
|
-
class RestoreNodeProcessContext {
|
|
6
|
-
constructor(result, parentMap) {
|
|
7
|
-
this.removeTokens = new Set();
|
|
8
|
-
this.result = result;
|
|
9
|
-
this.parentMap = parentMap;
|
|
10
|
-
}
|
|
11
|
-
addRemoveToken(test) {
|
|
12
|
-
this.removeTokens.add(test);
|
|
13
|
-
}
|
|
14
|
-
getParent(node) {
|
|
15
|
-
return this.parentMap.get(node) || null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
class ScriptContext {
|
|
19
|
-
constructor(ctx) {
|
|
20
|
-
this.script = "";
|
|
21
|
-
this.consumedIndex = 0;
|
|
22
|
-
this.offsets = [];
|
|
23
|
-
this.fragments = [];
|
|
24
|
-
this.tokens = [];
|
|
25
|
-
this.restoreNodeProcesses = [];
|
|
26
|
-
this.ctx = ctx;
|
|
27
|
-
}
|
|
28
|
-
get originalCode() {
|
|
29
|
-
return this.ctx.code;
|
|
30
|
-
}
|
|
31
|
-
skipOriginalOffset(offset) {
|
|
32
|
-
this.consumedIndex += offset;
|
|
33
|
-
}
|
|
34
|
-
appendOriginal(index) {
|
|
35
|
-
if (this.consumedIndex >= index) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.offsets.push({
|
|
39
|
-
original: this.consumedIndex,
|
|
40
|
-
script: this.script.length,
|
|
41
|
-
});
|
|
42
|
-
this.script += this.ctx.code.slice(this.consumedIndex, index);
|
|
43
|
-
this.consumedIndex = index;
|
|
44
|
-
}
|
|
45
|
-
appendScript(fragment) {
|
|
46
|
-
const start = this.script.length;
|
|
47
|
-
this.script += fragment;
|
|
48
|
-
this.fragments.push({ start, end: this.script.length });
|
|
49
|
-
}
|
|
50
|
-
addToken(type, range) {
|
|
51
|
-
if (range[0] >= range[1]) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
this.tokens.push(this.ctx.buildToken(type, range));
|
|
55
|
-
}
|
|
56
|
-
addRestoreNodeProcess(process) {
|
|
57
|
-
this.restoreNodeProcesses.push(process);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Restore AST nodes
|
|
61
|
-
*/
|
|
62
|
-
restore(result) {
|
|
63
|
-
// remap locations
|
|
64
|
-
const traversed = new Map();
|
|
65
|
-
(0, traverse_1.traverseNodes)(result.ast, {
|
|
66
|
-
visitorKeys: result.visitorKeys,
|
|
67
|
-
enterNode: (node, p) => {
|
|
68
|
-
if (!traversed.has(node)) {
|
|
69
|
-
traversed.set(node, p);
|
|
70
|
-
this.remapLocation(node);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
leaveNode: (_node) => {
|
|
74
|
-
// noop
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const tokens = [...this.tokens];
|
|
78
|
-
for (const token of result.ast.tokens || []) {
|
|
79
|
-
if (this.fragments.some((f) => f.start <= token.range[0] && token.range[1] <= f.end)) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
this.remapLocation(token);
|
|
83
|
-
tokens.push(token);
|
|
84
|
-
}
|
|
85
|
-
result.ast.tokens = tokens;
|
|
86
|
-
for (const token of result.ast.comments || []) {
|
|
87
|
-
this.remapLocation(token);
|
|
88
|
-
}
|
|
89
|
-
const context = new RestoreNodeProcessContext(result, traversed);
|
|
90
|
-
let restoreNodeProcesses = this.restoreNodeProcesses;
|
|
91
|
-
for (const [node, parent] of traversed) {
|
|
92
|
-
if (!parent)
|
|
93
|
-
continue;
|
|
94
|
-
restoreNodeProcesses = restoreNodeProcesses.filter((proc) => !proc(node, context));
|
|
95
|
-
}
|
|
96
|
-
if (context.removeTokens.size) {
|
|
97
|
-
const tokens = result.ast.tokens || [];
|
|
98
|
-
for (let index = tokens.length - 1; index >= 0; index--) {
|
|
99
|
-
const token = tokens[index];
|
|
100
|
-
for (const rt of context.removeTokens) {
|
|
101
|
-
if (rt(token)) {
|
|
102
|
-
tokens.splice(index, 1);
|
|
103
|
-
context.removeTokens.delete(rt);
|
|
104
|
-
if (!context.removeTokens.size) {
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Adjust program node location
|
|
112
|
-
const firstOffset = Math.min(...[
|
|
113
|
-
result.ast.body[0],
|
|
114
|
-
result.ast.tokens?.[0],
|
|
115
|
-
result.ast.comments?.[0],
|
|
116
|
-
]
|
|
117
|
-
.filter(Boolean)
|
|
118
|
-
.map((t) => t.range[0]));
|
|
119
|
-
if (firstOffset < result.ast.range[0]) {
|
|
120
|
-
result.ast.range[0] = firstOffset;
|
|
121
|
-
result.ast.loc.start = this.ctx.getLocFromIndex(firstOffset);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
remapLocation(node) {
|
|
125
|
-
let [start, end] = node.range;
|
|
126
|
-
const startFragment = this.fragments.find((f) => f.start <= start && start < f.end);
|
|
127
|
-
if (startFragment) {
|
|
128
|
-
start = startFragment.end;
|
|
129
|
-
}
|
|
130
|
-
const endFragment = this.fragments.find((f) => f.start < end && end <= f.end);
|
|
131
|
-
if (endFragment) {
|
|
132
|
-
end = endFragment.start;
|
|
133
|
-
}
|
|
134
|
-
if (end < start) {
|
|
135
|
-
const w = start;
|
|
136
|
-
start = end;
|
|
137
|
-
end = w;
|
|
138
|
-
}
|
|
139
|
-
const locs = this.ctx.getLocations(...this.getRemapRange(start, end));
|
|
140
|
-
node.loc = locs.loc;
|
|
141
|
-
node.range = locs.range;
|
|
142
|
-
if (node.start != null) {
|
|
143
|
-
delete node.start;
|
|
144
|
-
}
|
|
145
|
-
if (node.end != null) {
|
|
146
|
-
delete node.end;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
getRemapRange(start, end) {
|
|
150
|
-
if (!this.offsets.length) {
|
|
151
|
-
return [start, end];
|
|
152
|
-
}
|
|
153
|
-
let lastStart = this.offsets[0];
|
|
154
|
-
let lastEnd = this.offsets[0];
|
|
155
|
-
for (const offset of this.offsets) {
|
|
156
|
-
if (offset.script <= start) {
|
|
157
|
-
lastStart = offset;
|
|
158
|
-
}
|
|
159
|
-
if (offset.script < end) {
|
|
160
|
-
lastEnd = offset;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
if (offset.script === end) {
|
|
164
|
-
const remapStart = lastStart.original + (start - lastStart.script);
|
|
165
|
-
if (this.tokens.some((t) => t.range[0] <= remapStart &&
|
|
166
|
-
offset.original <= t.range[1])) {
|
|
167
|
-
lastEnd = offset;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const remapStart = lastStart.original + (start - lastStart.script);
|
|
174
|
-
const remapEnd = lastEnd.original + (end - lastEnd.script);
|
|
175
|
-
return [remapStart, remapEnd];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.ScriptContext = ScriptContext;
|
package/lib/debug.d.ts
DELETED
package/lib/debug.js
DELETED
|
@@ -1,8 +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.debug = void 0;
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
exports.debug = (0, debug_1.default)("astro-eslint-parser");
|
package/lib/errors.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Context } from "./context";
|
|
2
|
-
/**
|
|
3
|
-
* Astro parse errors.
|
|
4
|
-
*/
|
|
5
|
-
export declare class ParseError extends SyntaxError {
|
|
6
|
-
index: number;
|
|
7
|
-
lineNumber: number;
|
|
8
|
-
column: number;
|
|
9
|
-
originalAST: any;
|
|
10
|
-
/**
|
|
11
|
-
* Initialize this ParseError instance.
|
|
12
|
-
*/
|
|
13
|
-
constructor(message: string, offset: number, ctx: Context);
|
|
14
|
-
}
|
package/lib/errors.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParseError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Astro parse errors.
|
|
6
|
-
*/
|
|
7
|
-
class ParseError extends SyntaxError {
|
|
8
|
-
/**
|
|
9
|
-
* Initialize this ParseError instance.
|
|
10
|
-
*/
|
|
11
|
-
constructor(message, offset, ctx) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.index = offset;
|
|
14
|
-
const loc = ctx.getLocFromIndex(offset);
|
|
15
|
-
this.lineNumber = loc.line;
|
|
16
|
-
this.column = loc.column;
|
|
17
|
-
this.originalAST = ctx.originalAST;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.ParseError = ParseError;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFrontmatter = void 0;
|
|
4
|
-
/** Parse frontmatter */
|
|
5
|
-
function parseFrontmatter(code) {
|
|
6
|
-
if (!code.startsWith("---") || code[3] === "-") {
|
|
7
|
-
return {
|
|
8
|
-
frontmatter: null,
|
|
9
|
-
content: {
|
|
10
|
-
range: [0, code.length],
|
|
11
|
-
value: code,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
let closeIndex = code.indexOf("\n---", 3);
|
|
16
|
-
let contentOpenIndex = closeIndex + 4;
|
|
17
|
-
if (closeIndex === -1) {
|
|
18
|
-
closeIndex = code.length;
|
|
19
|
-
contentOpenIndex = code.length;
|
|
20
|
-
}
|
|
21
|
-
let openIndex = 3;
|
|
22
|
-
if (code[openIndex] === "\r") {
|
|
23
|
-
openIndex++;
|
|
24
|
-
}
|
|
25
|
-
if (code[openIndex] === "\n") {
|
|
26
|
-
openIndex++;
|
|
27
|
-
}
|
|
28
|
-
if (openIndex < closeIndex && code[closeIndex] === "\n") {
|
|
29
|
-
closeIndex--;
|
|
30
|
-
}
|
|
31
|
-
if (openIndex < closeIndex && code[closeIndex] === "\r") {
|
|
32
|
-
closeIndex++;
|
|
33
|
-
}
|
|
34
|
-
if (code[contentOpenIndex] === "\r") {
|
|
35
|
-
contentOpenIndex++;
|
|
36
|
-
}
|
|
37
|
-
if (code[contentOpenIndex] === "\n") {
|
|
38
|
-
contentOpenIndex++;
|
|
39
|
-
}
|
|
40
|
-
const frontmatter = code.slice(openIndex, closeIndex + 1);
|
|
41
|
-
const content = code.slice(contentOpenIndex);
|
|
42
|
-
return {
|
|
43
|
-
frontmatter: {
|
|
44
|
-
range: [openIndex, closeIndex + 1],
|
|
45
|
-
value: frontmatter,
|
|
46
|
-
},
|
|
47
|
-
content: {
|
|
48
|
-
range: [contentOpenIndex, code.length],
|
|
49
|
-
value: content,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
exports.parseFrontmatter = parseFrontmatter;
|
package/lib/markdown/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ScopeManager } from "eslint-scope";
|
|
2
|
-
import type { AstroProgram } from "../ast";
|
|
3
|
-
import type { ParseResult } from "@astrojs/compiler/node";
|
|
4
|
-
/**
|
|
5
|
-
* Parse source code
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseForESLint(code: string, options?: any): {
|
|
8
|
-
ast: AstroProgram;
|
|
9
|
-
services: Record<string, any> & {
|
|
10
|
-
isAstro: true;
|
|
11
|
-
getAstroAst: () => ParseResult;
|
|
12
|
-
isAstroMarkdown: true;
|
|
13
|
-
getAstroMarkdownFrontmatter: () => any;
|
|
14
|
-
};
|
|
15
|
-
visitorKeys: {
|
|
16
|
-
[type: string]: string[];
|
|
17
|
-
};
|
|
18
|
-
scopeManager: ScopeManager;
|
|
19
|
-
};
|
package/lib/markdown/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseForESLint = void 0;
|
|
4
|
-
const context_1 = require("../context");
|
|
5
|
-
const mdast_util_from_markdown_service_1 = require("./mdast-util-from-markdown-service");
|
|
6
|
-
const frontmatter_1 = require("./frontmatter");
|
|
7
|
-
const process_markdown_1 = require("./process-markdown");
|
|
8
|
-
const parser_1 = require("../parser");
|
|
9
|
-
const sort_1 = require("../parser/sort");
|
|
10
|
-
const script_1 = require("../context/script");
|
|
11
|
-
const yaml_1 = require("./yaml");
|
|
12
|
-
/**
|
|
13
|
-
* Parse source code
|
|
14
|
-
*/
|
|
15
|
-
function parseForESLint(code, options) {
|
|
16
|
-
const { frontmatter, content } = (0, frontmatter_1.parseFrontmatter)(code);
|
|
17
|
-
const ctx = new context_1.Context(code);
|
|
18
|
-
const root = (0, mdast_util_from_markdown_service_1.parseMarkdown)(content.value);
|
|
19
|
-
const scriptContext = new script_1.ScriptContext(ctx);
|
|
20
|
-
let yamlResult;
|
|
21
|
-
if (frontmatter) {
|
|
22
|
-
scriptContext.appendOriginal(frontmatter.range[0]);
|
|
23
|
-
yamlResult = (0, yaml_1.parseYaml)(frontmatter);
|
|
24
|
-
if (yamlResult) {
|
|
25
|
-
scriptContext.skipOriginalOffset(yamlResult.setupValueRange[0] - frontmatter.range[0]);
|
|
26
|
-
scriptContext.appendOriginal(yamlResult.setupValueRange[1]);
|
|
27
|
-
scriptContext.skipOriginalOffset(frontmatter.range[1] - yamlResult.setupValueRange[1]);
|
|
28
|
-
scriptContext.addToken("YAMLToken", [
|
|
29
|
-
frontmatter.range[0],
|
|
30
|
-
yamlResult.before,
|
|
31
|
-
]);
|
|
32
|
-
scriptContext.addToken("YAMLToken", [
|
|
33
|
-
yamlResult.after,
|
|
34
|
-
frontmatter.range[1],
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
scriptContext.skipOriginalOffset(frontmatter.range[1] - frontmatter.range[0]);
|
|
39
|
-
scriptContext.addToken("YAMLToken", [
|
|
40
|
-
frontmatter.range[0],
|
|
41
|
-
frontmatter.range[1],
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
(0, process_markdown_1.processMarkdown)(scriptContext, root, content.range[0]);
|
|
46
|
-
scriptContext.appendOriginal(code.length);
|
|
47
|
-
const resultAstro = (0, parser_1.parseForESLint)(scriptContext.script, options);
|
|
48
|
-
scriptContext.restore(resultAstro);
|
|
49
|
-
(0, sort_1.sort)(resultAstro.ast.comments);
|
|
50
|
-
(0, sort_1.sort)(resultAstro.ast.tokens);
|
|
51
|
-
(0, parser_1.extractTokens)(resultAstro, ctx);
|
|
52
|
-
resultAstro.services = Object.assign(resultAstro.services || {}, {
|
|
53
|
-
isAstroMarkdown: true,
|
|
54
|
-
getAstroMarkdownFrontmatter() {
|
|
55
|
-
return yamlResult?.getYamlValue();
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
return resultAstro;
|
|
59
|
-
}
|
|
60
|
-
exports.parseForESLint = parseForESLint;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMarkdown = void 0;
|
|
4
|
-
const synckit_1 = require("synckit");
|
|
5
|
-
const parseSync = (0, synckit_1.createSyncFn)(require.resolve("./mdast-util-from-markdown-worker"));
|
|
6
|
-
/**
|
|
7
|
-
* Parse code by `mdast-util-from-markdown`
|
|
8
|
-
*/
|
|
9
|
-
function parseMarkdown(code) {
|
|
10
|
-
return parseSync(code);
|
|
11
|
-
}
|
|
12
|
-
exports.parseMarkdown = parseMarkdown;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const synckit_1 = require("synckit");
|
|
4
|
-
const dynamicImport = new Function("m", "return import(m)");
|
|
5
|
-
(0, synckit_1.runAsWorker)(async (source) => {
|
|
6
|
-
const { fromMarkdown } = await dynamicImport("mdast-util-from-markdown");
|
|
7
|
-
return fromMarkdown(source);
|
|
8
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processMarkdown = void 0;
|
|
4
|
-
const types_1 = require("@typescript-eslint/types");
|
|
5
|
-
/**
|
|
6
|
-
* Process the markdown ast to generate a ScriptContext.
|
|
7
|
-
*/
|
|
8
|
-
function processMarkdown(script, root, offset) {
|
|
9
|
-
walk(root, (node) => {
|
|
10
|
-
const start = node.position.start.offset + offset;
|
|
11
|
-
const end = node.position.end.offset + offset;
|
|
12
|
-
script.appendOriginal(start);
|
|
13
|
-
if (node.type === "code" || node.type === "inlineCode") {
|
|
14
|
-
script.appendScript(`<></>`);
|
|
15
|
-
script.skipOriginalOffset(end - start);
|
|
16
|
-
script.addRestoreNodeProcess((scriptNode, context) => {
|
|
17
|
-
if (scriptNode.range[0] === start &&
|
|
18
|
-
scriptNode.type === types_1.AST_NODE_TYPES.JSXFragment) {
|
|
19
|
-
delete scriptNode.openingFragment;
|
|
20
|
-
delete scriptNode.closingFragment;
|
|
21
|
-
delete scriptNode.expression;
|
|
22
|
-
delete scriptNode.children;
|
|
23
|
-
const text = script.originalCode.slice(start, end);
|
|
24
|
-
const mdNode = scriptNode;
|
|
25
|
-
mdNode.type = "AstroRawText";
|
|
26
|
-
mdNode.value = text;
|
|
27
|
-
mdNode.raw = text;
|
|
28
|
-
let parent = context.getParent(scriptNode);
|
|
29
|
-
while (parent) {
|
|
30
|
-
let update = false;
|
|
31
|
-
if (parent.range[0] > scriptNode.range[0]) {
|
|
32
|
-
parent.range[0] = scriptNode.range[0];
|
|
33
|
-
parent.loc.start = {
|
|
34
|
-
line: scriptNode.loc.start.line,
|
|
35
|
-
column: scriptNode.loc.start.column,
|
|
36
|
-
};
|
|
37
|
-
update = true;
|
|
38
|
-
}
|
|
39
|
-
if (parent.range[1] < scriptNode.range[1]) {
|
|
40
|
-
parent.range[1] = scriptNode.range[1];
|
|
41
|
-
parent.loc.end = {
|
|
42
|
-
line: scriptNode.loc.end.line,
|
|
43
|
-
column: scriptNode.loc.end.column,
|
|
44
|
-
};
|
|
45
|
-
update = true;
|
|
46
|
-
}
|
|
47
|
-
if (!update) {
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
parent = context.getParent(parent);
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
});
|
|
56
|
-
script.addToken(types_1.AST_TOKEN_TYPES.JSXText, [start, end]);
|
|
57
|
-
}
|
|
58
|
-
}, (node) => {
|
|
59
|
-
// const start = node.position!.start.offset! + offset
|
|
60
|
-
const end = node.position.end.offset + offset;
|
|
61
|
-
script.appendOriginal(end);
|
|
62
|
-
});
|
|
63
|
-
script.addRestoreNodeProcess((scriptNode) => {
|
|
64
|
-
if (scriptNode.type === "JSXText") {
|
|
65
|
-
const rawNode = scriptNode;
|
|
66
|
-
rawNode.type = "AstroRawText";
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.processMarkdown = processMarkdown;
|
|
72
|
-
/** walk nodes */
|
|
73
|
-
function walk(parent, enter, leave, parents = []) {
|
|
74
|
-
const currParents = [parent, ...parents];
|
|
75
|
-
if ("children" in parent) {
|
|
76
|
-
for (const node of parent.children) {
|
|
77
|
-
enter(node, currParents);
|
|
78
|
-
walk(node, enter, leave, currParents);
|
|
79
|
-
leave(node, currParents);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
package/lib/markdown/yaml.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MarkdownContent } from "./frontmatter";
|
|
2
|
-
export declare type FrontmatterYAMLResult = {
|
|
3
|
-
before: number;
|
|
4
|
-
setupValueRange: [number, number];
|
|
5
|
-
after: number;
|
|
6
|
-
getYamlValue: () => any;
|
|
7
|
-
};
|
|
8
|
-
/** Parse for yaml */
|
|
9
|
-
export declare function parseYaml(frontmatter: MarkdownContent): FrontmatterYAMLResult | null;
|