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:
Haoqun Jiang 2020-09-15 09:51:15 +08:00 committed by GitHub
parent 0cddde6aa4
commit 273d19ad46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -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>

View File

@ -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) {