ember-eslint-parser 0.3.0 → 0.3.2
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/package.json +1 -1
- package/src/parser/transforms.js +25 -6
package/package.json
CHANGED
package/src/parser/transforms.js
CHANGED
|
@@ -125,6 +125,16 @@ function traverse(visitorKeys, node, visitor) {
|
|
|
125
125
|
if (!currentPath.node) continue;
|
|
126
126
|
|
|
127
127
|
const visitorKeys = allVisitorKeys[currentPath.node.type];
|
|
128
|
+
if (currentPath.node.type === 'GlimmerElementNode') {
|
|
129
|
+
if (!visitorKeys.includes('blockParamNodes')) {
|
|
130
|
+
visitorKeys.push('blockParamNodes', 'parts');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (currentPath.node.type === 'GlimmerProgram') {
|
|
134
|
+
if (!visitorKeys.includes('blockParamNodes')) {
|
|
135
|
+
visitorKeys.push('blockParamNodes');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
128
138
|
if (!visitorKeys) {
|
|
129
139
|
continue;
|
|
130
140
|
}
|
|
@@ -242,6 +252,7 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
242
252
|
const textNodes = [];
|
|
243
253
|
const emptyTextNodes = [];
|
|
244
254
|
const range = tpl.utf16Range;
|
|
255
|
+
const offset = range[0];
|
|
245
256
|
const template = code.slice(...range);
|
|
246
257
|
const docLines = new DocumentLines(template);
|
|
247
258
|
const ast = glimmer.preprocess(template, { mode: 'codemod' });
|
|
@@ -273,8 +284,8 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
273
284
|
for (const n of allNodes) {
|
|
274
285
|
if (n.type === 'PathExpression') {
|
|
275
286
|
n.head.range = [
|
|
276
|
-
|
|
277
|
-
|
|
287
|
+
offset + docLines.positionToOffset(n.head.loc.start),
|
|
288
|
+
offset + docLines.positionToOffset(n.head.loc.end),
|
|
278
289
|
];
|
|
279
290
|
n.head.loc = {
|
|
280
291
|
start: codeLines.offsetToPosition(n.head.range[0]),
|
|
@@ -283,10 +294,10 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
283
294
|
}
|
|
284
295
|
n.range =
|
|
285
296
|
n.type === 'Template'
|
|
286
|
-
? [tpl.utf16Range
|
|
297
|
+
? [...tpl.utf16Range]
|
|
287
298
|
: [
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
offset + docLines.positionToOffset(n.loc.start),
|
|
300
|
+
offset + docLines.positionToOffset(n.loc.end),
|
|
290
301
|
];
|
|
291
302
|
n.start = n.range[0];
|
|
292
303
|
n.end = n.range[1];
|
|
@@ -306,6 +317,10 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
306
317
|
parent: n,
|
|
307
318
|
type: 'GlimmerElementNodePart',
|
|
308
319
|
name: p.value,
|
|
320
|
+
range: [
|
|
321
|
+
offset + docLines.positionToOffset(p.loc.start),
|
|
322
|
+
offset + docLines.positionToOffset(p.loc.end),
|
|
323
|
+
],
|
|
309
324
|
}));
|
|
310
325
|
}
|
|
311
326
|
|
|
@@ -315,6 +330,10 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
315
330
|
...p,
|
|
316
331
|
parent: n,
|
|
317
332
|
name: p.value,
|
|
333
|
+
range: [
|
|
334
|
+
offset + docLines.positionToOffset(p.loc.start),
|
|
335
|
+
offset + docLines.positionToOffset(p.loc.end),
|
|
336
|
+
],
|
|
318
337
|
}));
|
|
319
338
|
}
|
|
320
339
|
n.type = `Glimmer${n.type}`;
|
|
@@ -323,7 +342,7 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
323
342
|
|
|
324
343
|
// ast should not contains empty text nodes
|
|
325
344
|
for (const node of emptyTextNodes) {
|
|
326
|
-
const children = node.parent.children || node.parent.body;
|
|
345
|
+
const children = node.parent.children || node.parent.body || node.parent.parts;
|
|
327
346
|
const idx = children.indexOf(node);
|
|
328
347
|
children.splice(idx, 1);
|
|
329
348
|
}
|