svelte2tsx 0.7.52 → 0.7.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -6
- package/index.mjs +12 -6
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -2810,12 +2810,9 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
|
|
|
2810
2810
|
if (!needsNumberConversion) {
|
|
2811
2811
|
attributeValue.push(quote);
|
|
2812
2812
|
}
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
str.overwrite(attrVal.start, attrVal.end, attrVal.data.split('\n').join('\\n'), {
|
|
2817
|
-
contentOnly: true
|
|
2818
|
-
});
|
|
2813
|
+
const escapedValue = tryEscapeAttributeValue(attrVal.data, !includesTemplateLiteralQuote);
|
|
2814
|
+
if (escapedValue !== null) {
|
|
2815
|
+
str.overwrite(attrVal.start, attrVal.end, escapedValue, { contentOnly: true });
|
|
2819
2816
|
}
|
|
2820
2817
|
attributeValue.push([attrVal.start, attrVal.end]);
|
|
2821
2818
|
if (!needsNumberConversion) {
|
|
@@ -2849,6 +2846,15 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
|
|
|
2849
2846
|
function attributeValueIsOfType(value, type) {
|
|
2850
2847
|
return value !== true && value.length == 1 && value[0].type == type;
|
|
2851
2848
|
}
|
|
2849
|
+
function tryEscapeAttributeValue(str, useTemplateLiteral) {
|
|
2850
|
+
// Multiline attribute value text which can't be wrapped in a template literal
|
|
2851
|
+
// -> ensure it's still a valid transformation by transforming the actual line break
|
|
2852
|
+
// \ is not a valid escape in HTML, but it could be part of the attribute value and would break the generated code
|
|
2853
|
+
if (!str.includes('\\') && (useTemplateLiteral || !str.includes('\n'))) {
|
|
2854
|
+
return null;
|
|
2855
|
+
}
|
|
2856
|
+
return JSON.stringify(str).slice(1, -1);
|
|
2857
|
+
}
|
|
2852
2858
|
|
|
2853
2859
|
/**
|
|
2854
2860
|
* This needs to be called on the way out, not on the way on, when walking,
|
package/index.mjs
CHANGED
|
@@ -2790,12 +2790,9 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
|
|
|
2790
2790
|
if (!needsNumberConversion) {
|
|
2791
2791
|
attributeValue.push(quote);
|
|
2792
2792
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
str.overwrite(attrVal.start, attrVal.end, attrVal.data.split('\n').join('\\n'), {
|
|
2797
|
-
contentOnly: true
|
|
2798
|
-
});
|
|
2793
|
+
const escapedValue = tryEscapeAttributeValue(attrVal.data, !includesTemplateLiteralQuote);
|
|
2794
|
+
if (escapedValue !== null) {
|
|
2795
|
+
str.overwrite(attrVal.start, attrVal.end, escapedValue, { contentOnly: true });
|
|
2799
2796
|
}
|
|
2800
2797
|
attributeValue.push([attrVal.start, attrVal.end]);
|
|
2801
2798
|
if (!needsNumberConversion) {
|
|
@@ -2829,6 +2826,15 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
|
|
|
2829
2826
|
function attributeValueIsOfType(value, type) {
|
|
2830
2827
|
return value !== true && value.length == 1 && value[0].type == type;
|
|
2831
2828
|
}
|
|
2829
|
+
function tryEscapeAttributeValue(str, useTemplateLiteral) {
|
|
2830
|
+
// Multiline attribute value text which can't be wrapped in a template literal
|
|
2831
|
+
// -> ensure it's still a valid transformation by transforming the actual line break
|
|
2832
|
+
// \ is not a valid escape in HTML, but it could be part of the attribute value and would break the generated code
|
|
2833
|
+
if (!str.includes('\\') && (useTemplateLiteral || !str.includes('\n'))) {
|
|
2834
|
+
return null;
|
|
2835
|
+
}
|
|
2836
|
+
return JSON.stringify(str).slice(1, -1);
|
|
2837
|
+
}
|
|
2832
2838
|
|
|
2833
2839
|
/**
|
|
2834
2840
|
* This needs to be called on the way out, not on the way on, when walking,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte2tsx",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.53",
|
|
4
4
|
"description": "Convert Svelte components to TSX for type checking",
|
|
5
5
|
"author": "The Svelte Community",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"@types/node": "^18.0.0",
|
|
30
30
|
"@types/unist": "^2.0.3",
|
|
31
31
|
"@types/vfile": "^3.0.2",
|
|
32
|
-
"builtin-modules": "^3.3.0",
|
|
33
32
|
"estree-walker": "^2.0.1",
|
|
34
33
|
"magic-string": "^0.30.11",
|
|
35
34
|
"mocha": "^9.2.0",
|