@@ -5,9 +5,9 @@ import type {
55 ImportSpecifier ,
66 JSCodeshift ,
77} from 'jscodeshift' ;
8- import type { ImportPropDecoratorMap } from './decorator-info' ;
9- import { getDecoratorInfo } from './decorator-info' ;
10- import { DEFAULT_OPTIONS } from './options' ;
8+ import type { DecoratorImportInfoMap } from './decorator-info' ;
9+ import { getDecoratorImportInfo } from './decorator-info' ;
10+ import type { Options } from './options' ;
1111import {
1212 createEmberDecoratorSpecifiers ,
1313 createImportDeclaration ,
@@ -99,8 +99,8 @@ function createNewImportDeclarations(
9999 root : Collection < unknown > ,
100100 decoratorsToImport : string [ ] ,
101101 /** Already imported paths */
102- decoratorPathsToIgnore : string [ ] = [ ] ,
103- options = DEFAULT_OPTIONS
102+ decoratorPathsToIgnore : string [ ] ,
103+ options : Options
104104) : void {
105105 const firstDeclaration = getFirstDeclaration ( j , root ) ;
106106
@@ -263,8 +263,8 @@ function getExistingImportForPath(
263263export function createDecoratorImportDeclarations (
264264 j : JSCodeshift ,
265265 root : Collection < unknown > ,
266- decoratorsToImport : string [ ] = [ ] ,
267- options = DEFAULT_OPTIONS
266+ decoratorsToImport : string [ ] ,
267+ options : Options
268268) : void {
269269 // Iterate through existing imports, extract the already imported specifiers
270270 const decoratorPathSpecifierMap = getDecoratorPathSpecifiers (
@@ -304,13 +304,40 @@ export function createDecoratorImportDeclarations(
304304 ) ;
305305}
306306
307- /** Get decorated props from `import` statements */
308- export function getImportedDecoratedProps (
307+ /**
308+ * Get decorator import info from `import` statements
309+ *
310+ * e.g. For these imports:
311+ * `import { observer as watcher, computed } from '@ember/object';`
312+ *
313+ * The returned value will be:
314+ * ```
315+ * {
316+ * watcher: {
317+ * name: "watcher",
318+ * importedName: "observer",
319+ * isImportedAs: true,
320+ * isMetaDecorator: false,
321+ * isMethodDecorator: true,
322+ * localName: "watcher",
323+ * },
324+ * computed: {
325+ * name: "computed",
326+ * importedName: "computed",
327+ * isImportedAs: false,
328+ * isMetaDecorator: false,
329+ * isMethodDecorator: false,
330+ * localName: "computed",
331+ * }
332+ * }
333+ * ```
334+ */
335+ export function getDecoratorImportInfos (
309336 j : JSCodeshift ,
310337 root : Collection < unknown >
311- ) : ImportPropDecoratorMap {
338+ ) : DecoratorImportInfoMap {
312339 const existingDecoratorImports = getExistingDecoratorImports ( j , root ) ;
313- const importedDecorators : ImportPropDecoratorMap = { } ;
340+ const decoratorImportInfo : DecoratorImportInfoMap = new Map ( ) ;
314341
315342 for ( const decoratorImport of existingDecoratorImports ) {
316343 const { importPropDecoratorMap } = defined (
@@ -325,13 +352,13 @@ export function getImportedDecoratedProps(
325352 if ( isSpecifierDecorator ( specifier , importPropDecoratorMap ) ) {
326353 const localName = specifier . local ?. name ;
327354 assert ( localName , 'expected localName' ) ;
328- importedDecorators [ localName ] = getDecoratorInfo (
329- specifier ,
330- importPropDecoratorMap
355+ decoratorImportInfo . set (
356+ localName ,
357+ getDecoratorImportInfo ( specifier , importPropDecoratorMap )
331358 ) ;
332359 }
333360 }
334361 }
335362
336- return importedDecorators ;
363+ return decoratorImportInfo ;
337364}
0 commit comments