ember-eslint-parser 0.5.3 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-eslint-parser",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -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');
@@ -567,7 +567,39 @@ module.exports.replaceRange = replaceRange;
567
567
 
568
568
  const processor = new ContentTag.Preprocessor();
569
569
 
570
- module.exports.transformForLint = function transformForLint(code) {
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
- const result = processor.parse(code);
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') {