diff --git a/.changeset/fluffy-eyes-add.md b/.changeset/fluffy-eyes-add.md new file mode 100644 index 0000000000..b8f02f1215 --- /dev/null +++ b/.changeset/fluffy-eyes-add.md @@ -0,0 +1,5 @@ +--- +'@builder.io/mitosis': patch +--- + +[react]: Changed `defaultProps` generation for react, because defaultProps for function components is deprecated diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3c6efb9149..8add094731 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -145,3 +145,21 @@ jobs: - name: Run E2E tests run: yarn ci:e2e + + - name: 🆙 Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: playwright-results + path: ./e2e/e2e-app/test-results + retention-days: 14 + + - name: 🆙 Upload e2e builds + if: failure() + uses: actions/upload-artifact@v4 + with: + name: e2e-builds + path: | + ./e2e/**/dist + !**/node_modules/** + retention-days: 14 diff --git a/e2e/e2e-app/src/component-paths.ts b/e2e/e2e-app/src/component-paths.ts index 11a06ff467..b5c68f7ede 100644 --- a/e2e/e2e-app/src/component-paths.ts +++ b/e2e/e2e-app/src/component-paths.ts @@ -1,4 +1,5 @@ export const COMPONENT_PATHS = [ + '/default-props/', '/one-component/', '/two-components/', '/types/', diff --git a/e2e/e2e-app/src/components/default-props/use-default-props.lite.tsx b/e2e/e2e-app/src/components/default-props/use-default-props.lite.tsx new file mode 100644 index 0000000000..828d588a90 --- /dev/null +++ b/e2e/e2e-app/src/components/default-props/use-default-props.lite.tsx @@ -0,0 +1,18 @@ +import { useDefaultProps, useStore } from '@builder.io/mitosis'; + +useDefaultProps({ foo: 'abc', bar: 'foo' }); + +type DefaultPropsType = { + foo?: string; + bar?: string; +}; + +export default function DefaultProps(props: DefaultPropsType) { + const state = useStore({ + getProps: () => { + return JSON.stringify({ foo: props.foo, bar: props.bar }); + }, + }); + + return
{state.getProps()}
; +} diff --git a/e2e/e2e-app/src/homepage.lite.tsx b/e2e/e2e-app/src/homepage.lite.tsx index 854dc7669b..7f6939aa4f 100644 --- a/e2e/e2e-app/src/homepage.lite.tsx +++ b/e2e/e2e-app/src/homepage.lite.tsx @@ -1,6 +1,7 @@ import { For, onMount, Show, useStore } from '@builder.io/mitosis'; import { COMPONENT_PATHS } from './component-paths'; import ComponentWithTypes from './components/component-with-types.lite'; +import DefaultProps from './components/default-props/use-default-props.lite'; import DisabledInput from './components/disabled-input/disabled-input.lite'; import NestedParent from './components/nested/nested-parent.lite'; import OneComponent from './components/one-component.lite'; @@ -42,6 +43,10 @@ export default function Homepage(props: { pathname?: string }) { + + + + diff --git a/e2e/e2e-app/tests/main.spec.ts b/e2e/e2e-app/tests/main.spec.ts index 2e11318a14..a40683081f 100644 --- a/e2e/e2e-app/tests/main.spec.ts +++ b/e2e/e2e-app/tests/main.spec.ts @@ -7,6 +7,18 @@ const test = playwrightTest.extend<{ packageName: PackageName | 'DEFAULT' }>({ }); test.describe('e2e', () => { + test('default props', async ({ page, packageName }) => { + // TODO: Some targets don't support `defaultProps` :( + if (['e2e-qwik', 'e2e-solid'].includes(packageName)) { + test.skip(); + } + + await page.goto('/default-props/'); + const text = await page.getByTestId('default-props').textContent(); + + expect(text?.includes('abc')).toBeTruthy(); + expect(text?.includes('xyz')).toBeTruthy(); + }); test('todo list add', async ({ page }) => { await page.goto('/one-component/'); diff --git a/e2e/e2e-react/src/App.tsx b/e2e/e2e-react/src/App.tsx index baa8978e4e..3e301d8b82 100644 --- a/e2e/e2e-react/src/App.tsx +++ b/e2e/e2e-react/src/App.tsx @@ -1,4 +1,5 @@ // Mitosis output for not yet include .d.ts, so ignore the types when importing. +// Trigger nx remote cache: 1 // @ts-ignore import { E2eApp } from '@builder.io/e2e-app/react'; diff --git a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap index 09c985ebb8..296eaffb75 100644 --- a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap @@ -2967,6 +2967,20 @@ exports[`Alpine.js > jsx > Javascript Test > typeDependency 1`] = ` " `; +exports[`Alpine.js > jsx > Javascript Test > typeExternalProps 1`] = ` +"
+ Hello + + ! +
+ +" +`; + exports[`Alpine.js > jsx > Javascript Test > typeExternalStore 1`] = ` "
Hello @@ -6085,6 +6099,20 @@ exports[`Alpine.js > jsx > Typescript Test > typeDependency 1`] = ` " `; +exports[`Alpine.js > jsx > Typescript Test > typeExternalProps 1`] = ` +"
+ Hello + + ! +
+ +" +`; + exports[`Alpine.js > jsx > Typescript Test > typeExternalStore 1`] = ` "
Hello diff --git a/packages/core/src/__tests__/__snapshots__/angular.import.test.ts.snap b/packages/core/src/__tests__/__snapshots__/angular.import.test.ts.snap index fd29d4e5e0..b5a14b03dd 100644 --- a/packages/core/src/__tests__/__snapshots__/angular.import.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/angular.import.test.ts.snap @@ -7140,6 +7140,38 @@ export class TypeDependencyModule {} " `; +exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; @@ -15133,6 +15165,40 @@ export class TypeDependencyModule {} " `; +exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; diff --git a/packages/core/src/__tests__/__snapshots__/angular.mapper.test.ts.snap b/packages/core/src/__tests__/__snapshots__/angular.mapper.test.ts.snap index 678825f373..35aedeeab1 100644 --- a/packages/core/src/__tests__/__snapshots__/angular.mapper.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/angular.mapper.test.ts.snap @@ -7259,6 +7259,39 @@ export class TypeDependencyModule {} " `; +exports[`Angular with Import Mapper Tests > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], + bootstrap: [SomeOtherComponent], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with Import Mapper Tests > jsx > Javascript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; @@ -15382,6 +15415,41 @@ export class TypeDependencyModule {} " `; +exports[`Angular with Import Mapper Tests > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], + bootstrap: [SomeOtherComponent], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with Import Mapper Tests > jsx > Typescript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; diff --git a/packages/core/src/__tests__/__snapshots__/angular.state.test.ts.snap b/packages/core/src/__tests__/__snapshots__/angular.state.test.ts.snap index df0e55ee93..d2343e27fc 100644 --- a/packages/core/src/__tests__/__snapshots__/angular.state.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/angular.state.test.ts.snap @@ -7357,6 +7357,38 @@ export class TypeDependencyModule {} " `; +exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; @@ -15626,6 +15658,40 @@ export class TypeDependencyModule {} " `; +exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; diff --git a/packages/core/src/__tests__/__snapshots__/angular.styles.test.ts.snap b/packages/core/src/__tests__/__snapshots__/angular.styles.test.ts.snap index dfef1606d6..3383a69abc 100644 --- a/packages/core/src/__tests__/__snapshots__/angular.styles.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/angular.styles.test.ts.snap @@ -6371,6 +6371,31 @@ export class TypeDependencyModule {} " `; +exports[`Angular with visuallyIgnoreHostElement = false > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, +}) +export default class TypeExternalProps { + @Input() name; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with visuallyIgnoreHostElement = false > jsx > Javascript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; @@ -13542,6 +13567,33 @@ export class TypeDependencyModule {} " `; +exports[`Angular with visuallyIgnoreHostElement = false > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + exports[`Angular with visuallyIgnoreHostElement = false > jsx > Typescript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; diff --git a/packages/core/src/__tests__/__snapshots__/angular.test.ts.snap b/packages/core/src/__tests__/__snapshots__/angular.test.ts.snap index 7da64dcada..35a9c9694e 100644 --- a/packages/core/src/__tests__/__snapshots__/angular.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/angular.test.ts.snap @@ -13415,6 +13415,63 @@ export default class TypeDependency { " `; +exports[`Angular > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + +exports[`Angular > jsx > Javascript Test > typeExternalProps 2`] = ` +"import { Component, Input } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], + standalone: true, + imports: [CommonModule], +}) +export default class TypeExternalProps { + @Input() name; +} +" +`; + exports[`Angular > jsx > Javascript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; @@ -28471,6 +28528,67 @@ export default class TypeDependency { " `; +exports[`Angular > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { NgModule } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { Component, Input } from \\"@angular/core\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} + +@NgModule({ + declarations: [TypeExternalProps], + imports: [CommonModule], + exports: [TypeExternalProps], +}) +export class TypeExternalPropsModule {} +" +`; + +exports[`Angular > jsx > Typescript Test > typeExternalProps 2`] = ` +"import { Component, Input } from \\"@angular/core\\"; +import { CommonModule } from \\"@angular/common\\"; + +import { FooProps } from \\"./foo-props\\"; + +@Component({ + selector: \\"type-external-props\\", + template: \` +
Hello {{name}} !
+ \`, + styles: [ + \` + :host { + display: contents; + } + \`, + ], + standalone: true, + imports: [CommonModule], +}) +export default class TypeExternalProps { + @Input() name!: FooProps[\\"name\\"]; +} +" +`; + exports[`Angular > jsx > Typescript Test > typeExternalStore 1`] = ` "import { NgModule } from \\"@angular/core\\"; import { CommonModule } from \\"@angular/common\\"; diff --git a/packages/core/src/__tests__/__snapshots__/html.test.ts.snap b/packages/core/src/__tests__/__snapshots__/html.test.ts.snap index 8d57f9a86c..077c1bb386 100644 --- a/packages/core/src/__tests__/__snapshots__/html.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/html.test.ts.snap @@ -7540,6 +7540,64 @@ exports[`Html > jsx > Javascript Test > typeDependency 1`] = ` " `; +exports[`Html > jsx > Javascript Test > typeExternalProps 1`] = ` +"
+ Hello + + ! +
+ +" +`; + exports[`Html > jsx > Javascript Test > typeExternalStore 1`] = ` "
Hello @@ -15388,6 +15446,64 @@ exports[`Html > jsx > Typescript Test > typeDependency 1`] = ` " `; +exports[`Html > jsx > Typescript Test > typeExternalProps 1`] = ` +"
+ Hello + + ! +
+ +" +`; + exports[`Html > jsx > Typescript Test > typeExternalStore 1`] = ` "
Hello diff --git a/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap b/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap index a34f841bd7..0e4bd98731 100644 --- a/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap @@ -943,6 +943,11 @@ exports[`Liquid > jsx > Javascript Test > typeDependency 1`] = ` " `; +exports[`Liquid > jsx > Javascript Test > typeExternalProps 1`] = ` +"
Hello {{name}} !
+" +`; + exports[`Liquid > jsx > Javascript Test > typeExternalStore 1`] = ` "
Hello {{_name}} !
" @@ -1957,6 +1962,11 @@ exports[`Liquid > jsx > Typescript Test > typeDependency 1`] = ` " `; +exports[`Liquid > jsx > Typescript Test > typeExternalProps 1`] = ` +"
Hello {{name}} !
+" +`; + exports[`Liquid > jsx > Typescript Test > typeExternalStore 1`] = ` "
Hello {{_name}} !
" diff --git a/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap b/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap index c7b341db53..119bbd88df 100644 --- a/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap @@ -4448,6 +4448,29 @@ export default class TypeDependency extends LitElement { " `; +exports[`Lit > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { LitElement, html, css } from \\"lit\\"; +import { customElement, property, state, query } from \\"lit/decorators.js\\"; + +@customElement(\\"type-external-props\\") +export default class TypeExternalProps extends LitElement { + createRenderRoot() { + return this; + } + + @property() name: any; + + render() { + return html\` + +
Hello \${this.name} !
+ + \`; + } +} +" +`; + exports[`Lit > jsx > Javascript Test > typeExternalStore 1`] = ` "import { LitElement, html, css } from \\"lit\\"; import { customElement, property, state, query } from \\"lit/decorators.js\\"; @@ -9563,6 +9586,31 @@ export default class TypeDependency extends LitElement { " `; +exports[`Lit > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { FooProps } from \\"./foo-props\\"; + +import { LitElement, html, css } from \\"lit\\"; +import { customElement, property, state, query } from \\"lit/decorators.js\\"; + +@customElement(\\"type-external-props\\") +export default class TypeExternalProps extends LitElement { + createRenderRoot() { + return this; + } + + @property() name: any; + + render() { + return html\` + +
Hello \${this.name} !
+ + \`; + } +} +" +`; + exports[`Lit > jsx > Typescript Test > typeExternalStore 1`] = ` "import { FooStore } from \\"./foo-store\\"; diff --git a/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap b/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap index 2a786b2d27..644897dbf9 100644 --- a/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap @@ -2678,6 +2678,12 @@ exports[`Marko > jsx > Javascript Test > typeDependency 1`] = `
\${input.foo}
" `; +exports[`Marko > jsx > Javascript Test > typeExternalProps 1`] = ` +"class {} + +
Hello \${input.name} !
" +`; + exports[`Marko > jsx > Javascript Test > typeExternalStore 1`] = ` "class { onCreate() { @@ -5440,6 +5446,14 @@ class {}
\${input.foo}
" `; +exports[`Marko > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { FooProps } from \\"./foo-props\\"; + +class {} + +
Hello \${input.name} !
" +`; + exports[`Marko > jsx > Typescript Test > typeExternalStore 1`] = ` "import { FooStore } from \\"./foo-store\\"; diff --git a/packages/core/src/__tests__/__snapshots__/mitosis.test.ts.snap b/packages/core/src/__tests__/__snapshots__/mitosis.test.ts.snap index 8b2e56b818..3b825855cf 100644 --- a/packages/core/src/__tests__/__snapshots__/mitosis.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/mitosis.test.ts.snap @@ -2979,6 +2979,18 @@ exports[`Mitosis, format: legacy (native loops and conditionals) > jsx > Javascr " `; +exports[`Mitosis, format: legacy (native loops and conditionals) > jsx > Javascript Test > typeExternalProps 1`] = ` +"export default function TypeExternalProps(props) { + return [ +
+ Hello + {props.name}!{\\" \\"} +
, + ]; +} +" +`; + exports[`Mitosis, format: legacy (native loops and conditionals) > jsx > Javascript Test > typeExternalStore 1`] = ` "import { useStore } from \\"@builder.io/mitosis\\"; @@ -6504,6 +6516,20 @@ export default function TypeDependency(props) { " `; +exports[`Mitosis, format: legacy (native loops and conditionals) > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { FooProps } from \\"./foo-props\\"; + +export default function TypeExternalProps(props) { + return [ +
+ Hello + {props.name}!{\\" \\"} +
, + ]; +} +" +`; + exports[`Mitosis, format: legacy (native loops and conditionals) > jsx > Typescript Test > typeExternalStore 1`] = ` "import { useStore } from \\"@builder.io/mitosis\\"; @@ -10365,6 +10391,18 @@ exports[`Mitosis, format: legacy > jsx > Javascript Test > typeDependency 1`] = " `; +exports[`Mitosis, format: legacy > jsx > Javascript Test > typeExternalProps 1`] = ` +"export default function TypeExternalProps(props) { + return ( +
+ Hello + {props.name}!{\\" \\"} +
+ ); +} +" +`; + exports[`Mitosis, format: legacy > jsx > Javascript Test > typeExternalStore 1`] = ` "import { useStore } from \\"@builder.io/mitosis\\"; @@ -13959,6 +13997,20 @@ export default function TypeDependency(props) { " `; +exports[`Mitosis, format: legacy > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { FooProps } from \\"./foo-props\\"; + +export default function TypeExternalProps(props) { + return ( +
+ Hello + {props.name}!{\\" \\"} +
+ ); +} +" +`; + exports[`Mitosis, format: legacy > jsx > Typescript Test > typeExternalStore 1`] = ` "import { useStore } from \\"@builder.io/mitosis\\"; @@ -15417,6 +15469,12 @@ import * as React from \\"react\\"; import { useState } from \\"react\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -15454,12 +15512,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -16938,6 +16990,15 @@ exports[`Mitosis, format: react > jsx > Javascript Test > defaultProps 1`] = ` import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -16962,15 +17023,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -16980,6 +17032,13 @@ exports[`Mitosis, format: react > jsx > Javascript Test > defaultPropsOutsideCom import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -17004,13 +17063,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -17857,7 +17909,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -18293,6 +18344,17 @@ export default TypeDependency; " `; +exports[`Mitosis, format: react > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`Mitosis, format: react > jsx > Javascript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -19125,6 +19187,12 @@ import { useState } from \\"react\\"; import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -19162,12 +19230,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -20654,6 +20716,15 @@ exports[`Mitosis, format: react > jsx > Typescript Test > defaultProps 1`] = ` import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -20678,15 +20749,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -20696,6 +20758,13 @@ exports[`Mitosis, format: react > jsx > Typescript Test > defaultPropsOutsideCom import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -20720,13 +20789,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -21582,7 +21644,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -22020,6 +22081,18 @@ export default TypeDependency; " `; +exports[`Mitosis, format: react > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`Mitosis, format: react > jsx > Typescript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -22315,21 +22388,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`Mitosis, format: react > svelte > Javascript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={activeTab}>
{activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={activeTab}>
{activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`Mitosis, format: react > svelte > Javascript Test > each 1`] = ` @@ -22450,11 +22521,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -22718,21 +22787,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`Mitosis, format: react > svelte > Typescript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={activeTab}>
{activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={activeTab}>
{activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`Mitosis, format: react > svelte > Typescript Test > each 1`] = ` @@ -22853,11 +22920,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap b/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap index 57e1f1b0a7..97b2f26fe0 100644 --- a/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap @@ -12288,6 +12288,77 @@ exports[`Parse JSX > Javascript > typeDependency 1`] = ` } `; +exports[`Parse JSX > Javascript > typeExternalProps 1`] = ` +{ + "@type": "@builder.io/mitosis/component", + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": "Hello ", + }, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "_text": { + "bindingType": "expression", + "code": "props.name", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": "! ", + }, + "scope": {}, + }, + ], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + ], + "context": { + "get": {}, + "set": {}, + }, + "exports": {}, + "hooks": { + "onEvent": [], + "onMount": [], + }, + "imports": [], + "inputs": [], + "meta": {}, + "name": "TypeExternalProps", + "refs": {}, + "state": {}, + "subComponents": [], +} +`; + exports[`Parse JSX > Javascript > typeExternalStore 1`] = ` { "@type": "@builder.io/mitosis/component", @@ -25904,6 +25975,86 @@ exports[`Parse JSX > Typescript > typeDependency 1`] = ` } `; +exports[`Parse JSX > Typescript > typeExternalProps 1`] = ` +{ + "@type": "@builder.io/mitosis/component", + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": "Hello ", + }, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "_text": { + "bindingType": "expression", + "code": "props.name", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": "! ", + }, + "scope": {}, + }, + ], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + ], + "context": { + "get": {}, + "set": {}, + }, + "exports": {}, + "hooks": { + "onEvent": [], + "onMount": [], + }, + "imports": [ + { + "importKind": "value", + "imports": { + "FooProps": "FooProps", + }, + "path": "./foo-props", + }, + ], + "inputs": [], + "meta": {}, + "name": "TypeExternalProps", + "propsTypeRef": "FooProps", + "refs": {}, + "state": {}, + "subComponents": [], +} +`; + exports[`Parse JSX > Typescript > typeExternalStore 1`] = ` { "@type": "@builder.io/mitosis/component", diff --git a/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap b/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap index 3e5fc770be..804db2d1eb 100644 --- a/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap @@ -561,6 +561,12 @@ import { h, Fragment } from \\"preact\\"; import { useState } from \\"preact/hooks\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -598,12 +604,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -2104,6 +2104,15 @@ exports[`Preact > jsx > Javascript Test > defaultProps 1`] = ` import { h, Fragment } from \\"preact\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -2128,15 +2137,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -2146,6 +2146,13 @@ exports[`Preact > jsx > Javascript Test > defaultPropsOutsideComponent 1`] = ` import { h, Fragment } from \\"preact\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -2170,13 +2177,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -3047,7 +3047,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -3572,6 +3571,18 @@ export default TypeDependency; " `; +exports[`Preact > jsx > Javascript Test > typeExternalProps 1`] = ` +"/** @jsx h */ +import { h, Fragment } from \\"preact\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`Preact > jsx > Javascript Test > typeExternalStore 1`] = ` "/** @jsx h */ import { h, Fragment } from \\"preact\\"; @@ -4385,6 +4396,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -4422,12 +4439,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -6162,6 +6173,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -6186,15 +6206,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -6212,6 +6223,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -6236,13 +6254,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -7200,7 +7211,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -7770,6 +7780,19 @@ export default TypeDependency; " `; +exports[`Preact > jsx > Typescript Test > typeExternalProps 1`] = ` +"/** @jsx h */ +import { h, Fragment } from \\"preact\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`Preact > jsx > Typescript Test > typeExternalStore 1`] = ` "/** @jsx h */ import { h, Fragment } from \\"preact\\"; @@ -8067,21 +8090,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`Preact > svelte > Javascript Test > context 1`] = ` -"'>' expected. (36:13) - 34 | return ( - 35 | -> 36 | <'activeTab'.Provider value={activeTab}>
{activeTab}
+"'>' expected. (33:13) + 31 | return ( + 32 | +> 33 | <'activeTab'.Provider value={activeTab}>
{activeTab}
| ^ - 37 | - 38 | - 39 |" + 34 | + 35 | + 36 |" `; exports[`Preact > svelte > Javascript Test > each 1`] = ` @@ -8202,11 +8223,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -8471,21 +8490,19 @@ function MyComponent(props: any) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`Preact > svelte > Typescript Test > context 1`] = ` -"'>' expected. (36:13) - 34 | return ( - 35 | -> 36 | <'activeTab'.Provider value={activeTab}>
{activeTab}
+"'>' expected. (33:13) + 31 | return ( + 32 | +> 33 | <'activeTab'.Provider value={activeTab}>
{activeTab}
| ^ - 37 | - 38 | - 39 |" + 34 | + 35 | + 36 |" `; exports[`Preact > svelte > Typescript Test > each 1`] = ` @@ -8606,11 +8623,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap b/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap index 4d49a89339..3acf9bf294 100644 --- a/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap @@ -5266,6 +5266,17 @@ export default TypeDependency; " `; +exports[`qwik > jsx > Javascript Test > typeExternalProps 1`] = ` +"import { Fragment, component$, h } from \\"@builder.io/qwik\\"; + +export const TypeExternalProps = component$((props) => { + return
Hello {props.name}!
; +}); + +export default TypeExternalProps; +" +`; + exports[`qwik > jsx > Javascript Test > typeExternalStore 1`] = ` "import { Fragment, component$, h, useStore } from \\"@builder.io/qwik\\"; @@ -9383,6 +9394,19 @@ export default TypeDependency; " `; +exports[`qwik > jsx > Typescript Test > typeExternalProps 1`] = ` +"import { FooProps } from \\"./foo-props\\"; + +import { Fragment, component$, h } from \\"@builder.io/qwik\\"; + +export const TypeExternalProps = component$((props: FooProps) => { + return
Hello {props.name}!
; +}); + +export default TypeExternalProps; +" +`; + exports[`qwik > jsx > Typescript Test > typeExternalStore 1`] = ` "import { FooStore } from \\"./foo-store\\"; diff --git a/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap index 7cd91475be..48fb395a75 100644 --- a/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap @@ -824,6 +824,12 @@ import { import { useState } from \\"react\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -860,12 +866,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -2843,6 +2843,15 @@ import { } from \\"react-native\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return ( {props.link ? ( @@ -2866,15 +2875,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -2896,6 +2896,13 @@ import { } from \\"react-native\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return ( {props.link ? ( @@ -2919,13 +2926,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -4206,7 +4206,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -5075,6 +5074,36 @@ export default TypeDependency; " `; +exports[`React Native > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { + FlatList, + ScrollView, + View, + StyleSheet, + Image, + Text, + Pressable, + TextInput, + TouchableOpacity, + Button, + Linking, +} from \\"react-native\\"; + +function TypeExternalProps(props) { + return ( + + Hello + {props.name} + ! + + ); +} + +export default TypeExternalProps; +" +`; + exports[`React Native > jsx > Javascript Test > typeExternalStore 1`] = ` "import * as React from \\"react\\"; import { @@ -6181,6 +6210,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const [name, setName] = useState(() => \\"king\\"); const [showContent, setShowContent] = useState(() => false); @@ -6217,12 +6252,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -8434,6 +8463,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return ( {props.link ? ( @@ -8457,15 +8495,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -8495,6 +8524,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return ( {props.link ? ( @@ -8518,13 +8554,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -9892,7 +9921,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -10806,6 +10834,37 @@ export default TypeDependency; " `; +exports[`React Native > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { + FlatList, + ScrollView, + View, + StyleSheet, + Image, + Text, + Pressable, + TextInput, + TouchableOpacity, + Button, + Linking, +} from \\"react-native\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + return ( + + Hello + {props.name} + ! + + ); +} + +export default TypeExternalProps; +" +`; + exports[`React Native > jsx > Typescript Test > typeExternalStore 1`] = ` "import * as React from \\"react\\"; import { @@ -11269,21 +11328,19 @@ function MyComponent(props) { return ; } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React Native > svelte > Javascript Test > context 1`] = ` -"'>' expected. (36:13) - 34 | return ( - 35 | -> 36 | <'activeTab'.Provider value={activeTab}>{activeTab} +"'>' expected. (33:13) + 31 | return ( + 32 | +> 33 | <'activeTab'.Provider value={activeTab}>{activeTab} | ^ - 37 | - 38 | - 39 |" + 34 | + 35 | + 36 |" `; exports[`React Native > svelte > Javascript Test > each 1`] = ` @@ -11488,11 +11545,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -11864,21 +11919,19 @@ function MyComponent(props: any) { return ; } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React Native > svelte > Typescript Test > context 1`] = ` -"'>' expected. (36:13) - 34 | return ( - 35 | -> 36 | <'activeTab'.Provider value={activeTab}>{activeTab} +"'>' expected. (33:13) + 31 | return ( + 32 | +> 33 | <'activeTab'.Provider value={activeTab}>{activeTab} | ^ - 37 | - 38 | - 39 |" + 34 | + 35 | + 36 |" `; exports[`React Native > svelte > Typescript Test > each 1`] = ` @@ -12083,11 +12136,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/react-state-builder.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-state-builder.test.ts.snap index bbea432570..1f9a051339 100644 --- a/packages/core/src/__tests__/__snapshots__/react-state-builder.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-state-builder.test.ts.snap @@ -565,6 +565,12 @@ exports[`React - stateType: builder > jsx > Javascript Test > ContentSlotJSX 1`] import * as React from \\"react\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useBuilderState({ name: \\"king\\", showContent: false, @@ -601,12 +607,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -2123,6 +2123,15 @@ exports[`React - stateType: builder > jsx > Javascript Test > defaultProps 1`] = import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; const state = useBuilderState({}); return ( @@ -2149,15 +2158,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -2167,6 +2167,13 @@ exports[`React - stateType: builder > jsx > Javascript Test > defaultPropsOutsid import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; const state = useBuilderState({}); return ( @@ -2193,13 +2200,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -3069,7 +3069,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -3550,6 +3549,19 @@ export default TypeDependency; " `; +exports[`React - stateType: builder > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; + +function TypeExternalProps(props) { + const state = useBuilderState({}); + + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: builder > jsx > Javascript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -4374,6 +4386,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useBuilderState({ name: \\"king\\", showContent: false, @@ -4410,12 +4428,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -6164,6 +6176,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; const state = useBuilderState({}); return ( @@ -6190,15 +6211,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -6216,6 +6228,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; const state = useBuilderState({}); return ( @@ -6242,13 +6261,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -7205,7 +7217,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -7731,6 +7742,20 @@ export default TypeDependency; " `; +exports[`React - stateType: builder > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + const state = useBuilderState({}); + + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: builder > jsx > Typescript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -8031,21 +8056,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: builder > svelte > Javascript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: builder > svelte > Javascript Test > each 1`] = ` @@ -8167,11 +8190,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -8431,21 +8452,19 @@ function MyComponent(props: any) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: builder > svelte > Typescript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: builder > svelte > Typescript Test > each 1`] = ` @@ -8567,11 +8586,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/react-state-mobx.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-state-mobx.test.ts.snap index e7ddbc2ad6..359c297ab9 100644 --- a/packages/core/src/__tests__/__snapshots__/react-state-mobx.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-state-mobx.test.ts.snap @@ -590,6 +590,12 @@ import * as React from \\"react\\"; import { useLocalObservable, observer } from \\"mobx-react-lite\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useLocalObservable(() => ({ name: \\"king\\", showContent: false, @@ -626,12 +632,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - const observedContentSlotJsxCode = observer(ContentSlotJsxCode); export default observedContentSlotJsxCode; " @@ -2176,6 +2176,15 @@ exports[`React - stateType: mobx > jsx > Javascript Test > defaultProps 1`] = ` import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -2200,15 +2209,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - const observedButton = observer(Button); export default observedButton; " @@ -2219,6 +2219,13 @@ exports[`React - stateType: mobx > jsx > Javascript Test > defaultPropsOutsideCo import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -2243,13 +2250,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - const observedButton = observer(Button); export default observedButton; " @@ -3128,7 +3128,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -3599,6 +3598,18 @@ export default observedTypeDependency; " `; +exports[`React - stateType: mobx > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +const observedTypeExternalProps = observer(TypeExternalProps); +export default observedTypeExternalProps; +" +`; + exports[`React - stateType: mobx > jsx > Javascript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -4444,6 +4455,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useLocalObservable(() => ({ name: \\"king\\", showContent: false, @@ -4480,12 +4497,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - const observedContentSlotJsxCode = observer(ContentSlotJsxCode); export default observedContentSlotJsxCode; " @@ -6251,6 +6262,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -6275,15 +6295,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - const observedButton = observer(Button); export default observedButton; " @@ -6302,6 +6313,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -6326,13 +6344,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - const observedButton = observer(Button); export default observedButton; " @@ -7292,7 +7303,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -7808,6 +7818,19 @@ export default observedTypeDependency; " `; +exports[`React - stateType: mobx > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + return
Hello {props.name}!
; +} + +const observedTypeExternalProps = observer(TypeExternalProps); +export default observedTypeExternalProps; +" +`; + exports[`React - stateType: mobx > jsx > Typescript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -8116,22 +8139,20 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - const observedMyComponent = observer(MyComponent); export default observedMyComponent; " `; exports[`React - stateType: mobx > svelte > Javascript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: mobx > svelte > Javascript Test > each 1`] = ` @@ -8263,11 +8284,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -8539,22 +8558,20 @@ function MyComponent(props: any) { ); } -MyComponent.defaultProps = {}; - const observedMyComponent = observer(MyComponent); export default observedMyComponent; " `; exports[`React - stateType: mobx > svelte > Typescript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: mobx > svelte > Typescript Test > each 1`] = ` @@ -8686,11 +8703,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/react-state-solid.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-state-solid.test.ts.snap index c183b05b58..bc0ea33ded 100644 --- a/packages/core/src/__tests__/__snapshots__/react-state-solid.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-state-solid.test.ts.snap @@ -570,6 +570,12 @@ import * as React from \\"react\\"; import { useMutable } from \\"react-solid-state\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useMutable({ name: \\"king\\", showContent: false, @@ -606,12 +612,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -2108,6 +2108,15 @@ exports[`React - stateType: solid > jsx > Javascript Test > defaultProps 1`] = ` import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -2132,15 +2141,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -2150,6 +2150,13 @@ exports[`React - stateType: solid > jsx > Javascript Test > defaultPropsOutsideC import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -2174,13 +2181,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -3032,7 +3032,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -3482,6 +3481,17 @@ export default TypeDependency; " `; +exports[`React - stateType: solid > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: solid > jsx > Javascript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -4299,6 +4309,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useMutable({ name: \\"king\\", showContent: false, @@ -4335,12 +4351,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -6058,6 +6068,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -6082,15 +6101,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -6108,6 +6118,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -6132,13 +6149,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -7071,7 +7081,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -7566,6 +7575,18 @@ export default TypeDependency; " `; +exports[`React - stateType: solid > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: solid > jsx > Typescript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -7864,21 +7885,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: solid > svelte > Javascript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: solid > svelte > Javascript Test > each 1`] = ` @@ -8003,11 +8022,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -8270,21 +8287,19 @@ function MyComponent(props: any) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: solid > svelte > Typescript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: solid > svelte > Typescript Test > each 1`] = ` @@ -8409,11 +8424,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/react-state-valtio.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-state-valtio.test.ts.snap index e7c9ed47cf..83ce3c332e 100644 --- a/packages/core/src/__tests__/__snapshots__/react-state-valtio.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-state-valtio.test.ts.snap @@ -570,6 +570,12 @@ import * as React from \\"react\\"; import { useLocalProxy } from \\"valtio/utils\\"; function ContentSlotJsxCode(props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useLocalProxy({ name: \\"king\\", showContent: false, @@ -606,12 +612,6 @@ function ContentSlotJsxCode(props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -2111,6 +2111,15 @@ exports[`React - stateType: valtio > jsx > Javascript Test > defaultProps 1`] = import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -2135,15 +2144,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -2153,6 +2153,13 @@ exports[`React - stateType: valtio > jsx > Javascript Test > defaultPropsOutside import * as React from \\"react\\"; function Button(props) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -2177,13 +2184,6 @@ function Button(props) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -3035,7 +3035,6 @@ function RenderContent(props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -3485,6 +3484,17 @@ export default TypeDependency; " `; +exports[`React - stateType: valtio > jsx > Javascript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; + +function TypeExternalProps(props) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: valtio > jsx > Javascript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -4302,6 +4312,12 @@ type Props = { import type { JSX } from \\"../../../../jsx-runtime\\"; function ContentSlotJsxCode(props: Props) { + props = { + content: \\"\\", + slotReference: undefined, + slotContent: undefined, + ...props, + }; const state = useLocalProxy({ name: \\"king\\", showContent: false, @@ -4338,12 +4354,6 @@ function ContentSlotJsxCode(props: Props) { ); } -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - export default ContentSlotJsxCode; " `; @@ -6064,6 +6074,15 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => { + console.log(\\"hi\\"); + }, + ...props, + }; return (
{props.link ? ( @@ -6088,15 +6107,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => { - console.log(\\"hi\\"); - }, -}; - export default Button; " `; @@ -6114,6 +6124,13 @@ export interface ButtonProps { } function Button(props: ButtonProps) { + props = { + text: \\"default text\\", + link: \\"https://builder.io/\\", + openLinkInNewTab: false, + onClick: () => {}, + ...props, + }; return (
{props.link ? ( @@ -6138,13 +6155,6 @@ function Button(props: ButtonProps) { ); } -Button.defaultProps = { - text: \\"default text\\", - link: \\"https://builder.io/\\", - openLinkInNewTab: false, - onClick: () => {}, -}; - export default Button; " `; @@ -7077,7 +7087,6 @@ function RenderContent(props: Props) { useEffect(() => { sendComponentsToVisualEditor(props.customComponents); }, []); - useEffect(() => { dispatchNewContentToVisualEditor(props.content); }, [props.content]); @@ -7572,6 +7581,18 @@ export default TypeDependency; " `; +exports[`React - stateType: valtio > jsx > Typescript Test > typeExternalProps 1`] = ` +"import * as React from \\"react\\"; +import { FooProps } from \\"./foo-props\\"; + +function TypeExternalProps(props: FooProps) { + return
Hello {props.name}!
; +} + +export default TypeExternalProps; +" +`; + exports[`React - stateType: valtio > jsx > Typescript Test > typeExternalStore 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; @@ -7870,21 +7891,19 @@ function MyComponent(props) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: valtio > svelte > Javascript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: valtio > svelte > Javascript Test > each 1`] = ` @@ -8009,11 +8028,9 @@ function MyComponent(props) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); @@ -8276,21 +8293,19 @@ function MyComponent(props: any) { ); } -MyComponent.defaultProps = {}; - export default MyComponent; " `; exports[`React - stateType: valtio > svelte > Typescript Test > context 1`] = ` -"'>' expected. (35:13) - 33 | return ( - 34 | -> 35 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
+"'>' expected. (32:13) + 30 | return ( + 31 | +> 32 | <'activeTab'.Provider value={state.activeTab}>
{state.activeTab}
| ^ - 36 | - 37 | - 38 |" + 33 | + 34 | + 35 |" `; exports[`React - stateType: valtio > svelte > Typescript Test > each 1`] = ` @@ -8415,11 +8430,9 @@ function MyComponent(props: any) { useEffect(() => { console.log(\\"onMount\\"); }, []); - useEffect(() => { console.log(\\"onAfterUpdate\\"); }); - useEffect(() => { return () => { console.log(\\"onDestroy\\"); diff --git a/packages/core/src/__tests__/__snapshots__/react-state-variables.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-state-variables.test.ts.snap index b3f4293bd6..95dac71280 100644 --- a/packages/core/src/__tests__/__snapshots__/react-state-variables.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-state-variables.test.ts.snap @@ -1,63 +1,115 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`React - stateType: variables > jsx > Javascript Test > AdvancedRef 1`] = ` -"'(' expected. (18:34) - 16 | const inputNoArgRef = useRef(null); - 17 | const name= 'PatrickJS' -> 18 | const onBlur = onBlur = function function onBlur() { - | ^ - 19 | // Maintain focus - 20 | inputRef.current.focus(); - 21 | }" -`; - -exports[`React - stateType: variables > jsx > Javascript Test > Basic 1`] = ` "\\"use client\\"; import * as React from \\"react\\"; +import { useRef, useEffect } from \\"react\\"; -export const DEFAULT_VALUES = { - name: \\"Steve\\", -}; - -function MyBasicComponent(props) { - const name = \\"Steve\\"; - const underscore_fn_name = function underscore_fn_name() { - return \\"bar\\"; +function MyBasicRefComponent(props) { + const inputRef = useRef(null); + const inputNoArgRef = useRef(null); + const name = \\"PatrickJS\\"; + const onBlur = function onBlur() { + // Maintain focus + inputRef.current.focus(); + }; + const lowerCaseName = function lowerCaseName() { + return name.toLowerCase(); }; - const age = 1; - const sports = [\\"\\"]; + + useEffect(() => { + console.log(\\"Received an update\\"); + }, [inputRef.current, inputNoArgRef.current]); return ( <> -
- (name = myEvent.target.value)} - /> - Hello! I can run in React, Vue, Solid, or Liquid! > +
+ {props.showInput ? ( + <> + onBlur()} + onChange={(event) => (name = event.target.value)} + /> + + + + ) : null} + Hello + {lowerCaseName()}! I can run in React, Qwik, Vue, Solid, or Web + Component!
); } -export default MyBasicComponent; +export default MyBasicRefComponent; " `; +exports[`React - stateType: variables > jsx > Javascript Test > Basic 1`] = ` +"'function' is not allowed as a variable declaration name. (19:7) + 17 | + 18 | const name= 'Steve' +> 19 | const function underscore_fn_name() { + | ^ + 20 | return 'bar'; + 21 | } + 22 | const age= 1" +`; + exports[`React - stateType: variables > jsx > Javascript Test > Basic Context 1`] = ` -"'(' expected. (16:38) - 14 | function MyBasicComponent(props) { - 15 | const name= 'PatrickJS' -> 16 | const onChange = onChange = function function onChange() { - | ^ - 17 | const change = myService.method('change'); - 18 | console.log(change); - 19 | }" +"\\"use client\\"; +import * as React from \\"react\\"; +import { useContext, useRef, useEffect } from \\"react\\"; +import { Injector, MyService, createInjector } from \\"@dummy/injection-js\\"; + +function MyBasicComponent(props) { + const name = \\"PatrickJS\\"; + const onChange = function onChange() { + const change = myService.method(\\"change\\"); + console.log(change); + }; + + const myService = useContext(MyService); + + const hasInitialized = useRef(false); + if (!hasInitialized.current) { + const hi = myService.method(\\"hi\\"); + console.log(hi); + hasInitialized.current = true; + } + + useEffect(() => { + const bye = myService.method(\\"hi\\"); + console.log(bye); + }, []); + + return ( + +
+ {myService.method(\\"hello\\") + name} + Hello! I can run in React, Vue, Solid, or Liquid! + onChange} /> +
+
+ ); +} + +export default MyBasicComponent; +" `; exports[`React - stateType: variables > jsx > Javascript Test > Basic OnMount Update 1`] = ` @@ -227,25 +279,82 @@ export default MyBasicForComponent; `; exports[`React - stateType: variables > jsx > Javascript Test > BasicRef 1`] = ` -"'(' expected. (18:34) - 16 | const inputNoArgRef = useRef(null); - 17 | const name= 'PatrickJS' -> 18 | const onBlur = onBlur = function function onBlur() { - | ^ - 19 | // Maintain focus - 20 | inputRef.current?.focus(); - 21 | }" +"\\"use client\\"; +import * as React from \\"react\\"; +import { useRef } from \\"react\\"; + +function MyBasicRefComponent(props) { + const inputRef = useRef(null); + const inputNoArgRef = useRef(null); + const name = \\"PatrickJS\\"; + const onBlur = function onBlur() { + // Maintain focus + inputRef.current?.focus(); + }; + const lowerCaseName = function lowerCaseName() { + return name.toLowerCase(); + }; + + return ( + <> +
+ {props.showInput ? ( + <> + onBlur()} + onChange={(event) => (name = event.target.value)} + /> + + + + ) : null} + Hello + {lowerCaseName()}! I can run in React, Qwik, Vue, Solid, or Web + Component! +
+ + + ); +} + +export default MyBasicRefComponent; +" `; exports[`React - stateType: variables > jsx > Javascript Test > BasicRefAssignment 1`] = ` -"'(' expected. (16:46) - 14 | function MyBasicRefAssignmentComponent(props) { - 15 | const holdValueRef = useRef('Patrick'); -> 16 | const handlerClick = handlerClick = function function handlerClick(event) { - | ^ - 17 | event.preventDefault(); - 18 | console.log('current value', holdValueRef.current); - 19 | holdValueRef.current = holdValueRef.current + 'JS';" +"\\"use client\\"; +import * as React from \\"react\\"; +import { useRef } from \\"react\\"; + +function MyBasicRefAssignmentComponent(props) { + const holdValueRef = useRef(\\"Patrick\\"); + const handlerClick = function handlerClick(event) { + event.preventDefault(); + console.log(\\"current value\\", holdValueRef.current); + holdValueRef.current = holdValueRef.current + \\"JS\\"; + }; + + return ( +
+ +
+ ); +} + +export default MyBasicRefAssignmentComponent; +" `; exports[`React - stateType: variables > jsx > Javascript Test > BasicRefPrevious 1`] = ` @@ -318,63 +427,14 @@ export default Button; `; exports[`React - stateType: variables > jsx > Javascript Test > Columns 1`] = ` -"import * as React from \\"react\\"; - -function Column(props) { - const getColumns = function getColumns() { - return props.columns || []; - }; - const getGutterSize = function getGutterSize() { - return typeof props.space === \\"number\\" ? props.space || 0 : 20; - }; - const getWidth = function getWidth(index) { - const columns = getColumns(); - return (columns[index] && columns[index].width) || 100 / columns.length; - }; - const getColumnCssWidth = function getColumnCssWidth(index) { - const columns = getColumns(); - const gutterSize = getGutterSize(); - const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length; - return \`calc(\${getWidth(index)}% - \${subtractWidth}px)\`; - }; - - return ( - <> -
- {props.columns?.map((column, index) => ( -
- {column.content} - {index} -
- ))} -
- - - ); -} - -export default Column; -" +"'function' is not allowed as a variable declaration name. (15:9) + 13 | function Column(props) { + 14 | +> 15 | const function getColumns() { + | ^ + 16 | return props.columns || []; + 17 | } + 18 | const function getGutterSize() {" `; exports[`React - stateType: variables > jsx > Javascript Test > ContentSlotHtml 1`] = ` @@ -399,214 +459,58 @@ export default ContentSlotCode; `; exports[`React - stateType: variables > jsx > Javascript Test > ContentSlotJSX 1`] = ` -"\\"use client\\"; -import * as React from \\"react\\"; - -function ContentSlotJsxCode(props) { - const name = \\"king\\"; - const showContent = false; - const cls = function cls() { - return props.slotContent && props.children ? \`\${name}-content\` : \\"\\"; - }; - const show = function show() { - props.slotContent ? 1 : \\"\\"; - }; - - return ( - <> - {props.slotReference ? ( - <> -
show()} - className={cls()} - > - {showContent && props.slotContent ? ( - <>{props.content || \\"{props.content}\\"} - ) : null} -
-
-
-
{props.children}
-
- - ) : null} - - ); -} - -ContentSlotJsxCode.defaultProps = { - content: \\"\\", - slotReference: undefined, - slotContent: undefined, -}; - -export default ContentSlotJsxCode; -" +"'function' is not allowed as a variable declaration name. (18:7) + 16 | const name= 'king' + 17 | const showContent= false +> 18 | const function cls() { + | ^ + 19 | return props.slotContent && props.children ? \`\${name}-content\` : ''; + 20 | } + 21 | const function show() {" `; exports[`React - stateType: variables > jsx > Javascript Test > CustomCode 1`] = ` -"\\"use client\\"; -import * as React from \\"react\\"; -import { useRef, useEffect } from \\"react\\"; - -function CustomCode(props) { - const elem = useRef(null); - const scriptsInserted = []; - const scriptsRun = []; - const findAndRunScripts = function findAndRunScripts() { - // TODO: Move this function to standalone one in '@builder.io/utils' - if (elem.current && typeof window !== \\"undefined\\") { - /** @type {HTMLScriptElement[]} */ - const scripts = elem.current.getElementsByTagName(\\"script\\"); - - for (let i = 0; i < scripts.length; i++) { - const script = scripts[i]; - - if (script.src) { - if (scriptsInserted.includes(script.src)) { - continue; - } - - scriptsInserted.push(script.src); - const newScript = document.createElement(\\"script\\"); - newScript.async = true; - newScript.src = script.src; - document.head.appendChild(newScript); - } else if ( - !script.type || - [ - \\"text/javascript\\", - \\"application/javascript\\", - \\"application/ecmascript\\", - ].includes(script.type) - ) { - if (scriptsRun.includes(script.innerText)) { - continue; - } - - try { - scriptsRun.push(script.innerText); - new Function(script.innerText)(); - } catch (error) { - console.warn(\\"\`CustomCode\`: Error running script:\\", error); - } - } - } - } - }; - - useEffect(() => { - findAndRunScripts(); - }, []); - - return ( -
- ); -} - -export default CustomCode; -" +"'function' is not allowed as a variable declaration name. (19:7) + 17 | const scriptsInserted= [] + 18 | const scriptsRun= [] +> 19 | const function findAndRunScripts() { + | ^ + 20 | // TODO: Move this function to standalone one in '@builder.io/utils' + 21 | if (elem.current && typeof window !== 'undefined') { + 22 | /** @type {HTMLScriptElement[]} */" `; exports[`React - stateType: variables > jsx > Javascript Test > Embed 1`] = ` -"\\"use client\\"; -import * as React from \\"react\\"; -import { useRef, useEffect } from \\"react\\"; - -function CustomCode(props) { - const elem = useRef(null); - const scriptsInserted = []; - const scriptsRun = []; - const findAndRunScripts = function findAndRunScripts() { - // TODO: Move this function to standalone one in '@builder.io/utils' - if (elem.current && typeof window !== \\"undefined\\") { - /** @type {HTMLScriptElement[]} */ - const scripts = elem.current.getElementsByTagName(\\"script\\"); - - for (let i = 0; i < scripts.length; i++) { - const script = scripts[i]; - - if (script.src) { - if (scriptsInserted.includes(script.src)) { - continue; - } - - scriptsInserted.push(script.src); - const newScript = document.createElement(\\"script\\"); - newScript.async = true; - newScript.src = script.src; - document.head.appendChild(newScript); - } else if ( - !script.type || - [ - \\"text/javascript\\", - \\"application/javascript\\", - \\"application/ecmascript\\", - ].includes(script.type) - ) { - if (scriptsRun.includes(script.innerText)) { - continue; - } - - try { - scriptsRun.push(script.innerText); - new Function(script.innerText)(); - } catch (error) { - console.warn(\\"\`CustomCode\`: Error running script:\\", error); - } - } - } - } - }; - - useEffect(() => { - findAndRunScripts(); - }, []); - - return ( -
- ); -} - -export default CustomCode; -" +"'function' is not allowed as a variable declaration name. (19:7) + 17 | const scriptsInserted= [] + 18 | const scriptsRun= [] +> 19 | const function findAndRunScripts() { + | ^ + 20 | // TODO: Move this function to standalone one in '@builder.io/utils' + 21 | if (elem.current && typeof window !== 'undefined') { + 22 | /** @type {HTMLScriptElement[]} */" `; exports[`React - stateType: variables > jsx > Javascript Test > Form 1`] = ` -"',' expected. (108:2796) - 106 | if (contentType && contentType !== 'multipart/form-data') { - 107 | if ( -> 108 | /* Zapier doesn't allow content-type header to be sent from browsers */ !(sendWithJs && props.action?.includes('zapier.com'))) { headers['content-type'] = contentType; } } const presubmitEvent = new CustomEvent('presubmit', { detail: { body } }); if (formRef.current) { formRef.current.dispatchEvent(presubmitEvent); if (presubmitEvent.defaultPrevented) { return; } } formState = 'sending'; const formUrl = \`\${builder.env === 'dev' ? 'http://localhost:5000' : 'https://builder.io'}/api/v1/form-submit?apiKey=\${builder.apiKey}&to=\${btoa(props.sendSubmissionsToEmail || '')}&name=\${encodeURIComponent(props.name || '')}\`; fetch(props.sendSubmissionsTo === 'email' ? formUrl : props.action /* TODO: throw error if no action URL */ , { body, headers, method: props.method || 'post' }).then(async res => { let body; const contentType = res.headers.get('content-type'); if (contentType && contentType.indexOf('application/json') !== -1) { body = await res.json(); } else { body = await res.text(); } if (!res.ok && props.errorMessagePath) { /* TODO: allow supplying an error formatter function */ let message = get(body, props.errorMessagePath); if (message) { if (typeof message !== 'string') { /* TODO: ideally convert json to yaml so it woul dbe like error: - email has been taken */ message = JSON.stringify(message); } formErrorMessage = message; } } responseData = body; formState = res.ok ? 'success' : 'error'; if (res.ok) { const submitSuccessEvent = new CustomEvent('submit:success', { detail: { res, body } }); if (formRef.current) { formRef.current.dispatchEvent(submitSuccessEvent); if (submitSuccessEvent.defaultPrevented) { return; } /* TODO: option to turn this on/off? */ if (props.resetFormOnSubmit !== false) { formRef.current.reset(); } } /* TODO: client side route event first that can be preventDefaulted */ if (props.successUrl) { if (formRef.current) { const event = new CustomEvent('route', { detail: { url: props.successUrl } }); formRef.current.dispatchEvent(event); if (!event.defaultPrevented) { location.href = props.successUrl; } } else { location.href = props.successUrl; } } } }, err => { const submitErrorEvent = new CustomEvent('submit:error', { detail: { error: err } }); if (formRef.current) { formRef.current.dispatchEvent(submitErrorEvent); if (submitErrorEvent.defaultPrevented) { return; } } responseData = err; formState = 'error'; }); } } return ( <>
onSubmit(event) } {...(props.attributes)}>{props.builderBlock && props.builderBlock.children ? ( <>{props.builderBlock?.children?.map((block, index) => ( ))} ) : null}{submissionState() === 'error' ? ( ) : null}{submissionState() === 'sending' ? ( ) : null}{submissionState() === 'error' && responseData ? (
{JSON.stringify(responseData, null, 2)}
) : null}{submissionState() === 'success' ? ( ) : null} ); } export default FormComponent; - | ^ - 109 | - 110 | - 111 |" +"'function' is not allowed as a variable declaration name. (21:7) + 19 | const responseData= null + 20 | const formErrorMessage= '' +> 21 | const function submissionState() { + | ^ + 22 | return Builder.isEditing && props.previewState || formState; + 23 | } + 24 | const function onSubmit(event) {" `; exports[`React - stateType: variables > jsx > Javascript Test > Image 1`] = ` -"'(' expected. (25:40) - 23 | return !!props.lazy && isBrowser(); - 24 | } -> 25 | const isBrowser = isBrowser = function function isBrowser() { - | ^ - 26 | return typeof window !== 'undefined' && window.navigator.product != 'ReactNative'; - 27 | } - 28 | const load= false" +"'function' is not allowed as a variable declaration name. (19:7) + 17 | const scrollListener= null + 18 | const imageLoaded= false +> 19 | const function setLoaded() { + | ^ + 20 | imageLoaded = true; + 21 | } + 22 | const function useLazyLoading() {" `; exports[`React - stateType: variables > jsx > Javascript Test > Image State 1`] = ` @@ -683,25 +587,14 @@ export default FormInputComponent; `; exports[`React - stateType: variables > jsx > Javascript Test > InputParent 1`] = ` -"import * as React from \\"react\\"; -import FormInputComponent from \\"./input.raw\\"; - -function Stepper(props) { - const handleChange = function handleChange(value) { - console.log(value); - }; - - return ( - handleChange(value)} - /> - ); -} - -export default Stepper; -" +"'function' is not allowed as a variable declaration name. (15:9) + 13 | function Stepper(props) { + 14 | +> 15 | const function handleChange(value) { + | ^ + 16 | console.log(value); + 17 | } + 18 |" `; exports[`React - stateType: variables > jsx > Javascript Test > NestedStore 1`] = ` @@ -862,154 +755,51 @@ export default SlotCode; `; exports[`React - stateType: variables > jsx > Javascript Test > Stamped.io 1`] = ` -"\\"use client\\"; -import * as React from \\"react\\"; -import { useEffect } from \\"react\\"; -import { kebabCase, snakeCase } from \\"lodash\\"; - -function SmileReviews(props) { - const reviews = []; - const name = \\"test\\"; - const showReviewPrompt = false; - const kebabCaseValue = function kebabCaseValue() { - return kebabCase(\\"testThat\\"); - }; - const snakeCaseValue = function snakeCaseValue() { - return snakeCase(\\"testThis\\"); - }; +"'function' is not allowed as a variable declaration name. (19:7) + 17 | const name= 'test' + 18 | const showReviewPrompt= false +> 19 | const function kebabCaseValue() { + | ^ + 20 | return kebabCase('testThat'); + 21 | } + 22 | const function snakeCaseValue() {" +`; - useEffect(() => { - fetch( - \`https://stamped.io/api/widget/reviews?storeUrl=builder-io.myshopify.com&apiKey=\${ - props.apiKey || \\"pubkey-8bbDq7W6w4sB3OWeM1HUy2s47702hM\\" - }&productId=\${props.productId || \\"2410511106127\\"}\` - ) - .then((res) => res.json()) - .then((data) => { - reviews = data.data; - }); - }, []); +exports[`React - stateType: variables > jsx > Javascript Test > StoreComment 1`] = ` +"'function' is not allowed as a variable declaration name. (17:7) + 15 | + 16 | const foo= true +> 17 | const function bar() {} + | ^ + 18 | + 19 | + 20 |" +`; - return ( - <> -
- - {showReviewPrompt || \\"asdf\\" ? ( - <> - - -