From 84d9352ea2c51c1a26b12739bd2455143f9f2098 Mon Sep 17 00:00:00 2001 From: John Chesley Date: Thu, 7 Mar 2019 22:39:48 -0500 Subject: [PATCH 1/3] add samples for various export syntax --- test/runtime/samples/prop-exports/_config.js | 29 ++++++++++++ test/runtime/samples/prop-exports/main.svelte | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/runtime/samples/prop-exports/_config.js create mode 100644 test/runtime/samples/prop-exports/main.svelte diff --git a/test/runtime/samples/prop-exports/_config.js b/test/runtime/samples/prop-exports/_config.js new file mode 100644 index 0000000000..5959d4e5a9 --- /dev/null +++ b/test/runtime/samples/prop-exports/_config.js @@ -0,0 +1,29 @@ +import { writable } from '../../../../store'; + +export default { + props: { + s1: writable(42), + s2: writable(43), + p1: 2, + p3: 3, + a1: writable(1), + a2: 4, + a6: writable(29), + for: 'loop', + continue: '...', + }, + + html: ` + $s1=42 + $s2=43 + p1=2 + p3=3 + $v1=1 + v2=4 + vi1=4 + $vs1=1 + vl1=test + $s3=29 + loop... + ` +} diff --git a/test/runtime/samples/prop-exports/main.svelte b/test/runtime/samples/prop-exports/main.svelte new file mode 100644 index 0000000000..8a8fadd7be --- /dev/null +++ b/test/runtime/samples/prop-exports/main.svelte @@ -0,0 +1,46 @@ + + +$s1={$s1} +$s2={$s2} +p1={p1} +p3={p3} +$v1={$v1} +v2={v2} +vi1={vi1} +$vs1={$vs1} +vl1={vl1} +$s3={$s3} +{k1}{k2} From 63b5ff96cfc71508003e58971770e418e7c81d68 Mon Sep 17 00:00:00 2001 From: John Chesley Date: Thu, 7 Mar 2019 22:42:54 -0500 Subject: [PATCH 2/3] add support for various export syntax --- src/compile/Component.ts | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index c4695abcec..3b3a425635 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -820,29 +820,34 @@ export default class Component { } if (variable.export_name) { - if (variable.subscribable) { - coalesced_declarations.push({ - kind: node.kind, - declarators: [declarator], - insert: get_insert(variable) - }); + if (current_group && current_group.kind !== node.kind) { current_group = null; - } else { - if (current_group && current_group.kind !== node.kind) { - current_group = null; - } + } - if (!current_group) { - current_group = { kind: node.kind, declarators: [], insert: null }; - coalesced_declarations.push(current_group); - } + const insert = variable.subscribable + ? get_insert(variable) + : null; + if (!current_group || (current_group.insert && insert)) { + current_group = { kind: node.kind, declarators: [declarator], insert }; + coalesced_declarations.push(current_group); + } else if (insert) { + current_group.insert = insert current_group.declarators.push(declarator); + } else { + current_group.declarators.push(declarator); + } + + if (variable.name !== variable.export_name) { + code.prependRight(declarator.id.start, `${variable.export_name}:`) } if (next) { const next_variable = component.var_lookup.get(next.id.name) - if (next_variable && !next_variable.export_name) { + const new_declaration = !next_variable.export_name + || (current_group.insert && next_variable.subscribable) + + if (new_declaration) { code.overwrite(declarator.end, next.start, ` ${node.kind} `); } } @@ -919,6 +924,11 @@ export default class Component { const all_hoistable = node.declarations.every(d => { if (!d.init) return false; if (d.init.type !== 'Literal') return false; + + const v = this.var_lookup.get(d.id.name) + if (v.reassigned) return false + if (v.export_name && v.export_name !== v.name) return false + if (this.var_lookup.get(d.id.name).reassigned) return false; if (this.vars.find(variable => variable.name === d.id.name && variable.module)) return false; From dba2574d2d37ec030fd7a54e74a326f8eca23552 Mon Sep 17 00:00:00 2001 From: John Chesley Date: Thu, 7 Mar 2019 22:49:47 -0500 Subject: [PATCH 3/3] tabs --- src/compile/Component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 3b3a425635..5ef2ac6835 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -839,7 +839,7 @@ export default class Component { } if (variable.name !== variable.export_name) { - code.prependRight(declarator.id.start, `${variable.export_name}:`) + code.prependRight(declarator.id.start, `${variable.export_name}:`) } if (next) {