diff --git a/.changeset/swift-crews-develop.md b/.changeset/swift-crews-develop.md new file mode 100644 index 000000000..594088782 --- /dev/null +++ b/.changeset/swift-crews-develop.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Fix props detection when importing `Props` from another file (see [#814](https://github.com/withastro/compiler/issues/814)) diff --git a/internal/js_scanner/js_scanner.go b/internal/js_scanner/js_scanner.go index f2a119f07..1c03f4521 100644 --- a/internal/js_scanner/js_scanner.go +++ b/internal/js_scanner/js_scanner.go @@ -310,6 +310,12 @@ outer: if js.IsIdentifier(token) { if isKeyword(value) { + // fix(#814): fix Props detection when using `{ Props as SomethingElse }` + if ident == "Props" && string(value) == "as" { + start = 0 + ident = defaultPropType + idents = make([]string, 0) + } i += len(value) continue } diff --git a/packages/compiler/test/tsx/props.ts b/packages/compiler/test/tsx/props.ts index 2959e5e78..eba6ecfc0 100644 --- a/packages/compiler/test/tsx/props.ts +++ b/packages/compiler/test/tsx/props.ts @@ -266,4 +266,23 @@ export default function __AstroComponent_(_props: Record): any {}\n assert.snapshot(code, output, `expected code to match snapshot`); }); +test('unrelated sibling prop', async () => { + const input = `--- +import type { Props as ComponentBProps } from './ComponentB.astro' +--- + +
+`; + const output = ` +import type { Props as ComponentBProps } from './ComponentB.astro' + +""; +
+ + +export default function __AstroComponent_(_props: Record): any {}\n`; + const { code } = await convertToTSX(input, { sourcemap: 'external' }); + assert.snapshot(code, output, `expected code to match snapshot`); +}); + test.run();