Skip to content

Commit 7132259

Browse files
authored
fix(compiler): fix attachInternals should be usable without formAssoc… (#6286)
* fix(compiler): fix attachInternals should be usable without formAssociated * feat: Add unit tests * fix: Prettier white space issue
1 parent 9da2c90 commit 7132259

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/compiler/transformers/component-lazy/attach-internals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { HOST_REF_ARG } from './constants';
4242
* @returns a list of expression statements
4343
*/
4444
export function createLazyAttachInternalsBinding(cmp: d.ComponentCompilerMeta): ts.Statement[] {
45-
if (cmp.formAssociated && cmp.attachInternalsMemberName) {
45+
if (cmp.attachInternalsMemberName) {
4646
return [
4747
ts.factory.createIfStatement(
4848
// the condition for the `if` statement here is just whether the

src/compiler/transformers/component-native/attach-internals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import ts from 'typescript';
3030
* @returns an expression statement syntax tree node
3131
*/
3232
export function createNativeAttachInternalsBinding(cmp: d.ComponentCompilerMeta): ts.ExpressionStatement[] {
33-
if (cmp.formAssociated && cmp.attachInternalsMemberName) {
33+
if (cmp.attachInternalsMemberName) {
3434
return [
3535
ts.factory.createExpressionStatement(
3636
ts.factory.createBinaryExpression(

src/compiler/transformers/test/parse-attach-internals.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,33 @@ describe('parse attachInternals', function () {
2626
`);
2727
expect(t.cmp!.attachInternalsMemberName).toBe(null);
2828
});
29+
30+
it('should set attachInternalsMemberName even if formAssociated is not defined', async () => {
31+
const t = transpileModule(`
32+
@Component({
33+
tag: 'cmp-a',
34+
})
35+
export class CmpA {
36+
@AttachInternals()
37+
myProp;
38+
}
39+
`);
40+
expect(t.cmp!.formAssociated).toBe(false);
41+
expect(t.cmp!.attachInternalsMemberName).toBe('myProp');
42+
});
43+
44+
it('should set attachInternalsMemberName even if formAssociated is false', async () => {
45+
const t = transpileModule(`
46+
@Component({
47+
tag: 'cmp-a',
48+
formAssociated: false
49+
})
50+
export class CmpA {
51+
@AttachInternals()
52+
myProp;
53+
}
54+
`);
55+
expect(t.cmp!.formAssociated).toBe(false);
56+
expect(t.cmp!.attachInternalsMemberName).toBe('myProp');
57+
});
2958
});

0 commit comments

Comments
 (0)