ember-eslint-parser 0.2.4 → 0.2.6
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/gjs-gts-parser.js +23 -14
- package/src/parser/transforms.js +17 -11
package/package.json
CHANGED
|
@@ -40,20 +40,29 @@ module.exports = {
|
|
|
40
40
|
throw new Error('Please install typescript to process gts');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
try {
|
|
44
|
+
result = isTypescript
|
|
45
|
+
? typescriptParser.parseForESLint(jsCode, { ...options, ranges: true, filePath })
|
|
46
|
+
: babelParser.parseForESLint(jsCode, {
|
|
47
|
+
...options,
|
|
48
|
+
requireConfigFile: false,
|
|
49
|
+
ranges: true,
|
|
50
|
+
});
|
|
51
|
+
if (!info.templateInfos?.length) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
const preprocessedResult = preprocessGlimmerTemplates(info, code);
|
|
55
|
+
const { templateVisitorKeys } = preprocessedResult;
|
|
56
|
+
const visitorKeys = { ...result.visitorKeys, ...templateVisitorKeys };
|
|
57
|
+
result.isTypescript = isTypescript;
|
|
58
|
+
convertAst(result, preprocessedResult, visitorKeys);
|
|
59
|
+
if (result.services?.program) {
|
|
60
|
+
syncMtsGtsSourceFiles(result.services?.program);
|
|
61
|
+
}
|
|
62
|
+
return { ...result, visitorKeys };
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(e);
|
|
65
|
+
throw e;
|
|
48
66
|
}
|
|
49
|
-
const preprocessedResult = preprocessGlimmerTemplates(info, code);
|
|
50
|
-
const { templateVisitorKeys } = preprocessedResult;
|
|
51
|
-
const visitorKeys = { ...result.visitorKeys, ...templateVisitorKeys };
|
|
52
|
-
result.isTypescript = isTypescript;
|
|
53
|
-
convertAst(result, preprocessedResult, visitorKeys);
|
|
54
|
-
if (result.services?.program) {
|
|
55
|
-
syncMtsGtsSourceFiles(result.services?.program);
|
|
56
|
-
}
|
|
57
|
-
return { ...result, visitorKeys };
|
|
58
67
|
},
|
|
59
68
|
};
|
package/src/parser/transforms.js
CHANGED
|
@@ -114,6 +114,7 @@ function traverse(visitorKeys, node, visitor) {
|
|
|
114
114
|
parent: null,
|
|
115
115
|
parentKey: null,
|
|
116
116
|
parentPath: null,
|
|
117
|
+
context: {},
|
|
117
118
|
});
|
|
118
119
|
|
|
119
120
|
while (queue.length > 0) {
|
|
@@ -121,6 +122,8 @@ function traverse(visitorKeys, node, visitor) {
|
|
|
121
122
|
|
|
122
123
|
visitor(currentPath);
|
|
123
124
|
|
|
125
|
+
if (!currentPath.node) continue;
|
|
126
|
+
|
|
124
127
|
const visitorKeys = allVisitorKeys[currentPath.node.type];
|
|
125
128
|
if (!visitorKeys) {
|
|
126
129
|
continue;
|
|
@@ -136,6 +139,7 @@ function traverse(visitorKeys, node, visitor) {
|
|
|
136
139
|
queue.push({
|
|
137
140
|
node: item,
|
|
138
141
|
parent: currentPath.node,
|
|
142
|
+
context: Object.assign({}, currentPath.context),
|
|
139
143
|
parentKey: visitorKey,
|
|
140
144
|
parentPath: currentPath,
|
|
141
145
|
});
|
|
@@ -144,6 +148,7 @@ function traverse(visitorKeys, node, visitor) {
|
|
|
144
148
|
queue.push({
|
|
145
149
|
node: child,
|
|
146
150
|
parent: currentPath.node,
|
|
151
|
+
context: Object.assign({}, currentPath.context),
|
|
147
152
|
parentKey: visitorKey,
|
|
148
153
|
parentPath: currentPath,
|
|
149
154
|
});
|
|
@@ -419,6 +424,7 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
|
|
|
419
424
|
// eslint-disable-next-line complexity
|
|
420
425
|
traverse(visitorKeys, result.ast, (path) => {
|
|
421
426
|
const node = path.node;
|
|
427
|
+
if (!node) return null;
|
|
422
428
|
if (
|
|
423
429
|
node.type === 'ExpressionStatement' ||
|
|
424
430
|
node.type === 'StaticBlock' ||
|
|
@@ -455,6 +461,9 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
|
|
|
455
461
|
}
|
|
456
462
|
}
|
|
457
463
|
if (node.type === 'GlimmerElementNode') {
|
|
464
|
+
if (node.tag === 'svg') {
|
|
465
|
+
path.context.inSvg = true;
|
|
466
|
+
}
|
|
458
467
|
// always reference first part of tag name, this also has the advantage
|
|
459
468
|
// that errors regarding this tag will only mark the tag name instead of
|
|
460
469
|
// the whole tag + children
|
|
@@ -462,22 +471,19 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
|
|
|
462
471
|
const { scope, variable } = findVarInParentScopes(result.scopeManager, path, n.name) || {};
|
|
463
472
|
/*
|
|
464
473
|
register a node in scope if we found a variable
|
|
465
|
-
we ignore named-blocks as we know that it doesn't reference anything in current scope
|
|
474
|
+
we ignore named-blocks and args as we know that it doesn't reference anything in current scope
|
|
475
|
+
we also ignore `this`
|
|
466
476
|
if we do not find a variable we register it with a missing variable if
|
|
467
477
|
* it starts with upper case, it should be a component with a reference
|
|
468
478
|
* it includes a dot, it's a path which should have a reference
|
|
469
479
|
* it's NOT a standard html tag, it should have a referenced variable
|
|
470
480
|
*/
|
|
471
|
-
|
|
472
|
-
n.name
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
isUpperCase(n.name[0]) ||
|
|
478
|
-
node.name.includes('.') ||
|
|
479
|
-
!htmlTags.includes(node.name))
|
|
480
|
-
) {
|
|
481
|
+
const ignore =
|
|
482
|
+
n.name === 'this' || n.name.startsWith(':') || n.name.startsWith('@') || !scope;
|
|
483
|
+
const registerUndef =
|
|
484
|
+
isUpperCase(n.name[0]) || node.name.includes('.') || !htmlTags.includes(node.name);
|
|
485
|
+
const allowUndef = path.parentPath?.context.inSvg;
|
|
486
|
+
if (!ignore && (variable || (registerUndef && !allowUndef))) {
|
|
481
487
|
registerNodeInScope(n, scope, variable);
|
|
482
488
|
}
|
|
483
489
|
}
|