Skip to content

Commit

Permalink
(fix) use let for #each block
Browse files Browse the repository at this point in the history
it's allowed to reassign them inside the loop
sveltejs#1352
  • Loading branch information
dummdidumm committed Sep 15, 2022
1 parent cb94f4b commit 56774e1
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function test(useNewTransformation: boolean) {
},
{
name: 'foo',
kind: 14,
kind: 13,
location: {
uri: getUri('documentsymbols.svelte'),
range: {
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export function handleEach(str: MagicString, eachBlock: BaseNode): void {
transforms = [
`{ const $$_each = __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
[eachBlock.expression.start, eachBlock.expression.end],
`${containsComma ? ')' : ''}); for(const `,
`${containsComma ? ')' : ''}); for(let `,
[eachBlock.context.start, eachBlock.context.end],
' of $$_each){'
];
} else {
transforms = [
'for(const ',
'for(let ',
[eachBlock.context.start, eachBlock.context.end],
` of __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
[eachBlock.expression.start, eachBlock.expression.end],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray((true, items))){
for(let item of __sveltets_2_ensureArray((true, items))){
{ svelteHTML.createElement("div", {});item; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(items)){
for(let item of __sveltets_2_ensureArray(items)){
{ svelteHTML.createElement("div", {});item; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(items)){let i = 1;
for(let item of __sveltets_2_ensureArray(items)){let i = 1;
{ svelteHTML.createElement("div", {});item;i; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for(const item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
for(let item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
{ svelteHTML.createElement("div", {});item;i; }
}
{ svelteHTML.createElement("div", {}); }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
for(let item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
{ svelteHTML.createElement("div", {});item;i; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(items ?? [])){
for(let item of __sveltets_2_ensureArray(items ?? [])){
{ svelteHTML.createElement("div", {});item; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(someObject?.items)){
for(let item of __sveltets_2_ensureArray(someObject?.items)){
{ svelteHTML.createElement("div", {});item; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const item of __sveltets_2_ensureArray(list)){item;
for(let item of __sveltets_2_ensureArray(list)){item;
{ svelteHTML.createElement("li", { });__sveltets_2_ensureAnimation(flip(svelteHTML.mapElementTag('li'),__sveltets_2_AnimationMove,(opt?.)));item; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for(const str of __sveltets_2_ensureArray([''])){
for(let str of __sveltets_2_ensureArray([''])){
const lower = str.;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
if(hello){
for(const hello of __sveltets_2_ensureArray(items)){let i = 1;hello.id;
for(let hello of __sveltets_2_ensureArray(items)){let i = 1;hello.id;
{ svelteHTML.createElement("div", {});hello;i; }
if(hello){
for(const hello of __sveltets_2_ensureArray(items)){
for(let hello of __sveltets_2_ensureArray(items)){
if(hello){
hello;
}
}
for(const foo of __sveltets_2_ensureArray(items)){
for(let foo of __sveltets_2_ensureArray(items)){
const hello = foo;
if(hello){
hello;
Expand All @@ -20,25 +20,25 @@ if(hello){
}

if(hi && bye){
for(const bye of __sveltets_2_ensureArray(items)){
for(let bye of __sveltets_2_ensureArray(items)){
{ svelteHTML.createElement("div", {});bye; }
}
if(bye){
bye;
}

} else if (cool){
for(const item of __sveltets_2_ensureArray(items)){let cool = 1;
for(let item of __sveltets_2_ensureArray(items)){let cool = 1;
{ svelteHTML.createElement("div", {});item;cool; }
}
}else{
for(const hello of __sveltets_2_ensureArray(items)){
for(let hello of __sveltets_2_ensureArray(items)){
{ svelteHTML.createElement("div", {});hello; }
}
}
}

for(const hello of __sveltets_2_ensureArray(items)){let i = 1;
for(let hello of __sveltets_2_ensureArray(items)){let i = 1;
if(hello && i && bye){
hello; i; bye;
} else if (hello && i && bye){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
if(hello){
for(const item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
for(let item of __sveltets_2_ensureArray(items)){let i = 1;item.id;
{ svelteHTML.createElement("div", {});item;i; }
}
if(hi && bye){
for(const item of __sveltets_2_ensureArray(items)){
for(let item of __sveltets_2_ensureArray(items)){
{ svelteHTML.createElement("div", {});item; }
}
{ svelteHTML.createElement("p", {}); }

} else if (cool){
for(const item of __sveltets_2_ensureArray(items)){let i = 1;
for(let item of __sveltets_2_ensureArray(items)){let i = 1;
{ svelteHTML.createElement("div", {});item;i; }
}
}else{
for(const item of __sveltets_2_ensureArray(items)){
for(let item of __sveltets_2_ensureArray(items)){
{ svelteHTML.createElement("div", {});item; }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(true){
if(true){} else if (true){}
}else{
for(const _ of __sveltets_2_ensureArray([])){}
for(let _ of __sveltets_2_ensureArray([])){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async () => {
}

{ svelteHTML.createElement("svg", { "on:click":handleClick,});
for(const circle of __sveltets_2_ensureArray(circles)){
for(let circle of __sveltets_2_ensureArray(circles)){
{ svelteHTML.createElement("circle", { "cx":circle.cx,"cy":circle.cy,"r":circle.r,"on:click":event => select(circle, event),"on:contextmenu":() => {
adjusting = !adjusting;
if (adjusting) selected = circle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { for(const item of __sveltets_2_ensureArray(items)){
async () => { for(let item of __sveltets_2_ensureArray(items)){
{ __sveltets_createSlot("default", { "a":item,}); }
}
for(const { a } of __sveltets_2_ensureArray(items2)){
for(let { a } of __sveltets_2_ensureArray(items2)){
{ __sveltets_createSlot("second", { a,}); }
}};
return { props: {}, slots: {'default': {a:__sveltets_1_unwrapArr(items)}, 'second': {a:(({ a }) => a)(__sveltets_1_unwrapArr(items2))}}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { for(const item of __sveltets_2_ensureArray(items)){
for(const { a } of __sveltets_2_ensureArray(item)){
async () => { for(let item of __sveltets_2_ensureArray(items)){
for(let { a } of __sveltets_2_ensureArray(item)){
{ __sveltets_createSlot("default", {a,}); }
}
{ __sveltets_createSlot("second", { a,}); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { for(const item of __sveltets_2_ensureArray(items)){
async () => { for(let item of __sveltets_2_ensureArray(items)){
{ __sveltets_createSlot("default", { "a":item,"b":{ item },"c":{ item: 'abc' }.item,"d":{ item: item },"e":$item,"f":$item,...g,...item,}); }
}};
return { props: {}, slots: {'default': {a:__sveltets_1_unwrapArr(items), b:{ item:__sveltets_1_unwrapArr(items) }, c:{ item: 'abc' }.item, d:{ item: __sveltets_1_unwrapArr(items) }, e:$item, f:$item, ...g, ...__sveltets_1_unwrapArr(items)}}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///<reference types="svelte" />
;function render() {
/*Ωignore_startΩ*/;const __sveltets_createSlot = __sveltets_2_createCreateSlot();/*Ωignore_endΩ*/
async () => { { const $$_each = __sveltets_2_ensureArray(items); for(const items of $$_each){
async () => { { const $$_each = __sveltets_2_ensureArray(items); for(let items of $$_each){
{ __sveltets_createSlot("default", { "a":items,}); }
}}};
return { props: {}, slots: {'default': {a:__sveltets_1_unwrapArr(items)}}, getters: {}, events: {} }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
;
async () => {

for(const { width, height } of __sveltets_2_ensureArray(boxes)){
for(let { width, height } of __sveltets_2_ensureArray(boxes)){
const {area, volume} = calculate(width, height, constant);
const perimeter = (width + height) * constant;
const [_width, _height, sum] = [width * constant, height, width * constant + height];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
;
async () => {

for(const box of __sveltets_2_ensureArray(boxes)){
for(let box of __sveltets_2_ensureArray(boxes)){
const {area, volume} = calculate(box.width, box.height, constant);
const perimeter = (box.width + box.height) * constant;
const [width, height, sum] = [box.width * constant, box.height, box.width * constant + box.height];
Expand Down

0 comments on commit 56774e1

Please sign in to comment.