astro-eslint-parser 0.9.5 → 0.10.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 +1 -1
- package/lib/index.js +32 -25
- package/lib/index.mjs +32 -25
- 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,10 @@ 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 READ_FLAG = 1;
|
|
1830
|
+
var WRITE_FLAG = 2;
|
|
1831
|
+
var READ_WRITE_FLAG = 3;
|
|
1820
1832
|
function getProgramScope(scopeManager) {
|
|
1821
1833
|
const globalScope = scopeManager.globalScope;
|
|
1822
1834
|
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
@@ -1851,15 +1863,12 @@ function removeAllScopeAndVariableAndReference(target, info) {
|
|
|
1851
1863
|
}
|
|
1852
1864
|
}
|
|
1853
1865
|
function addVirtualReference(node, variable, scope, readWrite) {
|
|
1854
|
-
const reference = new
|
|
1866
|
+
const reference = new import_scope_manager2.Reference(
|
|
1867
|
+
node,
|
|
1868
|
+
scope,
|
|
1869
|
+
readWrite.write && readWrite.read ? READ_WRITE_FLAG : readWrite.write ? WRITE_FLAG : READ_FLAG
|
|
1870
|
+
);
|
|
1855
1871
|
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
1872
|
addReference(variable.references, reference);
|
|
1864
1873
|
reference.resolved = variable;
|
|
1865
1874
|
return reference;
|
|
@@ -1869,9 +1878,7 @@ function addGlobalVariable(reference, scopeManager) {
|
|
|
1869
1878
|
const name = reference.identifier.name;
|
|
1870
1879
|
let variable = globalScope.set.get(name);
|
|
1871
1880
|
if (!variable) {
|
|
1872
|
-
variable = new
|
|
1873
|
-
variable.name = name;
|
|
1874
|
-
variable.scope = globalScope;
|
|
1881
|
+
variable = new import_scope_manager2.Variable(name, globalScope);
|
|
1875
1882
|
globalScope.variables.push(variable);
|
|
1876
1883
|
globalScope.set.set(name, variable);
|
|
1877
1884
|
}
|
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,10 @@ 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
|
+
var READ_FLAG = 1;
|
|
1804
|
+
var WRITE_FLAG = 2;
|
|
1805
|
+
var READ_WRITE_FLAG = 3;
|
|
1794
1806
|
function getProgramScope(scopeManager) {
|
|
1795
1807
|
const globalScope = scopeManager.globalScope;
|
|
1796
1808
|
return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
|
|
@@ -1825,15 +1837,12 @@ function removeAllScopeAndVariableAndReference(target, info) {
|
|
|
1825
1837
|
}
|
|
1826
1838
|
}
|
|
1827
1839
|
function addVirtualReference(node, variable, scope, readWrite) {
|
|
1828
|
-
const reference = new ReferenceClass(
|
|
1840
|
+
const reference = new ReferenceClass(
|
|
1841
|
+
node,
|
|
1842
|
+
scope,
|
|
1843
|
+
readWrite.write && readWrite.read ? READ_WRITE_FLAG : readWrite.write ? WRITE_FLAG : READ_FLAG
|
|
1844
|
+
);
|
|
1829
1845
|
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
1846
|
addReference(variable.references, reference);
|
|
1838
1847
|
reference.resolved = variable;
|
|
1839
1848
|
return reference;
|
|
@@ -1843,9 +1852,7 @@ function addGlobalVariable(reference, scopeManager) {
|
|
|
1843
1852
|
const name = reference.identifier.name;
|
|
1844
1853
|
let variable = globalScope.set.get(name);
|
|
1845
1854
|
if (!variable) {
|
|
1846
|
-
variable = new VariableClass();
|
|
1847
|
-
variable.name = name;
|
|
1848
|
-
variable.scope = globalScope;
|
|
1855
|
+
variable = new VariableClass(name, globalScope);
|
|
1849
1856
|
globalScope.variables.push(variable);
|
|
1850
1857
|
globalScope.set.set(name, variable);
|
|
1851
1858
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
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",
|