astro-eslint-parser 0.0.17 → 0.2.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.
Files changed (47) hide show
  1. package/README.md +21 -10
  2. package/lib/ast/astro.d.ts +49 -0
  3. package/lib/{ast.js → ast/astro.js} +0 -0
  4. package/lib/ast/base.d.ts +6 -0
  5. package/lib/ast/base.js +2 -0
  6. package/lib/ast/index.d.ts +8 -0
  7. package/lib/ast/index.js +18 -0
  8. package/lib/ast/jsx.d.ts +91 -0
  9. package/lib/ast/jsx.js +2 -0
  10. package/lib/astro/index.js +2 -4
  11. package/lib/astro-tools/index.d.ts +21 -0
  12. package/lib/astro-tools/index.js +26 -0
  13. package/lib/context/index.d.ts +13 -8
  14. package/lib/context/index.js +51 -100
  15. package/lib/context/parser-options.d.ts +8 -0
  16. package/lib/context/parser-options.js +71 -0
  17. package/lib/{parser → context/resolve-parser}/espree.d.ts +1 -1
  18. package/lib/{parser → context/resolve-parser}/espree.js +3 -18
  19. package/lib/context/resolve-parser/index.d.ts +5 -0
  20. package/lib/{parser/resolve-parser.js → context/resolve-parser/index.js} +0 -0
  21. package/lib/context/script.d.ts +1 -1
  22. package/lib/context/script.js +2 -3
  23. package/lib/index.d.ts +2 -1
  24. package/lib/index.js +3 -1
  25. package/lib/parser/astro-parser/astrojs-compiler-service.d.ts +2 -4
  26. package/lib/parser/astro-parser/astrojs-compiler-service.js +3 -12
  27. package/lib/parser/astro-parser/astrojs-compiler-worker.d.ts +1 -0
  28. package/lib/parser/astro-parser/astrojs-compiler-worker.js +11 -0
  29. package/lib/parser/astro-parser/parse.js +7 -51
  30. package/lib/parser/index.d.ts +0 -17
  31. package/lib/parser/index.js +6 -31
  32. package/lib/parser/lru-cache.d.ts +7 -0
  33. package/lib/parser/lru-cache.js +32 -0
  34. package/lib/parser/process-template.js +24 -5
  35. package/lib/parser/script.d.ts +3 -2
  36. package/lib/parser/script.js +18 -19
  37. package/lib/parser/template.d.ts +10 -0
  38. package/lib/parser/template.js +102 -0
  39. package/lib/parser/ts-patch.d.ts +8 -0
  40. package/lib/parser/ts-patch.js +58 -0
  41. package/lib/types.d.ts +21 -0
  42. package/lib/types.js +2 -0
  43. package/package.json +15 -11
  44. package/lib/ast.d.ts +0 -48
  45. package/lib/parser/astro-parser/wasm_exec.d.ts +0 -35
  46. package/lib/parser/astro-parser/wasm_exec.js +0 -470
  47. package/lib/parser/resolve-parser.d.ts +0 -16
@@ -0,0 +1,58 @@
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.tsPatch = void 0;
7
+ const module_1 = require("module");
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ /**
11
+ * Apply a patch to parse .astro files as TSX.
12
+ */
13
+ function tsPatch(scriptParserOptions) {
14
+ try {
15
+ // Apply a patch to parse .astro files as TSX.
16
+ const cwd = process.cwd();
17
+ const relativeTo = path_1.default.join(cwd, "__placeholder__.js");
18
+ const ts = (0, module_1.createRequire)(relativeTo)("typescript");
19
+ const { ensureScriptKind, getScriptKindFromFileName } = ts;
20
+ if (typeof ensureScriptKind === "function" &&
21
+ typeof getScriptKindFromFileName === "function") {
22
+ ts.ensureScriptKind = function (fileName, ...args) {
23
+ if (fileName.endsWith(".astro")) {
24
+ return ts.ScriptKind.TSX;
25
+ }
26
+ return ensureScriptKind.call(this, fileName, ...args);
27
+ };
28
+ ts.getScriptKindFromFileName = function (fileName, ...args) {
29
+ if (fileName.endsWith(".astro")) {
30
+ return ts.ScriptKind.TSX;
31
+ }
32
+ return getScriptKindFromFileName.call(this, fileName, ...args);
33
+ };
34
+ return {
35
+ terminate() {
36
+ ts.ensureScriptKind = ensureScriptKind;
37
+ ts.getScriptKindFromFileName = getScriptKindFromFileName;
38
+ },
39
+ };
40
+ }
41
+ }
42
+ catch {
43
+ // ignore
44
+ }
45
+ // If the patch cannot be applied, create a tsx file and parse it.
46
+ const tsxFilePath = `${scriptParserOptions.filePath}.tsx`;
47
+ scriptParserOptions.filePath = tsxFilePath;
48
+ if (!fs_1.default.existsSync(tsxFilePath)) {
49
+ fs_1.default.writeFileSync(tsxFilePath, "/* temp for astro-eslint-parser */");
50
+ return {
51
+ terminate() {
52
+ fs_1.default.unlinkSync(tsxFilePath);
53
+ },
54
+ };
55
+ }
56
+ return null;
57
+ }
58
+ exports.tsPatch = tsPatch;
package/lib/types.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { TSESTree } from "@typescript-eslint/types";
2
+ import type { ScopeManager } from "eslint-scope";
3
+ /**
4
+ * The parsing result of ESLint custom parsers.
5
+ */
6
+ export interface ESLintExtendedProgram {
7
+ ast: TSESTree.Program;
8
+ services?: Record<string, any>;
9
+ visitorKeys?: {
10
+ [type: string]: string[];
11
+ };
12
+ scopeManager?: ScopeManager;
13
+ }
14
+ /**
15
+ * The interface of a result of ESLint custom parser.
16
+ */
17
+ export declare type ESLintCustomParserResult = ESLintExtendedProgram["ast"] | ESLintExtendedProgram;
18
+ export interface ESLintCustomParser {
19
+ parse(code: string, options: any): ESLintCustomParserResult;
20
+ parseForESLint?(code: string, options: any): ESLintCustomParserResult;
21
+ }
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.0.17",
3
+ "version": "0.2.0",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "prebuild": "npm run -s clean",
14
14
  "build": "tsc --project ./tsconfig.build.json",
