* fix: should be able to parse decorators in script lang="ts"
* fix: should also support parsing jsx
Added to `compileScript` instead of `babelParserDefaultPlugins` because
it's not needed for template expression parsing
})
describe('SFC analyze <script> bindings', () => {
+ it('can parse decorators syntax in typescript block', () => {
+ const { scriptAst } = compile(`
+ <script lang="ts">
+ import { Options, Vue } from 'vue-class-component';
+ @Options({
+ components: {
+ HelloWorld,
+ },
+ props: ['foo', 'bar']
+ })
+ export default class Home extends Vue {}
+ </script>
+ `)
+
+ expect(scriptAst).toBeDefined()
+ })
it('recognizes props array declaration', () => {
const { bindings } = compile(`
<script>
const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang
const isTS = scriptLang === 'ts' || scriptSetupLang === 'ts'
- const plugins: ParserPlugin[] = [...babelParserDefaultPlugins]
+ const plugins: ParserPlugin[] = [...babelParserDefaultPlugins, 'jsx']
if (options.babelParserPlugins) plugins.push(...options.babelParserPlugins)
- if (isTS) plugins.push('typescript')
+ if (isTS) plugins.push('typescript', 'decorators-legacy')
if (!scriptSetup) {
if (!script) {