8000 fix(parser): ng-template visitor keys should include attributes · angular-eslint/angular-eslint@9b3041c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b3041c

Browse files
committed
fix(parser): ng-template visitor keys should include attributes
1 parent 76c6cac commit 9b3041c

File tree

2 files changed

+306
-1
lines changed

2 files changed

+306
-1
lines changed

packages/template-parser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const KEYS: VisitorKeys = {
4646
PrefixNot: ['expression'],
4747
Program: ['templateNodes'],
4848
PropertyRead: ['receiver'],
49-
Template: ['templateAttrs', 'children', 'inputs'],
49+
Template: ['templateAttrs', 'children', 'inputs', 'attributes'],
5050
BindingPipe: ['exp'],
5151
};
5252

packages/template-parser/tests/index.test.ts

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,309 @@ describe('parseForESLint()', () => {
508508
}
509509
`);
510510
});
511+
512+
describe('ng-template parsing', () => {
513+
it('should appropriately parse ng-templates with attributes into an AST', () => {
514+
expect(
515+
parseForESLint('<ng-template dir="hello" i18n-dir></ng-template>', {
516+
filePath: './ng-template.html',
517+
}).ast,
518+
).toMatchInlineSnapshot(`
519+
Object {
520+
"comments": Array [],
521+
"loc": Object {
522+
"end": Object {
523+
"column": 48,
524+
"line": 1,
525+
},
526+
"start": Object {
527+
"column": 0,
528+
"line": 1,
529+
},
530+
},
531+
"range": Array [
532+
0,
533+
48,
534+
],
535+
"templateNodes": Array [
536+
Template {
537+
"attributes": Array [
538+
TextAttribute {
539+
"i18n": Message {
540+
"customId": "",
541+
"description": "",
542+
"id": "3964919876711037238",
543+
"legacyIds": Array [],
544+
"meaning": "",
545+
"messageString": "hello",
546+
"nodes": Array [
547+
Text$2 {
548+
"sourceSpan": ParseSourceSpan {
549+
"details": null,
550+
"end": ParseLocation {
551+
"col": 23,
552+
"file": ParseSourceFile {
553+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
554+
"url": "./ng-template.html",
555+
},
556+
"line": 0,
557+
"offset": 23,
558+
},
559+
"fullStart": ParseLocation {
560+
"col": 18,
561+
"file": ParseSourceFile {
562+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
563+
"url": "./ng-template.html",
564+
},
565+
"line": 0,
566+
"offset": 18,
567+
},
568+
"start": ParseLocation {
569+
"col": 18,
570+
"file": ParseSourceFile {
571+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
572+
"url": "./ng-template.html",
573+
},
574+
"line": 0,
575+
"offset": 18,
576+
},
577+
},
578+
"value": "hello",
579+
},
580+
],
581+
"placeholderToMessage": Object {},
582+
"placeholders": Object {},
583+
"sources": Array [
584+
Object {
585+
"endCol": 19,
586+
"endLine": 1,
587+
"filePath": "./ng-template.html",
588+
"startCol": 19,
589+
"startLine": 1,
590+
},
591+
],
592+
},
593+
"keySpan": ParseSourceSpan {
594+
"details": null,
595+
"end": ParseLocation {
596+
"col": 16,
597+
"file": ParseSourceFile {
598+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
599+
"url": "./ng-template.html",
600+
},
601+
"line": 0,
602+
"offset": 16,
603+
},
604+
"fullStart": ParseLocation {
605+
"col": 13,
606+
"file": ParseSourceFile {
607+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
608+
"url": "./ng-template.html",
609+
},
610+
"line": 0,
611+
"offset": 13,
612+
},
613+
"start": ParseLocation {
614+
"col": 13,
615+
"file": ParseSourceFile {
616+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
617+
"url": "./ng-template.html",
618+
},
619+
"line": 0,
620+
"offset": 13,
621+
},
622+
},
623+
"loc": Object {
624+
"end": Object {
625+
"column": 24,
626+
"line": 1,
627+
},
628+
"start": Object {
629+
"column": 13,
630+
"line": 1,
631+
},
632+
},
633+
"name": "dir",
634+
"sourceSpan": ParseSourceSpan {
635+
"details": null,
636+
"end": ParseLocation {
637+
"col": 24,
638+
"file": ParseSourceFile {
639+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
640+
"url": "./ng-template.html",
641+
},
642+
"line": 0,
643+
"offset": 24,
644+
},
645+
"fullStart": ParseLocation {
646+
"col": 13,
647+
"file": ParseSourceFile {
648+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
649+
"url": "./ng-template.html",
650+
},
651+
"line": 0,
652+
"offset": 13,
653+
},
654+
"start": ParseLocation {
655+
"col": 13,
656+
"file": ParseSourceFile {
657+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
658+
"url": "./ng-template.html",
659+
},
660+
"line": 0,
661+
"offset": 13,
662+
},
663+
},
664+
"type": "TextAttribute",
665+
"value": "hello",
666+
"valueSpan": ParseSourceSpan {
667+
"details": null,
668+
"end": ParseLocation {
669+
"col": 23,
670+
"file": ParseSourceFile {
671+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
672+
"url": "./ng-template.html",
673+
},
674+
"line": 0,
675+
"offset": 23,
676+
},
677+
"fullStart": ParseLocation {
678+
"col": 18,
679+
"file": ParseSourceFile {
680+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
681+
"url": "./ng-template.html",
682+
},
683+
"line": 0,
684+
"offset": 18,
685+
},
686+
"start": ParseLocation {
687+
"col": 18,
688+
"file": ParseSourceFile {
689+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
690+
"url": "./ng-template.html",
691+
},
692+
"line": 0,
693+
"offset": 18,
694+
},
695+
},
696+
},
697+
],
698+
"children": Array [],
699+
"endSourceSpan": ParseSourceSpan {
700+
"details": null,
701+
"end": ParseLocation {
702+
"col": 48,
703+
"file": ParseSourceFile {
704+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
705+
"url": "./ng-template.html",
706+
},
707+
"line": 0,
708+
"offset": 48,
709+
},
710+
"fullStart": ParseLocation {
711+
"col": 34,
712+
"file": ParseSourceFile {
713+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
714+
"url": "./ng-template.html",
715+
},
716+
"line": 0,
717+
"offset": 34,
718+
},
719+
"start": ParseLocation {
720+
"col": 34,
721+
"file": ParseSourceFile {
722+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
723+
"url": "./ng-template.html",
724+
},
725+
"line": 0,
726+
"offset": 34,
727+
},
728+
},
729+
"i18n": undefined,
730+
"inputs": Array [],
731+
"loc": Object {
732+
"end": Object {
733+
"column": 48,
734+
"line": 1,
735+
},
736+
"start": Object {
737+
"column": 0,
738+
"line": 1,
739+
},
740+
},
741+
"outputs": Array [],
742+
"references": Array [],
743+
"sourceSpan": ParseSourceSpan {
744+
"details": null,
745+
"end": ParseLocation {
746+
"col": 48,
747+
"file": ParseSourceFile {
748+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
749+
"url": "./ng-template.html",
750+
},
751+
"line": 0,
752+
"offset": 48,
753+
},
754+
"fullStart": ParseLocation {
755+
"col": 0,
756+
"file": ParseSourceFile {
757+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
758+
"url": "./ng-template.html",
759+
},
760+
"line": 0,
761+
"offset": 0,
762+
},
763+
"start": ParseLocation {
764+
"col": 0,
765+
"file": ParseSourceFile {
766+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
767+
"url": "./ng-template.html",
768+
},
769+
"line": 0,
770+
"offset": 0,
771+
},
772+
},
773+
"startSourceSpan": ParseSourceSpan {
774+
"details": null,
775+
"end": ParseLocation {
776+
"col": 34,
777+
"file": ParseSourceFile {
778+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
779+
"url": "./ng-template.html",
780+
},
781+
"line": 0,
782+
"offset": 34,
783+
},
784+
"fullStart": ParseLocation {
785+
"col": 0,
786+
"file": ParseSourceFile {
787+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
788+
"url": "./ng-template.html",
789+
},
790+
"line": 0,
791+
"offset": 0,
792+
},
793+
"start": ParseLocation {
794+
"col": 0,
795+
"file": ParseSourceFile {
796+
"content": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
797+
"url": "./ng-template.html",
798+
},
799+
"line": 0,
800+
"offset": 0,
801+
},
802+
},
803+
"tagName": "ng-template",
804+
"templateAttrs": Array [],
805+
"type": "Template",
806+
"variables": Array [],
807+
},
808+
],
809+
"tokens": Array [],
810+
"type": "Program",
811+
"value": "<ng-template dir=\\"hello\\" i18n-dir></ng-template>",
812+
}
813+
`);
814+
});
815+
});
511816
});

0 commit comments

Comments
 (0)
0