fix: should be able to parse decorators in script lang="ts" & jsx (#2088)
* 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
This commit is contained in:
parent
0cddde6aa4
commit
273d19ad46
@ -520,6 +520,22 @@ describe('SFC compile <script setup>', () => {
|
||||
})
|
||||
|
||||
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>
|
||||
|
@ -60,9 +60,9 @@ export function compileScript(
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user