@@ -9,6 +9,7 @@ const babelParseOptions: babel.ParserOptions = {
99 'typescript' , // NonNullAssert
1010 ] ,
1111 ranges : true ,
12+ attachComment : false ,
1213} ;
1314
1415export const parseBabelExpression = ( input : string ) => {
@@ -32,51 +33,17 @@ export function massageAst(ast: any, parser: 'babel' | 'angular'): any {
3233 return ast . map ( ( node ) => massageAst ( node , parser ) ) ;
3334 }
3435
35- if ( parser === 'babel' && typeof ast . extra ?. parenStart === 'number' ) {
36- delete ast . extra . parenStart ;
37- }
38-
39- // Not exists in types, but exists in node.
40- if ( ast . type === 'ObjectProperty' ) {
41- if ( ast . method !== undefined && ast . method !== false ) {
42- throw new Error (
43- `Unexpected "method: ${ ast . method } " in "ObjectProperty".` ,
44- ) ;
36+ // We don't provide these
37+ if ( parser === 'babel' ) {
38+ if ( typeof ast . extra ?. parenStart === 'number' ) {
39+ delete ast . extra . parenStart ;
4540 }
46- delete ast . method ;
47-
48- if (
49- ast . shorthand &&
50- ast . extra &&
51- Object . keys ( ast . extra ) . length === 1 &&
52- ast . extra . shorthand
53- ) {
54- delete ast . extra ;
55- }
56- }
5741
58- delete ast . loc ;
42+ delete ast . loc ;
43+ }
5944
6045 const massaged = Object . keys ( ast ) . reduce ( ( reduced : any , key ) => {
61- switch ( key ) {
62- case 'trailingComments' :
63- // do nothing
64- break ;
65- case 'extra' : {
66- const extra = massageAst ( ast [ key ] , parser ) ;
67- if ( extra ) {
68- // we added a custom `parenEnd` field for positioning
69- delete extra . parenEnd ;
70- if ( Object . keys ( extra ) . length !== 0 ) {
71- reduced [ key ] = extra ;
72- }
73- }
74- break ;
75- }
76- default :
77- reduced [ key ] = massageAst ( ast [ key ] , parser ) ;
78- break ;
79- }
46+ reduced [ key ] = massageAst ( ast [ key ] , parser ) ;
8047 return reduced ;
8148 } , { } ) ;
8249
0 commit comments