Skip to content

Commit bb4764a

Browse files
committed
Correctly add pure annotation
1 parent 5b8da26 commit bb4764a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

__tests__/frameworks/vite/external.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('Vite external', () => {
178178
expect(code).toMatchInlineSnapshot(`
179179
"=== /fixtures/ftl/en/importer.js.ftl ===
180180
181-
export default /*#__PURE__*/ {"body":[{"id":"key","value":"Translations for js file","attributes":{}}]}
181+
export default {"body":[{"id":"key","value":"Translations for js file","attributes":{}}]}
182182
"
183183
`)
184184
})

src/plugins/external-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions) => {
132132
}
133133

134134
if (isFtl(id)) {
135-
const injectFtl = getInjectFtl(resolvedOptions)
135+
const injectFtl = getInjectFtl(resolvedOptions, true)
136136
const result = injectFtl`
137-
export default /*#__PURE__*/ ${source}
137+
export default ${source}
138138
`
139139

140140
if (result.error)

src/plugins/ftl/inject.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ function normalize(str: string) {
88
return str.replace(/\r\n/g, '\n').trim()
99
}
1010

11-
export function getInjectFtl(options: { checkSyntax: boolean, parseFtl: boolean }): InjectFtlFn {
11+
export function getInjectFtl(options: { checkSyntax: boolean, parseFtl: boolean }, addPureAnotation = false): InjectFtlFn {
1212
return (template, locale, source) => {
1313
if (source == null) {
1414
source = locale
1515
locale = undefined
1616
}
1717

18+
const pureAnotation = addPureAnotation ? '/*#__PURE__*/ ' : ''
19+
1820
if (source == null)
1921
throw new Error('Missing source')
2022

@@ -39,7 +41,7 @@ export function getInjectFtl(options: { checkSyntax: boolean, parseFtl: boolean
3941
magic.overwrite(0, source.length, JSON.stringify(resource))
4042
}
4143
else {
42-
magic.overwrite(0, source.length, `new FluentResource(${JSON.stringify(normalize(source))})`)
44+
magic.overwrite(0, source.length, `${pureAnotation}new FluentResource(${JSON.stringify(normalize(source))})`)
4345
}
4446

4547
if (template.length === 2) {

0 commit comments

Comments
 (0)