Skip to content

Commit 266b424

Browse files
committed
👕 refactor: reflector
1 parent c8bc6e5 commit 266b424

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/reflector.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,25 @@ const debug = Debug('vue-i18n-locale-message:reflector')
1010

1111
export default function reflectLocaleMessageMeta (basePath: string, components: SFCFileInfo[]): LocaleMessageMeta[] {
1212
return components.map(target => {
13-
const desc = parse({
13+
const { customBlocks } = parse({
1414
source: target.content,
1515
filename: target.path,
1616
compiler: compiler as VueTemplateCompiler
1717
})
18-
const { contentPath, component, hierarchy } = parsePath(basePath, target.path)
19-
return {
20-
contentPath,
21-
blocks: desc.customBlocks,
22-
component,
23-
hierarchy
24-
}
18+
return { ...parsePath(basePath, target.path), blocks: customBlocks }
2519
})
2620
}
2721

2822
function parsePath (basePath: string, targetPath: string) {
29-
const parsed = path.parse(targetPath)
23+
const { dir, name } = path.parse(targetPath)
3024
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31-
const [_, target] = parsed.dir.split(basePath)
25+
const [_, target] = dir.split(basePath)
3226
const parsedTargetPath = target.split(path.sep)
3327
parsedTargetPath.shift()
34-
debug(`parsePath: contentPath = ${targetPath}, component = ${parsed.name}, messageHierarchy = ${parsedTargetPath}`)
28+
debug(`parsePath: contentPath = ${targetPath}, component = ${name}, messageHierarchy = ${parsedTargetPath}`)
3529
return {
3630
contentPath: targetPath,
37-
component: parsed.name,
38-
hierarchy: [...parsedTargetPath, parsed.name]
31+
component: name,
32+
hierarchy: [...parsedTargetPath, name]
3933
}
4034
}

0 commit comments

Comments
 (0)