Skip to content

Commit

Permalink
fix(@formatjs/cli-lib): try catch vue script parsing, fix #4136
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Sep 18, 2023
1 parent 166d7ba commit 7a8fc8d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/cli-lib/src/vue_extractor.ts
Expand Up @@ -70,7 +70,14 @@ function templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {
// Wrap this in () since a vue comp node attribute can just be
// an object literal which, by itself is invalid TS
// but with () it becomes an ExpressionStatement
parseScriptFn(`(${content})`)
try {
parseScriptFn(`(${content})`)
} catch (e) {
console.warn(
`Failed to parse "${content}". Ignore this if content has no extractable message`,
e
)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/integration-tests/BUILD
Expand Up @@ -48,8 +48,8 @@ jest_test(
"//:node_modules/@babel/types",
"//:node_modules/@types/node",
"//:node_modules/@vue/compiler-core",
"//:node_modules/vue",
"//:node_modules/fast-glob",
"//:node_modules/vue",
],
flaky = True,
snapshots = glob(["extract-vue/__snapshots__/*"]),
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/integration-tests/extract-vue/comp.vue
Expand Up @@ -7,7 +7,7 @@
})
}}
</p>
<div class="message" v-for="message in messages">
<div class="message" v-for="message of messages">
{{ message.content }}
</div>
</template>
Expand All @@ -29,7 +29,7 @@ const messages = ref([
id: 2,
content: 'https://youtu.be/dQw4w9WgXcQ',
},
]);
])
const intl = useIntl()
console.log(intl.formatMessage({defaultMessage: 'script setup'}))
</script>

0 comments on commit 7a8fc8d

Please sign in to comment.