11import type * as ng from '@angular/compiler' ;
22import type * as b from '@babel/types' ;
3- import {
4- parseAction ,
5- parseBinding ,
6- parseInterpolationExpression ,
7- parseSimpleBinding ,
8- } from '../src/index.js' ;
3+ import * as estreeParser from '../src/index.js' ;
94import type { NGNode } from '../src/types.js' ;
10- import {
11- getNgType ,
12- parseNgAction ,
13- parseNgBinding ,
14- parseNgInterpolationExpression ,
15- parseNgSimpleBinding ,
16- } from '../src/utils.js' ;
5+ import { getNgType } from '../src/utils.js' ;
6+ import * as angularParser from '../src/parser.js' ;
177import {
188 massageAst ,
199 parseBabel ,
@@ -22,7 +12,7 @@ import {
2212} from './helpers.js' ;
2313
2414describe . each `
25- beforeType | afterType | input | action | binding | simple | interpolation
15+ angularType | estreeType | input | action | binding | simple | interpolation
2616 ${ 'Binary' } | ${ 'BinaryExpression' } | ${ ' 0 - 1 ' } | ${ true } | ${ true } | ${ true } | ${ true }
2717 ${ 'Binary' } | ${ 'LogicalExpression' } | ${ ' a && b ' } | ${ true } | ${ true } | ${ true } | ${ true }
2818 ${ 'Binary' } | ${ 'LogicalExpression' } | ${ ' a ?? b ' } | ${ true } | ${ true } | ${ true } | ${ true }
@@ -87,56 +77,60 @@ describe.each`
8777 ${ 'Call' } | ${ 'OptionalCallExpression' } | ${ ' a ?. b ( ) ' } | ${ true } | ${ true } | ${ true } | ${ true }
8878 ${ 'SafeCall' } | ${ 'OptionalCallExpression' } | ${ ' a ?. b ?. ( ) ' } | ${ true } | ${ true } | ${ true } | ${ true }
8979 ${ 'SafePropertyRead' } | ${ 'OptionalMemberExpression' } | ${ ' a ?. b ' } | ${ true } | ${ true } | ${ true } | ${ true }
90- ` ( '$input ($beforeType -> $afterType )' , ( fields ) => {
91- const { beforeType , afterType , input } = fields ;
80+ ` ( '$input ($angularType -> $estreeType )' , ( fields ) => {
81+ const { angularType , estreeType , input } = fields ;
9282
93- let beforeNode : ng . AST | null = null ;
94- let afterNode : NGNode | null = null ;
83+ let angularNode : ng . AST | null = null ;
84+ let estreeNode : NGNode | null = null ;
9585
9686 const testSection = (
9787 section : Extract < keyof typeof fields , string > ,
98- parseBefore : ( input : string ) => { ast : ng . AST } ,
99- parseAfter : ( input : string ) => NGNode ,
88+ parseAngular : ( input : string ) => { ast : ng . AST } ,
89+ parseEstree : ( input : string ) => NGNode ,
10090 ) => {
10191 if ( fields [ section ] ) {
10292 test ( `allowed in ${ section } ` , ( ) => {
103- expect ( ( ) => ( beforeNode = parseBefore ( input ) . ast ) ) . not . toThrow ( ) ;
104- expect ( ( ) => ( afterNode = parseAfter ( input ) ) ) . not . toThrow ( ) ;
93+ expect ( ( ) => ( angularNode = parseAngular ( input ) . ast ) ) . not . toThrow ( ) ;
94+ expect ( ( ) => ( estreeNode = parseEstree ( input ) ) ) . not . toThrow ( ) ;
10595 } ) ;
10696 } else {
10797 test ( `disallowed in ${ section } ` , ( ) => {
108- expect ( ( ) => parseBefore ( input ) ) . toThrow ( ) ;
109- expect ( ( ) => parseAfter ( input ) ) . toThrow ( ) ;
98+ expect ( ( ) => parseAngular ( input ) ) . toThrow ( ) ;
99+ expect ( ( ) => parseEstree ( input ) ) . toThrow ( ) ;
110100 } ) ;
111101 }
112102 } ;
113103
114- testSection ( 'action' , parseNgAction , parseAction ) ;
115- testSection ( 'binding' , parseNgBinding , parseBinding ) ;
116- testSection ( 'simple' , parseNgSimpleBinding , parseSimpleBinding ) ;
104+ testSection ( 'action' , angularParser . parseAction , estreeParser . parseAction ) ;
105+ testSection ( 'binding' , angularParser . parseBinding , estreeParser . parseBinding ) ;
106+ testSection (
107+ 'simple' ,
108+ angularParser . parseSimpleBinding ,
109+ estreeParser . parseSimpleBinding ,
110+ ) ;
117111 testSection (
118112 'interpolation' ,
119- parseNgInterpolationExpression ,
120- parseInterpolationExpression ,
113+ angularParser . parseInterpolationExpression ,
114+ estreeParser . parseInterpolationExpression ,
121115 ) ;
122116
123117 test ( 'ast' , ( ) => {
124- expect ( beforeNode ) . not . toEqual ( null ) ;
125- expect ( afterNode ) . not . toEqual ( null ) ;
118+ expect ( angularNode ) . not . toEqual ( null ) ;
119+ expect ( estreeNode ) . not . toEqual ( null ) ;
126120
127- expect ( getNgType ( beforeNode ! ) ) . toEqual ( beforeType ) ;
128- expect ( afterNode ! . type ) . toEqual ( afterType ) ;
121+ expect ( getNgType ( angularNode ! ) ) . toEqual ( angularType ) ;
122+ expect ( estreeNode ! . type ) . toEqual ( estreeType ) ;
129123
130- if ( afterNode ! . type . startsWith ( 'NG' ) ) {
131- expect ( snapshotAst ( afterNode , input ) ) . toMatchSnapshot ( ) ;
124+ if ( estreeNode ! . type . startsWith ( 'NG' ) ) {
125+ expect ( snapshotAst ( estreeNode , input ) ) . toMatchSnapshot ( ) ;
132126 } else {
133127 try {
134- expect ( afterNode ) . toEqual ( massageAst ( parseBabelExpression ( input ) ) ) ;
128+ expect ( estreeNode ) . toEqual ( massageAst ( parseBabelExpression ( input ) ) ) ;
135129 } catch {
136130 const { comments, program } = parseBabel ( input ) ;
137131 const statement = program . body [ 0 ] as b . ExpressionStatement ;
138132 expect ( statement . type ) . toEqual ( 'ExpressionStatement' ) ;
139- expect ( massageAst ( afterNode ) ) . toEqual (
133+ expect ( massageAst ( estreeNode ) ) . toEqual (
140134 massageAst ( { ...statement . expression , comments } ) ,
141135 ) ;
142136 }
0 commit comments