Skip to content

Commit

Permalink
refactor(bezier-codemod): add bezier context to enum transform function
Browse files Browse the repository at this point in the history
  • Loading branch information
yangwooseong committed Dec 22, 2023
1 parent bcf4880 commit 4a70aab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/bezier-codemod/src/shared/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Member = string
type Value = string
export type EnumTransformMap = Record<Name, Record<Member, Value>>

export const transformEnumMemberToStringLiteral = (sourceFile: SourceFile, enumTransforms: EnumTransformMap) => {
export const transformEnumTostringLiteralInBezier = (sourceFile: SourceFile, enumTransforms: EnumTransformMap) => {
const transformedEnumNames: string[] = []

Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type SourceFile } from 'ts-morph'

import {
type EnumTransformMap,
transformEnumMemberToStringLiteral,
transformEnumTostringLiteralInBezier,
} from '../../shared/enum.js'

const ENUM_TRANSFORM_MAP: EnumTransformMap = {
Expand All @@ -18,7 +18,7 @@ const ENUM_TRANSFORM_MAP: EnumTransformMap = {
}

function enumMemberToStringLiteral(sourceFile: SourceFile): true | void {
return transformEnumMemberToStringLiteral(sourceFile, ENUM_TRANSFORM_MAP)
return transformEnumTostringLiteralInBezier(sourceFile, ENUM_TRANSFORM_MAP)
}

export default enumMemberToStringLiteral
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-template-curly-in-string */
import { type SourceFile } from 'ts-morph'

import { transformEnumMemberToStringLiteral } from '../../shared/enum.js'
import { transformEnumTostringLiteralInBezier } from '../../shared/enum.js'
import { interpolationTransform } from '../../shared/interpolation.js'
import { removeUnusedNamedImport } from '../../utils/import.js'

const cssVariableByInterpolation = {
const CSS_VARIABLE_TRANSFORM_MAP = {
'ZIndex.Hide': 'var(--z-index-hidden);',
'ZIndex.Auto': 'var(--z-index-auto);',
'ZIndex.Base': 'var(--z-index-base);',
Expand All @@ -17,22 +17,24 @@ const cssVariableByInterpolation = {
'ZIndex.Important': 'var(--z-index-important);',
}

const ENUM_TRANSFORM_MAP = {
ZIndex: {
Hide: 'var(--z-index-hidden)',
Base: 'var(--z-index-base)',
Float: 'var(--z-index-float)',
Overlay: 'var(--z-index-overlay)',
Modal: 'var(--z-index-modal)',
Toast: 'var(--z-index-toast)',
Tooltip: 'var(--z-index-tooltip)',
Important: 'var(--z-index-important)',
},
}

const replaceZIndexInterpolation = (sourceFile: SourceFile) => {
const oldSourceFileText = sourceFile.getText()

interpolationTransform(sourceFile, cssVariableByInterpolation)
transformEnumMemberToStringLiteral(sourceFile, {
ZIndex: {
Hide: 'var(--z-index-hidden)',
Base: 'var(--z-index-base)',
Float: 'var(--z-index-float)',
Overlay: 'var(--z-index-overlay)',
Modal: 'var(--z-index-modal)',
Toast: 'var(--z-index-toast)',
Tooltip: 'var(--z-index-tooltip)',
Important: 'var(--z-index-important)',
},
})
interpolationTransform(sourceFile, CSS_VARIABLE_TRANSFORM_MAP)
transformEnumTostringLiteralInBezier(sourceFile, ENUM_TRANSFORM_MAP)

const isChanged = sourceFile.getText() !== oldSourceFileText
if (isChanged) {
Expand Down

0 comments on commit 4a70aab

Please sign in to comment.