diff --git a/packages/language-server/src/plugins/typescript/features/utils.ts b/packages/language-server/src/plugins/typescript/features/utils.ts index d96ba6ab7..1a9a60a8d 100644 --- a/packages/language-server/src/plugins/typescript/features/utils.ts +++ b/packages/language-server/src/plugins/typescript/features/utils.ts @@ -61,10 +61,9 @@ export async function getComponentAtPosition( export function isInGeneratedCode(text: string, start: number, end: number) { const lineStart = text.lastIndexOf('\n', start); const lineEnd = text.indexOf('\n', end); - return ( - text.substring(lineStart, start).includes('/*Ωignore_startΩ*/') && - text.substring(end, lineEnd).includes('/*Ωignore_endΩ*/') - ); + const lastStart = text.substring(lineStart, start).lastIndexOf('/*Ωignore_startΩ*/'); + const lastEnd = text.substring(lineStart, start).lastIndexOf('/*Ωignore_endΩ*/'); + return lastStart > lastEnd && text.substring(end, lineEnd).includes('/*Ωignore_endΩ*/'); } /** diff --git a/packages/language-server/test/plugins/typescript/features/RenameProvider.test.ts b/packages/language-server/test/plugins/typescript/features/RenameProvider.test.ts index 197abb1d8..4b99843dc 100644 --- a/packages/language-server/test/plugins/typescript/features/RenameProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/RenameProvider.test.ts @@ -36,6 +36,8 @@ describe('RenameProvider', () => { const renameDoc5 = await openDoc('rename5.svelte'); const renameDoc6 = await openDoc('rename6.svelte'); const renameDocIgnoreGenerated = await openDoc('rename-ignore-generated.svelte'); + const renameDocSlotEventsImporter = await openDoc('rename-slot-events-importer.svelte'); + const renameDocPropWithSlotEvents = await openDoc('rename-prop-with-slot-events.svelte'); return { provider, renameDoc1, @@ -45,6 +47,8 @@ describe('RenameProvider', () => { renameDoc5, renameDoc6, renameDocIgnoreGenerated, + renameDocSlotEventsImporter, + renameDocPropWithSlotEvents, docManager }; @@ -526,4 +530,61 @@ describe('RenameProvider', () => { } }); }); + + it('rename prop correctly when events/slots present', async () => { + const { provider, renameDocPropWithSlotEvents } = await setup(); + const result = await provider.rename( + renameDocPropWithSlotEvents, + Position.create(3, 15), + 'newName' + ); + + assert.deepStrictEqual(result, { + changes: { + [getUri('rename-prop-with-slot-events.svelte')]: [ + { + newText: 'newName', + range: { + end: { + character: 17, + line: 3 + }, + start: { + character: 13, + line: 3 + } + } + }, + { + newText: 'newName', + range: { + end: { + character: 17, + line: 8 + }, + start: { + character: 13, + line: 8 + } + } + } + ], + [getUri('rename-slot-events-importer.svelte')]: [ + { + newText: 'newName', + range: { + end: { + character: 7, + line: 4 + }, + start: { + character: 3, + line: 4 + } + } + } + ] + } + }); + }); }); diff --git a/packages/language-server/test/plugins/typescript/testfiles/rename/rename-prop-with-slot-events.svelte b/packages/language-server/test/plugins/typescript/testfiles/rename/rename-prop-with-slot-events.svelte new file mode 100644 index 000000000..420a5153c --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/rename/rename-prop-with-slot-events.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/packages/language-server/test/plugins/typescript/testfiles/rename/rename-slot-events-importer.svelte b/packages/language-server/test/plugins/typescript/testfiles/rename/rename-slot-events-importer.svelte new file mode 100644 index 000000000..4825f13f7 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/rename/rename-slot-events-importer.svelte @@ -0,0 +1,5 @@ + + + e} let:aSlot>{aSlot} diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/await.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/await.ts index d3e5a7748..2d65b6320 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/await.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/await.ts @@ -19,7 +19,7 @@ export function handleAwait( let ifCondition = ifScope.getFullCondition(); ifCondition = ifCondition ? surroundWithIgnoreComments(`if(${ifCondition}) {`) : ''; templateScopeManager.awaitEnter(awaitBlock); - const constRedeclares = ifScope.getConstsToRedeclare(); + const constRedeclares = ifScope.getConstDeclaration(); str.overwrite( awaitBlock.start, awaitBlock.expression.start, diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/each.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/each.ts index 174beca87..4293353bf 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/each.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/each.ts @@ -13,7 +13,7 @@ export function handleEach( ): void { // {#each items as item,i (key)} -> // {__sveltets_each(items, (item,i) => (key) && (possible if expression &&) <> - const constRedeclares = ifScope.getConstsToRedeclare(); + const constRedeclares = ifScope.getConstDeclaration(); const prefix = constRedeclares ? `{() => {${constRedeclares}() => ` : ''; str.overwrite(eachBlock.start, eachBlock.expression.start, `${prefix}{__sveltets_each(`); str.overwrite(eachBlock.expression.end, eachBlock.context.start, ', ('); diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts index 522562bbe..c1c639ed9 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts @@ -1,5 +1,5 @@ import MagicString from 'magic-string'; -import { getTypeForComponent, isQuote } from '../utils/node-utils'; +import { getInstanceType, isQuote } from '../utils/node-utils'; import { BaseDirective, BaseNode } from '../../interfaces'; /** @@ -36,7 +36,7 @@ export function handleEventHandler( if (attr.expression) { const on = 'on'; //for handler assignment, we change it to call to our __sveltets_ensureFunction - str.appendRight(attr.start, `{__sveltets_instanceOf(${getTypeForComponent(parent)}).$`); + str.appendRight(attr.start, `{${getInstanceType(parent, str.original)}.$`); const eventNameIndex = htmlx.indexOf(':', attr.start) + 1; str.overwrite(htmlx.indexOf(on, attr.start) + on.length, eventNameIndex, "('"); const eventEnd = htmlx.lastIndexOf('=', attr.expression.start); diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/if-scope.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/if-scope.ts index 9fdd39aa5..f5a5bae56 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/if-scope.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/if-scope.ts @@ -323,13 +323,21 @@ export class IfScope { * in the conditions which would be overwritten by the scope * (because they declare a variable with the same name, therefore shadowing the outer variable). */ - getConstsToRedeclare(): string { - const replacements = this.getNamesToRedeclare() - .map((identifier) => `${this.replacementPrefix + identifier}=${identifier}`) - .join(','); + getConstDeclaration(): string { + const replacements = this.getConstsToRedeclare().join(','); return replacements ? surroundWithIgnoreComments(`const ${replacements};`) : ''; } + /** + * Like `getConstsRedaclarationString`, but only returns a list of redaclaration-string without + * merging the result with `const` and a ignore comments surround. + */ + getConstsToRedeclare(): string[] { + return this.getNamesToRedeclare().map( + (identifier) => `${this.replacementPrefix + identifier}=${identifier}` + ); + } + /** * Returns true if given identifier is referenced in this IfScope or a parent scope. */ @@ -353,7 +361,7 @@ export class IfScope { /** * Contains a list of identifiers which would be overwritten by the child template scope. */ - private getNamesToRedeclare() { + getNamesToRedeclare() { return [...this.scope.value.inits.keys()].filter((init) => { let parent = this.scope.value.parent; while (parent && parent !== this.ownScope) { diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/slot.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/slot.ts index 5f4c5a7e0..5a4a701a5 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/slot.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/slot.ts @@ -1,15 +1,27 @@ import MagicString from 'magic-string'; -import { beforeStart } from '../utils/node-utils'; -import { getSingleSlotDef } from '../../svelte2tsx/nodes/slot'; +import { + beforeStart, + getInstanceType, + getInstanceTypeForDefaultSlot, + PropsShadowedByLet +} from '../utils/node-utils'; import { IfScope } from './if-scope'; import { TemplateScope } from '../nodes/template-scope'; import { BaseNode } from '../../interfaces'; +import { surroundWithIgnoreComments } from '../../utils/ignore'; + +const shadowedPropsSymbol = Symbol('shadowedProps'); + +interface ComponentNode extends BaseNode { + // Not pretty, but it works, and because it's a symbol, estree-walker will ignore it + [shadowedPropsSymbol]?: PropsShadowedByLet[]; +} export function handleSlot( htmlx: string, str: MagicString, slotEl: BaseNode, - component: BaseNode, + component: ComponentNode, slotName: string, ifScope: IfScope, templateScope: TemplateScope @@ -57,12 +69,18 @@ export function handleSlot( return; } - const constRedeclares = ifScope.getConstsToRedeclare(); + const { singleSlotDef, constRedeclares } = getSingleSlotDefAndConstsRedeclaration( + component, + slotName, + str.original, + ifScope, + slotElIsComponent + ); const prefix = constRedeclares ? `() => {${constRedeclares}` : ''; str.appendLeft(slotDefInsertionPoint, `{${prefix}() => { let {`); str.appendRight( slotDefInsertionPoint, - `} = ${getSingleSlotDef(component, slotName)}` + `;${ifScope.addPossibleIfCondition()}<>` + `} = ${singleSlotDef}` + `;${ifScope.addPossibleIfCondition()}<>` ); const closeSlotDefInsertionPoint = slotElIsComponent @@ -70,3 +88,44 @@ export function handleSlot( : slotEl.end; str.appendLeft(closeSlotDefInsertionPoint, `}}${constRedeclares ? '}' : ''}`); } + +function getSingleSlotDefAndConstsRedeclaration( + componentNode: ComponentNode, + slotName: string, + originalStr: string, + ifScope: IfScope, + findAndRedeclareShadowedProps: boolean +) { + if (findAndRedeclareShadowedProps) { + const replacement = 'Ψ'; + const { str, shadowedProps } = getInstanceTypeForDefaultSlot( + componentNode, + originalStr, + replacement + ); + componentNode[shadowedPropsSymbol] = shadowedProps; + return { + singleSlotDef: `${str}.$$slot_def['${slotName}']`, + constRedeclares: getConstsToRedeclare(ifScope, shadowedProps) + }; + } else { + const str = getInstanceType( + componentNode, + originalStr, + componentNode[shadowedPropsSymbol] || [] + ); + return { + singleSlotDef: `${str}.$$slot_def['${slotName}']`, + constRedeclares: ifScope.getConstDeclaration() + }; + } +} + +function getConstsToRedeclare(ifScope: IfScope, shadowedProps: PropsShadowedByLet[]) { + const ifScopeRedeclarations = ifScope.getConstsToRedeclare(); + const letRedeclarations = shadowedProps.map( + ({ value, replacement }) => `${replacement}=${value}` + ); + const replacements = [...ifScopeRedeclarations, ...letRedeclarations].join(','); + return replacements ? surroundWithIgnoreComments(`const ${replacements};`) : ''; +} diff --git a/packages/svelte2tsx/src/htmlxtojsx/utils/node-utils.ts b/packages/svelte2tsx/src/htmlxtojsx/utils/node-utils.ts index b7115f3c1..26751ab3e 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/utils/node-utils.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/utils/node-utils.ts @@ -1,5 +1,6 @@ import { Node, walk } from 'estree-walker'; import { BaseNode } from '../../interfaces'; +import { surroundWithIgnoreComments } from '../../utils/ignore'; export function getTypeForComponent(node: Node): string { if (node.name === 'svelte:component' || node.name === 'svelte:self') { @@ -9,6 +10,146 @@ export function getTypeForComponent(node: Node): string { } } +export function getInstanceType( + node: Node, + originalStr: string, + replacedPropValues: PropsShadowedByLet[] = [] +): string { + if (node.name === 'svelte:component' || node.name === 'svelte:self') { + return '__sveltets_instanceOf(__sveltets_componentType())'; + } + + const propsStr = getNameValuePairsFromAttributes(node, originalStr) + .map(({ name, value }) => { + const replacedPropValue = replacedPropValues.find( + ({ name: propName }) => propName === name + )?.replacement; + return `'${name}':${replacedPropValue || value}`; + }) + .join(', '); + return surroundWithIgnoreComments( + `new ${node.name}({target: __sveltets_any(''), props: {${propsStr}}})` + ); +} + +export interface PropsShadowedByLet { + name: string; + value: string; + replacement: string; +} + +/** + * Return a string which makes it possible for TypeScript to infer the instance type of the given component. + * In the case of another component, this is done by creating a `new Comp({.. props: {..}})` code string. + * Alongside with the result a list of shadowed props is returned. A shadowed prop is a prop + * whose value is either too complex to analyse or contains an identifier which has the same name + * as a `let:X` expression on the component. In that case, the returned string only contains a reference + * to a constant which is `replacedPropsPrefix + propName`, so the calling code needs to make sure + * to create such a `const`. + */ +export function getInstanceTypeForDefaultSlot( + node: Node, + originalStr: string, + replacedPropsPrefix: string +): { str: string; shadowedProps: PropsShadowedByLet[] } { + if (node.name === 'svelte:component' || node.name === 'svelte:self') { + return { + str: '__sveltets_instanceOf(__sveltets_componentType())', + shadowedProps: [] + }; + } + + const lets = new Set( + (node.attributes || []).filter((attr) => attr.type === 'Let').map((attr) => attr.name) + ); + const shadowedProps: PropsShadowedByLet[] = []; + // Go through attribute values and mark those for reassignment to a const that + // either definitely shadow a let: or where it cannot be determined because the value is too complex. + const propsStr = getNameValuePairsFromAttributes(node, originalStr) + .map(({ name, value, identifier, complexExpression }) => { + if (complexExpression || lets.has(identifier)) { + const replacement = replacedPropsPrefix + sanitizePropName(name); + shadowedProps.push({ name, value, replacement }); + return `'${name}':${replacement}`; + } else { + return `'${name}':${value}`; + } + }) + .join(', '); + const str = surroundWithIgnoreComments( + `new ${node.name}({target: __sveltets_any(''), props: {${propsStr}}})` + ); + return { str, shadowedProps }; +} + +function getNameValuePairsFromAttributes( + node: Node, + originalStr: string +): Array<{ + /** + * Attribute name + */ + name: string; + /** + * Attribute value string + */ + value: string; + /** + * If the attribute value's identifier can be determined, it's a string with its name. + * If the attribute value has no identifier or is too complex, it's unset. + */ + identifier?: string; + /** + * If the attribute's value is too complex to determine a specific identifier from it, + * this is true. + */ + complexExpression?: true; +}> { + return ((node.attributes as Node[]) || []) + .filter((attr) => attr.type === 'Attribute') + .map((attr) => { + const name: string = attr.name; + + if (attr.value === true) { + return { name, value: 'true' }; + } + + if (attr.value.length === 1) { + const val = attr.value[0]; + if (val.type === 'AttributeShorthand') { + return { name, value: name, identifier: name }; + } + if (val.type === 'Text') { + // Value not important, just that it's typeof text + return { name, value: '""' }; + } + if (val.type === 'MustacheTag') { + const valueStr = originalStr.substring(val.start + 1, val.end - 1); + if (val.expression.type === 'Identifier') { + return { name, value: valueStr, identifier: valueStr }; + } + if (val.expression.type === 'Literal') { + return { name, value: val.expression.value }; + } + return { name, value: valueStr, complexExpression: true }; + } + } + + // In the case of zero values, the user did attr="", which is the empty string. + // In the case of multiple values, the user did put in a property value + // like a="a{b}c" which is a template literal string. Since we only care + // about the type of the expression in the end, we can simplify this + return { name, value: '""' }; + }); +} + +function sanitizePropName(name: string): string { + return name + .split('') + .map((char) => (/[0-9A-Za-z$_]/.test(char) ? char : '_')) + .join(''); +} + export function getThisType(node: Node): string | undefined { switch (node.type) { case 'InlineComponent': diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/slot.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/slot.ts index 703e8d8ce..4ec1725c8 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/slot.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/slot.ts @@ -256,7 +256,13 @@ export class SlotHandler { } } -export function getSingleSlotDef(componentNode: Node, slotName: string) { +function getSingleSlotDef(componentNode: Node, slotName: string) { + // In contrast to getSingleSlotDef in htmlx2jsx, use a simple instanceOf-transformation here. + // This means that if someone forwards a slot whose type can only be infered from the input properties + // because there's a generic relationship, then that slot type is of type any or unknown. + // This is a limitation which could be tackled later. The problem is that in contrast to the transformation + // in htmlx2jsx, we cannot know for sure that all properties we would generate the component with exist + // in this scope, some could have been generated through each/await blocks or other lets. const componentType = getTypeForComponent(componentNode); return `__sveltets_instanceOf(${componentType}).$$slot_def['${slotName}']`; } diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let-destructure/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let-destructure/expected.jsx index a1e72d66d..9bfd7f8bd 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let-destructure/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let-destructure/expected.jsx @@ -1,3 +1,3 @@ -<>{() => { let {thing:{ a }} = __sveltets_instanceOf(Component).$$slot_def['default'];<> +<>{() => { let {thing:{ a }} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>

Hello { a }

-}}
+}}
\ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let/expected.jsx index cbdfee7ab..284cf030a 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-default-slot-let/expected.jsx @@ -1,3 +1,3 @@ -<>{() => { let {name:n, thing} = __sveltets_instanceOf(Component).$$slot_def['default'];<> +<>{() => { let {name:n, thing} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>

Hello {thing} {n}

-}}
+}}
\ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-multi-slot/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-multi-slot/expected.jsx index 0d0fbe375..39df516ff 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/component-multi-slot/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-multi-slot/expected.jsx @@ -1,11 +1,11 @@ -<>{() => { let {var:new_var} = __sveltets_instanceOf(Component).$$slot_def['default'];<> +<>{() => { let {var:new_var} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>

Hello {new_var}

- {() => { let {slotvar:newvar} = __sveltets_instanceOf(Component).$$slot_def['someslot'];<>
+ {() => { let {slotvar:newvar} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['someslot'];<>

Hi Slot {newvar}

}} - {() => { let {newvar2} = __sveltets_instanceOf(Component).$$slot_def['slotwithoutchildren'];<>
}} - {() => { let {hi1, hi2, hi3:hi3alias} = __sveltets_instanceOf(Component).$$slot_def['slotwithmultiplelets'];<>
}} + {() => { let {newvar2} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['slotwithoutchildren'];<>
}} + {() => { let {hi1, hi2, hi3:hi3alias} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['slotwithmultiplelets'];<>
}}

Test

-}} +}} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-named-slot/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-named-slot/expected.jsx index aa99fcbcd..1d4b3689c 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/component-named-slot/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-named-slot/expected.jsx @@ -1,8 +1,8 @@ -<>{() => { let {foo, bar:baz} = __sveltets_instanceOf(Parent).$$slot_def['default'];<> - {() => { let {bla} = __sveltets_instanceOf(Parent).$$slot_def['named'];<> +<>{() => { let {foo, bar:baz} = /*Ωignore_startΩ*/new Parent({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<> + {() => { let {bla} = /*Ωignore_startΩ*/new Parent({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];<> {foo} {baz} {bla} }} - {() => { let {blubb} = __sveltets_instanceOf(Component).$$slot_def['default'];<> + {() => { let {blubb} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<> {blubb} }} }} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/expected.jsx new file mode 100644 index 000000000..42d72d9ff --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/expected.jsx @@ -0,0 +1,8 @@ +<>{() => {/*Ωignore_startΩ*/const Ψcomplex={a},Ψa_dashed_complex={a};/*Ωignore_endΩ*/() => { let {foo} = /*Ωignore_startΩ*/new Parent({target: __sveltets_any(''), props: {'bare':true, 'shorthand':shorthand, 'text1':"", 'text2':"", 'text3':"", 'textEmpty':"", 'literal':true, 'complex':Ψcomplex, 'a-dashed-complex':Ψa_dashed_complex}})/*Ωignore_endΩ*/.$$slot_def['default'];<> + {() => { let {bar} = /*Ωignore_startΩ*/new Parent({target: __sveltets_any(''), props: {'bare':true, 'shorthand':shorthand, 'text1':"", 'text2':"", 'text3':"", 'textEmpty':"", 'literal':true, 'complex':Ψcomplex, 'a-dashed-complex':Ψa_dashed_complex}})/*Ωignore_endΩ*/.$$slot_def['named'];<> + {foo} {bar} + }} +
+ {foo} +
+}}}
\ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/input.svelte new file mode 100644 index 000000000..310d50fd8 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-infer-props/input.svelte @@ -0,0 +1,8 @@ + + + {foo} {bar} + +
+ {foo} +
+
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/expected.jsx new file mode 100644 index 000000000..6ac65dac9 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/expected.jsx @@ -0,0 +1,19 @@ +<>{() => {/*Ωignore_startΩ*/const Ψsubthing=subthing,Ψshadowed1=shadowed1,Ψshadowed_2=shadowed2,Ψcomplex={complex};/*Ωignore_endΩ*/() => { let {name:n, shadowed1, shadowed2, subthing} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {'unshadowed1':unshadowed1, 'foo':unshadowed2, 'subthing':Ψsubthing, 'shadowed1':Ψshadowed1, 'shadowed-2':Ψshadowed_2, 'templateString':"", 'complex':Ψcomplex}})/*Ωignore_endΩ*/.$$slot_def['default'];<> + {() => { let {subthing} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {'unshadowed1':unshadowed1, 'foo':unshadowed2, 'subthing':Ψsubthing, 'shadowed1':Ψshadowed1, 'shadowed-2':Ψshadowed_2, 'templateString':"", 'complex':Ψcomplex}})/*Ωignore_endΩ*/.$$slot_def['sub1'];<>

{thing}{subthing}

}} + + {() => { let {subthing, othersubthing} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {'unshadowed1':unshadowed1, 'foo':unshadowed2, 'subthing':Ψsubthing, 'shadowed1':Ψshadowed1, 'shadowed-2':Ψshadowed_2, 'templateString':"", 'complex':Ψcomplex}})/*Ωignore_endΩ*/.$$slot_def['sub2'];<>{thing}{subthing}}} + + {() => {/*Ωignore_startΩ*/const Ψsubthing=subthing;/*Ωignore_endΩ*/() => { let {subthing, othersubthing} = /*Ωignore_startΩ*/new Sub({target: __sveltets_any(''), props: {'subthing':Ψsubthing}})/*Ωignore_endΩ*/.$$slot_def['default'];<>{thing}{subthing}}}} +}}}
\ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/input.svelte new file mode 100644 index 000000000..78b2fd0d9 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/component-slot-shadowed-prop/input.svelte @@ -0,0 +1,19 @@ + +

{thing}{subthing}

+ + {thing}{subthing} + + {thing}{subthing} +
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/directive-quoted/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/directive-quoted/expected.jsx index c625af310..e3b7a2856 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/directive-quoted/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/directive-quoted/expected.jsx @@ -1,7 +1,7 @@ <>

console.log("click")}>Hello

-{__sveltets_instanceOf(Component).$on('click', test)} +{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$on('click', test)} - + \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/expected.jsx new file mode 100644 index 000000000..18f05d970 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/expected.jsx @@ -0,0 +1 @@ +<>{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {'bare':true, 'shorthand':shorthand, 'text1':"", 'text2':"", 'text3':"", 'textEmpty':"", 'literal':true, 'complex':{a}, 'a-dashed-complex':{a}}})/*Ωignore_endΩ*/.$on('click', e => e)} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/input.svelte new file mode 100644 index 000000000..e666ae094 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component-infer-props/input.svelte @@ -0,0 +1 @@ + e} /> \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component/expected.jsx index 612aca8dd..681aa8f65 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/event-handler-component/expected.jsx @@ -1 +1 @@ -<>{__sveltets_instanceOf(Component).$on('event', () => click())}{__sveltets_instanceOf(Component).$on('UpperCaseEvent', () => log('hi'))} +<>{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$on('event', () => click())}{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$on('UpperCaseEvent', () => log('hi'))} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/expected.jsx index 65d1fd704..6f8a49c0b 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/expected.jsx @@ -1,28 +1,33 @@ <>{(hello && hello1) ? <> - {() => {/*Ωignore_startΩ*/const Ωhello=hello;/*Ωignore_endΩ*/() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> + {() => {/*Ωignore_startΩ*/const Ωhello=hello;/*Ωignore_endΩ*/() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> {hello} - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> + {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> {(hello) ? <> {hello} : <>} }} - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['named1'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> + {() => {/*Ωignore_startΩ*/const Ψhello=hello;/*Ωignore_endΩ*/() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {'hello':Ψhello}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> + {(hello) ? <> + {hello} + : <>} + }}} + {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named1'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> {(hello) ? <> {hello} : <>} }} - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['named2'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<>

+ {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named2'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<>

{(hello) ? <> {hello} : <>}

}} - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['named3'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> + {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named3'];/*Ωignore_startΩ*/((Ωhello && hello1)) && /*Ωignore_endΩ*/<> {(hello) ? <> {hello} : <>} }} {(hello) ? <> - {() => {/*Ωignore_startΩ*/const ΩΩhello=hello;/*Ωignore_endΩ*/() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && ((ΩΩhello)) && /*Ωignore_endΩ*/<> + {() => {/*Ωignore_startΩ*/const ΩΩhello=hello;/*Ωignore_endΩ*/() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && ((ΩΩhello)) && /*Ωignore_endΩ*/<> {(hello) ? <> {hello} : <>} @@ -30,25 +35,25 @@ : <>} }}} {(hi && bye) ? <> - {() => {/*Ωignore_startΩ*/const Ωbye=bye;/*Ωignore_endΩ*/() => { let {foo:bye} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/(((hello && hello1))) && ((hi && Ωbye)) && /*Ωignore_endΩ*/<> + {() => {/*Ωignore_startΩ*/const Ωbye=bye;/*Ωignore_endΩ*/() => { let {foo:bye} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/(((hello && hello1))) && ((hi && Ωbye)) && /*Ωignore_endΩ*/<> {bye} }}} : (cool) ? <> - {() => {/*Ωignore_startΩ*/const Ωcool=cool,Ωhello=hello;/*Ωignore_endΩ*/() => { let {cool, hello} = __sveltets_instanceOf(Comp).$$slot_def['named'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && (!(hi && bye) && (Ωcool)) && /*Ωignore_endΩ*/<>
+ {() => {/*Ωignore_startΩ*/const Ωcool=cool,Ωhello=hello;/*Ωignore_endΩ*/() => { let {cool, hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && (!(hi && bye) && (Ωcool)) && /*Ωignore_endΩ*/<>
{hello}
}}} : <> - {() => {/*Ωignore_startΩ*/const Ωhello=hello;/*Ωignore_endΩ*/() => { let {foo:hello, hello1:other} = __sveltets_instanceOf(Comp).$$slot_def['named'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && (!(hi && bye) && !(cool)) && /*Ωignore_endΩ*/<>
+ {() => {/*Ωignore_startΩ*/const Ωhello=hello;/*Ωignore_endΩ*/() => { let {foo:hello, hello1:other} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];/*Ωignore_startΩ*/(((Ωhello && hello1))) && (!(hi && bye) && !(cool)) && /*Ωignore_endΩ*/<>
{hello}
}}} } : <>} -{() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['default'];<> +{() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<> {(hello && bye) ? <> {hello} {bye} : (hello && bye) ? <> @@ -56,7 +61,7 @@ : <> {hello} {bye} } - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['named1'];<> + {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named1'];<> {(hello && bye) ? <> {hello} {bye} : (hello && bye) ? <> @@ -65,7 +70,7 @@ {hello} {bye} } }} - {() => { let {hello} = __sveltets_instanceOf(Comp).$$slot_def['named2'];<>

+ {() => { let {hello} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named2'];<>

{(hello && bye) ? <> {hello} {bye} : (hello && bye) ? <> diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/input.svelte index 6d3489916..91324de96 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/input.svelte +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let-shadowed/input.svelte @@ -6,6 +6,11 @@ {hello} {/if} + + {#if hello} + {hello} + {/if} + {#if hello} {hello} diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let/expected.jsx index 768079481..969bda7ee 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/if-nested-slot-let/expected.jsx @@ -1,20 +1,20 @@ <>{(hello) ? <> - {() => { let {foo} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/((hello)) && /*Ωignore_endΩ*/<> + {() => { let {foo} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/((hello)) && /*Ωignore_endΩ*/<> {foo} }} {(hi && bye) ? <> - {() => { let {foo:bar} = __sveltets_instanceOf(Comp).$$slot_def['default'];/*Ωignore_startΩ*/(((hello))) && ((hi && bye)) && /*Ωignore_endΩ*/<> + {() => { let {foo:bar} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];/*Ωignore_startΩ*/(((hello))) && ((hi && bye)) && /*Ωignore_endΩ*/<> {bar} }} : (cool) ? <> - {() => { let {foo, foo1} = __sveltets_instanceOf(Comp).$$slot_def['named'];/*Ωignore_startΩ*/(((hello))) && (!(hi && bye) && (cool)) && /*Ωignore_endΩ*/<>

+ {() => { let {foo, foo1} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];/*Ωignore_startΩ*/(((hello))) && (!(hi && bye) && (cool)) && /*Ωignore_endΩ*/<>
{foo}
}} : <> - {() => { let {foo:bar} = __sveltets_instanceOf(Comp).$$slot_def['named'];/*Ωignore_startΩ*/(((hello))) && (!(hi && bye) && !(cool)) && /*Ωignore_endΩ*/<>
+ {() => { let {foo:bar} = /*Ωignore_startΩ*/new Comp({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];/*Ωignore_startΩ*/(((hello))) && (!(hi && bye) && !(cool)) && /*Ωignore_endΩ*/<>
{bar}
}} diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/svelte-fragment/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/svelte-fragment/expected.jsx index 564e2275a..9d010904e 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/svelte-fragment/expected.jsx +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/svelte-fragment/expected.jsx @@ -9,11 +9,11 @@ - {() => { let {foo, bar:baz} = __sveltets_instanceOf(Component).$$slot_def['default'];<> + {() => { let {foo, bar:baz} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>

{foo} {baz}

}} - {() => { let {foo, bar:baz} = __sveltets_instanceOf(Component).$$slot_def['named'];<> + {() => { let {foo, bar:baz} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['named'];<>

{foo} {baz}

}}
\ No newline at end of file diff --git a/packages/svelte2tsx/test/sourcemaps/samples/event-binding/mappings.jsx b/packages/svelte2tsx/test/sourcemaps/samples/event-binding/mappings.jsx index d80333621..1b608056b 100644 --- a/packages/svelte2tsx/test/sourcemaps/samples/event-binding/mappings.jsx +++ b/packages/svelte2tsx/test/sourcemaps/samples/event-binding/mappings.jsx @@ -1,13 +1,13 @@ /// <>;function render() { {/** ------------------------------------------------------------------------------------------------------------------------------------------------------ */} -<>{__sveltets_instanceOf(Component).$on('click', (__sveltets_store_get(check), $check) ? method1 : method2)} {/** -=# Originless mappings -<>{__sveltets_instanceOf(Component).$on('click',•(__sveltets_store_get(check),•$check)•?•method1•:•method2)}↲ [generated] line 3 - on: click= $ check •?•method1•:•method2} ↲ - #=================================== Order-breaking mappings -↲ -↲ [original] line 1 +<>{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$on('click', (__sveltets_store_get(check), $check) ? method1 : method2)}{/** +=# Originless mappings +<>{/*Ωignore_startΩ*/new•Component({target:•__sveltets_any(''),•props:•{}})/*Ωignore_endΩ*/.$on('click',•(__sveltets_store_get(check),•$check)•?•method1•:•method2)}↲ [generated] line 3 + on: click= $ check •?•method1•:•method2} ↲ + #=========================================================================================== Order-breaking mappings +↲ +↲ [original] line 1 ------------------------------------------------------------------------------------------------------------------------------------------------------ */} {/** Bla↲ [generated] line 4 diff --git a/packages/svelte2tsx/test/sourcemaps/samples/large-sample-1/mappings.jsx b/packages/svelte2tsx/test/sourcemaps/samples/large-sample-1/mappings.jsx index a2d169664..fa50c433c 100644 --- a/packages/svelte2tsx/test/sourcemaps/samples/large-sample-1/mappings.jsx +++ b/packages/svelte2tsx/test/sourcemaps/samples/large-sample-1/mappings.jsx @@ -430,17 +430,17 @@ s injectedJS={mapbox_setup} relaxed {/** ------------------------------------------------------------------------------------------------------------------------------------------------------ */} - />{__sveltets_instanceOf(Repl).$on('change', handle_change)} {/** - ╚╚╚/>{__sveltets_instanceOf(Repl).$on('change',•handle_change)}↲ [generated] line 172 - on('change',•handle_change)} [generated] subset - on: change= handle_change} - on:change= handle_change} - ╚╚╚╚on:change={handle_change}↲ [original] line 309 (rest generated at line 169) - - ╚╚╚/>{__sveltets_instanceOf(Repl).$on('change',•handle_change)}↲ [generated] line 172 - ╚╚╚/>{__sveltets_instanceOf(Repl).$ ↲ [generated] subset - ╚╚╚/> ↲ - ╚╚╚/>↲ [original] line 312 + />{/*Ωignore_startΩ*/new Repl({target: __sveltets_any(''), props: {'workersUrl':"", 'svelteUrl':svelteUrl, 'rollupUrl':rollupUrl, 'orientation':mobile ? 'columns' : 'rows', 'fixed':mobile, 'injectedJS':mapbox_setup, 'relaxed':true}})/*Ωignore_endΩ*/.$on('change', handle_change)}{/** + ╚╚╚/>{/*Ωignore_startΩ*/new•Repl({target:•__sveltets_any(''),•props:•{'workersUrl':"",•'svelteUrl':svelteUrl,•'rollupUrl':rollupUrl,•'orientation':mobile•?•'columns'•:•'rows',•'fixed':mobile,•'injectedJS':mapbox_setup,•'relaxed':true}})/*Ωignore_endΩ*/.$on('change',•handle_change)}↲ [generated] line 172 + on('change',•handle_change)} [generated] subset + on: change= handle_change} + on:change= handle_change} + ╚╚╚╚on:change={handle_change}↲ [original] line 309 (rest generated at line 169) + + ╚╚╚/>{/*Ωignore_startΩ*/new•Repl({target:•__sveltets_any(''),•props:•{'workersUrl':"",•'svelteUrl':svelteUrl,•'rollupUrl':rollupUrl,•'orientation':mobile•?•'columns'•:•'rows',•'fixed':mobile,•'injectedJS':mapbox_setup,•'relaxed':true}})/*Ωignore_endΩ*/.$on('change',•handle_change)}↲ [generated] line 172 + ╚╚╚/>{/*Ωignore_startΩ*/new•Repl({target:•__sveltets_any(''),•props:•{'workersUrl':"",•'svelteUrl':svelteUrl,•'rollupUrl':rollupUrl,•'orientation':mobile•?•'columns'•:•'rows',•'fixed':mobile,•'injectedJS':mapbox_setup,•'relaxed':true}})/*Ωignore_endΩ*/.$ ↲ [generated] subset + ╚╚╚/> ↲ + ╚╚╚/>↲ [original] line 312 ------------------------------------------------------------------------------------------------------------------------------------------------------ */}
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/expected.tsx new file mode 100644 index 000000000..68d41f4bf --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/expected.tsx @@ -0,0 +1,9 @@ +/// +<>;function render() { +<>{() => { let {foo} = /*Ωignore_startΩ*/new Parent({target: __sveltets_any(''), props: {'propA':true, 'propB':propB, 'propC':"", 'propD':"", 'propE':""}})/*Ωignore_endΩ*/.$$slot_def['default'];<> + +}} +return { props: {}, slots: {'default': {foo:__sveltets_instanceOf(Parent).$$slot_def['default'].foo}}, getters: {}, events: {} }} + +export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/input.svelte new file mode 100644 index 000000000..9fe23d2ab --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-forward-with-props/input.svelte @@ -0,0 +1,3 @@ + + + diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward-named-slot/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward-named-slot/expected.tsx index 5eed7c7de..7c6613577 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward-named-slot/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward-named-slot/expected.tsx @@ -1,7 +1,7 @@ /// <>;function render() { <> - {() => { let {a} = __sveltets_instanceOf(Component).$$slot_def['b'];<>
+ {() => { let {a} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['b'];<>
}} diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward/expected.tsx index 1f9f773d8..f18e90ffc 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-let-forward/expected.tsx @@ -1,6 +1,6 @@ /// <>;function render() { -<>{() => { let {name:n, thing, whatever:{ bla }} = __sveltets_instanceOf(Component).$$slot_def['default'];<> +<>{() => { let {name:n, thing, whatever:{ bla }} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<> }} return { props: {}, slots: {'default': {n:__sveltets_instanceOf(Component).$$slot_def['default'].name, thing:__sveltets_instanceOf(Component).$$slot_def['default'].thing, bla:(({ bla }) => bla)(__sveltets_instanceOf(Component).$$slot_def['default'].whatever)}}, getters: {}, events: {} }} diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-nest-scope/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-nest-scope/expected.tsx index 6e13676a0..a6b5bc712 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-nest-scope/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-nest-scope/expected.tsx @@ -6,7 +6,7 @@ )} )} -{() => { let {c} = __sveltets_instanceOf(Component).$$slot_def['default'];<>{ c }}} +{() => { let {c} = /*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>{ c }}} {() => {let _$$p = (promise); __sveltets_awaitThen(_$$p, (d) => {<> {d} })}} diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-no-space/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-no-space/expected.tsx index 92da42fa5..593560273 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-no-space/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-slot-no-space/expected.tsx @@ -7,7 +7,7 @@ function render() { ; () => (<> -
{() => { let {t} = __sveltets_instanceOf(Test).$$slot_def['default'];<>xx}}
); +
{() => { let {t} = /*Ωignore_startΩ*/new Test({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$$slot_def['default'];<>xx}}
); return { props: {}, slots: {}, getters: {}, events: {} }} export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/expected.tsx new file mode 100644 index 000000000..49fe8468d --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/expected.tsx @@ -0,0 +1,7 @@ +/// +<>;function render() { +<> +return { props: {}, slots: {}, getters: {}, events: {'click':__sveltets_bubbleEventDef(__sveltets_instanceOf(Component).$$events_def, 'click')} }} + +export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/input.svelte new file mode 100644 index 000000000..002e494d7 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/event-bubble-component-with-props/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-in-event-binding/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-in-event-binding/expected.tsx index bdb3fb921..cd5dec7b4 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-in-event-binding/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-$store-in-event-binding/expected.tsx @@ -1,6 +1,6 @@ /// <>;function render() { -<>{__sveltets_instanceOf(Component).$on('click', (__sveltets_store_get(check), $check) ? method1 : method2)} +<>{/*Ωignore_startΩ*/new Component({target: __sveltets_any(''), props: {}})/*Ωignore_endΩ*/.$on('click', (__sveltets_store_get(check), $check) ? method1 : method2)} return { props: {}, slots: {}, getters: {}, events: {} }}