Skip to content

Commit fa2f8b1

Browse files
committed
fix broken test
1 parent b787916 commit fa2f8b1

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
"import": "./store/index.mjs",
5252
"require": "./store/index.js"
5353
},
54+
"./slot": {
55+
"import": "./slot/index.mjs",
56+
"require": "./slot/index.js"
57+
},
5458
"./transition": {
5559
"import": "./transition/index.mjs",
5660
"require": "./transition/index.js"
@@ -129,7 +133,7 @@
129133
"source-map-support": "^0.5.13",
130134
"tiny-glob": "^0.2.6",
131135
"tslib": "^1.10.0",
132-
"typescript": "^3.5.3"
136+
"typescript": "^4.0.0"
133137
},
134138
"nyc": {
135139
"include": [

src/runtime/internal/Component.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ interface Fragment {
2121
}
2222
interface T$$ {
2323
dirty: number[];
24-
ctx: null|any;
24+
ctx?: any;
2525
bound: any;
2626
update: () => void;
27-
callbacks: any;
27+
callbacks: Record<string, CallableFunction[]>;
2828
after_update: any[];
2929
props: Record<string, 0 | string>;
3030
fragment: null|false|Fragment;
@@ -36,7 +36,7 @@ interface T$$ {
3636
skip_bound: boolean;
3737
}
3838

39-
export function bind(component, name, callback) {
39+
export function bind(component: SvelteComponent, name, callback) {
4040
const index = component.$$.props[name];
4141
if (index !== undefined) {
4242
component.$$.bound[index] = callback;
@@ -52,7 +52,7 @@ export function claim_component(block, parent_nodes) {
5252
block && block.l(parent_nodes);
5353
}
5454

55-
export function mount_component(component, target, anchor) {
55+
export function mount_component(component: SvelteComponent, target, anchor) {
5656
const { fragment, on_mount, on_destroy, after_update } = component.$$;
5757

5858
fragment && fragment.m(target, anchor);
@@ -73,7 +73,7 @@ export function mount_component(component, target, anchor) {
7373
after_update.forEach(add_render_callback);
7474
}
7575

76-
export function destroy_component(component, detaching) {
76+
export function destroy_component(component: SvelteComponent, detaching) {
7777
const $$ = component.$$;
7878
if ($$.fragment !== null) {
7979
run_all($$.on_destroy);
@@ -87,7 +87,7 @@ export function destroy_component(component, detaching) {
8787
}
8888
}
8989

90-
function make_dirty(component, i) {
90+
function make_dirty(component: SvelteComponent, i) {
9191
if (component.$$.dirty[0] === -1) {
9292
dirty_components.push(component);
9393
schedule_update();
@@ -96,7 +96,7 @@ function make_dirty(component, i) {
9696
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
9797
}
9898

99-
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
99+
export function init(component: SvelteComponent, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
100100
const parent_component = current_component;
101101
set_current_component(component);
102102

@@ -167,9 +167,11 @@ export function init(component, options, instance, create_fragment, not_equal, p
167167
set_current_component(parent_component);
168168
}
169169

170-
export let SvelteElement;
171-
if (typeof HTMLElement === 'function') {
172-
SvelteElement = class extends HTMLElement {
170+
export const SvelteElement = (() => {
171+
if (typeof HTMLElement !== 'function') {
172+
return
173+
}
174+
return class extends HTMLElement {
173175
$$: T$$;
174176
$$set?: ($$props: any) => void;
175177
constructor() {
@@ -213,7 +215,7 @@ if (typeof HTMLElement === 'function') {
213215
}
214216
}
215217
};
216-
}
218+
})();
217219

218220
export class SvelteComponent {
219221
$$: T$$;
@@ -224,7 +226,7 @@ export class SvelteComponent {
224226
this.$destroy = noop;
225227
}
226228

227-
$on(type, callback) {
229+
$on(type: string, callback: CallableFunction) {
228230
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
229231
callbacks.push(callback);
230232

src/runtime/internal/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ export function create_slot(definition, ctx, $$scope, fn) {
7979
}
8080
}
8181

82-
export function get_slot_context(definition, ctx, $$scope, fn) {
82+
export function get_slot_context(definition, ctx, $$scope: {ctx: unknown[]} | undefined, fn) {
8383
return definition[1] && fn
84-
? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
85-
: $$scope.ctx;
84+
? assign($$scope?.ctx.slice(), definition[1](fn(ctx)))
85+
: $$scope?.ctx;
8686
}
8787

8888
export function get_slot_changes(definition, $$scope, dirty, fn) {

test/js/samples/root-component-slot/expected.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import {
55
create_slot,
66
detach,
77
element,
8-
get_slot_changes,
9-
get_slot_context,
108
init,
119
insert,
1210
safe_not_equal,
1311
space,
1412
transition_in,
15-
transition_out
13+
transition_out,
14+
update_slot
1615
} from "svelte/internal";
1716

1817
const get_slot1_slot_changes = dirty => ({});
@@ -22,9 +21,9 @@ function create_fragment(ctx) {
2221
let div;
2322
let t;
2423
let current;
25-
const default_slot_template = /*$$slots*/ ctx[1].default;
24+
const default_slot_template = /*#slots*/ ctx[1].default;
2625
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[0], null);
27-
const slot1_slot_template = /*$$slots*/ ctx[1].slot1;
26+
const slot1_slot_template = /*#slots*/ ctx[1].slot1;
2827
const slot1_slot = create_slot(slot1_slot_template, ctx, /*$$scope*/ ctx[0], get_slot1_slot_context);
2928

3029
return {
@@ -50,12 +49,16 @@ function create_fragment(ctx) {
5049
current = true;
5150
},
5251
p(ctx, [dirty]) {
53-
if (default_slot && default_slot.p && dirty & /*$$scope*/ 1) {
54-
default_slot.p(get_slot_context(default_slot_template, ctx, /*$$scope*/ ctx[0], null), get_slot_changes(default_slot_template, /*$$scope*/ ctx[0], dirty, null));
52+
if (default_slot) {
53+
if (default_slot.p && dirty & /*$$scope*/ 1) {
54+
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[0], dirty, null, null);
55+
}
5556
}
5657

57-
if (slot1_slot && slot1_slot.p && dirty & /*$$scope*/ 1) {
58-
slot1_slot.p(get_slot_context(slot1_slot_template, ctx, /*$$scope*/ ctx[0], get_slot1_slot_context), get_slot_changes(slot1_slot_template, /*$$scope*/ ctx[0], dirty, get_slot1_slot_changes));
58+
if (slot1_slot) {
59+
if (slot1_slot.p && dirty & /*$$scope*/ 1) {
60+
update_slot(slot1_slot, slot1_slot_template, ctx, /*$$scope*/ ctx[0], dirty, get_slot1_slot_changes, get_slot1_slot_context);
61+
}
5962
}
6063
},
6164
i(local) {
@@ -78,13 +81,13 @@ function create_fragment(ctx) {
7881
}
7982

8083
function instance($$self, $$props, $$invalidate) {
81-
let { $$slots = {}, $$scope } = $$props;
84+
let { $$slots: slots = {}, $$scope } = $$props;
8285

83-
$$self.$set = $$props => {
86+
$$self.$$set = $$props => {
8487
if ("$$scope" in $$props) $$invalidate(0, $$scope = $$props.$$scope);
8588
};
8689

87-
return [$$scope, $$slots];
90+
return [$$scope, slots];
8891
}
8992

9093
class Component extends SvelteComponent {

test/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ let compile = null;
2424

2525
const sveltePath = process.cwd().split('\\').join('/');
2626

27-
let unhandled_rejection = false;
28-
process.on('unhandledRejection', err => {
27+
let unhandled_rejection: Error | null = null;
28+
process.on('unhandledRejection', (err: Error) => {
2929
unhandled_rejection = err;
3030
});
3131

0 commit comments

Comments
 (0)