Skip to content

Commit 2d6f26f

Browse files
authored
(fix) fix quote addition (#181)
End of attr and attrVal are the same even if they have quotes surrounding it -> needs an extra check for "last character is a quote" Fixes #143
1 parent 9d26bf0 commit 2d6f26f

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

packages/svelte2tsx/src/htmlxtojsx.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ export function convertHtmlxToJsx(
352352

353353
const equals = htmlx.lastIndexOf('=', attrVal.start);
354354
if (attrVal.type == 'Text') {
355-
if (attrVal.end == attr.end) {
355+
const endsWithQuote =
356+
htmlx.lastIndexOf('"', attrVal.end) === attrVal.end - 1 ||
357+
htmlx.lastIndexOf("'", attrVal.end) === attrVal.end - 1;
358+
if (attrVal.end == attr.end && !endsWithQuote) {
356359
//we are not quoted. Add some
357360
str.prependRight(equals + 1, '"');
358361
str.appendLeft(attr.end, '"');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<><script src="./abc.js"></script>
2+
<style src='./abc.js'></style></>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="./abc.js"></script>
2+
<style src='./abc.js'></style>

packages/svelte2tsx/test/svelte2tsx/samples/style-attribute/expected.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<></>;function render() {
2-
<>""</>
2+
<></>
33
return { props: {}, slots: {} }}
44

55
export default class {

0 commit comments

Comments
 (0)