Skip to content

Commit b44fcc8

Browse files
committed
Use strongly typed sentryFragmentContext
1 parent 3070c36 commit b44fcc8

File tree

1 file changed

+10
-15
lines changed
  • packages/babel-plugin-component-annotate/src

1 file changed

+10
-15
lines changed

packages/babel-plugin-component-annotate/src/index.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ interface AnnotationOpts {
5151
ignoredComponents?: string[];
5252
}
5353

54+
interface FragmentContext {
55+
fragmentAliases: Set<string>;
56+
reactNamespaceAliases: Set<string>;
57+
}
58+
5459
interface AnnotationPluginPass extends PluginPass {
5560
opts: AnnotationOpts;
61+
sentryFragmentContext?: FragmentContext;
5662
}
5763

5864
type AnnotationPlugin = PluginObj<AnnotationPluginPass>;
@@ -64,7 +70,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
6470
Program: {
6571
enter(path, state) {
6672
const fragmentContext = collectFragmentContext(path);
67-
state['sentryFragmentContext'] = fragmentContext;
73+
state.sentryFragmentContext = fragmentContext;
6874
}
6975
},
7076
FunctionDeclaration(path, state) {
@@ -75,8 +81,6 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
7581
return;
7682
}
7783

78-
const fragmentContext = state['sentryFragmentContext'] as FragmentContext | undefined;
79-
8084
functionBodyPushAttributes(
8185
state.opts["annotate-fragments"] === true,
8286
t,
@@ -85,7 +89,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
8589
sourceFileNameFromState(state),
8690
attributeNamesFromState(state),
8791
state.opts.ignoredComponents ?? [],
88-
fragmentContext
92+
state.sentryFragmentContext
8993
);
9094
},
9195
ArrowFunctionExpression(path, state) {
@@ -106,8 +110,6 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
106110
return;
107111
}
108112

109-
const fragmentContext = state['sentryFragmentContext'] as FragmentContext | undefined;
110-
111113
functionBodyPushAttributes(
112114
state.opts["annotate-fragments"] === true,
113115
t,
@@ -116,7 +118,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
116118
sourceFileNameFromState(state),
117119
attributeNamesFromState(state),
118120
state.opts.ignoredComponents ?? [],
119-
fragmentContext
121+
state.sentryFragmentContext
120122
);
121123
},
122124
ClassDeclaration(path, state) {
@@ -132,8 +134,6 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
132134

133135
const ignoredComponents = state.opts.ignoredComponents ?? [];
134136

135-
const fragmentContext = state['sentryFragmentContext'] as FragmentContext | undefined;
136-
137137
render.traverse({
138138
ReturnStatement(returnStatement) {
139139
const arg = returnStatement.get("argument");
@@ -150,7 +150,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
150150
sourceFileNameFromState(state),
151151
attributeNamesFromState(state),
152152
ignoredComponents,
153-
fragmentContext
153+
state.sentryFragmentContext
154154
);
155155
},
156156
});
@@ -467,11 +467,6 @@ function attributeNamesFromState(state: AnnotationPluginPass): [string, string,
467467
return [webComponentName, webElementName, webSourceFileName];
468468
}
469469

470-
interface FragmentContext {
471-
fragmentAliases: Set<string>;
472-
reactNamespaceAliases: Set<string>;
473-
}
474-
475470
function collectFragmentContext(programPath: Babel.NodePath): FragmentContext {
476471
const fragmentAliases = new Set<string>();
477472
const reactNamespaceAliases = new Set<string>(['React']); // Default React namespace

0 commit comments

Comments
 (0)