Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sveltosis: Treat arrow functions as regular function declarations #1188

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5251,6 +5251,26 @@ exports[`Alpine.js > svelte > Javascript Test > eventHandlers 1`] = `
"
`;

exports[`Alpine.js > svelte > Javascript Test > fatArrowFunctions 1`] = `
"<div x-data=\\"myComponent()\\">
<button x-on:click=\\"clickHandler1($event)\\">Button 1</button>
<button x-on:click=\\"clickHandler2($event)\\">Button 2</button>
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"myComponent\\", () => ({
clickHandler1: (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
}),
clickHandler2: function clickHandler2(event) {
console.log(\\"do something 2\\");
},
}));
});
</script>
"
`;

exports[`Alpine.js > svelte > Javascript Test > html 1`] = `
"<div x-data=\\"myComponent()\\" x-bind:innerHTML=\\"html\\"></div>
<script>
Expand Down Expand Up @@ -5565,6 +5585,26 @@ exports[`Alpine.js > svelte > Typescript Test > eventHandlers 1`] = `
"
`;

exports[`Alpine.js > svelte > Typescript Test > fatArrowFunctions 1`] = `
"<div x-data=\\"myComponent()\\">
<button x-on:click=\\"clickHandler1($event)\\">Button 1</button>
<button x-on:click=\\"clickHandler2($event)\\">Button 2</button>
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"myComponent\\", () => ({
clickHandler1: (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
}),
clickHandler2: function clickHandler2(event) {
console.log(\\"do something 2\\");
},
}));
});
</script>
"
`;

exports[`Alpine.js > svelte > Typescript Test > html 1`] = `
"<div x-data=\\"myComponent()\\" x-bind:innerHTML=\\"html\\"></div>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8799,6 +8799,39 @@ export class MyComponentModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > svelte > Javascript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > svelte > Javascript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -9328,6 +9361,39 @@ export class MyComponentModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > svelte > Typescript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > svelte > Typescript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8993,6 +8993,40 @@ export class MyComponentModule {}
"
`;

exports[`Angular with Import Mapper Tests > svelte > Javascript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
bootstrap: [SomeOtherComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular with Import Mapper Tests > svelte > Javascript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -9538,6 +9572,40 @@ export class MyComponentModule {}
"
`;

exports[`Angular with Import Mapper Tests > svelte > Typescript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
bootstrap: [SomeOtherComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular with Import Mapper Tests > svelte > Typescript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
118 changes: 118 additions & 0 deletions packages/core/src/__tests__/__snapshots__/angular.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16214,6 +16214,65 @@ export class MyComponent {
"
`;

exports[`Angular > svelte > Javascript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular > svelte > Javascript Test > fatArrowFunctions 2`] = `
"import { Component } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
standalone: true,
imports: [CommonModule],
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}
"
`;

exports[`Angular > svelte > Javascript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -17158,6 +17217,65 @@ export class MyComponent {
"
`;

exports[`Angular > svelte > Typescript Test > fatArrowFunctions 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}

@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
})
export class MyComponentModule {}
"
`;

exports[`Angular > svelte > Typescript Test > fatArrowFunctions 2`] = `
"import { Component } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

@Component({
selector: \\"my-component, MyComponent\\",
template: \`
<ng-container>
<button (click)=\\"clickHandler1($event)\\">Button 1</button>
<button (click)=\\"clickHandler2($event)\\">Button 2</button>
</ng-container>
\`,
standalone: true,
imports: [CommonModule],
})
export class MyComponent {
clickHandler1 = (this.clickHandler1 = (event) => {
console.log(\\"do something 1\\");
});
clickHandler2 = function clickHandler2(event) {
console.log(\\"do something 2\\");
};
}
"
`;

exports[`Angular > svelte > Typescript Test > html 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Loading