From 552f19b327a9ff56eb822fbfb9d6fd6d124d7b78 Mon Sep 17 00:00:00 2001 From: Tony Crowe Date: Mon, 16 Sep 2019 20:07:25 -0600 Subject: [PATCH 001/413] check if the attribute value is different before setting it --- src/runtime/internal/dom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 58a0d0729a..2a55e409a3 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -86,7 +86,7 @@ export function self(fn) { export function attr(node: Element, attribute: string, value?: string) { if (value == null) node.removeAttribute(attribute); - else node.setAttribute(attribute, value); + else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); } export function set_attributes(node: Element & ElementCSSInlineStyle, attributes: { [x: string]: string }) { From fbf4cbf22c144ef849dce6d3630a54344406d11a Mon Sep 17 00:00:00 2001 From: simeydotme Date: Tue, 24 Sep 2019 22:38:55 +0800 Subject: [PATCH 002/413] Calculate scale factor of elements in FLIP animations - divide the getBoundingClientRect dimensions by clientHeight or clientWidth - this gives us the element's scaled values as scaleX and scaleY - divide the "dx" and "dy" by the "scaleX" and "scaleY" This aims to fix #3555 by using the node's un-scaled width/height to calculate the amount it has been scaled. Then dividing the distance by this scale factor removes the janky start position which was shown in the test case. resolves #3555 --- src/runtime/animate/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/animate/index.ts b/src/runtime/animate/index.ts index d00d23c98d..3f841154a2 100644 --- a/src/runtime/animate/index.ts +++ b/src/runtime/animate/index.ts @@ -19,9 +19,11 @@ interface FlipParams { export function flip(node: Element, animation: { from: DOMRect; to: DOMRect }, params: FlipParams): AnimationConfig { const style = getComputedStyle(node); const transform = style.transform === 'none' ? '' : style.transform; + const scaleX = animation.from.width / node.clientWidth; + const scaleY = animation.from.height / node.clientHeight; - const dx = animation.from.left - animation.to.left; - const dy = animation.from.top - animation.to.top; + const dx = (animation.from.left - animation.to.left) / scaleX; + const dy = (animation.from.top - animation.to.top) / scaleY; const d = Math.sqrt(dx * dx + dy * dy); From 5e2c5248253dc77e1639a515d9d1298ef76ee585 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Mon, 30 Sep 2019 21:00:24 -0700 Subject: [PATCH 003/413] chore: update database ENV keys --- site/.env.example | 9 +++++++-- site/src/utils/db.js | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/site/.env.example b/site/.env.example index 4de2f6111a..9cfe50cd6c 100644 --- a/site/.env.example +++ b/site/.env.example @@ -2,7 +2,12 @@ NODE_ENV= PORT= BASEURL= -DATABASE_URL= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= -MAPBOX_ACCESS_TOKEN= \ No newline at end of file +MAPBOX_ACCESS_TOKEN= + +PGHOST=hostname +PGPORT=port +PGUSER=username +PGPASSWORD=password +PGDATABASE=database_name diff --git a/site/src/utils/db.js b/site/src/utils/db.js index a4d398e181..ba9d5e4066 100644 --- a/site/src/utils/db.js +++ b/site/src/utils/db.js @@ -1,8 +1,7 @@ import { Pool } from 'pg'; -export const DB = new Pool({ - connectionString: process.env.DATABASE_URL -}); +// Uses `PG*` ENV vars +export const DB = new Pool(); export function query(text, values=[]) { return DB.query(text, values).then(r => r.rows); From 02f5efd9e7ed99ae5873a00f7a0c32966ec0353d Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Fri, 4 Oct 2019 14:36:04 +0200 Subject: [PATCH 004/413] fix compound assignment dependencies in reactive statements (#3634) --- src/compiler/compile/Component.ts | 8 ++++- .../reactive-compound-operator/_config.js | 27 +++++++++++++++++ .../reactive-compound-operator/main.svelte | 8 +++++ .../reactive-update-expression/_config.js | 29 +++++++++++++++++++ .../reactive-update-expression/main.svelte | 12 ++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/reactive-compound-operator/_config.js create mode 100644 test/runtime/samples/reactive-compound-operator/main.svelte create mode 100644 test/runtime/samples/reactive-update-expression/_config.js create mode 100644 test/runtime/samples/reactive-update-expression/main.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index fa8665ffde..423186e4f3 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1265,10 +1265,16 @@ export default class Component { } if (node.type === 'AssignmentExpression') { - extract_identifiers(get_object(node.left)).forEach(node => { + const left = get_object(node.left); + + extract_identifiers(left).forEach(node => { assignee_nodes.add(node); assignees.add(node.name); }); + + if (node.operator !== '=') { + dependencies.add(left.name); + } } else if (node.type === 'UpdateExpression') { const identifier = get_object(node.argument); assignees.add(identifier.name); diff --git a/test/runtime/samples/reactive-compound-operator/_config.js b/test/runtime/samples/reactive-compound-operator/_config.js new file mode 100644 index 0000000000..dd59fbbf0a --- /dev/null +++ b/test/runtime/samples/reactive-compound-operator/_config.js @@ -0,0 +1,27 @@ +export default { + html: ` + +

count: 0

+ `, + + async test({ assert, component, target, window }) { + const click = new window.MouseEvent('click'); + const button = target.querySelector('button'); + + await button.dispatchEvent(click); + + assert.equal(component.x, 2); + assert.htmlEqual(target.innerHTML, ` + +

count: 2

+ `); + + await button.dispatchEvent(click); + + assert.equal(component.x, 6); + assert.htmlEqual(target.innerHTML, ` + +

count: 6

+ `); + } +}; diff --git a/test/runtime/samples/reactive-compound-operator/main.svelte b/test/runtime/samples/reactive-compound-operator/main.svelte new file mode 100644 index 0000000000..52654aed59 --- /dev/null +++ b/test/runtime/samples/reactive-compound-operator/main.svelte @@ -0,0 +1,8 @@ + + + +

count: {x}

diff --git a/test/runtime/samples/reactive-update-expression/_config.js b/test/runtime/samples/reactive-update-expression/_config.js new file mode 100644 index 0000000000..111460f7dd --- /dev/null +++ b/test/runtime/samples/reactive-update-expression/_config.js @@ -0,0 +1,29 @@ +export default { + html: ` + +

count: 1

+ `, + + async test({ assert, component, target, window }) { + const click = new window.MouseEvent('click'); + const button = target.querySelector('button'); + + assert.equal(component.x, 1); + + await button.dispatchEvent(click); + + assert.equal(component.x, 3); + assert.htmlEqual(target.innerHTML, ` + +

count: 3

+ `); + + await button.dispatchEvent(click); + + assert.equal(component.x, 5); + assert.htmlEqual(target.innerHTML, ` + +

count: 5

+ `); + } +}; diff --git a/test/runtime/samples/reactive-update-expression/main.svelte b/test/runtime/samples/reactive-update-expression/main.svelte new file mode 100644 index 0000000000..0e0b45ddd6 --- /dev/null +++ b/test/runtime/samples/reactive-update-expression/main.svelte @@ -0,0 +1,12 @@ + + + +

count: {x}

From f7565928f53cf09523e4e68e19c5f264fcc342d3 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 4 Oct 2019 08:38:10 -0400 Subject: [PATCH 005/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51e1e49cba..a7abca9a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) ## 3.12.1 From 87a9ee2d87353218159854a689b68ea65945d04a Mon Sep 17 00:00:00 2001 From: "Dewa M. Widyakumara" Date: Wed, 2 Oct 2019 18:47:17 +0700 Subject: [PATCH 006/413] replace tokopedia logo with svg --- .../routes/_components/WhosUsingSvelte.svelte | 2 +- site/static/organisations/tokopedia.2x.png | Bin 7530 -> 0 bytes site/static/organisations/tokopedia.3x.png | Bin 12699 -> 0 bytes site/static/organisations/tokopedia.png | Bin 3928 -> 0 bytes site/static/organisations/tokopedia.svg | 4 ++++ 5 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 site/static/organisations/tokopedia.2x.png delete mode 100644 site/static/organisations/tokopedia.3x.png delete mode 100644 site/static/organisations/tokopedia.png create mode 100644 site/static/organisations/tokopedia.svg diff --git a/site/src/routes/_components/WhosUsingSvelte.svelte b/site/src/routes/_components/WhosUsingSvelte.svelte index 6444596cc8..f1a1585506 100644 --- a/site/src/routes/_components/WhosUsingSvelte.svelte +++ b/site/src/routes/_components/WhosUsingSvelte.svelte @@ -78,7 +78,7 @@ Strix Cloud logoStrix Cloud Sucuri logo Thunderdome logo - Tokopedia logo + Tokopedia logo Webdesq logo Zevvle logo + your company? diff --git a/site/static/organisations/tokopedia.2x.png b/site/static/organisations/tokopedia.2x.png deleted file mode 100644 index 5ba45fdb2b7b353f385f79be864e489f586e7df5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7530 zcmYLO1ys{-)E+q+l}<;4gp??fg8>^I(h>^N4HD8JC^Hq*56m^E;V4(Kwrqn6`00W?^ z_(n#~K~bs-2Cjq(BnbfS0aBGPa1~UdMFMruEYy^$g8JV3q5vqC6bjQPfQkcr0aDcu zFqwK4R0_3T^qHX|GEGY0CV7DG!vkCigH}VOYvoZaRB;qop->Z22a`svW_h_51xTZU zM1zb>Jq%KZg2ANgA5y3y(slBv9knFu6r`)fI@Z7-^$HJ-YX8MiDOCM`@dtX1$^#PB=wB992V5^NU8{h?K3 z>eT!%_(4@Os=flGK~cI+;emx37RCCvP(z^r5-ks^APw>mlk!2d3#Yhar9n*T)} zy8lQ2PbVrhruo3CgMm>tmY^!2G|Nk&Dm(!Go9JKUVN945%9+{+g%2a3cGTdtiYPDy zCHo;OFVm>_AoZVbsJ#1I{xD}Kp!g9|I_)O6%UpFZ~f~c;Vbdb7o`D({Qpw&s7sUplo;p?6!M_qfhCPP zR6Th3Ag=}{`$zL%I|Zq#2el{)v=)jgh4NhPm$Gb|GD?_itCCEUB8rF_83mSYQGzrm zpq^`)W+jxva_uURI@EooDA%Tp8b`KOS?;%rT)Q%~Lj`4pOtYfQ10F?`m+w`Fb*e%; zRbky~k#j{QsGEDqMO|3~aCM7?c6Wn$jd6>9hjxW^g??~L{^=I$OzJ5*`UUXk-OVMo zU>MC~XB?_mxhzhzMwj~(P_m8@+~g_JQ)j~G^BH6Pg|C~G`0|!JEkDcLKHAyJ4wV%X zw#FOkvMmKMG12oMT?a+lU%C^dDM+jA^bk8?1bCZ3ka0)9uv=6q z{5caeU$BFpe0VAIg?mX~;dq*NsOX0uA=7!~g!uuX}P6wq15k6c*eQe+&Rn3Bw@ZH|{fgsX#BX z57n)MO>SoUb3XO~xYj)}K|ta;%4n7V7o5kI)bN-gPfrl^<6|zUL!2Rb92V&#EQ;N% zsotz2JLmb8=5sFrXHNw_EX*1&TPNoO#V6oJ`wzatm&+<_<^#fu_aa6jCk$R}zjOf^ zbLiR#Q*$(jby_cCOc{P_{f<4FRxd24Ng^m-K#K2ljuw_>KcPA0dGI^)16mOlJ+R(MH}2>EDqt%@f2@JG&QX9Li%_28&0e z!@M$>FuFH9mu&6>aLaElt-vd#P&oM%)rv=VG60FjF6ur{bXwF~Ztmomu$Z@c8(^?f ztj!1|IW2tw?U!_F{Z4qf&6qR)JP`3Yxz+}LVl9Kj>+d>WMq|N6U|rn=Qgk%_=~)ce zjDfWdOltM}?e=1M#Dz=F6l-q`-Kjl+(loBTz+>lDo=`zM$q8Wh8lk_tV&yg9>B`15 z&GQAqS>4CX;c!YXU-VuUCmnvdW#_EbHm_+aj}L*QDgG{P_;?t?XHURV%c&NT^IP{v zHCUFnZU9UFuP^Kf_~p{v3W`0{x^b%l6@Sd^Y)g=Iq^kBGD)e<}+eN#>q(HMFLf*U; z`FynT?HW8EP45TT2XFKDs$v?!`pe?5^azFan})&0YGU`pgFE7|I*Mr+Vj z(8o1x0t+`uFu%ctPE9C0h#QN!zYDk9o|(=wKk(S8r+fX9l?rK*$spKsydab{cI+SO ztQOqV>rAC6x077sDlu9?3$MhPf49ty-J;PDtl@%}5j z@saH6_>udIJCgi*+`g~8PgC6xvRXIM7N=5*(W~iPkj&&+05X6?++LJEO5XQrvG_W? z*cv;b!}MvjCP|T|RP4*Y*vfh1Rzx?FnQkoB9f3$e%+V&39|F4-_8I!##^=^2>k8Nia$Qes#q%)@Ck z4skpU-F@ERLEtwXi>|(+8U1_8*I$>L<2w~?Og0ibkR9}xkkL2u-QQ>UwR+!~guA@g z0@%H~H)ViHeo8Jx?ibzA;>pA^mdo{YyWe9~brnZ-*e%TJN?@1G&%b)$DMR*^$l6U0 z;jS?3w!}7bN*U?2n(BH4Zjz#XTFEDpW0JY8Z#R-4zk@x1|D-xI73DSRSQ# zYbOOQDucvYrPwr+D?`<-r+Ly;Pz{0vDWTErTgTf3I}T0EywcS~Q&FC&dM!shYE88t z)FX6?uw>8D$>B;7>9gn0&6E4Ci(_|W)J*u?@$4o{5yVfMn=DapFuI3|uR_5VTx-jT zef{9$?1?))~szUBalw zw3=UDSe(eF7+bd(M<$nJ?`kRqr5-vPD;L>@9#=Fw)wT-PiZ>v1GB3jCk<)>*Tic{LTIM&jL1AeEFq ztnrzP?k2*1gs4KRtWKYG~|Xd&r) z)^*xNN325m*ZCO<+b(tp73)PrP?FAGdVPx@wZWau=f1qyM0Bw(3dOylfuPTX%E|Cp zc59L!B|Ul3m>Aw>Kf9|o^O^AILW7fEHlTIpHi?yMWD!fB;Q99q4Ci@=tBkYr^1;ua zjpc7e#Pz*TZl?gg$4+iKBW}GW{he3}DWp78nLpDnoH{qQRN}qptOh$d41U4!l$f($ zC)miJJP3Zq;IB*`{ngkE^m#0n5a2$|zk4ZDh)ZQ(d1fpw8U8vXuPItzQ2In#rnc7Bwd|PU~Y$z}8&> z;|kdN^bWfU9&fC<5*-!4ViJab3utY9&q8cH^O^E;XaJ4iD6EoVGE!SVps_tD>i*{s zTR3Z?ewClon}z*I+Gw~#jY>~`uB&%?z-Pa)v?|9Z-O4?V5DMOclhCxmLYe01G~5eNMx2iLPg3gQ}Xt5~hzyb;bg@ z)tfXPTP7d0b0EPY&7?UX0I; z9y$+C(MzsO4XNfEv=>PKW=phi!!HEegjg^vf+@BJjKf> zwg^_d%ZYMlSy3Oe^D$sI+BqyjQb);Oaj4R#Oe&dFSH#4DmFRBsHELrHD|w3@T!_R*9_iCr9yy5s_Vz_C>LUmQ`8$@E%@+Qm%6%$5MjT z_Kkj5tW2ja3{yOG2>gYZdBjs8OR9Ok#(sbSnBix*rDSu)Bk7N&{@FJ; z1{FC&b$;4Rj=$8LI0MmMBbJXqn4Gq)Rc8kJ_#*^?1*3J2~zT?gc(~)NByUa*FJvLI}ROFY0Q-aj%`F#EAj$v6buAY;r zAv8bBQtTgJkBwxp?||v=`i%q9Dv11%!K&CPy2~TrnI)OjtHy6fp>~T4r*V=qu5$Pw z$K_P^xdL0!w2Ckj!EE15;wSoVA8BrkdT;2~`;93N4`qrRS}{cm^3wXhg-(*JbI{e0 zvwKk!d%eWN3kD8x7UQQpclC(`Q-33F%>o`9{Ng^G7BoP8EbcgJL@exFqfg>>S?i;F zeDn8$<;f5cDR*pHcvlKT+d%5w#%E|$j;w+0N?SH#SV;=l9M3&OnBX*h@A~9@*?C5*}V?oFoT)<2O>1xSvg_^u)hj(4JmL1($)C9brR;+kQ&|? z4eBFuAio=L?qIEi&Ba}s`2)JG1UN4k6>j)`{f9GzC+ zAE6ITKe1wwlnEuPGdAn=i?fTZWEJ+>Z^d;h*?n$2iiYe8u4#XhxwHOZ&FZz>mEojw z)Zo)(;TU3474IWM=I6>jRgn{8-wAKq!im1vM9$@na_I7&Fe?j)k6}Djy^Hd@;a|}0 zET;PV#{=DoZ%NIrgO)f`^U99ZQbKLrMS`(nulJRXc(q=}XijIQZTEgdldRK54^|X5 z^X$@>SB-gjfqPDp;t(xch6`LE_4zdKo@%SSmaR)A%%;n?xI0s^tUou`x z-iif2;=~5#wM3;VR7-d)uNvEtnfl&(uPOWQGO=7MmsuJuD!(i^x?doi{>rpM&EECr z7g`?^9+m&-JOc^+Yx~O8Tv~lZO_V5nO3thr%_(-*tSCNAnP(y_WI%G~edZZmTGYYN zOka>DVukJ5#j6bBW8J6o(7w@WIr2)Z5ezrNP#jYS`p=5CVe;EU3W(M|$No_Au^1NQD zt|xw?ON(_%h6*>;z_QWu7F#+6vP3zs^RwHXYYYjn4H2+*CTSMq*t)%s#q0lwS9a0G zUoJ2Y-*h@Ti*9Qjrfa%K0sp>z>#kU)fb+(JQ{5(0%5a%tDmNQM22tsien+-e#qIZ2 zKFT=Di_}Sj$0s9*dHm^4-Lmm87BYath4k6e6;Tm+g%qh>NN6#a-}NoJ<;KA^dO}wh zT}GV%rmC*AUJ!*O&>`;e2G|J|al3bZDz}>gbSYJI+VFAlI|4q}8sdb72~u3>n(v@j-ub>NMPr72&zfNMQMY}*QY^7SnJ(n z$Cq3YS(X^f-U9Ql9dwi6`S5FH3(mD?U6WRta2}`XcOMRDt^*Xf%~tU)hk2>>C=LAL zg{Fr}lK3)D38XA7b5Y+-ccLhs9mz7%#FvW6Iq4QAVOl7=TLO8>+KjbMQzBZ2PIck?x0iJNJ&GN(Up1fr+FJ+SR-j=vtF@FYa?5>^B~-br#vYF#~v?F;2EoZg z6#pPR{u7+&m(@2`eTjV56F;abHabn4^_&cs3Vau@a>Ax+D)OF9YeP)7;i;|b`}c)5%kmgc<)sU8@pwJMI0qcJ$=FB?YN@&3)8 zo_9L?GO!pLC9cjnl0R=0_5SJD;iq>XK80gA#cS1m{ZdZ#CScfBz|6|#l+vz#`SQ(X z3VkkdL*%FSgr|w4v}+bZK~0+PB;vXjx7_wHA}Y_2@40T~@>&e*ob)aAYzc2m`ooT` z;nTaXy4eP!qb67+WBT8YCal*lWfYuLhx=q)@YT&IrNg2Lx5k;_B<)!OAh|I57Text zM`=&N)a=6dH`zQ&JJ#ow?8{7b80DER`}jaPThA;aU(P&@5fURnCzOD=?0Me4@t*y} zc~ZlAj*7iD;}}9Slz?d=X}oiXpc^Cx*IzT=mv+i{KexqwlExLgiY?A-ep%u`(q-w) zoJQ%gK~?bT)}7+uuysk+wHHE~_3o1dm^9zbZFMf!ldJ_V?~d#>exW;6ihmzAdprjW zCK#hnBhR&@oTs$Wt%wJc_SBhTKT=LBypmStw1%2WXnkm^dP&MQ1vg{o;)K5ZwGulb zg2g5{3-QwFeU=lj6)_$o!lWo5{UdqIhLCTx9v7oP-1CCG6iQc@lM!He?$P1$W_xSc z?T<{iGC0||@)Ms-xyCy;-*Uj87aKoY4`p5jvQtxqKQH?0AE6<^;ze4Pl^aw@b-}xvAxFlIsS$tIvSI?RP6=k%`8L3^njBTv2WyWcS;C?6T0m?VbuGj zh_i;d{K`;W0n_AGp4YnhN)3)Hx0-F3hmb989xxIWBRSaOfI>_RZec|Owt_Yml?QKq zf^)|beHr+1Mc>9ANC^6{PLFEBcbUvqVV>yBcl}XAO|J|!`1^>TGK!Rb3s0pS8+%nO zd^cz>Ul;M$SS=1TlkRYlzXvwNGGWK#ofvuxW?LE0qAE4$p=CP^B62I38zQNqsfiV#wGcKk0S_}J+bZY zz1wKbNuYB-IGjlrlEx^9sfwwE>ClG#<_gIK6qT52r zt;d`urk|>HriU(^%j-3()3SRq3DRHITaS;X>1})G&kX;ej?q*?N3FhAb}zLSu*i1p z`)RiCP0g-5`s%@pu4bs@_P2qMEIwiNBhs(>y*Jx+GHNq1$tNGn@27H$uR<}j7T9kw z{S`f$HVgZ4etVEMN^o_`iaJvy(&<=QBInO;Q+Nv7kAL|W_PwV8z8L8v9BkBnE4=lU zA&*>zDiWD{D&#o*;R3Lf{4!d)B;){_=hFTK7qxSSsqT7;3|Y>s)9eh!1io$V}!^WLwr>{gXu~ks>}?^I>92o;zE2 ztieRcYxW13T6-3-Rg09ai$l)Havsq!GO}Zn%G&h(bGVPja#>}`U9l~a)Rhi0ene<9 zDXziYy?Agf6bSB`KfJ&1 zo7p_Gd-m?V=bYVnW@nOwDk(@|p_8Hm001l*X>k<*00H*g2fs#oer9tzeg*&#AC*9A z5>gJJXGEk^M7=~E00;Q``aXZ8A<|N9^5TuMz$RI-CRt#M9I#1FtWgHoEC*}>iM1&_ zgU>^;1{v{YIoUB4V56)^hX}wI0DJ}^GQbAe=PA)fS-yUC@#n|}8R%ROvk<8s1@Zsf1J!}}N>rtL6<@4w zl#yr!0UKVJys&zyE+f^W_>#62^x}4-jQGn&JUb(+4p)DUe{RwPN)pf7pI5agGM7Aq zFSK7WG|P%Vdsrv)La$vG*a{MFk`wPxcyXywRy|*h@#|d80*q zMI_puH}^lVNe9_bc0xpjFJR@e8%n|a2%IlKYcnl^BH{LJ94b@6EZy4 z27Y?!AxZh@oMl_PdJVUCx<+|34cD1LM}zx@!~X^SbR>sA!5hWkj&P)+d^r38A4T_1 z+Gkcc(_3yh*OMC_#%pYI%}*e{R|0V<3bd$N|1N$p*3ZLk?@v0r*89iy?kk3Q40Qsl zz5kH(z-JW|7u#RoJUkYEIgUOm|Le7z5xGWC375XR<%BnnRJ0`&qFs7gH($LIUoZs# z*c4^NMb*9|z-9tnS>*`&PwktnjmZepDM~%N(?V^RAeo-g-yXUd&Dq@~OP``o9_Lo8 zbWqU#D2Ts5%5{i}_~2KX-V(y-kHC(vjMzD{G%%0zYWxkt0}^6j08p&wO%!oxF~&M2 z?vPk+F76iHT(#rrX%||TV?||F;!hPiNjmzXe3YUBTFfY_#F*IBjKoZ)-RZnH;fU9}{XaU>p)dDh4LuuUkQX2@}Iq3akyu&~hBg^ptH?YzXXji2NVt znjsaxHeJ(LxzDh8%98<&Tr=JNxtEq;Yr75Jwtgbz&e~a(etVA)`PYZ}>o;PK=O(NTKg&Q9^?43*DpT0oSqq6X_uvAaXrpuVQOZhE4g8wye|f)S>y5zrccmh~6rT#SlgMmV zyDNOrz=B%$ao^2?}vbA88^*{TErKoAEq8 z1=O7pK;2xEC(EtET-`BZ``dt!$_W^2ZuM%?28a@C@tNx*1AI++}HBGQj?|>NO zv>__WAwz70g;QW_^)nwzYwu~OJF ztHIu@q4DaCf=@x_&j;1X6|%|(1z zMsb*{La2^wMF%>`*bbvlK<$)$e7;}#&#tTAh;B3sD!*diA0Qa+0-cI3y0Db1k8^T{My_>;q2MWTMIN3TTZ6A_^Pn`Vc<;>pva53dUP z7crfTN$CuV+u9wGo4ccxN)bNaIf`$9Grg%PN+m$&)q}8`TOZ|9|1rX^uQD_&!Z6mK zY^oa<=R*Uzf=3VPYZd}X;I#HUmI|(*njsI*KH5qwy=+5I)F(P#t4^gwz(G}VF!+0| z3Jk$+C??2>>Gs|(N0u^J z6U6;uzD!2}kW@%_hFRE`JG$Lf{`R`RY1M?Bv3)qmyuZ+-wDR8l`OY{(N8Hi)_UB4v z#a|4)=s+3u4}Qc39@q0g6I=E&R*&P`qSc18)v3BFGcB&8ZB#n?+r1D}5gd>1-_zmA z^C>LGyu1*X!PF*I0Npyna1=>xTIizns(`PmHtFYw*Jr&x%&3Lgw|(uBQJk*`>g^g@ z#Be`4^oQj{uN|U3Xg6S`2f)C(;bGCE#UR2+Md$EA%_V)D>}d%;6FLueWgB#fhz$SR zg(tKx6Hdc=04fp9e2%jx`GAgU*MD993x3)A3y<+M_8Ja)?t^V%}z_Xq5* zg|zX?K8DI`=T4;V_EWA%13}Eb)fY5hWD5cxQI}7nPJe_k=1zqa6;AVr2!Yd_E9leG z-$#a30F=q~wy1pDJU@uLNg3kLnK!(f6kGCfuOI`9#B`jFy(V_>w4{(v&y}1O&_~r( z9&aLMU-n;Pw#Vn87hN-`q05&Q6br5Sv4NH1>5<*_R^?V4*9t%HBdH?!3dZ{aX&XH0 z1OLkbk-wPea|!DcJc&;AyOe{$T=?v(kD3-^894!eGrg|5#ab!@3k9K;H^U-WNDp(E zgsqrQ$=FPd&liT=@uSzo{13~>`AeJP!aN3;CC%?|e0-R>!N2itwx38p^SbIVqJQyJ z%Zm&ap%g@uwzWz)%)=jZX1|^$rY1I1h^kNiKuXJuZ+li{9F9`UOM(2Cv+TnVumJ8grh9?M;f^$?T0TNeYhs&iu2`%S(Z;~xOsMiI-}C=-w|YmE_P#9 zXC!F8Gtk2Xe%-DY<%yv+(IDKwB2*%wNbm6zGsoY0pY-s7(T?Zrt3Gu~n#FbtIfo2G zxl94y${P^U5nXM#K`^{5$ZjmHobSiFpkD#Et$h2;QT!fTV3s~KR?Z@MZU?Js&J&>O~hufH~=}&Q$l;3%Cr^$lK3__@U!J%PE^h2@+Wa(t)r46F2|fX3+kUm>j}a5uGCcabV(pC32Cnu{Pdq%UN<&p> zyPhci9AU}jNx1XllXp}lI=&frFQWM1N^wMFB^@Le$}}*Gc5685{FT`^Gv_ZiOgeY= zq0ppNcydMM*QDhIFD!HeE87QP=60NZ?Y(zF_dVTCOZo)<0ZbzKw4gO*8zt1v$?v{0 zd!$CbfUJ!NUW~KA)g2=5@%&`A^ral#4&OpSb6qXbGq8((Rnj$Lb>L^ks%Zwo?|R-U zCx_o!ig7!ft2l$3Wku|-cS1?+J}?~?e-sE1MJ+l>)Dem()=E5Ja4u3u7AjKs!>#|N zMes4QwL^cqax0jpXRRFl+8!s&>QkYLMZ9MDED?L?cUigK%vEile1lw1VTLT)RXTlx z-|xJd7sZw?Jf?kdT(N6J9;V(M$+))p$Q9e7`8vtBtF-B}p2VG1&x_J0Io2|6bAL0o zvAMhM!WT5s^$nN7X2{|Gl?vvC#TgW%}P&m?a{i70p)Mh-k^zc zwp^?FKD-TetkW7@+~l%E0>UBtB9-JqPZkoN=8bT1ZG(R^MJIL%m!2DlJ}-Nsq!Heqr-j?&&&j5l&M$mO-e~A=mf< zJ+=sbWv`d)Phhc@_fV%Bz6Mx`cR4YEK zRrA2Mx1s_Ay6KxnaNWn#ros{L3MGo9L&ulfziG#B!6B z=140V(jTjZvFLgaevGl+`a`W&jT!Cz6Hrr_g0$x3f#>SrQR~IkPCKe@7~vg$Rv{IS zXuQ(f;-_I+yyQwzmy?PI2@OC@N0rSJb7C5y%?8Un*99(%XN~oR>J87zVmFz@GS=pB zisgJjydVu^FPvJjcCD`_OCg`??B2(Ff0l`l{oZ@tO5|bB6g_#qK zz97*J8_h=-M)1`m4VNs&_@PHEZha)C(rchD$qIV#QTRE(x}7pdpeSwh)nRs!4sH~l zthHI!HYsL@-%4EH%<4EtYCpM5cinP){|(d{6aDoZ4UHY?szpHPhf64P)jNKD)vVj) zjfw}FDkj6Pj-svElTpB)mRD4@742T&P)h+@W%eK3xL2wtf!}`$Kc?Id_^BEme&xiV zj%2_Dz~3aVvPyU9Is=ABpKnAP?SER|_aP$L?o(I7Qag54XR*%;blSQa2Um^G)}sZI%T}p#o%%kQ7k2>U;M1bc1VB zs@T<}&VJTPDAyKYIOp<0L`ax@Pf@$ukyhR$(RRg^i&{{aISPultabszR50W`PDd8(Ib zJ4X}#?1U^M+7`JHm6?u?JEM$6W8A+}Fxs@vK;EWa$dAd;(Bwp$8h@o5rcT~el1agh z!z0tWHM;Y&ibT%vpGN*&R77tWf(cMz<9Em5+gMk^vZ7fcgrvKbne37(L|{MxC?ZLa zi|VraM751Fd%b-d)(}%b)I~?^Xpt!wC9915C3NSnWH@zeXVy%m*!gDsQ74k=d}%`! zQ(2i>>W_fI6&$EaRGSJ2tJn(>M)PkP1FEe7yF$m2CcO;X?#K6-Uy{NVO@TPDpZ;v_ zqP(15bE{8RF&37>KvMi=2>|~j-pI4YYWf2?b8HQZjk|K_vzH!m&eMHD_XVZ(d`Qxj zZU`rk2N}y-9)qJ3-q;F6UG2^MB&TBgDs~iDE#4pXGL;;;KIr=o48BGCCOF`C9LbuK zGpQiKY#%^|VNZ1>vN;`!4ZH_zCPW~iVo@qaRNS{q{6hxQYd|n?q?4rY$GOTxmA{uS zTi{V1MIC<8=Y_iG`Rs?xFvrXKZ*VgU8kMVn0;wFKPKxjC-WUZ@iIQsk@>A{pV`R}3 zsUP2+!J2Uzhh~;DT}?SCGr!qED%0m8dF4`Gz2wl)%?2X({#)svJJn=weIXy!SMAA2 zQ;Gw=d88H#oNTZi?5|B7H~#F}QspnIhi0_W+nVMxQb~F1B*u`VyPQhGbDCO+msLH` zs1Vo5bU*dx&<#{}>hJmCOR8EwTrw*%i%(^P7O6GFlaiB38C|1T?lq#sSom)({KfFF zACSmhY!_kJ;;)Ay9rlPugZYBCFGMFnEE+&i#Dr`=WXce)22&M=FjMWR~f>+NR1@aS_4lOB~=eixt`-*i9P8=SO%1vm1%8)O!QNq*c;+pqeAGY`@}@%sPgZ_^tZjZlB$x+Rhsh|d zwK`@Xo%eou=k8yGXXip(ubKH@%+}d#!gwrfSTb$4GIuhf9ALv4$>}vUcY0MU2Xs(C^K?gGNa$ zWSg;IEcIWj^gzgjMGA75?3(e36RW3}exC-)p6KR^dZ?Om_>=Q_Vc3&Ql}@)nn9a}v z#o$rKaQt=2l7ZjFKoHhJ@M{Wun_}~~`>|d7j=wXQV6wH=Yk9&wkPZKz!{S+5mDKoP z=}BL3QxK^9^GaYdAI#bON}QQJGD2iR#=q25aUi3}2aTkK_#^MH{N1B(1VN8t0fcm?J>%GBlbGQEO3J&L~)1hj?>4)ef26< z>&KW0KgM+8heNA9+s^h%;wmN($&$Fa1TM#{jEJQ#QRvu?5G*akgS^(sRBH~>r(iCJ zbM?w|mp!1mX%>yafjB>Iw8|t-W$oOLdYxks2d_E}I>>jC6C<;Tsx!D+I_=<2{Oyzj zLgaX-)vj+*%ek`@wni0=wP?QRNDB4e$uZSGx?;7T`ID~oV@*F|yDuP~hHh&<&Z8qh zGD!_q-PCAAcxP%B{AiD>P7FRLQum1-PC_^*XHaAXpMt3wX~74CXD4Qh-NHyDiMTvD z<(gLTrq>69=|dJnrh2 zq|Uadw=YVCfoGd?d_suz@0VMfnqbio^m`iOgOB5fM|dr}Eb}nR^G63h6v621JBuxK zb+$*K;WYZJ2kX1xoj}xM#BUs^9g=mi7GAsN$A+FlrW{Z9H&+81S26T;sqgP+N2{_4 zyFPI77b1E$_e71`8v7o`dk5vJwD&c#LY^)sQKS(3y_=dCp-;e9kPmgiA^Jf$gC4lJC4cm@bUg2#|+$Zn875ihp|k_E4%5vY|cX( z*eOk`2mHX}7+`L$*y?h+nGx=k>*}ZwDTrstfDvag!rLv`6%0E!4Unv~O9N<|Lupx7 z>Z%eQbI8E17q3iZIC^}R3vd%pnHrVw-_vw!NMObmCnhIL-H1F?21BWgC)Zk@m;>@| zI95AWL@AMdnlNL`et3I-bXTe8)2Rfma>68zXVRLP8Ev3AOSa5{oM727Rq})IG241g zPmhbc;!N<})%N(=Z+A#=jgq#2ztI zE(g-JAt~>7u>S0eSDsQV#GYjz9P8``6t+8LDBJpz?fG2xy9npSA+RZ4<0Wqw+UnAl zYlF5>FzcNJ42*D|d9_j&;Swr#P8uAAj8hSpTfzwaGTQ`@r)-NtsG+Kj07fm)@M>FL zMJZh=C9lpmxm3@gT4x0dja3j=XU3B*h#~4$o0C7pAg);s?R}8HFkGGtT+IrTea- z5A-z~qwK_oKI2W~iE16|I)YS4CRmAbZJ}rJ#)q4~Q`|FJB?iyz`c?XkBK6wYbqe_e zf~?XpQ9MpN@7HlD2uI)${up}cE0)3LS7XJ&w53HB#5Iu|`ztDWM zt)R8WUvN_?BQ(7Puw^fd=WQzUe$WSAwMGmVJ~Zg|k0`lv{iCz+NcNI9vuwk}QIGqJ zSzBv_M}4rDsL%4%DW+nktF1_!WLtkE(^T@Fj(UW8)F(hte`$uesgVt;ox;JV@=l0R z5h%R<-8QnDgoU-Qs658}o8n!=@Qrf@(&M5}2e|t;vV)v| zisdw1&7lbdBYZqNM%UbSi1acBNrl1ou`{IvZYC5S0a$uea@f(+{o|h+FkMjVNrPeJ zY+9i;n75=e<}^UahJzC`lpoLZ1g;))ll*pV^!UePcgXhZ=kMs60VIhU^Gu&r&3hVl z^-tsRAE|Su(9;Eusev(^H;ODJ9Ni384QHp_l)FsZh3vIw^)gkyCQ%)@ap84=Jh4|> ze%y~)^WJ&qcu~pb!SX!$L%Bb5ibWCzb5G)WOc_ygX4Z<5A(;4lMX3ZR$L?Rk@)!7W zVma2#$|Vs!TepNnf(QNPhm;Kq1^E7HtC{hMK`;m7T$lI-B(OU_A+KIP#asdOv9BBy zaO8qv1@Gf85P5=r?|%|kdN3N~%5x>GGXCCxrc>*Qaf_|M)h#?InPhUesGSEKP}z)Mr0AJVkM! z4W@R}HvS&IR&_uKGe_3GuJVlVm34~Kf?!Ag4&JDJ1)X-O#x>-~F7?RIZ=2~%8Jts? z-q=f#DKPhLs5aq#C$c&9eOjz-RjPLZKmT*pj*ARLzTU^h(Zpk>A=XkOWalb;oh zk!-=WI#(aVaP30oU?CS2gquwVxx{l7#e^8$YEbfkQwmC4YFL#AB)?>FxhnA(=3KMX z-q4+bn9;5VQa&QYK)=OV4OP{w{Id7~l=ltD#}6lG1Xj-?a^`9NGe>aoR#`s2(`g8L z95-xDz>-aH;75tOZA@kQ`M^&VSEIJ)(JdFoC#N}+6~PkOIalyQ-YCrmljUo=bdp#q zfuiQOWP4Y#TC-g-hHr+ZuhtvPmC@#0681<3?lxrwTkwkG>93|a43GMLN)p<%k5dSs z@q3`@_AqpR021IS1fd8iQ~J8wdTp1R&*TZh{_wG?>ydSCCDG?X z5bVJYY8Z>w547%_e}XBx(~T(;87}r%0ARGn+tsHT%LX6rk^O~}Q*+1iik^h)!Lo_k zyB0`CD^8i58Y+AL0&bGImeHXdXq^J-b>}(3HL?f!0P_a%5;U8+TuQZIm&P`Z z3fih$wmn)J4B)DJL10nQxi;%T+FR9{5&@Q~N4$Z3>1Hq1YXNYaT9pNvk5BROJAk^& z)aU#@FINWEpEc&lMmV8pWJ<;vvdZ1Pmc%opJW;Qxvq?&^wapIvB-Xx@2>SveCnK$j zy(IL0B=Y?(rcj)^q;R{n%d%eqvCO(Fu-}pW5;8NCeOr67uWax>_VxX_nps9`mi{o_ z2nJK(6T(l9f2~4hkGb-F5|;c9d0AEGYl&#jBs1m!j!=oZPPG?4DKx{Y-0 zg4KInln6An)@BYomsR;6$d;`pS{g3k93ub;S3Kaj#?Y#rrhI-c+Z1}0=Oh_F!vy!O$XCcQ<|^Lo|J+g0^VS8 zL*sF96%oOaLvK9@^W_Pc4JsQ+noCB&=v|M|mKjKBck0dT zC(6jl`&HFj**B!qiWQ_3XSECgI9zl7Y22y_}+hOAf)I5eqJ@(e>rxBBw zZjxLVvs;s0*lllC^Eb%L70Cgg_D)K7eto9QOvSfarb`3uZth4J<&JT9L|wIXD>f4obRS}hv{~=akj^825JmS z*grtb0=!EasnK}08*AzDLc0FRcdh?XA2E+!sx4Y$QS?zZo#7zWsKPHZL7r1)G7P!f z_#Lx!H0k`kKHCl|V)B?JT&v*I;oDPW6!`foG0fS4uy;|#IGX>Lg_iMM)OuX?#8`H^ zi1*!2#|I&OeAhMOEpubc5$b|orvZxyW=0@$ybL}%3-+V;UZ=L_6->XeMV(MSIfNTy z>Llx3B(Z$hKp}ap%y@UhCKs$>c|-c%$wEQWDkHQg_Y4?%g+uQcTSz zwxB(u3C4JuPvBHc?~(LPHWLP$e?K)2u$t7-^K?esOZNEC<7K>qs$_#7G2vMpChS!+ zDD_>^Gi&QpC^nZKlPlZa{NL%VKB0BQIO&S>7UV?g3=|!=K3<)1W7`%R3ekRZ^WZgQ z1cjE~ICeU}ds<7dRKvFIDP~A)nasgz#<2UC8(qai4)V}SGWpUHs{pU3J8-{jJC*y` ztXrmez+9=W{+6`vufb_Ue@}a;KYAiNc6#^a$PvCH@7xxC*@+;#KNh_?#i#wT+zF3F z%UrXWLyc-@D^ZKu*Mx00;C4PIS)n&7sZ*Uv07bHl9XhB`Gv}&KY-5U8IKxDP0O@3W z(PX+fJmBb$PaBdfwLHnL(RoARbix!^Gn`u>DYU1?Au+d-BKCwO;ONJRM`UGpXFUnC z02h53^bC2-cy=es$@|jfcV}I7Jju4<}2yw&s)INbIze4>!f?2XwPi1P|gg>42fB zDnpyFODuXga~l%{c<_(cf+xG2q{3udDoHS_&0z~t4UUxOs3R0_-9`nE!@F362VaDw z#1;LLQ6CN^dUD|0=10Tod9y-yKy8)(c>G%c$ji}f6tit&tdovJwg|^z(ONY+X zD`0&BW=|3-w{!4FI+S16|2UFT@qwR=1LP(6y)ty@7g(&Ni5oUYP>9o+QHt%`+u*%bqq)B8&G(L>v1=v3KR-(q!)d$>a;dh`9{ zEqB@H?zpU+dPYeoJYGYqf3?z8fWL%|iA=lZ2WT+|W7$wt7(~9>3*d5_NGZ`SxBHDb ze8gw5nPB6B&{LK4{7#YkGf~={Y^0@syNgz36#whCb)>iQy0-gd@RFk<~eo1}( zSM(||@G2xxRWRTM<>8aWdxGm3`*GN-qNER8q!}UgO(JeQNruXZ)7aeK_jH}FUt^lIE4TIaQFxOwks2VwK45!UoF?Qe@w_*ru_%T> zx6Cq9oEaY0sIXC4kqftfx`y|cyNG=A+ZL#=u`ts3I{|c0!)J}BV+}84(sP%LN@mLE z+7lRj`lL0+&&?1lBRZ0c7KAz>+n0v<%2OxMz*X%4n!h=bhJJ>*n2iNW{II#=dpfb; z=~DJpuwD>c!+SE5zNqwjb(~{G1?bzL)6#m5739)bI`pZq)6|?LO~zvzW2tTb_127y zxQ0WMHPb3!d`n=>t^}alo*nC1@Udh zL_2anHkgf;C+*x&jt<_I2Jv!r9?x(%|K z5jl-oy#EprWXR}x_xYwAPsi2`U<2UF|HMj_o6lg^T5 zbN>XF^}Y{n?3yznxQkJ$*gGESxW323jxs-&wO3!860cNI>Q1mBW6ncy~VHM#tar>XAx;So_u;)w6Eg5yqvr@LHTO3T8EOWg|`*;nE4 z1M83_&3|oN+@mz`FtM2Z+F(SbM^YR6qt}#HWs;K=n&#T3s;X@1VqMtzBS2f-0-r9$ z=l5Xo?9+pHS0rM>t>*;j?w&CA@iBXzh^Cq!kKeDJs^e+(bD%&Oo1Fu?LB`Y=LhUfYtPcEy&+cUbiKWU2&Me?`mjLH}Ps@T-)gp~Zd z;2aauX7U>yP8voiTW;~}X+N`!zhxn?>Dlkx5M5i_=CqcO%=>;E>ISz0H$k9F#l{Vf z<`~nauY>h%bf}hRnJVif@Ah-ES?~KY{7N}p0|h+r^+qbM6+IK&3ONMN+vT2r9&taV zPWAcDzg;tIS*|YgV_5y-FYB%+Z9#xL(UXDaF2Gdk&8t68!uU%N+vM)CejbRit_7j- z^Qh7@`i4xOh({%*lq*Px4hh9)5cQo%mojd!~ zOn0BH%k}Tw%%s#CKGa_ho;CLC^PJ9qxy6!)|BhT87MbR2>?__twD`lG>FtEb01S@@ z55<{&v+oF&9;}5yg%)3(9G=lX$+?WY63Uf`qKM;!=OK>8fwjHOjvfb3aa*Y&U=&~y zyLQdYL|hzd@a{VbXYK*uqwB|Z6h2pWXoa5he z#t2^ZlA<(>PEr^L3STwgwNwRHXanauZ5ow<;h&Bue zVjOSwdd)d%wSM98)c8KlPoW{3;?t#5FT5IJ@F{`K(WNJW15EMZ6)U+^&}C;- z>mU=F;$u?3yUwsCREv@S_5FR7Wln(NVl>SHGwV`xz=5mPO0%U)2G7<{n6=H?~{|9`;-qQd8 diff --git a/site/static/organisations/tokopedia.png b/site/static/organisations/tokopedia.png deleted file mode 100644 index 16fef7fe63b4c01ef4c3476c5a4ffebc8f8e6246..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3928 zcmXX}c|6oz9~}*mtwM;gMI%ednx)2UW-<0P$xc~HPsvi4K@stiWZy~ImxeKnhJ>-C zs8HcSDU^MU!TTFMpU=#ld%yRb^F8<6`_IIhn_~F5#kfHr5FZYUvIKsMfv+4F7#P*Q zx|V}LV30Y%8jZP0K#+0pdMu(ItC67rC*y!6j1IFYvjOdci2Fn=1xq9n5%oBL2q$9! zB!~!tHQ)glP()GyJQmS_LpERy8mtf$763`X!02$6V4nt{157}GLIV!b03ZPXiv@20 znz9uBe&9fz0(ih706}1jg45{p0*F8n-iSv6TNFGC5A*`80#an0%|{zl6M;1c>J3=M zG8;4vgKi)IOO_NB|F@2ynXrgJYoN~ZfI~Fm55|M}0Ub#-KByS8Tv70dMl6zrVNr}4 zjerr|Yz!QbrP+Xky)i{JVvuBG1dD}7Q%wLQvKbh0usQn}VKg)3OI9N!^}qlS7jVGl|11H?!00GI3P=FeWDKx?380Urq5&NwD+D|oAhL>h zAT%Hrn|&J={@{$LW|je9$#P4<>D8FRftzXs4vuG0fGvtKkRj{V4qzxMAo8~bOOwR~ zqGNexjmTzWSRRa3JOBe*$Ohmp{)4f)H)0K06qdt-5op9B0tWu0uYlUB`h3AOWLR6Euy0YBomE z2$*&=qgGQOC``L4rp**ZHAcT80Jn*GV}_*Sv7P4F4l^JVz&4t0g6%RVytgI{SmPMx z#_z1K9p<=hi}QXbl7N>z7GP;=1=?h8aBS_cgV_#o9@=Kx{c}ikZ!Kbja`}kjx*=CC z$Kl;WZ3`Xq#+0`^d*jpSP1~=b9P6_35XYtMKk3_t#csB*9OmaPhru`QiS$qY=uS|L zwk)hqJxuFMO;NTJsbCuzN2T}q44U&kaLo_PGhR44_n z#T$43bSvpSPx_4j=~S050pS1D4M~0~J&WTD_RY$tUf9g;2~^0din_X$QM3Et6xY

tm=w9XJcS+^&i#Ord_HG%0Dns4fc}25j z`*kaZH=x>!_ax*wJ?mNu%0CsgYIOZ}M57(Pc1bwdKrE83B(KNWofcF`ch9``rKf_p zK+zZrBzIte-^aqAO||cxt6Q5w3RkC%mz&wNFU$r{RVzC z45GdF%g!SP4#o!>gH*a(!R0;uxjCze1ebWW?xI^^)1+yyToA!;b8Gqe%DpU&dOqFV z05}}}n5nsyA~gDsUFQj0iVtyT^w)%Ar3@$9a{AT8^;V3PbMhTkE&nehxzjP)Vfy9C z_7W@nJ)C|fouA_D&qj0e_iH9-yZi#PjakG6e63xG$4k$rOSrwssS$Hu+SI8}I%BKU z*S$bWFsuvD^t^-*$qaah#fHZ%t63Ws|7;yPRL8zKyjdt^~GiJooj17>x*Gf5wS9AH#+xFGkeu6YeBb zC)VACq5n+3*D%C@Er-&|n5!Wk?u#7$W|erV+@pxxwr$CYENO}K++oAm<|IDmZ^ilY zScNo1A^kbD1zDqOP%vbFO(7gt8W;aNXi{3bH7>B=a2($QvDY?QCl`3EVlCds=qps> zhoXXIJvSeSX@vMQiWxnEoV`K6 z^YLPAi3;IR*JOVtN&W>yd0e{?L-9#%TH*~>lH3<*@A1_!7ztlVJzAx8RsDucl8Url z@#x?y)gQU4xkFa289d;Gqw+PP2@Xul_p*78T!riYWd!7(&|}zHU4v52HNB?`3{=yP z>ZF*bq%&cDDbxTJLF5u4p1bak8X4`{;-D8CV3D4`q4H4Oj6v4;C?RSt^jnq^CV)ap zWrgKskKQo;bk@W5wwt6w?qQ^o!BWGM1 zbGu)GI)}Hb!jWFOG7c$@`Si(8y#mSt`&?vPOJC1?e8G1E>`9M4TGEF~;dbkoMszO6 z+Og85ADz;dNS7j$lWf_pS}O(!F@|>LXPnbr5FLlVznowbxp`*p@y|B?LIO?J(nln@ zJ8ntJi+BM#D!=S>I+%Cfw%y3AfIh2L)WdZJYEe)1(w(XqpRLx{5emYk3*H1dcT`9EqflCAZ!IzHl)S3amI|vfw(U)Bo?u>=#EDP6g&*ZCQs@%) zQ_C@3?Vbp?{mR(ZxtOXb2#2qR2i-QwLsoVtn9FPH4t;>;SDM?+UH^d=)Y}t%nig*# zzu=mvCmG3ulBmsH<|OKi5ntTVPt!zRl($?NP0nrW&GG*n@~A5B*OwaiLEkJdZmDa0 z4?bhhz57VY-JY$NZ4PPne009j6Pj~YhC_KC(l_uG^04AswVrR2jTd;k<$493odclw^!UMVJ0{HM%S2J!;NtcV^bz zxeEJ7T3OmM^B9wjYxZ0o539%gu6VyEW0VFSMJtY zt>LWH?gu;QpR!xFSvM5M#OW%)TV-9L0jh%#l1o?n?Hn?{u5v#LT4>Qx*d?C9$HgzA zW?rz(yk=DYhaECEI zF33@X@Y+?un@hpzqKi5g(z;EF{il+HdX^ZRlY= z*bLK8{HVdD2JIfr;u|R9??#tpXX>v&5V+*c=lpAqhsT?)9dXQT;B4LIk4r0Catz^bYd26k&fU)sCn@= zuYa0a6tla2ppT(*JIgaAo{hOxZ_|!zA$Dl%6tM?HqN}FQMQ9gDd*}_uS%}@%BhP2p!#=AHC;g0kXZv?1)qZOnHBbv2t=wE6LH4P% zZ8hC13ht4mBgC_r?yH(S4g(lj?Rlk#XV zo|iEaVnLVFz|~P0&&21Th!_Q#Khbmamf{ZI*fpNY%i4o={y$wVI&#UCJ^>9%)*n|Q zP%A(ss&|9kjorDupZZY*wK?DG5eAnBG(onSbW`2J?|KO}3TMaj8}Zu)w#}bLxu-aKd~!|_N#!qT{~$`k + + + From 77e3605c3947b51da32ea0fdfd9fb44a707e8a86 Mon Sep 17 00:00:00 2001 From: Infant Frontender <34810942+newbornfrontender@users.noreply.github.com> Date: Wed, 2 Oct 2019 12:39:46 +0300 Subject: [PATCH 007/413] Fix typo customElements -> customElement --- site/content/docs/03-run-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 8e56f4ce59..551945eade 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -945,7 +945,7 @@ app.count += 1; --- -Svelte components can also be compiled to custom elements (aka web components) using the `customElements: true` compiler option. You should specify a tag name for the component using the `` [element](docs#svelte_options). +Svelte components can also be compiled to custom elements (aka web components) using the `customElement: true` compiler option. You should specify a tag name for the component using the `` [element](docs#svelte_options). ```html From 5fd2a1c499b1bad9d6c52d099d06b7419dfc2a1d Mon Sep 17 00:00:00 2001 From: Mikhail Khorpyakov Date: Tue, 1 Oct 2019 13:15:53 +0300 Subject: [PATCH 008/413] Whos using: added SQL Tribe logo --- .../routes/_components/WhosUsingSvelte.svelte | 1 + site/static/organisations/sqltribe.svg | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 site/static/organisations/sqltribe.svg diff --git a/site/src/routes/_components/WhosUsingSvelte.svelte b/site/src/routes/_components/WhosUsingSvelte.svelte index f1a1585506..fdef19e802 100644 --- a/site/src/routes/_components/WhosUsingSvelte.svelte +++ b/site/src/routes/_components/WhosUsingSvelte.svelte @@ -74,6 +74,7 @@ Pankod logo Razorpay logo Socialist Party logo + SQL Tribe logo Stone Payments logo Strix Cloud logoStrix Cloud Sucuri logo diff --git a/site/static/organisations/sqltribe.svg b/site/static/organisations/sqltribe.svg new file mode 100644 index 0000000000..2a51dfc0a7 --- /dev/null +++ b/site/static/organisations/sqltribe.svg @@ -0,0 +1,106 @@ + +image/svg+xml \ No newline at end of file From def776520f3d8f0d0cb9707ee06db50b8cf93586 Mon Sep 17 00:00:00 2001 From: AlexxNB Date: Mon, 23 Sep 2019 17:30:30 +0300 Subject: [PATCH 009/413] bump @sveltejs/site-kit version --- site/package-lock.json | 6 +++--- site/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/site/package-lock.json b/site/package-lock.json index 189068b42d..526f53f163 100644 --- a/site/package-lock.json +++ b/site/package-lock.json @@ -1281,9 +1281,9 @@ } }, "@sveltejs/site-kit": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.1.3.tgz", - "integrity": "sha512-cJfz45cqq1nfPnk1V3oYVMcSySI/GnbHyvr+vQAyHhmOpmknO3pYavXDj545YXWJvEXg2sk8Fxcah+Z/56Ka0Q==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@sveltejs/site-kit/-/site-kit-1.1.4.tgz", + "integrity": "sha512-PsFUX1C/fhV0ODdCJaEQ8OwzgmaPJVmdefiSYA+i6zttBeV19d/ow+l7SPMXxBkux+vUIl5can4BwValCukCsw==", "dev": true, "requires": { "@sindresorhus/slugify": "^0.9.1", diff --git a/site/package.json b/site/package.json index 3f362ac891..e6c31f6bc8 100644 --- a/site/package.json +++ b/site/package.json @@ -35,7 +35,7 @@ "@babel/preset-env": "^7.6.0", "@babel/runtime": "^7.6.0", "@sindresorhus/slugify": "^0.9.1", - "@sveltejs/site-kit": "^1.1.3", + "@sveltejs/site-kit": "^1.1.4", "@sveltejs/svelte-repl": "^0.1.9", "degit": "^2.1.4", "dotenv": "^8.1.0", From 482a572e6a6450a20115eb621ef4e8e39ab6bc11 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 6 Oct 2019 13:30:10 +0800 Subject: [PATCH 010/413] show generated output if the error message does not match --- test/runtime/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/runtime/index.js b/test/runtime/index.js index 880e316e0c..f23379cd88 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -192,10 +192,12 @@ describe("runtime", () => { assert.equal(config.error, err.message); } } else { - failed.add(dir); - showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console throw err; } + }).catch(err => { + failed.add(dir); + showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console + throw err; }) .then(() => { if (config.show) { From d54ef0ca0c1f3db3fad45cd34b8722264e14d0f9 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 6 Oct 2019 13:55:16 +0800 Subject: [PATCH 011/413] should throw error if createEventDispatch is used after instantiation --- src/runtime/internal/lifecycle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index 0ca3e4306d..d5938874fc 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -28,7 +28,7 @@ export function onDestroy(fn) { } export function createEventDispatcher() { - const component = current_component; + const component = get_current_component(); return (type, detail) => { const callbacks = component.$$.callbacks[type]; From 52c086b1b9f814ca2c8bc7a9742b5e43d69ebe81 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 9 Oct 2019 12:41:08 -0400 Subject: [PATCH 012/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7abca9a0a..a08385671a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) +* Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) ## 3.12.1 From 7d9262c4216f9d779790a33c170e913386ef4456 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 10 Oct 2019 00:56:20 +0800 Subject: [PATCH 013/413] fix reactive updates not reflected when handle promise (#3660) --- src/runtime/internal/await_block.ts | 8 ++++++- .../_config.js | 13 ++++++++++++ .../main.svelte | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-set-simultaneous-reactive/_config.js create mode 100644 test/runtime/samples/await-set-simultaneous-reactive/main.svelte diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts index 4037caa98e..6cd7ee5cb4 100644 --- a/src/runtime/internal/await_block.ts +++ b/src/runtime/internal/await_block.ts @@ -14,6 +14,8 @@ export function handle_promise(promise, info) { const child_ctx = assign(assign({}, info.ctx), info.resolved); const block = type && (info.current = type)(child_ctx); + let needs_flush = false; + if (info.block) { if (info.blocks) { info.blocks.forEach((block, i) => { @@ -33,11 +35,15 @@ export function handle_promise(promise, info) { transition_in(block, 1); block.m(info.mount(), info.anchor); - flush(); + needs_flush = true; } info.block = block; if (info.blocks) info.blocks[index] = block; + + if (needs_flush) { + flush(); + } } if (is_promise(promise)) { diff --git a/test/runtime/samples/await-set-simultaneous-reactive/_config.js b/test/runtime/samples/await-set-simultaneous-reactive/_config.js new file mode 100644 index 0000000000..a591bf424f --- /dev/null +++ b/test/runtime/samples/await-set-simultaneous-reactive/_config.js @@ -0,0 +1,13 @@ +export default { + html: `

wait for it...

`, + test({ assert, component, target }) { + + return component.promise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the answer is 42!

+

the answer100 is 4200!

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-set-simultaneous-reactive/main.svelte b/test/runtime/samples/await-set-simultaneous-reactive/main.svelte new file mode 100644 index 0000000000..c1bbac66be --- /dev/null +++ b/test/runtime/samples/await-set-simultaneous-reactive/main.svelte @@ -0,0 +1,21 @@ + + +{#if promise} + {#await promise} +

wait for it...

+ {:then _} +

the answer is {answer}!

+

the answer100 is {answer100}!

+ {:catch error} +

well that's odd

+ {/await} +{/if} \ No newline at end of file From 40284d0a9b4e1a4dbf83a1afc385eb0421bfc685 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 9 Oct 2019 13:00:41 -0400 Subject: [PATCH 014/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a08385671a..42ee4c7174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) +* Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) ## 3.12.1 From 8206c27c0a8af28505c55470bd48acde1b5b6277 Mon Sep 17 00:00:00 2001 From: Sercan Eraslan Date: Tue, 1 Oct 2019 10:10:53 +0300 Subject: [PATCH 015/413] Fix: lifecycle update example overflow problem --- site/content/tutorial/07-lifecycle/03-update/app-a/App.svelte | 1 + site/content/tutorial/07-lifecycle/03-update/app-b/App.svelte | 1 + 2 files changed, 2 insertions(+) diff --git a/site/content/tutorial/07-lifecycle/03-update/app-a/App.svelte b/site/content/tutorial/07-lifecycle/03-update/app-a/App.svelte index 75fce63ca2..d8c4caabef 100644 --- a/site/content/tutorial/07-lifecycle/03-update/app-a/App.svelte +++ b/site/content/tutorial/07-lifecycle/03-update/app-a/App.svelte @@ -88,6 +88,7 @@ background-color: #0074D9; color: white; border-radius: 1em 1em 0 1em; + word-break: break-all; } diff --git a/site/content/tutorial/07-lifecycle/03-update/app-b/App.svelte b/site/content/tutorial/07-lifecycle/03-update/app-b/App.svelte index 3eb2dceb52..bdf42e28a9 100644 --- a/site/content/tutorial/07-lifecycle/03-update/app-b/App.svelte +++ b/site/content/tutorial/07-lifecycle/03-update/app-b/App.svelte @@ -88,6 +88,7 @@ background-color: #0074D9; color: white; border-radius: 1em 1em 0 1em; + word-break: break-all; } From 44c1b6f23d835823957dd25b66c90b2ff64e7170 Mon Sep 17 00:00:00 2001 From: mustafa0x Date: Tue, 24 Sep 2019 22:56:55 +0300 Subject: [PATCH 016/413] add `location` to globals --- src/compiler/utils/names.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/utils/names.ts b/src/compiler/utils/names.ts index 8d9150bc18..86cd686564 100644 --- a/src/compiler/utils/names.ts +++ b/src/compiler/utils/names.ts @@ -23,6 +23,7 @@ export const globals = new Set([ 'isNaN', 'JSON', 'localStorage', + 'location', 'Map', 'Math', 'NaN', From 729bb12d175dbc3003be6d159f54d1af03b8359d Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 9 Oct 2019 13:08:16 -0400 Subject: [PATCH 017/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ee4c7174..6363e0b337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) From 0eb825b45804ab56cac52763b064b06a673ff4a5 Mon Sep 17 00:00:00 2001 From: davidaq Date: Sun, 22 Sep 2019 22:31:53 +0800 Subject: [PATCH 018/413] Change HTMLElement type check Fix HTMLElement class extending problem for iOS 8 and 9 --- src/runtime/internal/Component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index ae80ae38c1..2d5795eccb 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -133,7 +133,7 @@ export function init(component, options, instance, create_fragment, not_equal, p } export let SvelteElement; -if (typeof HTMLElement !== 'undefined') { +if (typeof HTMLElement === 'function') { SvelteElement = class extends HTMLElement { $$: T$$; constructor() { From 1fce4c6931d2ff804b45b3cdf7f93746c890c531 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 9 Oct 2019 13:11:54 -0400 Subject: [PATCH 019/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6363e0b337..cef7c34a3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) From 0831887ef91b3a3a2439722bf95c0d367bac926d Mon Sep 17 00:00:00 2001 From: Chris Helgert Date: Mon, 7 Oct 2019 10:47:37 +0200 Subject: [PATCH 020/413] chore: resolve TODO for reusing of TransitionConfig But also provide the possibility to override the props and also keeps the namespace to provide breaking changes. --- src/runtime/animate/index.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/runtime/animate/index.ts b/src/runtime/animate/index.ts index d00d23c98d..ed6764a32c 100644 --- a/src/runtime/animate/index.ts +++ b/src/runtime/animate/index.ts @@ -1,14 +1,8 @@ import { cubicOut } from 'svelte/easing'; import { is_function } from 'svelte/internal'; +import { TransitionConfig } from 'svelte/transition'; -// todo: same as Transition, should it be shared? -export interface AnimationConfig { - delay?: number; - duration?: number; - easing?: (t: number) => number; - css?: (t: number, u: number) => string; - tick?: (t: number, u: number) => void; -} +export interface AnimationConfig extends TransitionConfig {} interface FlipParams { delay: number; From 30bf5fe95854d8b82620a537fee8e997419ae167 Mon Sep 17 00:00:00 2001 From: Chris Helgert Date: Mon, 7 Oct 2019 10:48:55 +0200 Subject: [PATCH 021/413] chore: resolve implicit any in animate/index.ts --- src/runtime/animate/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/animate/index.ts b/src/runtime/animate/index.ts index ed6764a32c..eafa8c9cfd 100644 --- a/src/runtime/animate/index.ts +++ b/src/runtime/animate/index.ts @@ -21,7 +21,7 @@ export function flip(node: Element, animation: { from: DOMRect; to: DOMRect }, p const { delay = 0, - duration = d => Math.sqrt(d) * 120, + duration = (d: number) => Math.sqrt(d) * 120, easing = cubicOut } = params; From 43245a30fd051904f90b80cebbcc97d38c4484ee Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 11 Oct 2019 14:19:47 -0400 Subject: [PATCH 022/413] Revert "chore: resolve TODO for reusing of TransitionConfig" This reverts commit 0831887ef91b3a3a2439722bf95c0d367bac926d. This was causing TypeScript linting errors, and can be revisited at another time. --- src/runtime/animate/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/runtime/animate/index.ts b/src/runtime/animate/index.ts index eafa8c9cfd..071b6b199d 100644 --- a/src/runtime/animate/index.ts +++ b/src/runtime/animate/index.ts @@ -1,8 +1,14 @@ import { cubicOut } from 'svelte/easing'; import { is_function } from 'svelte/internal'; -import { TransitionConfig } from 'svelte/transition'; -export interface AnimationConfig extends TransitionConfig {} +// todo: same as Transition, should it be shared? +export interface AnimationConfig { + delay?: number; + duration?: number; + easing?: (t: number) => number; + css?: (t: number, u: number) => string; + tick?: (t: number, u: number) => void; +} interface FlipParams { delay: number; From 57aeddcf859ffe474f17dbfbe484d2c4a048019c Mon Sep 17 00:00:00 2001 From: pngwn Date: Fri, 11 Oct 2019 14:20:54 +0100 Subject: [PATCH 023/413] Prevent element property set from throwing errors for readonly properties. Fixes #3681. --- CHANGELOG.md | 1 + src/runtime/internal/dom.ts | 4 +++- test/runtime/samples/spread-element-readonly/_config.js | 9 +++++++++ test/runtime/samples/spread-element-readonly/main.svelte | 9 +++++++++ .../samples/spread-attributes/_expected.html | 1 + .../samples/spread-attributes/main.svelte | 9 +++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-element-readonly/_config.js create mode 100644 test/runtime/samples/spread-element-readonly/main.svelte create mode 100644 test/server-side-rendering/samples/spread-attributes/_expected.html create mode 100644 test/server-side-rendering/samples/spread-attributes/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index cef7c34a3d..8e2b73a199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) +* Fix error resulting from trying to set a read-only property when spreading element attributes ([#3681](https://github.com/sveltejs/svelte/issues/3681)) ## 3.12.1 diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 58a0d0729a..1c904fe2a3 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -90,10 +90,12 @@ export function attr(node: Element, attribute: string, value?: string) { } export function set_attributes(node: Element & ElementCSSInlineStyle, attributes: { [x: string]: string }) { + // @ts-ignore + const descriptors = Object.getOwnPropertyDescriptors(node.__proto__); for (const key in attributes) { if (key === 'style') { node.style.cssText = attributes[key]; - } else if (key in node) { + } else if (descriptors[key] && descriptors[key].set) { node[key] = attributes[key]; } else { attr(node, key, attributes[key]); diff --git a/test/runtime/samples/spread-element-readonly/_config.js b/test/runtime/samples/spread-element-readonly/_config.js new file mode 100644 index 0000000000..1d349fd76f --- /dev/null +++ b/test/runtime/samples/spread-element-readonly/_config.js @@ -0,0 +1,9 @@ +export default { + skip_if_ssr: true, // DOM and SSR output is different, a separate SSR test exists + html: ``, + + test({ assert, target }) { + const div = target.querySelector('input'); + assert.equal(div.value, 'bar'); + } +}; diff --git a/test/runtime/samples/spread-element-readonly/main.svelte b/test/runtime/samples/spread-element-readonly/main.svelte new file mode 100644 index 0000000000..fc8c849396 --- /dev/null +++ b/test/runtime/samples/spread-element-readonly/main.svelte @@ -0,0 +1,9 @@ + + + diff --git a/test/server-side-rendering/samples/spread-attributes/_expected.html b/test/server-side-rendering/samples/spread-attributes/_expected.html new file mode 100644 index 0000000000..b78eafb8f4 --- /dev/null +++ b/test/server-side-rendering/samples/spread-attributes/_expected.html @@ -0,0 +1 @@ + diff --git a/test/server-side-rendering/samples/spread-attributes/main.svelte b/test/server-side-rendering/samples/spread-attributes/main.svelte new file mode 100644 index 0000000000..fc8c849396 --- /dev/null +++ b/test/server-side-rendering/samples/spread-attributes/main.svelte @@ -0,0 +1,9 @@ + + + From d3e815c20973824345af5376bd5037e5488bdec0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 11 Oct 2019 18:49:11 -0400 Subject: [PATCH 024/413] lint during CI --- .github/workflows/ci.yml | 6 ++++++ site/.eslintrc.js | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98897c5740..2e035c86b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,3 +16,9 @@ jobs: - run: 'npm i && npm test' env: CI: true + Lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + - run: 'npm i && npm run lint' diff --git a/site/.eslintrc.js b/site/.eslintrc.js index a436f7bbe4..255b8af9c5 100644 --- a/site/.eslintrc.js +++ b/site/.eslintrc.js @@ -47,6 +47,12 @@ module.exports = { }, settings: { 'import/core-modules': ['svelte'], - 'svelte3/compiler': require('svelte/compiler') + 'svelte3/compiler': (() => { + try { + return require('svelte/compiler'); + } catch (e) { + return null; + } + })() } }; From dcfe9f6b78be4d5b51cc1ec99aa5bfb43b99643f Mon Sep 17 00:00:00 2001 From: adrian5 Date: Fri, 11 Oct 2019 12:27:58 +0200 Subject: [PATCH 025/413] Doc: add file-type association instructions for Atom --- .../blog/2019-04-15-setting-up-your-editor.md | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/site/content/blog/2019-04-15-setting-up-your-editor.md b/site/content/blog/2019-04-15-setting-up-your-editor.md index bea7f4c762..5309a3714e 100644 --- a/site/content/blog/2019-04-15-setting-up-your-editor.md +++ b/site/content/blog/2019-04-15-setting-up-your-editor.md @@ -10,7 +10,25 @@ draft: true * eslint-plugin-svelte3 * svelte-vscode -* associating .svelte files with HTML in VSCode, Sublime, Atom, etc etc etc +* associating .svelte files with HTML in VSCode, Sublime, etc. + +## Atom + +To treat `.svelte` files as HTML, install the *file-types* package which enables such custom mappings: + +```bash +apm install file-types +``` + +From the toolbar, open Edit → Config... and add the following two lines to your root (`"*"`) section: + +```cson +"*": + core: + … + "file-types": + "*.svelte": "text.html.basic" +``` ## Vim/Neovim From c7cc6a55cfb5482575cdad7a94f2d57cef37c733 Mon Sep 17 00:00:00 2001 From: Sercan Eraslan Date: Tue, 1 Oct 2019 10:07:39 +0300 Subject: [PATCH 026/413] Fix: dimensions example overflow problem --- site/content/tutorial/06-bindings/11-dimensions/app-a/App.svelte | 1 + site/content/tutorial/06-bindings/11-dimensions/app-b/App.svelte | 1 + 2 files changed, 2 insertions(+) diff --git a/site/content/tutorial/06-bindings/11-dimensions/app-a/App.svelte b/site/content/tutorial/06-bindings/11-dimensions/app-a/App.svelte index 59e11c79f0..62e92cd536 100644 --- a/site/content/tutorial/06-bindings/11-dimensions/app-a/App.svelte +++ b/site/content/tutorial/06-bindings/11-dimensions/app-a/App.svelte @@ -8,6 +8,7 @@ diff --git a/site/content/tutorial/06-bindings/11-dimensions/app-b/App.svelte b/site/content/tutorial/06-bindings/11-dimensions/app-b/App.svelte index ca992599c1..920c74d276 100644 --- a/site/content/tutorial/06-bindings/11-dimensions/app-b/App.svelte +++ b/site/content/tutorial/06-bindings/11-dimensions/app-b/App.svelte @@ -8,6 +8,7 @@ From 0d20fb9b8d54daa67da472cc3a2cba8c85e782e2 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 11 Oct 2019 22:23:28 -0400 Subject: [PATCH 027/413] site: fix unknown syntax highlighting language in blog post --- site/content/blog/2019-04-15-setting-up-your-editor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/blog/2019-04-15-setting-up-your-editor.md b/site/content/blog/2019-04-15-setting-up-your-editor.md index 5309a3714e..8301928f33 100644 --- a/site/content/blog/2019-04-15-setting-up-your-editor.md +++ b/site/content/blog/2019-04-15-setting-up-your-editor.md @@ -22,7 +22,7 @@ apm install file-types From the toolbar, open Edit → Config... and add the following two lines to your root (`"*"`) section: -```cson +```html "*": core: … From 1a2af80818ff22f99cb1dbcc1fa91d2d5f9a8645 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 12 Oct 2019 07:32:53 -0400 Subject: [PATCH 028/413] site: handle unknown/missing markdown code block syntax languages --- site/src/routes/blog/_posts.js | 16 +++------------- site/src/routes/docs/_sections.js | 14 +++----------- site/src/routes/tutorial/[slug]/index.json.js | 13 +++---------- site/src/utils/highlight.js | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 34 deletions(-) create mode 100644 site/src/utils/highlight.js diff --git a/site/src/routes/blog/_posts.js b/site/src/routes/blog/_posts.js index d180ebd35e..2c86e13656 100644 --- a/site/src/routes/blog/_posts.js +++ b/site/src/routes/blog/_posts.js @@ -1,11 +1,10 @@ import fs from 'fs'; import path from 'path'; -import { extract_frontmatter, langs, link_renderer } from '@sveltejs/site-kit/utils/markdown.js'; +import { extract_frontmatter, link_renderer } from '@sveltejs/site-kit/utils/markdown.js'; import marked from 'marked'; import { makeSlugProcessor } from '../../utils/slug'; +import { highlight } from '../../utils/highlight'; import { SLUG_PRESERVE_UNICODE } from '../../../config'; -import PrismJS from 'prismjs'; -import 'prismjs/components/prism-bash'; const makeSlug = makeSlugProcessor(SLUG_PRESERVE_UNICODE); @@ -32,16 +31,7 @@ export default function get_posts() { renderer.link = link_renderer; - renderer.code = (source, lang) => { - const plang = langs[lang]; - const highlighted = PrismJS.highlight( - source, - PrismJS.languages[plang], - lang, - ); - - return `
${highlighted}
`; - }; + renderer.code = highlight; renderer.heading = (text, level, rawtext) => { const fragment = makeSlug(rawtext); diff --git a/site/src/routes/docs/_sections.js b/site/src/routes/docs/_sections.js index 35edc16cfa..bb081a050b 100644 --- a/site/src/routes/docs/_sections.js +++ b/site/src/routes/docs/_sections.js @@ -1,11 +1,10 @@ import fs from 'fs'; import path from 'path'; import { SLUG_PRESERVE_UNICODE, SLUG_SEPARATOR } from '../../../config'; -import { extract_frontmatter, extract_metadata, langs, link_renderer } from '@sveltejs/site-kit/utils/markdown.js'; +import { extract_frontmatter, extract_metadata, link_renderer } from '@sveltejs/site-kit/utils/markdown.js'; import { make_session_slug_processor } from '@sveltejs/site-kit/utils/slug'; +import { highlight } from '../../utils/highlight'; import marked from 'marked'; -import PrismJS from 'prismjs'; -import 'prismjs/components/prism-bash'; const blockTypes = [ 'blockquote', @@ -73,14 +72,7 @@ export default function() { if (meta && meta.hidden) return ''; - const plang = langs[lang]; - const highlighted = PrismJS.highlight( - source, - PrismJS.languages[plang], - lang - ); - - const html = `
${prefix}
${highlighted}
`; + const html = `
${prefix}${highlight(source, lang)}
`; if (block_open) { block_open = false; diff --git a/site/src/routes/tutorial/[slug]/index.json.js b/site/src/routes/tutorial/[slug]/index.json.js index 291760bc6b..26f5d54b31 100644 --- a/site/src/routes/tutorial/[slug]/index.json.js +++ b/site/src/routes/tutorial/[slug]/index.json.js @@ -1,9 +1,9 @@ import * as fs from 'fs'; import * as path from 'path'; import marked from 'marked'; -import PrismJS from 'prismjs'; import send from '@polka/send'; -import { extract_frontmatter, extract_metadata, langs, link_renderer } from '@sveltejs/site-kit/utils/markdown'; +import { extract_frontmatter, extract_metadata, link_renderer } from '@sveltejs/site-kit/utils/markdown'; +import { highlight } from '../../../utils/highlight'; const cache = new Map(); @@ -57,14 +57,7 @@ function get_tutorial(slug) { } } - const plang = langs[lang]; - const highlighted = PrismJS.highlight( - source, - PrismJS.languages[plang], - lang - ); - - return `
${prefix}
${highlighted}
`; + return `
${prefix}${highlight(source, lang)}
`; }; let html = marked(content, { renderer }); diff --git a/site/src/utils/highlight.js b/site/src/utils/highlight.js new file mode 100644 index 0000000000..d8be46b3a6 --- /dev/null +++ b/site/src/utils/highlight.js @@ -0,0 +1,14 @@ +import { langs } from '@sveltejs/site-kit/utils/markdown.js'; +import PrismJS from 'prismjs'; +import 'prismjs/components/prism-bash'; + +export function highlight(source, lang) { + const plang = langs[lang] || ''; + const highlighted = plang ? PrismJS.highlight( + source, + PrismJS.languages[plang], + lang, + ) : source.replace(/[&<>]/g, c => ({ '&': '&', '<': '<', '>': '>' })[c]); + + return `
${highlighted}
`; +} From 8d5b7e0ef3add1ad47a14f1b7766ddfbd2b2207a Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 12 Oct 2019 07:33:26 -0400 Subject: [PATCH 029/413] site: tidy a few markdown code block languages --- site/content/blog/2019-04-15-setting-up-your-editor.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/content/blog/2019-04-15-setting-up-your-editor.md b/site/content/blog/2019-04-15-setting-up-your-editor.md index 8301928f33..784ca8703c 100644 --- a/site/content/blog/2019-04-15-setting-up-your-editor.md +++ b/site/content/blog/2019-04-15-setting-up-your-editor.md @@ -22,7 +22,7 @@ apm install file-types From the toolbar, open Edit → Config... and add the following two lines to your root (`"*"`) section: -```html +```cson "*": core: … @@ -34,18 +34,18 @@ From the toolbar, open Edit → Config... and add the following two lines to you To treat all `*.svelte` files as HTML, add the following line to your `init.vim`: -```bash +``` au! BufNewFile,BufRead *.svelte set ft=html ``` To temporarily turn on HTML syntax highlighting for the current buffer, use: -```bash +``` :set ft=html ``` To set the filetype for a single file, use a [modeline](https://vim.fandom.com/wiki/Modeline_magic): -```bash +``` ``` From e4d7f7745338852fb28cc9aa8354fc817966400f Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Sat, 12 Oct 2019 07:17:42 -0500 Subject: [PATCH 030/413] site: add missing word --- site/content/docs/02-template-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index b878f1453e..da731d920a 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -1380,7 +1380,7 @@ As with ``, this element allows you to add listeners to events on --- -This element makes it possible to insert elements into `document.head`. During server-side rendering, `head` content exposed separately to the main `html` content. +This element makes it possible to insert elements into `document.head`. During server-side rendering, `head` content is exposed separately to the main `html` content. ```html From a778e50b35474d764369f8adc4dec447968a9f39 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 12 Oct 2019 20:32:11 +0800 Subject: [PATCH 031/413] fix globals shadowing template scope (#3674) --- src/compiler/compile/nodes/shared/Expression.ts | 4 ++-- .../samples/globals-shadowed-by-each-binding/_config.js | 3 +++ .../samples/globals-shadowed-by-each-binding/main.svelte | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/globals-shadowed-by-each-binding/_config.js create mode 100644 test/runtime/samples/globals-shadowed-by-each-binding/main.svelte diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index a5a730c4d1..7c7dad5e6c 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -127,7 +127,7 @@ export default class Expression { if (scope.has(name)) return; - if (globals.has(name) && !component.var_lookup.has(name)) return; + if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return; if (name[0] === '$' && template_scope.names.has(name.slice(1))) { component.error(node, { @@ -261,7 +261,7 @@ export default class Expression { const { name, nodes } = flatten_reference(node); if (scope.has(name)) return; - if (globals.has(name) && !component.var_lookup.has(name)) return; + if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return; if (function_expression) { if (template_scope.names.has(name)) { diff --git a/test/runtime/samples/globals-shadowed-by-each-binding/_config.js b/test/runtime/samples/globals-shadowed-by-each-binding/_config.js new file mode 100644 index 0000000000..f69e5e8b0e --- /dev/null +++ b/test/runtime/samples/globals-shadowed-by-each-binding/_config.js @@ -0,0 +1,3 @@ +export default { + html: '

Alert1

Alert2

', +}; diff --git a/test/runtime/samples/globals-shadowed-by-each-binding/main.svelte b/test/runtime/samples/globals-shadowed-by-each-binding/main.svelte new file mode 100644 index 0000000000..3d0ac3f3ec --- /dev/null +++ b/test/runtime/samples/globals-shadowed-by-each-binding/main.svelte @@ -0,0 +1,7 @@ + + +{#each alerts as alert} +

{alert}

+{/each} From d0d3b342e8d4dfb2e46cd2b9aa674741cf341f40 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 12 Oct 2019 08:33:38 -0400 Subject: [PATCH 032/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e2b73a199..9b70b95125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) +* Fix globals shadowing contextual template scope ([#3674](https://github.com/sveltejs/svelte/issues/3674)) * Fix error resulting from trying to set a read-only property when spreading element attributes ([#3681](https://github.com/sveltejs/svelte/issues/3681)) ## 3.12.1 From 565931dff957545bf1b8a9ea57cfc097ed1a7e83 Mon Sep 17 00:00:00 2001 From: adrian5 Date: Sat, 12 Oct 2019 22:03:24 +0200 Subject: [PATCH 033/413] Doc: update file-type association instructions for Atom --- .../blog/2019-04-15-setting-up-your-editor.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/site/content/blog/2019-04-15-setting-up-your-editor.md b/site/content/blog/2019-04-15-setting-up-your-editor.md index 784ca8703c..1db85a7974 100644 --- a/site/content/blog/2019-04-15-setting-up-your-editor.md +++ b/site/content/blog/2019-04-15-setting-up-your-editor.md @@ -14,20 +14,16 @@ draft: true ## Atom -To treat `.svelte` files as HTML, install the *file-types* package which enables such custom mappings: - -```bash -apm install file-types -``` - -From the toolbar, open Edit → Config... and add the following two lines to your root (`"*"`) section: +To treat `*.svelte` files as HTML, open Edit → Config... and add the following lines to your `core` section: ```cson "*": core: … - "file-types": - "*.svelte": "text.html.basic" + customFileTypes: + "text.html.basic": [ + "svelte" + ] ``` ## Vim/Neovim From b02638b43d4fac0886dfacf261d429538f2fe349 Mon Sep 17 00:00:00 2001 From: Ryan Atkinson Date: Sat, 12 Oct 2019 17:52:43 -0500 Subject: [PATCH 034/413] fix type of derived store callback function --- src/runtime/store/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index eb2eda5779..0aff706a1b 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -128,7 +128,7 @@ type StoresValues = T extends Readable ? U : */ export function derived( stores: S, - fn: (values: StoresValues, set?: Subscriber) => T | Unsubscriber | void, + fn: (values: StoresValues, set: Subscriber) => T | Unsubscriber | void, initial_value?: T, ): Readable { From 4eb9affda1e7fd1a6ed6e4105b93e98dab44ff62 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 13 Oct 2019 14:15:25 +0800 Subject: [PATCH 035/413] fix debugging with no dependencies --- .../compile/render_dom/wrappers/DebugTag.ts | 26 ++-- .../samples/debug-no-dependencies/_config.js | 5 + .../samples/debug-no-dependencies/expected.js | 144 ++++++++++++++++++ .../debug-no-dependencies/input.svelte | 7 + 4 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 test/js/samples/debug-no-dependencies/_config.js create mode 100644 test/js/samples/debug-no-dependencies/expected.js create mode 100644 test/js/samples/debug-no-dependencies/input.svelte diff --git a/src/compiler/compile/render_dom/wrappers/DebugTag.ts b/src/compiler/compile/render_dom/wrappers/DebugTag.ts index 6705b51cc5..b78b7c8ab9 100644 --- a/src/compiler/compile/render_dom/wrappers/DebugTag.ts +++ b/src/compiler/compile/render_dom/wrappers/DebugTag.ts @@ -59,21 +59,19 @@ export default class DebugTagWrapper extends Wrapper { .join(', '); const logged_identifiers = this.node.expressions.map(e => e.node.name).join(', '); - block.builders.update.add_block(deindent` - if (${condition}) { - const { ${ctx_identifiers} } = ctx; - @_console.${log}({ ${logged_identifiers} }); - debugger; - } - `); + const debugStatements = deindent` + { + const { ${ctx_identifiers} } = ctx; + @_console.${log}({ ${logged_identifiers} }); + debugger; + } + `; - block.builders.create.add_block(deindent` - { - const { ${ctx_identifiers} } = ctx; - @_console.${log}({ ${logged_identifiers} }); - debugger; - } - `); + block.builders.update.add_block(condition ? deindent` + if (${condition}) ${debugStatements} + ` : debugStatements); + + block.builders.create.add_block(debugStatements); } } } diff --git a/test/js/samples/debug-no-dependencies/_config.js b/test/js/samples/debug-no-dependencies/_config.js new file mode 100644 index 0000000000..b1f2518e8a --- /dev/null +++ b/test/js/samples/debug-no-dependencies/_config.js @@ -0,0 +1,5 @@ +export default { + options: { + dev: true + } +}; \ No newline at end of file diff --git a/test/js/samples/debug-no-dependencies/expected.js b/test/js/samples/debug-no-dependencies/expected.js new file mode 100644 index 0000000000..4c168f23ce --- /dev/null +++ b/test/js/samples/debug-no-dependencies/expected.js @@ -0,0 +1,144 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponentDev, + destroy_each, + detach_dev, + dispatch_dev, + empty, + init, + insert_dev, + noop, + safe_not_equal, + space, + text +} from "svelte/internal"; + +const file = undefined; + +function get_each_context(ctx, list, i) { + const child_ctx = Object.create(ctx); + child_ctx.thing = list[i]; + child_ctx.index = i; + return child_ctx; +} + +// (4:0) {#each things as thing, index} +function create_each_block(ctx) { + var t0, t1_value = ctx.thing + "", t1; + + const block = { + c: function create() { + { + const { index } = ctx; + console.log({ index }); + debugger; + } + + t0 = space(); + t1 = text(t1_value); + }, + + m: function mount(target, anchor) { + insert_dev(target, t0, anchor); + insert_dev(target, t1, anchor); + }, + + p: function update(changed, ctx) { + { + const { index } = ctx; + console.log({ index }); + debugger; + } + }, + + d: function destroy(detaching) { + if (detaching) { + detach_dev(t0); + detach_dev(t1); + } + } + }; + dispatch_dev("SvelteRegisterBlock", { block, id: create_each_block.name, type: "each", source: "(4:0) {#each things as thing, index}", ctx }); + return block; +} + +function create_fragment(ctx) { + var each_1_anchor; + + let each_value = things; + + let each_blocks = []; + + for (let i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i)); + } + + const block = { + c: function create() { + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + each_1_anchor = empty(); + }, + + l: function claim(nodes) { + throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); + }, + + m: function mount(target, anchor) { + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insert_dev(target, each_1_anchor, anchor); + }, + + p: function update(changed, ctx) { + if (changed.things) { + each_value = things; + + let i; + for (i = 0; i < each_value.length; i += 1) { + const child_ctx = get_each_context(ctx, each_value, i); + + if (each_blocks[i]) { + each_blocks[i].p(changed, child_ctx); + } else { + each_blocks[i] = create_each_block(child_ctx); + each_blocks[i].c(); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].d(1); + } + each_blocks.length = each_value.length; + } + }, + + i: noop, + o: noop, + + d: function destroy(detaching) { + destroy_each(each_blocks, detaching); + + if (detaching) { + detach_dev(each_1_anchor); + } + } + }; + dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + return block; +} + +class Component extends SvelteComponentDev { + constructor(options) { + super(options); + init(this, options, null, create_fragment, safe_not_equal, []); + dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/debug-no-dependencies/input.svelte b/test/js/samples/debug-no-dependencies/input.svelte new file mode 100644 index 0000000000..b2f0200be0 --- /dev/null +++ b/test/js/samples/debug-no-dependencies/input.svelte @@ -0,0 +1,7 @@ + + +{#each things as thing, index} + {@debug index} + {thing} +{/each} \ No newline at end of file From 92cd56a3483f5138d77959da279769aa7004fb32 Mon Sep 17 00:00:00 2001 From: Niels Jacobs Date: Sun, 13 Oct 2019 13:30:50 +0200 Subject: [PATCH 036/413] site: add Jacoux logo --- .../routes/_components/WhosUsingSvelte.svelte | 1 + site/static/organisations/jacoux.png | Bin 0 -> 4978 bytes 2 files changed, 1 insertion(+) create mode 100644 site/static/organisations/jacoux.png diff --git a/site/src/routes/_components/WhosUsingSvelte.svelte b/site/src/routes/_components/WhosUsingSvelte.svelte index fdef19e802..fe9a2fcc9d 100644 --- a/site/src/routes/_components/WhosUsingSvelte.svelte +++ b/site/src/routes/_components/WhosUsingSvelte.svelte @@ -61,6 +61,7 @@ Grainger logo HealthTree logo itslearning logo + Jacoux logo Metrovias logo Mustlab logo Nesta logo diff --git a/site/static/organisations/jacoux.png b/site/static/organisations/jacoux.png new file mode 100644 index 0000000000000000000000000000000000000000..6d3f52017c86c4d20f35949861dacc2f14d7cb8f GIT binary patch literal 4978 zcmbVQ2UOEbvkxkuND%>})F^5clu$&3&=fE#O{9Ym1B9Lgk`NLIph84Jg=?V~1x1>4 zLJOcs2SJGRb|XRr1VV2CUcB$Vd%pM1_wM`Nch3B0c6MfeJ3F&`_U!-BO%s>^pEw@? z01&u-P5%}Ez;%<;{;+=!hmR!Yk~o43cMEm}kk=tO#ZeCUT(iXi0D|?uKCYMYf)W70 zp^fYMmo12cv&kNK%Lb_rV=$eq>pDbDie1D*!}EhyGxtk-opSa?mf!R^XjLUC?^&8+ z#rNJmhw3S|^1|x8)%);64}ac^ri7g;3I`O4Tmc=|B}Rw2Os<+729e?`+5#c-)rlM1 z9ozdVmgbTJL;PKLiW?*W1rLte0`9W@585vT_*?ql0KP!#+O}~GX}>x3#(p&msHK-D zwBL}Or!93D03AeUPC_90m6Zva_s$&{lLjJ%@HwO7(W;necox0C|B_SvLmQb4(^Qj5 z-6LT@NvS}a1P6$0G}B~+cG3_ zXq2Xn;G*it-d?LkKIJpyphx+v)(ruAb5+UE+~KIE7KP^bhf}aMsowq`9v;V=K;eU| z7fY|*-QD-2x440~b)Q~#rT9ylVTC&0wXGsPJ!sgY;@rruETDXzCNd^J>3DDH7&WLp zPRT{wMUNOeDfO*b_)==btlk6u1L&X zqL3A%&JoqDUJmeG7WH4?+f(ceV4)PKs1D3v$J82ht#+lumc+U0VBI8d-mtQUe}_li zT{0mHQTOUwtw(pXt(X@`fm-XrvB524#W1{?e8b=QrA$7GL$fD66hOXYN5zM&Q5Vv4D1 z>Fb`_>)8v%*;TyD^&J=B$hPAZGkO~vbf*Car%^TikBYyAJUT=AD-GGJD)! z)u1mTHKpoDLf?~>fe{(r%}4alauTIy$x5<(b^g9SS;LF|Ya1;n3>2njPIbFVG~4i5 zo0>^69!tMHDF=2HSQKjQkUn9x)13veTIG2+`*4_DwE1v71FmR+Y+HC=Axo1TvV7Sp znx^gdWp@fgHVN4*sv2&KddkW|SQ=}i>QZyXig{9fo#X8BZvv1_p7ll0P@!B6f6*t{ z=~&(`g~nF3a(oH`$u(QH9$B3S7!FU-RxgET{qol1;eN!j=G}Cx zficm@47A?A8{ch-3bEc*;L)6fGn)lF^RJiMVC@&DI;(HbCBGD@t0I+dKpG>qN6GnZ zIdN}vayEN@lrYTGYidTRXB+~;<}aO^bnKGj`TxCGkCHgpLb!0Rxs})ufdpZK$x4jKg z%erPTRj4IVH)9yr9jFIyA7ukR78^En%RKDfs_%xDTy5!0y|{DNK6isEI>`?-3^{XS z9@yYqe}880i=|FCI8klpqLGS;L{4(-dQ;VoR~%*$HZLE6fYw1*-Zom#5{)0??Ieb& zg|_c6V^`8mK4sV2;mJ|M3&EX`r?}k4xSH1ov)gbLQ{2q{nEJz2@2}78^xu>gf6_{0 zWm}fAu5OD3ullVibZjF7i?<*NI`%%*^Q8?1Qj8JnFE*PbQEE`W%V(E#i^$rUzG}JT zy^)obpFb;QhqtRPH6_!VX!O`Xw^NO0JESSr>gU6Y&e34Sx3#{&f+UPhf*#F_H57~x z7~@sj33TIo-Rc#)xAPtA%r0tYo|FP7PePV={W6DbeEU}r4-*}T&l&Vpi&ct$>g1r? zv$#*MK~Cab2Roh_`S`% z)sV^OUkW`xDf|w3!;~)Fd(BO#>mqG$53qy(gvmK@V8~#REY1Id{`24Ke^-VmmTG8W@hKXeaN&pYP22Z%7TqnCV~5%1l;ycXYV*eOMADh<6goItuEBkTaIwx4L>oGZa|`z<#3 zqzfLWvHDZ4GJ3we2or%;)qih=Pah_?%V#ahc$o|+p4am4FL8v6^8!s1F*(7r_Fl~y zthxMrHYJKRO={ti*QCBPUmqWOTquL$wb`*wiuu%NT}&*=D`C4ONRuDsRcoE-ArG;O z(2_HsDrCt_-3)mxR}rxAp(lu{dK_Vxb;L#2iQeX{ByvMiUNjDBIcV8 z*ObF=tWR5CXtC0Kp=Y_-y+x+Fs^3-uP?}at4noR|`}m>iey^;N%Dab0mc6$nv1ZC9 zeGhic1Lj!Gc0oYh2-JE{lt*60beZ}I+VJ+HkS}P40D@PQvoAFm$Z*$aBLgRRUM5*z z&3jHT=-FWK_?up-o<3N~gnfkBrh#k_li_Ae>7mRt1y@l&rvudRI=_th_-VYD1d94D)H- zD?QMrGVbm8P{UByJEr(?S=v(rS*b2@6k}^-l`8A`6w#vPDd4=ub+WX?@FYcz|Ar8b zzt`jRvPuavM5Q5ypcXE_0yI}rivMcSv~$PdC8I_6WAlec)n5Qrrftc<0ZyKM(ma0&PNV|??7uI zu517*M9uvhTJQ(oY>gClM5l5o^!MjX5!v(!ovxffeELFeqg*N~*5s%1YCELjv-51L zq*%?E*P`c?U+0RD><_XJVpVP&xFLp7&YYj~U80Ut`JzzQe6Pyr>U6CQN}Z4Xz`%Ma6EJv^z2+ZNX)1hxV!r z*tg2#-xjnyqvV#pX`)w*{Z5>0AH`s-4vu7xU^G|Hs^+B~x7P8Tken6g_c{)3rF3|f3_{#s5Y-3uxFvhCrCf9Oar^ z$_%laKdO5v80nL>=_Vf)-w|q*80LN%NN(et34dJfVEMtfh?)L#2UAHy&~10sM$NPz z!g3-AnOBfuVUP`Wyc{w4J zFnwBE(grl?AW?);ZY*aJtb6m~GIe}6Y<8of2{&rptdZ>sL!Du$Cq1v-)ggoWU1zqN zqaE`b;P+t-?W(e$$`hpKHz)u?&b`8q8TZRITBfbpP*y-}^o_u%(R(Q$X|1r$r+Ei9 z7L#tyGK;17q??MMP@w37-EWQCdz~X2)2l{n!TH7MN;OdHu+EIx7U)=tJvCMPbZg_x zsbO}XBL&B>e68l(YXS0Vmulm(vc=-&Z&oDScU*|}3>9@8IkqXC>sfpdL&%ZH7P2*N z6TUwA;6`nGwXfRQvZNZtow#WtJh*JD^x4+r8?V!*%+6#how5aWvw-}~1FAl_ zftJix?xq*Aqti~lp$y~W{PpDufJ0jI}jI_4LP9o{kODsLI z(P8+jokh6h-P@Vn%!t`8{HRx^?Rq~HL^GzszK}u~z>&0L6N1qs2Ci#0Q+-~R%&;81 zB%qr?>2w(4oRL`8QvSh0#l0X}H5JxGdd~6`i0ZvM>e^hx>MGDW(cu*aNsTVxm(cAE zi+VO|=Hoa^s{C=Jkeqva>oMmlag`R+rG`bN%(^AdLkrI}Z85ouYw(Lc`uMLK5et)5hV6 zl(H_4fKtl(R^KEGQ5jsi9S1N~vn}dyWkKfgfI4SrN9g(gKMy>TV;(S03kC7!<7;F&xziC9)^bDgr!`<|&(B61Gq?bMONXQZ ze@}lq`W0}OSLdd1ugm%~F#urCVGj!%yp6GuhBF4GfN;S$Ar*)yAI>im06$6=po%bt_5I`<^d)a&H-M|>Mmd%Z9Yw+1_uCz z#3MjNls6iuLDT~Ofvdr3|LTT-L4Ua5y|lpBQ3yArhK2#r!_@+V@dha=DqKw$2R_SYK!TOdS)4<``C zKLg>oY3N~*2s{S+D`VPv2s8nq3HhJh|1^~UjE<95PJ$tSm5HPLRcIudQ(Y{ljNwyX Rn||$q>jozJc~|b-{|{cWxdH$H literal 0 HcmV?d00001 From 1b0e391fb0ead086376f748e105738509ebcaf6a Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 15 Oct 2019 16:59:32 -0400 Subject: [PATCH 037/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b70b95125..8cec108c4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ## 3.12.0 * Fire events on `document` in development to facilitate dev tooling ([#3005](https://github.com/sveltejs/svelte/pull/3005)) +* Remove old props when the keys in spread props are removed ([#2282](https://github.com/sveltejs/svelte/issues/2282)) ## 3.11.0 From b9f14846b0941d807d74e864a23874750364c964 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Oct 2019 10:57:23 -0400 Subject: [PATCH 038/413] Structured code generation (#3539) --- .eslintrc.js | 9 +- package-lock.json | 92 ++- package.json | 5 +- rollup.config.js | 3 +- src/compiler/compile/Component.ts | 590 +++++++----------- src/compiler/compile/create_module.ts | 251 +++++--- src/compiler/compile/css/Selector.ts | 32 +- src/compiler/compile/css/Stylesheet.ts | 51 +- .../compile/css/gather_possible_values.ts | 2 +- src/compiler/compile/css/interfaces.ts | 6 + src/compiler/compile/nodes/Attribute.ts | 36 +- src/compiler/compile/nodes/Binding.ts | 20 +- src/compiler/compile/nodes/EachBlock.ts | 42 +- src/compiler/compile/nodes/Element.ts | 2 +- src/compiler/compile/nodes/EventHandler.ts | 37 +- src/compiler/compile/nodes/InlineComponent.ts | 2 +- src/compiler/compile/nodes/Let.ts | 29 +- .../compile/nodes/shared/Expression.ts | 187 ++---- .../compile/nodes/shared/map_children.ts | 4 +- src/compiler/compile/render_dom/Block.ts | 442 ++++++------- src/compiler/compile/render_dom/Renderer.ts | 14 +- src/compiler/compile/render_dom/index.ts | 381 ++++++----- .../compile/render_dom/wrappers/AwaitBlock.ts | 91 ++- .../compile/render_dom/wrappers/Body.ts | 9 +- .../compile/render_dom/wrappers/DebugTag.ts | 66 +- .../compile/render_dom/wrappers/EachBlock.ts | 248 ++++---- .../render_dom/wrappers/Element/Attribute.ts | 106 ++-- .../render_dom/wrappers/Element/Binding.ts | 188 +++--- .../wrappers/Element/StyleAttribute.ts | 65 +- .../render_dom/wrappers/Element/index.ts | 388 +++++++----- .../compile/render_dom/wrappers/Fragment.ts | 3 +- .../compile/render_dom/wrappers/Head.ts | 6 +- .../compile/render_dom/wrappers/IfBlock.ts | 288 +++++---- .../wrappers/InlineComponent/index.ts | 266 ++++---- .../render_dom/wrappers/MustacheTag.ts | 12 +- .../render_dom/wrappers/RawMustacheTag.ts | 23 +- .../compile/render_dom/wrappers/Slot.ts | 117 ++-- .../compile/render_dom/wrappers/Text.ts | 15 +- .../compile/render_dom/wrappers/Title.ts | 85 +-- .../compile/render_dom/wrappers/Window.ts | 95 ++- .../compile/render_dom/wrappers/shared/Tag.ts | 37 +- .../render_dom/wrappers/shared/Wrapper.ts | 30 +- .../render_dom/wrappers/shared/add_actions.ts | 34 +- .../wrappers/shared/add_event_handlers.ts | 41 +- .../render_dom/wrappers/shared/bind_this.ts | 70 ++- .../render_dom/wrappers/shared/changed.ts | 7 + .../wrappers/shared/get_context_merger.ts | 27 +- .../render_dom/wrappers/shared/is_head.ts | 3 + src/compiler/compile/render_ssr/Renderer.ts | 64 +- .../compile/render_ssr/handlers/AwaitBlock.ts | 18 +- .../compile/render_ssr/handlers/Comment.ts | 10 +- .../compile/render_ssr/handlers/DebugTag.ts | 15 +- .../compile/render_ssr/handlers/EachBlock.ts | 29 +- .../compile/render_ssr/handlers/Element.ts | 132 ++-- .../compile/render_ssr/handlers/Head.ts | 7 +- .../compile/render_ssr/handlers/HtmlTag.ts | 3 +- .../compile/render_ssr/handlers/IfBlock.ts | 19 +- .../render_ssr/handlers/InlineComponent.ts | 104 ++- .../compile/render_ssr/handlers/Slot.ts | 18 +- .../compile/render_ssr/handlers/Tag.ts | 12 +- .../compile/render_ssr/handlers/Text.ts | 5 +- .../compile/render_ssr/handlers/Title.ts | 4 +- .../handlers/shared/get_attribute_value.ts | 28 + .../handlers/shared/get_slot_scope.ts | 21 +- src/compiler/compile/render_ssr/index.ts | 133 ++-- src/compiler/compile/utils/CodeBuilder.ts | 103 --- src/compiler/compile/utils/__test__.ts | 165 ----- src/compiler/compile/utils/deindent.ts | 53 -- .../compile/utils/flatten_reference.ts | 11 +- src/compiler/compile/utils/get_object.ts | 8 +- src/compiler/compile/utils/get_slot_data.ts | 42 +- src/compiler/compile/utils/invalidate.ts | 44 +- src/compiler/compile/utils/scope.ts | 52 +- src/compiler/compile/utils/snip.ts | 3 - src/compiler/compile/utils/stringify.ts | 7 +- .../compile/utils/stringify_attribute.ts | 27 - src/compiler/compile/utils/stringify_props.ts | 11 - src/compiler/compile/utils/tail.ts | 7 - src/compiler/compile/utils/unwrap_parens.ts | 6 - src/compiler/interfaces.ts | 38 +- src/compiler/parse/acorn.ts | 4 +- src/compiler/parse/index.ts | 12 +- src/compiler/parse/read/expression.ts | 26 +- src/compiler/parse/read/script.ts | 14 +- src/compiler/parse/read/style.ts | 14 +- src/compiler/parse/state/mustache.ts | 10 +- src/compiler/parse/state/tag.ts | 16 +- src/compiler/utils/indentation.ts | 57 -- src/compiler/utils/names.ts | 12 +- test/css/index.js | 18 +- test/custom-elements/assert.js | 26 + test/custom-elements/index.js | 5 + .../samples/no-missing-prop-warnings/test.js | 5 +- test/helpers.js | 63 +- .../action-custom-event-handler/expected.js | 27 +- test/js/samples/action/expected.js | 37 +- test/js/samples/bind-online/expected.js | 8 +- test/js/samples/bind-open/expected.js | 26 +- test/js/samples/bind-width-height/expected.js | 23 +- .../capture-inject-dev-only/expected.js | 31 +- .../expected.js | 20 +- .../component-static-array/expected.js | 13 +- .../component-static-immutable/expected.js | 13 +- .../component-static-immutable2/expected.js | 13 +- .../samples/component-static-var/expected.js | 46 +- test/js/samples/component-static/expected.js | 13 +- .../samples/computed-collapsed-if/expected.js | 10 +- test/js/samples/css-media-query/expected.js | 12 +- .../css-shadow-dom-keyframes/expected.js | 13 +- test/js/samples/data-attribute/expected.js | 19 +- test/js/samples/debug-empty/expected.js | 54 +- .../debug-foo-bar-baz-things/expected.js | 114 ++-- test/js/samples/debug-foo/expected.js | 98 +-- test/js/samples/debug-hoisted/expected.js | 27 +- test/js/samples/debug-ssr-foo/expected.js | 18 +- .../samples/deconflict-builtins/expected.js | 41 +- .../js/samples/deconflict-globals/expected.js | 12 +- .../expected.js | 65 +- .../samples/dont-invalidate-this/expected.js | 12 +- test/js/samples/dynamic-import/expected.js | 15 +- .../each-block-array-literal/expected.js | 56 +- .../each-block-changed-check/expected.js | 75 +-- .../each-block-keyed-animated/expected.js | 48 +- test/js/samples/each-block-keyed/expected.js | 43 +- .../event-handler-no-passive/expected.js | 14 +- test/js/samples/event-modifiers/expected.js | 22 +- .../js/samples/head-no-whitespace/expected.js | 7 +- test/js/samples/hoisted-const/expected.js | 16 +- test/js/samples/hoisted-let/expected.js | 16 +- test/js/samples/if-block-complex/expected.js | 29 +- .../js/samples/if-block-no-update/expected.js | 37 +- test/js/samples/if-block-simple/expected.js | 28 +- .../expected.js | 21 +- .../inline-style-optimized-url/expected.js | 13 +- .../inline-style-optimized/expected.js | 13 +- .../inline-style-unoptimized/expected.js | 32 +- .../inline-style-without-updates/expected.js | 12 +- test/js/samples/input-files/expected.js | 16 +- .../input-no-initial-value/expected.js | 36 +- test/js/samples/input-range/expected.js | 22 +- .../input-without-blowback-guard/expected.js | 22 +- .../expected.js | 27 +- .../expected.js | 28 +- .../expected.js | 27 +- .../expected.js | 31 +- test/js/samples/legacy-input-type/expected.js | 10 +- test/js/samples/media-bindings/expected.js | 95 +-- .../non-imported-component/expected.js | 24 +- .../samples/non-mutable-reference/expected.js | 15 +- .../expected.js | 22 +- .../expected.js | 21 +- .../samples/select-dynamic-value/expected.js | 20 +- test/js/samples/setup-method/expected.js | 8 +- .../samples/ssr-no-oncreate-etc/expected.js | 9 +- .../samples/ssr-preserve-comments/expected.js | 5 +- test/js/samples/svg-title/expected.js | 12 +- test/js/samples/title/expected.js | 17 +- test/js/samples/transition-local/expected.js | 56 +- .../transition-repeated-outro/expected.js | 43 +- .../expected.js | 45 +- .../use-elements-as-anchors/expected.js | 118 ++-- .../samples/window-binding-scroll/expected.js | 30 +- .../samples/action-with-call/output.json | 30 + .../samples/action-with-literal/output.json | 10 + test/parser/samples/animation/output.json | 20 + .../attribute-with-whitespace/output.json | 2 +- .../samples/await-then-catch/output.json | 50 ++ .../samples/binding-shorthand/output.json | 41 ++ test/parser/samples/binding/output.json | 41 ++ .../samples/component-dynamic/output.json | 40 ++ test/parser/samples/css/output.json | 1 + .../parser/samples/dynamic-import/output.json | 281 +++++++++ .../each-block-destructured/output.json | 10 + .../samples/each-block-else/output.json | 10 + .../samples/each-block-indexed/output.json | 10 + .../samples/each-block-keyed/output.json | 40 ++ test/parser/samples/each-block/output.json | 10 + test/parser/samples/event-handler/output.json | 50 ++ .../samples/if-block-elseif/output.json | 60 ++ test/parser/samples/raw-mustaches/output.json | 20 + test/parser/samples/refs/output.json | 41 ++ .../samples/script-comment-only/output.json | 11 + .../output.json | 51 ++ .../script-comment-trailing/output.json | 51 ++ test/parser/samples/script/output.json | 51 ++ .../parser/samples/self-reference/output.json | 60 ++ .../samples/transition-intro/output.json | 40 ++ .../samples/unusual-identifier/output.json | 20 + test/runtime/index.js | 12 +- test/runtime/samples/_/_config.js | 52 ++ test/runtime/samples/_/main.svelte | 12 + test/runtime/samples/action-this/main.svelte | 2 +- test/runtime/samples/action-update/_config.js | 2 +- test/runtime/samples/action/_config.js | 2 +- test/runtime/samples/class-helper/_config.js | 2 +- test/runtime/samples/head-if-block/_config.js | 2 +- .../invalidation-in-if-condition/_config.js | 1 - .../_config.js | 1 - .../transition-js-nested-each/_config.js | 2 +- test/server-side-rendering/index.js | 10 +- test/sourcemaps/index.js | 6 +- test/sourcemaps/samples/basic/test.js | 2 +- test/sourcemaps/samples/each-block/test.js | 6 +- test/test.js | 2 + 204 files changed, 4957 insertions(+), 4269 deletions(-) create mode 100644 src/compiler/compile/css/interfaces.ts create mode 100644 src/compiler/compile/render_dom/wrappers/shared/changed.ts create mode 100644 src/compiler/compile/render_dom/wrappers/shared/is_head.ts create mode 100644 src/compiler/compile/render_ssr/handlers/shared/get_attribute_value.ts delete mode 100644 src/compiler/compile/utils/CodeBuilder.ts delete mode 100644 src/compiler/compile/utils/deindent.ts delete mode 100644 src/compiler/compile/utils/snip.ts delete mode 100644 src/compiler/compile/utils/stringify_attribute.ts delete mode 100644 src/compiler/compile/utils/stringify_props.ts delete mode 100644 src/compiler/compile/utils/tail.ts delete mode 100644 src/compiler/compile/utils/unwrap_parens.ts delete mode 100644 src/compiler/utils/indentation.ts create mode 100644 test/runtime/samples/_/_config.js create mode 100644 test/runtime/samples/_/main.svelte diff --git a/.eslintrc.js b/.eslintrc.js index 2c7f2ed1b4..2023207f74 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,14 +22,7 @@ module.exports = { 'arrow-spacing': 2, 'no-inner-declarations': 0, 'require-atomic-updates': 'off', - '@typescript-eslint/indent': [ - 'error', - 'tab', - { - SwitchCase: 1, - ignoredNodes: ['TemplateLiteral'] - } - ], + '@typescript-eslint/indent': 'off', '@typescript-eslint/camelcase': 'off', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/array-type': ['error', 'array-simple'], diff --git a/package-lock.json b/package-lock.json index acfa52723a..97fa374f9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -489,6 +489,18 @@ "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, + "code-red": { + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/code-red/-/code-red-0.0.17.tgz", + "integrity": "sha512-RJJ48sXYOqyd0J4QelF4dRdYb+4DaLV/jHs4mNoxOdLroUGB840cMc9pMtEAbGKjFFzoTKREypFzqphBD8knMg==", + "dev": true, + "requires": { + "acorn": "^7.0.0", + "is-reference": "^1.1.3", + "periscopic": "^1.0.1", + "sourcemap-codec": "^1.4.6" + } + }, "codecov": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.5.0.tgz", @@ -792,6 +804,13 @@ "resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz", "integrity": "sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM=", "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true } } }, @@ -1169,9 +1188,9 @@ "dev": true }, "estree-walker": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", - "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.8.1.tgz", + "integrity": "sha512-H6cJORkqvrNziu0KX2hqOMAlA2CiuAxHeGJXSIoKA/KLv229Dw806J3II6mKTm5xiDX1At1EXCfsOQPB+tMB+g==", "dev": true }, "esutils": { @@ -1484,6 +1503,14 @@ "optimist": "^0.6.1", "source-map": "^0.6.1", "uglify-js": "^3.1.4" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } } }, "har-schema": { @@ -2693,6 +2720,26 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "periscopic": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-1.0.2.tgz", + "integrity": "sha512-KpKBKadLf8THXOxswQBhOY8E1lVVhfUidacPtQBrq7KDXaNkQLUPiTmXagzqpJGECP3/0gDXYFO6CZHVbGvOSw==", + "dev": true, + "requires": { + "is-reference": "^1.1.4" + }, + "dependencies": { + "is-reference": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", + "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39" + } + } + } + }, "pify": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", @@ -3049,6 +3096,14 @@ "magic-string": "^0.25.2", "resolve": "^1.11.0", "rollup-pluginutils": "^2.8.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + } } }, "rollup-plugin-json": { @@ -3116,6 +3171,14 @@ "dev": true, "requires": { "estree-walker": "^0.6.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + } } }, "run-async": { @@ -3202,9 +3265,9 @@ } }, "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", "dev": true }, "source-map-support": { @@ -3215,6 +3278,14 @@ "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } } }, "sourcemap-codec": { @@ -3522,6 +3593,15 @@ "requires": { "commander": "~2.20.0", "source-map": "~0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true + } } }, "uri-js": { diff --git a/package.json b/package.json index 4a1622b3f4..7868700246 100644 --- a/package.json +++ b/package.json @@ -63,12 +63,13 @@ "acorn": "^7.0.0", "agadoo": "^1.1.0", "c8": "^5.0.1", + "code-red": "0.0.17", "codecov": "^3.5.0", "css-tree": "1.0.0-alpha22", "eslint": "^6.3.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-svelte3": "^2.7.3", - "estree-walker": "^0.6.1", + "estree-walker": "^0.8.1", "is-reference": "^1.1.3", "jsdom": "^15.1.1", "kleur": "^3.0.3", @@ -84,7 +85,7 @@ "rollup-plugin-sucrase": "^2.1.0", "rollup-plugin-typescript": "^1.0.1", "rollup-plugin-virtual": "^1.0.1", - "source-map": "^0.6.1", + "source-map": "^0.7.3", "source-map-support": "^0.5.13", "tiny-glob": "^0.2.6", "tslib": "^1.10.0", diff --git a/rollup.config.js b/rollup.config.js index 7cce25e24c..4444494a5f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,8 +20,7 @@ const ts_plugin = is_publish const external = id => id.startsWith('svelte/'); -const inlined_estree = fs.readFileSync('./node_modules/estree-walker/index.d.ts', 'utf-8').replace(/declare.*\{((.|[\n\r])+)\}/m, '$1'); -fs.writeFileSync(`./compiler.d.ts`, `export { compile, parse, preprocess, VERSION } from './types/compiler/index';\n${inlined_estree}`); +fs.writeFileSync(`./compiler.d.ts`, `export { compile, parse, preprocess, VERSION } from './types/compiler/index';`); export default [ /* runtime */ diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 423186e4f3..ee24fc700c 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1,9 +1,7 @@ -import MagicString, { Bundle } from 'magic-string'; -// @ts-ignore import { walk, childKeys } from 'estree-walker'; import { getLocator } from 'locate-character'; import Stats from '../Stats'; -import { globals, reserved } from '../utils/names'; +import { globals, reserved, is_valid } from '../utils/names'; import { namespaces, valid_namespaces } from '../utils/namespaces'; import create_module from './create_module'; import { @@ -16,20 +14,19 @@ import Stylesheet from './css/Stylesheet'; import { test } from '../config'; import Fragment from './nodes/Fragment'; import internal_exports from './internal_exports'; -import { Node, Ast, CompileOptions, Var, Warning } from '../interfaces'; +import { Ast, CompileOptions, Var, Warning } from '../interfaces'; import error from '../utils/error'; import get_code_frame from '../utils/get_code_frame'; import flatten_reference from './utils/flatten_reference'; import is_reference from 'is-reference'; import TemplateScope from './nodes/shared/TemplateScope'; import fuzzymatch from '../utils/fuzzymatch'; -import { remove_indentation, add_indentation } from '../utils/indentation'; import get_object from './utils/get_object'; -import unwrap_parens from './utils/unwrap_parens'; import Slot from './nodes/Slot'; -import { Node as ESTreeNode } from 'estree'; +import { Node, ImportDeclaration, Identifier, Program, ExpressionStatement, AssignmentExpression, Literal } from 'estree'; import add_to_set from './utils/add_to_set'; import check_graph_for_cycles from './utils/check_graph_for_cycles'; +import { print, x } from 'code-red'; interface ComponentOptions { namespace?: string; @@ -46,40 +43,6 @@ childKeys.EachBlock = childKeys.IfBlock = ['children', 'else']; childKeys.Attribute = ['value']; childKeys.ExportNamedDeclaration = ['declaration', 'specifiers']; -function remove_node( - code: MagicString, - start: number, - end: number, - body: Node, - node: Node -) { - const i = body.indexOf(node); - if (i === -1) throw new Error('node not in list'); - - let a; - let b; - - if (body.length === 1) { - // remove everything, leave {} - a = start; - b = end; - } else if (i === 0) { - // remove everything before second node, including comments - a = start; - while (/\s/.test(code.original[a])) a += 1; - - b = body[i].end; - while (/[\s,]/.test(code.original[b])) b += 1; - } else { - // remove the end of the previous node to the end of this one - a = body[i - 1].end; - b = node.end; - } - - code.remove(a, b); - return; -} - export default class Component { stats: Stats; warnings: Warning[]; @@ -87,9 +50,9 @@ export default class Component { ignore_stack: Array> = []; ast: Ast; + original_ast: Ast; source: string; - code: MagicString; - name: string; + name: Identifier; compile_options: CompileOptions; fragment: Fragment; module_scope: Scope; @@ -104,14 +67,12 @@ export default class Component { vars: Var[] = []; var_lookup: Map = new Map(); - imports: Node[] = []; - module_javascript: string; - javascript: string; + imports: ImportDeclaration[] = []; hoistable_nodes: Set = new Set(); node_for_declaration: Map = new Map(); - partly_hoisted: string[] = []; - fully_hoisted: string[] = []; + partly_hoisted: Array<(Node | Node[])> = []; + fully_hoisted: Array<(Node | Node[])> = []; reactive_declarations: Array<{ assignees: Set; dependencies: Set; @@ -121,8 +82,8 @@ export default class Component { reactive_declaration_nodes: Set = new Set(); has_reactive_assignments = false; injected_reactive_declaration_vars: Set = new Set(); - helpers: Map = new Map(); - globals: Map = new Map(); + helpers: Map = new Map(); + globals: Map = new Map(); indirect_dependencies: Map> = new Map(); @@ -140,7 +101,7 @@ export default class Component { stylesheet: Stylesheet; - aliases: Map = new Map(); + aliases: Map = new Map(); used_names: Set = new Set(); globally_used_names: Set = new Set(); @@ -155,7 +116,7 @@ export default class Component { stats: Stats, warnings: Warning[] ) { - this.name = name; + this.name = { type: 'Identifier', name }; this.stats = stats; this.warnings = warnings; @@ -163,6 +124,15 @@ export default class Component { this.source = source; this.compile_options = compile_options; + // the instance JS gets mutated, so we park + // a copy here for later. TODO this feels gross + this.original_ast = { + html: ast.html, + css: ast.css, + instance: ast.instance && JSON.parse(JSON.stringify(ast.instance)), + module: ast.module + }; + this.file = compile_options.filename && (typeof process !== 'undefined' @@ -172,8 +142,6 @@ export default class Component { : compile_options.filename); this.locate = getLocator(this.source); - this.code = new MagicString(source); - // styles this.stylesheet = new Stylesheet( source, @@ -206,7 +174,7 @@ export default class Component { } this.tag = this.component_options.tag || compile_options.tag; } else { - this.tag = this.name; + this.tag = this.name.name; } this.walk_module_js(); @@ -257,15 +225,6 @@ export default class Component { } } - add_sourcemap_locations(node: Node) { - walk(node, { - enter: (node: Node) => { - this.code.addSourcemapLocation(node.start); - this.code.addSourcemapLocation(node.end); - }, - }); - } - alias(name: string) { if (!this.aliases.has(name)) { this.aliases.set(name, this.get_unique_name(name)); @@ -274,19 +233,13 @@ export default class Component { return this.aliases.get(name); } - helper(name: string) { - const alias = this.alias(name); - this.helpers.set(name, alias); - return alias; - } - global(name: string) { const alias = this.alias(name); this.globals.set(name, alias); return alias; } - generate(result: string) { + generate(result?: Node[]) { let js = null; let css = null; @@ -294,55 +247,66 @@ export default class Component { const { compile_options, name } = this; const { format = 'esm' } = compile_options; - const banner = `/* ${ - this.file ? `${this.file} ` : `` - }generated by Svelte v${'__VERSION__'} */`; - - result = result - .replace(/__svelte:self__/g, this.name) - .replace( - compile_options.generate === 'ssr' - ? /(@+|#+)(\w*(?:-\w*)?)/g - : /(@+)(\w*(?:-\w*)?)/g, - (_match: string, sigil: string, name: string) => { - if (sigil === '@') { - if (name[0] === '_') { - return this.global(name.slice(1)); - } + // TODO reinstate banner (along with fragment marker comments) + const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${'__VERSION__'} */`; - if (!internal_exports.has(name)) { - throw new Error( - `compiler error: this shouldn't happen! generated code is trying to use inexistent internal '${name}'` - ); + const program: any = { type: 'Program', body: result }; + + walk(program, { + enter: (node, parent, key) => { + if (node.type === 'Identifier') { + if (node.name[0] === '@') { + if (node.name[1] === '_') { + const alias = this.global(node.name.slice(2)); + node.name = alias.name; + } else { + let name = node.name.slice(1); + + if (compile_options.dev) { + if (internal_exports.has(`${name}_dev`)) { + name += '_dev'; + } else if (internal_exports.has(`${name}Dev`)) { + name += 'Dev'; + } + } + + const alias = this.alias(name); + this.helpers.set(name, alias); + node.name = alias.name; } + } + + else if (node.name[0] !== '#' && !is_valid(node.name)) { + // this hack allows x`foo.${bar}` where bar could be invalid + const literal: Literal = { type: 'Literal', value: node.name }; - if (compile_options.dev) { - if (internal_exports.has(`${name}_dev`)) name = `${name}_dev`; - else if (internal_exports.has(`${name}Dev`)) - name = `${name}Dev`; + if (parent.type === 'Property' && key === 'key') { + parent.key = literal; } - return this.helper(name); + else if (parent.type === 'MemberExpression' && key === 'property') { + parent.property = literal; + parent.computed = true; + } } - - return sigil.slice(1) + name; } - ); + } + }); const referenced_globals = Array.from( this.globals, - ([name, alias]) => name !== alias && { name, alias } + ([name, alias]) => name !== alias.name && { name, alias } ).filter(Boolean); if (referenced_globals.length) { - this.helper('globals'); + this.helpers.set('globals', this.alias('globals')); } const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({ name, alias, })); - const module = create_module( - result, + create_module( + program, format, name, banner, @@ -355,67 +319,30 @@ export default class Component { .map(variable => ({ name: variable.name, as: variable.export_name, - })), - this.source + })) ); - const parts = module.split('✂]'); - const final_chunk = parts.pop(); - - const compiled = new Bundle({ separator: '' }); - - function add_string(str: string) { - compiled.addSource({ - content: new MagicString(str), - }); - } - - const { filename } = compile_options; - - // special case — the source file doesn't actually get used anywhere. we need - // to add an empty file to populate map.sources and map.sourcesContent - if (!parts.length) { - compiled.addSource({ - filename, - content: new MagicString(this.source).remove(0, this.source.length), - }); - } - - const pattern = /\[✂(\d+)-(\d+)$/; - - parts.forEach((str: string) => { - const chunk = str.replace(pattern, ''); - if (chunk) add_string(chunk); - - const match = pattern.exec(str); - - const snippet = this.code.snip(+match[1], +match[2]); - - compiled.addSource({ - filename, - content: snippet, - }); - }); - - add_string(final_chunk); - css = compile_options.customElement ? { code: null, map: null } : this.stylesheet.render(compile_options.cssOutputFilename, true); - js = { - code: compiled.toString(), - map: compiled.generateMap({ - includeContent: true, - file: compile_options.outputFilename, - }), - }; + js = print(program, { + sourceMapSource: compile_options.filename + }); + + js.map.sources = [ + compile_options.filename ? get_relative_path(compile_options.outputFilename || '', compile_options.filename) : null + ]; + + js.map.sourcesContent = [ + this.source + ]; } return { js, css, - ast: this.ast, + ast: this.original_ast, warnings: this.warnings, vars: this.vars .filter(v => !v.global && !v.internal) @@ -433,7 +360,7 @@ export default class Component { }; } - get_unique_name(name: string) { + get_unique_name(name: string): Identifier { if (test) name = `${name}$`; let alias = name; for ( @@ -445,7 +372,7 @@ export default class Component { alias = `${name}_${i++}` ); this.used_names.add(alias); - return alias; + return { type: 'Identifier', name: alias }; } get_unique_name_maker() { @@ -459,7 +386,7 @@ export default class Component { internal_exports.forEach(add); this.var_lookup.forEach((_value, key) => add(key)); - return (name: string) => { + return (name: string): Identifier => { if (test) name = `${name}$`; let alias = name; for ( @@ -469,7 +396,11 @@ export default class Component { ); local_used_names.add(alias); this.globally_used_names.add(alias); - return alias; + + return { + type: 'Identifier', + name: alias + }; }; } @@ -530,21 +461,21 @@ export default class Component { } extract_imports(content) { - const { code } = this; + for (let i = 0; i < content.body.length; i += 1) { + const node = content.body[i]; - content.body.forEach(node => { if (node.type === 'ImportDeclaration') { - // imports need to be hoisted out of the IIFE - remove_node(code, content.start, content.end, content.body, node); + content.body.splice(i--, 1); this.imports.push(node); } - }); + } } extract_exports(content) { - const { code } = this; + let i = content.body.length; + while (i--) { + const node = content.body[i]; - content.body.forEach(node => { if (node.type === 'ExportDefaultDeclaration') { this.error(node, { code: `default-export`, @@ -574,25 +505,27 @@ export default class Component { variable.export_name = name; } - code.remove(node.start, node.declaration.start); + content.body[i] = node.declaration; } else { - remove_node(code, content.start, content.end, content.body, node); node.specifiers.forEach(specifier => { const variable = this.var_lookup.get(specifier.local.name); if (variable) { variable.export_name = specifier.exported.name; - } else { - // TODO what happens with `export { Math }` or some other global? } }); + + content.body.splice(i, 1); } } - }); + } } extract_javascript(script) { - const nodes_to_include = script.content.body.filter(node => { + if (!script) return null; + + return script.content.body.filter(node => { + if (!node) return false; if (this.hoistable_nodes.has(node)) return false; if (this.reactive_declaration_nodes.has(node)) return false; if (node.type === 'ImportDeclaration') return false; @@ -600,36 +533,6 @@ export default class Component { return false; return true; }); - - if (nodes_to_include.length === 0) return null; - - let a = script.content.start; - while (/\s/.test(this.source[a])) a += 1; - - let b = a; - - let result = ''; - - script.content.body.forEach(node => { - if ( - this.hoistable_nodes.has(node) || - this.reactive_declaration_nodes.has(node) - ) { - if (a !== b) result += `[✂${a}-${b}✂]`; - a = node.end; - } - - b = node.end; - }); - - // while (/\s/.test(this.source[a - 1])) a -= 1; - - b = script.content.end; - while (/\s/.test(this.source[b - 1])) b -= 1; - - if (a < b) result += `[✂${a}-${b}✂]`; - - return result || null; } walk_module_js() { @@ -640,7 +543,7 @@ export default class Component { walk(script.content, { enter(node) { if (node.type === 'LabeledStatement' && node.label.name === '$') { - component.warn(node, { + component.warn(node as any, { code: 'module-script-reactive-declaration', message: '$: has no effect in a module script', }); @@ -648,30 +551,30 @@ export default class Component { }, }); - this.add_sourcemap_locations(script.content); - const { scope, globals } = create_scopes(script.content); this.module_scope = scope; scope.declarations.forEach((node, name) => { if (name[0] === '$') { - this.error(node, { + this.error(node as any, { code: 'illegal-declaration', message: `The $ prefix is reserved, and cannot be used for variable and import names`, }); } + const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let'); + this.add_var({ name, module: true, hoistable: true, - writable: node.kind === 'var' || node.kind === 'let', + writable }); }); globals.forEach((node, name) => { if (name[0] === '$') { - this.error(node, { + this.error(node as any, { code: 'illegal-subscription', message: `Cannot reference store value inside '; -function get_context(parser: Parser, attributes: Node[], start: number) { +function get_context(parser: Parser, attributes: any[], start: number): string { const context = attributes.find(attribute => attribute.name === 'context'); if (!context) return 'default'; @@ -28,7 +29,7 @@ function get_context(parser: Parser, attributes: Node[], start: number) { return value; } -export default function read_script(parser: Parser, start: number, attributes: Node[]) { +export default function read_script(parser: Parser, start: number, attributes: Node[]): Script { const script_start = parser.index; const script_end = parser.template.indexOf(script_closing_tag, script_start); @@ -41,7 +42,7 @@ export default function read_script(parser: Parser, start: number, attributes: N repeat(' ', script_start) + parser.template.slice(script_start, script_end); parser.index = script_end + script_closing_tag.length; - let ast; + let ast: Program; try { ast = acorn.parse(source); @@ -49,8 +50,11 @@ export default function read_script(parser: Parser, start: number, attributes: N parser.acorn_error(err); } - ast.start = script_start; + // TODO is this necessary? + (ast as any).start = script_start; + return { + type: 'Script', start, end: parser.index, context: get_context(parser, attributes, start), diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index a14356e05b..4a16475d6b 100644 --- a/src/compiler/parse/read/style.ts +++ b/src/compiler/parse/read/style.ts @@ -1,9 +1,10 @@ import parse from 'css-tree/lib/parser/index.js'; import { walk } from 'estree-walker'; import { Parser } from '../index'; -import { Node } from '../../interfaces'; +import { Node } from 'estree'; +import { Style } from '../../interfaces'; -export default function read_style(parser: Parser, start: number, attributes: Node[]) { +export default function read_style(parser: Parser, start: number, attributes: Node[]): Style { const content_start = parser.index; const styles = parser.read_until(/<\/style>/); const content_end = parser.index; @@ -30,7 +31,7 @@ export default function read_style(parser: Parser, start: number, attributes: No // tidy up AST walk(ast, { - enter: (node: Node) => { + enter: (node: any) => { // `any` because this isn't an ESTree node // replace `ref:a` nodes if (node.type === 'Selector') { for (let i = 0; i < node.children.length; i += 1) { @@ -58,6 +59,7 @@ export default function read_style(parser: Parser, start: number, attributes: No const end = parser.index; return { + type: 'Style', start, end, attributes, @@ -65,12 +67,12 @@ export default function read_style(parser: Parser, start: number, attributes: No content: { start: content_start, end: content_end, - styles, - }, + styles + } }; } -function is_ref_selector(a: Node, b: Node) { +function is_ref_selector(a: any, b: any) { // TODO add CSS node types if (!b) return false; return ( diff --git a/src/compiler/parse/state/mustache.ts b/src/compiler/parse/state/mustache.ts index 8de35cee48..4a1578ada5 100644 --- a/src/compiler/parse/state/mustache.ts +++ b/src/compiler/parse/state/mustache.ts @@ -4,9 +4,9 @@ import { closing_tag_omitted } from '../utils/html'; import { whitespace } from '../../utils/patterns'; import { trim_start, trim_end } from '../../utils/trim'; import { Parser } from '../index'; -import { Node } from '../../interfaces'; +import { TemplateNode } from '../../interfaces'; -function trim_whitespace(block: Node, trim_before: boolean, trim_after: boolean) { +function trim_whitespace(block: TemplateNode, trim_before: boolean, trim_after: boolean) { if (!block.children || block.children.length === 0) return; // AwaitBlock const first_child = block.children[0]; @@ -175,7 +175,7 @@ export default function mustache(parser: Parser) { parser.eat('}', true); } - const then_block: Node = { + const then_block: TemplateNode = { start, end: null, type: 'ThenBlock', @@ -200,7 +200,7 @@ export default function mustache(parser: Parser) { parser.eat('}', true); } - const catch_block: Node = { + const catch_block: TemplateNode = { start, end: null, type: 'CatchBlock', @@ -232,7 +232,7 @@ export default function mustache(parser: Parser) { const expression = read_expression(parser); - const block: Node = type === 'AwaitBlock' ? + const block: TemplateNode = type === 'AwaitBlock' ? { start, end: null, diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 21a7b3caea..880c866ffe 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -4,7 +4,7 @@ import read_style from '../read/style'; import { decode_character_references, closing_tag_omitted } from '../utils/html'; import { is_void } from '../../utils/names'; import { Parser } from '../index'; -import { Directive, DirectiveType, Node, Text } from '../../interfaces'; +import { Directive, DirectiveType, TemplateNode, Text } from '../../interfaces'; import fuzzymatch from '../../utils/fuzzymatch'; import list from '../../utils/list'; @@ -37,10 +37,8 @@ const specials = new Map([ ], ]); -// eslint-disable-next-line no-useless-escape -const SELF = /^svelte:self(?=[\s\/>])/; -// eslint-disable-next-line no-useless-escape -const COMPONENT = /^svelte:component(?=[\s\/>])/; +const SELF = /^svelte:self(?=[\s/>])/; +const COMPONENT = /^svelte:component(?=[\s/>])/; function parent_is_head(stack) { let i = stack.length; @@ -112,7 +110,7 @@ export default function tag(parser: Parser) { : name === 'title' && parent_is_head(parser.stack) ? 'Title' : name === 'slot' && !parser.customElement ? 'Slot' : 'Element'; - const element: Node = { + const element: TemplateNode = { start, end: null, // filled in later type, @@ -406,7 +404,7 @@ function read_attribute(parser: Parser, unique_names: Set) { end: directive.end, type: 'Identifier', name: directive.name - }; + } as any; } return directive; @@ -447,7 +445,7 @@ function read_attribute_value(parser: Parser) { return value; } -function read_sequence(parser: Parser, done: () => boolean): Node[] { +function read_sequence(parser: Parser, done: () => boolean): TemplateNode[] { let current_chunk: Text = { start: parser.index, end: null, @@ -464,7 +462,7 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] { } } - const chunks: Node[] = []; + const chunks: TemplateNode[] = []; while (parser.index < parser.template.length) { const index = parser.index; diff --git a/src/compiler/utils/indentation.ts b/src/compiler/utils/indentation.ts deleted file mode 100644 index 54ededc37d..0000000000 --- a/src/compiler/utils/indentation.ts +++ /dev/null @@ -1,57 +0,0 @@ -import MagicString from 'magic-string'; -import { Node } from '../interfaces'; -import { walk } from 'estree-walker'; -import repeat from './repeat'; - -export function remove_indentation(code: MagicString, node: Node) { - const indent = code.getIndentString(); - const pattern = new RegExp(`^${indent}`, 'gm'); - - const excluded = []; - - walk(node, { - enter(node) { - if (node.type === 'TemplateElement') { - excluded.push(node); - } - } - }); - - const str = code.original.slice(node.start, node.end); - - let match; - while (match = pattern.exec(str)) { - const index = node.start + match.index; - while (excluded[0] && excluded[0].end < index) excluded.shift(); - if (excluded[0] && excluded[0].start < index) continue; - - code.remove(index, index + indent.length); - } -} - -export function add_indentation(code: MagicString, node: Node, levels = 1) { - const base_indent = code.getIndentString(); - const indent = repeat(base_indent, levels); - const pattern = /\n/gm; - - const excluded = []; - - walk(node, { - enter(node) { - if (node.type === 'TemplateElement') { - excluded.push(node); - } - } - }); - - const str = code.original.slice(node.start, node.end); - - let match; - while (match = pattern.exec(str)) { - const index = node.start + match.index; - while (excluded[0] && excluded[0].end < index) excluded.shift(); - if (excluded[0] && excluded[0].start < index) continue; - - code.appendLeft(index + 1, indent); - } -} diff --git a/src/compiler/utils/names.ts b/src/compiler/utils/names.ts index 86cd686564..53e9fce4a1 100644 --- a/src/compiler/utils/names.ts +++ b/src/compiler/utils/names.ts @@ -105,7 +105,7 @@ export function is_void(name: string) { return void_element_names.test(name) || name.toLowerCase() === '!doctype'; } -function is_valid(str: string): boolean { +export function is_valid(str: string): boolean { let i = 0; while (i < str.length) { @@ -118,16 +118,6 @@ function is_valid(str: string): boolean { return true; } -export function quote_name_if_necessary(name: string) { - if (!is_valid(name)) return `"${name}"`; - return name; -} - -export function quote_prop_if_necessary(name: string) { - if (!is_valid(name)) return `["${name}"]`; - return `.${name}`; -} - export function sanitize(name: string) { return name .replace(/[^a-zA-Z0-9_]+/g, '_') diff --git a/test/css/index.js b/test/css/index.js index be2a10bef1..61e8a0c6cb 100644 --- a/test/css/index.js +++ b/test/css/index.js @@ -82,10 +82,24 @@ describe('css', () => { assert.equal(dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'), expected.css); + let ClientComponent; + let ServerComponent; + // we do this here, rather than in the expected.html !== null // block, to verify that valid code was generated - const ClientComponent = create(dom.js.code); - const ServerComponent = create(ssr.js.code); + try { + ClientComponent = create(dom.js.code); + } catch (err) { + console.log(dom.js.code); + throw err; + } + + try { + ServerComponent = create(ssr.js.code); + } catch (err) { + console.log(dom.js.code); + throw err; + } // verify that the right elements have scoping selectors if (expected.html !== null) { diff --git a/test/custom-elements/assert.js b/test/custom-elements/assert.js index 79aba6c736..0edbd31124 100644 --- a/test/custom-elements/assert.js +++ b/test/custom-elements/assert.js @@ -1,3 +1,29 @@ +export function deepEqual(a, b, message) { + if (!is_equal(a, b)) { + throw new Error(message || `Expected ${JSON.stringify(a)} to equal ${JSON.stringify(b)}`); + } +} + +function is_equal(a, b) { + if (a && typeof a === 'object') { + const is_array = Array.isArray(a); + if (Array.isArray(b) !== is_array) return false; + + if (is_array) { + if (a.length !== b.length) return false; + return a.every((value, i) => is_equal(value, b[i])); + } + + const a_keys = Object.keys(a).sort(); + const b_keys = Object.keys(b).sort(); + if (a_keys.join(',') !== b_keys.join(',')) return false; + + return a_keys.every(key => is_equal(a[key], b[key])); + } + + return a === b; +} + export function equal(a, b, message) { if (a != b) throw new Error(message || `Expected ${a} to equal ${b}`); } diff --git a/test/custom-elements/index.js b/test/custom-elements/index.js index 9255d33c0e..7fe47f2ecd 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.js @@ -109,6 +109,11 @@ describe('custom-elements', function() { console[type](...args); }); + page.on('error', error => { + console.log('>>> an error happened'); + console.error(error); + }); + try { await page.goto('http://localhost:6789'); diff --git a/test/custom-elements/samples/no-missing-prop-warnings/test.js b/test/custom-elements/samples/no-missing-prop-warnings/test.js index e7ced25e19..1909e7aef9 100644 --- a/test/custom-elements/samples/no-missing-prop-warnings/test.js +++ b/test/custom-elements/samples/no-missing-prop-warnings/test.js @@ -11,8 +11,9 @@ export default function (target) { target.innerHTML = ''; - assert.equal(warnings.length, 1); - assert.equal(warnings[0], ` was created without expected prop 'bar'`); + assert.deepEqual(warnings, [ + ` was created without expected prop 'bar'` + ]); console.warn = warn; } \ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index e0c4c980ee..6ac20eed8b 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -47,7 +47,7 @@ export function tryToReadFile(file) { const virtualConsole = new jsdom.VirtualConsole(); virtualConsole.sendTo(console); -global.window = new jsdom.JSDOM('
', {virtualConsole}).window; +const window = new jsdom.JSDOM('
', {virtualConsole}).window; global.document = window.document; global.navigator = window.navigator; global.getComputedStyle = window.getComputedStyle; @@ -182,58 +182,21 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) { glob('**/*.svelte', { cwd }).forEach(file => { if (file[0] === '_') return; - const { js } = compile( - fs.readFileSync(`${cwd}/${file}`, 'utf-8'), - Object.assign(options, { - filename: file - }) - ); - - console.log( // eslint-disable-line no-console - `\n>> ${colors.cyan().bold(file)}\n${addLineNumbers(js.code)}\n<< ${colors.cyan().bold(file)}` - ); - }); -} - -const start = /\n(\t+)/; -export function deindent(strings, ...values) { - const indentation = start.exec(strings[0])[1]; - const pattern = new RegExp(`^${indentation}`, 'gm'); - - let result = strings[0].replace(start, '').replace(pattern, ''); - - let trailingIndentation = getTrailingIndentation(result); - - for (let i = 1; i < strings.length; i += 1) { - let expression = values[i - 1]; - const string = strings[i].replace(pattern, ''); - - if (Array.isArray(expression)) { - expression = expression.length ? expression.join('\n') : null; - } + try { + const { js } = compile( + fs.readFileSync(`${cwd}/${file}`, 'utf-8'), + Object.assign(options, { + filename: file + }) + ); - if (expression || expression === '') { - const value = String(expression).replace( - /\n/g, - `\n${trailingIndentation}` + console.log( // eslint-disable-line no-console + `\n>> ${colors.cyan().bold(file)}\n${addLineNumbers(js.code)}\n<< ${colors.cyan().bold(file)}` ); - result += value + string; - } else { - let c = result.length; - while (/\s/.test(result[c - 1])) c -= 1; - result = result.slice(0, c) + string; + } catch (err) { + console.log(`failed to generate output: ${err.message}`); } - - trailingIndentation = getTrailingIndentation(result); - } - - return result.trim().replace(/\t+$/gm, ''); -} - -function getTrailingIndentation(str) { - let i = str.length; - while (str[i - 1] === ' ' || str[i - 1] === '\t') i -= 1; - return str.slice(i, str.length); + }); } export function spaces(i) { diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index 34d5ca10aa..c54ad93202 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -1,43 +1,35 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, element, init, insert, + is_function, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { - var button, foo_action; + let button; + let foo_action; return { c() { button = element("button"); button.textContent = "foo"; }, - m(target, anchor) { insert(target, button, anchor); - foo_action = foo.call(null, button, ctx.foo_function) || {}; + foo_action = foo.call(null, button, ctx.foo_function) || ({}); }, - p(changed, ctx) { - if (typeof foo_action.update === 'function' && changed.bar) { - foo_action.update.call(null, ctx.foo_function); - } + if (is_function(foo_action.update) && changed.bar) foo_action.update.call(null, ctx.foo_function); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - } - - if (foo_action && typeof foo_action.destroy === 'function') foo_action.destroy(); + if (detaching) detach(button); + if (foo_action && is_function(foo_action.destroy)) foo_action.destroy(); } }; } @@ -47,16 +39,15 @@ function handleFoo(bar) { } function foo(node, callback) { - // code goes here + } function instance($$self, $$props, $$invalidate) { let { bar } = $$props; - const foo_function = () => handleFoo(bar); $$self.$set = $$props => { - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); }; return { bar, foo_function }; diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index ed0a0a7430..04882f88f5 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -6,12 +5,14 @@ import { element, init, insert, + is_function, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { - var a, link_action; + let a; + let link_action; return { c() { @@ -19,39 +20,33 @@ function create_fragment(ctx) { a.textContent = "Test"; attr(a, "href", "#"); }, - m(target, anchor) { insert(target, a, anchor); - link_action = link.call(null, a) || {}; + link_action = link.call(null, a) || ({}); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(a); - } - - if (link_action && typeof link_action.destroy === 'function') link_action.destroy(); + if (detaching) detach(a); + if (link_action && is_function(link_action.destroy)) link_action.destroy(); } }; } function link(node) { - function onClick(event) { - event.preventDefault(); - history.pushState(null, null, event.target.href); - } + function onClick(event) { + event.preventDefault(); + history.pushState(null, null, event.target.href); + } - node.addEventListener('click', onClick); + node.addEventListener("click", onClick); - return { - destroy() { - node.removeEventListener('click', onClick); - } - } + return { + destroy() { + node.removeEventListener("click", onClick); + } + }; } class Component extends SvelteComponent { diff --git a/test/js/samples/bind-online/expected.js b/test/js/samples/bind-online/expected.js index 0c9faa3ef6..30087ca615 100644 --- a/test/js/samples/bind-online/expected.js +++ b/test/js/samples/bind-online/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -10,8 +9,7 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var dispose; - + let dispose; add_render_callback(ctx.onlinestatuschanged); return { @@ -21,12 +19,10 @@ function create_fragment(ctx) { listen(window, "offline", ctx.onlinestatuschanged) ]; }, - m: noop, p: noop, i: noop, o: noop, - d(detaching) { run_all(dispose); } @@ -37,7 +33,7 @@ function instance($$self, $$props, $$invalidate) { let online; function onlinestatuschanged() { - online = navigator.onLine; $$invalidate('online', online); + $$invalidate("online", online = navigator.onLine); } return { online, onlinestatuschanged }; diff --git a/test/js/samples/bind-open/expected.js b/test/js/samples/bind-open/expected.js index 7f739aec8b..3ccd560459 100644 --- a/test/js/samples/bind-open/expected.js +++ b/test/js/samples/bind-open/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,34 +10,31 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var details, dispose; + let details; + let dispose; return { c() { details = element("details"); + details.innerHTML = `summarycontent - `; +`; + dispose = listen(details, "toggle", ctx.details_toggle_handler); }, - m(target, anchor) { insert(target, details, anchor); - details.open = ctx.open; }, - p(changed, ctx) { - if (changed.open) details.open = ctx.open; + if (changed.open) { + details.open = ctx.open; + } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(details); - } - + if (detaching) detach(details); dispose(); } }; @@ -49,11 +45,11 @@ function instance($$self, $$props, $$invalidate) { function details_toggle_handler() { open = this.open; - $$invalidate('open', open); + $$invalidate("open", open); } $$self.$set = $$props => { - if ('open' in $$props) $$invalidate('open', open = $$props.open); + if ("open" in $$props) $$invalidate("open", open = $$props.open); }; return { open, details_toggle_handler }; diff --git a/test/js/samples/bind-width-height/expected.js b/test/js/samples/bind-width-height/expected.js index 2ef190588f..b10074ce2b 100644 --- a/test/js/samples/bind-width-height/expected.js +++ b/test/js/samples/bind-width-height/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -12,7 +11,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div, div_resize_listener; + let div; + let div_resize_listener; return { c() { @@ -20,39 +20,34 @@ function create_fragment(ctx) { div.textContent = "some content"; add_render_callback(() => ctx.div_resize_handler.call(div)); }, - m(target, anchor) { insert(target, div, anchor); div_resize_listener = add_resize_listener(div, ctx.div_resize_handler.bind(div)); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } - + if (detaching) detach(div); div_resize_listener.cancel(); } }; } function instance($$self, $$props, $$invalidate) { - let { w, h } = $$props; + let { w } = $$props; + let { h } = $$props; function div_resize_handler() { w = this.offsetWidth; h = this.offsetHeight; - $$invalidate('w', w); - $$invalidate('h', h); + $$invalidate("w", w); + $$invalidate("h", h); } $$self.$set = $$props => { - if ('w' in $$props) $$invalidate('w', w = $$props.w); - if ('h' in $$props) $$invalidate('h', h = $$props.h); + if ("w" in $$props) $$invalidate("w", w = $$props.w); + if ("h" in $$props) $$invalidate("h", h = $$props.h); }; return { w, h, div_resize_handler }; diff --git a/test/js/samples/capture-inject-dev-only/expected.js b/test/js/samples/capture-inject-dev-only/expected.js index 8ed14d6cd5..7091990056 100644 --- a/test/js/samples/capture-inject-dev-only/expected.js +++ b/test/js/samples/capture-inject-dev-only/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -16,7 +15,11 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var p, t0, t1, input, dispose; + let p; + let t0; + let t1; + let input; + let dispose; return { c() { @@ -26,34 +29,26 @@ function create_fragment(ctx) { input = element("input"); dispose = listen(input, "input", ctx.input_input_handler); }, - m(target, anchor) { insert(target, p, anchor); append(p, t0); insert(target, t1, anchor); insert(target, input, anchor); - set_input_value(input, ctx.foo); }, - p(changed, ctx) { - if (changed.foo) { - set_data(t0, ctx.foo); - } + if (changed.foo) set_data(t0, ctx.foo); - if (changed.foo && (input.value !== ctx.foo)) set_input_value(input, ctx.foo); + if (changed.foo && input.value !== ctx.foo) { + set_input_value(input, ctx.foo); + } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(p); - detach(t1); - detach(input); - } - + if (detaching) detach(p); + if (detaching) detach(t1); + if (detaching) detach(input); dispose(); } }; @@ -64,7 +59,7 @@ function instance($$self, $$props, $$invalidate) { function input_input_handler() { foo = this.value; - $$invalidate('foo', foo); + $$invalidate("foo", foo); } return { foo, input_input_handler }; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 09b40a1e98..9a34f69b07 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -15,13 +14,14 @@ import { function add_css() { var style = element("style"); - style.id = 'svelte-1a7i8ec-style'; + style.id = "svelte-1a7i8ec-style"; style.textContent = "p.svelte-1a7i8ec{color:red}"; append(document.head, style); } function create_fragment(ctx) { - var p, t; + let p; + let t; return { c() { @@ -29,25 +29,17 @@ function create_fragment(ctx) { t = text(ctx.foo); attr(p, "class", "svelte-1a7i8ec"); }, - m(target, anchor) { insert(target, p, anchor); append(p, t); }, - p(changed, ctx) { - if (changed.foo) { - set_data(t, ctx.foo); - } + if (changed.foo) set_data(t, ctx.foo); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } @@ -56,7 +48,7 @@ function instance($$self, $$props, $$invalidate) { let { foo = 42 } = $$props; $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/component-static-array/expected.js b/test/js/samples/component-static-array/expected.js index 6997f431dd..3905fcce56 100644 --- a/test/js/samples/component-static-array/expected.js +++ b/test/js/samples/component-static-array/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -11,34 +10,27 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var current; - - var nested = new ctx.Nested({ props: { foo: [1, 2, 3] } }); + let current; + const nested = new ctx.Nested({ props: { foo: [1, 2, 3] } }); return { c() { nested.$$.fragment.c(); }, - m(target, anchor) { mount_component(nested, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(nested.$$.fragment, local); - current = true; }, - o(local) { transition_out(nested.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(nested, detaching); } @@ -47,7 +39,6 @@ function create_fragment(ctx) { function instance($$self) { const Nested = window.Nested; - return { Nested }; } diff --git a/test/js/samples/component-static-immutable/expected.js b/test/js/samples/component-static-immutable/expected.js index 4b33d537ca..0e8bf81d09 100644 --- a/test/js/samples/component-static-immutable/expected.js +++ b/test/js/samples/component-static-immutable/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -11,34 +10,27 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var current; - - var nested = new ctx.Nested({ props: { foo: "bar" } }); + let current; + const nested = new ctx.Nested({ props: { foo: "bar" } }); return { c() { nested.$$.fragment.c(); }, - m(target, anchor) { mount_component(nested, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(nested.$$.fragment, local); - current = true; }, - o(local) { transition_out(nested.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(nested, detaching); } @@ -47,7 +39,6 @@ function create_fragment(ctx) { function instance($$self) { const Nested = window.Nested; - return { Nested }; } diff --git a/test/js/samples/component-static-immutable2/expected.js b/test/js/samples/component-static-immutable2/expected.js index 4b33d537ca..0e8bf81d09 100644 --- a/test/js/samples/component-static-immutable2/expected.js +++ b/test/js/samples/component-static-immutable2/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -11,34 +10,27 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var current; - - var nested = new ctx.Nested({ props: { foo: "bar" } }); + let current; + const nested = new ctx.Nested({ props: { foo: "bar" } }); return { c() { nested.$$.fragment.c(); }, - m(target, anchor) { mount_component(nested, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(nested.$$.fragment, local); - current = true; }, - o(local) { transition_out(nested.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(nested, detaching); } @@ -47,7 +39,6 @@ function create_fragment(ctx) { function instance($$self) { const Nested = window.Nested; - return { Nested }; } diff --git a/test/js/samples/component-static-var/expected.js b/test/js/samples/component-static-var/expected.js index 2f6521f87e..aa3ec5a503 100644 --- a/test/js/samples/component-static-var/expected.js +++ b/test/js/samples/component-static-var/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -14,15 +13,18 @@ import { transition_in, transition_out } from "svelte/internal"; + import Foo from "./Foo.svelte"; import Bar from "./Bar.svelte"; function create_fragment(ctx) { - var t0, t1, input, current, dispose; - - var foo = new Foo({ props: { x: y } }); - - var bar = new Bar({ props: { x: ctx.z } }); + let t0; + let t1; + let input; + let current; + let dispose; + const foo = new Foo({ props: { x: y } }); + const bar = new Bar({ props: { x: ctx.z } }); return { c() { @@ -33,56 +35,41 @@ function create_fragment(ctx) { input = element("input"); dispose = listen(input, "input", ctx.input_input_handler); }, - m(target, anchor) { mount_component(foo, target, anchor); insert(target, t0, anchor); mount_component(bar, target, anchor); insert(target, t1, anchor); insert(target, input, anchor); - set_input_value(input, ctx.z); - current = true; }, - p(changed, ctx) { - var bar_changes = {}; + const bar_changes = {}; if (changed.z) bar_changes.x = ctx.z; bar.$set(bar_changes); - if (changed.z && (input.value !== ctx.z)) set_input_value(input, ctx.z); + if (changed.z && input.value !== ctx.z) { + set_input_value(input, ctx.z); + } }, - i(local) { if (current) return; transition_in(foo.$$.fragment, local); - transition_in(bar.$$.fragment, local); - current = true; }, - o(local) { transition_out(foo.$$.fragment, local); transition_out(bar.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(foo, detaching); - - if (detaching) { - detach(t0); - } - + if (detaching) detach(t0); destroy_component(bar, detaching); - - if (detaching) { - detach(t1); - detach(input); - } - + if (detaching) detach(t1); + if (detaching) detach(input); dispose(); } }; @@ -91,12 +78,11 @@ function create_fragment(ctx) { let y = 1; function instance($$self, $$props, $$invalidate) { - let z = 2; function input_input_handler() { z = this.value; - $$invalidate('z', z); + $$invalidate("z", z); } return { z, input_input_handler }; diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index 5a031a32a4..f82d5d026e 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -11,34 +10,27 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var current; - - var nested = new ctx.Nested({ props: { foo: "bar" } }); + let current; + const nested = new ctx.Nested({ props: { foo: "bar" } }); return { c() { nested.$$.fragment.c(); }, - m(target, anchor) { mount_component(nested, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(nested.$$.fragment, local); - current = true; }, - o(local) { transition_out(nested.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(nested, detaching); } @@ -47,7 +39,6 @@ function create_fragment(ctx) { function instance($$self) { const Nested = window.Nested; - return { Nested }; } diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index bc7c383319..2aff419120 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,10 +1,4 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { return { @@ -29,7 +23,7 @@ function instance($$self, $$props, $$invalidate) { } $$self.$set = $$props => { - if ('x' in $$props) $$invalidate('x', x = $$props.x); + if ("x" in $$props) $$invalidate("x", x = $$props.x); }; return { x, a, b }; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 82b7c5dfc8..8690f5a34e 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -13,32 +12,27 @@ import { function add_css() { var style = element("style"); - style.id = 'svelte-1slhpfn-style'; + style.id = "svelte-1slhpfn-style"; style.textContent = "@media(min-width: 1px){div.svelte-1slhpfn{color:red}}"; append(document.head, style); } function create_fragment(ctx) { - var div; + let div; return { c() { div = element("div"); attr(div, "class", "svelte-1slhpfn"); }, - m(target, anchor) { insert(target, div, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 9f70b8ec66..8178811880 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteElement, detach, @@ -10,7 +9,7 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div; + let div; return { c() { @@ -18,19 +17,14 @@ function create_fragment(ctx) { div.textContent = "fades in"; this.c = noop; }, - m(target, anchor) { insert(target, div, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } @@ -38,9 +32,7 @@ function create_fragment(ctx) { class Component extends SvelteElement { constructor(options) { super(); - this.shadowRoot.innerHTML = ``; - init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal, []); if (options) { @@ -52,5 +44,4 @@ class Component extends SvelteElement { } customElements.define("custom-element", Component); - export default Component; \ No newline at end of file diff --git a/test/js/samples/data-attribute/expected.js b/test/js/samples/data-attribute/expected.js index 12ba50e69f..a3d450d411 100644 --- a/test/js/samples/data-attribute/expected.js +++ b/test/js/samples/data-attribute/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -12,7 +11,9 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div0, t, div1; + let div0; + let t; + let div1; return { c() { @@ -22,28 +23,22 @@ function create_fragment(ctx) { attr(div0, "data-foo", "bar"); attr(div1, "data-foo", ctx.bar); }, - m(target, anchor) { insert(target, div0, anchor); insert(target, t, anchor); insert(target, div1, anchor); }, - p(changed, ctx) { if (changed.bar) { attr(div1, "data-foo", ctx.bar); } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div0); - detach(t); - detach(div1); - } + if (detaching) detach(div0); + if (detaching) detach(t); + if (detaching) detach(div1); } }; } @@ -52,7 +47,7 @@ function instance($$self, $$props, $$invalidate) { let { bar } = $$props; $$self.$set = $$props => { - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); }; return { bar }; diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index e0988b6222..05bcf281c5 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponentDev, add_location, @@ -18,7 +17,11 @@ import { const file = undefined; function create_fragment(ctx) { - var h1, t0, t1, t2, t3; + let h1; + let t0; + let t1; + let t2; + let t3; const block = { c: function create() { @@ -30,11 +33,9 @@ function create_fragment(ctx) { debugger; add_location(h1, file, 4, 0, 38); }, - l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, - m: function mount(target, anchor) { insert_dev(target, h1, anchor); append_dev(h1, t0); @@ -42,39 +43,39 @@ function create_fragment(ctx) { append_dev(h1, t2); insert_dev(target, t3, anchor); }, - p: function update(changed, ctx) { - if (changed.name) { - set_data_dev(t1, ctx.name); - } - + if (changed.name) set_data_dev(t1, ctx.name); debugger; }, - i: noop, o: noop, - d: function destroy(detaching) { - if (detaching) { - detach_dev(h1); - detach_dev(t3); - } + if (detaching) detach_dev(h1); + if (detaching) detach_dev(t3); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_fragment.name, + type: "component", + source: "", + ctx + }); + return block; } function instance($$self, $$props, $$invalidate) { let { name } = $$props; + const writable_props = ["name"]; - const writable_props = ['name']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith("$$")) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { - if ('name' in $$props) $$invalidate('name', name = $$props.name); + if ("name" in $$props) $$invalidate("name", name = $$props.name); }; $$self.$capture_state = () => { @@ -82,7 +83,7 @@ function instance($$self, $$props, $$invalidate) { }; $$self.$inject_state = $$props => { - if ('name' in $$props) $$invalidate('name', name = $$props.name); + if ("name" in $$props) $$invalidate("name", name = $$props.name); }; return { name }; @@ -92,11 +93,18 @@ class Component extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance, create_fragment, safe_not_equal, ["name"]); - dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + + dispatch_dev("SvelteRegisterComponent", { + component: this, + tagName: "Component", + options, + id: create_fragment.name + }); const { ctx } = this.$$; - const props = options.props || {}; - if (ctx.name === undefined && !('name' in props)) { + const props = options.props || ({}); + + if (ctx.name === undefined && !("name" in props)) { console.warn(" was created without expected prop 'name'"); } } diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 15d953f6bc..d9628b884b 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponentDev, add_location, @@ -24,9 +23,11 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (8:0) {#each things as thing} function create_each_block(ctx) { - var span, t0_value = ctx.thing.name + "", t0, t1; + let span; + let t0_value = ctx.thing.name + ""; + let t0; + let t1; const block = { c: function create() { @@ -39,19 +40,16 @@ function create_each_block(ctx) { console.log({ foo, bar, baz, thing }); debugger; } + add_location(span, file, 8, 1, 116); }, - m: function mount(target, anchor) { insert_dev(target, span, anchor); append_dev(span, t0); insert_dev(target, t1, anchor); }, - p: function update(changed, ctx) { - if ((changed.things) && t0_value !== (t0_value = ctx.thing.name + "")) { - set_data_dev(t0, t0_value); - } + if (changed.things && t0_value !== (t0_value = ctx.thing.name + "")) set_data_dev(t0, t0_value); if (changed.foo || changed.bar || changed.baz || changed.things) { const { foo, bar, baz, thing } = ctx; @@ -59,23 +57,29 @@ function create_each_block(ctx) { debugger; } }, - d: function destroy(detaching) { - if (detaching) { - detach_dev(span); - detach_dev(t1); - } + if (detaching) detach_dev(span); + if (detaching) detach_dev(t1); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_each_block.name, type: "each", source: "(8:0) {#each things as thing}", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_each_block.name, + type: "each", + source: "(8:0) {#each things as thing}", + ctx + }); + return block; } function create_fragment(ctx) { - var t0, p, t1, t2; - + let t0; + let p; + let t1; + let t2; let each_value = ctx.things; - let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { @@ -94,11 +98,9 @@ function create_fragment(ctx) { t2 = text(ctx.foo); add_location(p, file, 12, 0, 182); }, - l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, - m: function mount(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); @@ -109,12 +111,11 @@ function create_fragment(ctx) { append_dev(p, t1); append_dev(p, t2); }, - p: function update(changed, ctx) { if (changed.things) { each_value = ctx.things; - let i; + for (i = 0; i < each_value.length; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); @@ -130,43 +131,48 @@ function create_fragment(ctx) { for (; i < each_blocks.length; i += 1) { each_blocks[i].d(1); } + each_blocks.length = each_value.length; } - if (changed.foo) { - set_data_dev(t2, ctx.foo); - } + if (changed.foo) set_data_dev(t2, ctx.foo); }, - i: noop, o: noop, - d: function destroy(detaching) { destroy_each(each_blocks, detaching); - - if (detaching) { - detach_dev(t0); - detach_dev(p); - } + if (detaching) detach_dev(t0); + if (detaching) detach_dev(p); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_fragment.name, + type: "component", + source: "", + ctx + }); + return block; } function instance($$self, $$props, $$invalidate) { - let { things, foo, bar, baz } = $$props; + let { things } = $$props; + let { foo } = $$props; + let { bar } = $$props; + let { baz } = $$props; + const writable_props = ["things", "foo", "bar", "baz"]; - const writable_props = ['things', 'foo', 'bar', 'baz']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith("$$")) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); - if ('baz' in $$props) $$invalidate('baz', baz = $$props.baz); + if ("things" in $$props) $$invalidate("things", things = $$props.things); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); + if ("baz" in $$props) $$invalidate("baz", baz = $$props.baz); }; $$self.$capture_state = () => { @@ -174,10 +180,10 @@ function instance($$self, $$props, $$invalidate) { }; $$self.$inject_state = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); - if ('baz' in $$props) $$invalidate('baz', baz = $$props.baz); + if ("things" in $$props) $$invalidate("things", things = $$props.things); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); + if ("baz" in $$props) $$invalidate("baz", baz = $$props.baz); }; return { things, foo, bar, baz }; @@ -187,20 +193,30 @@ class Component extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo", "bar", "baz"]); - dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + + dispatch_dev("SvelteRegisterComponent", { + component: this, + tagName: "Component", + options, + id: create_fragment.name + }); const { ctx } = this.$$; - const props = options.props || {}; - if (ctx.things === undefined && !('things' in props)) { + const props = options.props || ({}); + + if (ctx.things === undefined && !("things" in props)) { console.warn(" was created without expected prop 'things'"); } - if (ctx.foo === undefined && !('foo' in props)) { + + if (ctx.foo === undefined && !("foo" in props)) { console.warn(" was created without expected prop 'foo'"); } - if (ctx.bar === undefined && !('bar' in props)) { + + if (ctx.bar === undefined && !("bar" in props)) { console.warn(" was created without expected prop 'bar'"); } - if (ctx.baz === undefined && !('baz' in props)) { + + if (ctx.baz === undefined && !("baz" in props)) { console.warn(" was created without expected prop 'baz'"); } } diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 08a92171d1..c4c7983fd6 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponentDev, add_location, @@ -24,9 +23,11 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (6:0) {#each things as thing} function create_each_block(ctx) { - var span, t0_value = ctx.thing.name + "", t0, t1; + let span; + let t0_value = ctx.thing.name + ""; + let t0; + let t1; const block = { c: function create() { @@ -39,19 +40,16 @@ function create_each_block(ctx) { console.log({ foo }); debugger; } + add_location(span, file, 6, 1, 82); }, - m: function mount(target, anchor) { insert_dev(target, span, anchor); append_dev(span, t0); insert_dev(target, t1, anchor); }, - p: function update(changed, ctx) { - if ((changed.things) && t0_value !== (t0_value = ctx.thing.name + "")) { - set_data_dev(t0, t0_value); - } + if (changed.things && t0_value !== (t0_value = ctx.thing.name + "")) set_data_dev(t0, t0_value); if (changed.foo) { const { foo } = ctx; @@ -59,23 +57,29 @@ function create_each_block(ctx) { debugger; } }, - d: function destroy(detaching) { - if (detaching) { - detach_dev(span); - detach_dev(t1); - } + if (detaching) detach_dev(span); + if (detaching) detach_dev(t1); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_each_block.name, type: "each", source: "(6:0) {#each things as thing}", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_each_block.name, + type: "each", + source: "(6:0) {#each things as thing}", + ctx + }); + return block; } function create_fragment(ctx) { - var t0, p, t1, t2; - + let t0; + let p; + let t1; + let t2; let each_value = ctx.things; - let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { @@ -94,11 +98,9 @@ function create_fragment(ctx) { t2 = text(ctx.foo); add_location(p, file, 10, 0, 131); }, - l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, - m: function mount(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); @@ -109,12 +111,11 @@ function create_fragment(ctx) { append_dev(p, t1); append_dev(p, t2); }, - p: function update(changed, ctx) { if (changed.things) { each_value = ctx.things; - let i; + for (i = 0; i < each_value.length; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); @@ -130,41 +131,44 @@ function create_fragment(ctx) { for (; i < each_blocks.length; i += 1) { each_blocks[i].d(1); } + each_blocks.length = each_value.length; } - if (changed.foo) { - set_data_dev(t2, ctx.foo); - } + if (changed.foo) set_data_dev(t2, ctx.foo); }, - i: noop, o: noop, - d: function destroy(detaching) { destroy_each(each_blocks, detaching); - - if (detaching) { - detach_dev(t0); - detach_dev(p); - } + if (detaching) detach_dev(t0); + if (detaching) detach_dev(p); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_fragment.name, + type: "component", + source: "", + ctx + }); + return block; } function instance($$self, $$props, $$invalidate) { - let { things, foo } = $$props; + let { things } = $$props; + let { foo } = $$props; + const writable_props = ["things", "foo"]; - const writable_props = ['things', 'foo']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith("$$")) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("things" in $$props) $$invalidate("things", things = $$props.things); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; $$self.$capture_state = () => { @@ -172,8 +176,8 @@ function instance($$self, $$props, $$invalidate) { }; $$self.$inject_state = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("things" in $$props) $$invalidate("things", things = $$props.things); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { things, foo }; @@ -183,14 +187,22 @@ class Component extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo"]); - dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + + dispatch_dev("SvelteRegisterComponent", { + component: this, + tagName: "Component", + options, + id: create_fragment.name + }); const { ctx } = this.$$; - const props = options.props || {}; - if (ctx.things === undefined && !('things' in props)) { + const props = options.props || ({}); + + if (ctx.things === undefined && !("things" in props)) { console.warn(" was created without expected prop 'things'"); } - if (ctx.foo === undefined && !('foo' in props)) { + + if (ctx.foo === undefined && !("foo" in props)) { console.warn(" was created without expected prop 'foo'"); } } diff --git a/test/js/samples/debug-hoisted/expected.js b/test/js/samples/debug-hoisted/expected.js index 62327860e2..08e1203fec 100644 --- a/test/js/samples/debug-hoisted/expected.js +++ b/test/js/samples/debug-hoisted/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponentDev, dispatch_dev, @@ -18,13 +17,10 @@ function create_fragment(ctx) { debugger; } }, - l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, - m: noop, - p: function update(changed, ctx) { if (changed.obj || changed.kobzol) { const { obj } = ctx; @@ -32,12 +28,19 @@ function create_fragment(ctx) { debugger; } }, - i: noop, o: noop, d: noop }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_fragment.name, + type: "component", + source: "", + ctx + }); + return block; } @@ -51,8 +54,8 @@ function instance($$self) { }; $$self.$inject_state = $$props => { - if ('obj' in $$props) $$invalidate('obj', obj = $$props.obj); - if ('kobzol' in $$props) $$invalidate('kobzol', kobzol = $$props.kobzol); + if ("obj" in $$props) $$invalidate("obj", obj = $$props.obj); + if ("kobzol" in $$props) $$invalidate("kobzol", kobzol = $$props.kobzol); }; return { obj }; @@ -62,7 +65,13 @@ class Component extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance, create_fragment, safe_not_equal, []); - dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + + dispatch_dev("SvelteRegisterComponent", { + component: this, + tagName: "Component", + options, + id: create_fragment.name + }); } } diff --git a/test/js/samples/debug-ssr-foo/expected.js b/test/js/samples/debug-ssr-foo/expected.js index 1b51af2592..38d07e994e 100644 --- a/test/js/samples/debug-ssr-foo/expected.js +++ b/test/js/samples/debug-ssr-foo/expected.js @@ -1,21 +1,15 @@ -/* generated by Svelte vX.Y.Z */ -import { - create_ssr_component, - debug, - each, - escape -} from "svelte/internal"; +import { create_ssr_component, debug, each, escape } from "svelte/internal"; const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { - let { things, foo } = $$props; - + let { things } = $$props; + let { foo } = $$props; if ($$props.things === void 0 && $$bindings.things && things !== void 0) $$bindings.things(things); if ($$props.foo === void 0 && $$bindings.foo && foo !== void 0) $$bindings.foo(foo); - return `${each(things, (thing) => `${escape(thing.name)} - ${debug(null, 7, 2, { foo })}`)} + return `${each(things, thing => `${escape(thing.name)} + ${debug(null, 7, 2, { foo })}`)} -

foo: ${escape(foo)}

`; +

foo: ${escape(foo)}

`; }); export default Component; \ No newline at end of file diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 6609fcccf7..222d473201 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -20,40 +19,32 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (5:0) {#each createElement as node} function create_each_block(ctx) { - var span, t_value = ctx.node + "", t; + let span; + let t_value = ctx.node + ""; + let t; return { c() { span = element("span"); t = text(t_value); }, - m(target, anchor) { insert(target, span, anchor); append(span, t); }, - p(changed, ctx) { - if ((changed.createElement) && t_value !== (t_value = ctx.node + "")) { - set_data(t, t_value); - } + if (changed.createElement && t_value !== (t_value = ctx.node + "")) set_data(t, t_value); }, - d(detaching) { - if (detaching) { - detach(span); - } + if (detaching) detach(span); } }; } function create_fragment(ctx) { - var each_1_anchor; - + let each_anchor; let each_value = ctx.createElement; - let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { @@ -66,22 +57,20 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = empty(); + each_anchor = empty(); }, - m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_1_anchor, anchor); + insert(target, each_anchor, anchor); }, - p(changed, ctx) { if (changed.createElement) { each_value = ctx.createElement; - let i; + for (i = 0; i < each_value.length; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); @@ -90,26 +79,22 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); + each_blocks[i].m(each_anchor.parentNode, each_anchor); } } for (; i < each_blocks.length; i += 1) { each_blocks[i].d(1); } + each_blocks.length = each_value.length; } }, - i: noop, o: noop, - d(detaching) { destroy_each(each_blocks, detaching); - - if (detaching) { - detach(each_1_anchor); - } + if (detaching) detach(each_anchor); } }; } @@ -118,7 +103,7 @@ function instance($$self, $$props, $$invalidate) { let { createElement } = $$props; $$self.$set = $$props => { - if ('createElement' in $$props) $$invalidate('createElement', createElement = $$props.createElement); + if ("createElement" in $$props) $$invalidate("createElement", createElement = $$props.createElement); }; return { createElement }; diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index 347d0417ec..360045a5b9 100644 --- a/test/js/samples/deconflict-globals/expected.js +++ b/test/js/samples/deconflict-globals/expected.js @@ -1,10 +1,4 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; import { onMount } from "svelte"; function create_fragment(ctx) { @@ -19,14 +13,14 @@ function create_fragment(ctx) { } function instance($$self, $$props, $$invalidate) { - let { foo = 'bar' } = $$props; + let { foo = "bar" } = $$props; onMount(() => { alert(JSON.stringify(data())); }); $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index ad0cbc8aba..69f19eb258 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponentDev, add_location, @@ -18,7 +17,11 @@ import { const file = undefined; function create_fragment(ctx) { - var p, t0_value = Math.max(0, ctx.foo) + "", t0, t1, t2; + let p; + let t0_value = Math.max(0, ctx.foo) + ""; + let t0; + let t1; + let t2; const block = { c: function create() { @@ -28,53 +31,48 @@ function create_fragment(ctx) { t2 = text(ctx.bar); add_location(p, file, 7, 0, 67); }, - l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, - m: function mount(target, anchor) { insert_dev(target, p, anchor); append_dev(p, t0); append_dev(p, t1); append_dev(p, t2); }, - p: function update(changed, ctx) { - if ((changed.foo) && t0_value !== (t0_value = Math.max(0, ctx.foo) + "")) { - set_data_dev(t0, t0_value); - } - - if (changed.bar) { - set_data_dev(t2, ctx.bar); - } + if (changed.foo && t0_value !== (t0_value = Math.max(0, ctx.foo) + "")) set_data_dev(t0, t0_value); + if (changed.bar) set_data_dev(t2, ctx.bar); }, - i: noop, o: noop, - d: function destroy(detaching) { - if (detaching) { - detach_dev(p); - } + if (detaching) detach_dev(p); } }; - dispatch_dev("SvelteRegisterBlock", { block, id: create_fragment.name, type: "component", source: "", ctx }); + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_fragment.name, + type: "component", + source: "", + ctx + }); + return block; } function instance($$self, $$props, $$invalidate) { let { foo } = $$props; - let bar; + const writable_props = ["foo"]; - const writable_props = ['foo']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith("$$")) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; $$self.$capture_state = () => { @@ -82,12 +80,14 @@ function instance($$self, $$props, $$invalidate) { }; $$self.$inject_state = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); }; - $$self.$$.update = ($$dirty = { foo: 1 }) => { - if ($$dirty.foo) { $$invalidate('bar', bar = foo * 2); } + $$self.$$.update = (changed = { foo: 1 }) => { + if (changed.foo) { + $: $$invalidate("bar", bar = foo * 2); + } }; return { foo, bar }; @@ -97,11 +97,18 @@ class Component extends SvelteComponentDev { constructor(options) { super(options); init(this, options, instance, create_fragment, safe_not_equal, ["foo"]); - dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "Component", options, id: create_fragment.name }); + + dispatch_dev("SvelteRegisterComponent", { + component: this, + tagName: "Component", + options, + id: create_fragment.name + }); const { ctx } = this.$$; - const props = options.props || {}; - if (ctx.foo === undefined && !('foo' in props)) { + const props = options.props || ({}); + + if (ctx.foo === undefined && !("foo" in props)) { console.warn(" was created without expected prop 'foo'"); } } diff --git a/test/js/samples/dont-invalidate-this/expected.js b/test/js/samples/dont-invalidate-this/expected.js index 92033148eb..0cdc5bb903 100644 --- a/test/js/samples/dont-invalidate-this/expected.js +++ b/test/js/samples/dont-invalidate-this/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,27 +10,22 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var input, dispose; + let input; + let dispose; return { c() { input = element("input"); dispose = listen(input, "input", make_uppercase); }, - m(target, anchor) { insert(target, input, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(input); - } - + if (detaching) detach(input); dispose(); } }; diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index 8692cd89b2..50172bcb40 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -9,44 +8,38 @@ import { transition_in, transition_out } from "svelte/internal"; + import LazyLoad from "./LazyLoad.svelte"; function create_fragment(ctx) { - var current; - - var lazyload = new LazyLoad({ props: { load: func } }); + let current; + const lazyload = new LazyLoad({ props: { load: func } }); return { c() { lazyload.$$.fragment.c(); }, - m(target, anchor) { mount_component(lazyload, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(lazyload.$$.fragment, local); - current = true; }, - o(local) { transition_out(lazyload.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(lazyload, detaching); } }; } -const func = () => import('./Foo.svelte'); +const func = () => import("./Foo.svelte"); class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index 6ca6773f6b..2eb1d903de 100644 --- a/test/js/samples/each-block-array-literal/expected.js +++ b/test/js/samples/each-block-array-literal/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -20,40 +19,32 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (9:0) {#each [a, b, c, d, e] as num} function create_each_block(ctx) { - var span, t_value = ctx.num + "", t; + let span; + let t_value = ctx.num + ""; + let t; return { c() { span = element("span"); t = text(t_value); }, - m(target, anchor) { insert(target, span, anchor); append(span, t); }, - p(changed, ctx) { - if ((changed.a || changed.b || changed.c || changed.d || changed.e) && t_value !== (t_value = ctx.num + "")) { - set_data(t, t_value); - } + if ((changed.a || changed.b || changed.c || changed.d || changed.e) && t_value !== (t_value = ctx.num + "")) set_data(t, t_value); }, - d(detaching) { - if (detaching) { - detach(span); - } + if (detaching) detach(span); } }; } function create_fragment(ctx) { - var each_1_anchor; - + let each_anchor; let each_value = [ctx.a, ctx.b, ctx.c, ctx.d, ctx.e]; - let each_blocks = []; for (let i = 0; i < 5; i += 1) { @@ -66,23 +57,21 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = empty(); + each_anchor = empty(); }, - m(target, anchor) { for (let i = 0; i < 5; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_1_anchor, anchor); + insert(target, each_anchor, anchor); }, - p(changed, ctx) { if (changed.a || changed.b || changed.c || changed.d || changed.e) { each_value = [ctx.a, ctx.b, ctx.c, ctx.d, ctx.e]; - let i; - for (i = 0; i < each_value.length; i += 1) { + + for (i = 0; i < 5; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); if (each_blocks[i]) { @@ -90,7 +79,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); + each_blocks[i].m(each_anchor.parentNode, each_anchor); } } @@ -99,29 +88,28 @@ function create_fragment(ctx) { } } }, - i: noop, o: noop, - d(detaching) { destroy_each(each_blocks, detaching); - - if (detaching) { - detach(each_1_anchor); - } + if (detaching) detach(each_anchor); } }; } function instance($$self, $$props, $$invalidate) { - let { a, b, c, d, e } = $$props; + let { a } = $$props; + let { b } = $$props; + let { c } = $$props; + let { d } = $$props; + let { e } = $$props; $$self.$set = $$props => { - if ('a' in $$props) $$invalidate('a', a = $$props.a); - if ('b' in $$props) $$invalidate('b', b = $$props.b); - if ('c' in $$props) $$invalidate('c', c = $$props.c); - if ('d' in $$props) $$invalidate('d', d = $$props.d); - if ('e' in $$props) $$invalidate('e', e = $$props.e); + if ("a" in $$props) $$invalidate("a", a = $$props.a); + if ("b" in $$props) $$invalidate("b", b = $$props.b); + if ("c" in $$props) $$invalidate("c", c = $$props.c); + if ("d" in $$props) $$invalidate("d", d = $$props.d); + if ("e" in $$props) $$invalidate("e", e = $$props.e); }; return { a, b, c, d, e }; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 0601c31334..7e528d1c6b 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { HtmlTag, SvelteComponent, @@ -23,9 +22,21 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (8:0) {#each comments as comment, i} function create_each_block(ctx) { - var div, strong, t0, t1, span, t2_value = ctx.comment.author + "", t2, t3, t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + "", t4, t5, t6, html_tag, raw_value = ctx.comment.html + ""; + let div; + let strong; + let t0; + let t1; + let span; + let t2_value = ctx.comment.author + ""; + let t2; + let t3; + let t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + ""; + let t4; + let t5; + let t6; + let html_tag; + let raw_value = ctx.comment.html + ""; return { c() { @@ -43,7 +54,6 @@ function create_each_block(ctx) { html_tag = new HtmlTag(raw_value, null); attr(div, "class", "comment"); }, - m(target, anchor) { insert(target, div, anchor); append(div, strong); @@ -57,34 +67,22 @@ function create_each_block(ctx) { append(div, t6); html_tag.m(div); }, - p(changed, ctx) { - if ((changed.comments) && t2_value !== (t2_value = ctx.comment.author + "")) { - set_data(t2, t2_value); - } - - if ((changed.elapsed || changed.comments || changed.time) && t4_value !== (t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + "")) { - set_data(t4, t4_value); - } - - if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html + "")) { - html_tag.p(raw_value); - } + if (changed.comments && t2_value !== (t2_value = ctx.comment.author + "")) set_data(t2, t2_value); + if ((changed.elapsed || changed.comments || changed.time) && t4_value !== (t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + "")) set_data(t4, t4_value); + if (changed.comments && raw_value !== (raw_value = ctx.comment.html + "")) html_tag.p(raw_value); }, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function create_fragment(ctx) { - var t0, p, t1; - + let t0; + let p; + let t1; let each_value = ctx.comments; - let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { @@ -101,7 +99,6 @@ function create_fragment(ctx) { p = element("p"); t1 = text(ctx.foo); }, - m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); @@ -111,12 +108,11 @@ function create_fragment(ctx) { insert(target, p, anchor); append(p, t1); }, - p(changed, ctx) { if (changed.comments || changed.elapsed || changed.time) { each_value = ctx.comments; - let i; + for (i = 0; i < each_value.length; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); @@ -132,36 +128,33 @@ function create_fragment(ctx) { for (; i < each_blocks.length; i += 1) { each_blocks[i].d(1); } + each_blocks.length = each_value.length; } - if (changed.foo) { - set_data(t1, ctx.foo); - } + if (changed.foo) set_data(t1, ctx.foo); }, - i: noop, o: noop, - d(detaching) { destroy_each(each_blocks, detaching); - - if (detaching) { - detach(t0); - detach(p); - } + if (detaching) detach(t0); + if (detaching) detach(p); } }; } function instance($$self, $$props, $$invalidate) { - let { comments, elapsed, time, foo } = $$props; + let { comments } = $$props; + let { elapsed } = $$props; + let { time } = $$props; + let { foo } = $$props; $$self.$set = $$props => { - if ('comments' in $$props) $$invalidate('comments', comments = $$props.comments); - if ('elapsed' in $$props) $$invalidate('elapsed', elapsed = $$props.elapsed); - if ('time' in $$props) $$invalidate('time', time = $$props.time); - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("comments" in $$props) $$invalidate("comments", comments = $$props.comments); + if ("elapsed" in $$props) $$invalidate("elapsed", elapsed = $$props.elapsed); + if ("time" in $$props) $$invalidate("time", time = $$props.time); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { comments, elapsed, time, foo }; diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 25aa1e5c5d..e2e8357805 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -23,65 +22,56 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (19:0) {#each things as thing (thing.id)} function create_each_block(key_1, ctx) { - var div, t_value = ctx.thing.name + "", t, rect, stop_animation = noop; + let div; + let t_value = ctx.thing.name + ""; + let t; + let rect; + let stop_animation = noop; return { key: key_1, - first: null, - c() { div = element("div"); t = text(t_value); this.first = div; }, - m(target, anchor) { insert(target, div, anchor); append(div, t); }, - p(changed, ctx) { - if ((changed.things) && t_value !== (t_value = ctx.thing.name + "")) { - set_data(t, t_value); - } + if (changed.things && t_value !== (t_value = ctx.thing.name + "")) set_data(t, t_value); }, - r() { rect = div.getBoundingClientRect(); }, - f() { fix_position(div); stop_animation(); }, - a() { stop_animation(); stop_animation = create_animation(div, rect, foo, {}); }, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function create_fragment(ctx) { - var each_blocks = [], each_1_lookup = new Map(), each_1_anchor; - + let each_blocks = []; + let each_lookup = new Map(); + let each_anchor; let each_value = ctx.things; - const get_key = ctx => ctx.thing.id; for (let i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); } return { @@ -90,35 +80,29 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = empty(); + each_anchor = empty(); }, - m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_1_anchor, anchor); + insert(target, each_anchor, anchor); }, - p(changed, ctx) { const each_value = ctx.things; for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r(); - each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, fix_and_destroy_block, create_each_block, each_1_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, fix_and_destroy_block, create_each_block, each_anchor, get_each_context); for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a(); }, - i: noop, o: noop, - d(detaching) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].d(detaching); } - if (detaching) { - detach(each_1_anchor); - } + if (detaching) detach(each_anchor); } }; } @@ -141,7 +125,7 @@ function instance($$self, $$props, $$invalidate) { let { things } = $$props; $$self.$set = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); + if ("things" in $$props) $$invalidate("things", things = $$props.things); }; return { things }; diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index ae20825344..5e149826b8 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -21,51 +20,43 @@ function get_each_context(ctx, list, i) { return child_ctx; } -// (5:0) {#each things as thing (thing.id)} function create_each_block(key_1, ctx) { - var div, t_value = ctx.thing.name + "", t; + let div; + let t_value = ctx.thing.name + ""; + let t; return { key: key_1, - first: null, - c() { div = element("div"); t = text(t_value); this.first = div; }, - m(target, anchor) { insert(target, div, anchor); append(div, t); }, - p(changed, ctx) { - if ((changed.things) && t_value !== (t_value = ctx.thing.name + "")) { - set_data(t, t_value); - } + if (changed.things && t_value !== (t_value = ctx.thing.name + "")) set_data(t, t_value); }, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function create_fragment(ctx) { - var each_blocks = [], each_1_lookup = new Map(), each_1_anchor; - + let each_blocks = []; + let each_lookup = new Map(); + let each_anchor; let each_value = ctx.things; - const get_key = ctx => ctx.thing.id; for (let i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); } return { @@ -74,33 +65,27 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = empty(); + each_anchor = empty(); }, - m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_1_anchor, anchor); + insert(target, each_anchor, anchor); }, - p(changed, ctx) { const each_value = ctx.things; - each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block, each_1_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, destroy_block, create_each_block, each_anchor, get_each_context); }, - i: noop, o: noop, - d(detaching) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].d(detaching); } - if (detaching) { - detach(each_1_anchor); - } + if (detaching) detach(each_anchor); } }; } @@ -109,7 +94,7 @@ function instance($$self, $$props, $$invalidate) { let { things } = $$props; $$self.$set = $$props => { - if ('things' in $$props) $$invalidate('things', things = $$props.things); + if ("things" in $$props) $$invalidate("things", things = $$props.things); }; return { things }; diff --git a/test/js/samples/event-handler-no-passive/expected.js b/test/js/samples/event-handler-no-passive/expected.js index 69285a29c6..305b4153b1 100644 --- a/test/js/samples/event-handler-no-passive/expected.js +++ b/test/js/samples/event-handler-no-passive/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -12,7 +11,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var a, dispose; + let a; + let dispose; return { c() { @@ -21,26 +21,20 @@ function create_fragment(ctx) { attr(a, "href", "https://example.com"); dispose = listen(a, "touchstart", touchstart_handler); }, - m(target, anchor) { insert(target, a, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(a); - } - + if (detaching) detach(a); dispose(); } }; } -const touchstart_handler = (e) => e.preventDefault(); +const touchstart_handler = e => e.preventDefault(); class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/event-modifiers/expected.js b/test/js/samples/event-modifiers/expected.js index bd449ea5a4..f586a89be2 100644 --- a/test/js/samples/event-modifiers/expected.js +++ b/test/js/samples/event-modifiers/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -16,7 +15,13 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div, button0, t1, button1, t3, button2, dispose; + let div; + let button0; + let t1; + let button1; + let t3; + let button2; + let dispose; return { c() { @@ -29,6 +34,7 @@ function create_fragment(ctx) { t3 = space(); button2 = element("button"); button2.textContent = "or me!"; + dispose = [ listen(button0, "click", stop_propagation(prevent_default(handleClick))), listen(button1, "click", handleClick, { once: true, capture: true }), @@ -36,7 +42,6 @@ function create_fragment(ctx) { listen(div, "touchstart", handleTouchstart, { passive: true }) ]; }, - m(target, anchor) { insert(target, div, anchor); append(div, button0); @@ -45,27 +50,22 @@ function create_fragment(ctx) { append(div, t3); append(div, button2); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } - + if (detaching) detach(div); run_all(dispose); } }; } function handleTouchstart() { - // ... + } function handleClick() { - // ... + } class Component extends SvelteComponent { diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js index 457df77dc8..34545ab656 100644 --- a/test/js/samples/head-no-whitespace/expected.js +++ b/test/js/samples/head-no-whitespace/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -11,7 +10,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var meta0, meta1; + let meta0; + let meta1; return { c() { @@ -22,16 +22,13 @@ function create_fragment(ctx) { attr(meta1, "name", "twitter:title"); attr(meta1, "content", "Svelte"); }, - m(target, anchor) { append(document.head, meta0); append(document.head, meta1); }, - p: noop, i: noop, o: noop, - d(detaching) { detach(meta0); detach(meta1); diff --git a/test/js/samples/hoisted-const/expected.js b/test/js/samples/hoisted-const/expected.js index ccd0b3c480..af4d360d35 100644 --- a/test/js/samples/hoisted-const/expected.js +++ b/test/js/samples/hoisted-const/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,34 +11,33 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var b, t_value = get_answer() + "", t; + let b; + let t_value = get_answer() + ""; + let t; return { c() { b = element("b"); t = text(t_value); }, - m(target, anchor) { insert(target, b, anchor); append(b, t); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(b); - } + if (detaching) detach(b); } }; } const ANSWER = 42; -function get_answer() { return ANSWER; } +function get_answer() { + return ANSWER; +} class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/hoisted-let/expected.js b/test/js/samples/hoisted-let/expected.js index e2a9186dbd..5392a5018c 100644 --- a/test/js/samples/hoisted-let/expected.js +++ b/test/js/samples/hoisted-let/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,34 +11,33 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var b, t_value = get_answer() + "", t; + let b; + let t_value = get_answer() + ""; + let t; return { c() { b = element("b"); t = text(t_value); }, - m(target, anchor) { insert(target, b, anchor); append(b, t); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(b); - } + if (detaching) detach(b); } }; } let ANSWER = 42; -function get_answer() { return ANSWER; } +function get_answer() { + return ANSWER; +} class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/if-block-complex/expected.js b/test/js/samples/if-block-complex/expected.js index 67d537f343..fd882d7561 100644 --- a/test/js/samples/if-block-complex/expected.js +++ b/test/js/samples/if-block-complex/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -11,63 +10,49 @@ import { safe_not_equal } from "svelte/internal"; -// (7:0) {#if (item.divider && item.divider.includes(1))} function create_if_block(ctx) { - var div; + let div; return { c() { div = element("div"); attr(div, "class", "divider"); }, - m(target, anchor) { insert(target, div, anchor); }, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function create_fragment(ctx) { - var show_if = (ctx.item.divider && ctx.item.divider.includes(1)), if_block_anchor; - - var if_block = (show_if) && create_if_block(ctx); + let show_if = ctx.item.divider && ctx.item.divider.includes(1); + let if_block_anchor; + let if_block = show_if && create_if_block(ctx); return { c() { if (if_block) if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if (if_block) if_block.m(target, anchor); insert(target, if_block_anchor, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { if (if_block) if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } function instance($$self) { - let item = { - divider: [1] - } - + let item = { divider: [1] }; return { item }; } diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 5cb29e8593..829ddf8ddd 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -10,92 +9,76 @@ import { safe_not_equal } from "svelte/internal"; -// (7:0) {:else} function create_else_block(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "not foo!"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } -// (5:0) {#if foo} function create_if_block(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "foo!"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } function create_fragment(ctx) { - var if_block_anchor; + let if_block_anchor; function select_block_type(changed, ctx) { if (ctx.foo) return create_if_block; return create_else_block; } - var current_block_type = select_block_type(null, ctx); - var if_block = current_block_type(ctx); + let current_block_type = select_block_type(null, ctx); + let if_block = current_block_type(ctx); return { c() { if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if_block.m(target, anchor); insert(target, if_block_anchor, anchor); }, - p(changed, ctx) { if (current_block_type !== (current_block_type = select_block_type(changed, ctx))) { if_block.d(1); if_block = current_block_type(ctx); + if (if_block) { if_block.c(); if_block.m(if_block_anchor.parentNode, if_block_anchor); } } }, - i: noop, o: noop, - d(detaching) { if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } @@ -104,7 +87,7 @@ function instance($$self, $$props, $$invalidate) { let { foo } = $$props; $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 94b0f37f31..8f4cd20e28 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -10,66 +9,55 @@ import { safe_not_equal } from "svelte/internal"; -// (5:0) {#if foo} function create_if_block(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "foo!"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } function create_fragment(ctx) { - var if_block_anchor; - - var if_block = (ctx.foo) && create_if_block(ctx); + let if_block_anchor; + let if_block = ctx.foo && create_if_block(ctx); return { c() { if (if_block) if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if (if_block) if_block.m(target, anchor); insert(target, if_block_anchor, anchor); }, - p(changed, ctx) { if (ctx.foo) { if (!if_block) { if_block = create_if_block(ctx); if_block.c(); if_block.m(if_block_anchor.parentNode, if_block_anchor); + } else { + } } else if (if_block) { if_block.d(1); if_block = null; } }, - i: noop, o: noop, - d(detaching) { if (if_block) if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } @@ -78,7 +66,7 @@ function instance($$self, $$props, $$invalidate) { let { foo } = $$props; $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index ea1d90e831..1296548b99 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,7 +10,7 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div; + let div; return { c() { @@ -19,11 +18,9 @@ function create_fragment(ctx) { set_style(div, "color", ctx.color); set_style(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); }, - m(target, anchor) { insert(target, div, anchor); }, - p(changed, ctx) { if (changed.color) { set_style(div, "color", ctx.color); @@ -33,25 +30,23 @@ function create_fragment(ctx) { set_style(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)"); } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function instance($$self, $$props, $$invalidate) { - let { color, x, y } = $$props; + let { color } = $$props; + let { x } = $$props; + let { y } = $$props; $$self.$set = $$props => { - if ('color' in $$props) $$invalidate('color', color = $$props.color); - if ('x' in $$props) $$invalidate('x', x = $$props.x); - if ('y' in $$props) $$invalidate('y', y = $$props.y); + if ("color" in $$props) $$invalidate("color", color = $$props.color); + if ("x" in $$props) $$invalidate("x", x = $$props.x); + if ("y" in $$props) $$invalidate("y", y = $$props.y); }; return { color, x, y }; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 8dfc48447d..c094fb73d6 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,31 +10,25 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div; + let div; return { c() { div = element("div"); set_style(div, "background", "url(data:image/png;base64," + ctx.data + ")"); }, - m(target, anchor) { insert(target, div, anchor); }, - p(changed, ctx) { if (changed.data) { set_style(div, "background", "url(data:image/png;base64," + ctx.data + ")"); } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } @@ -44,7 +37,7 @@ function instance($$self, $$props, $$invalidate) { let { data } = $$props; $$self.$set = $$props => { - if ('data' in $$props) $$invalidate('data', data = $$props.data); + if ("data" in $$props) $$invalidate("data", data = $$props.data); }; return { data }; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 1170c25458..d77f465dea 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,31 +10,25 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div; + let div; return { c() { div = element("div"); set_style(div, "color", ctx.color); }, - m(target, anchor) { insert(target, div, anchor); }, - p(changed, ctx) { if (changed.color) { set_style(div, "color", ctx.color); } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } @@ -44,7 +37,7 @@ function instance($$self, $$props, $$invalidate) { let { color } = $$props; $$self.$set = $$props => { - if ('color' in $$props) $$invalidate('color', color = $$props.color); + if ("color" in $$props) $$invalidate("color", color = $$props.color); }; return { color }; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 9349ade12c..d1a36c12ca 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -12,7 +11,10 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div0, t, div1, div1_style_value; + let div0; + let t; + let div1; + let div1_style_value; return { c() { @@ -20,45 +22,41 @@ function create_fragment(ctx) { t = space(); div1 = element("div"); attr(div0, "style", ctx.style); - attr(div1, "style", div1_style_value = "" + ctx.key + ": " + ctx.value); + attr(div1, "style", div1_style_value = "" + (ctx.key + ": " + ctx.value)); }, - m(target, anchor) { insert(target, div0, anchor); insert(target, t, anchor); insert(target, div1, anchor); }, - p(changed, ctx) { if (changed.style) { attr(div0, "style", ctx.style); } - if ((changed.key || changed.value) && div1_style_value !== (div1_style_value = "" + ctx.key + ": " + ctx.value)) { + if ((changed.key || changed.value) && div1_style_value !== (div1_style_value = "" + (ctx.key + ": " + ctx.value))) { attr(div1, "style", div1_style_value); } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div0); - detach(t); - detach(div1); - } + if (detaching) detach(div0); + if (detaching) detach(t); + if (detaching) detach(div1); } }; } function instance($$self, $$props, $$invalidate) { - let { style, key, value } = $$props; + let { style } = $$props; + let { key } = $$props; + let { value } = $$props; $$self.$set = $$props => { - if ('style' in $$props) $$invalidate('style', style = $$props.style); - if ('key' in $$props) $$invalidate('key', key = $$props.key); - if ('value' in $$props) $$invalidate('value', value = $$props.value); + if ("style" in $$props) $$invalidate("style", style = $$props.style); + if ("key" in $$props) $$invalidate("key", key = $$props.key); + if ("value" in $$props) $$invalidate("value", value = $$props.value); }; return { style, key, value }; diff --git a/test/js/samples/inline-style-without-updates/expected.js b/test/js/samples/inline-style-without-updates/expected.js index 73995c4755..6e56641236 100644 --- a/test/js/samples/inline-style-without-updates/expected.js +++ b/test/js/samples/inline-style-without-updates/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,31 +10,26 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var div; + let div; return { c() { div = element("div"); set_style(div, "color", color); }, - m(target, anchor) { insert(target, div, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } -let color = 'red'; +let color = "red"; class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/input-files/expected.js b/test/js/samples/input-files/expected.js index d4442d57ee..3584fde535 100644 --- a/test/js/samples/input-files/expected.js +++ b/test/js/samples/input-files/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -12,7 +11,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var input, dispose; + let input; + let dispose; return { c() { @@ -21,20 +21,14 @@ function create_fragment(ctx) { input.multiple = true; dispose = listen(input, "change", ctx.input_change_handler); }, - m(target, anchor) { insert(target, input, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(input); - } - + if (detaching) detach(input); dispose(); } }; @@ -45,11 +39,11 @@ function instance($$self, $$props, $$invalidate) { function input_change_handler() { files = this.files; - $$invalidate('files', files); + $$invalidate("files", files); } $$self.$set = $$props => { - if ('files' in $$props) $$invalidate('files', files = $$props.files); + if ("files" in $$props) $$invalidate("files", files = $$props.files); }; return { files, input_change_handler }; diff --git a/test/js/samples/input-no-initial-value/expected.js b/test/js/samples/input-no-initial-value/expected.js index a651d72059..db7f7df0c4 100644 --- a/test/js/samples/input-no-initial-value/expected.js +++ b/test/js/samples/input-no-initial-value/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -16,13 +15,17 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var form, input, t, button, dispose; + let form; + let input; + let t0; + let button; + let dispose; return { c() { form = element("form"); input = element("input"); - t = space(); + t0 = space(); button = element("button"); button.textContent = "Store"; attr(input, "type", "text"); @@ -33,29 +36,22 @@ function create_fragment(ctx) { listen(form, "submit", ctx.handleSubmit) ]; }, - m(target, anchor) { insert(target, form, anchor); append(form, input); - set_input_value(input, ctx.test); - - append(form, t); + append(form, t0); append(form, button); }, - p(changed, ctx) { - if (changed.test && (input.value !== ctx.test)) set_input_value(input, ctx.test); + if (changed.test && input.value !== ctx.test) { + set_input_value(input, ctx.test); + } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(form); - } - + if (detaching) detach(form); run_all(dispose); } }; @@ -66,15 +62,19 @@ function instance($$self, $$props, $$invalidate) { function handleSubmit(event) { event.preventDefault(); - console.log('value', test); + console.log("value", test); } function input_input_handler() { test = this.value; - $$invalidate('test', test); + $$invalidate("test", test); } - return { test, handleSubmit, input_input_handler }; + return { + test, + handleSubmit, + input_input_handler + }; } class Component extends SvelteComponent { diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js index 04552d20cd..e9b10c75b3 100644 --- a/test/js/samples/input-range/expected.js +++ b/test/js/samples/input-range/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -15,7 +14,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var input, dispose; + let input; + let dispose; return { c() { @@ -27,25 +27,19 @@ function create_fragment(ctx) { listen(input, "input", ctx.input_change_input_handler) ]; }, - m(target, anchor) { insert(target, input, anchor); - set_input_value(input, ctx.value); }, - p(changed, ctx) { - if (changed.value) set_input_value(input, ctx.value); + if (changed.value) { + set_input_value(input, ctx.value); + } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(input); - } - + if (detaching) detach(input); run_all(dispose); } }; @@ -56,11 +50,11 @@ function instance($$self, $$props, $$invalidate) { function input_change_input_handler() { value = to_number(this.value); - $$invalidate('value', value); + $$invalidate("value", value); } $$self.$set = $$props => { - if ('value' in $$props) $$invalidate('value', value = $$props.value); + if ("value" in $$props) $$invalidate("value", value = $$props.value); }; return { value, input_change_input_handler }; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index d97326fcea..f4a7399bda 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -12,7 +11,8 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var input, dispose; + let input; + let dispose; return { c() { @@ -20,25 +20,19 @@ function create_fragment(ctx) { attr(input, "type", "checkbox"); dispose = listen(input, "change", ctx.input_change_handler); }, - m(target, anchor) { insert(target, input, anchor); - input.checked = ctx.foo; }, - p(changed, ctx) { - if (changed.foo) input.checked = ctx.foo; + if (changed.foo) { + input.checked = ctx.foo; + } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(input); - } - + if (detaching) detach(input); dispose(); } }; @@ -49,11 +43,11 @@ function instance($$self, $$props, $$invalidate) { function input_change_handler() { foo = this.checked; - $$invalidate('foo', foo); + $$invalidate("foo", foo); } $$self.$set = $$props => { - if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ("foo" in $$props) $$invalidate("foo", foo = $$props.foo); }; return { foo, input_change_handler }; diff --git a/test/js/samples/instrumentation-script-if-no-block/expected.js b/test/js/samples/instrumentation-script-if-no-block/expected.js index ce5948de73..819263603a 100644 --- a/test/js/samples/instrumentation-script-if-no-block/expected.js +++ b/test/js/samples/instrumentation-script-if-no-block/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -15,7 +14,12 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var button, t1, p, t2, t3, dispose; + let button; + let t1; + let p; + let t2; + let t3; + let dispose; return { c() { @@ -27,7 +31,6 @@ function create_fragment(ctx) { t3 = text(ctx.x); dispose = listen(button, "click", ctx.foo); }, - m(target, anchor) { insert(target, button, anchor); insert(target, t1, anchor); @@ -35,23 +38,15 @@ function create_fragment(ctx) { append(p, t2); append(p, t3); }, - p(changed, ctx) { - if (changed.x) { - set_data(t3, ctx.x); - } + if (changed.x) set_data(t3, ctx.x); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - detach(t1); - detach(p); - } - + if (detaching) detach(button); + if (detaching) detach(t1); + if (detaching) detach(p); dispose(); } }; @@ -61,7 +56,7 @@ function instance($$self, $$props, $$invalidate) { let x = 0; function foo() { - if (true) $$invalidate('x', x += 1); + if (true) $$invalidate("x", x += 1); } return { x, foo }; diff --git a/test/js/samples/instrumentation-script-x-equals-x/expected.js b/test/js/samples/instrumentation-script-x-equals-x/expected.js index 0d7740b55d..bcae49d2a1 100644 --- a/test/js/samples/instrumentation-script-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-script-x-equals-x/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -15,7 +14,13 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var button, t1, p, t2, t3_value = ctx.things.length + "", t3, dispose; + let button; + let t1; + let p; + let t2; + let t3_value = ctx.things.length + ""; + let t3; + let dispose; return { c() { @@ -27,7 +32,6 @@ function create_fragment(ctx) { t3 = text(t3_value); dispose = listen(button, "click", ctx.foo); }, - m(target, anchor) { insert(target, button, anchor); insert(target, t1, anchor); @@ -35,23 +39,15 @@ function create_fragment(ctx) { append(p, t2); append(p, t3); }, - p(changed, ctx) { - if ((changed.things) && t3_value !== (t3_value = ctx.things.length + "")) { - set_data(t3, t3_value); - } + if (changed.things && t3_value !== (t3_value = ctx.things.length + "")) set_data(t3, t3_value); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - detach(t1); - detach(p); - } - + if (detaching) detach(button); + if (detaching) detach(t1); + if (detaching) detach(p); dispose(); } }; @@ -62,7 +58,7 @@ function instance($$self, $$props, $$invalidate) { function foo() { things.push(1); - $$invalidate('things', things); + $$invalidate("things", things); } return { things, foo }; diff --git a/test/js/samples/instrumentation-template-if-no-block/expected.js b/test/js/samples/instrumentation-template-if-no-block/expected.js index 4591d8c797..a3859b1b13 100644 --- a/test/js/samples/instrumentation-template-if-no-block/expected.js +++ b/test/js/samples/instrumentation-template-if-no-block/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -15,7 +14,12 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var button, t1, p, t2, t3, dispose; + let button; + let t1; + let p; + let t2; + let t3; + let dispose; return { c() { @@ -27,7 +31,6 @@ function create_fragment(ctx) { t3 = text(ctx.x); dispose = listen(button, "click", ctx.click_handler); }, - m(target, anchor) { insert(target, button, anchor); insert(target, t1, anchor); @@ -35,23 +38,15 @@ function create_fragment(ctx) { append(p, t2); append(p, t3); }, - p(changed, ctx) { - if (changed.x) { - set_data(t3, ctx.x); - } + if (changed.x) set_data(t3, ctx.x); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - detach(t1); - detach(p); - } - + if (detaching) detach(button); + if (detaching) detach(t1); + if (detaching) detach(p); dispose(); } }; @@ -61,7 +56,7 @@ function instance($$self, $$props, $$invalidate) { let x = 0; const click_handler = () => { - if (true) $$invalidate('x', x += 1); + if (true) $$invalidate("x", x += 1); }; return { x, click_handler }; diff --git a/test/js/samples/instrumentation-template-x-equals-x/expected.js b/test/js/samples/instrumentation-template-x-equals-x/expected.js index b08130016b..a1f3149aa1 100644 --- a/test/js/samples/instrumentation-template-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-template-x-equals-x/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -15,7 +14,13 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var button, t1, p, t2, t3_value = ctx.things.length + "", t3, dispose; + let button; + let t1; + let p; + let t2; + let t3_value = ctx.things.length + ""; + let t3; + let dispose; return { c() { @@ -27,7 +32,6 @@ function create_fragment(ctx) { t3 = text(t3_value); dispose = listen(button, "click", ctx.click_handler); }, - m(target, anchor) { insert(target, button, anchor); insert(target, t1, anchor); @@ -35,23 +39,15 @@ function create_fragment(ctx) { append(p, t2); append(p, t3); }, - p(changed, ctx) { - if ((changed.things) && t3_value !== (t3_value = ctx.things.length + "")) { - set_data(t3, t3_value); - } + if (changed.things && t3_value !== (t3_value = ctx.things.length + "")) set_data(t3, t3_value); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - detach(t1); - detach(p); - } - + if (detaching) detach(button); + if (detaching) detach(t1); + if (detaching) detach(p); dispose(); } }; @@ -60,7 +56,10 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let things = []; - const click_handler = () => { things.push(1); $$invalidate('things', things) }; + const click_handler = () => { + things.push(1); + $$invalidate("things", things); + }; return { things, click_handler }; } diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 4c77259a64..3cd5243db6 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, @@ -11,26 +10,21 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var input; + let input; return { c() { input = element("input"); set_input_type(input, "search"); }, - m(target, anchor) { insert(target, input, anchor); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(input); - } + if (detaching) detach(input); } }; } diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index b67bc31ed3..25d21137e4 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -15,14 +14,20 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var audio, audio_updating = false, audio_animationframe, audio_is_paused = true, dispose; + let audio; + let audio_updating = false; + let audio_animationframe; + let audio_is_paused = true; + let dispose; function audio_timeupdate_handler() { cancelAnimationFrame(audio_animationframe); + if (!audio.paused) { audio_animationframe = raf(audio_timeupdate_handler); audio_updating = true; } + ctx.audio_timeupdate_handler.call(audio); } @@ -45,87 +50,97 @@ function create_fragment(ctx) { listen(audio, "ratechange", ctx.audio_ratechange_handler) ]; }, - m(target, anchor) { insert(target, audio, anchor); - audio.volume = ctx.volume; - audio.playbackRate = ctx.playbackRate; }, - p(changed, ctx) { - if (!audio_updating && changed.currentTime && !isNaN(ctx.currentTime)) audio.currentTime = ctx.currentTime; - if (changed.paused && audio_is_paused !== (audio_is_paused = ctx.paused)) audio[audio_is_paused ? "pause" : "play"](); - if (changed.volume && !isNaN(ctx.volume)) audio.volume = ctx.volume; - if (changed.playbackRate && !isNaN(ctx.playbackRate)) audio.playbackRate = ctx.playbackRate; + if (!audio_updating && changed.currentTime && !isNaN(ctx.currentTime)) { + audio.currentTime = ctx.currentTime; + } + + if (changed.paused && audio_is_paused !== (audio_is_paused = ctx.paused)) { + audio[audio_is_paused ? "pause" : "play"](); + } + + if (changed.volume && !isNaN(ctx.volume)) { + audio.volume = ctx.volume; + } + + if (changed.playbackRate && !isNaN(ctx.playbackRate)) { + audio.playbackRate = ctx.playbackRate; + } + audio_updating = false; }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(audio); - } - + if (detaching) detach(audio); run_all(dispose); } }; } function instance($$self, $$props, $$invalidate) { - let { buffered, seekable, played, currentTime, duration, paused, volume, playbackRate } = $$props; + let { buffered } = $$props; + let { seekable } = $$props; + let { played } = $$props; + let { currentTime } = $$props; + let { duration } = $$props; + let { paused } = $$props; + let { volume } = $$props; + let { playbackRate } = $$props; function audio_timeupdate_handler() { played = time_ranges_to_array(this.played); currentTime = this.currentTime; - $$invalidate('played', played); - $$invalidate('currentTime', currentTime); + $$invalidate("played", played); + $$invalidate("currentTime", currentTime); } function audio_durationchange_handler() { duration = this.duration; - $$invalidate('duration', duration); + $$invalidate("duration", duration); } function audio_play_pause_handler() { paused = this.paused; - $$invalidate('paused', paused); + $$invalidate("paused", paused); } function audio_progress_handler() { buffered = time_ranges_to_array(this.buffered); - $$invalidate('buffered', buffered); + $$invalidate("buffered", buffered); } function audio_loadedmetadata_handler() { buffered = time_ranges_to_array(this.buffered); seekable = time_ranges_to_array(this.seekable); - $$invalidate('buffered', buffered); - $$invalidate('seekable', seekable); + $$invalidate("buffered", buffered); + $$invalidate("seekable", seekable); } function audio_volumechange_handler() { volume = this.volume; - $$invalidate('volume', volume); + $$invalidate("volume", volume); } function audio_ratechange_handler() { playbackRate = this.playbackRate; - $$invalidate('playbackRate', playbackRate); + $$invalidate("playbackRate", playbackRate); } $$self.$set = $$props => { - if ('buffered' in $$props) $$invalidate('buffered', buffered = $$props.buffered); - if ('seekable' in $$props) $$invalidate('seekable', seekable = $$props.seekable); - if ('played' in $$props) $$invalidate('played', played = $$props.played); - if ('currentTime' in $$props) $$invalidate('currentTime', currentTime = $$props.currentTime); - if ('duration' in $$props) $$invalidate('duration', duration = $$props.duration); - if ('paused' in $$props) $$invalidate('paused', paused = $$props.paused); - if ('volume' in $$props) $$invalidate('volume', volume = $$props.volume); - if ('playbackRate' in $$props) $$invalidate('playbackRate', playbackRate = $$props.playbackRate); + if ("buffered" in $$props) $$invalidate("buffered", buffered = $$props.buffered); + if ("seekable" in $$props) $$invalidate("seekable", seekable = $$props.seekable); + if ("played" in $$props) $$invalidate("played", played = $$props.played); + if ("currentTime" in $$props) $$invalidate("currentTime", currentTime = $$props.currentTime); + if ("duration" in $$props) $$invalidate("duration", duration = $$props.duration); + if ("paused" in $$props) $$invalidate("paused", paused = $$props.paused); + if ("volume" in $$props) $$invalidate("volume", volume = $$props.volume); + if ("playbackRate" in $$props) $$invalidate("playbackRate", playbackRate = $$props.playbackRate); }; return { @@ -150,7 +165,17 @@ function instance($$self, $$props, $$invalidate) { class Component extends SvelteComponent { constructor(options) { super(); - init(this, options, instance, create_fragment, safe_not_equal, ["buffered", "seekable", "played", "currentTime", "duration", "paused", "volume", "playbackRate"]); + + init(this, options, instance, create_fragment, safe_not_equal, [ + "buffered", + "seekable", + "played", + "currentTime", + "duration", + "paused", + "volume", + "playbackRate" + ]); } } diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 42a21aa496..1cbc13fac3 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, destroy_component, @@ -12,14 +11,14 @@ import { transition_in, transition_out } from "svelte/internal"; + import Imported from "Imported.svelte"; function create_fragment(ctx) { - var t, current; - - var imported = new Imported({}); - - var nonimported = new NonImported({}); + let t; + let current; + const imported = new Imported({}); + const nonimported = new NonImported({}); return { c() { @@ -27,38 +26,27 @@ function create_fragment(ctx) { t = space(); nonimported.$$.fragment.c(); }, - m(target, anchor) { mount_component(imported, target, anchor); insert(target, t, anchor); mount_component(nonimported, target, anchor); current = true; }, - p: noop, - i(local) { if (current) return; transition_in(imported.$$.fragment, local); - transition_in(nonimported.$$.fragment, local); - current = true; }, - o(local) { transition_out(imported.$$.fragment, local); transition_out(nonimported.$$.fragment, local); current = false; }, - d(detaching) { destroy_component(imported, detaching); - - if (detaching) { - detach(t); - } - + if (detaching) detach(t); destroy_component(nonimported, detaching); } }; diff --git a/test/js/samples/non-mutable-reference/expected.js b/test/js/samples/non-mutable-reference/expected.js index b6d63a387f..246850aaf4 100644 --- a/test/js/samples/non-mutable-reference/expected.js +++ b/test/js/samples/non-mutable-reference/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,7 +11,10 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var h1, t0, t1, t2; + let h1; + let t0; + let t1; + let t2; return { c() { @@ -21,27 +23,22 @@ function create_fragment(ctx) { t1 = text(name); t2 = text("!"); }, - m(target, anchor) { insert(target, h1, anchor); append(h1, t0); append(h1, t1); append(h1, t2); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(h1); - } + if (detaching) detach(h1); } }; } -let name = 'world'; +let name = "world"; class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/reactive-values-non-topologically-ordered/expected.js b/test/js/samples/reactive-values-non-topologically-ordered/expected.js index b5e2b04f75..adf0f24019 100644 --- a/test/js/samples/reactive-values-non-topologically-ordered/expected.js +++ b/test/js/samples/reactive-values-non-topologically-ordered/expected.js @@ -1,10 +1,4 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { return { @@ -19,17 +13,21 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let { x } = $$props; - let a; let b; $$self.$set = $$props => { - if ('x' in $$props) $$invalidate('x', x = $$props.x); + if ("x" in $$props) $$invalidate("x", x = $$props.x); }; - $$self.$$.update = ($$dirty = { x: 1, b: 1 }) => { - if ($$dirty.x) { $$invalidate('b', b = x); } - if ($$dirty.b) { a = b; } + $$self.$$.update = (changed = { x: 1, b: 1 }) => { + if (changed.x) { + $: $$invalidate("b", b = x); + } + + if (changed.b) { + $: a = b; + } }; return { x }; diff --git a/test/js/samples/reactive-values-non-writable-dependencies/expected.js b/test/js/samples/reactive-values-non-writable-dependencies/expected.js index 8958f1ffbc..f8ec29d70f 100644 --- a/test/js/samples/reactive-values-non-writable-dependencies/expected.js +++ b/test/js/samples/reactive-values-non-writable-dependencies/expected.js @@ -1,10 +1,4 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { return { @@ -18,15 +12,18 @@ function create_fragment(ctx) { } function instance($$self, $$props, $$invalidate) { - let { a = 1, b = 2 } = $$props; + let { a = 1 } = $$props; + let { b = 2 } = $$props; $$self.$set = $$props => { - if ('a' in $$props) $$invalidate('a', a = $$props.a); - if ('b' in $$props) $$invalidate('b', b = $$props.b); + if ("a" in $$props) $$invalidate("a", a = $$props.a); + if ("b" in $$props) $$invalidate("b", b = $$props.b); }; - $$self.$$.update = ($$dirty = { a: 1, b: 1 }) => { - if ($$dirty.a || $$dirty.b) { console.log('max', Math.max(a, b)); } + $$self.$$.update = (changed = { a: 1, b: 1 }) => { + if (changed.a || changed.b) { + $: console.log("max", Math.max(a, b)); + } }; return { a, b }; diff --git a/test/js/samples/select-dynamic-value/expected.js b/test/js/samples/select-dynamic-value/expected.js index 5a0af01f99..b7ed1e3b77 100644 --- a/test/js/samples/select-dynamic-value/expected.js +++ b/test/js/samples/select-dynamic-value/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -11,7 +10,10 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var select, option0, option1, select_value_value; + let select; + let option0; + let option1; + let select_value_value; return { c() { @@ -25,13 +27,12 @@ function create_fragment(ctx) { option1.__value = "2"; option1.value = option1.__value; }, - m(target, anchor) { insert(target, select, anchor); append(select, option0); append(select, option1); - select_value_value = ctx.current; + for (var i = 0; i < select.options.length; i += 1) { var option = select.options[i]; @@ -41,9 +42,8 @@ function create_fragment(ctx) { } } }, - p(changed, ctx) { - if ((changed.current) && select_value_value !== (select_value_value = ctx.current)) { + if (changed.current && select_value_value !== (select_value_value = ctx.current)) { for (var i = 0; i < select.options.length; i += 1) { var option = select.options[i]; @@ -54,14 +54,10 @@ function create_fragment(ctx) { } } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(select); - } + if (detaching) detach(select); } }; } @@ -70,7 +66,7 @@ function instance($$self, $$props, $$invalidate) { let { current } = $$props; $$self.$set = $$props => { - if ('current' in $$props) $$invalidate('current', current = $$props.current); + if ("current" in $$props) $$invalidate("current", current = $$props.current); }; return { current }; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index e9370d0e2b..041ac9bc95 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,10 +1,4 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { return { diff --git a/test/js/samples/ssr-no-oncreate-etc/expected.js b/test/js/samples/ssr-no-oncreate-etc/expected.js index 06cdf057e3..59edcaee16 100644 --- a/test/js/samples/ssr-no-oncreate-etc/expected.js +++ b/test/js/samples/ssr-no-oncreate-etc/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { create_ssr_component } from "svelte/internal"; import { onDestroy, onMount } from "svelte"; @@ -7,20 +6,20 @@ function preload(input) { } function foo() { - console.log('foo'); + console.log("foo"); } function swipe(node, callback) { - // TODO implement + } const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { onMount(() => { - console.log('onMount'); + console.log("onMount"); }); onDestroy(() => { - console.log('onDestroy'); + console.log("onDestroy"); }); return ``; diff --git a/test/js/samples/ssr-preserve-comments/expected.js b/test/js/samples/ssr-preserve-comments/expected.js index d9a63e6011..872cc2bca0 100644 --- a/test/js/samples/ssr-preserve-comments/expected.js +++ b/test/js/samples/ssr-preserve-comments/expected.js @@ -1,10 +1,9 @@ -/* generated by Svelte vX.Y.Z */ import { create_ssr_component } from "svelte/internal"; const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { return `
content
- -
more content
`; + +
more content
`; }); export default Component; \ No newline at end of file diff --git a/test/js/samples/svg-title/expected.js b/test/js/samples/svg-title/expected.js index 57e3fa3050..5b425482d3 100644 --- a/test/js/samples/svg-title/expected.js +++ b/test/js/samples/svg-title/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,7 +11,9 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var svg, title, t; + let svg; + let title; + let t; return { c() { @@ -20,21 +21,16 @@ function create_fragment(ctx) { title = svg_element("title"); t = text("a title"); }, - m(target, anchor) { insert(target, svg, anchor); append(svg, title); append(title, t); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(svg); - } + if (detaching) detach(svg); } }; } diff --git a/test/js/samples/title/expected.js b/test/js/samples/title/expected.js index 884f39e246..4a511abf75 100644 --- a/test/js/samples/title/expected.js +++ b/test/js/samples/title/expected.js @@ -1,26 +1,17 @@ -/* generated by Svelte vX.Y.Z */ -import { - SvelteComponent, - init, - noop, - safe_not_equal -} from "svelte/internal"; +import { SvelteComponent, init, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { - var title_value; - + let title_value; document.title = title_value = "a " + ctx.custom + " title"; return { c: noop, m: noop, - p(changed, ctx) { - if ((changed.custom) && title_value !== (title_value = "a " + ctx.custom + " title")) { + if (changed.custom && title_value !== (title_value = "a " + ctx.custom + " title")) { document.title = title_value; } }, - i: noop, o: noop, d: noop @@ -31,7 +22,7 @@ function instance($$self, $$props, $$invalidate) { let { custom } = $$props; $$self.$set = $$props => { - if ('custom' in $$props) $$invalidate('custom', custom = $$props.custom); + if ("custom" in $$props) $$invalidate("custom", custom = $$props.custom); }; return { custom }; diff --git a/test/js/samples/transition-local/expected.js b/test/js/samples/transition-local/expected.js index f1397e6308..2cdaba0bdd 100644 --- a/test/js/samples/transition-local/expected.js +++ b/test/js/samples/transition-local/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -13,23 +12,19 @@ import { transition_in } from "svelte/internal"; -// (8:0) {#if x} function create_if_block(ctx) { - var if_block_anchor; - - var if_block = (ctx.y) && create_if_block_1(ctx); + let if_block_anchor; + let if_block = ctx.y && create_if_block_1(ctx); return { c() { if (if_block) if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if (if_block) if_block.m(target, anchor); insert(target, if_block_anchor, anchor); }, - p(changed, ctx) { if (ctx.y) { if (!if_block) { @@ -37,37 +32,33 @@ function create_if_block(ctx) { if_block.c(); transition_in(if_block, 1); if_block.m(if_block_anchor.parentNode, if_block_anchor); - } else transition_in(if_block, 1); + } else { + transition_in(if_block, 1); + } } else if (if_block) { if_block.d(1); if_block = null; } }, - d(detaching) { if (if_block) if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } -// (9:1) {#if y} function create_if_block_1(ctx) { - var div, div_intro; + let div; + let div_intro; return { c() { div = element("div"); div.textContent = "..."; }, - m(target, anchor) { insert(target, div, anchor); }, - i(local) { if (local) { if (!div_intro) { @@ -78,33 +69,26 @@ function create_if_block_1(ctx) { } } }, - o: noop, - d(detaching) { - if (detaching) { - detach(div); - } + if (detaching) detach(div); } }; } function create_fragment(ctx) { - var if_block_anchor; - - var if_block = (ctx.x) && create_if_block(ctx); + let if_block_anchor; + let if_block = ctx.x && create_if_block(ctx); return { c() { if (if_block) if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if (if_block) if_block.m(target, anchor); insert(target, if_block_anchor, anchor); }, - p(changed, ctx) { if (ctx.x) { if (if_block) { @@ -119,28 +103,26 @@ function create_fragment(ctx) { if_block = null; } }, - i: noop, o: noop, - d(detaching) { if (if_block) if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } -function foo() {} +function foo() { + +} function instance($$self, $$props, $$invalidate) { - let { x, y } = $$props; + let { x } = $$props; + let { y } = $$props; $$self.$set = $$props => { - if ('x' in $$props) $$invalidate('x', x = $$props.x); - if ('y' in $$props) $$invalidate('y', y = $$props.y); + if ("x" in $$props) $$invalidate("x", x = $$props.x); + if ("y" in $$props) $$invalidate("y", y = $$props.y); }; return { x, y }; diff --git a/test/js/samples/transition-repeated-outro/expected.js b/test/js/samples/transition-repeated-outro/expected.js index 666f13a6aa..34a0381c99 100644 --- a/test/js/samples/transition-repeated-outro/expected.js +++ b/test/js/samples/transition-repeated-outro/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, check_outros, @@ -13,62 +12,54 @@ import { transition_in, transition_out } from "svelte/internal"; + import { fade } from "svelte/transition"; -// (7:0) {#if num < 5} function create_if_block(ctx) { - var div, div_outro, current; + let div; + let div_outro; + let current; return { c() { div = element("div"); div.innerHTML = `

wheeee

`; }, - m(target, anchor) { insert(target, div, anchor); current = true; }, - i(local) { if (current) return; if (div_outro) div_outro.end(1); - current = true; }, - o(local) { div_outro = create_out_transition(div, fade, {}); - current = false; }, - d(detaching) { - if (detaching) { - detach(div); - if (div_outro) div_outro.end(); - } + if (detaching) detach(div); + if (detaching && div_outro) div_outro.end(); } }; } function create_fragment(ctx) { - var if_block_anchor, current; - - var if_block = (ctx.num < 5) && create_if_block(ctx); + let if_block_anchor; + let current; + let if_block = ctx.num < 5 && create_if_block(ctx); return { c() { if (if_block) if_block.c(); if_block_anchor = empty(); }, - m(target, anchor) { if (if_block) if_block.m(target, anchor); insert(target, if_block_anchor, anchor); current = true; }, - p(changed, ctx) { if (ctx.num < 5) { if (!if_block) { @@ -76,33 +67,31 @@ function create_fragment(ctx) { if_block.c(); transition_in(if_block, 1); if_block.m(if_block_anchor.parentNode, if_block_anchor); - } else transition_in(if_block, 1); + } else { + transition_in(if_block, 1); + } } else if (if_block) { group_outros(); + transition_out(if_block, 1, 1, () => { if_block = null; }); + check_outros(); } }, - i(local) { if (current) return; transition_in(if_block); current = true; }, - o(local) { transition_out(if_block); current = false; }, - d(detaching) { if (if_block) if_block.d(detaching); - - if (detaching) { - detach(if_block_anchor); - } + if (detaching) detach(if_block_anchor); } }; } @@ -111,7 +100,7 @@ function instance($$self, $$props, $$invalidate) { let { num = 1 } = $$props; $$self.$set = $$props => { - if ('num' in $$props) $$invalidate('num', num = $$props.num); + if ("num" in $$props) $$invalidate("num", num = $$props.num); }; return { num }; diff --git a/test/js/samples/unreferenced-state-not-invalidated/expected.js b/test/js/samples/unreferenced-state-not-invalidated/expected.js index 17b5638a84..e2ce31d9f8 100644 --- a/test/js/samples/unreferenced-state-not-invalidated/expected.js +++ b/test/js/samples/unreferenced-state-not-invalidated/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -11,35 +10,29 @@ import { set_data, text } from "svelte/internal"; + import { onMount } from "svelte"; function create_fragment(ctx) { - var p, t; + let p; + let t; return { c() { p = element("p"); t = text(ctx.y); }, - m(target, anchor) { insert(target, p, anchor); append(p, t); }, - p(changed, ctx) { - if (changed.y) { - set_data(t, ctx.y); - } + if (changed.y) set_data(t, ctx.y); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } @@ -48,21 +41,29 @@ function instance($$self, $$props, $$invalidate) { let a, b, c; onMount(() => { - const interval = setInterval(() => { - $$invalidate('b', b += 1); - c += 1; - - console.log(b, c); - }, 1000); + const interval = setInterval( + () => { + $$invalidate("b", b += 1); + c += 1; + console.log(b, c); + }, + 1000 + ); return () => clearInterval(interval); }); - let x, y; + let x; + let y; + + $$self.$$.update = (changed = { a: 1, b: 1 }) => { + if (changed.a) { + $: x = a * 2; + } - $$self.$$.update = ($$dirty = { a: 1, b: 1 }) => { - if ($$dirty.a) { x = a * 2; } - if ($$dirty.b) { $$invalidate('y', y = b * 2); } + if (changed.b) { + $: $$invalidate("y", y = b * 2); + } }; return { y }; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index b93817d416..eab09dfaf9 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,128 +11,107 @@ import { space } from "svelte/internal"; -// (10:1) {#if a} function create_if_block_4(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "a"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } -// (16:1) {#if b} function create_if_block_3(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "b"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } -// (20:1) {#if c} function create_if_block_2(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "c"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } -// (26:1) {#if d} function create_if_block_1(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "d"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } -// (33:0) {#if e} function create_if_block(ctx) { - var p; + let p; return { c() { p = element("p"); p.textContent = "e"; }, - m(target, anchor) { insert(target, p, anchor); }, - d(detaching) { - if (detaching) { - detach(p); - } + if (detaching) detach(p); } }; } function create_fragment(ctx) { - var div, t0, p0, t2, t3, t4, p1, t6, t7, if_block4_anchor; - - var if_block0 = (ctx.a) && create_if_block_4(ctx); - - var if_block1 = (ctx.b) && create_if_block_3(ctx); - - var if_block2 = (ctx.c) && create_if_block_2(ctx); - - var if_block3 = (ctx.d) && create_if_block_1(ctx); - - var if_block4 = (ctx.e) && create_if_block(ctx); + let div; + let t0; + let p0; + let t2; + let t3; + let t4; + let p1; + let t6; + let t7; + let if_block4_anchor; + let if_block0 = ctx.a && create_if_block_4(ctx); + let if_block1 = ctx.b && create_if_block_3(ctx); + let if_block2 = ctx.c && create_if_block_2(ctx); + let if_block3 = ctx.d && create_if_block_1(ctx); + let if_block4 = ctx.e && create_if_block(ctx); return { c() { @@ -155,7 +133,6 @@ function create_fragment(ctx) { if (if_block4) if_block4.c(); if_block4_anchor = empty(); }, - m(target, anchor) { insert(target, div, anchor); if (if_block0) if_block0.m(div, null); @@ -173,13 +150,14 @@ function create_fragment(ctx) { if (if_block4) if_block4.m(target, anchor); insert(target, if_block4_anchor, anchor); }, - p(changed, ctx) { if (ctx.a) { if (!if_block0) { if_block0 = create_if_block_4(ctx); if_block0.c(); if_block0.m(div, t0); + } else { + } } else if (if_block0) { if_block0.d(1); @@ -191,6 +169,8 @@ function create_fragment(ctx) { if_block1 = create_if_block_3(ctx); if_block1.c(); if_block1.m(div, t3); + } else { + } } else if (if_block1) { if_block1.d(1); @@ -202,6 +182,8 @@ function create_fragment(ctx) { if_block2 = create_if_block_2(ctx); if_block2.c(); if_block2.m(div, t4); + } else { + } } else if (if_block2) { if_block2.d(1); @@ -213,6 +195,8 @@ function create_fragment(ctx) { if_block3 = create_if_block_1(ctx); if_block3.c(); if_block3.m(div, null); + } else { + } } else if (if_block3) { if_block3.d(1); @@ -224,48 +208,42 @@ function create_fragment(ctx) { if_block4 = create_if_block(ctx); if_block4.c(); if_block4.m(if_block4_anchor.parentNode, if_block4_anchor); + } else { + } } else if (if_block4) { if_block4.d(1); if_block4 = null; } }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(div); - } - + if (detaching) detach(div); if (if_block0) if_block0.d(); if (if_block1) if_block1.d(); if (if_block2) if_block2.d(); if (if_block3) if_block3.d(); - - if (detaching) { - detach(t7); - } - + if (detaching) detach(t7); if (if_block4) if_block4.d(detaching); - - if (detaching) { - detach(if_block4_anchor); - } + if (detaching) detach(if_block4_anchor); } }; } function instance($$self, $$props, $$invalidate) { - let { a, b, c, d, e } = $$props; + let { a } = $$props; + let { b } = $$props; + let { c } = $$props; + let { d } = $$props; + let { e } = $$props; $$self.$set = $$props => { - if ('a' in $$props) $$invalidate('a', a = $$props.a); - if ('b' in $$props) $$invalidate('b', b = $$props.b); - if ('c' in $$props) $$invalidate('c', c = $$props.c); - if ('d' in $$props) $$invalidate('d', d = $$props.d); - if ('e' in $$props) $$invalidate('e', e = $$props.e); + if ("a" in $$props) $$invalidate("a", a = $$props.a); + if ("b" in $$props) $$invalidate("b", b = $$props.b); + if ("c" in $$props) $$invalidate("c", c = $$props.c); + if ("d" in $$props) $$invalidate("d", d = $$props.d); + if ("e" in $$props) $$invalidate("e", e = $$props.e); }; return { a, b, c, d, e }; diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index fbe4596e2b..d85046c11b 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -15,8 +14,17 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var scrolling = false, clear_scrolling = () => { scrolling = false }, scrolling_timeout, p, t0, t1, dispose; + let scrolling = false; + let clear_scrolling = () => { + scrolling = false; + }; + + let scrolling_timeout; + let p; + let t0; + let t1; + let dispose; add_render_callback(ctx.onwindowscroll); return { @@ -24,6 +32,7 @@ function create_fragment(ctx) { p = element("p"); t0 = text("scrolled to "); t1 = text(ctx.y); + dispose = listen(window, "scroll", () => { scrolling = true; clearTimeout(scrolling_timeout); @@ -31,13 +40,11 @@ function create_fragment(ctx) { ctx.onwindowscroll(); }); }, - m(target, anchor) { insert(target, p, anchor); append(p, t0); append(p, t1); }, - p(changed, ctx) { if (changed.y && !scrolling) { scrolling = true; @@ -46,19 +53,12 @@ function create_fragment(ctx) { scrolling_timeout = setTimeout(clear_scrolling, 100); } - if (changed.y) { - set_data(t1, ctx.y); - } + if (changed.y) set_data(t1, ctx.y); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(p); - } - + if (detaching) detach(p); dispose(); } }; @@ -68,11 +68,11 @@ function instance($$self, $$props, $$invalidate) { let { y } = $$props; function onwindowscroll() { - y = window.pageYOffset; $$invalidate('y', y); + $$invalidate("y", y = window.pageYOffset); } $$self.$set = $$props => { - if ('y' in $$props) $$invalidate('y', y = $$props.y); + if ("y" in $$props) $$invalidate("y", y = $$props.y); }; return { y, onwindowscroll }; diff --git a/test/parser/samples/action-with-call/output.json b/test/parser/samples/action-with-call/output.json index e910f0b49f..ccb4011c67 100644 --- a/test/parser/samples/action-with-call/output.json +++ b/test/parser/samples/action-with-call/output.json @@ -20,10 +20,30 @@ "type": "CallExpression", "start": 21, "end": 37, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 37 + } + }, "callee": { "type": "Identifier", "start": 21, "end": 22, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, "name": "t" }, "arguments": [ @@ -31,6 +51,16 @@ "type": "Literal", "start": 23, "end": 36, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 36 + } + }, "value": "tooltip msg", "raw": "'tooltip msg'" } diff --git a/test/parser/samples/action-with-literal/output.json b/test/parser/samples/action-with-literal/output.json index 01a6b67549..bb0b13ee42 100644 --- a/test/parser/samples/action-with-literal/output.json +++ b/test/parser/samples/action-with-literal/output.json @@ -20,6 +20,16 @@ "type": "Literal", "start": 21, "end": 34, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 34 + } + }, "value": "tooltip msg", "raw": "'tooltip msg'" } diff --git a/test/parser/samples/animation/output.json b/test/parser/samples/animation/output.json index f4d183eb5c..1958ba2817 100644 --- a/test/parser/samples/animation/output.json +++ b/test/parser/samples/animation/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 13, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 13 + } + }, "name": "things" }, "children": [ @@ -51,6 +61,16 @@ "type": "Identifier", "start": 24, "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + } + }, "name": "thing" } } diff --git a/test/parser/samples/attribute-with-whitespace/output.json b/test/parser/samples/attribute-with-whitespace/output.json index eab6054f2a..11d5aa5e06 100644 --- a/test/parser/samples/attribute-with-whitespace/output.json +++ b/test/parser/samples/attribute-with-whitespace/output.json @@ -36,4 +36,4 @@ } ] } -} +} \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/output.json b/test/parser/samples/await-then-catch/output.json index ac598a403a..d9defb6932 100644 --- a/test/parser/samples/await-then-catch/output.json +++ b/test/parser/samples/await-then-catch/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 8, "end": 18, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, "name": "thePromise" }, "value": "theValue", @@ -88,6 +98,16 @@ "type": "Identifier", "start": 74, "end": 82, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 26 + } + }, "name": "theValue" } } @@ -137,16 +157,46 @@ "type": "MemberExpression", "start": 118, "end": 134, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 28 + } + }, "object": { "type": "Identifier", "start": 118, "end": 126, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 20 + } + }, "name": "theError" }, "property": { "type": "Identifier", "start": 127, "end": 134, + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 28 + } + }, "name": "message" }, "computed": false diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json index 7fe7acb5b3..17012db31a 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 28, "context": "default", @@ -43,20 +44,60 @@ "type": "Program", "start": 8, "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 9 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, "id": { "type": "Identifier", "start": 14, "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, "name": "foo" }, "init": null diff --git a/test/parser/samples/binding/output.json b/test/parser/samples/binding/output.json index 72ad60202c..558215f41a 100644 --- a/test/parser/samples/binding/output.json +++ b/test/parser/samples/binding/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 29, "context": "default", @@ -43,20 +44,60 @@ "type": "Program", "start": 8, "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 19, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 10 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, "id": { "type": "Identifier", "start": 14, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, "name": "name" }, "init": null diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json index 77837d1ca9..32cde85f1a 100644 --- a/test/parser/samples/component-dynamic/output.json +++ b/test/parser/samples/component-dynamic/output.json @@ -15,22 +15,62 @@ "type": "ConditionalExpression", "start": 25, "end": 40, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 40 + } + }, "test": { "type": "Identifier", "start": 25, "end": 28, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 28 + } + }, "name": "foo" }, "consequent": { "type": "Identifier", "start": 31, "end": 34, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 34 + } + }, "name": "Foo" }, "alternate": { "type": "Identifier", "start": 37, "end": 40, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 40 + } + }, "name": "Bar" } } diff --git a/test/parser/samples/css/output.json b/test/parser/samples/css/output.json index 12d74ae7f8..676b11f6a9 100644 --- a/test/parser/samples/css/output.json +++ b/test/parser/samples/css/output.json @@ -30,6 +30,7 @@ ] }, "css": { + "type": "Style", "start": 16, "end": 56, "attributes": [], diff --git a/test/parser/samples/dynamic-import/output.json b/test/parser/samples/dynamic-import/output.json index f66cdaaa0b..1e41252afa 100644 --- a/test/parser/samples/dynamic-import/output.json +++ b/test/parser/samples/dynamic-import/output.json @@ -6,6 +6,7 @@ "children": [] }, "instance": { + "type": "Script", "start": 0, "end": 146, "context": "default", @@ -13,26 +14,76 @@ "type": "Program", "start": 8, "end": 137, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + }, "body": [ { "type": "ImportDeclaration", "start": 10, "end": 43, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 34 + } + }, "specifiers": [ { "type": "ImportSpecifier", "start": 19, "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + }, "imported": { "type": "Identifier", "start": 19, "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + }, "name": "onMount" }, "local": { "type": "Identifier", "start": 19, "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + }, "name": "onMount" } } @@ -41,6 +92,16 @@ "type": "Literal", "start": 34, "end": 42, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, "value": "svelte", "raw": "'svelte'" } @@ -49,14 +110,44 @@ "type": "ExpressionStatement", "start": 46, "end": 136, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 8, + "column": 4 + } + }, "expression": { "type": "CallExpression", "start": 46, "end": 135, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 8, + "column": 3 + } + }, "callee": { "type": "Identifier", "start": 46, "end": 53, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 8 + } + }, "name": "onMount" }, "arguments": [ @@ -64,6 +155,16 @@ "type": "ArrowFunctionExpression", "start": 54, "end": 134, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, "id": null, "expression": false, "generator": false, @@ -73,27 +174,87 @@ "type": "BlockStatement", "start": 60, "end": 134, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 8, + "column": 2 + } + }, "body": [ { "type": "ExpressionStatement", "start": 64, "end": 131, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 5 + } + }, "expression": { "type": "CallExpression", "start": 64, "end": 130, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 4 + } + }, "callee": { "type": "MemberExpression", "start": 64, "end": 87, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 25 + } + }, "object": { "type": "ImportExpression", "start": 64, "end": 82, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + }, "source": { "type": "Literal", "start": 71, "end": 81, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 19 + } + }, "value": "./foo.js", "raw": "'./foo.js'" } @@ -102,6 +263,16 @@ "type": "Identifier", "start": 83, "end": 87, + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 25 + } + }, "name": "then" }, "computed": false @@ -111,6 +282,16 @@ "type": "ArrowFunctionExpression", "start": 88, "end": 129, + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 7, + "column": 3 + } + }, "id": null, "expression": false, "generator": false, @@ -120,6 +301,16 @@ "type": "Identifier", "start": 88, "end": 91, + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 29 + } + }, "name": "foo" } ], @@ -127,29 +318,89 @@ "type": "BlockStatement", "start": 95, "end": 129, + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 7, + "column": 3 + } + }, "body": [ { "type": "ExpressionStatement", "start": 100, "end": 125, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 28 + } + }, "expression": { "type": "CallExpression", "start": 100, "end": 124, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 27 + } + }, "callee": { "type": "MemberExpression", "start": 100, "end": 111, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 14 + } + }, "object": { "type": "Identifier", "start": 100, "end": 107, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 10 + } + }, "name": "console" }, "property": { "type": "Identifier", "start": 108, "end": 111, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + }, "name": "log" }, "computed": false @@ -159,16 +410,46 @@ "type": "MemberExpression", "start": 112, "end": 123, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 26 + } + }, "object": { "type": "Identifier", "start": 112, "end": 115, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 18 + } + }, "name": "foo" }, "property": { "type": "Identifier", "start": 116, "end": 123, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 26 + } + }, "name": "default" }, "computed": false diff --git a/test/parser/samples/each-block-destructured/output.json b/test/parser/samples/each-block-destructured/output.json index 6368b445d6..bafde1324d 100644 --- a/test/parser/samples/each-block-destructured/output.json +++ b/test/parser/samples/each-block-destructured/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, "name": "animals" }, "children": [ diff --git a/test/parser/samples/each-block-else/output.json b/test/parser/samples/each-block-else/output.json index 1e8ac455e6..19b5af19b4 100644 --- a/test/parser/samples/each-block-else/output.json +++ b/test/parser/samples/each-block-else/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, "name": "animals" }, "children": [ diff --git a/test/parser/samples/each-block-indexed/output.json b/test/parser/samples/each-block-indexed/output.json index 77417ba67a..68a12ea31c 100644 --- a/test/parser/samples/each-block-indexed/output.json +++ b/test/parser/samples/each-block-indexed/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, "name": "animals" }, "children": [ diff --git a/test/parser/samples/each-block-keyed/output.json b/test/parser/samples/each-block-keyed/output.json index 11cdd45ff1..61b5442c0d 100644 --- a/test/parser/samples/each-block-keyed/output.json +++ b/test/parser/samples/each-block-keyed/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + } + }, "name": "todos" }, "children": [ @@ -46,16 +56,46 @@ "type": "MemberExpression", "start": 22, "end": 29, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 29 + } + }, "object": { "type": "Identifier", "start": 22, "end": 26, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 26 + } + }, "name": "todo" }, "property": { "type": "Identifier", "start": 27, "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, "name": "id" }, "computed": false diff --git a/test/parser/samples/each-block/output.json b/test/parser/samples/each-block/output.json index 6a60823952..38bc7e1d04 100644 --- a/test/parser/samples/each-block/output.json +++ b/test/parser/samples/each-block/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, "name": "animals" }, "children": [ diff --git a/test/parser/samples/event-handler/output.json b/test/parser/samples/event-handler/output.json index f792ffadcc..44bb83de7d 100644 --- a/test/parser/samples/event-handler/output.json +++ b/test/parser/samples/event-handler/output.json @@ -20,6 +20,16 @@ "type": "ArrowFunctionExpression", "start": 19, "end": 43, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 43 + } + }, "id": null, "expression": true, "generator": false, @@ -29,23 +39,63 @@ "type": "AssignmentExpression", "start": 25, "end": 43, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 43 + } + }, "operator": "=", "left": { "type": "Identifier", "start": 25, "end": 32, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 32 + } + }, "name": "visible" }, "right": { "type": "UnaryExpression", "start": 35, "end": 43, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 43 + } + }, "operator": "!", "prefix": true, "argument": { "type": "Identifier", "start": 36, "end": 43, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 43 + } + }, "name": "visible" } } diff --git a/test/parser/samples/if-block-elseif/output.json b/test/parser/samples/if-block-elseif/output.json index 54fb53dacb..0d8fcd987e 100644 --- a/test/parser/samples/if-block-elseif/output.json +++ b/test/parser/samples/if-block-elseif/output.json @@ -12,10 +12,30 @@ "type": "BinaryExpression", "start": 5, "end": 11, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, "left": { "type": "Identifier", "start": 5, "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, "name": "x" }, "operator": ">", @@ -23,6 +43,16 @@ "type": "Literal", "start": 9, "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, "value": 10, "raw": "10" } @@ -59,10 +89,30 @@ "type": "BinaryExpression", "start": 52, "end": 57, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 15 + } + }, "left": { "type": "Identifier", "start": 52, "end": 53, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, "name": "x" }, "operator": "<", @@ -70,6 +120,16 @@ "type": "Literal", "start": 56, "end": 57, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, "value": 5, "raw": "5" } diff --git a/test/parser/samples/raw-mustaches/output.json b/test/parser/samples/raw-mustaches/output.json index 1b3d9b7a9c..764b6df07d 100644 --- a/test/parser/samples/raw-mustaches/output.json +++ b/test/parser/samples/raw-mustaches/output.json @@ -26,6 +26,16 @@ "type": "Identifier", "start": 11, "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, "name": "raw1" } }, @@ -44,6 +54,16 @@ "type": "Identifier", "start": 24, "end": 28, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 28 + } + }, "name": "raw2" } }, diff --git a/test/parser/samples/refs/output.json b/test/parser/samples/refs/output.json index e09383f9b6..72a3d7689c 100644 --- a/test/parser/samples/refs/output.json +++ b/test/parser/samples/refs/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 28, "context": "default", @@ -43,20 +44,60 @@ "type": "Program", "start": 8, "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 9 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, "id": { "type": "Identifier", "start": 14, "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, "name": "foo" }, "init": null diff --git a/test/parser/samples/script-comment-only/output.json b/test/parser/samples/script-comment-only/output.json index ba28434318..3441d8a7bb 100644 --- a/test/parser/samples/script-comment-only/output.json +++ b/test/parser/samples/script-comment-only/output.json @@ -22,6 +22,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 43, "context": "default", @@ -29,6 +30,16 @@ "type": "Program", "start": 8, "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, "body": [], "sourceType": "module" } diff --git a/test/parser/samples/script-comment-trailing-multiline/output.json b/test/parser/samples/script-comment-trailing-multiline/output.json index 7d01599efa..3c02b1fbde 100644 --- a/test/parser/samples/script-comment-trailing-multiline/output.json +++ b/test/parser/samples/script-comment-trailing-multiline/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 77, "context": "default", @@ -55,26 +56,76 @@ "type": "Program", "start": 8, "end": 68, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 29, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 20 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + }, "id": { "type": "Identifier", "start": 14, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, "name": "name" }, "init": { "type": "Literal", "start": 21, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 19 + } + }, "value": "world", "raw": "'world'" } diff --git a/test/parser/samples/script-comment-trailing/output.json b/test/parser/samples/script-comment-trailing/output.json index bc8f3e4e67..beca001042 100644 --- a/test/parser/samples/script-comment-trailing/output.json +++ b/test/parser/samples/script-comment-trailing/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 66, "context": "default", @@ -55,26 +56,76 @@ "type": "Program", "start": 8, "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 29, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 20 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + }, "id": { "type": "Identifier", "start": 14, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, "name": "name" }, "init": { "type": "Literal", "start": 21, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 19 + } + }, "value": "world", "raw": "'world'" } diff --git a/test/parser/samples/script/output.json b/test/parser/samples/script/output.json index 75aa0a7d2c..00b7073a19 100644 --- a/test/parser/samples/script/output.json +++ b/test/parser/samples/script/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 39, "context": "default", @@ -55,26 +56,76 @@ "type": "Program", "start": 8, "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, "body": [ { "type": "VariableDeclaration", "start": 10, "end": 29, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 20 + } + }, "declarations": [ { "type": "VariableDeclarator", "start": 14, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + }, "id": { "type": "Identifier", "start": 14, "end": 18, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, "name": "name" }, "init": { "type": "Literal", "start": 21, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 19 + } + }, "value": "world", "raw": "'world'" } diff --git a/test/parser/samples/self-reference/output.json b/test/parser/samples/self-reference/output.json index 92dfdfe4d0..ea9eecc691 100644 --- a/test/parser/samples/self-reference/output.json +++ b/test/parser/samples/self-reference/output.json @@ -12,10 +12,30 @@ "type": "BinaryExpression", "start": 5, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 14 + } + }, "left": { "type": "Identifier", "start": 5, "end": 10, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, "name": "depth" }, "operator": ">", @@ -23,6 +43,16 @@ "type": "Literal", "start": 13, "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, "value": 1, "raw": "1" } @@ -48,10 +78,30 @@ "type": "BinaryExpression", "start": 38, "end": 47, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 31 + } + }, "left": { "type": "Identifier", "start": 38, "end": 43, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 27 + } + }, "name": "depth" }, "operator": "-", @@ -59,6 +109,16 @@ "type": "Literal", "start": 46, "end": 47, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, "value": 1, "raw": "1" } diff --git a/test/parser/samples/transition-intro/output.json b/test/parser/samples/transition-intro/output.json index 418bb97e16..1e10f40c42 100644 --- a/test/parser/samples/transition-intro/output.json +++ b/test/parser/samples/transition-intro/output.json @@ -20,11 +20,31 @@ "type": "ObjectExpression", "start": 16, "end": 28, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 28 + } + }, "properties": [ { "type": "Property", "start": 17, "end": 27, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 27 + } + }, "method": false, "shorthand": false, "computed": false, @@ -32,12 +52,32 @@ "type": "Identifier", "start": 17, "end": 24, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 24 + } + }, "name": "opacity" }, "value": { "type": "Literal", "start": 26, "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, "value": 0, "raw": "0" }, diff --git a/test/parser/samples/unusual-identifier/output.json b/test/parser/samples/unusual-identifier/output.json index e4a2a18619..76cc82cfd6 100644 --- a/test/parser/samples/unusual-identifier/output.json +++ b/test/parser/samples/unusual-identifier/output.json @@ -12,6 +12,16 @@ "type": "Identifier", "start": 7, "end": 13, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 13 + } + }, "name": "things" }, "children": [ @@ -30,6 +40,16 @@ "type": "Identifier", "start": 26, "end": 28, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 7 + } + }, "name": "𐊧" } } diff --git a/test/runtime/index.js b/test/runtime/index.js index 880e316e0c..646eeb99b6 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -33,9 +33,7 @@ describe("runtime", () => { require.extensions[".svelte"] = function(module, filename) { const options = Object.assign({ - filename, - format: 'cjs', - sveltePath + filename }, compileOptions); const { js: { code } } = compile(fs.readFileSync(filename, "utf-8"), options); @@ -72,6 +70,7 @@ describe("runtime", () => { const cwd = path.resolve(`test/runtime/samples/${dir}`); compileOptions = config.compileOptions || {}; + compileOptions.format = 'cjs'; compileOptions.sveltePath = sveltePath; compileOptions.hydratable = hydrate; compileOptions.immutable = config.immutable; @@ -197,6 +196,11 @@ describe("runtime", () => { throw err; } }) + .catch(err => { + // print a clickable link to open the directory + err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), cwd)}/main.svelte`; + throw err; + }) .then(() => { if (config.show) { showOutput(cwd, compileOptions, compile); @@ -229,7 +233,7 @@ describe("runtime", () => { }), { name: 'svelte-packages', - resolveId: (importee, importer) => { + resolveId: (importee) => { if (importee.startsWith('svelte/')) { return importee.replace('svelte', process.cwd()) + '/index.mjs'; } diff --git a/test/runtime/samples/_/_config.js b/test/runtime/samples/_/_config.js new file mode 100644 index 0000000000..3258754400 --- /dev/null +++ b/test/runtime/samples/_/_config.js @@ -0,0 +1,52 @@ +export default { + props: { + state: 'deconflicted', + states: [ + 'Alabama', + 'Alaska', + 'Arizona', + 'Arkansas', + '...and some others' + ] + }, + + html: ` +

Current state: deconflicted

+ +
    +
  • Alabama
  • +
  • Alaska
  • +
  • Arizona
  • +
  • Arkansas
  • +
  • ...and some others
  • +
+ `, + + test({ assert, component, target }) { + component.states = [ + 'Maine', + 'Maryland', + 'Massachusetts', + 'Michigan', + 'Minnesota', + 'Mississippi', + 'Missouri', + 'Montana' + ]; + + assert.htmlEqual( target.innerHTML, ` +

Current state: deconflicted

+ +
    +
  • Maine
  • +
  • Maryland
  • +
  • Massachusetts
  • +
  • Michigan
  • +
  • Minnesota
  • +
  • Mississippi
  • +
  • Missouri
  • +
  • Montana
  • +
+ ` ); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/_/main.svelte b/test/runtime/samples/_/main.svelte new file mode 100644 index 0000000000..a03a5a7919 --- /dev/null +++ b/test/runtime/samples/_/main.svelte @@ -0,0 +1,12 @@ + + +

Current state: {state}

+ +
    + {#each states as state} +
  • {state}
  • + {/each} +
\ No newline at end of file diff --git a/test/runtime/samples/action-this/main.svelte b/test/runtime/samples/action-this/main.svelte index 28d5444b32..c7d74a8b97 100644 --- a/test/runtime/samples/action-this/main.svelte +++ b/test/runtime/samples/action-this/main.svelte @@ -4,7 +4,7 @@ function foo(node) { const handler = () => { x += 1; - } + }; node.addEventListener('click', handler); handler(); diff --git a/test/runtime/samples/action-update/_config.js b/test/runtime/samples/action-update/_config.js index 305c890ca8..b5e90e4b10 100644 --- a/test/runtime/samples/action-update/_config.js +++ b/test/runtime/samples/action-update/_config.js @@ -3,7 +3,7 @@ export default { `, - async test({ assert, component, target, window }) { + async test({ assert, target, window }) { const button = target.querySelector('button'); const enter = new window.MouseEvent('mouseenter'); const leave = new window.MouseEvent('mouseleave'); diff --git a/test/runtime/samples/action/_config.js b/test/runtime/samples/action/_config.js index 07b4087dcc..6aa972f1a8 100644 --- a/test/runtime/samples/action/_config.js +++ b/test/runtime/samples/action/_config.js @@ -3,7 +3,7 @@ export default { `, - async test({ assert, component, target, window }) { + async test({ assert, target, window }) { const button = target.querySelector('button'); const eventEnter = new window.MouseEvent('mouseenter'); const eventLeave = new window.MouseEvent('mouseleave'); diff --git a/test/runtime/samples/class-helper/_config.js b/test/runtime/samples/class-helper/_config.js index 2c4606fbe8..c38cc88240 100644 --- a/test/runtime/samples/class-helper/_config.js +++ b/test/runtime/samples/class-helper/_config.js @@ -5,7 +5,7 @@ export default { html: `
`, - test({ assert, component, target, window }) { + test({ assert, component, target }) { component.user = { active: false }; assert.htmlEqual(target.innerHTML, ` diff --git a/test/runtime/samples/head-if-block/_config.js b/test/runtime/samples/head-if-block/_config.js index 439ed2cb1b..cb8b6eccb9 100644 --- a/test/runtime/samples/head-if-block/_config.js +++ b/test/runtime/samples/head-if-block/_config.js @@ -3,7 +3,7 @@ export default { condition: false }, - test({ assert, component, target, window }) { + test({ assert, component, window }) { assert.equal(window.document.title, ''); component.condition = true; diff --git a/test/runtime/samples/invalidation-in-if-condition/_config.js b/test/runtime/samples/invalidation-in-if-condition/_config.js index 60b02d9934..27209c75c9 100644 --- a/test/runtime/samples/invalidation-in-if-condition/_config.js +++ b/test/runtime/samples/invalidation-in-if-condition/_config.js @@ -1,5 +1,4 @@ export default { - show: 1, html: ``, async test({ assert, target, window }) { diff --git a/test/runtime/samples/reactive-values-implicit-self-dependency/_config.js b/test/runtime/samples/reactive-values-implicit-self-dependency/_config.js index d7f2bbf920..f215de098e 100644 --- a/test/runtime/samples/reactive-values-implicit-self-dependency/_config.js +++ b/test/runtime/samples/reactive-values-implicit-self-dependency/_config.js @@ -1,5 +1,4 @@ export default { - show: 1, html: `

1 / 1

`, diff --git a/test/runtime/samples/transition-js-nested-each/_config.js b/test/runtime/samples/transition-js-nested-each/_config.js index 3d2fe3c32e..c21024dd69 100644 --- a/test/runtime/samples/transition-js-nested-each/_config.js +++ b/test/runtime/samples/transition-js-nested-each/_config.js @@ -4,7 +4,7 @@ export default { things: ['a'] }, - test({ assert, component, target, window, raf }) { + test({ assert, component, target, raf }) { component.x = true; const div = target.querySelector('div'); diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.js index cf6e5ad964..1097486124 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.js @@ -72,9 +72,10 @@ describe("ssr", () => { ); } - if (show) showOutput(dir, { generate: 'ssr' }); + if (show) showOutput(dir, { generate: 'ssr', format: 'cjs' }); } catch (err) { - showOutput(dir, { generate: 'ssr' }); + showOutput(dir, { generate: 'ssr', format: 'cjs' }); + err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`; throw err; } }); @@ -104,7 +105,8 @@ describe("ssr", () => { delete global.window; const compileOptions = Object.assign({ sveltePath }, config.compileOptions, { - generate: 'ssr' + generate: 'ssr', + format: 'cjs' }); require("../../register")(compileOptions); @@ -129,6 +131,8 @@ describe("ssr", () => { showOutput(cwd, compileOptions); } } catch (err) { + err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), cwd)}/main.svelte`; + if (config.error) { if (typeof config.error === 'function') { config.error(assert, err); diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.js index ee169ebe1b..e5915780c6 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.js @@ -17,7 +17,7 @@ describe("sourcemaps", () => { throw new Error("Forgot to remove `solo: true` from test"); } - (solo ? it.only : skip ? it.skip : it)(dir, () => { + (solo ? it.only : skip ? it.skip : it)(dir, async () => { const filename = path.resolve( `test/sourcemaps/samples/${dir}/input.svelte` ); @@ -61,10 +61,10 @@ describe("sourcemaps", () => { const locateInSource = getLocator(input); - const smc = new SourceMapConsumer(js.map); + const smc = await new SourceMapConsumer(js.map); const locateInGenerated = getLocator(_code); - const smcCss = css.map && new SourceMapConsumer(css.map); + const smcCss = css.map && await new SourceMapConsumer(css.map); const locateInGeneratedCss = getLocator(css.code || ''); test({ assert, code: _code, map: js.map, smc, smcCss, locateInSource, locateInGenerated, locateInGeneratedCss }); diff --git a/test/sourcemaps/samples/basic/test.js b/test/sourcemaps/samples/basic/test.js index f13ff5d0e1..f2ce4198fd 100644 --- a/test/sourcemaps/samples/basic/test.js +++ b/test/sourcemaps/samples/basic/test.js @@ -4,7 +4,7 @@ export function test({ assert, smc, locateInSource, locateInGenerated }) { let start; let actual; - start = locateInGenerated( 'foo.bar.baz' ); + start = locateInGenerated('foo.bar.baz'); actual = smc.originalPositionFor({ line: start.line + 1, diff --git a/test/sourcemaps/samples/each-block/test.js b/test/sourcemaps/samples/each-block/test.js index 6e9d2d70b0..35479986a5 100644 --- a/test/sourcemaps/samples/each-block/test.js +++ b/test/sourcemaps/samples/each-block/test.js @@ -1,15 +1,15 @@ -export function test({ assert, code, smc, locateInSource, locateInGenerated }) { +export function test({ assert, code, smc, map, locateInSource, locateInGenerated }) { const startIndex = code.indexOf('create_main_fragment'); const expected = locateInSource('each'); - const start = locateInGenerated('length', startIndex ); + const start = locateInGenerated('length', startIndex); const actual = smc.originalPositionFor({ line: start.line + 1, column: start.column }); - assert.deepEqual( actual, { + assert.deepEqual(actual, { source: 'input.svelte', name: null, line: expected.line + 1, diff --git a/test/test.js b/test/test.js index f18c01c149..9480ae7836 100644 --- a/test/test.js +++ b/test/test.js @@ -6,6 +6,8 @@ require('./setup'); require('./helpers'); require('../internal'); +console.clear(); + glob('*/index.js', { cwd: 'test' }).forEach((file) => { require('./' + file); }); From abcfa6c4930173e9a86ba6b08c7db86d0ddc3938 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 16 Oct 2019 11:44:18 -0400 Subject: [PATCH 039/413] add deconflict-ctx test against regression (#3556) --- test/runtime/samples/deconflict-ctx/_config.js | 5 +++++ test/runtime/samples/deconflict-ctx/main.svelte | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 test/runtime/samples/deconflict-ctx/_config.js create mode 100644 test/runtime/samples/deconflict-ctx/main.svelte diff --git a/test/runtime/samples/deconflict-ctx/_config.js b/test/runtime/samples/deconflict-ctx/_config.js new file mode 100644 index 0000000000..88f3e2efca --- /dev/null +++ b/test/runtime/samples/deconflict-ctx/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +

Hello world!

+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/deconflict-ctx/main.svelte b/test/runtime/samples/deconflict-ctx/main.svelte new file mode 100644 index 0000000000..d1af46a18d --- /dev/null +++ b/test/runtime/samples/deconflict-ctx/main.svelte @@ -0,0 +1,5 @@ + + +

Hello {ctx}!

From 0707f1c25d6ac28407b27b2bf7958df14794040e Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 16 Oct 2019 11:51:57 -0400 Subject: [PATCH 040/413] add reactive-value-coerce-precedence test against regression (#3564) --- .../samples/reactive-value-coerce-precedence/_config.js | 5 +++++ .../samples/reactive-value-coerce-precedence/main.svelte | 1 + 2 files changed, 6 insertions(+) create mode 100644 test/runtime/samples/reactive-value-coerce-precedence/_config.js create mode 100644 test/runtime/samples/reactive-value-coerce-precedence/main.svelte diff --git a/test/runtime/samples/reactive-value-coerce-precedence/_config.js b/test/runtime/samples/reactive-value-coerce-precedence/_config.js new file mode 100644 index 0000000000..4fe47e26fa --- /dev/null +++ b/test/runtime/samples/reactive-value-coerce-precedence/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +

true

+ ` +}; diff --git a/test/runtime/samples/reactive-value-coerce-precedence/main.svelte b/test/runtime/samples/reactive-value-coerce-precedence/main.svelte new file mode 100644 index 0000000000..fc73456e9e --- /dev/null +++ b/test/runtime/samples/reactive-value-coerce-precedence/main.svelte @@ -0,0 +1 @@ +

{1 === 1}

\ No newline at end of file From ae169cb9092b776b38ed3b9705a308f03e86861a Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 16 Oct 2019 14:50:29 -0400 Subject: [PATCH 041/413] add semicolon-hoisting test against regression (#2292) --- test/runtime/samples/semicolon-hoisting/_config.js | 3 +++ test/runtime/samples/semicolon-hoisting/main.svelte | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 test/runtime/samples/semicolon-hoisting/_config.js create mode 100644 test/runtime/samples/semicolon-hoisting/main.svelte diff --git a/test/runtime/samples/semicolon-hoisting/_config.js b/test/runtime/samples/semicolon-hoisting/_config.js new file mode 100644 index 0000000000..88d81cdc9e --- /dev/null +++ b/test/runtime/samples/semicolon-hoisting/_config.js @@ -0,0 +1,3 @@ +export default { + html: `` +}; \ No newline at end of file diff --git a/test/runtime/samples/semicolon-hoisting/main.svelte b/test/runtime/samples/semicolon-hoisting/main.svelte new file mode 100644 index 0000000000..234fa715d2 --- /dev/null +++ b/test/runtime/samples/semicolon-hoisting/main.svelte @@ -0,0 +1,6 @@ + \ No newline at end of file From 1ebfdb78c342fd525350b1d27fc4a87b88a70086 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 16 Oct 2019 14:56:28 -0400 Subject: [PATCH 042/413] add destructuring-between-exports test against regression (#3628) --- .../samples/destructuring-between-exports/_config.js | 8 ++++++++ .../samples/destructuring-between-exports/main.svelte | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 test/runtime/samples/destructuring-between-exports/_config.js create mode 100644 test/runtime/samples/destructuring-between-exports/main.svelte diff --git a/test/runtime/samples/destructuring-between-exports/_config.js b/test/runtime/samples/destructuring-between-exports/_config.js new file mode 100644 index 0000000000..56061f510f --- /dev/null +++ b/test/runtime/samples/destructuring-between-exports/_config.js @@ -0,0 +1,8 @@ +export default { + props: { + foo: { bar: 42 } + }, + html: ` +

42

+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/destructuring-between-exports/main.svelte b/test/runtime/samples/destructuring-between-exports/main.svelte new file mode 100644 index 0000000000..17cc8dc17d --- /dev/null +++ b/test/runtime/samples/destructuring-between-exports/main.svelte @@ -0,0 +1,7 @@ + + +

{bar}

\ No newline at end of file From 231fbfa020d477e265b14f99a7cb93e934c79719 Mon Sep 17 00:00:00 2001 From: Aaron George Date: Thu, 17 Oct 2019 06:20:04 +1100 Subject: [PATCH 043/413] FIXED: Media Elements Example Seeking was happening regardless of if a drag was happening --- .../content/examples/05-bindings/08-media-elements/App.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/content/examples/05-bindings/08-media-elements/App.svelte b/site/content/examples/05-bindings/08-media-elements/App.svelte index fd4f843ca1..469e9e12eb 100644 --- a/site/content/examples/05-bindings/08-media-elements/App.svelte +++ b/site/content/examples/05-bindings/08-media-elements/App.svelte @@ -14,7 +14,7 @@ showControlsTimeout = setTimeout(() => showControls = false, 2500); showControls = true; - if (e.which !== 1) return; // mouse not down + if (!(e.buttons & 1)) return; // mouse not down if (!duration) return; // video not loaded yet const { left, right } = this.getBoundingClientRect(); @@ -127,4 +127,4 @@ {format(duration)} - \ No newline at end of file + From 36ca31150048fbe86aea7038853d7c2826f00a62 Mon Sep 17 00:00:00 2001 From: Aaron George Date: Thu, 17 Oct 2019 06:29:53 +1100 Subject: [PATCH 044/413] FIXED: Media Elements Tutorial * FIXED: Seeking Seeking was being caused on the mousemove event, regardless of if the mouse was actually dragging or not --- .../tutorial/06-bindings/10-media-elements/app-a/App.svelte | 4 ++-- .../tutorial/06-bindings/10-media-elements/app-b/App.svelte | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/site/content/tutorial/06-bindings/10-media-elements/app-a/App.svelte b/site/content/tutorial/06-bindings/10-media-elements/app-a/App.svelte index 4b24316232..40276110f4 100644 --- a/site/content/tutorial/06-bindings/10-media-elements/app-a/App.svelte +++ b/site/content/tutorial/06-bindings/10-media-elements/app-a/App.svelte @@ -14,7 +14,7 @@ showControlsTimeout = setTimeout(() => showControls = false, 2500); showControls = true; - if (e.which !== 1) return; // mouse not down + if (!(e.buttons & 1)) return; // mouse not down if (!duration) return; // video not loaded yet const { left, right } = this.getBoundingClientRect(); @@ -124,4 +124,4 @@ {format(duration)} - \ No newline at end of file + diff --git a/site/content/tutorial/06-bindings/10-media-elements/app-b/App.svelte b/site/content/tutorial/06-bindings/10-media-elements/app-b/App.svelte index 59e3dbe0c7..8712d6718b 100644 --- a/site/content/tutorial/06-bindings/10-media-elements/app-b/App.svelte +++ b/site/content/tutorial/06-bindings/10-media-elements/app-b/App.svelte @@ -14,7 +14,7 @@ showControlsTimeout = setTimeout(() => showControls = false, 2500); showControls = true; - if (e.which !== 1) return; // mouse not down + if (!(e.buttons & 1)) return; // mouse not down if (!duration) return; // video not loaded yet const { left, right } = this.getBoundingClientRect(); From 982a1937db9001ec3bba4928416e0816fa8e2848 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 17 Oct 2019 04:48:32 +0800 Subject: [PATCH 045/413] fix binding shadow the array in each block (#1565) --- .../compile/render_dom/wrappers/Element/index.ts | 5 ++++- .../each-block-scope-shadow-self/_config.js | 13 +++++++++++++ .../each-block-scope-shadow-self/main.svelte | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/each-block-scope-shadow-self/_config.js create mode 100644 test/runtime/samples/each-block-scope-shadow-self/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 1744b5af12..3f1b411966 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -495,7 +495,10 @@ export default class ElementWrapper extends Wrapper { this.renderer.component.partly_hoisted.push(b` function ${handler}(${arg}) { ${group.bindings.map(b => b.handler.mutation)} - ${Array.from(dependencies).filter(dep => dep[0] !== '$').map(dep => b`${this.renderer.component.invalidate(dep)};`)} + ${Array.from(dependencies) + .filter(dep => dep[0] !== '$') + .filter(dep => !contextual_dependencies.has(dep)) + .map(dep => b`${this.renderer.component.invalidate(dep)};`)} } `); diff --git a/test/runtime/samples/each-block-scope-shadow-self/_config.js b/test/runtime/samples/each-block-scope-shadow-self/_config.js new file mode 100644 index 0000000000..1669dc5b6e --- /dev/null +++ b/test/runtime/samples/each-block-scope-shadow-self/_config.js @@ -0,0 +1,13 @@ +export default { + async test({ assert, component, target }) { + assert.equal(target.querySelectorAll('input').length, 3); + + const input = target.querySelector('input'); + input.value = 'svelte'; + await input.dispatchEvent(new window.Event('input')); + + assert.equal(target.querySelectorAll('input').length, 3); + assert.deepEqual(component.data, { a: 'svelte', b: 'B', c: 'C' }); + assert.deepEqual(component.x, ['a', 'b', 'c']); + }, +}; diff --git a/test/runtime/samples/each-block-scope-shadow-self/main.svelte b/test/runtime/samples/each-block-scope-shadow-self/main.svelte new file mode 100644 index 0000000000..e3643c524a --- /dev/null +++ b/test/runtime/samples/each-block-scope-shadow-self/main.svelte @@ -0,0 +1,15 @@ + + +{#each x as x} + +{/each} \ No newline at end of file From 3d629ffb0c7390828a6bf7e69eaeb140286fe6bb Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 16 Oct 2019 16:50:38 -0400 Subject: [PATCH 046/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cec108c4b..bdee28d1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) From aa8503ac511debe063af095a26161c4b3dc6ab97 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Oct 2019 17:56:30 -0400 Subject: [PATCH 047/413] alpha.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7868700246..c4f1269139 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.12.1", + "version": "3.13.0-alpha.0", "description": "Cybernetically enhanced web apps", "module": "index.mjs", "main": "index", From 84b0e865830a2f4cc943975c2683342ea651069f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Oct 2019 18:17:32 -0400 Subject: [PATCH 048/413] allow site to run locally without PG env vars --- site/src/server.js | 6 ++++-- site/src/utils/db.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/site/src/server.js b/site/src/server.js index 2425b51f54..fb003961bc 100644 --- a/site/src/server.js +++ b/site/src/server.js @@ -14,9 +14,11 @@ const app = polka({ } }); -app.use( - authenticate(), +if (process.env.PGHOST) { + app.use(authenticate); +} +app.use( sirv('static', { dev: process.env.NODE_ENV === 'development', setHeaders(res) { diff --git a/site/src/utils/db.js b/site/src/utils/db.js index ba9d5e4066..069450b0f3 100644 --- a/site/src/utils/db.js +++ b/site/src/utils/db.js @@ -1,7 +1,7 @@ import { Pool } from 'pg'; // Uses `PG*` ENV vars -export const DB = new Pool(); +export const DB = process.env.PGHOST ? new Pool() : null; export function query(text, values=[]) { return DB.query(text, values).then(r => r.rows); From 54a129c7fa3e17fda299d1972eaaa17e936fd83d Mon Sep 17 00:00:00 2001 From: das Date: Wed, 16 Oct 2019 20:13:37 -0400 Subject: [PATCH 049/413] continue inlining $$invalidate calls (#3548) * finish inlining $$invalidate * add failing test * add test for navigator online * add tests for store invalidate refactor * add test for reactive_store_subscriptions * remove failing test * update --- src/compiler/compile/render_dom/index.ts | 6 +- .../expected.js | 55 ++++++++++++++ .../input.svelte | 6 ++ .../expected.js | 45 +++++++++++ .../input.svelte | 7 ++ .../component-store-file-invalidate/store.js | 3 + .../expected.js | 74 +++++++++++++++++++ .../input.svelte | 7 ++ .../samples/window-binding-online/expected.js | 49 ++++++++++++ .../window-binding-online/input.svelte | 5 ++ 10 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 test/js/samples/component-store-access-invalidate/expected.js create mode 100644 test/js/samples/component-store-access-invalidate/input.svelte create mode 100644 test/js/samples/component-store-file-invalidate/expected.js create mode 100644 test/js/samples/component-store-file-invalidate/input.svelte create mode 100644 test/js/samples/component-store-file-invalidate/store.js create mode 100644 test/js/samples/component-store-reassign-invalidate/expected.js create mode 100644 test/js/samples/component-store-reassign-invalidate/input.svelte create mode 100644 test/js/samples/window-binding-online/expected.js create mode 100644 test/js/samples/window-binding-online/input.svelte diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 1186f1b483..bd7b99bd8f 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -228,7 +228,7 @@ export default function dom( return b`${`$$subscribe_${name}`}()`; } - const callback = x`$$value => { $$invalidate('${value}', ${value} = $$value) }`; + const callback = x`$$value => $$invalidate('${value}', ${value} = $$value)`; let insert = b`@component_subscribe($$self, ${name}, $${callback})`; if (component.compile_options.dev) { @@ -305,7 +305,7 @@ export default function dom( }) .map(({ name }) => b` ${component.compile_options.dev && `@validate_store(${name.slice(1)}, '${name.slice(1)}');`} - @component_subscribe($$self, ${name.slice(1)}, $$value => { ${name} = $$value; $$invalidate('${name}', ${name}); }); + @component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate('${name}', ${name} = $$value)); `); const resubscribable_reactive_store_unsubscribers = reactive_stores @@ -356,7 +356,7 @@ export default function dom( if (store && store.reassigned) { const unsubscribe = `$$unsubscribe_${name}`; const subscribe = `$$subscribe_${name}`; - return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => { ${$name} = $$value; $$invalidate('${$name}', ${$name}); }), ${name})`; + return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate('${$name}', ${$name} = $$value)), ${name})`; } return b`let ${$name};`; diff --git a/test/js/samples/component-store-access-invalidate/expected.js b/test/js/samples/component-store-access-invalidate/expected.js new file mode 100644 index 0000000000..029c0a6d21 --- /dev/null +++ b/test/js/samples/component-store-access-invalidate/expected.js @@ -0,0 +1,55 @@ +import { + SvelteComponent, + append, + component_subscribe, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; + +import { writable } from "svelte/store"; + +function create_fragment(ctx) { + let h1; + let t; + + return { + c() { + h1 = element("h1"); + t = text(ctx.$foo); + }, + m(target, anchor) { + insert(target, h1, anchor); + append(h1, t); + }, + p(changed, ctx) { + if (changed.$foo) set_data(t, ctx.$foo); + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(h1); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let $foo; + const foo = writable(0); + component_subscribe($$self, foo, $$value => $$invalidate("$foo", $foo = $$value)); + return { foo, $foo }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/component-store-access-invalidate/input.svelte b/test/js/samples/component-store-access-invalidate/input.svelte new file mode 100644 index 0000000000..f42bbe295c --- /dev/null +++ b/test/js/samples/component-store-access-invalidate/input.svelte @@ -0,0 +1,6 @@ + + +

{$foo}

\ No newline at end of file diff --git a/test/js/samples/component-store-file-invalidate/expected.js b/test/js/samples/component-store-file-invalidate/expected.js new file mode 100644 index 0000000000..8082d6e7ee --- /dev/null +++ b/test/js/samples/component-store-file-invalidate/expected.js @@ -0,0 +1,45 @@ +import { + SvelteComponent, + component_subscribe, + init, + noop, + safe_not_equal, + set_store_value +} from "svelte/internal"; + +import { count } from "./store.js"; + +function create_fragment(ctx) { + return { + c: noop, + m: noop, + p: noop, + i: noop, + o: noop, + d: noop + }; +} + +function instance($$self, $$props, $$invalidate) { + let $count; + component_subscribe($$self, count, $$value => $$invalidate("$count", $count = $$value)); + + function increment() { + set_store_value(count, $count++, $count); + } + + return { increment }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, ["increment"]); + } + + get increment() { + return this.$$.ctx.increment; + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/component-store-file-invalidate/input.svelte b/test/js/samples/component-store-file-invalidate/input.svelte new file mode 100644 index 0000000000..3c2fca2e80 --- /dev/null +++ b/test/js/samples/component-store-file-invalidate/input.svelte @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/js/samples/component-store-file-invalidate/store.js b/test/js/samples/component-store-file-invalidate/store.js new file mode 100644 index 0000000000..99e27e5584 --- /dev/null +++ b/test/js/samples/component-store-file-invalidate/store.js @@ -0,0 +1,3 @@ +import { writable } from '../../../../store'; + +export const count = writable(0); \ No newline at end of file diff --git a/test/js/samples/component-store-reassign-invalidate/expected.js b/test/js/samples/component-store-reassign-invalidate/expected.js new file mode 100644 index 0000000000..fc3cc65366 --- /dev/null +++ b/test/js/samples/component-store-reassign-invalidate/expected.js @@ -0,0 +1,74 @@ +import { + SvelteComponent, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + space, + subscribe, + text +} from "svelte/internal"; + +import { writable } from "svelte/store"; + +function create_fragment(ctx) { + let h1; + let t0; + let t1; + let button; + let dispose; + + return { + c() { + h1 = element("h1"); + t0 = text(ctx.$foo); + t1 = space(); + button = element("button"); + button.textContent = "reset"; + dispose = listen(button, "click", ctx.click_handler); + }, + m(target, anchor) { + insert(target, h1, anchor); + append(h1, t0); + insert(target, t1, anchor); + insert(target, button, anchor); + }, + p(changed, ctx) { + if (changed.$foo) set_data(t0, ctx.$foo); + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(h1); + if (detaching) detach(t1); + if (detaching) detach(button); + dispose(); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let $foo, + $$unsubscribe_foo = noop, + $$subscribe_foo = () => ($$unsubscribe_foo(), $$unsubscribe_foo = subscribe(foo, $$value => $$invalidate("$foo", $foo = $$value)), foo); + + $$self.$$.on_destroy.push(() => $$unsubscribe_foo()); + let foo = writable(0); + $$subscribe_foo(); + const click_handler = () => $$subscribe_foo($$invalidate("foo", foo = writable(0))); + return { foo, $foo, click_handler }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/component-store-reassign-invalidate/input.svelte b/test/js/samples/component-store-reassign-invalidate/input.svelte new file mode 100644 index 0000000000..bbb52b9669 --- /dev/null +++ b/test/js/samples/component-store-reassign-invalidate/input.svelte @@ -0,0 +1,7 @@ + + +

{$foo}

+ \ No newline at end of file diff --git a/test/js/samples/window-binding-online/expected.js b/test/js/samples/window-binding-online/expected.js new file mode 100644 index 0000000000..30087ca615 --- /dev/null +++ b/test/js/samples/window-binding-online/expected.js @@ -0,0 +1,49 @@ +import { + SvelteComponent, + add_render_callback, + init, + listen, + noop, + run_all, + safe_not_equal +} from "svelte/internal"; + +function create_fragment(ctx) { + let dispose; + add_render_callback(ctx.onlinestatuschanged); + + return { + c() { + dispose = [ + listen(window, "online", ctx.onlinestatuschanged), + listen(window, "offline", ctx.onlinestatuschanged) + ]; + }, + m: noop, + p: noop, + i: noop, + o: noop, + d(detaching) { + run_all(dispose); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let online; + + function onlinestatuschanged() { + $$invalidate("online", online = navigator.onLine); + } + + return { online, onlinestatuschanged }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/window-binding-online/input.svelte b/test/js/samples/window-binding-online/input.svelte new file mode 100644 index 0000000000..9f4b7064d8 --- /dev/null +++ b/test/js/samples/window-binding-online/input.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file From 908a06c13317c1fa01f10d1aadb52a9ee5c5aff5 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 16 Oct 2019 21:29:54 -0400 Subject: [PATCH 050/413] typos --- test/js/samples/debug-no-dependencies/expected.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/js/samples/debug-no-dependencies/expected.js b/test/js/samples/debug-no-dependencies/expected.js index c8de6e112b..2212f3e0bb 100644 --- a/test/js/samples/debug-no-dependencies/expected.js +++ b/test/js/samples/debug-no-dependencies/expected.js @@ -41,7 +41,7 @@ function create_each_block(ctx) { insert_dev(target, t0, anchor); insert_dev(target, t1, anchor); }, - p: noop}, + p: noop, d: function destroy(detaching) { if (detaching) detach_dev(t0); if (detaching) detach_dev(t1); @@ -106,6 +106,7 @@ function create_fragment(ctx) { for (; i < each_blocks.length; i += 1) { each_blocks[i].d(1); } + each_blocks.length = each_value.length; } }, From 8aa98795a17a760edc81a3fb3f172f5bd9d8cb7b Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 16 Oct 2019 22:14:12 -0400 Subject: [PATCH 051/413] dont cache attribute values (ref #3579) --- .../compile/render_dom/wrappers/Element/Attribute.ts | 2 +- test/js/samples/inline-style-unoptimized/expected.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 876be588d6..d2def7e5cf 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -95,7 +95,7 @@ export default class AttributeWrapper { const is_select_value_attribute = name === 'value' && element.node.name === 'select'; - const should_cache = (this.node.should_cache() || is_select_value_attribute); + const should_cache = is_select_value_attribute; // TODO is this necessary? const last = should_cache && block.get_unique_name( `${element.var.name}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value` diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index d1a36c12ca..74ef64639f 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -14,7 +14,6 @@ function create_fragment(ctx) { let div0; let t; let div1; - let div1_style_value; return { c() { @@ -22,7 +21,7 @@ function create_fragment(ctx) { t = space(); div1 = element("div"); attr(div0, "style", ctx.style); - attr(div1, "style", div1_style_value = "" + (ctx.key + ": " + ctx.value)); + attr(div1, "style", "" + (ctx.key + ": " + ctx.value)); }, m(target, anchor) { insert(target, div0, anchor); @@ -34,8 +33,8 @@ function create_fragment(ctx) { attr(div0, "style", ctx.style); } - if ((changed.key || changed.value) && div1_style_value !== (div1_style_value = "" + (ctx.key + ": " + ctx.value))) { - attr(div1, "style", div1_style_value); + if (changed.key || changed.value) { + attr(div1, "style", "" + (ctx.key + ": " + ctx.value)); } }, i: noop, From 8c4fd745435e622cac28f011078015a38491a9eb Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 6 Oct 2019 13:07:08 +0800 Subject: [PATCH 052/413] resubscribe props if reassigned --- src/compiler/compile/Component.ts | 2 +- src/compiler/compile/render_dom/index.ts | 18 +++++++------ .../store-resubscribe-export/_config.js | 27 +++++++++++++++++++ .../store-resubscribe-export/main.svelte | 6 +++++ 4 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 test/runtime/samples/store-resubscribe-export/_config.js create mode 100644 test/runtime/samples/store-resubscribe-export/main.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index ee24fc700c..456a3ee022 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -772,7 +772,7 @@ export default class Component { invalidate(name, value?) { const variable = this.var_lookup.get(name); - if (variable && (variable.subscribable && variable.reassigned)) { + if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) { return x`${`$$subscribe_${name}`}($$invalidate('${name}', ${value || name}))`; } diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index bd7b99bd8f..83b0c6ef0a 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -221,16 +221,18 @@ export default function dom( } }); - component.rewrite_props(({ name, reassigned }) => { + component.rewrite_props(({ name, reassigned, export_name }) => { const value = `$${name}`; + + let insert: string; + if (reassigned || export_name) { + insert = b`${`$$subscribe_${name}`}()`; + } else { + const callback = x`$$value => $$invalidate('${value}', ${value} = $$value)`; - if (reassigned) { - return b`${`$$subscribe_${name}`}()`; + insert = b`@component_subscribe($$self, ${name}, $${callback})`; } - const callback = x`$$value => $$invalidate('${value}', ${value} = $$value)`; - - let insert = b`@component_subscribe($$self, ${name}, $${callback})`; if (component.compile_options.dev) { insert = b`@validate_store(${name}, '${name}'); ${insert}`; } @@ -311,7 +313,7 @@ export default function dom( const resubscribable_reactive_store_unsubscribers = reactive_stores .filter(store => { const variable = component.var_lookup.get(store.name.slice(1)); - return variable && variable.reassigned; + return variable && (variable.reassigned || variable.export_name); }) .map(({ name }) => b`$$self.$$.on_destroy.push(() => ${`$$unsubscribe_${name.slice(1)}`}());`); @@ -353,7 +355,7 @@ export default function dom( const name = $name.slice(1); const store = component.var_lookup.get(name); - if (store && store.reassigned) { + if (store && (store.reassigned || store.export_name)) { const unsubscribe = `$$unsubscribe_${name}`; const subscribe = `$$subscribe_${name}`; return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate('${$name}', ${$name} = $$value)), ${name})`; diff --git a/test/runtime/samples/store-resubscribe-export/_config.js b/test/runtime/samples/store-resubscribe-export/_config.js new file mode 100644 index 0000000000..b6e6f11344 --- /dev/null +++ b/test/runtime/samples/store-resubscribe-export/_config.js @@ -0,0 +1,27 @@ +let subscribeCalled = false; + +const fakeStore = val => ({ + subscribe: cb => { + cb(val); + return { + unsubscribe: () => { + subscribeCalled = true; + }, + }; + }, +}); + +export default { + props: { + foo: fakeStore(1), + }, + html: ` +

1

+ `, + + async test({ assert, component, target }) { + component.foo = fakeStore(5); + + return assert.htmlEqual(target.innerHTML, `

5

`); + }, +}; diff --git a/test/runtime/samples/store-resubscribe-export/main.svelte b/test/runtime/samples/store-resubscribe-export/main.svelte new file mode 100644 index 0000000000..44b00544b7 --- /dev/null +++ b/test/runtime/samples/store-resubscribe-export/main.svelte @@ -0,0 +1,6 @@ + + +

{$foo}

From 6a98febf5fb41d54c4bd1446934a6f4624657eb5 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 17 Oct 2019 21:47:40 +0800 Subject: [PATCH 053/413] fix typescript error --- src/compiler/compile/render_dom/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 83b0c6ef0a..582d9041cc 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -224,7 +224,7 @@ export default function dom( component.rewrite_props(({ name, reassigned, export_name }) => { const value = `$${name}`; - let insert: string; + let insert: Node[]; if (reassigned || export_name) { insert = b`${`$$subscribe_${name}`}()`; } else { From ddbbccc9e4ddb83c423b2f48c3bb8563077c00cf Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 17 Oct 2019 09:53:58 -0400 Subject: [PATCH 054/413] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdee28d1dc..3fa087e03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) +* Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) From dda9a53727c3b5d635dac4db5f251f0a878104b0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 17 Oct 2019 10:06:44 -0400 Subject: [PATCH 055/413] preserve `$:` label in reactive blocks in SSR mode (#2828) (#3469) --- CHANGELOG.md | 1 + src/compiler/compile/render_ssr/index.ts | 2 ++ .../samples/reactive-block-break/_config.js | 3 +++ .../samples/reactive-block-break/main.svelte | 14 ++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 test/runtime/samples/reactive-block-break/_config.js create mode 100644 test/runtime/samples/reactive-block-break/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa087e03a..e19af3e53f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index d193508a89..00157cc256 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -98,6 +98,8 @@ export default function ssr( : b` let ${left} = ${right}`; } + } else { // TODO do not add label if it's not referenced + statement = b`$: { ${statement} }`; } return statement; diff --git a/test/runtime/samples/reactive-block-break/_config.js b/test/runtime/samples/reactive-block-break/_config.js new file mode 100644 index 0000000000..f2d3e6a8f5 --- /dev/null +++ b/test/runtime/samples/reactive-block-break/_config.js @@ -0,0 +1,3 @@ +export default { + html: `

1 2

` +}; \ No newline at end of file diff --git a/test/runtime/samples/reactive-block-break/main.svelte b/test/runtime/samples/reactive-block-break/main.svelte new file mode 100644 index 0000000000..5b0aa005c0 --- /dev/null +++ b/test/runtime/samples/reactive-block-break/main.svelte @@ -0,0 +1,14 @@ + + +

{foo} {bar}

\ No newline at end of file From a31fea139b3c80ef503bf5d35ebb240a58a030a8 Mon Sep 17 00:00:00 2001 From: Li Hau Tan Date: Fri, 18 Oct 2019 17:59:50 +0800 Subject: [PATCH 056/413] then and catch block expect await, optional then block --- src/compiler/parse/state/mustache.ts | 92 +++++----- test/parser/samples/await-catch/input.svelte | 5 + test/parser/samples/await-catch/output.json | 168 ++++++++++++++++++ .../error-catch-without-await/error.json | 10 ++ .../error-catch-without-await/input.svelte | 1 + .../error-then-without-await/error.json | 10 ++ .../error-then-without-await/input.svelte | 1 + 7 files changed, 246 insertions(+), 41 deletions(-) create mode 100644 test/parser/samples/await-catch/input.svelte create mode 100644 test/parser/samples/await-catch/output.json create mode 100644 test/parser/samples/error-catch-without-await/error.json create mode 100644 test/parser/samples/error-catch-without-await/input.svelte create mode 100644 test/parser/samples/error-then-without-await/error.json create mode 100644 test/parser/samples/error-then-without-await/input.svelte diff --git a/src/compiler/parse/state/mustache.ts b/src/compiler/parse/state/mustache.ts index 4a1578ada5..d34b6a3b6c 100644 --- a/src/compiler/parse/state/mustache.ts +++ b/src/compiler/parse/state/mustache.ts @@ -163,54 +163,64 @@ export default function mustache(parser: Parser) { } else if (parser.eat(':then')) { // TODO DRY out this and the next section const pending_block = parser.current(); - if (pending_block.type === 'PendingBlock') { - pending_block.end = start; - parser.stack.pop(); - const await_block = parser.current(); - - if (!parser.eat('}')) { - parser.require_whitespace(); - await_block.value = parser.read_identifier(); - parser.allow_whitespace(); - parser.eat('}', true); - } + if (pending_block.type !== 'PendingBlock') { + parser.error({ + code: `invalid-then-placement`, + message: 'Cannot have an {:then} block outside an {#await ...} block' + }); + } - const then_block: TemplateNode = { - start, - end: null, - type: 'ThenBlock', - children: [], - skip: false - }; + pending_block.end = start; + parser.stack.pop(); + const await_block = parser.current(); - await_block.then = then_block; - parser.stack.push(then_block); + if (!parser.eat('}')) { + parser.require_whitespace(); + await_block.value = parser.read_identifier(); + parser.allow_whitespace(); + parser.eat('}', true); } - } else if (parser.eat(':catch')) { - const then_block = parser.current(); - if (then_block.type === 'ThenBlock') { - then_block.end = start; - parser.stack.pop(); - const await_block = parser.current(); - if (!parser.eat('}')) { - parser.require_whitespace(); - await_block.error = parser.read_identifier(); - parser.allow_whitespace(); - parser.eat('}', true); - } + const then_block: TemplateNode = { + start, + end: null, + type: 'ThenBlock', + children: [], + skip: false + }; + + await_block.then = then_block; + parser.stack.push(then_block); + } else if (parser.eat(':catch')) { + const block = parser.current(); + if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') { + parser.error({ + code: `invalid-catch-placement`, + message: 'Cannot have an {:catch} block outside an {#await ...} block' + }); + } - const catch_block: TemplateNode = { - start, - end: null, - type: 'CatchBlock', - children: [], - skip: false - }; + block.end = start; + parser.stack.pop(); + const await_block = parser.current(); - await_block.catch = catch_block; - parser.stack.push(catch_block); + if (!parser.eat('}')) { + parser.require_whitespace(); + await_block.error = parser.read_identifier(); + parser.allow_whitespace(); + parser.eat('}', true); } + + const catch_block: TemplateNode = { + start, + end: null, + type: 'CatchBlock', + children: [], + skip: false + }; + + await_block.catch = catch_block; + parser.stack.push(catch_block); } else if (parser.eat('#')) { // {#if foo}, {#each foo} or {#await foo} let type; diff --git a/test/parser/samples/await-catch/input.svelte b/test/parser/samples/await-catch/input.svelte new file mode 100644 index 0000000000..207bacb5b1 --- /dev/null +++ b/test/parser/samples/await-catch/input.svelte @@ -0,0 +1,5 @@ +{#await thePromise} +

loading...

+{:catch theError} +

oh no! {theError.message}

+{/await} \ No newline at end of file diff --git a/test/parser/samples/await-catch/output.json b/test/parser/samples/await-catch/output.json new file mode 100644 index 0000000000..2461f467f2 --- /dev/null +++ b/test/parser/samples/await-catch/output.json @@ -0,0 +1,168 @@ +{ + "html": { + "start": 0, + "end": 99, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 99, + "type": "AwaitBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "thePromise" + }, + "value": null, + "error": "theError", + "pending": { + "start": 19, + "end": 39, + "type": "PendingBlock", + "children": [ + { + "start": 19, + "end": 21, + "type": "Text", + "raw": "\n\t", + "data": "\n\t" + }, + { + "start": 21, + "end": 38, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 24, + "end": 34, + "type": "Text", + "raw": "loading...", + "data": "loading..." + } + ] + }, + { + "start": 38, + "end": 39, + "type": "Text", + "raw": "\n", + "data": "\n" + } + ], + "skip": false + }, + "then": { + "start": null, + "end": null, + "type": "ThenBlock", + "children": [], + "skip": true + }, + "catch": { + "start": 39, + "end": 91, + "type": "CatchBlock", + "children": [ + { + "start": 56, + "end": 58, + "type": "Text", + "raw": "\n\t", + "data": "\n\t" + }, + { + "start": 58, + "end": 90, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 61, + "end": 68, + "type": "Text", + "raw": "oh no! ", + "data": "oh no! " + }, + { + "start": 68, + "end": 86, + "type": "MustacheTag", + "expression": { + "type": "MemberExpression", + "start": 69, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "object": { + "type": "Identifier", + "start": 69, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "name": "theError" + }, + "property": { + "type": "Identifier", + "start": 78, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "name": "message" + }, + "computed": false + } + } + ] + }, + { + "start": 90, + "end": 91, + "type": "Text", + "raw": "\n", + "data": "\n" + } + ], + "skip": false + } + } + ] + } +} \ No newline at end of file diff --git a/test/parser/samples/error-catch-without-await/error.json b/test/parser/samples/error-catch-without-await/error.json new file mode 100644 index 0000000000..86cf64a673 --- /dev/null +++ b/test/parser/samples/error-catch-without-await/error.json @@ -0,0 +1,10 @@ +{ + "code": "invalid-catch-placement", + "message": "Cannot have an {:catch} block outside an {#await ...} block", + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "pos": 7 +} diff --git a/test/parser/samples/error-catch-without-await/input.svelte b/test/parser/samples/error-catch-without-await/input.svelte new file mode 100644 index 0000000000..ee2fab68e0 --- /dev/null +++ b/test/parser/samples/error-catch-without-await/input.svelte @@ -0,0 +1 @@ +{:catch theValue} diff --git a/test/parser/samples/error-then-without-await/error.json b/test/parser/samples/error-then-without-await/error.json new file mode 100644 index 0000000000..62d9cbc3c9 --- /dev/null +++ b/test/parser/samples/error-then-without-await/error.json @@ -0,0 +1,10 @@ +{ + "code": "invalid-then-placement", + "message": "Cannot have an {:then} block outside an {#await ...} block", + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "pos": 6 +} diff --git a/test/parser/samples/error-then-without-await/input.svelte b/test/parser/samples/error-then-without-await/input.svelte new file mode 100644 index 0000000000..4b7fb6c677 --- /dev/null +++ b/test/parser/samples/error-then-without-await/input.svelte @@ -0,0 +1 @@ +{:then theValue} From 03d4bf48f9269ef9276bd1ed5f05f067807ffbf4 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 19 Oct 2019 00:32:38 +0800 Subject: [PATCH 057/413] DRY out :then and :catch --- src/compiler/parse/state/mustache.ts | 64 ++++++++++------------------ 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/src/compiler/parse/state/mustache.ts b/src/compiler/parse/state/mustache.ts index d34b6a3b6c..c470ab548e 100644 --- a/src/compiler/parse/state/mustache.ts +++ b/src/compiler/parse/state/mustache.ts @@ -160,44 +160,24 @@ export default function mustache(parser: Parser) { parser.stack.push(block.else); } - } else if (parser.eat(':then')) { - // TODO DRY out this and the next section - const pending_block = parser.current(); - if (pending_block.type !== 'PendingBlock') { - parser.error({ - code: `invalid-then-placement`, - message: 'Cannot have an {:then} block outside an {#await ...} block' - }); - } - - pending_block.end = start; - parser.stack.pop(); - const await_block = parser.current(); - - if (!parser.eat('}')) { - parser.require_whitespace(); - await_block.value = parser.read_identifier(); - parser.allow_whitespace(); - parser.eat('}', true); - } - - const then_block: TemplateNode = { - start, - end: null, - type: 'ThenBlock', - children: [], - skip: false - }; - - await_block.then = then_block; - parser.stack.push(then_block); - } else if (parser.eat(':catch')) { + } else if (parser.match(':then') || parser.match(':catch')) { const block = parser.current(); - if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') { - parser.error({ - code: `invalid-catch-placement`, - message: 'Cannot have an {:catch} block outside an {#await ...} block' - }); + const isThen = parser.eat(':then') || !parser.eat(':catch'); + + if (isThen) { + if (block.type !== 'PendingBlock') { + parser.error({ + code: `invalid-then-placement`, + message: 'Cannot have an {:then} block outside an {#await ...} block' + }); + } + } else { + if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') { + parser.error({ + code: `invalid-catch-placement`, + message: 'Cannot have an {:catch} block outside an {#await ...} block' + }); + } } block.end = start; @@ -206,21 +186,21 @@ export default function mustache(parser: Parser) { if (!parser.eat('}')) { parser.require_whitespace(); - await_block.error = parser.read_identifier(); + await_block[isThen ? 'value': 'error'] = parser.read_identifier(); parser.allow_whitespace(); parser.eat('}', true); } - const catch_block: TemplateNode = { + const new_block: TemplateNode = { start, end: null, - type: 'CatchBlock', + type: isThen ? 'ThenBlock': 'CatchBlock', children: [], skip: false }; - await_block.catch = catch_block; - parser.stack.push(catch_block); + await_block[isThen ? 'then' : 'catch'] = new_block; + parser.stack.push(new_block); } else if (parser.eat('#')) { // {#if foo}, {#each foo} or {#await foo} let type; From daf4b465e67f090efbd0071d90e7465817b85875 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 19 Oct 2019 00:37:06 +0800 Subject: [PATCH 058/413] name.slice to slug --- src/compiler/parse/state/tag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 880c866ffe..c7e761afc2 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -81,7 +81,7 @@ export default function tag(parser: Parser) { parser.current().children.length ) { parser.error({ - code: `invalid-${name.slice(7)}-content`, + code: `invalid-${slug}-content`, message: `<${name}> cannot have children` }, parser.current().children[0].start); } From 577333e180b1f3ece52554d94dd4d5aec5bf587c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 18 Oct 2019 13:52:09 -0400 Subject: [PATCH 059/413] add each-block-keyed-iife test against regression (#3436) --- test/runtime/samples/each-block-keyed-iife/_config.js | 7 +++++++ test/runtime/samples/each-block-keyed-iife/main.svelte | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-iife/_config.js create mode 100644 test/runtime/samples/each-block-keyed-iife/main.svelte diff --git a/test/runtime/samples/each-block-keyed-iife/_config.js b/test/runtime/samples/each-block-keyed-iife/_config.js new file mode 100644 index 0000000000..da0b0aeac1 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-iife/_config.js @@ -0,0 +1,7 @@ +export default { + html: ` +
1
+
2
+
3
+ ` +}; diff --git a/test/runtime/samples/each-block-keyed-iife/main.svelte b/test/runtime/samples/each-block-keyed-iife/main.svelte new file mode 100644 index 0000000000..8753357bae --- /dev/null +++ b/test/runtime/samples/each-block-keyed-iife/main.svelte @@ -0,0 +1,9 @@ + + +{#each arr as item ((() => item)())} +
+ {item} +
+{/each} From ce5bd1bf35d7f0ac98fa651ee5b181acce97c267 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Fri, 18 Oct 2019 11:55:50 -0700 Subject: [PATCH 060/413] fix: invoke `authenticate` factory --- site/src/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/src/server.js b/site/src/server.js index fb003961bc..c7cf93c3b5 100644 --- a/site/src/server.js +++ b/site/src/server.js @@ -15,7 +15,7 @@ const app = polka({ }); if (process.env.PGHOST) { - app.use(authenticate); + app.use(authenticate()); } app.use( @@ -34,4 +34,4 @@ app.use( }) ); -app.listen(PORT); \ No newline at end of file +app.listen(PORT); From e14197d94406068ea8f6913a1190848bae740a60 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 19 Oct 2019 07:16:19 +0800 Subject: [PATCH 061/413] remove component locator --- src/compiler/compile/Component.ts | 21 ++++--------------- .../compile/render_dom/wrappers/DebugTag.ts | 1 - .../compile/render_dom/wrappers/EachBlock.ts | 1 - .../render_dom/wrappers/Element/index.ts | 2 +- .../shared/create_debugging_comment.ts | 2 +- .../compile/render_ssr/handlers/DebugTag.ts | 2 +- 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index ee24fc700c..58d7db39ba 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -90,15 +90,6 @@ export default class Component { file: string; locate: (c: number) => { line: number; column: number }; - // TODO this does the same as component.locate! remove one or the other - locator: ( - search: number, - startIndex?: number - ) => { - line: number; - column: number; - }; - stylesheet: Stylesheet; aliases: Map = new Map(); @@ -140,7 +131,7 @@ export default class Component { .replace(process.cwd(), '') .replace(/^[/\\]/, '') : compile_options.filename); - this.locate = getLocator(this.source); + this.locate = getLocator(this.source, { offsetLine: 1 }); // styles this.stylesheet = new Stylesheet( @@ -438,12 +429,8 @@ export default class Component { return; } - if (!this.locator) { - this.locator = getLocator(this.source, { offsetLine: 1 }); - } - - const start = this.locator(pos.start); - const end = this.locator(pos.end); + const start = this.locate(pos.start); + const end = this.locate(pos.end); const frame = get_code_frame(this.source, start.line - 1, start.column); @@ -456,7 +443,7 @@ export default class Component { pos: pos.start, filename: this.compile_options.filename, toString: () => - `${warning.message} (${start.line + 1}:${start.column})\n${frame}`, + `${warning.message} (${start.line}:${start.column})\n${frame}`, }); } diff --git a/src/compiler/compile/render_dom/wrappers/DebugTag.ts b/src/compiler/compile/render_dom/wrappers/DebugTag.ts index 87e186f3b4..dc3a2f2857 100644 --- a/src/compiler/compile/render_dom/wrappers/DebugTag.ts +++ b/src/compiler/compile/render_dom/wrappers/DebugTag.ts @@ -30,7 +30,6 @@ export default class DebugTagWrapper extends Wrapper { const { var_lookup } = component; const start = component.locate(this.node.start + 1); - start.line += 1; const end = { line: start.line, column: start.column + 6 }; const loc = { start, end }; diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index 5c8d193f56..922679c39f 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -108,7 +108,6 @@ export default class EachBlockWrapper extends Wrapper { let c = this.node.start + 2; while (renderer.component.source[c] !== 'e') c += 1; const start = renderer.component.locate(c); - start.line += 1; const end = { line: start.line, column: start.column + 4 }; const length = { type: 'Identifier', diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 3f1b411966..d7c1c7686b 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -354,7 +354,7 @@ export default class ElementWrapper extends Wrapper { if (renderer.options.dev) { const loc = renderer.locate(this.node.start); block.chunks.hydrate.push( - b`@add_location(${this.var}, ${renderer.file_var}, ${loc.line}, ${loc.column}, ${this.node.start});` + b`@add_location(${this.var}, ${renderer.file_var}, ${loc.line - 1}, ${loc.column}, ${this.node.start});` ); } } diff --git a/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts b/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts index df1ae9ff8e..e2aa0c0b41 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts @@ -26,7 +26,7 @@ export default function create_debugging_comment( } const start = locate(c); - const loc = `(${start.line + 1}:${start.column})`; + const loc = `(${start.line}:${start.column})`; return `${loc} ${source.slice(c, d)}`.replace(/\s/g, ' '); } diff --git a/src/compiler/compile/render_ssr/handlers/DebugTag.ts b/src/compiler/compile/render_ssr/handlers/DebugTag.ts index 6955d1d1e6..99323a9c4d 100644 --- a/src/compiler/compile/render_ssr/handlers/DebugTag.ts +++ b/src/compiler/compile/render_ssr/handlers/DebugTag.ts @@ -12,5 +12,5 @@ export default function(node: DebugTag, renderer: Renderer, options: RenderOptio ${node.expressions.map(e => p`${e.node.name}`)} }`; - renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line}, ${column}, ${obj})`); + renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line - 1}, ${column}, ${obj})`); } From db901725ae3fa246b25234fc37602b5231ad633f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 18 Oct 2019 20:40:06 -0400 Subject: [PATCH 062/413] simplify --- src/compiler/compile/render_dom/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 582d9041cc..ba070beee9 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -224,17 +224,12 @@ export default function dom( component.rewrite_props(({ name, reassigned, export_name }) => { const value = `$${name}`; - let insert: Node[]; - if (reassigned || export_name) { - insert = b`${`$$subscribe_${name}`}()`; - } else { - const callback = x`$$value => $$invalidate('${value}', ${value} = $$value)`; - - insert = b`@component_subscribe($$self, ${name}, $${callback})`; - } + const insert = (reassigned || export_name) + ? b`${`$$subscribe_${name}`}()` + : b`@component_subscribe($$self, ${name}, #value => $$invalidate('${value}', ${value} = #value))`; if (component.compile_options.dev) { - insert = b`@validate_store(${name}, '${name}'); ${insert}`; + return b`@validate_store(${name}, '${name}'); ${insert}`; } return insert; From 4419a5597733466e9c7228952ef5b639e9e6b4a5 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Fri, 18 Oct 2019 20:46:51 -0400 Subject: [PATCH 063/413] fix test --- test/js/samples/component-store-access-invalidate/expected.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js/samples/component-store-access-invalidate/expected.js b/test/js/samples/component-store-access-invalidate/expected.js index 029c0a6d21..f9f7b453e6 100644 --- a/test/js/samples/component-store-access-invalidate/expected.js +++ b/test/js/samples/component-store-access-invalidate/expected.js @@ -41,7 +41,7 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let $foo; const foo = writable(0); - component_subscribe($$self, foo, $$value => $$invalidate("$foo", $foo = $$value)); + component_subscribe($$self, foo, value => $$invalidate("$foo", $foo = value)); return { foo, $foo }; } From 65d87e51d1041b26292b6b3f1f03d7495e40efff Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Fri, 18 Oct 2019 20:49:31 -0400 Subject: [PATCH 064/413] snake_case --- src/compiler/parse/state/mustache.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/parse/state/mustache.ts b/src/compiler/parse/state/mustache.ts index c470ab548e..140e722b10 100644 --- a/src/compiler/parse/state/mustache.ts +++ b/src/compiler/parse/state/mustache.ts @@ -162,9 +162,9 @@ export default function mustache(parser: Parser) { } } else if (parser.match(':then') || parser.match(':catch')) { const block = parser.current(); - const isThen = parser.eat(':then') || !parser.eat(':catch'); + const is_then = parser.eat(':then') || !parser.eat(':catch'); - if (isThen) { + if (is_then) { if (block.type !== 'PendingBlock') { parser.error({ code: `invalid-then-placement`, @@ -186,7 +186,7 @@ export default function mustache(parser: Parser) { if (!parser.eat('}')) { parser.require_whitespace(); - await_block[isThen ? 'value': 'error'] = parser.read_identifier(); + await_block[is_then ? 'value': 'error'] = parser.read_identifier(); parser.allow_whitespace(); parser.eat('}', true); } @@ -194,12 +194,12 @@ export default function mustache(parser: Parser) { const new_block: TemplateNode = { start, end: null, - type: isThen ? 'ThenBlock': 'CatchBlock', + type: is_then ? 'ThenBlock': 'CatchBlock', children: [], skip: false }; - await_block[isThen ? 'then' : 'catch'] = new_block; + await_block[is_then ? 'then' : 'catch'] = new_block; parser.stack.push(new_block); } else if (parser.eat('#')) { // {#if foo}, {#each foo} or {#await foo} From 2e2b0c9175cf720542527313b3a046f92384cb01 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 19 Oct 2019 01:52:59 -0400 Subject: [PATCH 065/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e19af3e53f..e357e58acd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) +* Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) From 8d7d0ff7dd7b248ca6d9b6b4cac098430c6e6ffa Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 19 Oct 2019 08:51:59 -0400 Subject: [PATCH 066/413] fix `bind:this` binding to a store (#3591) --- CHANGELOG.md | 1 + src/compiler/compile/Component.ts | 2 +- test/runtime/samples/binding-this-store/_config.js | 4 ++++ test/runtime/samples/binding-this-store/main.svelte | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/binding-this-store/_config.js create mode 100644 test/runtime/samples/binding-this-store/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index e357e58acd..c2611da704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) +* Fix `bind:this` binding to a store ([#3591](https://github.com/sveltejs/svelte/issue/3591)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623)) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 20c0d09e24..8d1384e7a1 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -764,7 +764,7 @@ export default class Component { } if (name[0] === '$' && name[1] !== '$') { - return x`${name.slice(1)}.set(${name})`; + return x`${name.slice(1)}.set(${value || name})`; } if ( diff --git a/test/runtime/samples/binding-this-store/_config.js b/test/runtime/samples/binding-this-store/_config.js new file mode 100644 index 0000000000..f818c2e31e --- /dev/null +++ b/test/runtime/samples/binding-this-store/_config.js @@ -0,0 +1,4 @@ +export default { + skip_if_ssr: true, + html: `
object
` +}; diff --git a/test/runtime/samples/binding-this-store/main.svelte b/test/runtime/samples/binding-this-store/main.svelte new file mode 100644 index 0000000000..7958dfa2d8 --- /dev/null +++ b/test/runtime/samples/binding-this-store/main.svelte @@ -0,0 +1,6 @@ + + +
{typeof $foo}
From 914d155d9f2b8f93f5ef44ed84c76581187f9111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Kishi?= Date: Sat, 19 Oct 2019 16:20:46 -0300 Subject: [PATCH 067/413] fix store validation code generation (#3735) --- src/compiler/compile/render_dom/index.ts | 2 +- test/runtime/samples/store-imported/_config.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index ba070beee9..72f81cfb05 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -301,7 +301,7 @@ export default function dom( return !variable || variable.hoistable; }) .map(({ name }) => b` - ${component.compile_options.dev && `@validate_store(${name.slice(1)}, '${name.slice(1)}');`} + ${component.compile_options.dev && b`@validate_store(${name.slice(1)}, '${name.slice(1)}');`} @component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate('${name}', ${name} = $$value)); `); diff --git a/test/runtime/samples/store-imported/_config.js b/test/runtime/samples/store-imported/_config.js index c2d471a329..251866e5ba 100644 --- a/test/runtime/samples/store-imported/_config.js +++ b/test/runtime/samples/store-imported/_config.js @@ -1,4 +1,6 @@ export default { + compileOptions: { dev: true }, // tests `@validate_store` code generation + html: `

42

` From 3e02b954887514983a62a7b14bf12309ac1fac02 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 20 Oct 2019 07:29:33 -0400 Subject: [PATCH 068/413] fix compound ifs with outros and no dependencies (#3595) --- CHANGELOG.md | 1 + .../compile/render_dom/wrappers/IfBlock.ts | 10 ++++-- .../_config.js | 3 ++ .../main.svelte | 32 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/if-block-compound-outro-no-dependencies/_config.js create mode 100644 test/runtime/samples/if-block-compound-outro-no-dependencies/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index c2611da704..1328066397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) +* Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issue/3595)) * Fix `bind:this` binding to a store ([#3591](https://github.com/sveltejs/svelte/issue/3591)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index c54994a36c..dff7851b5a 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -271,8 +271,8 @@ export default class IfBlockWrapper extends Wrapper { ? b` ${snippet && ( dependencies.length > 0 - ? b`if ((${condition} == null) || ${changed(dependencies)}) ${condition} = !!(${snippet})` - : b`if (${condition} == null) ${condition} = !!(${snippet})` + ? b`if (${condition} == null || ${changed(dependencies)}) ${condition} = !!${snippet}` + : b`if (${condition} == null) ${condition} = !!${snippet}` )} if (${condition}) return ${block.name};` : b`return ${block.name};`)} @@ -388,7 +388,11 @@ export default class IfBlockWrapper extends Wrapper { function ${select_block_type}(#changed, #ctx) { ${this.branches.map(({ dependencies, condition, snippet }, i) => condition ? b` - ${snippet && b`if ((${condition} == null) || ${changed(dependencies)}) ${condition} = !!(${snippet})`} + ${snippet && ( + dependencies.length > 0 + ? b`if (${condition} == null || ${changed(dependencies)}) ${condition} = !!${snippet}` + : b`if (${condition} == null) ${condition} = !!${snippet}` + )} if (${condition}) return ${i};` : b`return ${i};`)} ${!has_else && b`return -1;`} diff --git a/test/runtime/samples/if-block-compound-outro-no-dependencies/_config.js b/test/runtime/samples/if-block-compound-outro-no-dependencies/_config.js new file mode 100644 index 0000000000..58b0521022 --- /dev/null +++ b/test/runtime/samples/if-block-compound-outro-no-dependencies/_config.js @@ -0,0 +1,3 @@ +export default { + html: `blah blah blah blah` +}; diff --git a/test/runtime/samples/if-block-compound-outro-no-dependencies/main.svelte b/test/runtime/samples/if-block-compound-outro-no-dependencies/main.svelte new file mode 100644 index 0000000000..84224116da --- /dev/null +++ b/test/runtime/samples/if-block-compound-outro-no-dependencies/main.svelte @@ -0,0 +1,32 @@ + + +{#if $foo} + blah +{:else} + {#if bar()} + + {/if} +{/if} + +{#if $foo} + blah +{:else} + {#if bar} + + {/if} +{/if} + +{#if $foo} + blah +{:else if bar()} + +{/if} + +{#if $foo} + blah +{:else if bar} + +{/if} From 39b387a4546d36cf6a4d045f4439e8197cd6cda4 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 19 Oct 2019 03:40:59 -0400 Subject: [PATCH 069/413] hoist globals even if they are mentioned in a script block (#3607) --- src/compiler/compile/Component.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 8d1384e7a1..b22b351da0 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -569,6 +569,7 @@ export default class Component { this.add_var({ name, global: true, + hoistable: true }); } }); @@ -661,6 +662,7 @@ export default class Component { this.add_var({ name, global: true, + hoistable: true }); } }); From 0d36f1a7941dc11b75d44f329ae7efddffffd25d Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 19 Oct 2019 03:46:46 -0400 Subject: [PATCH 070/413] don't consult known globals when walking Expression nodes (#3708) --- src/compiler/compile/nodes/shared/Expression.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index 4a3e96a282..ad4a1bc24d 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -3,7 +3,7 @@ import { walk } from 'estree-walker'; import is_reference from 'is-reference'; import flatten_reference from '../../utils/flatten_reference'; import { create_scopes, Scope, extract_names } from '../../utils/scope'; -import { globals, sanitize } from '../../../utils/names'; +import { sanitize } from '../../../utils/names'; import Wrapper from '../../render_dom/wrappers/shared/Wrapper'; import TemplateScope from './TemplateScope'; import get_object from '../../utils/get_object'; @@ -75,8 +75,6 @@ export default class Expression { if (scope.has(name)) return; - if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return; - if (name[0] === '$' && template_scope.names.has(name.slice(1))) { component.error(node, { code: `contextual-store`, @@ -202,7 +200,6 @@ export default class Expression { const { name } = flatten_reference(node); if (scope.has(name)) return; - if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return; if (function_expression) { if (template_scope.names.has(name)) { From 8ef32d766ad12c14aa922083af136e9d7d027206 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 20 Oct 2019 07:39:11 -0400 Subject: [PATCH 071/413] produce better code for (#3631) --- CHANGELOG.md | 1 + .../compile/render_dom/wrappers/Slot.ts | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1328066397..e39b8b4972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623)) +* Clean up dead code emitted for ``s ([#3631](https://github.com/sveltejs/svelte/issues/3631)) * Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634)) * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) diff --git a/src/compiler/compile/render_dom/wrappers/Slot.ts b/src/compiler/compile/render_dom/wrappers/Slot.ts index 1ab1b6abcb..fb90afab5b 100644 --- a/src/compiler/compile/render_dom/wrappers/Slot.ts +++ b/src/compiler/compile/render_dom/wrappers/Slot.ts @@ -137,12 +137,12 @@ export default class SlotWrapper extends Wrapper { block.render_listeners(`_${slot.name}`); block.event_listeners = listeners; - if (block.chunks.create) create.push(b`if (!${slot}) { ${block.chunks.create} }`); - if (block.chunks.claim) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`); - if (block.chunks.hydrate) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`); - if (block.chunks.mount) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`); - if (block.chunks.update) update.push(b`if (!${slot}) { ${block.chunks.update} }`); - if (block.chunks.destroy) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`); + if (block.chunks.create.length) create.push(b`if (!${slot}) { ${block.chunks.create} }`); + if (block.chunks.claim.length) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`); + if (block.chunks.hydrate.length) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`); + if (block.chunks.mount.length) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`); + if (block.chunks.update.length) update.push(b`if (!${slot}) { ${block.chunks.update} }`); + if (block.chunks.destroy.length) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`); block.chunks.create = create; block.chunks.claim = claim; @@ -155,9 +155,11 @@ export default class SlotWrapper extends Wrapper { b`if (${slot}) ${slot}.c();` ); - block.chunks.claim.push( - b`if (${slot}) ${slot}.l(${parent_nodes});` - ); + if (renderer.options.hydratable) { + block.chunks.claim.push( + b`if (${slot}) ${slot}.l(${parent_nodes});` + ); + } block.chunks.mount.push(b` if (${slot}) { From e3953b234c47c1337e3fc17ca33332f537182bc6 Mon Sep 17 00:00:00 2001 From: vages Date: Sun, 20 Oct 2019 21:26:26 +0200 Subject: [PATCH 072/413] Add Entur to "Who is using Svelte?" (#3754) --- site/src/routes/_components/WhosUsingSvelte.svelte | 1 + site/static/organisations/entur.svg | 1 + 2 files changed, 2 insertions(+) create mode 100644 site/static/organisations/entur.svg diff --git a/site/src/routes/_components/WhosUsingSvelte.svelte b/site/src/routes/_components/WhosUsingSvelte.svelte index fe9a2fcc9d..2a944fe289 100644 --- a/site/src/routes/_components/WhosUsingSvelte.svelte +++ b/site/src/routes/_components/WhosUsingSvelte.svelte @@ -55,6 +55,7 @@ Deck logo Dextra logo Entriwise logo + Entur logo From-Now-On logo FusionCharts logo GoDaddy logo diff --git a/site/static/organisations/entur.svg b/site/static/organisations/entur.svg new file mode 100644 index 0000000000..98bb5cc937 --- /dev/null +++ b/site/static/organisations/entur.svg @@ -0,0 +1 @@ + \ No newline at end of file From fca35def5389c8c132b80882d3cf4154d77bf4e9 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Mon, 21 Oct 2019 23:19:15 +0800 Subject: [PATCH 073/413] deconflict with builtins (#3724) --- src/compiler/compile/render_dom/Block.ts | 4 +++- test/js/samples/debug-no-dependencies/expected.js | 10 +++++----- test/js/samples/deconflict-builtins/expected.js | 10 +++++----- .../samples/each-block-array-literal/expected.js | 10 +++++----- .../samples/each-block-keyed-animated/expected.js | 14 +++++++------- test/js/samples/each-block-keyed/expected.js | 14 +++++++------- .../samples/deconflict-builtins-2/_config.js | 4 ++++ .../samples/deconflict-builtins-2/main.svelte | 5 +++++ 8 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 test/runtime/samples/deconflict-builtins-2/_config.js create mode 100644 test/runtime/samples/deconflict-builtins-2/main.svelte diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index f73212f3ba..b268954dd0 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -146,11 +146,13 @@ export default class Block { if (!wrapper.var) continue; + let suffix = ''; if (dupes.has(wrapper.var.name)) { const i = counts.get(wrapper.var.name) || 0; counts.set(wrapper.var.name, i + 1); - wrapper.var.name = this.get_unique_name(wrapper.var.name + i).name; + suffix = i; } + wrapper.var.name = this.get_unique_name(wrapper.var.name + suffix).name; } } diff --git a/test/js/samples/debug-no-dependencies/expected.js b/test/js/samples/debug-no-dependencies/expected.js index 2212f3e0bb..57a67e9ea9 100644 --- a/test/js/samples/debug-no-dependencies/expected.js +++ b/test/js/samples/debug-no-dependencies/expected.js @@ -60,7 +60,7 @@ function create_each_block(ctx) { } function create_fragment(ctx) { - let each_anchor; + let each_1_anchor; let each_value = things; let each_blocks = []; @@ -74,7 +74,7 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = empty(); + each_1_anchor = empty(); }, l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); @@ -84,7 +84,7 @@ function create_fragment(ctx) { each_blocks[i].m(target, anchor); } - insert_dev(target, each_anchor, anchor); + insert_dev(target, each_1_anchor, anchor); }, p: function update(changed, ctx) { if (changed.things) { @@ -99,7 +99,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_anchor.parentNode, each_anchor); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); } } @@ -114,7 +114,7 @@ function create_fragment(ctx) { o: noop, d: function destroy(detaching) { destroy_each(each_blocks, detaching); - if (detaching) detach_dev(each_anchor); + if (detaching) detach_dev(each_1_anchor); } }; diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 222d473201..194188ad4e 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -43,7 +43,7 @@ function create_each_block(ctx) { } function create_fragment(ctx) { - let each_anchor; + let each_1_anchor; let each_value = ctx.createElement; let each_blocks = []; @@ -57,14 +57,14 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = empty(); + each_1_anchor = empty(); }, m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { if (changed.createElement) { @@ -79,7 +79,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_anchor.parentNode, each_anchor); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); } } @@ -94,7 +94,7 @@ function create_fragment(ctx) { o: noop, d(detaching) { destroy_each(each_blocks, detaching); - if (detaching) detach(each_anchor); + if (detaching) detach(each_1_anchor); } }; } diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index 2eb1d903de..cd8e8b97c2 100644 --- a/test/js/samples/each-block-array-literal/expected.js +++ b/test/js/samples/each-block-array-literal/expected.js @@ -43,7 +43,7 @@ function create_each_block(ctx) { } function create_fragment(ctx) { - let each_anchor; + let each_1_anchor; let each_value = [ctx.a, ctx.b, ctx.c, ctx.d, ctx.e]; let each_blocks = []; @@ -57,14 +57,14 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = empty(); + each_1_anchor = empty(); }, m(target, anchor) { for (let i = 0; i < 5; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { if (changed.a || changed.b || changed.c || changed.d || changed.e) { @@ -79,7 +79,7 @@ function create_fragment(ctx) { } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); - each_blocks[i].m(each_anchor.parentNode, each_anchor); + each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor); } } @@ -92,7 +92,7 @@ function create_fragment(ctx) { o: noop, d(detaching) { destroy_each(each_blocks, detaching); - if (detaching) detach(each_anchor); + if (detaching) detach(each_1_anchor); } }; } diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index e2e8357805..02022d7d67 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -63,15 +63,15 @@ function create_each_block(key_1, ctx) { function create_fragment(ctx) { let each_blocks = []; - let each_lookup = new Map(); - let each_anchor; + let each_1_lookup = new Map(); + let each_1_anchor; let each_value = ctx.things; const get_key = ctx => ctx.thing.id; for (let i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); } return { @@ -80,19 +80,19 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = empty(); + each_1_anchor = empty(); }, m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { const each_value = ctx.things; for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r(); - each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, fix_and_destroy_block, create_each_block, each_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, fix_and_destroy_block, create_each_block, each_1_anchor, get_each_context); for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a(); }, i: noop, @@ -102,7 +102,7 @@ function create_fragment(ctx) { each_blocks[i].d(detaching); } - if (detaching) detach(each_anchor); + if (detaching) detach(each_1_anchor); } }; } diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index 5e149826b8..050c499e01 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -48,15 +48,15 @@ function create_each_block(key_1, ctx) { function create_fragment(ctx) { let each_blocks = []; - let each_lookup = new Map(); - let each_anchor; + let each_1_lookup = new Map(); + let each_1_anchor; let each_value = ctx.things; const get_key = ctx => ctx.thing.id; for (let i = 0; i < each_value.length; i += 1) { let child_ctx = get_each_context(ctx, each_value, i); let key = get_key(child_ctx); - each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); } return { @@ -65,18 +65,18 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_anchor = empty(); + each_1_anchor = empty(); }, m(target, anchor) { for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(target, anchor); } - insert(target, each_anchor, anchor); + insert(target, each_1_anchor, anchor); }, p(changed, ctx) { const each_value = ctx.things; - each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, destroy_block, create_each_block, each_anchor, get_each_context); + each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block, each_1_anchor, get_each_context); }, i: noop, o: noop, @@ -85,7 +85,7 @@ function create_fragment(ctx) { each_blocks[i].d(detaching); } - if (detaching) detach(each_anchor); + if (detaching) detach(each_1_anchor); } }; } diff --git a/test/runtime/samples/deconflict-builtins-2/_config.js b/test/runtime/samples/deconflict-builtins-2/_config.js new file mode 100644 index 0000000000..5870ff073b --- /dev/null +++ b/test/runtime/samples/deconflict-builtins-2/_config.js @@ -0,0 +1,4 @@ +export default { + html: `hello world`, + preserveIdentifiers: true, +}; \ No newline at end of file diff --git a/test/runtime/samples/deconflict-builtins-2/main.svelte b/test/runtime/samples/deconflict-builtins-2/main.svelte new file mode 100644 index 0000000000..82f9213045 --- /dev/null +++ b/test/runtime/samples/deconflict-builtins-2/main.svelte @@ -0,0 +1,5 @@ + + +{foo} \ No newline at end of file From d976203da8d8feb41d870580aa1edc86c6ea5161 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 20 Oct 2019 22:42:59 -0400 Subject: [PATCH 074/413] update code-red etc (#3752) --- package-lock.json | 53 ++++++++----------------------- package.json | 6 ++-- src/compiler/parse/acorn.ts | 2 -- src/compiler/parse/read/script.ts | 2 +- 4 files changed, 17 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index 97fa374f9d..f1eb8739b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.12.1", + "version": "3.13.0-alpha.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -167,9 +167,9 @@ "dev": true }, "acorn": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", - "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", + "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", "dev": true }, "acorn-globals": { @@ -490,14 +490,14 @@ "dev": true }, "code-red": { - "version": "0.0.17", - "resolved": "https://registry.npmjs.org/code-red/-/code-red-0.0.17.tgz", - "integrity": "sha512-RJJ48sXYOqyd0J4QelF4dRdYb+4DaLV/jHs4mNoxOdLroUGB840cMc9pMtEAbGKjFFzoTKREypFzqphBD8knMg==", + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/code-red/-/code-red-0.0.18.tgz", + "integrity": "sha512-g7W6RwRqBbQTtMaUqrNWDyyl2GK0Uulk/uZPzGdgTXpOGX/LA8bW67EKQLdQgpYfd6APhZVwoX2lrL7mnJOWkA==", "dev": true, "requires": { - "acorn": "^7.0.0", - "is-reference": "^1.1.3", - "periscopic": "^1.0.1", + "acorn": "^7.1.0", + "is-reference": "^1.1.4", + "periscopic": "^1.0.2", "sourcemap-codec": "^1.4.6" } }, @@ -1147,14 +1147,6 @@ "acorn": "^7.0.0", "acorn-jsx": "^5.0.2", "eslint-visitor-keys": "^1.1.0" - }, - "dependencies": { - "acorn": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", - "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", - "dev": true - } } }, "esprima": { @@ -1768,9 +1760,9 @@ "dev": true }, "is-reference": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.3.tgz", - "integrity": "sha512-W1iHHv/oyBb2pPxkBxtaewxa1BC58Pn5J0hogyCdefwUIvb6R+TGbAcIa4qPNYLqLhb3EnOgUf2MQkkF76BcKw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", + "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", "dev": true, "requires": { "@types/estree": "0.0.39" @@ -2727,17 +2719,6 @@ "dev": true, "requires": { "is-reference": "^1.1.4" - }, - "dependencies": { - "is-reference": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", - "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", - "dev": true, - "requires": { - "@types/estree": "0.0.39" - } - } } }, "pify": { @@ -3646,14 +3627,6 @@ "@types/istanbul-lib-coverage": "^2.0.1", "convert-source-map": "^1.6.0", "source-map": "^0.7.3" - }, - "dependencies": { - "source-map": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", - "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", - "dev": true - } } }, "validate-npm-package-license": { diff --git a/package.json b/package.json index c4f1269139..0cdc30eccb 100644 --- a/package.json +++ b/package.json @@ -60,17 +60,17 @@ "@types/node": "^8.10.53", "@typescript-eslint/eslint-plugin": "^1.13.0", "@typescript-eslint/parser": "^2.1.0", - "acorn": "^7.0.0", + "acorn": "^7.1.0", "agadoo": "^1.1.0", "c8": "^5.0.1", - "code-red": "0.0.17", + "code-red": "0.0.18", "codecov": "^3.5.0", "css-tree": "1.0.0-alpha22", "eslint": "^6.3.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-svelte3": "^2.7.3", "estree-walker": "^0.8.1", - "is-reference": "^1.1.3", + "is-reference": "^1.1.4", "jsdom": "^15.1.1", "kleur": "^3.0.3", "locate-character": "^2.0.5", diff --git a/src/compiler/parse/acorn.ts b/src/compiler/parse/acorn.ts index a7d2703956..30ab3c398c 100644 --- a/src/compiler/parse/acorn.ts +++ b/src/compiler/parse/acorn.ts @@ -4,13 +4,11 @@ const Parser = acorn.Parser; export const parse = (source: string) => Parser.parse(source, { sourceType: 'module', - // @ts-ignore TODO pending release of fixed types ecmaVersion: 11, locations: true }); export const parse_expression_at = (source: string, index: number) => Parser.parseExpressionAt(source, index, { - // @ts-ignore TODO pending release of fixed types ecmaVersion: 11, locations: true }); \ No newline at end of file diff --git a/src/compiler/parse/read/script.ts b/src/compiler/parse/read/script.ts index efc9306677..0c416be6e8 100644 --- a/src/compiler/parse/read/script.ts +++ b/src/compiler/parse/read/script.ts @@ -45,7 +45,7 @@ export default function read_script(parser: Parser, start: number, attributes: N let ast: Program; try { - ast = acorn.parse(source); + ast = acorn.parse(source) as any as Program; } catch (err) { parser.acorn_error(err); } From ebf7a9024a47a5dd40a9e43c6c589bb6c1ffa449 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 21 Oct 2019 11:21:54 -0400 Subject: [PATCH 075/413] alpha.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f1eb8739b5..1ca8b7cdb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.13.0-alpha.0", + "version": "3.13.0-alpha.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0cdc30eccb..950c44d965 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.13.0-alpha.0", + "version": "3.13.0-alpha.1", "description": "Cybernetically enhanced web apps", "module": "index.mjs", "main": "index", From 714508ccc549ab5790eefaa59502d173619cf7c8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 21 Oct 2019 15:33:19 -0400 Subject: [PATCH 076/413] allow spring/tweened values to be initially undefined - closes #3761 --- src/runtime/motion/spring.ts | 4 ++-- src/runtime/motion/tweened.ts | 7 ++++++- test/motion/index.js | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/motion/index.js diff --git a/src/runtime/motion/spring.ts b/src/runtime/motion/spring.ts index 7742dd4106..20fa6ffcde 100644 --- a/src/runtime/motion/spring.ts +++ b/src/runtime/motion/spring.ts @@ -65,7 +65,7 @@ interface Spring extends Readable{ stiffness: number; } -export function spring(value: T, opts: SpringOpts = {}): Spring { +export function spring(value?: T, opts: SpringOpts = {}): Spring { const store = writable(value); const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts; @@ -84,7 +84,7 @@ export function spring(value: T, opts: SpringOpts = {}): Spring { target_value = new_value; const token = current_token = {}; - if (opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) { + if (value == null || opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) { cancel_task = true; // cancel any running animation last_time = now(); last_value = value; diff --git a/src/runtime/motion/tweened.ts b/src/runtime/motion/tweened.ts index 7159c17eb5..e33f0f79f9 100644 --- a/src/runtime/motion/tweened.ts +++ b/src/runtime/motion/tweened.ts @@ -69,13 +69,18 @@ interface Tweened extends Readable { update(updater: Updater, opts: Options): Promise; } -export function tweened(value: T, defaults: Options = {}): Tweened { +export function tweened(value?: T, defaults: Options = {}): Tweened { const store = writable(value); let task: Task; let target_value = value; function set(new_value: T, opts: Options) { + if (value == null) { + store.set(value = new_value); + return Promise.resolve(); + } + target_value = new_value; let previous_task = task; diff --git a/test/motion/index.js b/test/motion/index.js new file mode 100644 index 0000000000..33489b18e1 --- /dev/null +++ b/test/motion/index.js @@ -0,0 +1,23 @@ +import * as assert from 'assert'; +import { get } from '../../store'; +import { spring, tweened } from '../../motion'; + +describe('motion', () => { + describe('spring', () => { + it('handles initially undefined values', () => { + const size = spring(); + + size.set(100); + assert.equal(get(size), 100); + }); + }); + + describe('tweened', () => { + it('handles initially undefined values', () => { + const size = tweened(); + + size.set(100); + assert.equal(get(size), 100); + }); + }); +}); From 488d06860d0788afb2ef180f2de35501e98f4b2e Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 22 Oct 2019 09:22:58 +0800 Subject: [PATCH 077/413] Adding contributing.md --- CONTRIBUTING.md | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..d698d02cd2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,128 @@ +# Contributing to Svelte + +Svelte is a new way to build web applications. It's a compiler that takes your declarative components and converts them into efficient JavaScript that surgically updates the DOM. + +The [Open Source Guides](https://opensource.guide/) website has a collection of resources for individuals, communities, and companies who want to learn how to run and contribute to an open source project. Contributors and people new to open source alike will find the following guides especially useful: + +* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) +* [Building Welcoming Communities](https://opensource.guide/building-community/) + +## Get Involved + +There are many ways to contribute to Svelte, and many of them do not involve writing any code. Here's a few ideas to get started: + +- Simply start using Svelte. Go through the [Getting Started](https://svelte.dev/blog/the-easiest-way-to-get-started) guide. Does everything work as expected? If not, we're always looking for improvements. Let us know by [opening an issue](#reporting-new-issues). +- Look through the [open issues](https://github.com/sveltejs/svelte/issues). Provide workarounds, ask for clarification, or suggest labels. Help [triage issues](#triaging-issues-and-pull-requests). +- If you find an issue you would like to fix, [open a pull request](#your-first-pull-request). +- Read through our amazing [Tutorials](https://svelte.dev/tutorial/basics). If you find anything that is confusing or can be improved, you can make edits by clicking "Edit this chapter" at the bottom left of the tutorials. +- Take a look at the [features requested](https://github.com/sveltejs/svelte/labels/enhancement) by others in the community and consider opening a pull request if you see something you want to work on. + +Contributions are very welcome. If you think you need help planning your contribution, please ping us on Twitter at [@sveltejs](https://twitter.com/sveltejs) and let us know you are looking for a bit of help. + +### Triaging Issues and Pull Requests + +One great way you can contribute to the project without writing any code is to help triage issues and pull requests as they come in. + +- Ask for more information if you believe the issue does not provide all the details required to solve it. +- Suggest [labels](https://github.com/sveltejs/svelte/labels) that can help categorize issues. +- Flag issues that are stale or that should be closed. +- Ask for test plans and review code. + +## Bugs + +We use [GitHub Issues](https://github.com/sveltejs/svelte/issues) for our public bugs. If you would like to report a problem, take a look around and see if someone already opened an issue about it. If you a are certain this is a new, unreported bug, you can submit a [bug report](#reporting-new-issues). + +If you have questions about using Svelte, contact the Svelte Twitter account at [@sveltejs](https://twitter.com/sveltejs), and we will do our best to answer your questions. + +If you see anything you'd like to be implemented, create a [feature request issue](https://github.com/sveltejs/svelte/issues/new?template=feature_request.md) + +## Reporting New Issues + +When [opening a new issue](https://github.com/sveltejs/svelte/issues/new/choose), always make sure to fill out the issue template. **This step is very important!** Not doing so may result in your issue not managed in a timely fashion. Don't take this personally if this happens, and feel free to open a new issue once you've gathered all the information required by the template. + +- **One issue, one bug:** Please report a single bug per issue. +- **Provide reproduction steps:** List all the steps necessary to reproduce the issue. The person reading your bug report should be able to follow these steps to reproduce your issue with minimal effort. + +## Installation + +1. Ensure you have [npm](https://www.npmjs.com/get-npm) installed. +1. After cloning the repository, run `npm install` in the root of the repository. +1. To start a development server, run `npm run dev`. + + +## Pull Requests + +### Your First Pull Request + +So you have decided to contribute code back to upstream by opening a pull request. You've invested a good chunk of time, and we appreciate it. We will do our best to work with you and get the PR looked at. + +Working on your first Pull Request? You can learn how from this free video series: + +[**How to Contribute to an Open Source Project on GitHub**](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) + +### Proposing a Change + +If you would like to request a new feature or enhancement but are not yet thinking about opening a pull request, you can also file an issue with [feature template](https://github.com/sveltejs/svelte/issues/new?template=feature_request.md). + +If you're only fixing a bug, it's fine to submit a pull request right away but we still recommend to file an issue detailing what you're fixing. This is helpful in case we don't accept that specific fix but want to keep track of the issue. + +### Sending a Pull Request + +Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. + +Please make sure the following is done when submitting a pull request: + +1. Fork [the repository](https://github.com/sveltejs/svelte) and create your branch from `master`. +1. Describe your **test plan** in your pull request description. Make sure to test your changes. +1. Make sure your code lints (`npm run lint`). +1. Make sure your tests pass (`npm run test`). + +All pull requests should be opened against the `master` branch. + +#### Test Plan + +A good test plan has the exact commands you ran and their output, provides screenshots or videos if the pull request changes UI. + +- If you've changed APIs, update the documentation. + +#### Writing Tests + +All tests are located in `/test` folder. + +Tests samples are kept in `/test/xxx/samples` folder. + +#### Running Tests + +1. To run test, run `npm run test` +1. To run test for a specific feature, you can use the `-g` (aka `--grep`) option. For example, to only run test invloving transitions, run `npm run test -- -g transition`. +1. To run only 1 test sample, append the `.solo` to the test sample folder name, for example, `test/runtime/samples/action.solo`. + +#### Breaking Changes + +When adding a new breaking change, follow this template in your pull request: + +```md +### New breaking change here + +- **Who does this affect**: +- **How to migrate**: +- **Why make this breaking change**: +- **Severity (number of people affected x effort)**: +``` + +### What Happens Next? + +The core Svelte team will be monitoring for pull requests. Do help us by making your pull request easy to review by following the guidelines above. + +## Style Guide + +[Eslint](https://eslint.org) will catch most styling issues that may exist in your code. You can check the status of your code styling by simply running `npm run lint`. + +### Code Conventions + +- `snake_case` for internal variable names and methods +- `camelCase` for public variable names and methods. + +## License + +By contributing to Svelte, you agree that your contributions will be licensed under its [MIT license](https://github.com/sveltejs/svelte/blob/master/LICENSE). \ No newline at end of file From 614393edcba4806300d0601919e8b70d5b81be68 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 22 Oct 2019 09:17:23 -0400 Subject: [PATCH 078/413] add sigil-expression-function-body test against regression (#3756) --- test/runtime/samples/sigil-expression-function-body/_config.js | 3 +++ .../runtime/samples/sigil-expression-function-body/main.svelte | 1 + 2 files changed, 4 insertions(+) create mode 100644 test/runtime/samples/sigil-expression-function-body/_config.js create mode 100644 test/runtime/samples/sigil-expression-function-body/main.svelte diff --git a/test/runtime/samples/sigil-expression-function-body/_config.js b/test/runtime/samples/sigil-expression-function-body/_config.js new file mode 100644 index 0000000000..fccd0db2d0 --- /dev/null +++ b/test/runtime/samples/sigil-expression-function-body/_config.js @@ -0,0 +1,3 @@ +export default { + html: `@foo` +}; diff --git a/test/runtime/samples/sigil-expression-function-body/main.svelte b/test/runtime/samples/sigil-expression-function-body/main.svelte new file mode 100644 index 0000000000..074496d6f4 --- /dev/null +++ b/test/runtime/samples/sigil-expression-function-body/main.svelte @@ -0,0 +1 @@ +{(() => '@foo')()} From d91e9afab6fbaf85d0263111ce4b64932b7e5e09 Mon Sep 17 00:00:00 2001 From: Paul Murray Date: Tue, 22 Oct 2019 16:45:43 -0400 Subject: [PATCH 079/413] Fixes #3008: Better SSR docs --- site/content/docs/03-run-time.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 551945eade..fd709dd9d5 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -1019,8 +1019,12 @@ Unlike client-side components, server-side components don't have a lifespan afte A server-side component exposes a `render` method that can be called with optional props. It returns an object with `head`, `html`, and `css` properties, where `head` contains the contents of any `` elements encountered. +You can import a Svelte component directly into Node using [`svelte/register`](docs#svelte_register). + ```js -const App = require('./App.svelte'); +require('svelte/register'); + +const App = require('./App.svelte').default; const { head, html, css } = App.render({ answer: 42 From f68b3a3b8c7bd3e023a3576f6f6a7ac84580267f Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 23 Oct 2019 12:43:20 -0400 Subject: [PATCH 080/413] Fix boolean attributes in presence of spread attributes (#3775) * add failing tests * fix boolean attributes along with spreads (DOM mode) * fix boolean attributes along with spreads (SSR mode) * update changelog (#3764) * fix removing attributes in spreads --- CHANGELOG.md | 1 + src/compiler/compile/nodes/Attribute.ts | 2 +- .../render_dom/wrappers/Element/Attribute.ts | 11 +++++-- .../render_dom/wrappers/Element/index.ts | 20 ++++++------ .../compile/render_ssr/handlers/Element.ts | 32 +++++++++---------- src/runtime/internal/dom.ts | 4 ++- src/runtime/internal/ssr.ts | 2 +- .../_config.js | 3 ++ .../main.svelte | 1 + .../attribute-boolean-with-spread/_config.js | 3 ++ .../attribute-boolean-with-spread/main.svelte | 1 + .../samples/spread-element-removal/_config.js | 3 ++ .../spread-element-removal/main.svelte | 1 + 13 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 test/runtime/samples/attribute-boolean-case-insensitive/_config.js create mode 100644 test/runtime/samples/attribute-boolean-case-insensitive/main.svelte create mode 100644 test/runtime/samples/attribute-boolean-with-spread/_config.js create mode 100644 test/runtime/samples/attribute-boolean-with-spread/main.svelte create mode 100644 test/runtime/samples/spread-element-removal/_config.js create mode 100644 test/runtime/samples/spread-element-removal/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index e39b8b4972..31fc1eddd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) * Fix globals shadowing contextual template scope ([#3674](https://github.com/sveltejs/svelte/issues/3674)) * Fix error resulting from trying to set a read-only property when spreading element attributes ([#3681](https://github.com/sveltejs/svelte/issues/3681)) +* Fix handling of boolean attributes in presence of other spread attributes ([#3764](https://github.com/sveltejs/svelte/issues/3764)) ## 3.12.1 diff --git a/src/compiler/compile/nodes/Attribute.ts b/src/compiler/compile/nodes/Attribute.ts index c09f9c3074..97d2fd7b2e 100644 --- a/src/compiler/compile/nodes/Attribute.ts +++ b/src/compiler/compile/nodes/Attribute.ts @@ -9,7 +9,7 @@ import TemplateScope from './shared/TemplateScope'; import { x } from 'code-red'; export default class Attribute extends Node { - type: 'Attribute'; + type: 'Attribute' | 'Spread'; start: number; end: number; scope: TemplateScope; diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index d2def7e5cf..2cd284108c 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -44,9 +44,7 @@ export default class AttributeWrapper { const element = this.parent; const name = fix_attribute_casing(this.node.name); - let metadata = element.node.namespace ? null : attribute_lookup[name]; - if (metadata && metadata.applies_to && !~metadata.applies_to.indexOf(element.node.name)) - metadata = null; + const metadata = this.get_metadata(); const is_indirectly_bound_value = name === 'value' && @@ -193,6 +191,13 @@ export default class AttributeWrapper { } } + get_metadata() { + if (this.parent.node.namespace) return null; + const metadata = attribute_lookup[fix_attribute_casing(this.node.name)]; + if (metadata && metadata.applies_to && !metadata.applies_to.includes(this.parent.node.name)) return null; + return metadata; + } + get_class_name_text() { const scoped_css = this.node.chunks.some((chunk: Text) => chunk.synthetic); const rendered = this.render_chunks(); diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index d7c1c7686b..bb4c2d310a 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -573,8 +573,7 @@ export default class ElementWrapper extends Wrapper { } }); - // @ts-ignore todo: - if (this.node.attributes.find(attr => attr.type === 'Spread')) { + if (this.node.attributes.some(attr => attr.is_spread)) { this.add_spread_attributes(block); return; } @@ -591,21 +590,24 @@ export default class ElementWrapper extends Wrapper { const initial_props = []; const updates = []; - this.node.attributes - .filter(attr => attr.type === 'Attribute' || attr.type === 'Spread') + this.attributes .forEach(attr => { - const condition = attr.dependencies.size > 0 - ? changed(Array.from(attr.dependencies)) + const condition = attr.node.dependencies.size > 0 + ? changed(Array.from(attr.node.dependencies)) : null; - if (attr.is_spread) { - const snippet = attr.expression.manipulate(block); + if (attr.node.is_spread) { + const snippet = attr.node.expression.manipulate(block); initial_props.push(snippet); updates.push(condition ? x`${condition} && ${snippet}` : snippet); } else { - const snippet = x`{ ${attr.name}: ${attr.get_value(block)} }`; + const metadata = attr.get_metadata(); + const snippet = x`{ ${ + (metadata && metadata.property_name) || + fix_attribute_casing(attr.node.name) + }: ${attr.node.get_value(block)} }`; initial_props.push(snippet); updates.push(condition ? x`${condition} && ${snippet}` : snippet); diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index 762152f4d5..1f7c0b7b9f 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -1,5 +1,4 @@ import { is_void } from '../../../utils/names'; -import Attribute from '../../nodes/Attribute'; import Class from '../../nodes/Class'; import { get_attribute_value, get_class_attribute_value } from './shared/get_attribute_value'; import { get_slot_scope } from './shared/get_slot_scope'; @@ -80,62 +79,61 @@ export default function(node: Element, renderer: Renderer, options: RenderOption let add_class_attribute = class_expression ? true : false; - if (node.attributes.find(attr => attr.is_spread)) { + if (node.attributes.some(attr => attr.is_spread)) { // TODO dry this out const args = []; node.attributes.forEach(attribute => { if (attribute.is_spread) { args.push(attribute.expression.node); } else { - if (attribute.name === 'value' && node.name === 'textarea') { + const name = attribute.name.toLowerCase(); + if (name === 'value' && node.name.toLowerCase() === 'textarea') { node_contents = get_attribute_value(attribute); } else if (attribute.is_true) { args.push(x`{ ${attribute.name}: true }`); } else if ( - boolean_attributes.has(attribute.name) && + boolean_attributes.has(name) && attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text' ) { // a boolean attribute with one non-Text chunk - args.push(x`{ ${attribute.name}: ${(attribute.chunks[0] as Expression).node} }`); - } else if (attribute.name === 'class' && class_expression) { + args.push(x`{ ${attribute.name}: ${(attribute.chunks[0] as Expression).node} || null }`); + } else if (name === 'class' && class_expression) { // Add class expression args.push(x`{ ${attribute.name}: [${get_class_attribute_value(attribute)}, ${class_expression}].join(' ').trim() }`); } else { - args.push(x`{ ${attribute.name}: ${attribute.name === 'class' ? get_class_attribute_value(attribute) : get_attribute_value(attribute)} }`); + args.push(x`{ ${attribute.name}: ${(name === 'class' ? get_class_attribute_value : get_attribute_value)(attribute)} }`); } } }); renderer.add_expression(x`@spread([${args}])`); } else { - node.attributes.forEach((attribute: Attribute) => { - if (attribute.type !== 'Attribute') return; - - if (attribute.name === 'value' && node.name === 'textarea') { + node.attributes.forEach(attribute => { + const name = attribute.name.toLowerCase(); + if (name === 'value' && node.name.toLowerCase() === 'textarea') { node_contents = get_attribute_value(attribute); } else if (attribute.is_true) { renderer.add_string(` ${attribute.name}`); } else if ( - boolean_attributes.has(attribute.name) && + boolean_attributes.has(name) && attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text' ) { // a boolean attribute with one non-Text chunk renderer.add_string(` `); renderer.add_expression(x`${(attribute.chunks[0] as Expression).node} ? "${attribute.name}" : ""`); - } else if (attribute.name === 'class' && class_expression) { + } else if (name === 'class' && class_expression) { add_class_attribute = false; - renderer.add_string(` class="`); + renderer.add_string(` ${attribute.name}="`); renderer.add_expression(x`[${get_class_attribute_value(attribute)}, ${class_expression}].join(' ').trim()`); renderer.add_string(`"`); } else if (attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text') { - const { name } = attribute; const snippet = (attribute.chunks[0] as Expression).node; - renderer.add_expression(x`@add_attribute("${name}", ${snippet}, ${boolean_attributes.has(name) ? 1 : 0})`); + renderer.add_expression(x`@add_attribute("${attribute.name}", ${snippet}, ${boolean_attributes.has(name) ? 1 : 0})`); } else { renderer.add_string(` ${attribute.name}="`); - renderer.add_expression(attribute.name === 'class' ? get_class_attribute_value(attribute) : get_attribute_value(attribute)); + renderer.add_expression((name === 'class' ? get_class_attribute_value : get_attribute_value)(attribute)); renderer.add_string(`"`); } }); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 481fb7d74a..c60f437863 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -93,7 +93,9 @@ export function set_attributes(node: Element & ElementCSSInlineStyle, attributes // @ts-ignore const descriptors = Object.getOwnPropertyDescriptors(node.__proto__); for (const key in attributes) { - if (key === 'style') { + if (attributes[key] == null) { + node.removeAttribute(key); + } else if (key === 'style') { node.style.cssText = attributes[key]; } else if (descriptors[key] && descriptors[key].set) { node[key] = attributes[key]; diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index d8fbf15f0a..208a4637c7 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -13,7 +13,7 @@ export function spread(args) { if (invalid_attribute_name_character.test(name)) return; const value = attributes[name]; - if (value === undefined) return; + if (value == null) return; if (value === true) str += " " + name; const escaped = String(value) diff --git a/test/runtime/samples/attribute-boolean-case-insensitive/_config.js b/test/runtime/samples/attribute-boolean-case-insensitive/_config.js new file mode 100644 index 0000000000..16e5ade6d2 --- /dev/null +++ b/test/runtime/samples/attribute-boolean-case-insensitive/_config.js @@ -0,0 +1,3 @@ +export default { + html: `` +}; diff --git a/test/runtime/samples/attribute-boolean-case-insensitive/main.svelte b/test/runtime/samples/attribute-boolean-case-insensitive/main.svelte new file mode 100644 index 0000000000..9020894086 --- /dev/null +++ b/test/runtime/samples/attribute-boolean-case-insensitive/main.svelte @@ -0,0 +1 @@ + diff --git a/test/runtime/samples/attribute-boolean-with-spread/_config.js b/test/runtime/samples/attribute-boolean-with-spread/_config.js new file mode 100644 index 0000000000..270804170d --- /dev/null +++ b/test/runtime/samples/attribute-boolean-with-spread/_config.js @@ -0,0 +1,3 @@ +export default { + html: `` +}; diff --git a/test/runtime/samples/attribute-boolean-with-spread/main.svelte b/test/runtime/samples/attribute-boolean-with-spread/main.svelte new file mode 100644 index 0000000000..d0616e3024 --- /dev/null +++ b/test/runtime/samples/attribute-boolean-with-spread/main.svelte @@ -0,0 +1 @@ + diff --git a/test/runtime/samples/spread-element-removal/_config.js b/test/runtime/samples/spread-element-removal/_config.js new file mode 100644 index 0000000000..270804170d --- /dev/null +++ b/test/runtime/samples/spread-element-removal/_config.js @@ -0,0 +1,3 @@ +export default { + html: `` +}; diff --git a/test/runtime/samples/spread-element-removal/main.svelte b/test/runtime/samples/spread-element-removal/main.svelte new file mode 100644 index 0000000000..f6adc82c80 --- /dev/null +++ b/test/runtime/samples/spread-element-removal/main.svelte @@ -0,0 +1 @@ + From 5dbb08d19b9ec85b49cc90f0a091a5638ee33631 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 24 Oct 2019 02:52:49 +0800 Subject: [PATCH 081/413] allow solo for test suite (#3747) --- test/css/index.js | 12 ++++++------ test/custom-elements/index.js | 6 +++--- test/hydration/index.js | 4 ++-- test/js/index.js | 4 ++-- test/parser/index.js | 12 ++++++------ test/preprocess/index.js | 10 +++++----- test/runtime/index.js | 6 +++--- test/server-side-rendering/index.js | 4 ++-- test/sourcemaps/index.js | 6 +++--- test/stats/index.js | 8 ++++---- test/test.js | 17 ++++++++++++++--- test/validator/index.js | 10 +++++----- test/vars/index.js | 8 ++++---- 13 files changed, 59 insertions(+), 48 deletions(-) diff --git a/test/css/index.js b/test/css/index.js index 61e8a0c6cb..1f90d243be 100644 --- a/test/css/index.js +++ b/test/css/index.js @@ -37,7 +37,7 @@ function create(code) { } describe('css', () => { - fs.readdirSync('test/css/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -51,7 +51,7 @@ describe('css', () => { (solo ? it.only : skip ? it.skip : it)(dir, () => { const config = try_require(`./samples/${dir}/_config.js`) || {}; const input = fs - .readFileSync(`test/css/samples/${dir}/input.svelte`, 'utf-8') + .readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8') .replace(/\s+$/, ''); const expected_warnings = (config.warnings || []).map(normalize_warning); @@ -74,10 +74,10 @@ describe('css', () => { assert.deepEqual(dom_warnings, ssr_warnings); assert.deepEqual(dom_warnings.map(normalize_warning), expected_warnings); - fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css.code); + fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.css`, dom.css.code); const expected = { - html: read(`test/css/samples/${dir}/expected.html`), - css: read(`test/css/samples/${dir}/expected.css`) + html: read(`${__dirname}/samples/${dir}/expected.html`), + css: read(`${__dirname}/samples/${dir}/expected.css`) }; assert.equal(dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'), expected.css); @@ -112,7 +112,7 @@ describe('css', () => { new ClientComponent({ target, props: config.props }); const html = target.innerHTML; - fs.writeFileSync(`test/css/samples/${dir}/_actual.html`, html); + fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.html`, html); assert.equal( normalizeHtml(window, html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz')), diff --git a/test/custom-elements/index.js b/test/custom-elements/index.js index 7fe47f2ecd..5d2847bfab 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.js @@ -14,7 +14,7 @@ const page = ` `; -const assert = fs.readFileSync('test/custom-elements/assert.js', 'utf-8'); +const assert = fs.readFileSync(`${__dirname}/assert.js`, 'utf-8'); describe('custom-elements', function() { this.timeout(10000); @@ -53,7 +53,7 @@ describe('custom-elements', function() { await browser.close(); }); - fs.readdirSync('test/custom-elements/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; const solo = /\.solo$/.test(dir); @@ -67,7 +67,7 @@ describe('custom-elements', function() { const expected_warnings = config.warnings || []; const bundle = await rollup({ - input: `test/custom-elements/samples/${dir}/test.js`, + input: `${__dirname}/samples/${dir}/test.js`, plugins: [ { resolveId(importee) { diff --git a/test/hydration/index.js b/test/hydration/index.js index 856052d69e..fda799ef2d 100644 --- a/test/hydration/index.js +++ b/test/hydration/index.js @@ -47,7 +47,7 @@ describe('hydration', () => { } (config.skip ? it.skip : config.solo ? it.only : it)(dir, () => { - const cwd = path.resolve(`test/hydration/samples/${dir}`); + const cwd = path.resolve(`${__dirname}/samples/${dir}`); compileOptions = config.compileOptions || {}; @@ -96,7 +96,7 @@ describe('hydration', () => { }); } - fs.readdirSync('test/hydration/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { runTest(dir, null); }); }); diff --git a/test/js/index.js b/test/js/index.js index 14d73d6c65..5fd632d606 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -4,7 +4,7 @@ import * as path from "path"; import { loadConfig, svelte } from "../helpers.js"; describe("js", () => { - fs.readdirSync("test/js/samples").forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === ".") return; // add .solo to a sample directory name to only run that test @@ -15,7 +15,7 @@ describe("js", () => { } (solo ? it.only : it)(dir, () => { - dir = path.resolve("test/js/samples", dir); + dir = path.resolve(`${__dirname}/samples`, dir); const config = loadConfig(`${dir}/_config.js`); const input = fs.readFileSync(`${dir}/input.svelte`, "utf-8").replace(/\s+$/, ""); diff --git a/test/parser/index.js b/test/parser/index.js index 990a8751ef..0188fac431 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -3,7 +3,7 @@ import * as fs from 'fs'; import { svelte, tryToLoadJson } from '../helpers.js'; describe('parse', () => { - fs.readdirSync('test/parser/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -16,18 +16,18 @@ describe('parse', () => { } (solo ? it.only : it)(dir, () => { - const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {}; + const options = tryToLoadJson(`${__dirname}/samples/${dir}/options.json`) || {}; - const input = fs.readFileSync(`test/parser/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, ''); - const expectedOutput = tryToLoadJson(`test/parser/samples/${dir}/output.json`); - const expectedError = tryToLoadJson(`test/parser/samples/${dir}/error.json`); + const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, ''); + const expectedOutput = tryToLoadJson(`${__dirname}/samples/${dir}/output.json`); + const expectedError = tryToLoadJson(`${__dirname}/samples/${dir}/error.json`); try { const { ast } = svelte.compile(input, Object.assign(options, { generate: false })); - fs.writeFileSync(`test/parser/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t')); + fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t')); assert.deepEqual(ast.html, expectedOutput.html); assert.deepEqual(ast.css, expectedOutput.css); diff --git a/test/preprocess/index.js b/test/preprocess/index.js index 8d114ab7b3..ea24645295 100644 --- a/test/preprocess/index.js +++ b/test/preprocess/index.js @@ -3,21 +3,21 @@ import * as assert from 'assert'; import { loadConfig, svelte } from '../helpers.js'; describe('preprocess', () => { - fs.readdirSync('test/preprocess/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; - const config = loadConfig(`./preprocess/samples/${dir}/_config.js`); + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); if (config.solo && process.env.CI) { throw new Error('Forgot to remove `solo: true` from test'); } (config.skip ? it.skip : config.solo ? it.only : it)(dir, async () => { - const input = fs.readFileSync(`test/preprocess/samples/${dir}/input.svelte`, 'utf-8'); - const expected = fs.readFileSync(`test/preprocess/samples/${dir}/output.svelte`, 'utf-8'); + const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8'); + const expected = fs.readFileSync(`${__dirname}/samples/${dir}/output.svelte`, 'utf-8'); const result = await svelte.preprocess(input, config.preprocess); - fs.writeFileSync(`test/preprocess/samples/${dir}/_actual.html`, result.code); + fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.html`, result.code); assert.equal(result.code, expected); diff --git a/test/runtime/index.js b/test/runtime/index.js index 1480e058a3..397cfef172 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -49,7 +49,7 @@ describe("runtime", () => { function runTest(dir, hydrate) { if (dir[0] === ".") return; - const config = loadConfig(`./runtime/samples/${dir}/_config.js`); + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); if (hydrate && config.skip_if_hydrate) return; @@ -67,7 +67,7 @@ describe("runtime", () => { compile = (config.preserveIdentifiers ? svelte : svelte$).compile; - const cwd = path.resolve(`test/runtime/samples/${dir}`); + const cwd = path.resolve(`${__dirname}/samples/${dir}`); compileOptions = config.compileOptions || {}; compileOptions.format = 'cjs'; @@ -215,7 +215,7 @@ describe("runtime", () => { }); } - fs.readdirSync("test/runtime/samples").forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { runTest(dir, false); runTest(dir, true); }); diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.js index 1097486124..0a4b6f7496 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.js @@ -30,7 +30,7 @@ describe("ssr", () => { return setupHtmlEqual(); }); - fs.readdirSync("test/server-side-rendering/samples").forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === ".") return; // add .solo to a sample directory name to only run that test, or @@ -43,7 +43,7 @@ describe("ssr", () => { } (solo ? it.only : it)(dir, () => { - dir = path.resolve("test/server-side-rendering/samples", dir); + dir = path.resolve(`${__dirname}/samples`, dir); try { const Component = require(`${dir}/main.svelte`).default; diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.js index e5915780c6..0b0424a764 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.js @@ -6,7 +6,7 @@ import { SourceMapConsumer } from "source-map"; import { getLocator } from "locate-character"; describe("sourcemaps", () => { - fs.readdirSync("test/sourcemaps/samples").forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === ".") return; // add .solo to a sample directory name to only run that test @@ -19,10 +19,10 @@ describe("sourcemaps", () => { (solo ? it.only : skip ? it.skip : it)(dir, async () => { const filename = path.resolve( - `test/sourcemaps/samples/${dir}/input.svelte` + `${__dirname}/samples/${dir}/input.svelte` ); const outputFilename = path.resolve( - `test/sourcemaps/samples/${dir}/output` + `${__dirname}/samples/${dir}/output` ); const input = fs.readFileSync(filename, "utf-8").replace(/\s+$/, ""); diff --git a/test/stats/index.js b/test/stats/index.js index aafc58c926..acea7a4663 100644 --- a/test/stats/index.js +++ b/test/stats/index.js @@ -3,7 +3,7 @@ import * as assert from 'assert'; import { svelte, loadConfig, tryToLoadJson } from '../helpers.js'; describe('stats', () => { - fs.readdirSync('test/stats/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -15,12 +15,12 @@ describe('stats', () => { } (solo ? it.only : skip ? it.skip : it)(dir, () => { - const config = loadConfig(`./stats/samples/${dir}/_config.js`); - const filename = `test/stats/samples/${dir}/input.svelte`; + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); + const filename = `${__dirname}/samples/${dir}/input.svelte`; const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, ''); const expectedError = tryToLoadJson( - `test/stats/samples/${dir}/error.json` + `${__dirname}/samples/${dir}/error.json` ); let result; diff --git a/test/test.js b/test/test.js index 9480ae7836..df6585f7da 100644 --- a/test/test.js +++ b/test/test.js @@ -8,6 +8,17 @@ require('../internal'); console.clear(); -glob('*/index.js', { cwd: 'test' }).forEach((file) => { - require('./' + file); -}); +const testFolders = glob('*/index.js', { cwd: 'test' }); +const solo = testFolders.find(folder => /\.solo/.test(folder)); + +if (solo) { + if (process.env.CI) { + throw new Error('Forgot to remove `solo: true` from test'); + } + require('./' + solo); +} else { + testFolders.forEach(file => { + console.log('file', file); + require('./' + file); + }); +} diff --git a/test/validator/index.js b/test/validator/index.js index 1e54cc20db..9f991df4f2 100644 --- a/test/validator/index.js +++ b/test/validator/index.js @@ -3,7 +3,7 @@ import * as assert from "assert"; import { svelte, loadConfig, tryToLoadJson } from "../helpers.js"; describe("validate", () => { - fs.readdirSync("test/validator/samples").forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === ".") return; // add .solo to a sample directory name to only run that test @@ -15,11 +15,11 @@ describe("validate", () => { } (solo ? it.only : skip ? it.skip : it)(dir, () => { - const config = loadConfig(`./validator/samples/${dir}/_config.js`); + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); - const input = fs.readFileSync(`test/validator/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, ""); - const expected_warnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || []; - const expected_errors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`); + const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, ""); + const expected_warnings = tryToLoadJson(`${__dirname}/samples/${dir}/warnings.json`) || []; + const expected_errors = tryToLoadJson(`${__dirname}/samples/${dir}/errors.json`); let error; diff --git a/test/vars/index.js b/test/vars/index.js index 66ffd94c70..a12ac177f2 100644 --- a/test/vars/index.js +++ b/test/vars/index.js @@ -3,7 +3,7 @@ import * as assert from 'assert'; import { svelte, loadConfig, tryToLoadJson } from '../helpers.js'; describe('vars', () => { - fs.readdirSync('test/vars/samples').forEach(dir => { + fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; // add .solo to a sample directory name to only run that test @@ -16,12 +16,12 @@ describe('vars', () => { for (const generate of ['dom', 'ssr', false]) { (solo ? it.only : skip ? it.skip : it)(`${dir}, generate: ${generate}`, () => { - const config = loadConfig(`./vars/samples/${dir}/_config.js`); - const filename = `test/vars/samples/${dir}/input.svelte`; + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); + const filename = `${__dirname}/samples/${dir}/input.svelte`; const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, ''); const expectedError = tryToLoadJson( - `test/vars/samples/${dir}/error.json` + `${__dirname}/samples/${dir}/error.json` ); let result; From 6d2d025d3b0b6fcdbca51a4e9131a244cba3a65e Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 23 Oct 2019 17:04:21 -0400 Subject: [PATCH 082/413] tidy up core test.js script --- test/test.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/test.js b/test/test.js index df6585f7da..6ea4bd60ab 100644 --- a/test/test.js +++ b/test/test.js @@ -8,17 +8,14 @@ require('../internal'); console.clear(); -const testFolders = glob('*/index.js', { cwd: 'test' }); -const solo = testFolders.find(folder => /\.solo/.test(folder)); +const test_folders = glob('*/index.js', { cwd: 'test' }); +const solo_folders = test_folders.filter(folder => /\.solo/.test(folder)); -if (solo) { +if (solo_folders.length) { if (process.env.CI) { - throw new Error('Forgot to remove `solo: true` from test'); + throw new Error('Forgot to remove `.solo` from test'); } - require('./' + solo); + solo_folders.forEach(name => require('./' + name)); } else { - testFolders.forEach(file => { - console.log('file', file); - require('./' + file); - }); + test_folders.forEach(name => require('./' + name)); } From 1f6e0eb316adb20804480b407f3cdf0986580245 Mon Sep 17 00:00:00 2001 From: mrkishi Date: Tue, 22 Oct 2019 23:00:57 -0300 Subject: [PATCH 083/413] improve derived store typing for users --- src/runtime/store/index.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index 0aff706a1b..64a63d4179 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -122,16 +122,30 @@ type StoresValues = T extends Readable ? U : /** * Derived value store by synchronizing one or more readable stores and * applying an aggregation function over its input values. - * @param {Stores} stores input stores - * @param {function(Stores=, function(*)=):*}fn function callback that aggregates the values - * @param {*=}initial_value when used asynchronously + * + * @param stores - input stores + * @param fn - function callback that aggregates the values */ -export function derived( +export function derived( stores: S, - fn: (values: StoresValues, set: Subscriber) => T | Unsubscriber | void, - initial_value?: T, -): Readable { + fn: (values: StoresValues) => T +): Readable; +/** + * Derived value store by synchronizing one or more readable stores and + * applying an aggregation function over its input values. + * + * @param stores - input stores + * @param fn - function callback that aggregates the values + * @param initial_value - when used asynchronously + */ +export function derived( + stores: S, + fn: (values: StoresValues, set: (value: T) => void) => Unsubscriber | void, + initial_value?: T +): Readable; + +export function derived(stores: Stores, fn: Function, initial_value?: T): Readable { const single = !Array.isArray(stores); const stores_array: Array> = single ? [stores as Readable] @@ -141,7 +155,7 @@ export function derived( return readable(initial_value, (set) => { let inited = false; - const values: StoresValues = [] as StoresValues; + const values = []; let pending = 0; let cleanup = noop; From cfd3b63b9bb87395b9725e676372cc090d3c66d1 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 24 Oct 2019 11:54:50 +0800 Subject: [PATCH 084/413] warn if using svelte:options tag without compile_options.customElement --- src/compiler/compile/Component.ts | 7 +++++++ .../input.svelte | 1 + .../warnings.json | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/validator/samples/missing-custom-element-compile-options/input.svelte create mode 100644 test/validator/samples/missing-custom-element-compile-options/warnings.json diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index b22b351da0..e76696c53d 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1307,6 +1307,13 @@ function process_component_options(component: Component, nodes) { }); } + if (tag && !component.compile_options.customElement) { + component.warn(attribute, { + code: 'missing-custom-element-compile-options', + message: `tag name is used when compiling the compenent as a custom element. Did you forgot to add "customElement" for compile options?` + }); + } + component_options.tag = tag; break; } diff --git a/test/validator/samples/missing-custom-element-compile-options/input.svelte b/test/validator/samples/missing-custom-element-compile-options/input.svelte new file mode 100644 index 0000000000..94ecce3ef6 --- /dev/null +++ b/test/validator/samples/missing-custom-element-compile-options/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/validator/samples/missing-custom-element-compile-options/warnings.json b/test/validator/samples/missing-custom-element-compile-options/warnings.json new file mode 100644 index 0000000000..a4c52792ab --- /dev/null +++ b/test/validator/samples/missing-custom-element-compile-options/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "missing-custom-element-compile-options", + "end": { + "character": 36, + "column": 36, + "line": 1 + }, + "message": "tag name is used when compiling the compenent as a custom element. Did you forgot to add \"customElement\" for compile options?", + "pos": 16, + "start": { + "character": 16, + "column": 16, + "line": 1 + } + } +] From 8c0c15c3aa12ba73225e83954c7c59d0599913dd Mon Sep 17 00:00:00 2001 From: "Alessandro (Ale) Segala" <43508+ItalyPaleAle@users.noreply.github.com> Date: Wed, 23 Oct 2019 22:30:54 -0700 Subject: [PATCH 085/413] Fixed anchor link in documentation --- site/content/docs/03-run-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index fd709dd9d5..19a19c4f41 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -184,7 +184,7 @@ dispatch: ((name: string, detail?: any) => void) = createEventDispatcher(); --- -Creates an event dispatcher that can be used to dispatch [component events](docs#Component_events). Event dispatchers are functions that can take two arguments: `name` and `detail`. +Creates an event dispatcher that can be used to dispatch [component events](docs#on_component_event). Event dispatchers are functions that can take two arguments: `name` and `detail`. Component events created with `createEventDispatcher` create a [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent). These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture) and are not cancellable with `event.preventDefault()`. The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) property and can contain any type of data. From 0419039d26cd9556f94c79c1dc3e584e192f3f32 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 24 Oct 2019 08:18:33 -0400 Subject: [PATCH 086/413] Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating (#3781) * include all class: directive updates on elements with spreads (#3421) * add test * update changelog --- CHANGELOG.md | 1 + src/compiler/compile/render_dom/wrappers/Element/index.ts | 5 ++++- test/runtime/samples/spread-element-class/_config.js | 7 +++++++ test/runtime/samples/spread-element-class/main.svelte | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-element-class/_config.js create mode 100644 test/runtime/samples/spread-element-class/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 31fc1eddd1..a3ce06485e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) +* Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating ([#3421](https://github.com/sveltejs/svelte/issues/3421)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issue/3595)) diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index bb4c2d310a..8f54ebf468 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -809,6 +809,7 @@ export default class ElementWrapper extends Wrapper { } add_classes(block: Block) { + const has_spread = this.node.attributes.some(attr => attr.is_spread); this.node.classes.forEach(class_directive => { const { expression, name } = class_directive; let snippet; @@ -824,7 +825,9 @@ export default class ElementWrapper extends Wrapper { block.chunks.hydrate.push(updater); - if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) { + if (has_spread) { + block.chunks.update.push(updater); + } else if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) { const all_dependencies = this.class_dependencies.concat(...dependencies); const condition = changed(all_dependencies); diff --git a/test/runtime/samples/spread-element-class/_config.js b/test/runtime/samples/spread-element-class/_config.js new file mode 100644 index 0000000000..7fc3d49012 --- /dev/null +++ b/test/runtime/samples/spread-element-class/_config.js @@ -0,0 +1,7 @@ +export default { + html: `
hello
`, + test({ assert, component, target }) { + component.blah = 'goodbye'; + assert.htmlEqual(target.innerHTML, `
goodbye
`); + } +}; diff --git a/test/runtime/samples/spread-element-class/main.svelte b/test/runtime/samples/spread-element-class/main.svelte new file mode 100644 index 0000000000..a678659013 --- /dev/null +++ b/test/runtime/samples/spread-element-class/main.svelte @@ -0,0 +1,5 @@ + + +
{blah}
From af0557a2d41e468e98f179607693eba28c652e2e Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Thu, 24 Oct 2019 13:45:03 +0100 Subject: [PATCH 087/413] add regression test for missing class on elem with bind and spread (#3668) relates to #2707 --- .../class-with-spread-and-bind/_config.js | 18 ++++++++++++++++++ .../class-with-spread-and-bind/main.svelte | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/runtime/samples/class-with-spread-and-bind/_config.js create mode 100644 test/runtime/samples/class-with-spread-and-bind/main.svelte diff --git a/test/runtime/samples/class-with-spread-and-bind/_config.js b/test/runtime/samples/class-with-spread-and-bind/_config.js new file mode 100644 index 0000000000..f3c54e8c52 --- /dev/null +++ b/test/runtime/samples/class-with-spread-and-bind/_config.js @@ -0,0 +1,18 @@ +export default { + props: { + primary: true, + }, + + html: `
`, + + test({ assert, component, target, window }) { + component.primary = true; + + assert.htmlEqual( + target.innerHTML, + ` +
+ ` + ); + }, +}; diff --git a/test/runtime/samples/class-with-spread-and-bind/main.svelte b/test/runtime/samples/class-with-spread-and-bind/main.svelte new file mode 100644 index 0000000000..c7c24a2e7b --- /dev/null +++ b/test/runtime/samples/class-with-spread-and-bind/main.svelte @@ -0,0 +1,11 @@ + + +
From b605f3867e9f98cde9db71e43df6c9dcc7017c66 Mon Sep 17 00:00:00 2001 From: mustafa0x Date: Thu, 24 Oct 2019 18:34:23 +0300 Subject: [PATCH 088/413] reduce confusion mentioned in #2452 --- site/src/routes/tutorial/[slug]/index.svelte | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/site/src/routes/tutorial/[slug]/index.svelte b/site/src/routes/tutorial/[slug]/index.svelte index ec23906057..ff6451d129 100644 --- a/site/src/routes/tutorial/[slug]/index.svelte +++ b/site/src/routes/tutorial/[slug]/index.svelte @@ -218,18 +218,20 @@ } .show { - background: rgba(0,0,0,.4); + background: var(--prime); padding: .3em .7em; border-radius: var(--border-r); top: .1em; position: relative; font-size: var(--h5); font-weight: 300; + box-shadow: 0 0 20px #444; + color: #fff; + transition: box-shadow .2s; } .show:hover { - background: rgba(0,0,0,.65); - color: white; + box-shadow: 0 0 30px 2px #333; } a.next { From b6798e522171f94cded4f06103f03321809be2b7 Mon Sep 17 00:00:00 2001 From: Jesse Skinner Date: Thu, 24 Oct 2019 13:34:58 -0400 Subject: [PATCH 089/413] allow multiple ancestors to be scoped with class (#3544) --- src/compiler/compile/css/Selector.ts | 104 +++++++++++------- .../expected.css | 1 + .../expected.html | 4 + .../input.svelte | 16 +++ .../expected.css | 1 + .../expected.html | 5 + .../input.svelte | 16 +++ .../expected.css | 1 + .../expected.html | 5 + .../input.svelte | 16 +++ 10 files changed, 131 insertions(+), 38 deletions(-) create mode 100644 test/css/samples/omit-scoping-attribute-global-children/expected.css create mode 100644 test/css/samples/omit-scoping-attribute-global-children/expected.html create mode 100644 test/css/samples/omit-scoping-attribute-global-children/input.svelte create mode 100644 test/css/samples/omit-scoping-attribute-global-descendants/expected.css create mode 100644 test/css/samples/omit-scoping-attribute-global-descendants/expected.html create mode 100644 test/css/samples/omit-scoping-attribute-global-descendants/input.svelte create mode 100644 test/css/samples/omit-scoping-attribute-multiple-descendants/expected.css create mode 100644 test/css/samples/omit-scoping-attribute-multiple-descendants/expected.html create mode 100644 test/css/samples/omit-scoping-attribute-multiple-descendants/input.svelte diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index 95eeaaf8cd..ab19ebd1e1 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -4,6 +4,12 @@ import { gather_possible_values, UNKNOWN } from './gather_possible_values'; import { CssNode } from './interfaces'; import Component from '../Component'; +enum BlockAppliesToNode { + NotPossible, + Possible, + UnknownSelectorType +} + export default class Selector { node: CssNode; stylesheet: Stylesheet; @@ -31,10 +37,10 @@ export default class Selector { apply(node: CssNode, stack: CssNode[]) { const to_encapsulate: CssNode[] = []; - apply_selector(this.stylesheet, this.local_blocks.slice(), node, stack.slice(), to_encapsulate); + apply_selector(this.local_blocks.slice(), node, stack.slice(), to_encapsulate); if (to_encapsulate.length > 0) { - to_encapsulate.filter((_, i) => i === 0 || i === to_encapsulate.length - 1).forEach(({ node, block }) => { + to_encapsulate.forEach(({ node, block }) => { this.stylesheet.nodes_with_css_class.add(node); block.should_encapsulate = true; }); @@ -126,7 +132,7 @@ export default class Selector { } } -function apply_selector(stylesheet: Stylesheet, blocks: Block[], node: CssNode, stack: CssNode[], to_encapsulate: any[]): boolean { +function apply_selector(blocks: Block[], node: CssNode, stack: CssNode[], to_encapsulate: any[]): boolean { const block = blocks.pop(); if (!block) return false; @@ -134,49 +140,30 @@ function apply_selector(stylesheet: Stylesheet, blocks: Block[], node: CssNode, return blocks.every(block => block.global); } - let i = block.selectors.length; - - while (i--) { - const selector = block.selectors[i]; - const name = typeof selector.name === 'string' && selector.name.replace(/\\(.)/g, '$1'); - - if (selector.type === 'PseudoClassSelector' && name === 'global') { - // TODO shouldn't see this here... maybe we should enforce that :global(...) - // cannot be sandwiched between non-global selectors? + switch (block_might_apply_to_node(block, node)) { + case BlockAppliesToNode.NotPossible: return false; - } - - if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') { - continue; - } - - if (selector.type === 'ClassSelector') { - if (!attribute_matches(node, 'class', name, '~=', false) && !node.classes.some(c => c.name === name)) return false; - } - - else if (selector.type === 'IdSelector') { - if (!attribute_matches(node, 'id', name, '=', false)) return false; - } - else if (selector.type === 'AttributeSelector') { - if (!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) return false; - } - - else if (selector.type === 'TypeSelector') { - if (node.name.toLowerCase() !== name.toLowerCase() && name !== '*') return false; - } - - else { + case BlockAppliesToNode.UnknownSelectorType: // bail. TODO figure out what these could be to_encapsulate.push({ node, block }); return true; - } } if (block.combinator) { if (block.combinator.type === 'WhiteSpace') { - while (stack.length) { - if (apply_selector(stylesheet, blocks.slice(), stack.pop(), stack, to_encapsulate)) { + for (const ancestor_block of blocks) { + if (ancestor_block.global) { + continue; + } + + for (const stack_node of stack) { + if (block_might_apply_to_node(ancestor_block, stack_node) !== BlockAppliesToNode.NotPossible) { + to_encapsulate.push({ node: stack_node, block: ancestor_block }); + } + } + + if (to_encapsulate.length) { to_encapsulate.push({ node, block }); return true; } @@ -189,7 +176,7 @@ function apply_selector(stylesheet: Stylesheet, blocks: Block[], node: CssNode, return false; } else if (block.combinator.name === '>') { - if (apply_selector(stylesheet, blocks, stack.pop(), stack, to_encapsulate)) { + if (apply_selector(blocks, stack.pop(), stack, to_encapsulate)) { to_encapsulate.push({ node, block }); return true; } @@ -206,6 +193,47 @@ function apply_selector(stylesheet: Stylesheet, blocks: Block[], node: CssNode, return true; } +function block_might_apply_to_node(block, node): BlockAppliesToNode { + let i = block.selectors.length; + + while (i--) { + const selector = block.selectors[i]; + const name = typeof selector.name === 'string' && selector.name.replace(/\\(.)/g, '$1'); + + if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') { + continue; + } + + if (selector.type === 'PseudoClassSelector' && name === 'global') { + // TODO shouldn't see this here... maybe we should enforce that :global(...) + // cannot be sandwiched between non-global selectors? + return BlockAppliesToNode.NotPossible; + } + + if (selector.type === 'ClassSelector') { + if (!attribute_matches(node, 'class', name, '~=', false) && !node.classes.some(c => c.name === name)) return BlockAppliesToNode.NotPossible; + } + + else if (selector.type === 'IdSelector') { + if (!attribute_matches(node, 'id', name, '=', false)) return BlockAppliesToNode.NotPossible; + } + + else if (selector.type === 'AttributeSelector') { + if (!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) return BlockAppliesToNode.NotPossible; + } + + else if (selector.type === 'TypeSelector') { + if (node.name.toLowerCase() !== name.toLowerCase() && name !== '*') return BlockAppliesToNode.NotPossible; + } + + else { + return BlockAppliesToNode.UnknownSelectorType; + } + } + + return BlockAppliesToNode.Possible; +} + function test_attribute(operator, expected_value, case_insensitive, value) { if (case_insensitive) { expected_value = expected_value.toLowerCase(); diff --git a/test/css/samples/omit-scoping-attribute-global-children/expected.css b/test/css/samples/omit-scoping-attribute-global-children/expected.css new file mode 100644 index 0000000000..2a7a510449 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-children/expected.css @@ -0,0 +1 @@ +.root.svelte-xyz p{color:red} \ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-global-children/expected.html b/test/css/samples/omit-scoping-attribute-global-children/expected.html new file mode 100644 index 0000000000..f7ee02fd83 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-children/expected.html @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-global-children/input.svelte b/test/css/samples/omit-scoping-attribute-global-children/input.svelte new file mode 100644 index 0000000000..5e52d48738 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-children/input.svelte @@ -0,0 +1,16 @@ + + + + +
+
+ +
+
diff --git a/test/css/samples/omit-scoping-attribute-global-descendants/expected.css b/test/css/samples/omit-scoping-attribute-global-descendants/expected.css new file mode 100644 index 0000000000..c1fd7da897 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-descendants/expected.css @@ -0,0 +1 @@ +html body .root.svelte-xyz p.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-global-descendants/expected.html b/test/css/samples/omit-scoping-attribute-global-descendants/expected.html new file mode 100644 index 0000000000..3750091bc7 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-descendants/expected.html @@ -0,0 +1,5 @@ +
+
+

hello

+
+
\ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-global-descendants/input.svelte b/test/css/samples/omit-scoping-attribute-global-descendants/input.svelte new file mode 100644 index 0000000000..7c9782ebad --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-global-descendants/input.svelte @@ -0,0 +1,16 @@ + + + + +
+
+

hello

+
+
diff --git a/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.css b/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.css new file mode 100644 index 0000000000..5452f68073 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.css @@ -0,0 +1 @@ +.root.svelte-xyz p.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.html b/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.html new file mode 100644 index 0000000000..3750091bc7 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-multiple-descendants/expected.html @@ -0,0 +1,5 @@ +
+
+

hello

+
+
\ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-multiple-descendants/input.svelte b/test/css/samples/omit-scoping-attribute-multiple-descendants/input.svelte new file mode 100644 index 0000000000..dc77a6c794 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-multiple-descendants/input.svelte @@ -0,0 +1,16 @@ + + + + +
+
+

hello

+
+
From 07b9d0378ec2a73f6e99fe8e4c2e8ce35bac69cb Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 24 Oct 2019 13:36:28 -0400 Subject: [PATCH 090/413] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3ce06485e..69bd58c47b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating ([#3421](https://github.com/sveltejs/svelte/issues/3421)) +* Fix application of style scoping class in cases of ambiguity ([#3544](https://github.com/sveltejs/svelte/issues/3544)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issue/3595)) From aa3dab93db17c38c4efef31b65e68260ef62b971 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 24 Oct 2019 13:55:53 -0400 Subject: [PATCH 091/413] fix running tests on github actions --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e035c86b2..2488902b24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,8 @@ jobs: - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - run: 'npm i && npm test' + - run: npm install + - run: npm test env: CI: true Lint: From d4fd91cbb96206404b7f6260d0a8d572dd3a530d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 24 Oct 2019 15:06:01 -0400 Subject: [PATCH 092/413] tweak 'show me' styles --- site/src/routes/tutorial/[slug]/index.svelte | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/site/src/routes/tutorial/[slug]/index.svelte b/site/src/routes/tutorial/[slug]/index.svelte index ff6451d129..be59665970 100644 --- a/site/src/routes/tutorial/[slug]/index.svelte +++ b/site/src/routes/tutorial/[slug]/index.svelte @@ -225,13 +225,11 @@ position: relative; font-size: var(--h5); font-weight: 300; - box-shadow: 0 0 20px #444; - color: #fff; - transition: box-shadow .2s; + color: rgba(255,255,255,0.7); } .show:hover { - box-shadow: 0 0 30px 2px #333; + color: white; } a.next { From ad0e8670caed3830b2ccb95830cadb7adfebc69a Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Thu, 24 Oct 2019 21:47:05 -0400 Subject: [PATCH 093/413] tweak text of warning --- src/compiler/compile/Component.ts | 2 +- .../missing-custom-element-compile-options/warnings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index e76696c53d..3bd7373f7f 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1310,7 +1310,7 @@ function process_component_options(component: Component, nodes) { if (tag && !component.compile_options.customElement) { component.warn(attribute, { code: 'missing-custom-element-compile-options', - message: `tag name is used when compiling the compenent as a custom element. Did you forgot to add "customElement" for compile options?` + message: `The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?` }); } diff --git a/test/validator/samples/missing-custom-element-compile-options/warnings.json b/test/validator/samples/missing-custom-element-compile-options/warnings.json index a4c52792ab..8d6d574fb2 100644 --- a/test/validator/samples/missing-custom-element-compile-options/warnings.json +++ b/test/validator/samples/missing-custom-element-compile-options/warnings.json @@ -6,7 +6,7 @@ "column": 36, "line": 1 }, - "message": "tag name is used when compiling the compenent as a custom element. Did you forgot to add \"customElement\" for compile options?", + "message": "The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?", "pos": 16, "start": { "character": 16, From 9f83a2ad23047c8e5f2d9ba2efd95f9397d8c6b9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 24 Oct 2019 22:12:21 -0400 Subject: [PATCH 094/413] address a few nits --- CONTRIBUTING.md | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d698d02cd2..f00ebc07b9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,19 +7,19 @@ The [Open Source Guides](https://opensource.guide/) website has a collection of * [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) * [Building Welcoming Communities](https://opensource.guide/building-community/) -## Get Involved +## Get involved There are many ways to contribute to Svelte, and many of them do not involve writing any code. Here's a few ideas to get started: - Simply start using Svelte. Go through the [Getting Started](https://svelte.dev/blog/the-easiest-way-to-get-started) guide. Does everything work as expected? If not, we're always looking for improvements. Let us know by [opening an issue](#reporting-new-issues). - Look through the [open issues](https://github.com/sveltejs/svelte/issues). Provide workarounds, ask for clarification, or suggest labels. Help [triage issues](#triaging-issues-and-pull-requests). - If you find an issue you would like to fix, [open a pull request](#your-first-pull-request). -- Read through our amazing [Tutorials](https://svelte.dev/tutorial/basics). If you find anything that is confusing or can be improved, you can make edits by clicking "Edit this chapter" at the bottom left of the tutorials. +- Read through our [tutorials](https://svelte.dev/tutorial/basics). If you find anything that is confusing or can be improved, you can make edits by clicking "Edit this chapter" at the bottom left of the tutorial page. - Take a look at the [features requested](https://github.com/sveltejs/svelte/labels/enhancement) by others in the community and consider opening a pull request if you see something you want to work on. -Contributions are very welcome. If you think you need help planning your contribution, please ping us on Twitter at [@sveltejs](https://twitter.com/sveltejs) and let us know you are looking for a bit of help. +Contributions are very welcome. If you think you need help planning your contribution, please ping us on Discord at [svelte.dev/chat](https://svelte.dev/chat) and let us know you are looking for a bit of help. -### Triaging Issues and Pull Requests +### Triaging issues and pull requests One great way you can contribute to the project without writing any code is to help triage issues and pull requests as they come in. @@ -30,18 +30,18 @@ One great way you can contribute to the project without writing any code is to h ## Bugs -We use [GitHub Issues](https://github.com/sveltejs/svelte/issues) for our public bugs. If you would like to report a problem, take a look around and see if someone already opened an issue about it. If you a are certain this is a new, unreported bug, you can submit a [bug report](#reporting-new-issues). +We use [GitHub issues](https://github.com/sveltejs/svelte/issues) for our public bugs. If you would like to report a problem, take a look around and see if someone already opened an issue about it. If you a are certain this is a new, unreported bug, you can submit a [bug report](#reporting-new-issues). -If you have questions about using Svelte, contact the Svelte Twitter account at [@sveltejs](https://twitter.com/sveltejs), and we will do our best to answer your questions. +If you have questions about using Svelte, contact us on Discord at [svelte.dev/chat](https://svelte.dev/chat), and we will do our best to answer your questions. If you see anything you'd like to be implemented, create a [feature request issue](https://github.com/sveltejs/svelte/issues/new?template=feature_request.md) -## Reporting New Issues +## Reporting new issues -When [opening a new issue](https://github.com/sveltejs/svelte/issues/new/choose), always make sure to fill out the issue template. **This step is very important!** Not doing so may result in your issue not managed in a timely fashion. Don't take this personally if this happens, and feel free to open a new issue once you've gathered all the information required by the template. +When [opening a new issue](https://github.com/sveltejs/svelte/issues/new/choose), always make sure to fill out the issue template. **This step is very important!** Not doing so may result in your issue not being managed in a timely fashion. Don't take this personally if this happens, and feel free to open a new issue once you've gathered all the information required by the template. - **One issue, one bug:** Please report a single bug per issue. -- **Provide reproduction steps:** List all the steps necessary to reproduce the issue. The person reading your bug report should be able to follow these steps to reproduce your issue with minimal effort. +- **Provide reproduction steps:** List all the steps necessary to reproduce the issue. The person reading your bug report should be able to follow these steps to reproduce your issue with minimal effort. If possible, use the [REPL](https://svelte.dev/repl) to create your reproduction. ## Installation @@ -50,9 +50,9 @@ When [opening a new issue](https://github.com/sveltejs/svelte/issues/new/choose) 1. To start a development server, run `npm run dev`. -## Pull Requests +## Pull requests -### Your First Pull Request +### Your first pull request So you have decided to contribute code back to upstream by opening a pull request. You've invested a good chunk of time, and we appreciate it. We will do our best to work with you and get the PR looked at. @@ -60,13 +60,13 @@ Working on your first Pull Request? You can learn how from this free video serie [**How to Contribute to an Open Source Project on GitHub**](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) -### Proposing a Change +### Proposing a change If you would like to request a new feature or enhancement but are not yet thinking about opening a pull request, you can also file an issue with [feature template](https://github.com/sveltejs/svelte/issues/new?template=feature_request.md). If you're only fixing a bug, it's fine to submit a pull request right away but we still recommend to file an issue detailing what you're fixing. This is helpful in case we don't accept that specific fix but want to keep track of the issue. -### Sending a Pull Request +### Sending a pull request Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. @@ -79,25 +79,24 @@ Please make sure the following is done when submitting a pull request: All pull requests should be opened against the `master` branch. -#### Test Plan +#### Test plan A good test plan has the exact commands you ran and their output, provides screenshots or videos if the pull request changes UI. - If you've changed APIs, update the documentation. -#### Writing Tests +#### Writing tests All tests are located in `/test` folder. -Tests samples are kept in `/test/xxx/samples` folder. +Test samples are kept in `/test/xxx/samples` folder. -#### Running Tests +#### Running tests 1. To run test, run `npm run test` -1. To run test for a specific feature, you can use the `-g` (aka `--grep`) option. For example, to only run test invloving transitions, run `npm run test -- -g transition`. -1. To run only 1 test sample, append the `.solo` to the test sample folder name, for example, `test/runtime/samples/action.solo`. +1. To run test for a specific feature, you can use the `-g` (aka `--grep`) option. For example, to only run test involving transitions, run `npm run test -- -g transition`. -#### Breaking Changes +#### Breaking changes When adding a new breaking change, follow this template in your pull request: @@ -110,19 +109,19 @@ When adding a new breaking change, follow this template in your pull request: - **Severity (number of people affected x effort)**: ``` -### What Happens Next? +### What happens next? The core Svelte team will be monitoring for pull requests. Do help us by making your pull request easy to review by following the guidelines above. -## Style Guide +## Style guide [Eslint](https://eslint.org) will catch most styling issues that may exist in your code. You can check the status of your code styling by simply running `npm run lint`. -### Code Conventions +### Code conventions - `snake_case` for internal variable names and methods - `camelCase` for public variable names and methods. ## License -By contributing to Svelte, you agree that your contributions will be licensed under its [MIT license](https://github.com/sveltejs/svelte/blob/master/LICENSE). \ No newline at end of file +By contributing to Svelte, you agree that your contributions will be licensed under its [MIT license](https://github.com/sveltejs/svelte/blob/master/LICENSE). From 85692cbd5ac9f24f02c37f641feb54cdac54ca8c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 25 Oct 2019 13:03:09 -0400 Subject: [PATCH 095/413] fix handling of style scoping and `class:` with spread scopes (#3792) --- CHANGELOG.md | 4 +-- src/compiler/compile/nodes/Element.ts | 6 ++++ .../render_dom/wrappers/Element/index.ts | 9 +++++ .../compile/render_ssr/handlers/Element.ts | 36 +++++++++---------- src/runtime/internal/ssr.ts | 9 ++++- .../samples/spread-element-class/main.svelte | 2 +- .../samples/spread-element-scope/_config.js | 7 ++++ .../samples/spread-element-scope/main.svelte | 10 ++++++ 8 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 test/runtime/samples/spread-element-scope/_config.js create mode 100644 test/runtime/samples/spread-element-scope/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 69bd58c47b..4f5ab9acf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Fix several bugs related to interaction of `{...spread}` attributes with other features ([#2721](https://github.com/sveltejs/svelte/issues/2721), [#3421](https://github.com/sveltejs/svelte/issues/3421), [#3681](https://github.com/sveltejs/svelte/issues/3681), [#3764](https://github.com/sveltejs/svelte/issues/3764), [#3790](https://github.com/sveltejs/svelte/issues/3790)) * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) -* Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating ([#3421](https://github.com/sveltejs/svelte/issues/3421)) * Fix application of style scoping class in cases of ambiguity ([#3544](https://github.com/sveltejs/svelte/issues/3544)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) @@ -19,8 +19,6 @@ * Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660)) * Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667)) * Fix globals shadowing contextual template scope ([#3674](https://github.com/sveltejs/svelte/issues/3674)) -* Fix error resulting from trying to set a read-only property when spreading element attributes ([#3681](https://github.com/sveltejs/svelte/issues/3681)) -* Fix handling of boolean attributes in presence of other spread attributes ([#3764](https://github.com/sveltejs/svelte/issues/3764)) ## 3.12.1 diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 2981741fa0..d353d20158 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -105,6 +105,7 @@ export default class Element extends Node { animation?: Animation = null; children: INode[]; namespace: string; + needs_manual_style_scoping: boolean; constructor(component, parent, scope, info: any) { super(component, parent, scope, info); @@ -712,6 +713,11 @@ export default class Element extends Node { } add_css_class() { + if (this.attributes.some(attr => attr.is_spread)) { + this.needs_manual_style_scoping = true; + return; + } + const { id } = this.component.stylesheet; const class_attribute = this.attributes.find(a => a.name === 'class'); diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 8f54ebf468..253ab107d8 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -344,6 +344,7 @@ export default class ElementWrapper extends Wrapper { this.add_animation(block); this.add_actions(block); this.add_classes(block); + this.add_manual_style_scoping(block); if (nodes && this.renderer.options.hydratable) { block.chunks.claim.push( @@ -838,6 +839,14 @@ export default class ElementWrapper extends Wrapper { } }); } + + add_manual_style_scoping(block) { + if (this.node.needs_manual_style_scoping) { + const updater = b`@toggle_class(${this.var}, "${this.node.component.stylesheet.id}", true);`; + block.chunks.hydrate.push(updater); + block.chunks.update.push(updater); + } + } } function to_html(wrappers: Array, block: Block, literal: any, state: any) { diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index 1f7c0b7b9f..65013a8d07 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -1,5 +1,4 @@ import { is_void } from '../../../utils/names'; -import Class from '../../nodes/Class'; import { get_attribute_value, get_class_attribute_value } from './shared/get_attribute_value'; import { get_slot_scope } from './shared/get_slot_scope'; import Renderer, { RenderOptions } from '../Renderer'; @@ -69,15 +68,17 @@ export default function(node: Element, renderer: Renderer, options: RenderOption renderer.add_string(`<${node.name}`); - const class_expression = node.classes.length > 0 && node.classes - .map((class_directive: Class) => { - const { expression, name } = class_directive; - const snippet = expression ? expression.node : x`#ctx.${name}`; - return x`${snippet} ? "${name}" : ""`; - }) - .reduce((lhs, rhs) => x`${lhs} + ' ' + ${rhs}`); - - let add_class_attribute = class_expression ? true : false; + const class_expression_list = node.classes.map(class_directive => { + const { expression, name } = class_directive; + const snippet = expression ? expression.node : x`#ctx.${name}`; + return x`${snippet} ? "${name}" : ""`; + }); + if (node.needs_manual_style_scoping) { + class_expression_list.push(x`"${node.component.stylesheet.id}"`); + } + const class_expression = + class_expression_list.length > 0 && + class_expression_list.reduce((lhs, rhs) => x`${lhs} + ' ' + ${rhs}`); if (node.attributes.some(attr => attr.is_spread)) { // TODO dry this out @@ -98,17 +99,15 @@ export default function(node: Element, renderer: Renderer, options: RenderOption ) { // a boolean attribute with one non-Text chunk args.push(x`{ ${attribute.name}: ${(attribute.chunks[0] as Expression).node} || null }`); - } else if (name === 'class' && class_expression) { - // Add class expression - args.push(x`{ ${attribute.name}: [${get_class_attribute_value(attribute)}, ${class_expression}].join(' ').trim() }`); } else { - args.push(x`{ ${attribute.name}: ${(name === 'class' ? get_class_attribute_value : get_attribute_value)(attribute)} }`); + args.push(x`{ ${attribute.name}: ${get_attribute_value(attribute)} }`); } } }); - renderer.add_expression(x`@spread([${args}])`); + renderer.add_expression(x`@spread([${args}], ${class_expression});`); } else { + let add_class_attribute = !!class_expression; node.attributes.forEach(attribute => { const name = attribute.name.toLowerCase(); if (name === 'value' && node.name.toLowerCase() === 'textarea') { @@ -137,6 +136,9 @@ export default function(node: Element, renderer: Renderer, options: RenderOption renderer.add_string(`"`); } }); + if (add_class_attribute) { + renderer.add_expression(x`@add_classes([${class_expression}].join(' ').trim())`); + } } node.bindings.forEach(binding => { @@ -162,10 +164,6 @@ export default function(node: Element, renderer: Renderer, options: RenderOption } }); - if (add_class_attribute) { - renderer.add_expression(x`@add_classes([${class_expression}].join(' ').trim())`); - } - renderer.add_string('>'); if (node_contents !== undefined) { diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index 208a4637c7..83e585a899 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -5,8 +5,15 @@ export const invalid_attribute_name_character = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFF // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 // https://infra.spec.whatwg.org/#noncharacter -export function spread(args) { +export function spread(args, classes_to_add) { const attributes = Object.assign({}, ...args); + if (classes_to_add) { + if (attributes.class == null) { + attributes.class = classes_to_add; + } else { + attributes.class += ' ' + classes_to_add; + } + } let str = ''; Object.keys(attributes).forEach(name => { diff --git a/test/runtime/samples/spread-element-class/main.svelte b/test/runtime/samples/spread-element-class/main.svelte index a678659013..026132287b 100644 --- a/test/runtime/samples/spread-element-class/main.svelte +++ b/test/runtime/samples/spread-element-class/main.svelte @@ -2,4 +2,4 @@ export let blah = 'hello'; -
{blah}
+
{blah}
diff --git a/test/runtime/samples/spread-element-scope/_config.js b/test/runtime/samples/spread-element-scope/_config.js new file mode 100644 index 0000000000..457524ca37 --- /dev/null +++ b/test/runtime/samples/spread-element-scope/_config.js @@ -0,0 +1,7 @@ +export default { + html: ` +
red
+
red
+
red and bold
+ ` +}; diff --git a/test/runtime/samples/spread-element-scope/main.svelte b/test/runtime/samples/spread-element-scope/main.svelte new file mode 100644 index 0000000000..7a25f90939 --- /dev/null +++ b/test/runtime/samples/spread-element-scope/main.svelte @@ -0,0 +1,10 @@ + + +
red
+ +
red
+ +
red and bold
From 4c239974c391d1c44adcdebaa0cd01bffd5602c4 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 25 Oct 2019 13:04:18 -0400 Subject: [PATCH 096/413] alpha.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ca8b7cdb5..cc5bd88a6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.13.0-alpha.1", + "version": "3.13.0-alpha.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 950c44d965..a061cdf742 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.13.0-alpha.1", + "version": "3.13.0-alpha.2", "description": "Cybernetically enhanced web apps", "module": "index.mjs", "main": "index", From 3f6b743dd01d952c9b6e79ccad1b5b9f46d06efa Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 26 Oct 2019 16:15:51 -0400 Subject: [PATCH 097/413] site: add REPL imports to .zip's pkg.devDependencies (#3795) --- .../routes/repl/[id]/_components/AppControls/index.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/site/src/routes/repl/[id]/_components/AppControls/index.svelte b/site/src/routes/repl/[id]/_components/AppControls/index.svelte index 4cfd5d43b2..007dba3461 100644 --- a/site/src/routes/repl/[id]/_components/AppControls/index.svelte +++ b/site/src/routes/repl/[id]/_components/AppControls/index.svelte @@ -140,12 +140,12 @@ if (imports.length > 0) { const idx = files.findIndex(({ path }) => path === 'package.json'); const pkg = JSON.parse(files[idx].data); - const deps = {}; + const { devDependencies } = pkg; imports.forEach(mod => { const match = /^(@[^/]+\/)?[^@/]+/.exec(mod); - deps[match[0]] = 'latest'; + devDependencies[match[0]] = 'latest'; }); - pkg.dependencies = deps; + pkg.devDependencies = devDependencies; files[idx].data = JSON.stringify(pkg, null, ' '); } From b8107e7fa73979cd4eeae3e2b20f42f250c97226 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 26 Oct 2019 17:05:10 -0400 Subject: [PATCH 098/413] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f5ab9acf8..a3c4adac7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* New structured code generation, which eliminates a number of edge cases and obscure bugs ([#3539](https://github.com/sveltejs/svelte/pull/3539)) + +Also: + * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) * Fix several bugs related to interaction of `{...spread}` attributes with other features ([#2721](https://github.com/sveltejs/svelte/issues/2721), [#3421](https://github.com/sveltejs/svelte/issues/3421), [#3681](https://github.com/sveltejs/svelte/issues/3681), [#3764](https://github.com/sveltejs/svelte/issues/3764), [#3790](https://github.com/sveltejs/svelte/issues/3790)) From 1e55d46bc0c710730069509eaf04a39cacab1ce3 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 26 Oct 2019 23:53:13 +0100 Subject: [PATCH 099/413] Add Key handling to modal example This is a basic accessibility requirement for key access --- .../15-composition/04-modal/Modal.svelte | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/site/content/examples/15-composition/04-modal/Modal.svelte b/site/content/examples/15-composition/04-modal/Modal.svelte index 5ffa5989a4..8ddaf55921 100644 --- a/site/content/examples/15-composition/04-modal/Modal.svelte +++ b/site/content/examples/15-composition/04-modal/Modal.svelte @@ -2,7 +2,23 @@ import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); - + + const handleClose = () => dispatch('close') + + function handleKeydown(event) { + if (event.key == 'Escape') { + handleClose() + } else if (event.key == 'Tab') { + event.preventDefault() + } + } + + let closeButton + onMount(() => { + closeButton.focus() + }) + + - + From 81c5c480e896b079aafe704e99699b65973f9db2 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 27 Oct 2019 13:42:50 +0800 Subject: [PATCH 100/413] feat: warn unused exports --- src/compiler/compile/Component.ts | 253 ++++++++++++------ .../compile/utils/is_used_as_reference.ts | 33 +++ src/compiler/interfaces.ts | 3 +- .../unreferenced-variables/input.svelte | 21 ++ .../unreferenced-variables/warnings.json | 77 ++++++ .../vars/samples/$$props-logicless/_config.js | 1 + test/vars/samples/$$props/_config.js | 1 + test/vars/samples/actions/_config.js | 2 + test/vars/samples/animations/_config.js | 2 + .../samples/component-namespaced/_config.js | 1 + .../duplicate-non-hoistable/_config.js | 1 + test/vars/samples/duplicate-vars/_config.js | 2 + .../vars/samples/implicit-reactive/_config.js | 2 + test/vars/samples/imports/_config.js | 3 + .../mutated-vs-reassigned-bindings/_config.js | 2 + .../samples/mutated-vs-reassigned/_config.js | 2 + test/vars/samples/props/_config.js | 4 + .../samples/referenced-from-script/_config.js | 160 +++++++++++ .../referenced-from-script/input.svelte | 16 ++ test/vars/samples/store-referenced/_config.js | 2 + .../samples/store-unreferenced/_config.js | 2 + .../samples/template-references/_config.js | 3 + test/vars/samples/transitions/_config.js | 6 + 23 files changed, 511 insertions(+), 88 deletions(-) create mode 100644 src/compiler/compile/utils/is_used_as_reference.ts create mode 100644 test/validator/samples/unreferenced-variables/input.svelte create mode 100644 test/validator/samples/unreferenced-variables/warnings.json create mode 100644 test/vars/samples/referenced-from-script/_config.js create mode 100644 test/vars/samples/referenced-from-script/input.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 3bd7373f7f..cc3bf2e308 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -18,6 +18,7 @@ import { Ast, CompileOptions, Var, Warning } from '../interfaces'; import error from '../utils/error'; import get_code_frame from '../utils/get_code_frame'; import flatten_reference from './utils/flatten_reference'; +import is_used_as_reference from './utils/is_used_as_reference'; import is_reference from 'is-reference'; import TemplateScope from './nodes/shared/TemplateScope'; import fuzzymatch from '../utils/fuzzymatch'; @@ -168,12 +169,13 @@ export default class Component { this.tag = this.name.name; } - this.walk_module_js(); + this.walk_module_js_pre_template(); this.walk_instance_js_pre_template(); this.fragment = new Fragment(this, ast.html); this.name = this.get_unique_name(name); + this.walk_module_js_post_template(); this.walk_instance_js_post_template(); if (!compile_options.customElement) this.stylesheet.reify(); @@ -346,6 +348,7 @@ export default class Component { reassigned: v.reassigned || false, referenced: v.referenced || false, writable: v.writable || false, + referenced_from_script: v.referenced_from_script || false, })), stats: this.stats.render(), }; @@ -447,63 +450,64 @@ export default class Component { }); } - extract_imports(content) { - for (let i = 0; i < content.body.length; i += 1) { - const node = content.body[i]; - - if (node.type === 'ImportDeclaration') { - content.body.splice(i--, 1); - this.imports.push(node); - } - } + extract_imports(node) { + this.imports.push(node); } - extract_exports(content) { - let i = content.body.length; - while (i--) { - const node = content.body[i]; + extract_exports(node) { + if (node.type === 'ExportDefaultDeclaration') { + this.error(node, { + code: `default-export`, + message: `A component cannot have a default export`, + }); + } - if (node.type === 'ExportDefaultDeclaration') { + if (node.type === 'ExportNamedDeclaration') { + if (node.source) { this.error(node, { - code: `default-export`, - message: `A component cannot have a default export`, + code: `not-implemented`, + message: `A component currently cannot have an export ... from`, }); } - - if (node.type === 'ExportNamedDeclaration') { - if (node.source) { - this.error(node, { - code: `not-implemented`, - message: `A component currently cannot have an export ... from`, + if (node.declaration) { + if (node.declaration.type === 'VariableDeclaration') { + node.declaration.declarations.forEach(declarator => { + extract_names(declarator.id).forEach(name => { + const variable = this.var_lookup.get(name); + variable.export_name = name; + if (variable.writable && !(variable.referenced || variable.referenced_from_script)) { + this.warn(declarator, { + code: `unused-export-let`, + message: `${this.name.name} has unused export property '${name}'. If it is for external reference only, please consider using \`export const '${name}'\`` + }); + } + }); }); + } else { + const { name } = node.declaration.id; + + const variable = this.var_lookup.get(name); + variable.export_name = name; } - if (node.declaration) { - if (node.declaration.type === 'VariableDeclaration') { - node.declaration.declarations.forEach(declarator => { - extract_names(declarator.id).forEach(name => { - const variable = this.var_lookup.get(name); - variable.export_name = name; - }); - }); - } else { - const { name } = node.declaration.id; - const variable = this.var_lookup.get(name); - variable.export_name = name; - } + return node.declaration; + } else { + node.specifiers.forEach(specifier => { + const variable = this.var_lookup.get(specifier.local.name); - content.body[i] = node.declaration; - } else { - node.specifiers.forEach(specifier => { - const variable = this.var_lookup.get(specifier.local.name); + if (variable) { + variable.export_name = specifier.exported.name; - if (variable) { - variable.export_name = specifier.exported.name; + if (variable.writable && !(variable.referenced || variable.referenced_from_script)) { + this.warn(specifier, { + code: `unused-export-let`, + message: `${this.name.name} has unused export property '${specifier.exported.name}'. If it is for external reference only, please consider using \`export const '${specifier.exported.name}'\`` + }); } - }); + } + }); - content.body.splice(i, 1); - } + return null; } } } @@ -522,7 +526,7 @@ export default class Component { }); } - walk_module_js() { + walk_module_js_pre_template() { const component = this; const script = this.ast.module; if (!script) return; @@ -573,9 +577,6 @@ export default class Component { }); } }); - - this.extract_imports(script.content); - this.extract_exports(script.content); } walk_instance_js_pre_template() { @@ -657,7 +658,10 @@ export default class Component { this.add_reference(name.slice(1)); const variable = this.var_lookup.get(name.slice(1)); - if (variable) variable.subscribable = true; + if (variable) { + variable.subscribable = true; + variable.referenced_from_script = true; + } } else { this.add_var({ name, @@ -667,46 +671,83 @@ export default class Component { } }); - this.extract_imports(script.content); - this.extract_exports(script.content); - this.track_mutations(); + this.track_references_and_mutations(); + } + + walk_module_js_post_template() { + const script = this.ast.module; + if (!script) return; + + const { body } = script.content; + let i = body.length; + while(--i >= 0) { + const node = body[i]; + if (node.type === 'ImportDeclaration') { + this.extract_imports(node); + body.splice(i, 1); + } + + if (/^Export/.test(node.type)) { + const replacement = this.extract_exports(node); + if (replacement) { + body[i] = replacement; + } else { + body.splice(i, 1); + } + } + } } walk_instance_js_post_template() { const script = this.ast.instance; if (!script) return; - this.warn_on_undefined_store_value_references(); + this.post_template_walk(); + this.hoist_instance_declarations(); this.extract_reactive_declarations(); } - // TODO merge this with other walks that are independent - track_mutations() { + post_template_walk() { + const script = this.ast.instance; + if (!script) return; + const component = this; + const { content } = script; const { instance_scope, instance_scope_map: map } = this; let scope = instance_scope; - walk(this.ast.instance.content, { - enter(node) { + const toRemove = []; + const remove = (parent, prop, index) => { + toRemove.unshift([parent, prop, index]); + } + + walk(content, { + enter(node, parent, prop, index) { if (map.has(node)) { scope = map.get(node); } - if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') { - const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument; - const names = extract_names(assignee); - - const deep = assignee.type === 'MemberExpression'; + if (node.type === 'ImportDeclaration') { + component.extract_imports(node); + // TODO: to use actual remove + remove(parent, prop, index); + return this.skip(); + } - names.forEach(name => { - if (scope.find_owner(name) === instance_scope) { - const variable = component.var_lookup.get(name); - variable[deep ? 'mutated' : 'reassigned'] = true; - } - }); + if (/^Export/.test(node.type)) { + const replacement = component.extract_exports(node); + if (replacement) { + this.replace(replacement); + } else { + // TODO: to use actual remove + remove(parent, prop, index); + } + return this.skip(); } + + component.warn_on_undefined_store_value_references(node, parent, scope); }, leave(node) { @@ -715,37 +756,53 @@ export default class Component { } }, }); + + for(const [parent, prop, index] of toRemove) { + if (parent) { + if (index !== null) { + parent[prop].splice(index, 1); + } else { + delete parent[prop]; + } + } + } } - warn_on_undefined_store_value_references() { - // TODO this pattern happens a lot... can we abstract it - // (or better still, do fewer AST walks)? + track_references_and_mutations() { + const script = this.ast.instance; + if (!script) return; + const component = this; - let { instance_scope: scope, instance_scope_map: map } = this; + const { content } = script; + const { instance_scope, instance_scope_map: map } = this; - walk(this.ast.instance.content, { + let scope = instance_scope; + + walk(content, { enter(node, parent) { if (map.has(node)) { scope = map.get(node); } - if ( - node.type === 'LabeledStatement' && - node.label.name === '$' && - parent.type !== 'Program' - ) { - component.warn(node as any, { - code: 'non-top-level-reactive-declaration', - message: '$: has no effect outside of the top-level', + if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') { + const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument; + const names = extract_names(assignee); + + const deep = assignee.type === 'MemberExpression'; + + names.forEach(name => { + if (scope.find_owner(name) === instance_scope) { + const variable = component.var_lookup.get(name); + variable[deep ? 'mutated' : 'reassigned'] = true; + } }); } - if (is_reference(node as Node, parent as Node)) { + if (is_used_as_reference(node, parent)) { const object = get_object(node); - const { name } = object; - - if (name[0] === '$' && !scope.has(name)) { - component.warn_if_undefined(name, object, null); + if (scope.find_owner(object.name) === instance_scope) { + const variable = component.var_lookup.get(object.name); + variable.referenced_from_script = true; } } }, @@ -758,6 +815,28 @@ export default class Component { }); } + warn_on_undefined_store_value_references(node, parent, scope) { + if ( + node.type === 'LabeledStatement' && + node.label.name === '$' && + parent.type !== 'Program' + ) { + this.warn(node as any, { + code: 'non-top-level-reactive-declaration', + message: '$: has no effect outside of the top-level', + }); + } + + if (is_reference(node as Node, parent as Node)) { + const object = get_object(node); + const { name } = object; + + if (name[0] === '$' && !scope.has(name)) { + this.warn_if_undefined(name, object, null); + } + } + } + invalidate(name, value?) { const variable = this.var_lookup.get(name); diff --git a/src/compiler/compile/utils/is_used_as_reference.ts b/src/compiler/compile/utils/is_used_as_reference.ts new file mode 100644 index 0000000000..8d55182794 --- /dev/null +++ b/src/compiler/compile/utils/is_used_as_reference.ts @@ -0,0 +1,33 @@ +import { Node } from 'estree'; +import is_reference from 'is-reference'; + +export default function is_used_as_reference( + node: Node, + parent: Node +): boolean { + if (!is_reference(node, parent)) { + return false; + } + if (!parent) { + return true; + } + + switch (parent.type) { + // disregard the `foo` in `const foo = bar` + case 'VariableDeclarator': + return node !== parent.id; + // disregard the `foo`, `bar` in `function foo(bar){}` + case 'FunctionDeclaration': + // disregard the `foo` in `import { foo } from 'foo'` + case 'ImportSpecifier': + // disregard the `foo` in `import foo from 'foo'` + case 'ImportDefaultSpecifier': + // disregard the `foo` in `import * as foo from 'foo'` + case 'ImportNamespaceSpecifier': + // disregard the `foo` in `export { foo }` + case 'ExportSpecifier': + return false; + default: + return true; + } +} diff --git a/src/compiler/interfaces.ts b/src/compiler/interfaces.ts index 1e0028e8aa..f877b93b56 100644 --- a/src/compiler/interfaces.ts +++ b/src/compiler/interfaces.ts @@ -148,7 +148,8 @@ export interface Var { module?: boolean; mutated?: boolean; reassigned?: boolean; - referenced?: boolean; + referenced?: boolean; // referenced from template scope + referenced_from_script?: boolean; // referenced from script writable?: boolean; // used internally, but not exposed diff --git a/test/validator/samples/unreferenced-variables/input.svelte b/test/validator/samples/unreferenced-variables/input.svelte new file mode 100644 index 0000000000..1180f6ef1a --- /dev/null +++ b/test/validator/samples/unreferenced-variables/input.svelte @@ -0,0 +1,21 @@ + diff --git a/test/validator/samples/unreferenced-variables/warnings.json b/test/validator/samples/unreferenced-variables/warnings.json new file mode 100644 index 0000000000..7d9e0111bf --- /dev/null +++ b/test/validator/samples/unreferenced-variables/warnings.json @@ -0,0 +1,77 @@ +[ + { + "code": "unused-export-let", + "end": { + "character": 103, + "column": 12, + "line": 8 + }, + "message": "Component has unused export property 'd'. If it is for external reference only, please consider using `export const 'd'`", + "pos": 102, + "start": { + "character": 102, + "column": 11, + "line": 8 + } + }, + { + "code": "unused-export-let", + "end": { + "character": 106, + "column": 15, + "line": 8 + }, + "message": "Component has unused export property 'e'. If it is for external reference only, please consider using `export const 'e'`", + "pos": 105, + "start": { + "character": 105, + "column": 14, + "line": 8 + } + }, + { + "code": "unused-export-let", + "end": { + "character": 130, + "column": 18, + "line": 9 + }, + "message": "Component has unused export property 'g'. If it is for external reference only, please consider using `export const 'g'`", + "pos": 125, + "start": { + "character": 125, + "column": 13, + "line": 9 + } + }, + { + "code": "unused-export-let", + "end": { + "character": 150, + "column": 18, + "line": 10 + }, + "message": "Component has unused export property 'h'. If it is for external reference only, please consider using `export const 'h'`", + "pos": 145, + "start": { + "character": 145, + "column": 13, + "line": 10 + } + }, + { + "code": "unused-export-let", + "end": { + "character": 199, + "column": 25, + "line": 12 + }, + "message": "Component has unused export property 'j'. If it is for external reference only, please consider using `export const 'j'`", + "pos": 187, + "start": { + "character": 187, + "column": 13, + "line": 12 + } + } +] diff --git a/test/vars/samples/$$props-logicless/_config.js b/test/vars/samples/$$props-logicless/_config.js index b0d76bebbd..20f9b99466 100644 --- a/test/vars/samples/$$props-logicless/_config.js +++ b/test/vars/samples/$$props-logicless/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/$$props/_config.js b/test/vars/samples/$$props/_config.js index b0d76bebbd..20f9b99466 100644 --- a/test/vars/samples/$$props/_config.js +++ b/test/vars/samples/$$props/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/actions/_config.js b/test/vars/samples/actions/_config.js index 6b6f8696e7..4cc2b9d18c 100644 --- a/test/vars/samples/actions/_config.js +++ b/test/vars/samples/actions/_config.js @@ -9,6 +9,7 @@ export default { name: 'hoistable_foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: false }, { @@ -19,6 +20,7 @@ export default { name: 'foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/animations/_config.js b/test/vars/samples/animations/_config.js index 6b6f8696e7..4cc2b9d18c 100644 --- a/test/vars/samples/animations/_config.js +++ b/test/vars/samples/animations/_config.js @@ -9,6 +9,7 @@ export default { name: 'hoistable_foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: false }, { @@ -19,6 +20,7 @@ export default { name: 'foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/component-namespaced/_config.js b/test/vars/samples/component-namespaced/_config.js index ac63873967..a801c52780 100644 --- a/test/vars/samples/component-namespaced/_config.js +++ b/test/vars/samples/component-namespaced/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/duplicate-non-hoistable/_config.js b/test/vars/samples/duplicate-non-hoistable/_config.js index bb7f52d4db..4ebc5b00cf 100644 --- a/test/vars/samples/duplicate-non-hoistable/_config.js +++ b/test/vars/samples/duplicate-non-hoistable/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/duplicate-vars/_config.js b/test/vars/samples/duplicate-vars/_config.js index 276ae130a1..eb10c44a9a 100644 --- a/test/vars/samples/duplicate-vars/_config.js +++ b/test/vars/samples/duplicate-vars/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: false, + referenced_from_script: false, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/implicit-reactive/_config.js b/test/vars/samples/implicit-reactive/_config.js index fd67e8b249..770de590e6 100644 --- a/test/vars/samples/implicit-reactive/_config.js +++ b/test/vars/samples/implicit-reactive/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: true, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: false, reassigned: true, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/imports/_config.js b/test/vars/samples/imports/_config.js index 90f2468b54..ecf120c7d6 100644 --- a/test/vars/samples/imports/_config.js +++ b/test/vars/samples/imports/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: false, + referenced_from_script: false, writable: false }, { @@ -19,6 +20,7 @@ export default { mutated: false, reassigned: false, referenced: false, + referenced_from_script: false, writable: false }, { @@ -29,6 +31,7 @@ export default { mutated: false, reassigned: false, referenced: false, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/mutated-vs-reassigned-bindings/_config.js b/test/vars/samples/mutated-vs-reassigned-bindings/_config.js index 21fc14d820..ba499674d2 100644 --- a/test/vars/samples/mutated-vs-reassigned-bindings/_config.js +++ b/test/vars/samples/mutated-vs-reassigned-bindings/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: true, referenced: true, + referenced_from_script: false, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: true, reassigned: false, referenced: true, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/mutated-vs-reassigned/_config.js b/test/vars/samples/mutated-vs-reassigned/_config.js index 21fc14d820..ba499674d2 100644 --- a/test/vars/samples/mutated-vs-reassigned/_config.js +++ b/test/vars/samples/mutated-vs-reassigned/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: true, referenced: true, + referenced_from_script: false, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: true, reassigned: false, referenced: true, + referenced_from_script: false, writable: false } ]); diff --git a/test/vars/samples/props/_config.js b/test/vars/samples/props/_config.js index 0c5c6f7e2a..a51c93fb03 100644 --- a/test/vars/samples/props/_config.js +++ b/test/vars/samples/props/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: true }, { @@ -29,6 +31,7 @@ export default { mutated: false, reassigned: false, referenced: false, + referenced_from_script: true, writable: true }, { @@ -39,6 +42,7 @@ export default { mutated: false, reassigned: true, referenced: true, + referenced_from_script: true, writable: true } ]); diff --git a/test/vars/samples/referenced-from-script/_config.js b/test/vars/samples/referenced-from-script/_config.js new file mode 100644 index 0000000000..191a52f8cc --- /dev/null +++ b/test/vars/samples/referenced-from-script/_config.js @@ -0,0 +1,160 @@ +export default { + test(assert, vars) { + assert.deepEqual(vars, [ + { + name: 'i', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false, + referenced_from_script: false, + }, + { + name: 'j', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false, + referenced_from_script: false, + }, + { + name: 'k', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false, + referenced_from_script: false, + }, + { + name: 'a', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: true, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'b', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'c', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'd', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'e', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: false, + }, + { + name: 'f', + export_name: 'f', + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: false, + }, + { + name: 'g', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'h', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: true, + referenced: false, + writable: true, + referenced_from_script: true, + }, + { + name: 'foo', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false, + referenced_from_script: false, + }, + { + name: 'l', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + referenced_from_script: true, + writable: false, + }, + { + name: 'bar', + export_name: 'bar', + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false, + referenced_from_script: false, + }, + ]); + }, +}; diff --git a/test/vars/samples/referenced-from-script/input.svelte b/test/vars/samples/referenced-from-script/input.svelte new file mode 100644 index 0000000000..fbec4e6cf7 --- /dev/null +++ b/test/vars/samples/referenced-from-script/input.svelte @@ -0,0 +1,16 @@ + diff --git a/test/vars/samples/store-referenced/_config.js b/test/vars/samples/store-referenced/_config.js index 632a9e5b3f..bac35d1dba 100644 --- a/test/vars/samples/store-referenced/_config.js +++ b/test/vars/samples/store-referenced/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: false, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: true, reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/store-unreferenced/_config.js b/test/vars/samples/store-unreferenced/_config.js index 86e467c859..4965e52fec 100644 --- a/test/vars/samples/store-unreferenced/_config.js +++ b/test/vars/samples/store-unreferenced/_config.js @@ -9,6 +9,7 @@ export default { mutated: false, reassigned: false, referenced: true, + referenced_from_script: true, writable: true }, { @@ -19,6 +20,7 @@ export default { mutated: true, reassigned: false, referenced: false, + referenced_from_script: false, writable: true } ]); diff --git a/test/vars/samples/template-references/_config.js b/test/vars/samples/template-references/_config.js index adacc0d2ef..674e351517 100644 --- a/test/vars/samples/template-references/_config.js +++ b/test/vars/samples/template-references/_config.js @@ -9,6 +9,7 @@ export default { name: 'Bar', reassigned: false, referenced: true, + referenced_from_script: false, writable: false, }, { @@ -19,6 +20,7 @@ export default { name: 'foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: true, }, { @@ -29,6 +31,7 @@ export default { name: 'baz', reassigned: false, referenced: true, + referenced_from_script: false, writable: true, }, ]); diff --git a/test/vars/samples/transitions/_config.js b/test/vars/samples/transitions/_config.js index b2522a1b56..29a99b16cc 100644 --- a/test/vars/samples/transitions/_config.js +++ b/test/vars/samples/transitions/_config.js @@ -9,6 +9,7 @@ export default { name: 'hoistable_foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: false }, { @@ -19,6 +20,7 @@ export default { name: 'hoistable_bar', reassigned: false, referenced: true, + referenced_from_script: false, writable: false }, { @@ -29,6 +31,7 @@ export default { name: 'hoistable_baz', reassigned: false, referenced: true, + referenced_from_script: false, writable: false }, { @@ -39,6 +42,7 @@ export default { name: 'foo', reassigned: false, referenced: true, + referenced_from_script: false, writable: true }, { @@ -49,6 +53,7 @@ export default { name: 'bar', reassigned: false, referenced: true, + referenced_from_script: false, writable: true }, { @@ -59,6 +64,7 @@ export default { name: 'baz', reassigned: false, referenced: true, + referenced_from_script: false, writable: true } ]); From 9f7565cf198803acb4bd5a0c1b901b8137a94ab7 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 27 Oct 2019 13:53:17 +0800 Subject: [PATCH 101/413] fix changelog issue link --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c4adac7b..924413bc02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,10 @@ Also: * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Fix application of style scoping class in cases of ambiguity ([#3544](https://github.com/sveltejs/svelte/issues/3544)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) -* Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) -* Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issue/3595)) -* Fix `bind:this` binding to a store ([#3591](https://github.com/sveltejs/svelte/issue/3591)) -* Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) +* Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issues/3588)) +* Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issues/3595)) +* Fix `bind:this` binding to a store ([#3591](https://github.com/sveltejs/svelte/issues/3591)) +* Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issues/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623)) * Clean up dead code emitted for ``s ([#3631](https://github.com/sveltejs/svelte/issues/3631)) From 9f48d1a5fd9ec50d5eb630ad97fb11e84f39855a Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 27 Oct 2019 08:53:01 -0400 Subject: [PATCH 102/413] fix SSR spread with boolean attributes (#3797) * in SSR, adjust spread with boolean attributes (#2916) * add tests * update changelog --- CHANGELOG.md | 2 +- .../compile/render_ssr/handlers/Element.ts | 42 +------------------ .../handlers/shared/boolean_attributes.ts | 27 ++++++++++++ src/runtime/internal/ssr.ts | 15 +++---- .../samples/attribute-boolean/_expected.html | 1 + .../samples/attribute-boolean/main.svelte | 1 + .../spread-attributes-boolean/_expected.html | 2 + .../spread-attributes-boolean/main.svelte | 2 + 8 files changed, 43 insertions(+), 49 deletions(-) create mode 100644 src/compiler/compile/render_ssr/handlers/shared/boolean_attributes.ts create mode 100644 test/server-side-rendering/samples/spread-attributes-boolean/_expected.html create mode 100644 test/server-side-rendering/samples/spread-attributes-boolean/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 924413bc02..40acabf61c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Also: * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) -* Fix several bugs related to interaction of `{...spread}` attributes with other features ([#2721](https://github.com/sveltejs/svelte/issues/2721), [#3421](https://github.com/sveltejs/svelte/issues/3421), [#3681](https://github.com/sveltejs/svelte/issues/3681), [#3764](https://github.com/sveltejs/svelte/issues/3764), [#3790](https://github.com/sveltejs/svelte/issues/3790)) +* Fix several bugs related to interaction of `{...spread}` attributes with other features ([#2721](https://github.com/sveltejs/svelte/issues/2721), [#2916](https://github.com/sveltejs/svelte/issues/2916), [#3421](https://github.com/sveltejs/svelte/issues/3421), [#3681](https://github.com/sveltejs/svelte/issues/3681), [#3764](https://github.com/sveltejs/svelte/issues/3764), [#3790](https://github.com/sveltejs/svelte/issues/3790)) * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Fix application of style scoping class in cases of ambiguity ([#3544](https://github.com/sveltejs/svelte/issues/3544)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index 65013a8d07..c77a44990c 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -1,52 +1,12 @@ import { is_void } from '../../../utils/names'; import { get_attribute_value, get_class_attribute_value } from './shared/get_attribute_value'; import { get_slot_scope } from './shared/get_slot_scope'; +import { boolean_attributes } from './shared/boolean_attributes'; import Renderer, { RenderOptions } from '../Renderer'; import Element from '../../nodes/Element'; import { x } from 'code-red'; import Expression from '../../nodes/shared/Expression'; -// source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7 -const boolean_attributes = new Set([ - 'async', - 'autocomplete', - 'autofocus', - 'autoplay', - 'border', - 'challenge', - 'checked', - 'compact', - 'contenteditable', - 'controls', - 'default', - 'defer', - 'disabled', - 'formnovalidate', - 'frameborder', - 'hidden', - 'indeterminate', - 'ismap', - 'loop', - 'multiple', - 'muted', - 'nohref', - 'noresize', - 'noshade', - 'novalidate', - 'nowrap', - 'open', - 'readonly', - 'required', - 'reversed', - 'scoped', - 'scrolling', - 'seamless', - 'selected', - 'sortable', - 'spellcheck', - 'translate' -]); - export default function(node: Element, renderer: Renderer, options: RenderOptions & { slot_scopes: Map; }) { diff --git a/src/compiler/compile/render_ssr/handlers/shared/boolean_attributes.ts b/src/compiler/compile/render_ssr/handlers/shared/boolean_attributes.ts new file mode 100644 index 0000000000..4520a2064e --- /dev/null +++ b/src/compiler/compile/render_ssr/handlers/shared/boolean_attributes.ts @@ -0,0 +1,27 @@ +// source: https://html.spec.whatwg.org/multipage/indices.html +export const boolean_attributes = new Set([ + 'allowfullscreen', + 'allowpaymentrequest', + 'async', + 'autofocus', + 'autoplay', + 'checked', + 'controls', + 'default', + 'defer', + 'disabled', + 'formnovalidate', + 'hidden', + 'ismap', + 'loop', + 'multiple', + 'muted', + 'nomodule', + 'novalidate', + 'open', + 'playsinline', + 'readonly', + 'required', + 'reversed', + 'selected' +]); diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index 83e585a899..274006f243 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -1,5 +1,6 @@ import { set_current_component, current_component } from './lifecycle'; import { run_all, blank_object } from './utils'; +import { boolean_attributes } from '../../compiler/compile/render_ssr/handlers/shared/boolean_attributes'; export const invalid_attribute_name_character = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u; // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 @@ -20,14 +21,14 @@ export function spread(args, classes_to_add) { if (invalid_attribute_name_character.test(name)) return; const value = attributes[name]; - if (value == null) return; if (value === true) str += " " + name; - - const escaped = String(value) - .replace(/"/g, '"') - .replace(/'/g, '''); - - str += " " + name + "=" + JSON.stringify(escaped); + else if (boolean_attributes.has(name.toLowerCase())) { + if (value) str += " " + name; + } else if (value != null) { + str += " " + name + "=" + JSON.stringify(String(value) + .replace(/"/g, '"') + .replace(/'/g, ''')); + } }); return str; diff --git a/test/server-side-rendering/samples/attribute-boolean/_expected.html b/test/server-side-rendering/samples/attribute-boolean/_expected.html index 3ca3bfd9a8..5b36bb6c3f 100644 --- a/test/server-side-rendering/samples/attribute-boolean/_expected.html +++ b/test/server-side-rendering/samples/attribute-boolean/_expected.html @@ -1 +1,2 @@ + diff --git a/test/server-side-rendering/samples/attribute-boolean/main.svelte b/test/server-side-rendering/samples/attribute-boolean/main.svelte index 3ca3bfd9a8..0852e12418 100644 --- a/test/server-side-rendering/samples/attribute-boolean/main.svelte +++ b/test/server-side-rendering/samples/attribute-boolean/main.svelte @@ -1 +1,2 @@ + diff --git a/test/server-side-rendering/samples/spread-attributes-boolean/_expected.html b/test/server-side-rendering/samples/spread-attributes-boolean/_expected.html new file mode 100644 index 0000000000..06048d3efa --- /dev/null +++ b/test/server-side-rendering/samples/spread-attributes-boolean/_expected.html @@ -0,0 +1,2 @@ + + diff --git a/test/server-side-rendering/samples/spread-attributes-boolean/main.svelte b/test/server-side-rendering/samples/spread-attributes-boolean/main.svelte new file mode 100644 index 0000000000..3d865c0082 --- /dev/null +++ b/test/server-side-rendering/samples/spread-attributes-boolean/main.svelte @@ -0,0 +1,2 @@ + + From 7c445093fb97c2073c10dd6711ea3205eca328b9 Mon Sep 17 00:00:00 2001 From: pngwn Date: Sun, 27 Oct 2019 12:57:21 +0000 Subject: [PATCH 103/413] Document bind:playbackRate in the API documentation. Closes #3806. --- site/content/docs/02-template-syntax.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index da731d920a..694010dfe7 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -570,9 +570,10 @@ Media elements (`