svelte2tsx 0.4.12 → 0.4.13
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 +45 -7
- package/index.mjs +45 -7
- package/package.json +1 -1
- package/svelte-jsx.d.ts +5 -12
package/index.js
CHANGED
|
@@ -4151,6 +4151,12 @@ class SlotHandler {
|
|
|
4151
4151
|
}
|
|
4152
4152
|
return resolved;
|
|
4153
4153
|
}
|
|
4154
|
+
/**
|
|
4155
|
+
* Returns a string which expresses the given identifier unpacked to
|
|
4156
|
+
* the top level in order to express the slot types correctly later on.
|
|
4157
|
+
*
|
|
4158
|
+
* Example: {#each items as item} ---> __sveltets_1_unwrapArr(items)
|
|
4159
|
+
*/
|
|
4154
4160
|
getResolveExpressionStr(identifierDef, scope, initExpression) {
|
|
4155
4161
|
const { name } = identifierDef;
|
|
4156
4162
|
const owner = scope.getOwner(name);
|
|
@@ -4219,6 +4225,10 @@ class SlotHandler {
|
|
|
4219
4225
|
slotName
|
|
4220
4226
|
}));
|
|
4221
4227
|
}
|
|
4228
|
+
/**
|
|
4229
|
+
* Resolves the slot expression to a string that can be used
|
|
4230
|
+
* in the props-object in the return type of the render function
|
|
4231
|
+
*/
|
|
4222
4232
|
resolveExpression(expression, scope) {
|
|
4223
4233
|
let resolved = this.resolvedExpression.get(expression);
|
|
4224
4234
|
if (resolved) {
|
|
@@ -4279,6 +4289,12 @@ class SlotHandler {
|
|
|
4279
4289
|
if (attr.name == 'name') {
|
|
4280
4290
|
continue;
|
|
4281
4291
|
}
|
|
4292
|
+
if (attr.type === 'Spread') {
|
|
4293
|
+
const rawName = attr.expression.name;
|
|
4294
|
+
const init = scope.getInit(rawName);
|
|
4295
|
+
const name = init ? this.resolved.get(init) : rawName;
|
|
4296
|
+
attributes.set(`__spread__${name}`, name);
|
|
4297
|
+
}
|
|
4282
4298
|
if (!((_a = attr.value) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
4283
4299
|
continue;
|
|
4284
4300
|
}
|
|
@@ -4714,6 +4730,25 @@ class Generics {
|
|
|
4714
4730
|
}
|
|
4715
4731
|
}
|
|
4716
4732
|
|
|
4733
|
+
/**
|
|
4734
|
+
* move imports to top of script so they appear outside our render function
|
|
4735
|
+
*/
|
|
4736
|
+
function handleImportDeclaration(node, str, astOffset, scriptStart) {
|
|
4737
|
+
var _a;
|
|
4738
|
+
const comments = (_a = ts__default['default'].getLeadingCommentRanges(node.getFullText(), 0)) !== null && _a !== void 0 ? _a : [];
|
|
4739
|
+
for (const comment of comments) {
|
|
4740
|
+
const commentEnd = node.pos + comment.end + astOffset;
|
|
4741
|
+
str.move(node.pos + comment.pos + astOffset, commentEnd, scriptStart + 1);
|
|
4742
|
+
if (comment.hasTrailingNewLine) {
|
|
4743
|
+
str.overwrite(commentEnd - 1, commentEnd, str.original[commentEnd - 1] + '\n');
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
str.move(node.getStart() + astOffset, node.end + astOffset, scriptStart + 1);
|
|
4747
|
+
//add in a \n
|
|
4748
|
+
const originalEndChar = str.original[node.end + astOffset - 1];
|
|
4749
|
+
str.overwrite(node.end + astOffset - 1, node.end + astOffset, originalEndChar + '\n');
|
|
4750
|
+
}
|
|
4751
|
+
|
|
4717
4752
|
function processInstanceScriptContent(str, script, events, implicitStoreValues, mode) {
|
|
4718
4753
|
const htmlx = str.original;
|
|
4719
4754
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
@@ -4813,7 +4848,12 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
4813
4848
|
// - in order to get ts errors if store is not assignable to SvelteStore
|
|
4814
4849
|
// - use $store variable defined above to get ts flow control
|
|
4815
4850
|
const dollar = str.original.indexOf('$', ident.getStart() + astOffset);
|
|
4816
|
-
const getPrefix = isSafeToPrefixWithSemicolon(ident)
|
|
4851
|
+
const getPrefix = isSafeToPrefixWithSemicolon(ident)
|
|
4852
|
+
? ';'
|
|
4853
|
+
: ts__namespace.isShorthandPropertyAssignment(parent)
|
|
4854
|
+
? // { $store } --> { $store: __sveltets_1_store_get(..)}
|
|
4855
|
+
ident.text + ': '
|
|
4856
|
+
: '';
|
|
4817
4857
|
str.overwrite(dollar, dollar + 1, getPrefix + '(__sveltets_1_store_get(');
|
|
4818
4858
|
str.prependLeft(ident.end + astOffset, `), $${storename})`);
|
|
4819
4859
|
};
|
|
@@ -4909,11 +4949,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
4909
4949
|
exportedNames.handleExportDeclaration(node);
|
|
4910
4950
|
}
|
|
4911
4951
|
if (ts__namespace.isImportDeclaration(node)) {
|
|
4912
|
-
|
|
4913
|
-
str.move(node.getStart() + astOffset, node.end + astOffset, script.start + 1);
|
|
4914
|
-
//add in a \n
|
|
4915
|
-
const originalEndChar = str.original[node.end + astOffset - 1];
|
|
4916
|
-
str.overwrite(node.end + astOffset - 1, node.end + astOffset, originalEndChar + '\n');
|
|
4952
|
+
handleImportDeclaration(node, str, astOffset, script.start);
|
|
4917
4953
|
// Check if import is the event dispatcher
|
|
4918
4954
|
events.checkIfImportIsEventDispatcher(node);
|
|
4919
4955
|
}
|
|
@@ -5261,7 +5297,9 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
|
|
|
5261
5297
|
Array.from(slots.entries())
|
|
5262
5298
|
.map(([name, attrs]) => {
|
|
5263
5299
|
const attrsAsString = Array.from(attrs.entries())
|
|
5264
|
-
.map(([exportName, expr]) =>
|
|
5300
|
+
.map(([exportName, expr]) => exportName.startsWith('__spread__')
|
|
5301
|
+
? `...${expr}`
|
|
5302
|
+
: `${exportName}:${expr}`)
|
|
5265
5303
|
.join(', ');
|
|
5266
5304
|
return `'${name}': {${attrsAsString}}`;
|
|
5267
5305
|
})
|
package/index.mjs
CHANGED
|
@@ -4121,6 +4121,12 @@ class SlotHandler {
|
|
|
4121
4121
|
}
|
|
4122
4122
|
return resolved;
|
|
4123
4123
|
}
|
|
4124
|
+
/**
|
|
4125
|
+
* Returns a string which expresses the given identifier unpacked to
|
|
4126
|
+
* the top level in order to express the slot types correctly later on.
|
|
4127
|
+
*
|
|
4128
|
+
* Example: {#each items as item} ---> __sveltets_1_unwrapArr(items)
|
|
4129
|
+
*/
|
|
4124
4130
|
getResolveExpressionStr(identifierDef, scope, initExpression) {
|
|
4125
4131
|
const { name } = identifierDef;
|
|
4126
4132
|
const owner = scope.getOwner(name);
|
|
@@ -4189,6 +4195,10 @@ class SlotHandler {
|
|
|
4189
4195
|
slotName
|
|
4190
4196
|
}));
|
|
4191
4197
|
}
|
|
4198
|
+
/**
|
|
4199
|
+
* Resolves the slot expression to a string that can be used
|
|
4200
|
+
* in the props-object in the return type of the render function
|
|
4201
|
+
*/
|
|
4192
4202
|
resolveExpression(expression, scope) {
|
|
4193
4203
|
let resolved = this.resolvedExpression.get(expression);
|
|
4194
4204
|
if (resolved) {
|
|
@@ -4249,6 +4259,12 @@ class SlotHandler {
|
|
|
4249
4259
|
if (attr.name == 'name') {
|
|
4250
4260
|
continue;
|
|
4251
4261
|
}
|
|
4262
|
+
if (attr.type === 'Spread') {
|
|
4263
|
+
const rawName = attr.expression.name;
|
|
4264
|
+
const init = scope.getInit(rawName);
|
|
4265
|
+
const name = init ? this.resolved.get(init) : rawName;
|
|
4266
|
+
attributes.set(`__spread__${name}`, name);
|
|
4267
|
+
}
|
|
4252
4268
|
if (!((_a = attr.value) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
4253
4269
|
continue;
|
|
4254
4270
|
}
|
|
@@ -4684,6 +4700,25 @@ class Generics {
|
|
|
4684
4700
|
}
|
|
4685
4701
|
}
|
|
4686
4702
|
|
|
4703
|
+
/**
|
|
4704
|
+
* move imports to top of script so they appear outside our render function
|
|
4705
|
+
*/
|
|
4706
|
+
function handleImportDeclaration(node, str, astOffset, scriptStart) {
|
|
4707
|
+
var _a;
|
|
4708
|
+
const comments = (_a = ts__default.getLeadingCommentRanges(node.getFullText(), 0)) !== null && _a !== void 0 ? _a : [];
|
|
4709
|
+
for (const comment of comments) {
|
|
4710
|
+
const commentEnd = node.pos + comment.end + astOffset;
|
|
4711
|
+
str.move(node.pos + comment.pos + astOffset, commentEnd, scriptStart + 1);
|
|
4712
|
+
if (comment.hasTrailingNewLine) {
|
|
4713
|
+
str.overwrite(commentEnd - 1, commentEnd, str.original[commentEnd - 1] + '\n');
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
str.move(node.getStart() + astOffset, node.end + astOffset, scriptStart + 1);
|
|
4717
|
+
//add in a \n
|
|
4718
|
+
const originalEndChar = str.original[node.end + astOffset - 1];
|
|
4719
|
+
str.overwrite(node.end + astOffset - 1, node.end + astOffset, originalEndChar + '\n');
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4687
4722
|
function processInstanceScriptContent(str, script, events, implicitStoreValues, mode) {
|
|
4688
4723
|
const htmlx = str.original;
|
|
4689
4724
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
@@ -4783,7 +4818,12 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
4783
4818
|
// - in order to get ts errors if store is not assignable to SvelteStore
|
|
4784
4819
|
// - use $store variable defined above to get ts flow control
|
|
4785
4820
|
const dollar = str.original.indexOf('$', ident.getStart() + astOffset);
|
|
4786
|
-
const getPrefix = isSafeToPrefixWithSemicolon(ident)
|
|
4821
|
+
const getPrefix = isSafeToPrefixWithSemicolon(ident)
|
|
4822
|
+
? ';'
|
|
4823
|
+
: ts.isShorthandPropertyAssignment(parent)
|
|
4824
|
+
? // { $store } --> { $store: __sveltets_1_store_get(..)}
|
|
4825
|
+
ident.text + ': '
|
|
4826
|
+
: '';
|
|
4787
4827
|
str.overwrite(dollar, dollar + 1, getPrefix + '(__sveltets_1_store_get(');
|
|
4788
4828
|
str.prependLeft(ident.end + astOffset, `), $${storename})`);
|
|
4789
4829
|
};
|
|
@@ -4879,11 +4919,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
4879
4919
|
exportedNames.handleExportDeclaration(node);
|
|
4880
4920
|
}
|
|
4881
4921
|
if (ts.isImportDeclaration(node)) {
|
|
4882
|
-
|
|
4883
|
-
str.move(node.getStart() + astOffset, node.end + astOffset, script.start + 1);
|
|
4884
|
-
//add in a \n
|
|
4885
|
-
const originalEndChar = str.original[node.end + astOffset - 1];
|
|
4886
|
-
str.overwrite(node.end + astOffset - 1, node.end + astOffset, originalEndChar + '\n');
|
|
4922
|
+
handleImportDeclaration(node, str, astOffset, script.start);
|
|
4887
4923
|
// Check if import is the event dispatcher
|
|
4888
4924
|
events.checkIfImportIsEventDispatcher(node);
|
|
4889
4925
|
}
|
|
@@ -5231,7 +5267,9 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
|
|
|
5231
5267
|
Array.from(slots.entries())
|
|
5232
5268
|
.map(([name, attrs]) => {
|
|
5233
5269
|
const attrsAsString = Array.from(attrs.entries())
|
|
5234
|
-
.map(([exportName, expr]) =>
|
|
5270
|
+
.map(([exportName, expr]) => exportName.startsWith('__spread__')
|
|
5271
|
+
? `...${expr}`
|
|
5272
|
+
: `${exportName}:${expr}`)
|
|
5235
5273
|
.join(', ');
|
|
5236
5274
|
return `'${name}': {${attrsAsString}}`;
|
|
5237
5275
|
})
|
package/package.json
CHANGED
package/svelte-jsx.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ declare namespace svelte.JSX {
|
|
|
100
100
|
onchange?: FormEventHandler<T> | undefined | null;
|
|
101
101
|
oninput?: FormEventHandler<T> | undefined | null;
|
|
102
102
|
onreset?: FormEventHandler<T> | undefined | null;
|
|
103
|
-
onsubmit?:
|
|
103
|
+
onsubmit?: EventHandler<SubmitEvent, T> | undefined | null;
|
|
104
104
|
oninvalid?: EventHandler<Event, T> | undefined | null;
|
|
105
105
|
onbeforeinput?: EventHandler<InputEvent, T> | undefined | null;
|
|
106
106
|
|
|
@@ -557,7 +557,7 @@ declare namespace svelte.JSX {
|
|
|
557
557
|
title?: string | undefined | null;
|
|
558
558
|
type?: string | undefined | null;
|
|
559
559
|
usemap?: string | undefined | null;
|
|
560
|
-
value?:
|
|
560
|
+
value?: any | undefined | null;
|
|
561
561
|
/**
|
|
562
562
|
* a value between 0 and 1
|
|
563
563
|
*/
|
|
@@ -581,6 +581,7 @@ declare namespace svelte.JSX {
|
|
|
581
581
|
autocorrect?: string | undefined | null;
|
|
582
582
|
autosave?: string | undefined | null;
|
|
583
583
|
color?: string | undefined | null;
|
|
584
|
+
controlslist?: 'nodownload' | 'nofullscreen' | 'noplaybackrate' | 'noremoteplayback';
|
|
584
585
|
itemprop?: string | undefined | null;
|
|
585
586
|
itemscope?: boolean | undefined | null;
|
|
586
587
|
itemtype?: string | undefined | null;
|
|
@@ -873,14 +874,6 @@ declare namespace svelte.JSX {
|
|
|
873
874
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
874
875
|
interface SVGProps<T extends EventTarget> extends SVGAttributes<T> {}
|
|
875
876
|
|
|
876
|
-
interface SvelteOptionProps extends HTMLProps<HTMLOptionElement> {
|
|
877
|
-
value?: any | undefined | null;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
interface SvelteSelectProps extends HTMLProps<HTMLSelectElement> {
|
|
881
|
-
value?: any | undefined | null;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
877
|
interface SvelteInputProps extends HTMLProps<HTMLInputElement> {
|
|
885
878
|
group?: any | undefined | null;
|
|
886
879
|
files?: FileList | undefined | null;
|
|
@@ -1052,7 +1045,7 @@ declare namespace svelte.JSX {
|
|
|
1052
1045
|
object: HTMLProps<HTMLObjectElement>;
|
|
1053
1046
|
ol: HTMLProps<HTMLOListElement>;
|
|
1054
1047
|
optgroup: HTMLProps<HTMLOptGroupElement>;
|
|
1055
|
-
option:
|
|
1048
|
+
option: HTMLProps<HTMLOptionElement>;
|
|
1056
1049
|
output: HTMLProps<HTMLElement>;
|
|
1057
1050
|
p: HTMLProps<HTMLParagraphElement>;
|
|
1058
1051
|
param: HTMLProps<HTMLParamElement>;
|
|
@@ -1067,7 +1060,7 @@ declare namespace svelte.JSX {
|
|
|
1067
1060
|
samp: HTMLProps<HTMLElement>;
|
|
1068
1061
|
script: HTMLProps<HTMLElement>;
|
|
1069
1062
|
section: HTMLProps<HTMLElement>;
|
|
1070
|
-
select:
|
|
1063
|
+
select: HTMLProps<HTMLSelectElement>;
|
|
1071
1064
|
small: HTMLProps<HTMLElement>;
|
|
1072
1065
|
source: HTMLProps<HTMLSourceElement>;
|
|
1073
1066
|
span: HTMLProps<HTMLSpanElement>;
|