@tsrx/eslint-parser 0.3.25
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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/index.d.ts +529 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +150 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
- package/src/index.ts +209 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @tsrx/eslint-parser
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tsrx/eslint-parser)
|
|
4
|
+
[](https://www.npmjs.com/package/@tsrx/eslint-parser)
|
|
5
|
+
|
|
6
|
+
ESLint parser for Ripple component files. This parser enables ESLint to understand
|
|
7
|
+
and lint `.tsrx` files by default, while also supporting `.tsrx` files through
|
|
8
|
+
Ripple's built-in compiler.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add --save-dev '@tsrx/eslint-parser' ripple
|
|
14
|
+
# or
|
|
15
|
+
npm install --save-dev '@tsrx/eslint-parser' ripple
|
|
16
|
+
# or
|
|
17
|
+
yarn add --dev '@tsrx/eslint-parser' ripple
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Note:** This parser requires `ripple` as a peer dependency.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Flat Config (ESLint 9+)
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// eslint.config.js
|
|
28
|
+
import rippleParser from '@tsrx/eslint-parser';
|
|
29
|
+
import ripplePlugin from '@tsrx/eslint-plugin';
|
|
30
|
+
|
|
31
|
+
export default [
|
|
32
|
+
{
|
|
33
|
+
files: ['**/*.{tsrx,ripple}'],
|
|
34
|
+
languageOptions: {
|
|
35
|
+
parser: rippleParser,
|
|
36
|
+
},
|
|
37
|
+
plugins: {
|
|
38
|
+
ripple: ripplePlugin,
|
|
39
|
+
},
|
|
40
|
+
rules: {
|
|
41
|
+
...ripplePlugin.configs.recommended.rules,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Legacy Config (.eslintrc)
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"overrides": [
|
|
52
|
+
{
|
|
53
|
+
"files": ["*.tsrx", "*.tsrx"],
|
|
54
|
+
"parser": "@tsrx/eslint-parser",
|
|
55
|
+
"plugins": ["ripple"],
|
|
56
|
+
"extends": ["plugin:ripple/recommended"]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## How It Works
|
|
63
|
+
|
|
64
|
+
This parser uses Ripple's compiler (`ripple/compiler`) to parse Ripple component
|
|
65
|
+
files into an ESTree-compatible AST that ESLint can analyze. The Ripple compiler
|
|
66
|
+
already outputs ESTree-compliant ASTs, making integration straightforward.
|
|
67
|
+
|
|
68
|
+
The parser:
|
|
69
|
+
|
|
70
|
+
1. Loads the Ripple compiler
|
|
71
|
+
2. Parses the component source code (`.tsrx` or `.tsrx`)
|
|
72
|
+
3. Returns the ESTree AST to ESLint
|
|
73
|
+
4. Allows ESLint rules to analyze Ripple-specific patterns
|
|
74
|
+
|
|
75
|
+
## Supported Syntax
|
|
76
|
+
|
|
77
|
+
The parser supports all Ripple syntax including:
|
|
78
|
+
|
|
79
|
+
- `component` declarations
|
|
80
|
+
- `track()` reactive values (imported from `ripple`)
|
|
81
|
+
- `@` unboxing operator
|
|
82
|
+
- Reactive collections (`RippleArray`, `RippleObject`, etc.)
|
|
83
|
+
- JSX-like templating inside components
|
|
84
|
+
- All standard JavaScript/TypeScript syntax
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
|
|
88
|
+
Given a `.tsrx` file:
|
|
89
|
+
|
|
90
|
+
```ripple
|
|
91
|
+
import { track } from 'ripple';
|
|
92
|
+
|
|
93
|
+
export component Counter() {
|
|
94
|
+
let count = track(0);
|
|
95
|
+
|
|
96
|
+
<div>
|
|
97
|
+
<button onClick={() => @count++}>Increment</button>
|
|
98
|
+
<span>{@count}</span>
|
|
99
|
+
</div>
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The parser will successfully parse this and allow ESLint rules (like those from
|
|
104
|
+
`@tsrx/eslint-plugin`) to check for:
|
|
105
|
+
|
|
106
|
+
- Track calls at module scope
|
|
107
|
+
- Missing @ operators
|
|
108
|
+
- Component export requirements
|
|
109
|
+
- And more
|
|
110
|
+
|
|
111
|
+
## Limitations
|
|
112
|
+
|
|
113
|
+
- The parser requires Node.js runtime as it uses `require()` to load the Ripple
|
|
114
|
+
compiler
|
|
115
|
+
- Browser-based linting is not currently supported
|
|
116
|
+
|
|
117
|
+
## Related Packages
|
|
118
|
+
|
|
119
|
+
- [@tsrx/eslint-plugin](https://www.npmjs.com/package/@tsrx/eslint-plugin) -
|
|
120
|
+
ESLint rules for Ripple
|
|
121
|
+
- [ripple](https://ripplejs.com) - The Ripple framework
|
|
122
|
+
- [@ripple-ts/vite-plugin](https://www.npmjs.com/package/@ripple-ts/vite-plugin) -
|
|
123
|
+
Vite plugin for Ripple
|
|
124
|
+
- [@ripple-ts/prettier-plugin](https://www.npmjs.com/package/@ripple-ts/prettier-plugin) -
|
|
125
|
+
Prettier plugin for Ripple
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { Linter } from "eslint";
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/@types+estree@1.0.8/node_modules/@types/estree/index.d.ts
|
|
4
|
+
// This definition file follows a somewhat unusual format. ESTree allows
|
|
5
|
+
// runtime type checks based on the `type` parameter. In order to explain this
|
|
6
|
+
// to typescript we want to use discriminated union types:
|
|
7
|
+
// https://github.com/Microsoft/TypeScript/pull/9163
|
|
8
|
+
//
|
|
9
|
+
// For ESTree this is a bit tricky because the high level interfaces like
|
|
10
|
+
// Node or Function are pulling double duty. We want to pass common fields down
|
|
11
|
+
// to the interfaces that extend them (like Identifier or
|
|
12
|
+
// ArrowFunctionExpression), but you can't extend a type union or enforce
|
|
13
|
+
// common fields on them. So we've split the high level interfaces into two
|
|
14
|
+
// types, a base type which passes down inherited fields, and a type union of
|
|
15
|
+
// all types which extend the base type. Only the type union is exported, and
|
|
16
|
+
// the union is how other types refer to the collection of inheriting types.
|
|
17
|
+
//
|
|
18
|
+
// This makes the definitions file here somewhat more difficult to maintain,
|
|
19
|
+
// but it has the notable advantage of making ESTree much easier to use as
|
|
20
|
+
// an end user.
|
|
21
|
+
interface BaseNodeWithoutComments {
|
|
22
|
+
// Every leaf interface that extends BaseNode must specify a type property.
|
|
23
|
+
// The type property should be a string literal. For example, Identifier
|
|
24
|
+
// has: `type: "Identifier"`
|
|
25
|
+
type: string;
|
|
26
|
+
loc?: SourceLocation | null | undefined;
|
|
27
|
+
range?: [number, number] | undefined;
|
|
28
|
+
}
|
|
29
|
+
interface BaseNode extends BaseNodeWithoutComments {
|
|
30
|
+
leadingComments?: Comment[] | undefined;
|
|
31
|
+
trailingComments?: Comment[] | undefined;
|
|
32
|
+
}
|
|
33
|
+
interface Comment extends BaseNodeWithoutComments {
|
|
34
|
+
type: "Line" | "Block";
|
|
35
|
+
value: string;
|
|
36
|
+
}
|
|
37
|
+
interface SourceLocation {
|
|
38
|
+
source?: string | null | undefined;
|
|
39
|
+
start: Position;
|
|
40
|
+
end: Position;
|
|
41
|
+
}
|
|
42
|
+
interface Position {
|
|
43
|
+
/** >= 1 */
|
|
44
|
+
line: number;
|
|
45
|
+
/** >= 0 */
|
|
46
|
+
column: number;
|
|
47
|
+
}
|
|
48
|
+
interface Program extends BaseNode {
|
|
49
|
+
type: "Program";
|
|
50
|
+
sourceType: "script" | "module";
|
|
51
|
+
body: Array<Directive | Statement | ModuleDeclaration>;
|
|
52
|
+
comments?: Comment[] | undefined;
|
|
53
|
+
}
|
|
54
|
+
interface Directive extends BaseNode {
|
|
55
|
+
type: "ExpressionStatement";
|
|
56
|
+
expression: Literal;
|
|
57
|
+
directive: string;
|
|
58
|
+
}
|
|
59
|
+
interface BaseFunction extends BaseNode {
|
|
60
|
+
params: Pattern[];
|
|
61
|
+
generator?: boolean | undefined;
|
|
62
|
+
async?: boolean | undefined; // The body is either BlockStatement or Expression because arrow functions
|
|
63
|
+
// can have a body that's either. FunctionDeclarations and
|
|
64
|
+
// FunctionExpressions have only BlockStatement bodies.
|
|
65
|
+
body: BlockStatement | Expression;
|
|
66
|
+
}
|
|
67
|
+
type Statement = ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
|
|
68
|
+
interface BaseStatement extends BaseNode {}
|
|
69
|
+
interface EmptyStatement extends BaseStatement {
|
|
70
|
+
type: "EmptyStatement";
|
|
71
|
+
}
|
|
72
|
+
interface BlockStatement extends BaseStatement {
|
|
73
|
+
type: "BlockStatement";
|
|
74
|
+
body: Statement[];
|
|
75
|
+
innerComments?: Comment[] | undefined;
|
|
76
|
+
}
|
|
77
|
+
interface StaticBlock extends Omit<BlockStatement, "type"> {
|
|
78
|
+
type: "StaticBlock";
|
|
79
|
+
}
|
|
80
|
+
interface ExpressionStatement extends BaseStatement {
|
|
81
|
+
type: "ExpressionStatement";
|
|
82
|
+
expression: Expression;
|
|
83
|
+
}
|
|
84
|
+
interface IfStatement extends BaseStatement {
|
|
85
|
+
type: "IfStatement";
|
|
86
|
+
test: Expression;
|
|
87
|
+
consequent: Statement;
|
|
88
|
+
alternate?: Statement | null | undefined;
|
|
89
|
+
}
|
|
90
|
+
interface LabeledStatement extends BaseStatement {
|
|
91
|
+
type: "LabeledStatement";
|
|
92
|
+
label: Identifier;
|
|
93
|
+
body: Statement;
|
|
94
|
+
}
|
|
95
|
+
interface BreakStatement extends BaseStatement {
|
|
96
|
+
type: "BreakStatement";
|
|
97
|
+
label?: Identifier | null | undefined;
|
|
98
|
+
}
|
|
99
|
+
interface ContinueStatement extends BaseStatement {
|
|
100
|
+
type: "ContinueStatement";
|
|
101
|
+
label?: Identifier | null | undefined;
|
|
102
|
+
}
|
|
103
|
+
interface WithStatement extends BaseStatement {
|
|
104
|
+
type: "WithStatement";
|
|
105
|
+
object: Expression;
|
|
106
|
+
body: Statement;
|
|
107
|
+
}
|
|
108
|
+
interface SwitchStatement extends BaseStatement {
|
|
109
|
+
type: "SwitchStatement";
|
|
110
|
+
discriminant: Expression;
|
|
111
|
+
cases: SwitchCase[];
|
|
112
|
+
}
|
|
113
|
+
interface ReturnStatement extends BaseStatement {
|
|
114
|
+
type: "ReturnStatement";
|
|
115
|
+
argument?: Expression | null | undefined;
|
|
116
|
+
}
|
|
117
|
+
interface ThrowStatement extends BaseStatement {
|
|
118
|
+
type: "ThrowStatement";
|
|
119
|
+
argument: Expression;
|
|
120
|
+
}
|
|
121
|
+
interface TryStatement extends BaseStatement {
|
|
122
|
+
type: "TryStatement";
|
|
123
|
+
block: BlockStatement;
|
|
124
|
+
handler?: CatchClause | null | undefined;
|
|
125
|
+
finalizer?: BlockStatement | null | undefined;
|
|
126
|
+
}
|
|
127
|
+
interface WhileStatement extends BaseStatement {
|
|
128
|
+
type: "WhileStatement";
|
|
129
|
+
test: Expression;
|
|
130
|
+
body: Statement;
|
|
131
|
+
}
|
|
132
|
+
interface DoWhileStatement extends BaseStatement {
|
|
133
|
+
type: "DoWhileStatement";
|
|
134
|
+
body: Statement;
|
|
135
|
+
test: Expression;
|
|
136
|
+
}
|
|
137
|
+
interface ForStatement extends BaseStatement {
|
|
138
|
+
type: "ForStatement";
|
|
139
|
+
init?: VariableDeclaration | Expression | null | undefined;
|
|
140
|
+
test?: Expression | null | undefined;
|
|
141
|
+
update?: Expression | null | undefined;
|
|
142
|
+
body: Statement;
|
|
143
|
+
}
|
|
144
|
+
interface BaseForXStatement extends BaseStatement {
|
|
145
|
+
left: VariableDeclaration | Pattern;
|
|
146
|
+
right: Expression;
|
|
147
|
+
body: Statement;
|
|
148
|
+
}
|
|
149
|
+
interface ForInStatement extends BaseForXStatement {
|
|
150
|
+
type: "ForInStatement";
|
|
151
|
+
}
|
|
152
|
+
interface DebuggerStatement extends BaseStatement {
|
|
153
|
+
type: "DebuggerStatement";
|
|
154
|
+
}
|
|
155
|
+
type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
|
|
156
|
+
interface BaseDeclaration extends BaseStatement {}
|
|
157
|
+
interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration {
|
|
158
|
+
type: "FunctionDeclaration";
|
|
159
|
+
/** It is null when a function declaration is a part of the `export default function` statement */
|
|
160
|
+
id: Identifier | null;
|
|
161
|
+
body: BlockStatement;
|
|
162
|
+
}
|
|
163
|
+
interface FunctionDeclaration extends MaybeNamedFunctionDeclaration {
|
|
164
|
+
id: Identifier;
|
|
165
|
+
}
|
|
166
|
+
interface VariableDeclaration extends BaseDeclaration {
|
|
167
|
+
type: "VariableDeclaration";
|
|
168
|
+
declarations: VariableDeclarator[];
|
|
169
|
+
kind: "var" | "let" | "const" | "using" | "await using";
|
|
170
|
+
}
|
|
171
|
+
interface VariableDeclarator extends BaseNode {
|
|
172
|
+
type: "VariableDeclarator";
|
|
173
|
+
id: Pattern;
|
|
174
|
+
init?: Expression | null | undefined;
|
|
175
|
+
}
|
|
176
|
+
interface ExpressionMap {
|
|
177
|
+
ArrayExpression: ArrayExpression;
|
|
178
|
+
ArrowFunctionExpression: ArrowFunctionExpression;
|
|
179
|
+
AssignmentExpression: AssignmentExpression;
|
|
180
|
+
AwaitExpression: AwaitExpression;
|
|
181
|
+
BinaryExpression: BinaryExpression;
|
|
182
|
+
CallExpression: CallExpression;
|
|
183
|
+
ChainExpression: ChainExpression;
|
|
184
|
+
ClassExpression: ClassExpression;
|
|
185
|
+
ConditionalExpression: ConditionalExpression;
|
|
186
|
+
FunctionExpression: FunctionExpression;
|
|
187
|
+
Identifier: Identifier;
|
|
188
|
+
ImportExpression: ImportExpression;
|
|
189
|
+
Literal: Literal;
|
|
190
|
+
LogicalExpression: LogicalExpression;
|
|
191
|
+
MemberExpression: MemberExpression;
|
|
192
|
+
MetaProperty: MetaProperty;
|
|
193
|
+
NewExpression: NewExpression;
|
|
194
|
+
ObjectExpression: ObjectExpression;
|
|
195
|
+
SequenceExpression: SequenceExpression;
|
|
196
|
+
TaggedTemplateExpression: TaggedTemplateExpression;
|
|
197
|
+
TemplateLiteral: TemplateLiteral;
|
|
198
|
+
ThisExpression: ThisExpression;
|
|
199
|
+
UnaryExpression: UnaryExpression;
|
|
200
|
+
UpdateExpression: UpdateExpression;
|
|
201
|
+
YieldExpression: YieldExpression;
|
|
202
|
+
}
|
|
203
|
+
type Expression = ExpressionMap[keyof ExpressionMap];
|
|
204
|
+
interface BaseExpression extends BaseNode {}
|
|
205
|
+
type ChainElement = SimpleCallExpression | MemberExpression;
|
|
206
|
+
interface ChainExpression extends BaseExpression {
|
|
207
|
+
type: "ChainExpression";
|
|
208
|
+
expression: ChainElement;
|
|
209
|
+
}
|
|
210
|
+
interface ThisExpression extends BaseExpression {
|
|
211
|
+
type: "ThisExpression";
|
|
212
|
+
}
|
|
213
|
+
interface ArrayExpression extends BaseExpression {
|
|
214
|
+
type: "ArrayExpression";
|
|
215
|
+
elements: Array<Expression | SpreadElement | null>;
|
|
216
|
+
}
|
|
217
|
+
interface ObjectExpression extends BaseExpression {
|
|
218
|
+
type: "ObjectExpression";
|
|
219
|
+
properties: Array<Property | SpreadElement>;
|
|
220
|
+
}
|
|
221
|
+
interface PrivateIdentifier extends BaseNode {
|
|
222
|
+
type: "PrivateIdentifier";
|
|
223
|
+
name: string;
|
|
224
|
+
}
|
|
225
|
+
interface Property extends BaseNode {
|
|
226
|
+
type: "Property";
|
|
227
|
+
key: Expression | PrivateIdentifier;
|
|
228
|
+
value: Expression | Pattern; // Could be an AssignmentProperty
|
|
229
|
+
kind: "init" | "get" | "set";
|
|
230
|
+
method: boolean;
|
|
231
|
+
shorthand: boolean;
|
|
232
|
+
computed: boolean;
|
|
233
|
+
}
|
|
234
|
+
interface PropertyDefinition extends BaseNode {
|
|
235
|
+
type: "PropertyDefinition";
|
|
236
|
+
key: Expression | PrivateIdentifier;
|
|
237
|
+
value?: Expression | null | undefined;
|
|
238
|
+
computed: boolean;
|
|
239
|
+
static: boolean;
|
|
240
|
+
}
|
|
241
|
+
interface FunctionExpression extends BaseFunction, BaseExpression {
|
|
242
|
+
id?: Identifier | null | undefined;
|
|
243
|
+
type: "FunctionExpression";
|
|
244
|
+
body: BlockStatement;
|
|
245
|
+
}
|
|
246
|
+
interface SequenceExpression extends BaseExpression {
|
|
247
|
+
type: "SequenceExpression";
|
|
248
|
+
expressions: Expression[];
|
|
249
|
+
}
|
|
250
|
+
interface UnaryExpression extends BaseExpression {
|
|
251
|
+
type: "UnaryExpression";
|
|
252
|
+
operator: UnaryOperator;
|
|
253
|
+
prefix: true;
|
|
254
|
+
argument: Expression;
|
|
255
|
+
}
|
|
256
|
+
interface BinaryExpression extends BaseExpression {
|
|
257
|
+
type: "BinaryExpression";
|
|
258
|
+
operator: BinaryOperator;
|
|
259
|
+
left: Expression | PrivateIdentifier;
|
|
260
|
+
right: Expression;
|
|
261
|
+
}
|
|
262
|
+
interface AssignmentExpression extends BaseExpression {
|
|
263
|
+
type: "AssignmentExpression";
|
|
264
|
+
operator: AssignmentOperator;
|
|
265
|
+
left: Pattern | MemberExpression;
|
|
266
|
+
right: Expression;
|
|
267
|
+
}
|
|
268
|
+
interface UpdateExpression extends BaseExpression {
|
|
269
|
+
type: "UpdateExpression";
|
|
270
|
+
operator: UpdateOperator;
|
|
271
|
+
argument: Expression;
|
|
272
|
+
prefix: boolean;
|
|
273
|
+
}
|
|
274
|
+
interface LogicalExpression extends BaseExpression {
|
|
275
|
+
type: "LogicalExpression";
|
|
276
|
+
operator: LogicalOperator;
|
|
277
|
+
left: Expression;
|
|
278
|
+
right: Expression;
|
|
279
|
+
}
|
|
280
|
+
interface ConditionalExpression extends BaseExpression {
|
|
281
|
+
type: "ConditionalExpression";
|
|
282
|
+
test: Expression;
|
|
283
|
+
alternate: Expression;
|
|
284
|
+
consequent: Expression;
|
|
285
|
+
}
|
|
286
|
+
interface BaseCallExpression extends BaseExpression {
|
|
287
|
+
callee: Expression | Super;
|
|
288
|
+
arguments: Array<Expression | SpreadElement>;
|
|
289
|
+
}
|
|
290
|
+
type CallExpression = SimpleCallExpression | NewExpression;
|
|
291
|
+
interface SimpleCallExpression extends BaseCallExpression {
|
|
292
|
+
type: "CallExpression";
|
|
293
|
+
optional: boolean;
|
|
294
|
+
}
|
|
295
|
+
interface NewExpression extends BaseCallExpression {
|
|
296
|
+
type: "NewExpression";
|
|
297
|
+
}
|
|
298
|
+
interface MemberExpression extends BaseExpression, BasePattern {
|
|
299
|
+
type: "MemberExpression";
|
|
300
|
+
object: Expression | Super;
|
|
301
|
+
property: Expression | PrivateIdentifier;
|
|
302
|
+
computed: boolean;
|
|
303
|
+
optional: boolean;
|
|
304
|
+
}
|
|
305
|
+
type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
|
|
306
|
+
interface BasePattern extends BaseNode {}
|
|
307
|
+
interface SwitchCase extends BaseNode {
|
|
308
|
+
type: "SwitchCase";
|
|
309
|
+
test?: Expression | null | undefined;
|
|
310
|
+
consequent: Statement[];
|
|
311
|
+
}
|
|
312
|
+
interface CatchClause extends BaseNode {
|
|
313
|
+
type: "CatchClause";
|
|
314
|
+
param: Pattern | null;
|
|
315
|
+
body: BlockStatement;
|
|
316
|
+
}
|
|
317
|
+
interface Identifier extends BaseNode, BaseExpression, BasePattern {
|
|
318
|
+
type: "Identifier";
|
|
319
|
+
name: string;
|
|
320
|
+
}
|
|
321
|
+
type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
|
|
322
|
+
interface SimpleLiteral extends BaseNode, BaseExpression {
|
|
323
|
+
type: "Literal";
|
|
324
|
+
value: string | boolean | number | null;
|
|
325
|
+
raw?: string | undefined;
|
|
326
|
+
}
|
|
327
|
+
interface RegExpLiteral extends BaseNode, BaseExpression {
|
|
328
|
+
type: "Literal";
|
|
329
|
+
value?: RegExp | null | undefined;
|
|
330
|
+
regex: {
|
|
331
|
+
pattern: string;
|
|
332
|
+
flags: string;
|
|
333
|
+
};
|
|
334
|
+
raw?: string | undefined;
|
|
335
|
+
}
|
|
336
|
+
interface BigIntLiteral extends BaseNode, BaseExpression {
|
|
337
|
+
type: "Literal";
|
|
338
|
+
value?: bigint | null | undefined;
|
|
339
|
+
bigint: string;
|
|
340
|
+
raw?: string | undefined;
|
|
341
|
+
}
|
|
342
|
+
type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
|
|
343
|
+
type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "in" | "instanceof";
|
|
344
|
+
type LogicalOperator = "||" | "&&" | "??";
|
|
345
|
+
type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "||=" | "&&=" | "??=";
|
|
346
|
+
type UpdateOperator = "++" | "--";
|
|
347
|
+
interface ForOfStatement extends BaseForXStatement {
|
|
348
|
+
type: "ForOfStatement";
|
|
349
|
+
await: boolean;
|
|
350
|
+
}
|
|
351
|
+
interface Super extends BaseNode {
|
|
352
|
+
type: "Super";
|
|
353
|
+
}
|
|
354
|
+
interface SpreadElement extends BaseNode {
|
|
355
|
+
type: "SpreadElement";
|
|
356
|
+
argument: Expression;
|
|
357
|
+
}
|
|
358
|
+
interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
|
|
359
|
+
type: "ArrowFunctionExpression";
|
|
360
|
+
expression: boolean;
|
|
361
|
+
body: BlockStatement | Expression;
|
|
362
|
+
}
|
|
363
|
+
interface YieldExpression extends BaseExpression {
|
|
364
|
+
type: "YieldExpression";
|
|
365
|
+
argument?: Expression | null | undefined;
|
|
366
|
+
delegate: boolean;
|
|
367
|
+
}
|
|
368
|
+
interface TemplateLiteral extends BaseExpression {
|
|
369
|
+
type: "TemplateLiteral";
|
|
370
|
+
quasis: TemplateElement[];
|
|
371
|
+
expressions: Expression[];
|
|
372
|
+
}
|
|
373
|
+
interface TaggedTemplateExpression extends BaseExpression {
|
|
374
|
+
type: "TaggedTemplateExpression";
|
|
375
|
+
tag: Expression;
|
|
376
|
+
quasi: TemplateLiteral;
|
|
377
|
+
}
|
|
378
|
+
interface TemplateElement extends BaseNode {
|
|
379
|
+
type: "TemplateElement";
|
|
380
|
+
tail: boolean;
|
|
381
|
+
value: {
|
|
382
|
+
/** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */cooked?: string | null | undefined;
|
|
383
|
+
raw: string;
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
interface AssignmentProperty extends Property {
|
|
387
|
+
value: Pattern;
|
|
388
|
+
kind: "init";
|
|
389
|
+
method: boolean; // false
|
|
390
|
+
}
|
|
391
|
+
interface ObjectPattern extends BasePattern {
|
|
392
|
+
type: "ObjectPattern";
|
|
393
|
+
properties: Array<AssignmentProperty | RestElement>;
|
|
394
|
+
}
|
|
395
|
+
interface ArrayPattern extends BasePattern {
|
|
396
|
+
type: "ArrayPattern";
|
|
397
|
+
elements: Array<Pattern | null>;
|
|
398
|
+
}
|
|
399
|
+
interface RestElement extends BasePattern {
|
|
400
|
+
type: "RestElement";
|
|
401
|
+
argument: Pattern;
|
|
402
|
+
}
|
|
403
|
+
interface AssignmentPattern extends BasePattern {
|
|
404
|
+
type: "AssignmentPattern";
|
|
405
|
+
left: Pattern;
|
|
406
|
+
right: Expression;
|
|
407
|
+
}
|
|
408
|
+
interface BaseClass extends BaseNode {
|
|
409
|
+
superClass?: Expression | null | undefined;
|
|
410
|
+
body: ClassBody;
|
|
411
|
+
}
|
|
412
|
+
interface ClassBody extends BaseNode {
|
|
413
|
+
type: "ClassBody";
|
|
414
|
+
body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
|
|
415
|
+
}
|
|
416
|
+
interface MethodDefinition extends BaseNode {
|
|
417
|
+
type: "MethodDefinition";
|
|
418
|
+
key: Expression | PrivateIdentifier;
|
|
419
|
+
value: FunctionExpression;
|
|
420
|
+
kind: "constructor" | "method" | "get" | "set";
|
|
421
|
+
computed: boolean;
|
|
422
|
+
static: boolean;
|
|
423
|
+
}
|
|
424
|
+
interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration {
|
|
425
|
+
type: "ClassDeclaration";
|
|
426
|
+
/** It is null when a class declaration is a part of the `export default class` statement */
|
|
427
|
+
id: Identifier | null;
|
|
428
|
+
}
|
|
429
|
+
interface ClassDeclaration extends MaybeNamedClassDeclaration {
|
|
430
|
+
id: Identifier;
|
|
431
|
+
}
|
|
432
|
+
interface ClassExpression extends BaseClass, BaseExpression {
|
|
433
|
+
type: "ClassExpression";
|
|
434
|
+
id?: Identifier | null | undefined;
|
|
435
|
+
}
|
|
436
|
+
interface MetaProperty extends BaseExpression {
|
|
437
|
+
type: "MetaProperty";
|
|
438
|
+
meta: Identifier;
|
|
439
|
+
property: Identifier;
|
|
440
|
+
}
|
|
441
|
+
type ModuleDeclaration = ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration;
|
|
442
|
+
interface BaseModuleDeclaration extends BaseNode {}
|
|
443
|
+
interface BaseModuleSpecifier extends BaseNode {
|
|
444
|
+
local: Identifier;
|
|
445
|
+
}
|
|
446
|
+
interface ImportDeclaration extends BaseModuleDeclaration {
|
|
447
|
+
type: "ImportDeclaration";
|
|
448
|
+
specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
|
|
449
|
+
attributes: ImportAttribute[];
|
|
450
|
+
source: Literal;
|
|
451
|
+
}
|
|
452
|
+
interface ImportSpecifier extends BaseModuleSpecifier {
|
|
453
|
+
type: "ImportSpecifier";
|
|
454
|
+
imported: Identifier | Literal;
|
|
455
|
+
}
|
|
456
|
+
interface ImportAttribute extends BaseNode {
|
|
457
|
+
type: "ImportAttribute";
|
|
458
|
+
key: Identifier | Literal;
|
|
459
|
+
value: Literal;
|
|
460
|
+
}
|
|
461
|
+
interface ImportExpression extends BaseExpression {
|
|
462
|
+
type: "ImportExpression";
|
|
463
|
+
source: Expression;
|
|
464
|
+
options?: Expression | null | undefined;
|
|
465
|
+
}
|
|
466
|
+
interface ImportDefaultSpecifier extends BaseModuleSpecifier {
|
|
467
|
+
type: "ImportDefaultSpecifier";
|
|
468
|
+
}
|
|
469
|
+
interface ImportNamespaceSpecifier extends BaseModuleSpecifier {
|
|
470
|
+
type: "ImportNamespaceSpecifier";
|
|
471
|
+
}
|
|
472
|
+
interface ExportNamedDeclaration extends BaseModuleDeclaration {
|
|
473
|
+
type: "ExportNamedDeclaration";
|
|
474
|
+
declaration?: Declaration | null | undefined;
|
|
475
|
+
specifiers: ExportSpecifier[];
|
|
476
|
+
attributes: ImportAttribute[];
|
|
477
|
+
source?: Literal | null | undefined;
|
|
478
|
+
}
|
|
479
|
+
interface ExportSpecifier extends Omit<BaseModuleSpecifier, "local"> {
|
|
480
|
+
type: "ExportSpecifier";
|
|
481
|
+
local: Identifier | Literal;
|
|
482
|
+
exported: Identifier | Literal;
|
|
483
|
+
}
|
|
484
|
+
interface ExportDefaultDeclaration extends BaseModuleDeclaration {
|
|
485
|
+
type: "ExportDefaultDeclaration";
|
|
486
|
+
declaration: MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | Expression;
|
|
487
|
+
}
|
|
488
|
+
interface ExportAllDeclaration extends BaseModuleDeclaration {
|
|
489
|
+
type: "ExportAllDeclaration";
|
|
490
|
+
exported: Identifier | Literal | null;
|
|
491
|
+
attributes: ImportAttribute[];
|
|
492
|
+
source: Literal;
|
|
493
|
+
}
|
|
494
|
+
interface AwaitExpression extends BaseExpression {
|
|
495
|
+
type: "AwaitExpression";
|
|
496
|
+
argument: Expression;
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/index.d.ts
|
|
500
|
+
interface ParseResult {
|
|
501
|
+
ast: Program;
|
|
502
|
+
services?: Record<string, any>;
|
|
503
|
+
scopeManager?: any;
|
|
504
|
+
visitorKeys?: Record<string, string[]>;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* ESLint parser for Ripple (.tsrx) files
|
|
508
|
+
*
|
|
509
|
+
* This parser uses Ripple's built-in compiler to parse .tsrx files
|
|
510
|
+
* and returns an ESTree-compatible AST for ESLint to analyze.
|
|
511
|
+
*/
|
|
512
|
+
declare function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult;
|
|
513
|
+
/**
|
|
514
|
+
* Legacy parse function for older ESLint versions
|
|
515
|
+
*/
|
|
516
|
+
declare function parse(code: string, options?: Linter.ParserOptions): Program;
|
|
517
|
+
declare global {
|
|
518
|
+
var __RIPPLE_COMPILER__: {
|
|
519
|
+
parse: (source: string) => Program;
|
|
520
|
+
compile: (source: string, filename: string, options?: any) => any;
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
declare const _default: {
|
|
524
|
+
parseForESLint: typeof parseForESLint;
|
|
525
|
+
parse: typeof parse;
|
|
526
|
+
};
|
|
527
|
+
//#endregion
|
|
528
|
+
export { _default as default, parse, parseForESLint };
|
|
529
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["BaseNodeWithoutComments","SourceLocation","type","loc","range","BaseNode","Comment","leadingComments","trailingComments","NodeMap","AssignmentProperty","CatchClause","Class","ClassBody","Expression","Function","Identifier","Literal","MethodDefinition","ModuleDeclaration","ModuleSpecifier","Pattern","PrivateIdentifier","Program","Property","PropertyDefinition","SpreadElement","Statement","Super","SwitchCase","TemplateElement","VariableDeclarator","Node","value","Position","source","start","end","line","column","Directive","Array","sourceType","body","comments","expression","directive","BaseFunction","BlockStatement","params","generator","async","FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ExpressionStatement","StaticBlock","EmptyStatement","DebuggerStatement","WithStatement","ReturnStatement","LabeledStatement","BreakStatement","ContinueStatement","IfStatement","SwitchStatement","ThrowStatement","TryStatement","WhileStatement","DoWhileStatement","ForStatement","ForInStatement","ForOfStatement","Declaration","BaseStatement","innerComments","Omit","test","consequent","alternate","label","object","discriminant","cases","argument","block","handler","finalizer","VariableDeclaration","init","update","BaseForXStatement","left","right","ClassDeclaration","BaseDeclaration","MaybeNamedFunctionDeclaration","id","declarations","kind","ExpressionMap","ArrayExpression","AssignmentExpression","AwaitExpression","BinaryExpression","CallExpression","ChainExpression","ClassExpression","ConditionalExpression","ImportExpression","LogicalExpression","MemberExpression","MetaProperty","NewExpression","ObjectExpression","SequenceExpression","TaggedTemplateExpression","TemplateLiteral","ThisExpression","UnaryExpression","UpdateExpression","YieldExpression","BaseExpression","ChainElement","SimpleCallExpression","elements","properties","name","key","method","shorthand","computed","static","expressions","UnaryOperator","operator","prefix","BinaryOperator","AssignmentOperator","UpdateOperator","LogicalOperator","BaseCallExpression","callee","arguments","optional","BasePattern","property","ObjectPattern","ArrayPattern","RestElement","AssignmentPattern","param","SimpleLiteral","RegExpLiteral","BigIntLiteral","raw","RegExp","regex","pattern","flags","bigint","await","delegate","quasis","tag","quasi","tail","cooked","BaseClass","superClass","MaybeNamedClassDeclaration","meta","ImportDeclaration","ExportNamedDeclaration","ExportDefaultDeclaration","ExportAllDeclaration","BaseModuleDeclaration","ImportSpecifier","ImportDefaultSpecifier","ImportNamespaceSpecifier","ExportSpecifier","BaseModuleSpecifier","local","ImportAttribute","specifiers","attributes","imported","options","declaration","exported"],"sources":["../../../node_modules/.pnpm/@types+estree@1.0.8/node_modules/@types/estree/index.d.ts","../src/index.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;UAkBiBA,uBAAAA;EAAAA;EAAAA;EAAAA;EAIbE,IAAAA;EACAC,GAAAA,GAAMF,cAAAA;EACNG,KAAAA;AAAAA;AA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SAAwBmB,cAAAA;EACrCxH,IAAAA;EACAkF,QAAAA,EAAUtE,UAAAA;AAAAA;;;UChrBJ,WAAA;EACT,GAAA,EAAK,OAAA;EACL,QAAA,GAAW,MAAA;EACX,YAAA;EACA,WAAA,GAAc,MAAA;AAAA;;;;;;ADmBf;iBCyFgB,cAAA,CAAe,IAAA,UAAc,OAAA,GAAU,MAAA,CAAO,aAAA,GAAgB,WAAA;;;;iBA8C9D,KAAA,CAAM,IAAA,UAAc,OAAA,GAAU,MAAA,CAAO,aAAA,GAAgB,OAAA;AAAA,QAoC7D,MAAA;EAAA,IACH,mBAAA;IACH,KAAA,GAAQ,MAAA,aAAmB,OAAA;IAC3B,OAAA,GAAU,MAAA,UAAgB,QAAA,UAAkB,OAAA;EAAA;AAAA;AAAA,cAC5C,QAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`
|
|
6
|
+
* and `Element.openingElement.attributes`) that are useful for formatters/source-maps.
|
|
7
|
+
* ESLint's traverser will visit both paths and can trigger duplicate rule reports.
|
|
8
|
+
*
|
|
9
|
+
* For ESLint, we prune JSX wrapper nodes to keep a single traversal path.
|
|
10
|
+
*/
|
|
11
|
+
function normalizeRippleAstForEslint(ast) {
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
const visit = (node) => {
|
|
14
|
+
if (!node || typeof node !== "object") return;
|
|
15
|
+
if (seen.has(node)) return;
|
|
16
|
+
seen.add(node);
|
|
17
|
+
if (node.type === "Element") {
|
|
18
|
+
delete node.openingElement;
|
|
19
|
+
delete node.closingElement;
|
|
20
|
+
}
|
|
21
|
+
for (const key of Object.keys(node)) {
|
|
22
|
+
if (key === "parent" || key === "loc" || key === "range") continue;
|
|
23
|
+
const value = node[key];
|
|
24
|
+
if (Array.isArray(value)) for (const child of value) visit(child);
|
|
25
|
+
else if (value && typeof value === "object") visit(value);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
visit(ast);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Recursively walks the AST and ensures all nodes have range and loc properties
|
|
32
|
+
* ESLint's scope analyzer requires these properties on ALL nodes
|
|
33
|
+
*/
|
|
34
|
+
function ensureNodeProperties(node, code) {
|
|
35
|
+
if (!node || typeof node !== "object") return;
|
|
36
|
+
if (node.start !== void 0 && node.end !== void 0 && !node.range) node.range = [node.start, node.end];
|
|
37
|
+
if (!node.loc && node.start !== void 0 && node.end !== void 0) {
|
|
38
|
+
const lines = code.split("\n");
|
|
39
|
+
let currentPos = 0;
|
|
40
|
+
let startLine = 1;
|
|
41
|
+
let startColumn = 0;
|
|
42
|
+
let endLine = 1;
|
|
43
|
+
let endColumn = 0;
|
|
44
|
+
for (let i = 0; i < lines.length; i++) {
|
|
45
|
+
const lineLength = lines[i].length + 1;
|
|
46
|
+
if (currentPos + lineLength > node.start) {
|
|
47
|
+
startLine = i + 1;
|
|
48
|
+
startColumn = node.start - currentPos;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
currentPos += lineLength;
|
|
52
|
+
}
|
|
53
|
+
currentPos = 0;
|
|
54
|
+
for (let i = 0; i < lines.length; i++) {
|
|
55
|
+
const lineLength = lines[i].length + 1;
|
|
56
|
+
if (currentPos + lineLength > node.end) {
|
|
57
|
+
endLine = i + 1;
|
|
58
|
+
endColumn = node.end - currentPos;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
currentPos += lineLength;
|
|
62
|
+
}
|
|
63
|
+
node.loc = {
|
|
64
|
+
start: {
|
|
65
|
+
line: startLine,
|
|
66
|
+
column: startColumn
|
|
67
|
+
},
|
|
68
|
+
end: {
|
|
69
|
+
line: endLine,
|
|
70
|
+
column: endColumn
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
for (const key in node) {
|
|
75
|
+
if (key === "parent" || key === "loc" || key === "range") continue;
|
|
76
|
+
const value = node[key];
|
|
77
|
+
if (Array.isArray(value)) value.forEach((child) => ensureNodeProperties(child, code));
|
|
78
|
+
else if (value && typeof value === "object" && value.type) ensureNodeProperties(value, code);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* ESLint parser for Ripple (.tsrx) files
|
|
83
|
+
*
|
|
84
|
+
* This parser uses Ripple's built-in compiler to parse .tsrx files
|
|
85
|
+
* and returns an ESTree-compatible AST for ESLint to analyze.
|
|
86
|
+
*/
|
|
87
|
+
function parseForESLint(code, options) {
|
|
88
|
+
try {
|
|
89
|
+
const ast = requireRippleCompiler().parse(code);
|
|
90
|
+
if (!ast) throw new Error("Parser returned null or undefined AST");
|
|
91
|
+
normalizeRippleAstForEslint(ast);
|
|
92
|
+
ensureNodeProperties(ast, code);
|
|
93
|
+
return {
|
|
94
|
+
ast: {
|
|
95
|
+
type: ast.type || "Program",
|
|
96
|
+
start: ast.start !== void 0 ? ast.start : 0,
|
|
97
|
+
end: ast.end !== void 0 ? ast.end : code.length,
|
|
98
|
+
loc: ast.loc || {
|
|
99
|
+
start: {
|
|
100
|
+
line: 1,
|
|
101
|
+
column: 0
|
|
102
|
+
},
|
|
103
|
+
end: {
|
|
104
|
+
line: code.split("\n").length,
|
|
105
|
+
column: 0
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
range: ast.range || [0, code.length],
|
|
109
|
+
body: ast.body || [],
|
|
110
|
+
sourceType: ast.sourceType || "module",
|
|
111
|
+
comments: ast.comments || [],
|
|
112
|
+
tokens: ast.tokens || []
|
|
113
|
+
},
|
|
114
|
+
services: {},
|
|
115
|
+
visitorKeys: void 0
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Legacy parse function for older ESLint versions
|
|
123
|
+
*/
|
|
124
|
+
function parse(code, options) {
|
|
125
|
+
return parseForESLint(code, options).ast;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Helper to require the Ripple compiler
|
|
129
|
+
* This handles both CommonJS and ESM environments
|
|
130
|
+
*/
|
|
131
|
+
function requireRippleCompiler() {
|
|
132
|
+
const globalRipple = globalThis.__RIPPLE_COMPILER__;
|
|
133
|
+
if (globalRipple && globalRipple.parse) return globalRipple;
|
|
134
|
+
try {
|
|
135
|
+
const ripple = createRequire(import.meta.url)("@tsrx/ripple");
|
|
136
|
+
if (!ripple || !ripple.parse) throw new Error("Ripple compiler loaded but parse function not found.");
|
|
137
|
+
globalThis.__RIPPLE_COMPILER__ = ripple;
|
|
138
|
+
return ripple;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw new Error(`Failed to load Ripple compiler: ${error.message}. Make sure the "@tsrx/ripple" package is installed as a peer dependency.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var src_default = {
|
|
144
|
+
parseForESLint,
|
|
145
|
+
parse
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
export { src_default as default, parse, parseForESLint };
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Program } from 'estree';\nimport type { Linter } from 'eslint';\nimport { createRequire } from 'module';\n\ninterface ParseResult {\n\tast: Program;\n\tservices?: Record<string, any>;\n\tscopeManager?: any;\n\tvisitorKeys?: Record<string, string[]>;\n}\n\n/**\n * The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`\n * and `Element.openingElement.attributes`) that are useful for formatters/source-maps.\n * ESLint's traverser will visit both paths and can trigger duplicate rule reports.\n *\n * For ESLint, we prune JSX wrapper nodes to keep a single traversal path.\n */\nfunction normalizeRippleAstForEslint(ast: any): void {\n\tconst seen = new Set<any>();\n\tconst visit = (node: any) => {\n\t\tif (!node || typeof node !== 'object') return;\n\t\tif (seen.has(node)) return;\n\t\tseen.add(node);\n\n\t\tif (node.type === 'Element') {\n\t\t\t// Avoid duplicate traversal of attributes/children through openingElement/closingElement.\n\t\t\t// The Element node itself carries the data ESLint rules care about.\n\t\t\tdelete node.openingElement;\n\t\t\tdelete node.closingElement;\n\t\t}\n\n\t\tfor (const key of Object.keys(node)) {\n\t\t\tif (key === 'parent' || key === 'loc' || key === 'range') continue;\n\t\t\tconst value = node[key];\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const child of value) visit(child);\n\t\t\t} else if (value && typeof value === 'object') {\n\t\t\t\tvisit(value);\n\t\t\t}\n\t\t}\n\t};\n\n\tvisit(ast);\n}\n\n/**\n * Recursively walks the AST and ensures all nodes have range and loc properties\n * ESLint's scope analyzer requires these properties on ALL nodes\n */\nfunction ensureNodeProperties(node: any, code: string): void {\n\tif (!node || typeof node !== 'object') {\n\t\treturn;\n\t}\n\n\t// Ensure range property exists\n\tif (node.start !== undefined && node.end !== undefined && !node.range) {\n\t\tnode.range = [node.start, node.end];\n\t}\n\n\t// Ensure loc property exists\n\tif (!node.loc && node.start !== undefined && node.end !== undefined) {\n\t\tconst lines = code.split('\\n');\n\t\tlet currentPos = 0;\n\t\tlet startLine = 1;\n\t\tlet startColumn = 0;\n\t\tlet endLine = 1;\n\t\tlet endColumn = 0;\n\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.start) {\n\t\t\t\tstartLine = i + 1;\n\t\t\t\tstartColumn = node.start - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tcurrentPos = 0;\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.end) {\n\t\t\t\tendLine = i + 1;\n\t\t\t\tendColumn = node.end - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tnode.loc = {\n\t\t\tstart: { line: startLine, column: startColumn },\n\t\t\tend: { line: endLine, column: endColumn },\n\t\t};\n\t}\n\n\tfor (const key in node) {\n\t\tif (key === 'parent' || key === 'loc' || key === 'range') {\n\t\t\tcontinue; // Skip these to avoid infinite loops\n\t\t}\n\n\t\tconst value = node[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach((child) => ensureNodeProperties(child, code));\n\t\t} else if (value && typeof value === 'object' && value.type) {\n\t\t\tensureNodeProperties(value, code);\n\t\t}\n\t}\n}\n\n/**\n * ESLint parser for Ripple (.tsrx) files\n *\n * This parser uses Ripple's built-in compiler to parse .tsrx files\n * and returns an ESTree-compatible AST for ESLint to analyze.\n */\nexport function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult {\n\ttry {\n\t\t// Dynamically import the Ripple compiler\n\t\t// We use dynamic import to avoid bundling the entire compiler\n\t\tconst rippleCompiler = requireRippleCompiler();\n\n\t\t// Parse the Ripple source code using the Ripple compiler\n\t\tconst ast = rippleCompiler.parse(code);\n\t\tif (!ast) throw new Error('Parser returned null or undefined AST');\n\n\t\t// Normalize for ESLint traversal (avoid duplicate node visits)\n\t\tnormalizeRippleAstForEslint(ast);\n\n\t\t// Recursively ensure all nodes have range and loc properties\n\t\tensureNodeProperties(ast, code);\n\n\t\t// Create a properly structured AST object ensuring all required properties exist\n\t\tconst result: any = {\n\t\t\ttype: ast.type || 'Program',\n\t\t\tstart: ast.start !== undefined ? ast.start : 0,\n\t\t\tend: ast.end !== undefined ? ast.end : code.length,\n\t\t\tloc: ast.loc || {\n\t\t\t\tstart: { line: 1, column: 0 },\n\t\t\t\tend: { line: code.split('\\n').length, column: 0 },\n\t\t\t},\n\t\t\trange: ast.range || [0, code.length],\n\t\t\tbody: ast.body || [],\n\t\t\tsourceType: ast.sourceType || 'module',\n\t\t\tcomments: ast.comments || [],\n\t\t\ttokens: ast.tokens || [],\n\t\t};\n\n\t\treturn {\n\t\t\tast: result,\n\t\t\tservices: {},\n\t\t\tvisitorKeys: undefined, // Use ESLint's default visitor keys\n\t\t};\n\t} catch (error: any) {\n\t\t// Transform Ripple parse errors to ESLint-compatible format\n\t\tthrow new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);\n\t}\n}\n\n/**\n * Legacy parse function for older ESLint versions\n */\nexport function parse(code: string, options?: Linter.ParserOptions): Program {\n\tconst result = parseForESLint(code, options);\n\treturn result.ast;\n}\n\n/**\n * Helper to require the Ripple compiler\n * This handles both CommonJS and ESM environments\n */\nfunction requireRippleCompiler(): any {\n\tconst globalRipple = (globalThis as any).__RIPPLE_COMPILER__;\n\tif (globalRipple && globalRipple.parse) {\n\t\treturn globalRipple;\n\t}\n\n\ttry {\n\t\t// Use createRequire to dynamically require the module\n\t\t// This works in both ESM and CommonJS contexts\n\t\tconst require = createRequire(import.meta.url);\n\t\tconst ripple = require('@tsrx/ripple');\n\n\t\tif (!ripple || !ripple.parse) {\n\t\t\tthrow new Error('Ripple compiler loaded but parse function not found.');\n\t\t}\n\n\t\t(globalThis as any).__RIPPLE_COMPILER__ = ripple;\n\n\t\treturn ripple;\n\t} catch (error: any) {\n\t\tthrow new Error(\n\t\t\t`Failed to load Ripple compiler: ${error.message}. ` +\n\t\t\t\t'Make sure the \"@tsrx/ripple\" package is installed as a peer dependency.',\n\t\t);\n\t}\n}\n\ndeclare global {\n\tvar __RIPPLE_COMPILER__: {\n\t\tparse: (source: string) => Program;\n\t\tcompile: (source: string, filename: string, options?: any) => any;\n\t};\n}\n\nexport default {\n\tparseForESLint,\n\tparse,\n};\n"],"mappings":";;;;;;;;;;AAkBA,SAAS,4BAA4B,KAAgB;CACpD,MAAM,uBAAO,IAAI,KAAU;CAC3B,MAAM,SAAS,SAAc;AAC5B,MAAI,CAAC,QAAQ,OAAO,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BAAgB,aAAa,MAChC,QAAO;AAGR,KAAI;EAIH,MAAM,SADU,cAAc,OAAO,KAAK,IAAI,CACvB,eAAe;AAEtC,MAAI,CAAC,UAAU,CAAC,OAAO,MACtB,OAAM,IAAI,MAAM,uDAAuD;AAGxE,EAAC,WAAmB,sBAAsB;AAE1C,SAAO;UACC,OAAY;AACpB,QAAM,IAAI,MACT,mCAAmC,MAAM,QAAQ,2EAEjD;;;AAWH,kBAAe;CACd;CACA;CACA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsrx/eslint-parser",
|
|
3
|
+
"version": "0.3.25",
|
|
4
|
+
"description": "ESLint parser for Ripple (.tsrx files)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Ripple-TS/ripple.git",
|
|
10
|
+
"directory": "packages/eslint-parser"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Ripple-TS/ripple/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://ripple-ts.com",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"eslint",
|
|
27
|
+
"parser",
|
|
28
|
+
"ripple"
|
|
29
|
+
],
|
|
30
|
+
"author": "Dominic Gannaway",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"eslint": ">=9.0.0",
|
|
34
|
+
"ripple": "*"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@tsrx/ripple": "0.0.6"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/eslint": "^9.6.1",
|
|
41
|
+
"@types/estree": "^1.0.8",
|
|
42
|
+
"@types/node": "^24.3.0",
|
|
43
|
+
"tsdown": "^0.20.3",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dist": "perl -pi -e 's/\"main\": \"src\\/index.ts\"/\"main\": \"dist\\/index.js\"/' package.json",
|
|
51
|
+
"src": "perl -pi -e 's/\"main\": \"dist\\/index.js\"/\"main\": \"src\\/index.ts\"/' package.json",
|
|
52
|
+
"build": "pnpm dist && tsdown && pnpm src || pnpm src"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { Program } from 'estree';
|
|
2
|
+
import type { Linter } from 'eslint';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
|
|
5
|
+
interface ParseResult {
|
|
6
|
+
ast: Program;
|
|
7
|
+
services?: Record<string, any>;
|
|
8
|
+
scopeManager?: any;
|
|
9
|
+
visitorKeys?: Record<string, string[]>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`
|
|
14
|
+
* and `Element.openingElement.attributes`) that are useful for formatters/source-maps.
|
|
15
|
+
* ESLint's traverser will visit both paths and can trigger duplicate rule reports.
|
|
16
|
+
*
|
|
17
|
+
* For ESLint, we prune JSX wrapper nodes to keep a single traversal path.
|
|
18
|
+
*/
|
|
19
|
+
function normalizeRippleAstForEslint(ast: any): void {
|
|
20
|
+
const seen = new Set<any>();
|
|
21
|
+
const visit = (node: any) => {
|
|
22
|
+
if (!node || typeof node !== 'object') return;
|
|
23
|
+
if (seen.has(node)) return;
|
|
24
|
+
seen.add(node);
|
|
25
|
+
|
|
26
|
+
if (node.type === 'Element') {
|
|
27
|
+
// Avoid duplicate traversal of attributes/children through openingElement/closingElement.
|
|
28
|
+
// The Element node itself carries the data ESLint rules care about.
|
|
29
|
+
delete node.openingElement;
|
|
30
|
+
delete node.closingElement;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const key of Object.keys(node)) {
|
|
34
|
+
if (key === 'parent' || key === 'loc' || key === 'range') continue;
|
|
35
|
+
const value = node[key];
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
for (const child of value) visit(child);
|
|
38
|
+
} else if (value && typeof value === 'object') {
|
|
39
|
+
visit(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
visit(ast);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Recursively walks the AST and ensures all nodes have range and loc properties
|
|
49
|
+
* ESLint's scope analyzer requires these properties on ALL nodes
|
|
50
|
+
*/
|
|
51
|
+
function ensureNodeProperties(node: any, code: string): void {
|
|
52
|
+
if (!node || typeof node !== 'object') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Ensure range property exists
|
|
57
|
+
if (node.start !== undefined && node.end !== undefined && !node.range) {
|
|
58
|
+
node.range = [node.start, node.end];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Ensure loc property exists
|
|
62
|
+
if (!node.loc && node.start !== undefined && node.end !== undefined) {
|
|
63
|
+
const lines = code.split('\n');
|
|
64
|
+
let currentPos = 0;
|
|
65
|
+
let startLine = 1;
|
|
66
|
+
let startColumn = 0;
|
|
67
|
+
let endLine = 1;
|
|
68
|
+
let endColumn = 0;
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < lines.length; i++) {
|
|
71
|
+
const lineLength = lines[i].length + 1;
|
|
72
|
+
if (currentPos + lineLength > node.start) {
|
|
73
|
+
startLine = i + 1;
|
|
74
|
+
startColumn = node.start - currentPos;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
currentPos += lineLength;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
currentPos = 0;
|
|
81
|
+
for (let i = 0; i < lines.length; i++) {
|
|
82
|
+
const lineLength = lines[i].length + 1;
|
|
83
|
+
if (currentPos + lineLength > node.end) {
|
|
84
|
+
endLine = i + 1;
|
|
85
|
+
endColumn = node.end - currentPos;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
currentPos += lineLength;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
node.loc = {
|
|
92
|
+
start: { line: startLine, column: startColumn },
|
|
93
|
+
end: { line: endLine, column: endColumn },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const key in node) {
|
|
98
|
+
if (key === 'parent' || key === 'loc' || key === 'range') {
|
|
99
|
+
continue; // Skip these to avoid infinite loops
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const value = node[key];
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
value.forEach((child) => ensureNodeProperties(child, code));
|
|
105
|
+
} else if (value && typeof value === 'object' && value.type) {
|
|
106
|
+
ensureNodeProperties(value, code);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* ESLint parser for Ripple (.tsrx) files
|
|
113
|
+
*
|
|
114
|
+
* This parser uses Ripple's built-in compiler to parse .tsrx files
|
|
115
|
+
* and returns an ESTree-compatible AST for ESLint to analyze.
|
|
116
|
+
*/
|
|
117
|
+
export function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult {
|
|
118
|
+
try {
|
|
119
|
+
// Dynamically import the Ripple compiler
|
|
120
|
+
// We use dynamic import to avoid bundling the entire compiler
|
|
121
|
+
const rippleCompiler = requireRippleCompiler();
|
|
122
|
+
|
|
123
|
+
// Parse the Ripple source code using the Ripple compiler
|
|
124
|
+
const ast = rippleCompiler.parse(code);
|
|
125
|
+
if (!ast) throw new Error('Parser returned null or undefined AST');
|
|
126
|
+
|
|
127
|
+
// Normalize for ESLint traversal (avoid duplicate node visits)
|
|
128
|
+
normalizeRippleAstForEslint(ast);
|
|
129
|
+
|
|
130
|
+
// Recursively ensure all nodes have range and loc properties
|
|
131
|
+
ensureNodeProperties(ast, code);
|
|
132
|
+
|
|
133
|
+
// Create a properly structured AST object ensuring all required properties exist
|
|
134
|
+
const result: any = {
|
|
135
|
+
type: ast.type || 'Program',
|
|
136
|
+
start: ast.start !== undefined ? ast.start : 0,
|
|
137
|
+
end: ast.end !== undefined ? ast.end : code.length,
|
|
138
|
+
loc: ast.loc || {
|
|
139
|
+
start: { line: 1, column: 0 },
|
|
140
|
+
end: { line: code.split('\n').length, column: 0 },
|
|
141
|
+
},
|
|
142
|
+
range: ast.range || [0, code.length],
|
|
143
|
+
body: ast.body || [],
|
|
144
|
+
sourceType: ast.sourceType || 'module',
|
|
145
|
+
comments: ast.comments || [],
|
|
146
|
+
tokens: ast.tokens || [],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
ast: result,
|
|
151
|
+
services: {},
|
|
152
|
+
visitorKeys: undefined, // Use ESLint's default visitor keys
|
|
153
|
+
};
|
|
154
|
+
} catch (error: any) {
|
|
155
|
+
// Transform Ripple parse errors to ESLint-compatible format
|
|
156
|
+
throw new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Legacy parse function for older ESLint versions
|
|
162
|
+
*/
|
|
163
|
+
export function parse(code: string, options?: Linter.ParserOptions): Program {
|
|
164
|
+
const result = parseForESLint(code, options);
|
|
165
|
+
return result.ast;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Helper to require the Ripple compiler
|
|
170
|
+
* This handles both CommonJS and ESM environments
|
|
171
|
+
*/
|
|
172
|
+
function requireRippleCompiler(): any {
|
|
173
|
+
const globalRipple = (globalThis as any).__RIPPLE_COMPILER__;
|
|
174
|
+
if (globalRipple && globalRipple.parse) {
|
|
175
|
+
return globalRipple;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
// Use createRequire to dynamically require the module
|
|
180
|
+
// This works in both ESM and CommonJS contexts
|
|
181
|
+
const require = createRequire(import.meta.url);
|
|
182
|
+
const ripple = require('@tsrx/ripple');
|
|
183
|
+
|
|
184
|
+
if (!ripple || !ripple.parse) {
|
|
185
|
+
throw new Error('Ripple compiler loaded but parse function not found.');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
(globalThis as any).__RIPPLE_COMPILER__ = ripple;
|
|
189
|
+
|
|
190
|
+
return ripple;
|
|
191
|
+
} catch (error: any) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`Failed to load Ripple compiler: ${error.message}. ` +
|
|
194
|
+
'Make sure the "@tsrx/ripple" package is installed as a peer dependency.',
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare global {
|
|
200
|
+
var __RIPPLE_COMPILER__: {
|
|
201
|
+
parse: (source: string) => Program;
|
|
202
|
+
compile: (source: string, filename: string, options?: any) => any;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default {
|
|
207
|
+
parseForESLint,
|
|
208
|
+
parse,
|
|
209
|
+
};
|