ember-eslint-parser 0.5.2 → 0.5.4
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
CHANGED
|
@@ -29,7 +29,7 @@ module.exports = {
|
|
|
29
29
|
patchTs();
|
|
30
30
|
registerParsedFile(options.filePath);
|
|
31
31
|
let jsCode = code;
|
|
32
|
-
const info = transformForLint(code);
|
|
32
|
+
const info = transformForLint(code, options.filePath);
|
|
33
33
|
jsCode = info.output;
|
|
34
34
|
|
|
35
35
|
const isTypescript = options.filePath.endsWith('.gts') || options.filePath.endsWith('.ts');
|
package/src/parser/transforms.js
CHANGED
|
@@ -567,7 +567,39 @@ module.exports.replaceRange = replaceRange;
|
|
|
567
567
|
|
|
568
568
|
const processor = new ContentTag.Preprocessor();
|
|
569
569
|
|
|
570
|
-
|
|
570
|
+
class EmberParserError extends Error {
|
|
571
|
+
constructor(message, fileName, location) {
|
|
572
|
+
super(message);
|
|
573
|
+
this.location = location;
|
|
574
|
+
this.fileName = fileName;
|
|
575
|
+
Object.defineProperty(this, 'name', {
|
|
576
|
+
configurable: true,
|
|
577
|
+
enumerable: false,
|
|
578
|
+
value: new.target.name,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// For old version of ESLint https://github.com/typescript-eslint/typescript-eslint/pull/6556#discussion_r1123237311
|
|
583
|
+
get index() {
|
|
584
|
+
return this.location.start.offset;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// https://github.com/eslint/eslint/blob/b09a512107249a4eb19ef5a37b0bd672266eafdb/lib/linter/linter.js#L853
|
|
588
|
+
get lineNumber() {
|
|
589
|
+
return this.location.start.line;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// https://github.com/eslint/eslint/blob/b09a512107249a4eb19ef5a37b0bd672266eafdb/lib/linter/linter.js#L854
|
|
593
|
+
get column() {
|
|
594
|
+
return this.location.start.column;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function createError(code, message, fileName, start, end = start) {
|
|
599
|
+
return new EmberParserError(message, fileName, { end, start });
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
module.exports.transformForLint = function transformForLint(code, fileName) {
|
|
571
603
|
let jsCode = code;
|
|
572
604
|
/**
|
|
573
605
|
*
|
|
@@ -593,7 +625,26 @@ module.exports.transformForLint = function transformForLint(code) {
|
|
|
593
625
|
* };
|
|
594
626
|
* }[]}
|
|
595
627
|
*/
|
|
596
|
-
|
|
628
|
+
let result = null;
|
|
629
|
+
try {
|
|
630
|
+
result = processor.parse(code);
|
|
631
|
+
} catch (e) {
|
|
632
|
+
// Parse Error at <anon>:1:19: 1:19
|
|
633
|
+
if (e.message.includes('Parse Error at')) {
|
|
634
|
+
const [line, column] = e.message
|
|
635
|
+
.split(':')
|
|
636
|
+
.slice(-2)
|
|
637
|
+
.map((x) => parseInt(x));
|
|
638
|
+
// e.source_code has actually usable info, e.g × Expected ',', got 'string literal (, '')'
|
|
639
|
+
// ╭─[9:1]
|
|
640
|
+
// 9 │
|
|
641
|
+
// 10 │ console.log(test'');
|
|
642
|
+
// · ──
|
|
643
|
+
// ╰────
|
|
644
|
+
throw createError(code, e.source_code, fileName, { line, column });
|
|
645
|
+
}
|
|
646
|
+
throw e;
|
|
647
|
+
}
|
|
597
648
|
for (const tplInfo of result.reverse()) {
|
|
598
649
|
const content = tplInfo.contents.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
599
650
|
if (tplInfo.type === 'class-member') {
|
package/src/preprocessor/noop.js
CHANGED
|
@@ -23,7 +23,7 @@ module.exports = {
|
|
|
23
23
|
msgs[0].message += '\n';
|
|
24
24
|
msgs[0].message +=
|
|
25
25
|
'To lint Gjs/Gts files please follow the setup guide at https://github.com/ember-cli/eslint-plugin-ember#gtsgjs' +
|
|
26
|
-
'\nNote that this error can also happen if you have multiple versions of
|
|
26
|
+
'\nNote that this error can also happen if you have multiple versions of eslint-plugin-ember in your node_modules';
|
|
27
27
|
}
|
|
28
28
|
parsedFiles.delete(fileName); // required for tests
|
|
29
29
|
return msgs;
|