15
15
  "clean": "rimraf .nyc_output lib coverage",
16
- "lint": "eslint . --ext .js,.ts,.json",
16
+ "lint": "eslint . --ext .js,.ts,.json,.astro,.svelte",
17
17
  "eslint-fix": "npm run lint -- --fix",
18
18
  "test": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
19
19
  "cover": "nyc --reporter=lcov npm run test",
@@ -42,13 +42,16 @@
42
42
  },
43
43
  "homepage": "https://github.com/ota-meshi/astro-eslint-parser#readme",
44
44
  "dependencies": {
45
- "@astrojs/compiler": "^0.14.2",
45
+ "@astrojs/compiler": "^0.15.0",
46
+ "@typescript-eslint/types": "^5.25.0",
46
47
  "debug": "^4.3.4",
47
48
  "eslint-visitor-keys": "^3.0.0",
48
- "espree": "^9.0.0"
49
+ "espree": "^9.0.0",
50
+ "synckit": "^0.7.1"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@ota-meshi/eslint-plugin": "^0.10.0",
54
+ "@ota-meshi/eslint-plugin-svelte": "^0.34.0",
52
55
  "@types/benchmark": "^2.1.1",
53
56
  "@types/chai": "^4.3.0",
54
57
  "@types/debug": "^4.1.7",
@@ -60,22 +63,22 @@
60
63
  "@types/semver": "^7.3.9",
61
64
  "@typescript-eslint/eslint-plugin": "^5.4.0",
62
65
  "@typescript-eslint/parser": "^5.4.0",
63
- "astro-eslint-parser": ">=0.0.15",
66
+ "astro-eslint-parser": ">=0.1.0",
64
67
  "benchmark": "^2.1.4",
65
68
  "chai": "^4.3.4",
66
69
  "code-red": "^0.2.3",
67
- "eslint": "^8.14.0",
70
+ "eslint": "^8.15.0",
68
71
  "eslint-config-prettier": "^8.3.0",
69
72
  "eslint-formatter-codeframe": "^7.32.1",
73
+ "eslint-plugin-astro": "^0.2.0",
70
74
  "eslint-plugin-eslint-comments": "^3.2.0",
71
- "eslint-plugin-json-schema-validator": "^2.1.6",
75
+ "eslint-plugin-json-schema-validator": "^3.0.0",
72
76
  "eslint-plugin-jsonc": "^2.0.0",
73
77
  "eslint-plugin-node": "^11.1.0",
74
78
  "eslint-plugin-node-dependencies": "^0.8.0",
75
79
  "eslint-plugin-prettier": "^4.0.0",
76
80
  "eslint-plugin-react": "^7.29.4",
77
81
  "eslint-plugin-regexp": "^1.5.0",
78
- "eslint-plugin-vue": "^8.0.3",
79
82
  "estree-walker": "^3.0.0",
80
83
  "locate-character": "^2.0.5",
81
84
  "magic-string": "^0.26.0",
@@ -83,11 +86,12 @@
83
86
  "mocha-chai-jest-snapshot": "^1.1.3",
84
87
  "nyc": "^15.1.0",
85
88
  "prettier": "^2.0.5",
86
- "prettier-plugin-astro": "^0.0.12",
89
+ "prettier-plugin-astro": "^0.1.0-0",
90
+ "prettier-plugin-svelte": "^2.7.0",
87
91
  "semver": "^7.3.5",
88
92
  "string-replace-loader": "^3.0.3",
93
+ "svelte": "^3.48.0",
89
94
  "ts-node": "^10.4.0",
90
- "typescript": "~4.6.0",
91
- "vue-eslint-parser": "^9.0.0"
95
+ "typescript": "~4.7.0"
92
96
  }
