@@ -60,144 +60,144 @@ async function runForPath(path, options = {}) {
6060 let componentPaths = await globby ( 'app/components/**/*.js' , { cwd : path } ) ;
6161 debug ( 'componentPaths = %O' , componentPaths ) ;
6262
63- files: for ( let componentPath of componentPaths ) {
64- let dimPath = chalk . dim ( componentPath ) ;
65-
66- let source = fs . readFileSync ( componentPath , 'utf8' ) ;
67-
68- let root = j ( source ) ;
69-
70- // find `export default Component.extend({ ... });` AST node
71- let exportDefaultDeclarations = root . find ( j . ExportDefaultDeclaration , {
72- declaration : {
73- type : 'CallExpression' ,
74- callee : {
75- type : 'MemberExpression' ,
76- object : { name : 'Component' } ,
77- property : { name : 'extend' } ,
78- } ,
79- } ,
80- } ) ;
81-
82- if ( exportDefaultDeclarations . length !== 1 ) {
83- console . log (
84- chalk . yellow ( `${ dimPath } : Could not find \`export default Component.extend({ ... });\`` )
85- ) ;
86- continue ;
87- }
88-
89- let exportDefaultDeclaration = exportDefaultDeclarations . get ( ) ;
90-
91- // find first `{ ... }` inside `Component.extend()` arguments
92- let extendObjectArgs = exportDefaultDeclaration
93- . get ( 'declaration' , 'arguments' )
94- . filter ( path => path . value . type === 'ObjectExpression' ) ;
63+ for ( let componentPath of componentPaths ) {
64+ transform ( componentPath ) ;
65+ }
9566
96- let objectArg = extendObjectArgs [ 0 ] ;
97- if ( ! objectArg ) {
98- console . log (
99- chalk . yellow (
100- `${ dimPath } : Could not find object argument in \`export default Component.extend({ ... });\``
101- )
102- ) ;
103- continue ;
104- }
67+ debug ( 'runForPath() finished' ) ;
68+ }
10569
106- // find `tagName` property if it exists
107- let properties = objectArg . get ( 'properties' ) ;
70+ function transform ( componentPath ) {
71+ let dimPath = chalk . dim ( componentPath ) ;
10872
109- let tagName = findTagName ( properties ) ;
110- if ( tagName . constructor . name === 'NodePath' ) {
111- console . log (
112- chalk . yellow ( `${ dimPath } : Unexpected \`tagName\` value: ${ j ( tagName ) . toSource ( ) } ` )
113- ) ;
114- continue ;
115- }
73+ let source = fs . readFileSync ( componentPath , 'utf8' ) ;
11674
117- // skip tagless components (silent)
118- if ( tagName === '' ) {
119- debug ( `${ componentPath } : tagName: %o -> skip` , tagName ) ;
120- continue ;
121- }
75+ let root = j ( source ) ;
12276
123- debug ( `${ componentPath } : tagName: %o` , tagName ) ;
77+ // find `export default Component.extend({ ... });` AST node
78+ let exportDefaultDeclarations = root . find ( j . ExportDefaultDeclaration , {
79+ declaration : {
80+ type : 'CallExpression' ,
81+ callee : {
82+ type : 'MemberExpression' ,
83+ object : { name : 'Component' } ,
84+ property : { name : 'extend' } ,
85+ } ,
86+ } ,
87+ } ) ;
88+
89+ if ( exportDefaultDeclarations . length !== 1 ) {
90+ console . log (
91+ chalk . yellow ( `${ dimPath } : Could not find \`export default Component.extend({ ... });\`` )
92+ ) ;
93+ return ;
94+ }
12495
125- // skip components that use `this.element`
126- let thisElementPaths = j ( objectArg ) . find ( j . MemberExpression , {
127- object : { type : 'ThisExpression' } ,
128- property : { name : 'element' } ,
129- } ) ;
130- if ( thisElementPaths . length !== 0 ) {
131- console . log (
132- chalk . yellow ( `${ dimPath } : Using \`this.element\` is not supported in tagless components` )
133- ) ;
134- continue ;
135- }
96+ let exportDefaultDeclaration = exportDefaultDeclarations . get ( ) ;
97+
98+ // find first `{ ... }` inside `Component.extend()` arguments
99+ let extendObjectArgs = exportDefaultDeclaration
100+ . get ( 'declaration' , 'arguments' )
101+ . filter ( path => path . value . type === 'ObjectExpression' ) ;
102+
103+ let objectArg = extendObjectArgs [ 0 ] ;
104+ if ( ! objectArg ) {
105+ console . log (
106+ chalk . yellow (
107+ `${ dimPath } : Could not find object argument in \`export default Component.extend({ ... });\``
108+ )
109+ ) ;
110+ return ;
111+ }
136112
137- // skip components that use `click()` etc.
138- for ( let methodName of EVENT_HANDLER_METHODS ) {
139- let handlerMethod = properties . filter ( path => isMethod ( path , methodName ) ) [ 0 ] ;
140- if ( handlerMethod ) {
141- console . log (
142- chalk . yellow (
143- `${ dimPath } : Using \`${ methodName } ()\` is not supported in tagless components`
144- )
145- ) ;
146- continue files;
147- }
148- }
113+ // find `tagName` property if it exists
114+ let properties = objectArg . get ( 'properties' ) ;
149115
150- // analyze `elementId`, `attributeBindings`, `classNames` and `classNameBindings`
151- let elementId = findElementId ( properties ) ;
152- if ( elementId !== null && elementId . constructor . name === 'NodePath' ) {
153- console . log (
154- chalk . yellow ( `${ dimPath } : Unexpected \`elementId\` value: ${ j ( elementId ) . toSource ( ) } ` )
155- ) ;
156- continue ;
157- }
158- debug ( `${ componentPath } : elementId: %o` , elementId ) ;
116+ let tagName = findTagName ( properties ) ;
117+ if ( tagName . constructor . name === 'NodePath' ) {
118+ console . log ( chalk . yellow ( `${ dimPath } : Unexpected \`tagName\` value: ${ j ( tagName ) . toSource ( ) } ` ) ) ;
119+ return ;
120+ }
159121
160- let attributeBindings = findAttributeBindings ( properties ) ;
161- if ( attributeBindings . constructor . name === 'NodePath' ) {
162- console . log (
163- chalk . yellow (
164- `${ dimPath } : Unexpected \`attributeBindings\` value: ${ j ( attributeBindings ) . toSource ( ) } `
165- )
166- ) ;
167- continue ;
168- }
169- debug ( `${ componentPath } : attributeBindings: %o` , attributeBindings ) ;
122+ // skip tagless components (silent)
123+ if ( tagName === '' ) {
124+ debug ( `${ componentPath } : tagName: %o -> skip` , tagName ) ;
125+ return ;
126+ }
170127
171- let classNames = findClassNames ( properties ) ;
172- if ( classNames . constructor . name === 'NodePath' ) {
173- console . log (
174- chalk . yellow ( `${ dimPath } : Unexpected \`classNames\` value: ${ j ( classNames ) . toSource ( ) } ` )
175- ) ;
176- continue ;
177- }
178- debug ( `${ componentPath } : classNames: %o` , classNames ) ;
128+ debug ( `${ componentPath } : tagName: %o` , tagName ) ;
129+
130+ // skip components that use `this.element`
131+ let thisElementPaths = j ( objectArg ) . find ( j . MemberExpression , {
132+ object : { type : 'ThisExpression' } ,
133+ property : { name : 'element' } ,
134+ } ) ;
135+ if ( thisElementPaths . length !== 0 ) {
136+ console . log (
137+ chalk . yellow ( `${ dimPath } : Using \`this.element\` is not supported in tagless components` )
138+ ) ;
139+ return ;
140+ }
179141
180- let classNameBindings = findClassNameBindings ( properties ) ;
181- if ( classNameBindings . constructor . name === 'NodePath' ) {
142+ // skip components that use `click()` etc.
143+ for ( let methodName of EVENT_HANDLER_METHODS ) {
144+ let handlerMethod = properties . filter ( path => isMethod ( path , methodName ) ) [ 0 ] ;
145+ if ( handlerMethod ) {
182146 console . log (
183- chalk . yellow (
184- `${ dimPath } : Unexpected \`classNameBindings\` value: ${ j ( classNameBindings ) . toSource ( ) } `
185- )
147+ chalk . yellow ( `${ dimPath } : Using \`${ methodName } ()\` is not supported in tagless components` )
186148 ) ;
187- continue ;
149+ return ;
188150 }
189- debug ( ` ${ componentPath } : classNameBindings: %o` , classNameBindings ) ;
151+ }
190152
191- // TODO skip on error (warn incl. please report)
153+ // analyze `elementId`, `attributeBindings`, `classNames` and `classNameBindings`
154+ let elementId = findElementId ( properties ) ;
155+ if ( elementId !== null && elementId . constructor . name === 'NodePath' ) {
156+ console . log (
157+ chalk . yellow ( `${ dimPath } : Unexpected \`elementId\` value: ${ j ( elementId ) . toSource ( ) } ` )
158+ ) ;
159+ return ;
160+ }
161+ debug ( `${ componentPath } : elementId: %o` , elementId ) ;
162+
163+ let attributeBindings = findAttributeBindings ( properties ) ;
164+ if ( attributeBindings . constructor . name === 'NodePath' ) {
165+ console . log (
166+ chalk . yellow (
167+ `${ dimPath } : Unexpected \`attributeBindings\` value: ${ j ( attributeBindings ) . toSource ( ) } `
168+ )
169+ ) ;
170+ return ;
171+ }
172+ debug ( `${ componentPath } : attributeBindings: %o` , attributeBindings ) ;
173+
174+ let classNames = findClassNames ( properties ) ;
175+ if ( classNames . constructor . name === 'NodePath' ) {
176+ console . log (
177+ chalk . yellow ( `${ dimPath } : Unexpected \`classNames\` value: ${ j ( classNames ) . toSource ( ) } ` )
178+ ) ;
179+ return ;
180+ }
181+ debug ( `${ componentPath } : classNames: %o` , classNames ) ;
182+
183+ let classNameBindings = findClassNameBindings ( properties ) ;
184+ if ( classNameBindings . constructor . name === 'NodePath' ) {
185+ console . log (
186+ chalk . yellow (
187+ `${ dimPath } : Unexpected \`classNameBindings\` value: ${ j ( classNameBindings ) . toSource ( ) } `
188+ )
189+ ) ;
190+ return ;
191+ }
192+ debug ( `${ componentPath } : classNameBindings: %o` , classNameBindings ) ;
192193
193- // TODO find corresponding template files
194- // TODO skip if not found (warn)
194+ // TODO skip on error (warn incl. please report)
195195
196- // TODO set `tagName: ''` and remove `attributeBindings`, `classNames`, ...
197- // TODO wrap existing template with root element
198- }
196+ // TODO find corresponding template files
197+ // TODO skip if not found (warn)
199198
200- debug ( 'runForPath() finished' ) ;
199+ // TODO set `tagName: ''` and remove `attributeBindings`, `classNames`, ...
200+ // TODO wrap existing template with root element
201201}
202202
203203function isProperty ( path , name ) {
0 commit comments