@sentry/bundler-plugins 11.11.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
- package/build/cjs/babel-plugin/component-annotation.js +14 -32
- package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
- package/build/cjs/babel-plugin/constants.js +140 -122
- package/build/cjs/babel-plugin/constants.js.map +1 -1
- package/build/cjs/babel-plugin/experimental.js +204 -307
- package/build/cjs/babel-plugin/experimental.js.map +1 -1
- package/build/cjs/babel-plugin/index.js +315 -437
- package/build/cjs/babel-plugin/index.js.map +1 -1
- package/build/cjs/bun/index.js +81 -117
- package/build/cjs/bun/index.js.map +1 -1
- package/build/cjs/core/build-plugin-manager.js +626 -683
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/cli.js +134 -129
- package/build/cjs/core/cli.js.map +1 -1
- package/build/cjs/core/component-annotate-hooks.js +16 -27
- package/build/cjs/core/component-annotate-hooks.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc.js +68 -103
- package/build/cjs/core/component-annotation-oxc.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +223 -234
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/get-code-injection-position.js +59 -74
- package/build/cjs/core/get-code-injection-position.js.map +1 -1
- package/build/cjs/core/glob.js +9 -7
- package/build/cjs/core/glob.js.map +1 -1
- package/build/cjs/core/index.js +77 -61
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/logger.js +17 -26
- package/build/cjs/core/logger.js.map +1 -1
- package/build/cjs/core/options-mapping.js +95 -117
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +90 -105
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sentry/transports.js +92 -99
- package/build/cjs/core/sentry/transports.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +98 -61
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/upload-filter.js +52 -0
- package/build/cjs/core/upload-filter.js.map +1 -0
- package/build/cjs/core/utils.js +228 -219
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +4 -5
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +180 -210
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/loader-utils/index.js +5 -10
- package/build/cjs/rollup/debug-id-injection.js +22 -38
- package/build/cjs/rollup/debug-id-injection.js.map +1 -1
- package/build/cjs/rollup/debug-id-stamping.js +14 -24
- package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
- package/build/cjs/rollup/index.js +195 -209
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +178 -0
- package/build/cjs/rollup/source-map-handling.js.map +1 -0
- package/build/cjs/vite/index.js +19 -35
- package/build/cjs/vite/index.js.map +1 -1
- package/build/cjs/vite/source-map-hooks.js +116 -0
- package/build/cjs/vite/source-map-hooks.js.map +1 -0
- package/build/cjs/webpack/component-annotation-transform.js +20 -26
- package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
- package/build/cjs/webpack/index.js +277 -234
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/esm/_virtual/_rolldown/runtime.js +2 -0
- package/build/esm/babel-plugin/component-annotation.js +13 -29
- package/build/esm/babel-plugin/component-annotation.js.map +1 -1
- package/build/esm/babel-plugin/constants.js +140 -120
- package/build/esm/babel-plugin/constants.js.map +1 -1
- package/build/esm/babel-plugin/experimental.js +204 -305
- package/build/esm/babel-plugin/experimental.js.map +1 -1
- package/build/esm/babel-plugin/index.js +311 -434
- package/build/esm/babel-plugin/index.js.map +1 -1
- package/build/esm/bun/index.js +76 -101
- package/build/esm/bun/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +621 -664
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/cli.js +134 -127
- package/build/esm/core/cli.js.map +1 -1
- package/build/esm/core/component-annotate-hooks.js +16 -25
- package/build/esm/core/component-annotate-hooks.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js +9 -19
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-walk.js +61 -121
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/esm/core/component-annotation-oxc.js +65 -96
- package/build/esm/core/component-annotation-oxc.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +218 -213
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/get-code-injection-position.js +59 -72
- package/build/esm/core/get-code-injection-position.js.map +1 -1
- package/build/esm/core/glob.js +9 -5
- package/build/esm/core/glob.js.map +1 -1
- package/build/esm/core/index.js +62 -47
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/logger.js +17 -24
- package/build/esm/core/logger.js.map +1 -1
- package/build/esm/core/options-mapping.js +95 -115
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +89 -102
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sentry/transports.js +90 -83
- package/build/esm/core/sentry/transports.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +96 -59
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/upload-filter.js +50 -0
- package/build/esm/core/upload-filter.js.map +1 -0
- package/build/esm/core/utils.js +221 -209
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +4 -3
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +176 -194
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/loader-utils/index.js +4 -3
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/debug-id-injection.js +22 -36
- package/build/esm/rollup/debug-id-injection.js.map +1 -1
- package/build/esm/rollup/debug-id-stamping.js +14 -22
- package/build/esm/rollup/debug-id-stamping.js.map +1 -1
- package/build/esm/rollup/index.js +191 -189
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +173 -0
- package/build/esm/rollup/source-map-handling.js.map +1 -0
- package/build/esm/vite/index.js +19 -32
- package/build/esm/vite/index.js.map +1 -1
- package/build/esm/vite/source-map-hooks.js +114 -0
- package/build/esm/vite/source-map-hooks.js.map +1 -0
- package/build/esm/webpack/component-annotation-transform.js +17 -24
- package/build/esm/webpack/component-annotation-transform.js.map +1 -1
- package/build/esm/webpack/index.js +274 -216
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts +33 -10
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/cli.d.ts +6 -1
- package/build/types/core/cli.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +7 -4
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +4 -3
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +4 -3
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +10 -1
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +32 -1
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/upload-filter.d.ts +9 -0
- package/build/types/core/upload-filter.d.ts.map +1 -0
- package/build/types/core/utils.d.ts +4 -0
- package/build/types/core/utils.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts +2 -2
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +107 -7
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts +59 -0
- package/build/types/rollup/source-map-handling.d.ts.map +1 -0
- package/build/types/vite/index.d.ts +4 -8
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/source-map-hooks.d.ts +45 -0
- package/build/types/vite/source-map-hooks.d.ts.map +1 -0
- package/build/types/webpack/index.d.ts +7 -3
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +33 -38
- package/build/cjs/loader-utils/index.js.map +0 -1
- package/build/esm/loader-utils/index.js.map +0 -1
|
@@ -1,190 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const core = require('@sentry/core');
|
|
6
|
-
|
|
1
|
+
const require_component_annotation = require("../babel-plugin/component-annotation.js");
|
|
2
|
+
const require_component_annotation_oxc_ast = require("./component-annotation-oxc-ast.js");
|
|
3
|
+
let _sentry_core = require("@sentry/core");
|
|
4
|
+
// src/core/component-annotation-oxc-jsx.ts
|
|
7
5
|
const UNKNOWN_ELEMENT_NAME = "unknown";
|
|
8
6
|
const REACT_NATIVE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
"Image",
|
|
8
|
+
"Text",
|
|
9
|
+
"View",
|
|
10
|
+
"ScrollView",
|
|
11
|
+
"TextInput",
|
|
12
|
+
"TouchableOpacity",
|
|
13
|
+
"TouchableHighlight",
|
|
14
|
+
"TouchableWithoutFeedback",
|
|
15
|
+
"FlatList",
|
|
16
|
+
"SectionList",
|
|
17
|
+
"ActivityIndicator",
|
|
18
|
+
"Button",
|
|
19
|
+
"Switch",
|
|
20
|
+
"Modal",
|
|
21
|
+
"SafeAreaView",
|
|
22
|
+
"StatusBar",
|
|
23
|
+
"KeyboardAvoidingView",
|
|
24
|
+
"RefreshControl",
|
|
25
|
+
"Picker",
|
|
26
|
+
"Slider"
|
|
29
27
|
]);
|
|
30
|
-
const WEB_ATTRIBUTE_NAMES = [
|
|
28
|
+
const WEB_ATTRIBUTE_NAMES = [
|
|
29
|
+
require_component_annotation.WEB_ELEMENT_NAME,
|
|
30
|
+
require_component_annotation.WEB_COMPONENT_NAME,
|
|
31
|
+
require_component_annotation.WEB_SOURCE_FILE_NAME
|
|
32
|
+
];
|
|
31
33
|
const WEB_ATTRIBUTE_NAME_SET = new Set(WEB_ATTRIBUTE_NAMES);
|
|
32
34
|
function isJSXElement(value) {
|
|
33
|
-
|
|
35
|
+
return require_component_annotation_oxc_ast.isAstNode(value) && value.type === "JSXElement";
|
|
34
36
|
}
|
|
35
37
|
function isJSXFragment(value) {
|
|
36
|
-
|
|
38
|
+
return require_component_annotation_oxc_ast.isAstNode(value) && value.type === "JSXFragment";
|
|
37
39
|
}
|
|
38
40
|
function isJSXRoot(value) {
|
|
39
|
-
|
|
41
|
+
return isJSXElement(value) || isJSXFragment(value);
|
|
40
42
|
}
|
|
41
43
|
function getStringName(node) {
|
|
42
|
-
|
|
44
|
+
return (0, _sentry_core.isObjectLike)(node) && typeof node.name === "string" ? node.name : null;
|
|
43
45
|
}
|
|
44
46
|
function getJSXName(name) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
if (name.type === "JSXNamespacedName") {
|
|
52
|
-
return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;
|
|
53
|
-
}
|
|
54
|
-
if (name.type === "JSXMemberExpression") {
|
|
55
|
-
const objectName = getJSXName(name.object);
|
|
56
|
-
const propertyName = getJSXName(name.property);
|
|
57
|
-
return `${objectName}.${propertyName}`;
|
|
58
|
-
}
|
|
59
|
-
return UNKNOWN_ELEMENT_NAME;
|
|
47
|
+
if (!require_component_annotation_oxc_ast.isAstNode(name)) return UNKNOWN_ELEMENT_NAME;
|
|
48
|
+
if (name.type === "JSXIdentifier") return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;
|
|
49
|
+
if (name.type === "JSXNamespacedName") return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;
|
|
50
|
+
if (name.type === "JSXMemberExpression") return `${getJSXName(name.object)}.${getJSXName(name.property)}`;
|
|
51
|
+
return UNKNOWN_ELEMENT_NAME;
|
|
60
52
|
}
|
|
61
53
|
function getInsertionOffset(code, openingElement) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
let offset = openingElement.end - 2;
|
|
69
|
-
while (offset > 0 && /\s/.test(code[offset] ?? "")) {
|
|
70
|
-
offset -= 1;
|
|
71
|
-
}
|
|
72
|
-
return code[offset] === "/" ? offset : openingElement.end - 1;
|
|
54
|
+
if (typeof openingElement.end !== "number") return null;
|
|
55
|
+
if (!openingElement.selfClosing) return openingElement.end - 1;
|
|
56
|
+
let offset = openingElement.end - 2;
|
|
57
|
+
while (offset > 0 && /\s/.test(code[offset] ?? "")) offset -= 1;
|
|
58
|
+
return code[offset] === "/" ? offset : openingElement.end - 1;
|
|
73
59
|
}
|
|
74
60
|
function isReactFragment(openingElement, fragmentContext) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const objectName = getJSXName(openingElement.name.object);
|
|
84
|
-
const propertyName = getJSXName(openingElement.name.property);
|
|
85
|
-
return propertyName === "Fragment" && (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName));
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
61
|
+
const elementName = getJSXName(openingElement.name);
|
|
62
|
+
if (elementName === "Fragment" || elementName === "React.Fragment") return true;
|
|
63
|
+
if (fragmentContext.fragmentAliases.has(elementName)) return true;
|
|
64
|
+
if ((0, _sentry_core.isObjectLike)(openingElement.name) && openingElement.name.type === "JSXMemberExpression") {
|
|
65
|
+
const objectName = getJSXName(openingElement.name.object);
|
|
66
|
+
return getJSXName(openingElement.name.property) === "Fragment" && (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName));
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
88
69
|
}
|
|
89
70
|
function addPendingAttributes(code, openingElement, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const insertion = getOrCreateInsertion(insertionsByOffset, offset);
|
|
112
|
-
for (const [name, value] of attributes) {
|
|
113
|
-
insertion.attributeValues.set(name, value);
|
|
114
|
-
}
|
|
71
|
+
const offset = getInsertionOffset(code, openingElement);
|
|
72
|
+
if (offset === null) return;
|
|
73
|
+
const pendingInsertion = insertionsByOffset.get(offset);
|
|
74
|
+
const existingAttributes = getExistingAttributeNames(openingElement);
|
|
75
|
+
for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) existingAttributes.add(attributeName);
|
|
76
|
+
const attributes = require_component_annotation.getComponentAnnotationAttributes({
|
|
77
|
+
attributeNames: [
|
|
78
|
+
require_component_annotation.WEB_COMPONENT_NAME,
|
|
79
|
+
require_component_annotation.WEB_ELEMENT_NAME,
|
|
80
|
+
require_component_annotation.WEB_SOURCE_FILE_NAME
|
|
81
|
+
],
|
|
82
|
+
componentName,
|
|
83
|
+
elementName: getJSXName(openingElement.name),
|
|
84
|
+
existingAttributes,
|
|
85
|
+
ignoredComponents,
|
|
86
|
+
isFragment: isReactFragment(openingElement, fragmentContext),
|
|
87
|
+
sourceFileName
|
|
88
|
+
});
|
|
89
|
+
if (attributes.length === 0) return;
|
|
90
|
+
const insertion = getOrCreateInsertion(insertionsByOffset, offset);
|
|
91
|
+
for (const [name, value] of attributes) insertion.attributeValues.set(name, value);
|
|
115
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns `true` when the element is an HTML element, because HTML mode only
|
|
95
|
+
* annotates the first HTML elements below a component root.
|
|
96
|
+
*/
|
|
116
97
|
function addPendingHtmlAttribute(code, openingElement, componentName, ignoredComponents, fragmentContext, insertionsByOffset) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
const offset = getInsertionOffset(code, openingElement);
|
|
128
|
-
if (offset === null) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
if (getExistingAttributeNames(openingElement).has(componentAnnotation.WEB_COMPONENT_NAME) || insertionsByOffset.get(offset)?.attributeValues.has(componentAnnotation.WEB_COMPONENT_NAME)) {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(componentAnnotation.WEB_COMPONENT_NAME, componentName);
|
|
135
|
-
return true;
|
|
98
|
+
if (isReactFragment(openingElement, fragmentContext)) return false;
|
|
99
|
+
const elementName = getJSXName(openingElement.name);
|
|
100
|
+
if (!isHtmlElement(elementName)) return false;
|
|
101
|
+
if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) return true;
|
|
102
|
+
const offset = getInsertionOffset(code, openingElement);
|
|
103
|
+
if (offset === null) return true;
|
|
104
|
+
if (getExistingAttributeNames(openingElement).has("data-sentry-component") || insertionsByOffset.get(offset)?.attributeValues.has("data-sentry-component")) return true;
|
|
105
|
+
getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(require_component_annotation.WEB_COMPONENT_NAME, componentName);
|
|
106
|
+
return true;
|
|
136
107
|
}
|
|
137
108
|
function isHtmlElement(elementName) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return REACT_NATIVE_ELEMENTS.has(elementName);
|
|
109
|
+
if (elementName === UNKNOWN_ELEMENT_NAME) return false;
|
|
110
|
+
if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) return true;
|
|
111
|
+
return REACT_NATIVE_ELEMENTS.has(elementName);
|
|
145
112
|
}
|
|
146
113
|
function getOrCreateInsertion(insertionsByOffset, offset) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
114
|
+
let insertion = insertionsByOffset.get(offset);
|
|
115
|
+
if (!insertion) {
|
|
116
|
+
insertion = {
|
|
117
|
+
offset,
|
|
118
|
+
attributeValues: /* @__PURE__ */ new Map()
|
|
119
|
+
};
|
|
120
|
+
insertionsByOffset.set(offset, insertion);
|
|
121
|
+
}
|
|
122
|
+
return insertion;
|
|
153
123
|
}
|
|
154
124
|
function toAttributeInsertions(insertionsByOffset) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
125
|
+
return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({
|
|
126
|
+
offset,
|
|
127
|
+
attributes: getOrderedAttributes(attributeValues)
|
|
128
|
+
}));
|
|
159
129
|
}
|
|
160
130
|
function getExistingAttributeNames(openingElement) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return names;
|
|
131
|
+
const names = /* @__PURE__ */ new Set();
|
|
132
|
+
for (const attribute of openingElement.attributes ?? []) if (attribute.type === "JSXAttribute") {
|
|
133
|
+
const name = getStringName(attribute.name);
|
|
134
|
+
if (name) names.add(name);
|
|
135
|
+
}
|
|
136
|
+
return names;
|
|
171
137
|
}
|
|
172
138
|
function getOrderedAttributes(attributeValues) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
for (const [name, value] of attributeValues) {
|
|
181
|
-
if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {
|
|
182
|
-
attributes.push([name, value]);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return attributes;
|
|
139
|
+
const attributes = [];
|
|
140
|
+
for (const name of WEB_ATTRIBUTE_NAMES) {
|
|
141
|
+
const value = attributeValues.get(name);
|
|
142
|
+
if (value !== void 0) attributes.push([name, value]);
|
|
143
|
+
}
|
|
144
|
+
for (const [name, value] of attributeValues) if (!WEB_ATTRIBUTE_NAME_SET.has(name)) attributes.push([name, value]);
|
|
145
|
+
return attributes;
|
|
186
146
|
}
|
|
187
|
-
|
|
188
147
|
exports.addPendingAttributes = addPendingAttributes;
|
|
189
148
|
exports.addPendingHtmlAttribute = addPendingHtmlAttribute;
|
|
190
149
|
exports.getInsertionOffset = getInsertionOffset;
|
|
@@ -195,4 +154,5 @@ exports.isJSXFragment = isJSXFragment;
|
|
|
195
154
|
exports.isJSXRoot = isJSXRoot;
|
|
196
155
|
exports.isReactFragment = isReactFragment;
|
|
197
156
|
exports.toAttributeInsertions = toAttributeInsertions;
|
|
198
|
-
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=component-annotation-oxc-jsx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-jsx.js","sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst REACT_NATIVE_ELEMENTS = new Set([\n 'Image',\n 'Text',\n 'View',\n 'ScrollView',\n 'TextInput',\n 'TouchableOpacity',\n 'TouchableHighlight',\n 'TouchableWithoutFeedback',\n 'FlatList',\n 'SectionList',\n 'ActivityIndicator',\n 'Button',\n 'Switch',\n 'Modal',\n 'SafeAreaView',\n 'StatusBar',\n 'KeyboardAvoidingView',\n 'RefreshControl',\n 'Picker',\n 'Slider',\n]);\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion = getOrCreateInsertion(insertionsByOffset, offset);\n\n for (const [name, value] of attributes) {\n insertion.attributeValues.set(name, value);\n }\n}\n\n/**\n * Returns `true` when the element is an HTML element, because HTML mode only\n * annotates the first HTML elements below a component root.\n */\nexport function addPendingHtmlAttribute(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, PendingInsertion>,\n): boolean {\n if (isReactFragment(openingElement, fragmentContext)) {\n return false;\n }\n\n const elementName = getJSXName(openingElement.name);\n\n if (!isHtmlElement(elementName)) {\n return false;\n }\n\n if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) {\n return true;\n }\n\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return true;\n }\n\n if (\n getExistingAttributeNames(openingElement).has(WEB_COMPONENT_NAME) ||\n insertionsByOffset.get(offset)?.attributeValues.has(WEB_COMPONENT_NAME)\n ) {\n return true;\n }\n\n getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(WEB_COMPONENT_NAME, componentName);\n\n return true;\n}\n\nfunction isHtmlElement(elementName: string): boolean {\n if (elementName === UNKNOWN_ELEMENT_NAME) {\n return false;\n }\n\n if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {\n return true;\n }\n\n return REACT_NATIVE_ELEMENTS.has(elementName);\n}\n\nfunction getOrCreateInsertion(insertionsByOffset: Map<number, PendingInsertion>, offset: number): PendingInsertion {\n let insertion = insertionsByOffset.get(offset);\n\n if (!insertion) {\n insertion = { offset, attributeValues: new Map() };\n insertionsByOffset.set(offset, insertion);\n }\n\n return insertion;\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n // HTML mode writes an empty component name for anonymous classes.\n if (value !== undefined) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"names":["WEB_ELEMENT_NAME","WEB_COMPONENT_NAME","WEB_SOURCE_FILE_NAME","isAstNode","isObjectLike","getComponentAnnotationAttributes"],"mappings":";;;;;;AAiBA,MAAM,oBAAA,GAAuB,SAAA;AAC7B,MAAM,qBAAA,uBAA4B,GAAA,CAAI;AAAA,EACpC,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,0BAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA;AAAA,EACA,mBAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AACD,MAAM,mBAAA,GAAsB,CAACA,oCAAA,EAAkBC,sCAAA,EAAoBC,wCAAoB,CAAA;AACvF,MAAM,sBAAA,GAAyB,IAAI,GAAA,CAAY,mBAAmB,CAAA;AAO3D,SAAS,aAAa,KAAA,EAAyC;AACpE,EAAA,OAAOC,mCAAA,CAAU,KAAK,CAAA,IAA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AAC,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACrC,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,OAAO,UAAA;AACT;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-jsx.js","names":["WEB_ELEMENT_NAME","WEB_COMPONENT_NAME","WEB_SOURCE_FILE_NAME","isAstNode","isObjectLike","getComponentAnnotationAttributes"],"sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst REACT_NATIVE_ELEMENTS = new Set([\n 'Image',\n 'Text',\n 'View',\n 'ScrollView',\n 'TextInput',\n 'TouchableOpacity',\n 'TouchableHighlight',\n 'TouchableWithoutFeedback',\n 'FlatList',\n 'SectionList',\n 'ActivityIndicator',\n 'Button',\n 'Switch',\n 'Modal',\n 'SafeAreaView',\n 'StatusBar',\n 'KeyboardAvoidingView',\n 'RefreshControl',\n 'Picker',\n 'Slider',\n]);\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion = getOrCreateInsertion(insertionsByOffset, offset);\n\n for (const [name, value] of attributes) {\n insertion.attributeValues.set(name, value);\n }\n}\n\n/**\n * Returns `true` when the element is an HTML element, because HTML mode only\n * annotates the first HTML elements below a component root.\n */\nexport function addPendingHtmlAttribute(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, PendingInsertion>,\n): boolean {\n if (isReactFragment(openingElement, fragmentContext)) {\n return false;\n }\n\n const elementName = getJSXName(openingElement.name);\n\n if (!isHtmlElement(elementName)) {\n return false;\n }\n\n if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) {\n return true;\n }\n\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return true;\n }\n\n if (\n getExistingAttributeNames(openingElement).has(WEB_COMPONENT_NAME) ||\n insertionsByOffset.get(offset)?.attributeValues.has(WEB_COMPONENT_NAME)\n ) {\n return true;\n }\n\n getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(WEB_COMPONENT_NAME, componentName);\n\n return true;\n}\n\nfunction isHtmlElement(elementName: string): boolean {\n if (elementName === UNKNOWN_ELEMENT_NAME) {\n return false;\n }\n\n if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {\n return true;\n }\n\n return REACT_NATIVE_ELEMENTS.has(elementName);\n}\n\nfunction getOrCreateInsertion(insertionsByOffset: Map<number, PendingInsertion>, offset: number): PendingInsertion {\n let insertion = insertionsByOffset.get(offset);\n\n if (!insertion) {\n insertion = { offset, attributeValues: new Map() };\n insertionsByOffset.set(offset, insertion);\n }\n\n return insertion;\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n // HTML mode writes an empty component name for anonymous classes.\n if (value !== undefined) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"mappings":";;;;AAiBA,MAAM,uBAAuB;AAC7B,MAAM,wCAAwB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,sBAAsB;CAACA,6BAAAA;CAAkBC,6BAAAA;CAAoBC,6BAAAA;AAAoB;AACvF,MAAM,yBAAyB,IAAI,I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CAAC,MAAM,KAAK,CAAC;CAIjC,OAAO;AACT"}
|
|
@@ -1,142 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const core = require('@sentry/core');
|
|
7
|
-
|
|
1
|
+
const require_component_annotation_oxc_jsx = require("./component-annotation-oxc-jsx.js");
|
|
2
|
+
const require_component_annotation_oxc_ast = require("./component-annotation-oxc-ast.js");
|
|
3
|
+
const require_component_annotation_oxc_fragments = require("./component-annotation-oxc-fragments.js");
|
|
4
|
+
let _sentry_core = require("@sentry/core");
|
|
5
|
+
// src/core/component-annotation-oxc-walk.ts
|
|
8
6
|
function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName, injectIntoHtml) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
16
|
-
} else {
|
|
17
|
-
processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return componentAnnotationOxcJsx.toAttributeInsertions(insertionsByOffset);
|
|
7
|
+
const fragmentContext = require_component_annotation_oxc_fragments.collectFragmentContext(ast);
|
|
8
|
+
const components = collectComponentJSXRoots(ast);
|
|
9
|
+
const insertionsByOffset = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const component of components) for (const root of component.roots) if (injectIntoHtml) processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
11
|
+
else processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
12
|
+
return require_component_annotation_oxc_jsx.toAttributeInsertions(insertionsByOffset);
|
|
22
13
|
}
|
|
23
14
|
function processHtmlJSX(code, node, componentName, ignoredComponents, fragmentContext, insertionsByOffset) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
node.openingElement,
|
|
27
|
-
componentName,
|
|
28
|
-
ignoredComponents,
|
|
29
|
-
fragmentContext,
|
|
30
|
-
insertionsByOffset
|
|
31
|
-
)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
for (const child of node.children ?? []) {
|
|
35
|
-
if (componentAnnotationOxcJsx.isJSXRoot(child)) {
|
|
36
|
-
processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
15
|
+
if (require_component_annotation_oxc_jsx.isJSXElement(node) && require_component_annotation_oxc_jsx.addPendingHtmlAttribute(code, node.openingElement, componentName, ignoredComponents, fragmentContext, insertionsByOffset)) return;
|
|
16
|
+
for (const child of node.children ?? []) if (require_component_annotation_oxc_jsx.isJSXRoot(child)) processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
39
17
|
}
|
|
40
18
|
function getJSXRootsFromReturnArgument(argument) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (core.isObjectLike(argument) && argument.type === "ConditionalExpression") {
|
|
45
|
-
return [argument.consequent, argument.alternate].filter(componentAnnotationOxcJsx.isJSXRoot);
|
|
46
|
-
}
|
|
47
|
-
return [];
|
|
19
|
+
if (require_component_annotation_oxc_jsx.isJSXRoot(argument)) return [argument];
|
|
20
|
+
if ((0, _sentry_core.isObjectLike)(argument) && argument.type === "ConditionalExpression") return [argument.consequent, argument.alternate].filter(require_component_annotation_oxc_jsx.isJSXRoot);
|
|
21
|
+
return [];
|
|
48
22
|
}
|
|
49
23
|
function getReturnedJSXFromFunction(functionNode) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const bodyStatements = Array.isArray(body.body) ? body.body : [];
|
|
58
|
-
const returnStatement = bodyStatements.find((statement) => {
|
|
59
|
-
return componentAnnotationOxcAst.isAstNode(statement) && statement.type === "ReturnStatement";
|
|
60
|
-
});
|
|
61
|
-
return core.isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];
|
|
24
|
+
const body = functionNode.body;
|
|
25
|
+
if (require_component_annotation_oxc_jsx.isJSXRoot(body)) return [body];
|
|
26
|
+
if (!(0, _sentry_core.isObjectLike)(body) || body.type !== "BlockStatement") return [];
|
|
27
|
+
const returnStatement = (Array.isArray(body.body) ? body.body : []).find((statement) => {
|
|
28
|
+
return require_component_annotation_oxc_ast.isAstNode(statement) && statement.type === "ReturnStatement";
|
|
29
|
+
});
|
|
30
|
+
return (0, _sentry_core.isObjectLike)(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];
|
|
62
31
|
}
|
|
63
32
|
function pushFunctionComponent(components, nameNode, functionNode) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
}
|
|
33
|
+
const name = require_component_annotation_oxc_jsx.getStringName(nameNode);
|
|
34
|
+
if (name) components.push({
|
|
35
|
+
name,
|
|
36
|
+
roots: getReturnedJSXFromFunction(functionNode)
|
|
37
|
+
});
|
|
71
38
|
}
|
|
72
39
|
function collectComponentJSXRoots(ast) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
pushClassComponent(components, node);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return components;
|
|
40
|
+
const components = [];
|
|
41
|
+
require_component_annotation_oxc_ast.walkAst(ast, (node) => {
|
|
42
|
+
if (node.type === "FunctionDeclaration" && (0, _sentry_core.isObjectLike)(node.id)) {
|
|
43
|
+
pushFunctionComponent(components, node.id, node);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (node.type === "VariableDeclarator" && (0, _sentry_core.isObjectLike)(node.id)) {
|
|
47
|
+
if (require_component_annotation_oxc_ast.isAstNode(node.init) && node.init.type === "ArrowFunctionExpression") pushFunctionComponent(components, node.id, node.init);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (node.type === "ClassDeclaration") pushClassComponent(components, node);
|
|
51
|
+
});
|
|
52
|
+
return components;
|
|
90
53
|
}
|
|
91
54
|
function pushClassComponent(components, node) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
components.push({
|
|
103
|
-
name: componentAnnotationOxcJsx.getStringName(node.id) ?? "",
|
|
104
|
-
roots
|
|
105
|
-
});
|
|
55
|
+
const renderMethodBody = getClassRenderMethodBody(node);
|
|
56
|
+
if (!renderMethodBody) return;
|
|
57
|
+
const roots = [];
|
|
58
|
+
require_component_annotation_oxc_ast.walkAst(renderMethodBody, (child) => {
|
|
59
|
+
if (child.type === "ReturnStatement" && require_component_annotation_oxc_jsx.isJSXRoot(child.argument)) roots.push(child.argument);
|
|
60
|
+
});
|
|
61
|
+
components.push({
|
|
62
|
+
name: require_component_annotation_oxc_jsx.getStringName(node.id) ?? "",
|
|
63
|
+
roots
|
|
64
|
+
});
|
|
106
65
|
}
|
|
107
66
|
function getClassRenderMethodBody(node) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
if (componentAnnotationOxcAst.isAstNode(renderMethod.value)) {
|
|
118
|
-
return renderMethod.value;
|
|
119
|
-
}
|
|
120
|
-
return componentAnnotationOxcAst.isAstNode(renderMethod) ? renderMethod : null;
|
|
67
|
+
if (!(0, _sentry_core.isObjectLike)(node.body) || !Array.isArray(node.body.body)) return null;
|
|
68
|
+
const renderMethod = node.body.body.find((member) => {
|
|
69
|
+
return (0, _sentry_core.isObjectLike)(member) && (0, _sentry_core.isObjectLike)(member.key) && require_component_annotation_oxc_jsx.getStringName(member.key) === "render" && ((0, _sentry_core.isObjectLike)(member.value) || (0, _sentry_core.isObjectLike)(member.body));
|
|
70
|
+
});
|
|
71
|
+
if (!(0, _sentry_core.isObjectLike)(renderMethod)) return null;
|
|
72
|
+
if (require_component_annotation_oxc_ast.isAstNode(renderMethod.value)) return renderMethod.value;
|
|
73
|
+
return require_component_annotation_oxc_ast.isAstNode(renderMethod) ? renderMethod : null;
|
|
121
74
|
}
|
|
122
75
|
function processJSX(code, node, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
code,
|
|
126
|
-
node.openingElement,
|
|
127
|
-
componentName,
|
|
128
|
-
ignoredComponents,
|
|
129
|
-
fragmentContext,
|
|
130
|
-
sourceFileName,
|
|
131
|
-
insertionsByOffset
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
for (const child of node.children ?? []) {
|
|
135
|
-
if (componentAnnotationOxcJsx.isJSXRoot(child)) {
|
|
136
|
-
processJSX(code, child, "", ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
76
|
+
if (require_component_annotation_oxc_jsx.isJSXElement(node)) require_component_annotation_oxc_jsx.addPendingAttributes(code, node.openingElement, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
77
|
+
for (const child of node.children ?? []) if (require_component_annotation_oxc_jsx.isJSXRoot(child)) processJSX(code, child, "", ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
139
78
|
}
|
|
140
|
-
|
|
141
79
|
exports.collectOxcComponentAnnotationInsertions = collectOxcComponentAnnotationInsertions;
|
|
142
|
-
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=component-annotation-oxc-walk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-walk.js","sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n addPendingHtmlAttribute,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-oxc-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { collectFragmentContext } from './component-annotation-oxc-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectOxcComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n injectIntoHtml: boolean,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n if (injectIntoHtml) {\n processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);\n } else {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction processHtmlJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (\n isJSXElement(node) &&\n addPendingHtmlAttribute(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n insertionsByOffset,\n )\n ) {\n return;\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);\n }\n }\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"names":["collectFragmentContext","toAttributeInsertions","isJSXElement","addPendingHtmlAttribute","isJSXRoot","isObjectLike","isAstNode","getStringName","walkAst","addPendingAttributes"],"mappings":";;;;;;;AAcO,SAAS,uCAAA,CACd,IAAA,EACA,GAAA,EACA,iBAAA,EACA,gBACA,cAAA,EACsB;AACtB,EAAA,MAAM,eAAA,GAAkBA,uDAAuB,GAAG,CAAA;AAClD,EAAA,MAAM,UAAA,GAAa,yBAAyB,GAAG,CAAA;AAC/C,EAAA,MAAM,kBAAA,uBAAyB,GAAA,EAAsE;AAErG,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;AAClC,MAAA,IAAI,cAAA,EAAgB;AAClB,QAAA,cAAA,CAAe,MAAM,IAAA,EAAM,SAAA,CAAU,IAAA,EAAM,iBAAA,EAAmB,iBAAiB,kBAAkB,CAAA;AAAA,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A,KAAU;AACjD,IAAA,OACEA,kBAAa,MAAM,CAAA,IACnBA,kBAAa,MAAA,CAAO,GAAG,KACvBE,uCAAA,CAAc,MAAA,CAAO,GAAG,CAAA,KAAM,aAC7BF,iBAAA,CAAa,MAAA,CAAO,KAAK,CAAA,IAAKA,iBAAA,CAAa,OAAO,IAAI,CAAA,CAAA;AAAA,EAE3D,CAAC,CAAA;AAED,EAAA,IAAI,CAACA,iBAAA,CAAa,YAAY,CAAA,EAAG;AAC/B,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAIC,mCAAA,CAAU,YAAA,CAAa,KAAK,CAAA,EAAG;AACjC,IAAA,OAAO,YAAA,CAAa,KAAA;AAAA,EACtB;AAEA,EAAA,OAAOA,mCAAA,CAAU,YAAY,CAAA,GAAI,YAAA,GAAe,IAAA;AAClD;AAEA,SAAS,WACP,IAAA,EACA,IAAA,EACA,eACA,iBAAA,EACA,eAAA,EACA,gBACA,kBAAA,EACM;AACN,EAAA,IAAIJ,sCAAA,CAAa,IAAI,CAAA,EAAG;AACtB,IAAAO,8CAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA,CAAK,cAAA;AAAA,MACL,aAAA;AAAA,MACA,iBAAA;AAAA,MACA,eAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAIL,mCAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-walk.js","names":["collectFragmentContext","toAttributeInsertions","isJSXElement","addPendingHtmlAttribute","isJSXRoot","isObjectLike","isAstNode","getStringName","walkAst","addPendingAttributes"],"sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n addPendingHtmlAttribute,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-oxc-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { collectFragmentContext } from './component-annotation-oxc-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectOxcComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n injectIntoHtml: boolean,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n if (injectIntoHtml) {\n processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);\n } else {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction processHtmlJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (\n isJSXElement(node) &&\n addPendingHtmlAttribute(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n insertionsByOffset,\n )\n ) {\n return;\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);\n }\n }\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"mappings":";;;;;AAcA,SAAgB,wCACd,MACA,KACA,mBACA,gBACA,gBACsB;CACtB,MAAM,kBAAkBA,2CAAAA,uBAAuB,GAAG;CAClD,MAAM,aAAa,yBAAyB,GAAG;CAC/C,MAAM,qCAAqB,IAAI,IAAsE;CAErG,KAAK,MAAM,aAAa,YACtB,KAAK,MAAM,QAAQ,UAAU,OAC3B,IAAI,gBACF,eAAe,MAAM,MAAM,UAAU,MAAM,mBAAmB,iBAAiB,kBAAkB;MAEjG,WAAW,MAAM,MAAM,UAAU,MAAM,mBAAmB,iBAAiB,gBAAgB,kBAAkB;CAKnH,OAAOC,qCAAAA,sBAAsB,kBAAkB;AACjD;AAEA,SAAS,eACP,MACA,MACA,eACA,mBACA,iBACA,oBACM;CACN,IACEC,qCAAAA,aAAa,IAAI,KACjBC,qCAAAA,wBACE,MACA,KAAK,gBACL,eACA,mBACA,iBACA,kBACF,GAEA;CAGF,KAAK,MAAM,SAAS,KAAK,YAAY,CAAC,GACpC,IAAIC,qCAAAA,UAAU,KAAK,GACjB,eAAe,MAAM,OAAO,eAAe,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