93
97
  }
package/lib/ast.d.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { TSESTree } from "@typescript-eslint/types";
2
- export declare type AstroNode = AstroProgram | AstroFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
3
- export declare type AstroChild = TSESTree.JSXFragment["children"][number] | AstroHTMLComment;
4
- /** Node of Astro program root */
5
- export interface AstroProgram extends Omit<TSESTree.Program, "type" | "body"> {
6
- type: "Program";
7
- body: (TSESTree.Program["body"][number] | AstroFragment)[];
8
- sourceType: "script" | "module";
9
- comments: TSESTree.Comment[];
10
- tokens: TSESTree.Token[];
11
- parent: undefined;
12
- }
13
- /** Node of Astro fragment */
14
- export interface AstroFragment extends Omit<TSESTree.BaseNode, "type" | "parent"> {
15
- type: "AstroFragment";
16
- children: AstroChild[];
17
- parent: TSESTree.JSXFragment["parent"];
18
- }
19
- /** Node of Astro html comment */
20
- export interface AstroHTMLComment extends Omit<TSESTree.BaseNode, "type" | "parent"> {
21
- type: "AstroHTMLComment";
22
- value: string;
23
- parent: AstroFragment | AstroFragment | TSESTree.JSXElement | TSESTree.JSXFragment;
24
- }
25
- /** Node of Astro doctype */
26
- export interface AstroDoctype extends Omit<TSESTree.BaseNode, "type" | "parent"> {
27
- type: "AstroDoctype";
28
- parent: AstroFragment | AstroFragment;
29
- }
30
- /** Node of Astro shorthand attribute */
31
- export interface AstroShorthandAttribute extends Omit<TSESTree.JSXAttribute, "type" | "parent"> {
32
- type: "AstroShorthandAttribute";
33
- value: TSESTree.JSXExpressionContainer;
34
- parent: TSESTree.JSXElement | TSESTree.JSXFragment;
35
- }
36
- /** Node of Astro template-literal attribute */
37
- export interface AstroTemplateLiteralAttribute extends Omit<TSESTree.JSXAttribute, "type" | "parent"> {
38
- type: "AstroTemplateLiteralAttribute";
39
- value: TSESTree.JSXExpressionContainer & {
40
- expression: TSESTree.TemplateLiteral;
41
- };
42
- parent: TSESTree.JSXElement | TSESTree.JSXFragment;
43
- }
44
- /** Node of Astro raw text */
45
- export interface AstroRawText extends Omit<TSESTree.JSXText, "type" | "parent"> {
46
- type: "AstroRawText";
47
- parent: AstroFragment | TSESTree.JSXElement | TSESTree.JSXFragment;
48
- }
@@ -1,35 +0,0 @@
1
- export default class Go {
2
- importObject: {
3
- go: {
4
- 'runtime.wasmExit': (sp: any) => void;
5
- 'runtime.wasmWrite': (sp: any) => void;
6
- 'runtime.resetMemoryDataView': (sp: any) => void;
7
- 'runtime.nanotime1': (sp: any) => void;
8
- 'runtime.walltime': (sp: any) => void;
9
- 'runtime.scheduleTimeoutEvent': (sp: any) => void;
10
- 'runtime.clearTimeoutEvent': (sp: any) => void;
11
- 'runtime.getRandomData': (sp: any) => void;
12
- 'syscall/js.finalizeRef': (sp: any) => void;
13
- 'syscall/js.stringVal': (sp: any) => void;
14
- 'syscall/js.valueGet': (sp: any) => void;
15
- 'syscall/js.valueSet': (sp: any) => void;
16
- 'syscall/js.valueDelete': (sp: any) => void;
17
- 'syscall/js.valueIndex': (sp: any) => void;
18
- 'syscall/js.valueSetIndex': (sp: any) => void;
19
- 'syscall/js.valueCall': (sp: any) => void;
20
- 'syscall/js.valueInvoke': (sp: any) => void;
21
- 'syscall/js.valueNew': (sp: any) => void;
22
- 'syscall/js.valueLength': (sp: any) => void;
23
- 'syscall/js.valuePrepareString': (sp: any) => void;
24
- 'syscall/js.valueLoadString': (sp: any) => void;
25
- 'syscall/js.valueInstanceOf': (sp: any) => void;
26
- 'syscall/js.copyBytesToGo': (sp: any) => void;
27
- 'syscall/js.copyBytesToJS': (sp: any) => void;
28
- debug: (value: any) => void;
29
- };
30
- };
31
- constructor();
32
- run(instance: any): Promise<void>;
33
- private _resume;
34
- private _makeFuncWrapper;
35
- }