Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,23 @@ export function handleAttribute(
parent.type === 'Element' &&
numberOnlyAttributes.has(attr.name.toLowerCase()) &&
!isNaN(attrVal.data);
const quote = ['"', "'"].includes(str.original[attrVal.start - 1])
const includesTemplateLiteralQuote = attrVal.data.includes('`');
const quote = !includesTemplateLiteralQuote
? '`'
: ['"', "'"].includes(str.original[attrVal.start - 1])
? str.original[attrVal.start - 1]
: '"';

if (!needsNumberConversion) {
attributeValue.push(quote);
}
if (includesTemplateLiteralQuote && attrVal.data.split('\n').length > 1) {
// Multiline attribute value text which can't be wrapped in a template literal
// -> ensure it's still a valid transformation by transforming the actual line break
str.overwrite(attrVal.start, attrVal.end, attrVal.data.split('\n').join('\\n'), {
contentOnly: true
});
}
attributeValue.push([attrVal.start, attrVal.end]);
if (!needsNumberConversion) {
attributeValue.push(quote);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{ const $$_Hello0C = __sveltets_2_ensureComponent(Hello); new $$_Hello0C({ target: __sveltets_2_any(), props: { "|-wtf":"foo",}}); Hello}
{ svelteHTML.createElement("div", { "--custom-prop":"foo",}); }
{ const $$_Hello0C = __sveltets_2_ensureComponent(Hello); new $$_Hello0C({ target: __sveltets_2_any(), props: { "|-wtf":`foo`,}}); Hello}
{ svelteHTML.createElement("div", { "--custom-prop":`foo`,}); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<><Comp multilineattr="hello
world" />
<Comp multilineattr="he`llo
world" />
<Comp multilineattr={`
color: ${color}
display: block`} />

<div multilineattr="hello
world" />
<div multilineattr="he`llo
world" />
<div multilineattr={`
color: ${color}
display: block`} /></>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ const $$_Comp0C = __sveltets_2_ensureComponent(Comp); new $$_Comp0C({ target: __sveltets_2_any(), props: { "multilineattr":`hello
world`,}});}
{ const $$_Comp0C = __sveltets_2_ensureComponent(Comp); new $$_Comp0C({ target: __sveltets_2_any(), props: { "multilineattr":"he`llo\nworld",}});}
{ const $$_Comp0C = __sveltets_2_ensureComponent(Comp); new $$_Comp0C({ target: __sveltets_2_any(), props: { "multilineattr":`
color: ${color}
display: block`,}});}

{ svelteHTML.createElement("div", { "multilineattr":`hello
world`,});}
{ svelteHTML.createElement("div", { "multilineattr":"he`llo\nworld",});}
{ svelteHTML.createElement("div", { "multilineattr":`
color: ${color}
display: block`,});}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Comp multilineattr="hello
world" />
<Comp multilineattr="he`llo
world" />
<Comp multilineattr="
color: {color}
display: block" />

<div multilineattr="hello
world" />
<div multilineattr="he`llo
world" />
<div multilineattr="
color: {color}
display: block" />

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{ svelteHTML.createElement("input", { "type":"text",value,});}
{ svelteHTML.createElement("input", { "type":"checkbox",checked,});}
{ svelteHTML.createElement("input", { "type":`text`,value,});}
{ svelteHTML.createElement("input", { "type":`checkbox`,checked,});}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{ svelteHTML.createElement("input", { "type":"radio","value":"Plain",});group;}
{ svelteHTML.createElement("input", { "type":"radio","value":"Plain",});group;}
{ svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});group;}
{ svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});group;}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ svelteHTML.createElement("input", { "type":"radio","value":"Plain",});tortilla;}
{ svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});tortilla;}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{ svelteHTML.createElement("input", { "type":"text",value:test,});}
{ svelteHTML.createElement("input", { "type":"text",value:test,});}
{ svelteHTML.createElement("input", { "type":"text",value:test,});}
{ svelteHTML.createElement("input", { "type":`text`,value:test,});}
{ svelteHTML.createElement("input", { "type":`text`,value:test,});}
{ svelteHTML.createElement("input", { "type":`text`,value:test,});}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ const $$_Parent0C = __sveltets_2_ensureComponent(Parent); const $$_Parent0 = new $$_Parent0C({ target: __sveltets_2_any(), props: { "bare":true,shorthand,"text1":"val1","text2":"val2","text3":`a${a}b${b}`,"textEmpty":"","literal":true,"strLiteral":'foo',"complex":{a},"a-dashed-complex":{a},...__sveltets_2_cssProp({"--custom-cssprop":"foo"}),}});{const {/*Ωignore_startΩ*/$$_$$/*Ωignore_endΩ*/,foo,} = $$_Parent0.$$slot_def.default;$$_$$;
{ const $$_Parent0C = __sveltets_2_ensureComponent(Parent); const $$_Parent0 = new $$_Parent0C({ target: __sveltets_2_any(), props: { "bare":true,shorthand,"text1":`val1`,"text2":`val2`,"text3":`a${a}b${b}`,"textEmpty":``,"literal":true,"strLiteral":'foo',"complex":{a},"a-dashed-complex":{a},...__sveltets_2_cssProp({"--custom-cssprop":`foo`}),}});{const {/*Ωignore_startΩ*/$$_$$/*Ωignore_endΩ*/,foo,} = $$_Parent0.$$slot_def.default;$$_$$;
{const {/*Ωignore_startΩ*/$$_$$/*Ωignore_endΩ*/,bar,} = $$_Parent0.$$slot_def["named"];$$_$$;{ const $$_Component1C = __sveltets_2_ensureComponent(Component); new $$_Component1C({ target: __sveltets_2_any(), props: { }});
foo; bar;
}Component}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{ svelteHTML.createElement("html", { "lang":"en",});
{ svelteHTML.createElement("html", { "lang":`en`,});
{ svelteHTML.createElement("body", {});
{ svelteHTML.createElement("h1", {}); }
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ svelteHTML.createElement("svg", { "width":"12","height":"12","viewBox":"0 0 24 24",}); }
{ svelteHTML.createElement("svg", { "width":`12`,"height":`12`,"viewBox":`0 0 24 24`,}); }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///<reference types="svelte" />
;function render() {
async () => { { svelteHTML.createElement("element", { "someAttr":"hi","someOtherAttribute":"there",}); }
{ const $$_Component0C = __sveltets_2_ensureComponent(Component); new $$_Component0C({ target: __sveltets_2_any(), props: { "someAttr":"5","otherAttr":6,}});}};
async () => { { svelteHTML.createElement("element", { "someAttr":`hi`,"someOtherAttribute":`there`,}); }
{ const $$_Component0C = __sveltets_2_ensureComponent(Component); new $$_Component0C({ target: __sveltets_2_any(), props: { "someAttr":`5`,"otherAttr":6,}});}};
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///<reference types="svelte" />
;function render() {
async () => { { svelteHTML.createElement("input", { "id":"dom-input","type":"radio","value":"dom",});(__sveltets_1_store_get(compile_options), $compile_options).generate;}};
async () => { { svelteHTML.createElement("input", { "id":`dom-input`,"type":`radio`,"value":`dom`,});(__sveltets_1_store_get(compile_options), $compile_options).generate;}};
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async () => {



{ svelteHTML.createElement("div", { "class":"controls",});
{ svelteHTML.createElement("div", { "class":`controls`,});
{ svelteHTML.createElement("button", { "onclick":() => travel(-1),"disabled":i === 0,}); }
{ svelteHTML.createElement("button", { "onclick":() => travel(+1),"disabled":i === undoStack.length -1,}); }
}
Expand All @@ -79,9 +79,9 @@ async () => {
}

if(adjusting){
{ svelteHTML.createElement("div", { "class":"adjuster",});
{ svelteHTML.createElement("div", { "class":`adjuster`,});
{ svelteHTML.createElement("p", {}); selected.cx; selected.cy; }
{ svelteHTML.createElement("input", { "type":"range","value":selected.r,"oninput":adjust,});}
{ svelteHTML.createElement("input", { "type":`range`,"value":selected.r,"oninput":adjust,});}
}
}};
return { props: {}, slots: {}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/;
async () => {
{ svelteHTML.createElement("div", {});
{ __sveltets_createSlot("default", { "a":b,b,"c":"b","d":`a${b}`,"e":b,}); }
{ __sveltets_createSlot("default", { "a":b,b,"c":`b`,"d":`a${b}`,"e":b,}); }
}};
return { props: {}, slots: {'default': {a:b, b:b, c:"b", d:"__svelte_ts_string", e:b}}, getters: {}, events: {} }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { { __sveltets_createSlot("default", {}); { svelteHTML.createElement("div", {}); } }
{ __sveltets_createSlot("foo", { bar,"baz":"boo",});
{ __sveltets_createSlot("foo", { bar,"baz":`boo`,});
{ svelteHTML.createElement("p", {}); }
}};
return { props: {}, slots: {'default': {}, 'foo': {bar:bar, baz:"boo"}}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { { const $$_Parent0C = __sveltets_2_ensureComponent(Parent); const $$_Parent0 = new $$_Parent0C({ target: __sveltets_2_any(), props: { "propA":true,propB,"propC":"val1","propD":"val2","propE":`a${a}b${b}`,}});{const {/*Ωignore_startΩ*/$$_$$/*Ωignore_endΩ*/,foo,} = $$_Parent0.$$slot_def.default;$$_$$;
async () => { { const $$_Parent0C = __sveltets_2_ensureComponent(Parent); const $$_Parent0 = new $$_Parent0C({ target: __sveltets_2_any(), props: { "propA":true,propB,"propC":`val1`,"propD":`val2`,"propE":`a${a}b${b}`,}});{const {/*Ωignore_startΩ*/$$_$$/*Ωignore_endΩ*/,foo,} = $$_Parent0.$$slot_def.default;$$_$$;
{ __sveltets_createSlot("default", { foo,});}
}Parent}};
return { props: {}, slots: {'default': {foo:__sveltets_1_instanceOf(Parent).$$slot_def['default'].foo}}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///<reference types="svelte" />
;function render() {
async () => { { const $$_Component0C = __sveltets_2_ensureComponent(Component); const $$_Component0 = new $$_Component0C({ target: __sveltets_2_any(), props: { "propA":true,propB,"propC":"val1","propD":"val2","propE":`a${a}b${b}`,}});$$_Component0.$on("click", () => {});}};
async () => { { const $$_Component0C = __sveltets_2_ensureComponent(Component); const $$_Component0 = new $$_Component0C({ target: __sveltets_2_any(), props: { "propA":true,propB,"propC":`val1`,"propD":`val2`,"propE":`a${a}b${b}`,}});$$_Component0.$on("click", () => {});}};
return { props: {}, slots: {}, getters: {}, events: {'click':__sveltets_1_bubbleEventDef(__sveltets_1_instanceOf(Component).$$events_def, 'click')} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function render() {


;
async () => { { const $$_Test0C = __sveltets_2_ensureComponent(Test); new $$_Test0C({ target: __sveltets_2_any(), props: { "b":"6",}}); Test}
async () => { { const $$_Test0C = __sveltets_2_ensureComponent(Test); new $$_Test0C({ target: __sveltets_2_any(), props: { "b":`6`,}}); Test}
};
return { props: {}, slots: {}, getters: {}, events: {} }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async () => { { svelteHTML.createElement("div", {});


{ svelteHTML.createElement("sveltehead", {});
{ svelteHTML.createElement("link", { "rel":"stylesheet","href":"/lib/jodit.es2018.min.css",});}
{ svelteHTML.createElement("link", { "rel":`stylesheet`,"href":`/lib/jodit.es2018.min.css`,});}

}};
return { props: {}, slots: {}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function render() {

let a = 'b';
;
async () => { { const $$_Test0C = __sveltets_2_ensureComponent(Test); new $$_Test0C({ target: __sveltets_2_any(), props: { "b":"6",}});}
async () => { { const $$_Test0C = __sveltets_2_ensureComponent(Test); new $$_Test0C({ target: __sveltets_2_any(), props: { "b":`6`,}});}
};
return { props: {}, slots: {}, getters: {}, events: {} }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///<reference types="svelte" />
;function render() {
async () => { { svelteHTML.createElement("iframe", { "src":"",});}
async () => { { svelteHTML.createElement("iframe", { "src":``,});}
};
return { props: {}, slots: {}, getters: {}, events: {} }}

Expand Down