astro-eslint-parser 0.9.4 → 0.10.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/lib/index.d.ts +1 -1
- package/lib/index.js +33 -26
- package/lib/index.mjs +33 -26
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as eslint from 'eslint';
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
3
|
-
import { ScopeManager } from 'eslint-
|
|
3
|
+
import { ScopeManager } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { ParseResult } from '@astrojs/compiler';
|
|
5
5
|
import { Node, AttributeNode, ParentNode } from '@astrojs/compiler/types';
|
|
6
6
|
import { VisitorKeys as VisitorKeys$1 } from '@typescript-eslint/visitor-keys';
|
package/lib/index.js
CHANGED
|
@@ -137,21 +137,31 @@ function isTSESLintParserObject(value) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// src/parser/script.ts
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
var import_scope_manager = require("@typescript-eslint/scope-manager");
|
|
141
|
+
function parseScript(code, ctx, parserOptionsCtx) {
|
|
142
|
+
const result = parseScriptInternal(code, ctx, parserOptionsCtx);
|
|
143
|
+
const parserOptions = parserOptionsCtx.parserOptions;
|
|
144
|
+
if (!result.scopeManager && parserOptions.eslintScopeManager) {
|
|
145
|
+
result.scopeManager = (0, import_scope_manager.analyze)(result.ast, {
|
|
146
|
+
ecmaVersion: 1e8,
|
|
147
|
+
globalReturn: parserOptions.ecmaFeatures?.globalReturn,
|
|
148
|
+
jsxPragma: parserOptions.jsxPragma,
|
|
149
|
+
jsxFragmentName: parserOptions.jsxFragmentName,
|
|
150
|
+
lib: parserOptions.lib,
|
|
151
|
+
sourceType: parserOptions.sourceType
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function parseScriptInternal(code, _ctx, parserOptionsCtx) {
|
|
157
|
+
const parser = parserOptionsCtx.getParser();
|
|
142
158
|
let patchResult;
|
|
143
159
|
try {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
scriptParserOptions.ecmaFeatures = {
|
|
148
|
-
...scriptParserOptions.ecmaFeatures || {},
|
|
149
|
-
jsx: true
|
|
150
|
-
};
|
|
151
|
-
if (parserOptions.isTypeScript() && scriptParserOptions.filePath && scriptParserOptions.project) {
|
|
152
|
-
patchResult = tsPatch(scriptParserOptions);
|
|
160
|
+
const parserOptions = parserOptionsCtx.parserOptions;
|
|
161
|
+
if (parserOptionsCtx.isTypeScript() && parserOptions.filePath && parserOptions.project) {
|
|
162
|
+
patchResult = tsPatch(parserOptions);
|
|
153
163
|
}
|
|
154
|
-
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code,
|
|
164
|
+
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code, parserOptions) : parser.parse(code, parserOptions);
|
|
155
165
|
if ("ast" in result && result.ast != null) {
|
|
156
166
|
return result;
|
|
157
167
|
}
|
|
@@ -1763,7 +1773,6 @@ var ParserOptionsContext = class {
|
|
|
1763
1773
|
tokens: true,
|
|
1764
1774
|
comment: true,
|
|
1765
1775
|
eslintVisitorKeys: true,
|
|
1766
|
-
eslintScopeManager: true,
|
|
1767
1776
|
...options || {}
|
|
1768
1777
|
};
|
|
1769
1778
|
parserOptions.ecmaFeatures = {
|
|
@@ -1816,7 +1825,8 @@ var ParserOptionsContext = class {
|
|
|
1816
1825
|
};
|
|
1817
1826
|
|
|
1818
1827
|
// src/parser/scope/index.ts
|
|
1819
|
-
var
|
|
1828
|
+
var import_scope_manager2 = require("@typescript-eslint/scope-manager");
|
|
1829
|
+
var import_Reference = require("@typescript-eslint/scope-manager/dist/referencer/Reference");
|
|
1820
1830
|
function getProgramScope(scopeManager) {
|
|
1821
1831
|
const globalScope = scopeManager.globalScope;
|
|
1822
1832
|
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
@@ -1851,15 +1861,12 @@ function removeAllScopeAndVariableAndReference(target, info) {
|
|
|
1851
1861
|
}
|
|
1852
1862
|
}
|
|
1853
1863
|
function addVirtualReference(node, variable, scope, readWrite) {
|
|
1854
|
-
const reference = new
|
|
1864
|
+
const reference = new import_scope_manager2.Reference(
|
|
1865
|
+
node,
|
|
1866
|
+
scope,
|
|
1867
|
+
readWrite.write && readWrite.read ? import_Reference.ReferenceFlag.ReadWrite : readWrite.write ? import_Reference.ReferenceFlag.Write : import_Reference.ReferenceFlag.Read
|
|
1868
|
+
);
|
|
1855
1869
|
reference.astroVirtualReference = true;
|
|
1856
|
-
reference.from = scope;
|
|
1857
|
-
reference.identifier = node;
|
|
1858
|
-
reference.isWrite = () => Boolean(readWrite.write);
|
|
1859
|
-
reference.isWriteOnly = () => Boolean(readWrite.write) && !readWrite.read;
|
|
1860
|
-
reference.isRead = () => Boolean(readWrite.read);
|
|
1861
|
-
reference.isReadOnly = () => Boolean(readWrite.read) && !readWrite.write;
|
|
1862
|
-
reference.isReadWrite = () => Boolean(readWrite.read && readWrite.write);
|
|
1863
1870
|
addReference(variable.references, reference);
|
|
1864
1871
|
reference.resolved = variable;
|
|
1865
1872
|
return reference;
|
|
@@ -1869,9 +1876,7 @@ function addGlobalVariable(reference, scopeManager) {
|
|
|
1869
1876
|
const name = reference.identifier.name;
|
|
1870
1877
|
let variable = globalScope.set.get(name);
|
|
1871
1878
|
if (!variable) {
|
|
1872
|
-
variable = new
|
|
1873
|
-
variable.name = name;
|
|
1874
|
-
variable.scope = globalScope;
|
|
1879
|
+
variable = new import_scope_manager2.Variable(name, globalScope);
|
|
1875
1880
|
globalScope.variables.push(variable);
|
|
1876
1881
|
globalScope.set.set(name, variable);
|
|
1877
1882
|
}
|
|
@@ -2084,7 +2089,9 @@ function parseForESLint(code, options) {
|
|
|
2084
2089
|
propsVariable.identifiers[0],
|
|
2085
2090
|
propsVariable,
|
|
2086
2091
|
scope,
|
|
2087
|
-
{
|
|
2092
|
+
{
|
|
2093
|
+
read: true
|
|
2094
|
+
}
|
|
2088
2095
|
);
|
|
2089
2096
|
}
|
|
2090
2097
|
const astroGlobalReferences = scope.through.filter(
|
package/lib/index.mjs
CHANGED
|
@@ -108,21 +108,31 @@ function isTSESLintParserObject(value) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
// src/parser/script.ts
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
import { analyze } from "@typescript-eslint/scope-manager";
|
|
112
|
+
function parseScript(code, ctx, parserOptionsCtx) {
|
|
113
|
+
const result = parseScriptInternal(code, ctx, parserOptionsCtx);
|
|
114
|
+
const parserOptions = parserOptionsCtx.parserOptions;
|
|
115
|
+
if (!result.scopeManager && parserOptions.eslintScopeManager) {
|
|
116
|
+
result.scopeManager = analyze(result.ast, {
|
|
117
|
+
ecmaVersion: 1e8,
|
|
118
|
+
globalReturn: parserOptions.ecmaFeatures?.globalReturn,
|
|
119
|
+
jsxPragma: parserOptions.jsxPragma,
|
|
120
|
+
jsxFragmentName: parserOptions.jsxFragmentName,
|
|
121
|
+
lib: parserOptions.lib,
|
|
122
|
+
sourceType: parserOptions.sourceType
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function parseScriptInternal(code, _ctx, parserOptionsCtx) {
|
|
128
|
+
const parser = parserOptionsCtx.getParser();
|
|
113
129
|
let patchResult;
|
|
114
130
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
scriptParserOptions.ecmaFeatures = {
|
|
119
|
-
...scriptParserOptions.ecmaFeatures || {},
|
|
120
|
-
jsx: true
|
|
121
|
-
};
|
|
122
|
-
if (parserOptions.isTypeScript() && scriptParserOptions.filePath && scriptParserOptions.project) {
|
|
123
|
-
patchResult = tsPatch(scriptParserOptions);
|
|
131
|
+
const parserOptions = parserOptionsCtx.parserOptions;
|
|
132
|
+
if (parserOptionsCtx.isTypeScript() && parserOptions.filePath && parserOptions.project) {
|
|
133
|
+
patchResult = tsPatch(parserOptions);
|
|
124
134
|
}
|
|
125
|
-
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code,
|
|
135
|
+
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code, parserOptions) : parser.parse(code, parserOptions);
|
|
126
136
|
if ("ast" in result && result.ast != null) {
|
|
127
137
|
return result;
|
|
128
138
|
}
|
|
@@ -1734,7 +1744,6 @@ var ParserOptionsContext = class {
|
|
|
1734
1744
|
tokens: true,
|
|
1735
1745
|
comment: true,
|
|
1736
1746
|
eslintVisitorKeys: true,
|
|
1737
|
-
eslintScopeManager: true,
|
|
1738
1747
|
...options || {}
|
|
1739
1748
|
};
|
|
1740
1749
|
parserOptions.ecmaFeatures = {
|
|
@@ -1790,7 +1799,8 @@ var ParserOptionsContext = class {
|
|
|
1790
1799
|
import {
|
|
1791
1800
|
Reference as ReferenceClass,
|
|
1792
1801
|
Variable as VariableClass
|
|
1793
|
-
} from "eslint-
|
|
1802
|
+
} from "@typescript-eslint/scope-manager";
|
|
1803
|
+
import { ReferenceFlag } from "@typescript-eslint/scope-manager/dist/referencer/Reference";
|
|
1794
1804
|
function getProgramScope(scopeManager) {
|
|
1795
1805
|
const globalScope = scopeManager.globalScope;
|
|
1796
1806
|
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
@@ -1825,15 +1835,12 @@ function removeAllScopeAndVariableAndReference(target, info) {
|
|
|
1825
1835
|
}
|
|
1826
1836
|
}
|
|
1827
1837
|
function addVirtualReference(node, variable, scope, readWrite) {
|
|
1828
|
-
const reference = new ReferenceClass(
|
|
1838
|
+
const reference = new ReferenceClass(
|
|
1839
|
+
node,
|
|
1840
|
+
scope,
|
|
1841
|
+
readWrite.write && readWrite.read ? ReferenceFlag.ReadWrite : readWrite.write ? ReferenceFlag.Write : ReferenceFlag.Read
|
|
1842
|
+
);
|
|
1829
1843
|
reference.astroVirtualReference = true;
|
|
1830
|
-
reference.from = scope;
|
|
1831
|
-
reference.identifier = node;
|
|
1832
|
-
reference.isWrite = () => Boolean(readWrite.write);
|
|
1833
|
-
reference.isWriteOnly = () => Boolean(readWrite.write) && !readWrite.read;
|
|
1834
|
-
reference.isRead = () => Boolean(readWrite.read);
|
|
1835
|
-
reference.isReadOnly = () => Boolean(readWrite.read) && !readWrite.write;
|
|
1836
|
-
reference.isReadWrite = () => Boolean(readWrite.read && readWrite.write);
|
|
1837
1844
|
addReference(variable.references, reference);
|
|
1838
1845
|
reference.resolved = variable;
|
|
1839
1846
|
return reference;
|
|
@@ -1843,9 +1850,7 @@ function addGlobalVariable(reference, scopeManager) {
|
|
|
1843
1850
|
const name = reference.identifier.name;
|
|
1844
1851
|
let variable = globalScope.set.get(name);
|
|
1845
1852
|
if (!variable) {
|
|
1846
|
-
variable = new VariableClass();
|
|
1847
|
-
variable.name = name;
|
|
1848
|
-
variable.scope = globalScope;
|
|
1853
|
+
variable = new VariableClass(name, globalScope);
|
|
1849
1854
|
globalScope.variables.push(variable);
|
|
1850
1855
|
globalScope.set.set(name, variable);
|
|
1851
1856
|
}
|
|
@@ -2058,7 +2063,9 @@ function parseForESLint(code, options) {
|
|
|
2058
2063
|
propsVariable.identifiers[0],
|
|
2059
2064
|
propsVariable,
|
|
2060
2065
|
scope,
|
|
2061
|
-
{
|
|
2066
|
+
{
|
|
2067
|
+
read: true
|
|
2068
|
+
}
|
|
2062
2069
|
);
|
|
2063
2070
|
}
|
|
2064
2071
|
const astroGlobalReferences = scope.through.filter(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Astro component parser for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/ota-meshi/astro-eslint-parser#readme",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@astrojs/compiler": "
|
|
50
|
+
"@astrojs/compiler": "^0.33.0",
|
|
51
|
+
"@typescript-eslint/scope-manager": "^5.48.2",
|
|
51
52
|
"@typescript-eslint/types": "^5.25.0",
|
|
52
53
|
"astrojs-compiler-sync": "^0.3.0",
|
|
53
54
|
"debug": "^4.3.4",
|
|
54
|
-
"eslint-scope": "^7.1.1",
|
|
55
55
|
"eslint-visitor-keys": "^3.0.0",
|
|
56
56
|
"espree": "^9.0.0"
|
|
57
57
|
},
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"eslint-plugin-prettier": "^4.0.0",
|
|
92
92
|
"eslint-plugin-react": "^7.29.4",
|
|
93
93
|
"eslint-plugin-regexp": "^1.5.0",
|
|
94
|
-
"eslint-plugin-simple-import-sort": "^
|
|
94
|
+
"eslint-plugin-simple-import-sort": "^9.0.0",
|
|
95
95
|
"eslint-plugin-svelte": "^2.0.0",
|
|
96
96
|
"estree-walker": "^3.0.0",
|
|
97
97
|
"locate-character": "^2.0.5",
|