1
1
/* eslint-disable-next-line */
2
- /// <reference path="../types/shims-vue-template- compiler.d.ts"/>
3
- import { SFCBlock , SFCDescriptor } from 'vue-template- compiler'
2
+ /// <reference path="../types/shims-vue-compiler-sfc .d.ts"/>
3
+ import { SFCBlock , SFCDescriptor } from '@ vue/ compiler-sfc '
4
4
import { Locale , MetaLocaleMessage , SFCI18nBlock , SFCFileInfo , FormatOptions } from '../types'
5
5
6
6
import { escape , reflectSFCDescriptor , parseContent , stringifyContent } from './utils'
@@ -24,7 +24,7 @@ function generate (meta: MetaLocaleMessage, descriptor: SFCDescriptor, options?:
24
24
debug ( 'target i18n blocks\n' , i18nBlocks )
25
25
26
26
const blocks : SFCBlock [ ] = getBlocks ( descriptor )
27
- blocks . forEach ( b => debug ( `block: type=${ b . type } , start=${ b . start } , end=${ b . end } ` ) )
27
+ blocks . forEach ( b => debug ( `block: type=${ b . type } , start=${ b . loc . start . offset } , end=${ b . loc . end . offset } ` ) )
28
28
29
29
const { raw } = descriptor
30
30
const content = buildContent ( i18nBlocks , raw , blocks , options )
@@ -39,7 +39,9 @@ function getBlocks (descriptor: SFCDescriptor): SFCBlock[] {
39
39
const blocks : SFCBlock [ ] = [ ...styles , ...customBlocks ]
40
40
template && blocks . push ( template as SFCBlock )
41
41
script && blocks . push ( script as SFCBlock )
42
- blocks . sort ( ( a , b ) => { return ( a . start as number ) - ( b . start as number ) } )
42
+ blocks . sort ( ( a , b ) => {
43
+ return a . loc . start . offset - b . loc . start . offset
44
+ } )
43
45
return blocks
44
46
}
45
47
@@ -52,7 +54,7 @@ function buildContent (i18nBlocks: SFCI18nBlock[], raw: string, blocks: SFCBlock
52
54
if ( block . type === 'i18n' ) {
53
55
let lang = block . attrs . lang
54
56
lang = ( ! lang || typeof lang !== 'string' ) ? 'json' : lang
55
- const locale : Locale | undefined = block . attrs . locale
57
+ const locale : Locale | true = block . attrs . locale
56
58
const i18nBlock = i18nBlocks [ i18nBlockCounter ]
57
59
debug ( `meta.lang = ${ i18nBlock . lang } , block.lang = ${ lang } , meta.locale = ${ i18nBlock . locale } , block.locale = ${ locale } ` )
58
60
@@ -68,14 +70,14 @@ function buildContent (i18nBlocks: SFCI18nBlock[], raw: string, blocks: SFCBlock
68
70
messages = parseContent ( block . content , lang )
69
71
}
70
72
71
- contents = contents . concat ( raw . slice ( offset , block . start ) )
73
+ contents = contents . concat ( raw . slice ( offset , block . loc . start . offset ) )
72
74
const serialized = `\n${ stringifyContent ( messages , lang , options ) } `
73
75
contents = contents . concat ( serialized )
74
- offset = block . end as number
76
+ offset = block . loc . end . offset
75
77
i18nBlockCounter ++
76
78
} else {
77
- contents = contents . concat ( raw . slice ( offset , block . end ) )
78
- offset = block . end as number
79
+ contents = contents . concat ( raw . slice ( offset , block . loc . end . offset ) )
80
+ offset = block . loc . end . offset
79
81
}
80
82
return contents
81
83
} , contents )
0 commit comments