@angular-eslint/template-parser 20.5.2-alpha.6 → 20.5.2-alpha.8
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -6
- package/package.json +2 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EAEX,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAS,YAAY,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AAEtC,KAAK,eAAe,GAAG,GAAG,CAAC;AAE3B,UAAU,IAAI;IAEZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,EAAE,eAAe,CAAC;CACvB;AAED,UAAU,WAAW;IACnB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC9B;AAED,UAAU,KAAM,SAAQ,QAAQ,CAAC,QAAQ;IACvC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,GAAI,SAAQ,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC/C,QAAQ,EAAE,KAAK,EAAE,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,aAAa,EAAE,GAAG,EAAE,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EAEX,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BA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C;IAChD,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE;QACR,6BAA6B,EAAE,OAAO,6BAA6B,CAAC;QACpE,0BAA0B,EAAE,OAAO,0BAA0B,CAAC;KAC/D,CAAC;CACH,CAsDA;AAED,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,GAAG,CAE/D;AAGD,eAAO,MAAM,OAAO,EAAE,MAA2C,CAAC;AAElE,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -67,16 +67,87 @@ function isNode(node) {
|
|
|
67
67
|
typeof node === 'object' &&
|
|
68
68
|
typeof node.type === 'string');
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Get line offsets for a source code string (cached for performance)
|
|
72
|
+
*/
|
|
73
|
+
let lineOffsetsCache = null;
|
|
74
|
+
function getLineOffsets(sourceCode) {
|
|
75
|
+
if (!lineOffsetsCache) {
|
|
76
|
+
lineOffsetsCache = new Map();
|
|
77
|
+
}
|
|
78
|
+
let offsets = lineOffsetsCache.get(sourceCode);
|
|
79
|
+
if (!offsets) {
|
|
80
|
+
offsets = [0];
|
|
81
|
+
for (let i = 0; i < sourceCode.length; i++) {
|
|
82
|
+
if (sourceCode[i] === '\n') {
|
|
83
|
+
offsets.push(i + 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
lineOffsetsCache.set(sourceCode, offsets);
|
|
87
|
+
}
|
|
88
|
+
return offsets;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convert absolute offsets to line/column positions
|
|
92
|
+
*/
|
|
93
|
+
function convertAbsoluteSourceSpanToLoc(sourceCode, span) {
|
|
94
|
+
const lineOffsets = getLineOffsets(sourceCode);
|
|
95
|
+
// Binary search for start line
|
|
96
|
+
let startLine = 0;
|
|
97
|
+
let left = 0;
|
|
98
|
+
let right = lineOffsets.length - 1;
|
|
99
|
+
while (left <= right) {
|
|
100
|
+
const mid = Math.floor((left + right) / 2);
|
|
101
|
+
if (lineOffsets[mid] <= span.start) {
|
|
102
|
+
startLine = mid;
|
|
103
|
+
left = mid + 1;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
right = mid - 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const startColumn = span.start - lineOffsets[startLine];
|
|
110
|
+
// Binary search for end line
|
|
111
|
+
let endLine = startLine; // Start from startLine as optimization
|
|
112
|
+
left = startLine;
|
|
113
|
+
right = lineOffsets.length - 1;
|
|
114
|
+
while (left <= right) {
|
|
115
|
+
const mid = Math.floor((left + right) / 2);
|
|
116
|
+
if (lineOffsets[mid] <= span.end) {
|
|
117
|
+
endLine = mid;
|
|
118
|
+
left = mid + 1;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
right = mid - 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const endColumn = span.end - lineOffsets[endLine];
|
|
125
|
+
return {
|
|
126
|
+
start: { line: startLine + 1, column: startColumn },
|
|
127
|
+
end: { line: endLine + 1, column: endColumn },
|
|
128
|
+
};
|
|
129
|
+
}
|
|
70
130
|
/**
|
|
71
131
|
* ESLint requires all Nodes to have `type` and `loc` properties before it can
|
|
72
132
|
* work with the custom AST.
|
|
73
133
|
*/
|
|
74
|
-
function preprocessNode(node) {
|
|
134
|
+
function preprocessNode(node, sourceCode) {
|
|
75
135
|
let i = 0;
|
|
76
136
|
let j = 0;
|
|
77
137
|
const keys = KEYS[node.type] || getFallbackKeys(node);
|
|
78
|
-
if (!node.loc
|
|
79
|
-
|
|
138
|
+
if (!node.loc) {
|
|
139
|
+
if (node.sourceSpan &&
|
|
140
|
+
node.sourceSpan.start &&
|
|
141
|
+
typeof node.sourceSpan.start.line === 'number') {
|
|
142
|
+
// Regular ParseSourceSpan
|
|
143
|
+
node.loc = (0, convert_source_span_to_loc_1.convertNodeSourceSpanToLoc)(node.sourceSpan);
|
|
144
|
+
}
|
|
145
|
+
else if (node.sourceSpan &&
|
|
146
|
+
typeof node.sourceSpan.start === 'number' &&
|
|
147
|
+
sourceCode) {
|
|
148
|
+
// AbsoluteSourceSpan
|
|
149
|
+
node.loc = convertAbsoluteSourceSpanToLoc(sourceCode, node.sourceSpan);
|
|
150
|
+
}
|
|
80
151
|
}
|
|
81
152
|
for (i = 0; i < keys.length; ++i) {
|
|
82
153
|
const child = node[keys[i]];
|
|
@@ -105,12 +176,12 @@ function preprocessNode(node) {
|
|
|
105
176
|
c.type = c.constructor.name;
|
|
106
177
|
}
|
|
107
178
|
if (isNode(c)) {
|
|
108
|
-
preprocessNode(c);
|
|
179
|
+
preprocessNode(c, sourceCode);
|
|
109
180
|
}
|
|
110
181
|
}
|
|
111
182
|
}
|
|
112
183
|
else if (isNode(child)) {
|
|
113
|
-
preprocessNode(child);
|
|
184
|
+
preprocessNode(child, sourceCode);
|
|
114
185
|
}
|
|
115
186
|
}
|
|
116
187
|
}
|
|
@@ -213,7 +284,7 @@ function parseForESLint(code, options) {
|
|
|
213
284
|
};
|
|
214
285
|
const scopeManager = new eslint_scope_1.ScopeManager({});
|
|
215
286
|
new eslint_scope_1.Scope(scopeManager, 'module', null, ast, false);
|
|
216
|
-
preprocessNode(ast);
|
|
287
|
+
preprocessNode(ast, code);
|
|
217
288
|
const startSourceSpan = getStartSourceSpanFromAST(ast);
|
|
218
289
|
const endSourceSpan = getEndSourceSpanFromAST(ast);
|
|
219
290
|
if (startSourceSpan && endSourceSpan) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/template-parser",
|
|
3
|
-
"version": "20.5.2-alpha.
|
|
3
|
+
"version": "20.5.2-alpha.8",
|
|
4
4
|
"description": "Angular Template parser for ESLint",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"eslint-scope": "^8.0.2",
|
|
22
|
-
"@angular-eslint/bundled-angular-compiler": "20.5.2-alpha.
|
|
22
|
+
"@angular-eslint/bundled-angular-compiler": "20.5.2-alpha.8"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"eslint": "^8.57.0 || ^9.0.0",
|