Skip to content

Commit

Permalink
fix: async functions in store are preserved (#1612)
Browse files Browse the repository at this point in the history
* test: add failing test

* preserve async status

* add fix

* fix path

* better fix

* snapshots

* changeset

* snapshots

* workarounds do not apply for async fns

* add comments

* add another test case

* account for object methods too

* add comment

* remove log

* update snapshots

* style
  • Loading branch information
liamdebeasi authored Oct 28, 2024
1 parent f87b9e5 commit 5e2cf3c
Show file tree
Hide file tree
Showing 35 changed files with 1,935 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-phones-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

respect async with anonymous arrow function in state
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 @@ -2629,6 +2629,26 @@ exports[`Alpine.js > jsx > Javascript Test > spreadProps 1`] = `
"
`;
exports[`Alpine.js > jsx > Javascript Test > store-async-function 1`] = `
"<div x-data=\\"stringLiteralStore()\\"></div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"stringLiteralStore\\", () => ({
arrowFunction: async function arrowFunction() {
return Promise.resolve();
},
namedFunction: async function namedFunction() {
return Promise.resolve();
},
fetchUsers: async function fetchUsers() {
return Promise.resolve();
},
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Javascript Test > string-literal-store 1`] = `
"<div x-data=\\"stringLiteralStore()\\"><span x-html=\\"foo\\"></span></div>
<script>
Expand Down Expand Up @@ -5517,6 +5537,26 @@ exports[`Alpine.js > jsx > Typescript Test > spreadProps 1`] = `
"
`;
exports[`Alpine.js > jsx > Typescript Test > store-async-function 1`] = `
"<div x-data=\\"stringLiteralStore()\\"></div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"stringLiteralStore\\", () => ({
arrowFunction: async function arrowFunction() {
return Promise.resolve();
},
namedFunction: async function namedFunction() {
return Promise.resolve();
},
fetchUsers: async function fetchUsers() {
return Promise.resolve();
},
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Typescript Test > string-literal-store 1`] = `
"<div x-data=\\"stringLiteralStore()\\"><span x-html=\\"foo\\"></span></div>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6324,6 +6324,46 @@ export class MyComponentModule {}
"
`;

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

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > string-literal-store 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -13814,6 +13854,46 @@ export class MyComponentModule {}
"
`;

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

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > string-literal-store 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 @@ -6425,6 +6425,47 @@ export class MyComponentModule {}
"
`;

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

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with Import Mapper Tests > jsx > Javascript Test > string-literal-store 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -14034,6 +14075,47 @@ export class MyComponentModule {}
"
`;

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

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with Import Mapper Tests > jsx > Typescript Test > string-literal-store 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 @@ -6510,6 +6510,46 @@ export class MyComponentModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > store-async-function 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > string-literal-store 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -14255,6 +14295,46 @@ export class MyComponentModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > store-async-function 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

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

@Component({
selector: \\"string-literal-store\\",
template: \`
<div></div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class StringLiteralStore {
arrowFunction = async function arrowFunction() {
return Promise.resolve();
};
namedFunction = async function namedFunction() {
return Promise.resolve();
};
fetchUsers = async function fetchUsers() {
return Promise.resolve();
};
}

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

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > string-literal-store 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Loading

0 comments on commit 5e2cf3c

Please sign in to comment.