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
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[
{
"range": {
"start": { "line": 13, "character": 11 },
"end": { "line": 13, "character": 16 }
"start": { "line": 14, "character": 11 },
"end": { "line": 14, "character": 16 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String'.",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String | Number'.",
"code": 2345,
"tags": []
},
{
"range": {
"start": { "line": 14, "character": 18 },
"end": { "line": 14, "character": 23 }
"start": { "line": 15, "character": 18 },
"end": { "line": 15, "character": 23 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String'.",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String | Number'.",
"code": 2345,
"tags": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[
{
"range": {
"start": { "line": 13, "character": 11 },
"end": { "line": 13, "character": 16 }
"start": { "line": 14, "character": 11 },
"end": { "line": 14, "character": 16 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String'.",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String | Number'.",
"code": 2345,
"tags": []
},
{
"range": {
"start": { "line": 14, "character": 18 },
"end": { "line": 14, "character": 23 }
"start": { "line": 15, "character": 18 },
"end": { "line": 15, "character": 23 }
},
"severity": 1,
"source": "ts",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String'.",
"message": "Argument of type 'boolean' is not assignable to parameter of type 'String | Number'.",
"code": 2345,
"tags": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!-- ok -->
<div style:right />
<div style:right={right} />
<div style:right={12} />
<div style:right="right" />
<div style:right={`right${right}`} />
<div style:right=right{right} />
Expand Down
20 changes: 12 additions & 8 deletions packages/svelte2tsx/src/htmlxtojsx/nodes/style-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { StyleDirective } from '../../interfaces';
import { buildTemplateString } from '../utils/node-utils';

/**
* style:xx ---> __sveltets_1_ensureType(String, xx);
* style:xx={yy} ---> __sveltets_1_ensureType(String, yy);
* style:xx="yy" ---> __sveltets_1_ensureType(String, "yy");
* style:xx="a{b}" ---> __sveltets_1_ensureType(String, `a${b}`);
* style:xx ---> __sveltets_1_ensureType(String, Number, xx);
* style:xx={yy} ---> __sveltets_1_ensureType(String, Number, yy);
* style:xx="yy" ---> __sveltets_1_ensureType(String, Number, "yy");
* style:xx="a{b}" ---> __sveltets_1_ensureType(String, Number, `a${b}`);
*/
export function handleStyleDirective(str: MagicString, style: StyleDirective): void {
const htmlx = str.original;
if (style.value === true || style.value.length === 0) {
str.overwrite(
style.start,
htmlx.indexOf(':', style.start) + 1,
'{...__sveltets_1_ensureType(String, '
'{...__sveltets_1_ensureType(String, Number, '
);
str.appendLeft(style.end, ')}');
return;
Expand All @@ -25,7 +25,7 @@ export function handleStyleDirective(str: MagicString, style: StyleDirective): v
style,
str,
htmlx,
'{...__sveltets_1_ensureType(String, `',
'{...__sveltets_1_ensureType(String, Number, `',
'`)}',
style.start
);
Expand All @@ -34,15 +34,19 @@ export function handleStyleDirective(str: MagicString, style: StyleDirective): v

const styleVal = style.value[0];
if (styleVal.type === 'Text') {
str.overwrite(style.start, styleVal.start, '{...__sveltets_1_ensureType(String, "');
str.overwrite(style.start, styleVal.start, '{...__sveltets_1_ensureType(String, Number, "');
if (styleVal.end === style.end) {
str.appendLeft(style.end, '")}');
} else {
str.overwrite(styleVal.end, style.end, '")}');
}
} else {
// MustacheTag
str.overwrite(style.start, styleVal.start + 1, '{...__sveltets_1_ensureType(String, ');
str.overwrite(
style.start,
styleVal.start + 1,
'{...__sveltets_1_ensureType(String, Number, '
);
str.overwrite(styleVal.end - 1, style.end, ')}');
}
}
20 changes: 12 additions & 8 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/StyleDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { StyleDirective } from '../../interfaces';
import { Element } from './Element';

/**
* style:xx ---> __sveltets_2_ensureType(String, xx);
* style:xx={yy} ---> __sveltets_2_ensureType(String, yy);
* style:xx="yy" ---> __sveltets_2_ensureType(String, "yy");
* style:xx="a{b}" ---> __sveltets_2_ensureType(String, `a${b}`);
* style:xx ---> __sveltets_2_ensureType(String, Number, xx);
* style:xx={yy} ---> __sveltets_2_ensureType(String, Number, yy);
* style:xx="yy" ---> __sveltets_2_ensureType(String, Number, "yy");
* style:xx="a{b}" ---> __sveltets_2_ensureType(String, Number, `a${b}`);
*/
export function handleStyleDirective(
str: MagicString,
Expand All @@ -16,7 +16,7 @@ export function handleStyleDirective(
const htmlx = str.original;
if (style.value === true || style.value.length === 0) {
element.appendToStartEnd([
'__sveltets_2_ensureType(String, ',
'__sveltets_2_ensureType(String, Number, ',
[htmlx.indexOf(':', style.start) + 1, style.end],
');'
]);
Expand All @@ -40,7 +40,11 @@ export function handleStyleDirective(
str.appendRight(n.start, '$');
}
}
element.appendToStartEnd(['__sveltets_2_ensureType(String, `', [start, end], '`);']);
element.appendToStartEnd([
'__sveltets_2_ensureType(String, Number, `',
[start, end],
'`);'
]);
return;
}

Expand All @@ -50,12 +54,12 @@ export function handleStyleDirective(
? str.original[styleVal.start - 1]
: '"';
element.appendToStartEnd([
`__sveltets_2_ensureType(String, ${quote}`,
`__sveltets_2_ensureType(String, Number, ${quote}`,
[start, end],
`${quote});`
]);
} else {
// MustacheTag
element.appendToStartEnd(['__sveltets_2_ensureType(String, ', [start, end], ');']);
element.appendToStartEnd(['__sveltets_2_ensureType(String, Number, ', [start, end], ');']);
}
}
2 changes: 2 additions & 0 deletions packages/svelte2tsx/svelte-shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ declare function __sveltets_1_ensureAction(actionCall: SvelteActionReturnType):
declare function __sveltets_1_ensureTransition(transitionCall: SvelteTransitionReturnType): {};
declare function __sveltets_1_ensureFunction(expression: (e: Event & { detail?: any }) => unknown ): {};
declare function __sveltets_1_ensureType<T>(type: AConstructorTypeOf<T>, el: T): {};
declare function __sveltets_1_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2): {};
declare function __sveltets_1_createEnsureSlot<Slots = Record<string, Record<string, any>>>(): <K1 extends keyof Slots, K2 extends keyof Slots[K1]>(k1: K1, k2: K2, val: Slots[K1][K2]) => Slots[K1][K2];
declare function __sveltets_1_ensureRightProps<Props>(props: Props): {};
declare function __sveltets_1_cssProp(prop: Record<string, any>): {};
Expand Down Expand Up @@ -253,6 +254,7 @@ type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConf
declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};

declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T): {};
declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2): {};

declare function __sveltets_2_ensureComponent<T extends new (args: {target: any, props?: any}) => Svelte2TsxComponent<any, any, any>>(type: T): T extends never ? Svelte2TsxComponent<any, any, any> : T;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<><div {...__sveltets_1_ensureType(String, shorthand)}>Hello</div>
<div {...__sveltets_1_ensureType(String, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, "string")}>Hello</div>
<div {...__sveltets_1_ensureType(String, "string")}>Hello</div>
<div {...__sveltets_1_ensureType(String, `string${mixed}`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, `string${mixed}`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, `${mixed}string`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, `string${mixed}string`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, `template${literal}`)}>Hello</div>
<><div {...__sveltets_1_ensureType(String, Number, shorthand)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, value)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, "string")}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, "string")}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, `string${mixed}`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, `string${mixed}`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, `${mixed}string`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, `string${mixed}string`)}>Hello</div>
<div {...__sveltets_1_ensureType(String, Number, `template${literal}`)}>Hello</div>

<div {...__sveltets_1_ensureType(String, shorthand)} /></>
<div {...__sveltets_1_ensureType(String, Number, shorthand)} /></>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, shorthand); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, " "); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, " "); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, ` $mixed`); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, ` $mixed`); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, `mixed; `); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, ` $mixed; `); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, `template${literal}`); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, shorthand); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, value); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, " "); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, " "); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, ` $mixed`); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, ` $mixed`); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, `mixed; `); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, ` $mixed; `); }
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, `template${literal}`); }

{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, shorthand);}
{ svelteHTML.createElement("div", { });__sveltets_2_ensureType(String, Number, shorthand);}