-- TS 7 content mapper 가 transform 요청을 받으면: CSS 모듈 → TS 모듈 + 대응표 + 진단transform :: Options -> Content -> Resulttransform opts = stripBom >>> parse >>> collectLocals >>> exportsOf (localsConvention opts) >>> render opts >>> shiftBom -- BOM: postcss 가 떼므로 그만큼 원본 위치·진단 위치를 다시 민다-- ① 오타 하나가 이 파일을 import 하는 모든 곳을 깨지 않게parse :: CSS -> (Root, [Diagnostic])parse css = case postcss css of Right root -> (root, []) Left err -> (safeParse css, [syntaxError err]) -- 진단을 남기고 살릴 수 있는 만큼 살린다-- ② 내보낼 이름과, CSS 에 적힌 그 이름의 위치 (escape 포함) — 이 위치가 ④의 대응 끝점이다locals :: Node -> [Local]locals (Rule ":export" decls) = map prop decls -- ICSS: 키 그대로locals (Rule sel) | inKeyframes = [] -- from·to·50% 는 이름이 아니다 | otherwise = classesAndIds sel -- :global(…) 안은 빼고, 인자 없는 :global 은 뒤쪽 전부를 뺀다locals (AtRule "keyframes" name) = [name] -- :global 이면 없음locals (AtRule "value" params) = valueNames params -- @value a: … / @value a, b as c from "…"locals (AtRule "scope" params) = parenthesized params >>= classesAndIds -- @scope (.card) to (.content)locals (Decl "composes" v) = [] -- 대신 검사: 이 파일에 없는 클래스면 진단, from 이 붙으면 건너뜀 -- 같은 이름은 처음 것만. hover 문서 = 앞의 /** */ 주석 + 선언 CSS (12줄까지)-- ③ 이름 → 키. Vite 의 css.modules.localsConvention 과 같은 값keys :: Convention -> Name -> [Key]keys CamelCase n = [n, camelCase n] -- camelCase = lodash.camelcase (postcss-modules 와 같게)keys CamelCaseOnly n = [camelCase n]keys Dashes n = [n, dashesCamelCase n] -- 대시 뒤 글자만 대문자로keys DashesOnly n = [dashesCamelCase n]keys _ n = [n]-- ④ TS 를 써 내려가다 키를 쓰는 순간, 그 자리를 원본 이름 자리에 잇는다emitKey :: Key -> Local -> Writer (Text, [SpanMapping]) ()emitKey key local = do here <- length <$> text tell ( key , [(here, length key, start local, length local, Alias, Hover .|. Definition .|. References .|. DocumentHighlights)] ) -- Alias: 키(btnPrimary)와 원본(btn-primary)이 달라도 에러·정의로 가기는 원본 이름에 붙는다render :: Options -> [(Key, Local)] -> (Text, [SpanMapping])render opts exports = [ "declare const styles: { readonly " <> emitKey k l <> ": string; … }; export default styles;" | defaultExport opts ] -- 식별자가 아닌 키는 "btn-primary" 문자열 키로 -- styles 라는 키가 있으면 바인딩을 _styles 로 <> [ "export declare const " <> emitKey k l <> ": string;" | namedExports opts, isBindingName k ] -- 식별자이고 예약어가 아닐 때만 `orElse` "export {};" -- 내보낼 게 없어도 모듈이어야 한다