pawelgabryelewicz / babel-preset-typescript-vue

TypeScript preset for Babel 7.x supporting Vue.js components written in TS
MIT License
22 stars 4 forks source link

Incorrectly parses non-XML-compliant template #2

Closed akoidan closed 4 years ago

akoidan commented 4 years ago

This template causes typescript error:

<template>
<img src="logo.png">
</template>

Note the image closing tag is missing, but it's still valid vue template. Things like linters inspire that syntax

ERROR in ./src/components/App.vue?vue&type=script&lang=ts& (../node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/App.vue?vue&type=script&lang=ts&) Module build failed (from ../node_modules/babel-loader/lib/index.js): SyntaxError: /home/andrew/WebstormProjects/vue-webpack-typescript/src/components/App.vue: Unexpected token (32:10)

30 | }) 31 | export default class App extends Vue {

32 | private i: number = 0; | ^ 33 | private readonly a: number[] = []; 34 | 35 | private readonly id: string = 'App';

pawelgabryelewicz commented 4 years ago

Hi! Thank you for reporting this. Unfortunately, the official docs don't say which syntax must be used for the <template> section. In fact the XML parsing works fine - what you have mentioned as an example is not a valid XML - I guess it's SGML (which is a quite relaxed superset) and that kind of parser has to be used. At first glance I can't see any reasonable high-level parser written in JS (and I don't want to write one + don't want to rely on string replace method as well :D). I'll investigate if there is any suitable solution. I've stopped using vue recently so I may not be up to date - maybe this package is no longer required and the official vue-loader already covers this case?

akoidan commented 4 years ago

@pawelgabryelewicz well, I stuck to that issue for the second time, and it's really hard to track those errors, cause from the first look it seems like the cause should be in babel-loader.

pawelgabryelewicz commented 4 years ago

I have recently released version 1.1.1 which relies on internal vue-template-compiler - please check if the issue persists. Starting from now all the files that Vue is able to compile, should work here as well. It's not exactly the source that you mentioned, but that was a good point to start with. Thanks for your contribution and your time. Sorry for the delay, this is a very side project.