Skip to content

Commit d33f43d

Browse files
committed
update react views to have displayName as the component name
1 parent 7a0e6b0 commit d33f43d

File tree

7 files changed

+38
-1
lines changed

7 files changed

+38
-1
lines changed

packages/engine.babel-plugin-hmr/specs/__snapshots__/general.spec.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ const result = viewRandomId({
104104
},
105105
},
106106
},
107+
meta: {
108+
name: "result",
109+
},
107110
type: "view",
108111
buildId: "unique_id",
109112
});
@@ -121,6 +124,9 @@ const result2 = viewRandomId({
121124
},
122125
},
123126
},
127+
meta: {
128+
name: "result2",
129+
},
124130
type: "view",
125131
buildId: "unique_id",
126132
});
@@ -151,6 +157,9 @@ export const result = viewRandomId({
151157
},
152158
},
153159
},
160+
meta: {
161+
name: "result",
162+
},
154163
type: "view",
155164
buildId: "unique_id",
156165
});

packages/engine.babel-plugin-syntax/specs/__snapshots__/view.spec.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const foo = viewRandomId({
2424
},
2525
},
2626
},
27+
meta: {
28+
name: "foo",
29+
},
2730
type: "view",
2831
buildId: "unique_id",
2932
});
@@ -43,6 +46,9 @@ const bar = viewRandomId({
4346
},
4447
},
4548
},
49+
meta: {
50+
name: "bar",
51+
},
4652
type: "view",
4753
buildId: "unique_id",
4854
});
@@ -73,6 +79,9 @@ const foo = viewRandomId({
7379
},
7480
},
7581
},
82+
meta: {
83+
name: "foo",
84+
},
7685
type: "view",
7786
buildId: "unique_id",
7887
});
@@ -92,6 +101,9 @@ const foo = viewRandomId({
92101
props: {
93102
type: "PASSTHROUGH",
94103
},
104+
meta: {
105+
name: "foo",
106+
},
95107
type: "view",
96108
buildId: "unique_id",
97109
});
@@ -114,6 +126,9 @@ const foo = viewRandomId({
114126
props: {
115127
type: "PASSTHROUGH",
116128
},
129+
meta: {
130+
name: "foo",
131+
},
117132
type: "view",
118133
buildId: "unique_id",
119134
});
@@ -136,6 +151,9 @@ const foo = viewRandomId({
136151
props: {
137152
type: "PASSTHROUGH",
138153
},
154+
meta: {
155+
name: "foo",
156+
},
139157
type: "view",
140158
buildId: "unique_id",
141159
});
@@ -164,6 +182,9 @@ const foo = viewRandomId({
164182
},
165183
},
166184
},
185+
meta: {
186+
name: "foo",
187+
},
167188
type: "view",
168189
buildId: "unique_id",
169190
});

packages/engine.babel-plugin-syntax/src/utils/instrumentView.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ export const instrumentView = (
100100
}
101101
node.init = t.callExpression(t.identifier(alias), [t.identifier(configId)]);
102102
} else {
103+
const meta = rawObjectCompiler(babel, {
104+
name: metaProps.name
105+
});
103106
const result = t.objectExpression([
104107
t.objectProperty(t.identifier("fn"), fn),
105108
t.objectProperty(t.identifier("props"), props),
109+
t.objectProperty(t.identifier("meta"), meta),
106110
t.objectProperty(t.identifier("type"), t.stringLiteral("view")),
107111
t.objectProperty(t.identifier("buildId"), t.stringLiteral(buildId)),
108112
]);

packages/engine.react/specs/basic.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test("Simple load of a react component", async () => {
2929
return <div data-testid="foo">{foo}</div>;
3030
};
3131

32+
Component.displayName;
3233
expect(Component.displayName).not.toBeUndefined();
3334

3435
const app = engine({

packages/engine.react/specs/events.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ test("Simple load of a react component", async () => {
3737
return <div data-testid="foo">{foo}</div>;
3838
};
3939

40+
Component.displayName;
4041
expect(Component.displayName).not.toBeUndefined();
4142

4243
const on = jest.fn();

packages/engine.react/specs/viewInstance.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ test("should create a state instance for a view", async () => {
6767
);
6868
};
6969

70+
Component.displayName;
7071
expect(Component.displayName).not.toBeUndefined();
7172

7273
let get;

packages/engine.react/src/view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function view(config: ViewConfig) {
102102
emit: RenderContext["emit"];
103103
config: ViewConfig;
104104
static contextType = ViewContext;
105-
static displayName = `${config.meta?.relativeFilePath}::${config.meta?.name}:${config.meta?.location?.start.line}`;
105+
static displayName = config.meta?.name;
106106
stateUpdate: any = {};
107107
fn: any;
108108
isComponentMounted: boolean = false;

0 commit comments

Comments
 (0)