11import { getTelemetryFor } from 'ember-codemods-telemetry-helpers' ;
22import type { JSCodeshift } from 'jscodeshift' ;
33import path from 'path' ;
4+ import type { ASTPath , Collection , EOExtendExpression } from './ast' ;
5+ import { isNode } from './ast' ;
46import {
57 createDecoratorImportDeclarations ,
68 getDecoratorImportInfos as getExistingDecoratorImportInfos ,
@@ -18,10 +20,7 @@ import {
1820} from './parse-helper' ;
1921import { isRuntimeData } from './runtime-data' ;
2022import { createClass , withComments } from './transform-helper' ;
21- import { dig } from './util/index' ;
22- import { isString } from './util/types' ;
2323import { hasValidProps , isFileOfType , isTestFile } from './validation-helper' ;
24- import type { Collection } from './ast' ;
2524
2625/** Main entry point for parsing and replacing ember objects */
2726export default function maybeTransformEmberObjects (
@@ -42,13 +41,14 @@ export default function maybeTransformEmberObjects(
4241 return ;
4342 }
4443
45- // FIXME: Revert
46- const runtimeData = getTelemetryFor ( path . resolve ( filePath ) ) ?? { } ;
47- if ( ! isRuntimeData ( runtimeData ) ) {
48- // logger.warn(
49- // `[${filePath}]: SKIPPED Could not find runtime data NO_RUNTIME_DATA`
50- // );
51- // return;
44+ const runtimeData = process . env [ 'DOGFOOD' ]
45+ ? { }
46+ : getTelemetryFor ( path . resolve ( filePath ) ) ;
47+ if ( ! runtimeData || ! isRuntimeData ( runtimeData ) ) {
48+ logger . warn (
49+ `[${ filePath } ]: SKIPPED Could not find runtime data NO_RUNTIME_DATA`
50+ ) ;
51+ return ;
5252 }
5353
5454 const options : Options = {
@@ -100,73 +100,76 @@ function _maybeTransformEmberObjects(
100100 } ;
101101
102102 // eslint-disable-next-line unicorn/no-array-for-each
103- getEOExtendExpressionCollection ( j , root ) . forEach ( ( eoExtendExpressionPath ) => {
104- const { eoExpression, mixins } = parseEOExtendExpression (
105- eoExtendExpressionPath . value
106- ) ;
107-
108- const eoProps = getEOProps (
109- eoExpression ,
110- existingDecoratorImportInfos ,
111- options . runtimeData
112- ) ;
113-
114- const errors = hasValidProps ( j , eoProps , options ) ;
103+ getEOExtendExpressionCollection ( j , root ) . forEach (
104+ ( eoExtendExpressionPath : ASTPath < EOExtendExpression > ) => {
105+ const { eoExpression, mixins } = parseEOExtendExpression (
106+ eoExtendExpressionPath . value
107+ ) ;
115108
116- if (
117- dig ( eoExtendExpressionPath , 'parentPath.value.type' , isString ) ===
118- 'MemberExpression'
119- ) {
120- errors . push (
121- 'class has chained definition (e.g. EmberObject.extend().reopenClass();'
109+ const eoProps = getEOProps (
110+ eoExpression ,
111+ existingDecoratorImportInfos ,
112+ options . runtimeData
122113 ) ;
123- }
124114
125- if ( errors . length > 0 ) {
126- logger . warn (
127- `[${ filePath } ]: FAILURE \nValidation errors: \n\t${ errors . join ( '\n\t' ) } `
115+ const errors = hasValidProps ( j , eoProps , options ) ;
116+
117+ if (
118+ isNode ( eoExtendExpressionPath . parentPath ?. value , 'MemberExpression' )
119+ ) {
120+ errors . push (
121+ 'class has chained definition (e.g. EmberObject.extend().reopenClass();'
122+ ) ;
123+ }
124+
125+ if ( errors . length > 0 ) {
126+ logger . warn (
127+ `[${ filePath } ]: FAILURE \nValidation errors: \n\t${ errors . join (
128+ '\n\t'
129+ ) } `
130+ ) ;
131+ return ;
132+ }
133+
134+ let className = getClassName (
135+ j ,
136+ eoExtendExpressionPath ,
137+ filePath ,
138+ options . runtimeData . type
128139 ) ;
129- return ;
130- }
131140
132- let className = getClassName (
133- j ,
134- eoExtendExpressionPath ,
135- filePath ,
136- options . runtimeData . type
137- ) ;
141+ const callee = eoExtendExpressionPath . value . callee ;
142+ const superClassName = callee . object . name ;
138143
139- const callee = eoExtendExpressionPath . value . callee ;
140- const superClassName = callee . object . name ;
144+ if ( className === superClassName ) {
145+ className = `_${ className } ` ;
146+ }
141147
142- if ( className === superClassName ) {
143- className = `_${ className } ` ;
144- }
145-
146- const es6ClassDeclaration = createClass (
147- j ,
148- className ,
149- eoProps ,
150- superClassName ,
151- mixins ,
152- options
153- ) ;
148+ const es6ClassDeclaration = createClass (
149+ j ,
150+ className ,
151+ eoProps ,
152+ superClassName ,
153+ mixins ,
154+ options
155+ ) ;
154156
155- const expressionToReplace = getExpressionToReplace (
156- j ,
157- eoExtendExpressionPath
158- ) ;
159- j ( expressionToReplace ) . replaceWith (
160- withComments ( es6ClassDeclaration , expressionToReplace . value )
161- ) ;
157+ const expressionToReplace = getExpressionToReplace (
158+ j ,
159+ eoExtendExpressionPath
160+ ) ;
161+ j ( expressionToReplace ) . replaceWith (
162+ withComments ( es6ClassDeclaration , expressionToReplace . value )
163+ ) ;
162164
163- transformed = true ;
165+ transformed = true ;
164166
165- decoratorImportSpecs = getDecoratorsToImportSpecs (
166- eoProps . instanceProps ,
167- decoratorImportSpecs
168- ) ;
169- } ) ;
167+ decoratorImportSpecs = getDecoratorsToImportSpecs (
168+ eoProps . instanceProps ,
169+ decoratorImportSpecs
170+ ) ;
171+ }
172+ ) ;
170173
171174 return { transformed, decoratorImportSpecs } ;
172175}
0 commit comments