@@ -567,7 +567,39 @@ module.exports.replaceRange = replaceRange;
567567
568568const processor = new ContentTag . Preprocessor ( ) ;
569569
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 ) {
571603 let jsCode = code ;
572604 /**
573605 *
@@ -593,7 +625,26 @@ module.exports.transformForLint = function transformForLint(code) {
593625 * };
594626 * }[] }
595627 */
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+ }
597648 for ( const tplInfo of result . reverse ( ) ) {
598649 const content = tplInfo . contents . replace ( / ` / g, '\\`' ) . replace ( / \$ / g, '\\$' ) ;
599650 if ( tplInfo . type === 'class-member' ) {
0 commit comments