@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,30 +1,21 @@
|
|
|
1
|
-
import { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync } from
|
|
2
|
-
|
|
1
|
+
import { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync } from "./component-annotation-oxc.js";
|
|
2
|
+
// src/core/component-annotate-hooks.ts
|
|
3
3
|
const PARSER_UNAVAILABLE_MESSAGE = "Could not load `oxc-parser` for this platform. React components will not be annotated.";
|
|
4
4
|
let warnedParserUnavailable = false;
|
|
5
5
|
function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml, options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return parseAstAsync;
|
|
19
|
-
},
|
|
20
|
-
injectIntoHtml
|
|
21
|
-
);
|
|
22
|
-
return {
|
|
23
|
-
transform(code, id, meta) {
|
|
24
|
-
return hooks.transform(code, id, meta);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
6
|
+
const hooks = createOxcComponentNameAnnotateHooks(ignoredComponents, async () => {
|
|
7
|
+
const parseAstAsync = await options.getParseAstAsync?.() ?? await getOxcParseAstAsync();
|
|
8
|
+
if (!parseAstAsync && !warnedParserUnavailable) {
|
|
9
|
+
warnedParserUnavailable = true;
|
|
10
|
+
if (options.logger) options.logger.warn(PARSER_UNAVAILABLE_MESSAGE);
|
|
11
|
+
else console.warn(`[@sentry/bundler-plugins] ${PARSER_UNAVAILABLE_MESSAGE}`);
|
|
12
|
+
}
|
|
13
|
+
return parseAstAsync;
|
|
14
|
+
}, injectIntoHtml);
|
|
15
|
+
return { transform(code, id, meta) {
|
|
16
|
+
return hooks.transform(code, id, meta);
|
|
17
|
+
} };
|
|
27
18
|
}
|
|
28
|
-
|
|
29
19
|
export { createComponentNameAnnotateHooks };
|
|
30
|
-
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=component-annotate-hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotate-hooks.js","sources":["../../../src/core/component-annotate-hooks.ts"],"sourcesContent":["import { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync } from './component-annotation-oxc';\nimport type { ComponentAnnotationTransformMeta, ParseAstAsync } from './component-annotation-oxc-ast';\nimport type { Logger } from './logger';\n\nconst PARSER_UNAVAILABLE_MESSAGE =\n 'Could not load `oxc-parser` for this platform. React components will not be annotated.';\n\n// Module level, because the Turbopack loader creates new hooks for\n// every file.\nlet warnedParserUnavailable = false;\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(\n ignoredComponents: string[],\n injectIntoHtml: boolean,\n options: { getParseAstAsync?: () => Promise<ParseAstAsync | null>; logger?: Logger } = {},\n) {\n const hooks = createOxcComponentNameAnnotateHooks(\n ignoredComponents,\n async () => {\n const parseAstAsync = (await options.getParseAstAsync?.()) ?? (await getOxcParseAstAsync());\n\n if (!parseAstAsync && !warnedParserUnavailable) {\n warnedParserUnavailable = true;\n if (options.logger) {\n options.logger.warn(PARSER_UNAVAILABLE_MESSAGE);\n } else {\n // eslint-disable-next-line no-console\n console.warn(`[@sentry/bundler-plugins] ${PARSER_UNAVAILABLE_MESSAGE}`);\n }\n }\n\n return parseAstAsync;\n },\n injectIntoHtml,\n );\n\n return {\n transform(this: void, code: string, id: string, meta?: ComponentAnnotationTransformMeta) {\n return hooks.transform(code, id, meta);\n },\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"component-annotate-hooks.js","names":[],"sources":["../../../src/core/component-annotate-hooks.ts"],"sourcesContent":["import { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync } from './component-annotation-oxc';\nimport type { ComponentAnnotationTransformMeta, ParseAstAsync } from './component-annotation-oxc-ast';\nimport type { Logger } from './logger';\n\nconst PARSER_UNAVAILABLE_MESSAGE =\n 'Could not load `oxc-parser` for this platform. React components will not be annotated.';\n\n// Module level, because the Turbopack loader creates new hooks for\n// every file.\nlet warnedParserUnavailable = false;\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(\n ignoredComponents: string[],\n injectIntoHtml: boolean,\n options: { getParseAstAsync?: () => Promise<ParseAstAsync | null>; logger?: Logger } = {},\n) {\n const hooks = createOxcComponentNameAnnotateHooks(\n ignoredComponents,\n async () => {\n const parseAstAsync = (await options.getParseAstAsync?.()) ?? (await getOxcParseAstAsync());\n\n if (!parseAstAsync && !warnedParserUnavailable) {\n warnedParserUnavailable = true;\n if (options.logger) {\n options.logger.warn(PARSER_UNAVAILABLE_MESSAGE);\n } else {\n // eslint-disable-next-line no-console\n console.warn(`[@sentry/bundler-plugins] ${PARSER_UNAVAILABLE_MESSAGE}`);\n }\n }\n\n return parseAstAsync;\n },\n injectIntoHtml,\n );\n\n return {\n transform(this: void, code: string, id: string, meta?: ComponentAnnotationTransformMeta) {\n return hooks.transform(code, id, meta);\n },\n };\n}\n"],"mappings":";;AAIA,MAAM,6BACJ;AAIF,IAAI,0BAA0B;AAG9B,SAAgB,iCACd,mBACA,gBACA,UAAuF,CAAC,GACxF;CACA,MAAM,QAAQ,oCACZ,mBACA,YAAY;EACV,MAAM,gBAAiB,MAAM,QAAQ,mBAAmB,KAAO,MAAM,oBAAoB;EAEzF,IAAI,CAAC,iBAAiB,CAAC,yBAAyB;GAC9C,0BAA0B;GAC1B,IAAI,QAAQ,QACV,QAAQ,OAAO,KAAK,0BAA0B;QAG9C,QAAQ,KAAK,6BAA6B,4BAA4B;EAE1E;EAEA,OAAO;CACT,GACA,cACF;CAEA,OAAO,EACL,UAAsB,MAAc,IAAY,MAAyC;EACvF,OAAO,MAAM,UAAU,MAAM,IAAI,IAAI;CACvC,EACF;AACF"}
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import { isObjectLike } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isObjectLike } from "@sentry/core";
|
|
2
|
+
// src/core/component-annotation-oxc-ast.ts
|
|
4
3
|
function isAstNode(value) {
|
|
5
|
-
|
|
4
|
+
return isObjectLike(value) && typeof value.type === "string";
|
|
6
5
|
}
|
|
7
6
|
function walkAst(node, visit) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (const value of Object.values(node)) {
|
|
13
|
-
if (Array.isArray(value)) {
|
|
14
|
-
for (const child of value) {
|
|
15
|
-
walkAst(child, visit);
|
|
16
|
-
}
|
|
17
|
-
} else if (isAstNode(value)) {
|
|
18
|
-
walkAst(value, visit);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
7
|
+
if (!isAstNode(node)) return;
|
|
8
|
+
visit(node);
|
|
9
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) for (const child of value) walkAst(child, visit);
|
|
10
|
+
else if (isAstNode(value)) walkAst(value, visit);
|
|
21
11
|
}
|
|
12
|
+
export { isAstNode, isObjectLike, walkAst };
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
//# sourceMappingURL=component-annotation-oxc-ast.js.map
|
|
14
|
+
//# sourceMappingURL=component-annotation-oxc-ast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-ast.js","sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult = {\n code: string;\n map?: SourceMap | string;\n} | null;\n\nexport function isAstNode(value: unknown): value is AstNode {\n return isObjectLike(value) && typeof value.type === 'string';\n}\n\nexport function walkAst(node: unknown, visit: (node: AstNode) => void): void {\n if (!isAstNode(node)) {\n return;\n }\n\n visit(node);\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n walkAst(child, visit);\n }\n } else if (isAstNode(value)) {\n walkAst(value, visit);\n }\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-ast.js","names":[],"sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult = {\n code: string;\n map?: SourceMap | string;\n} | null;\n\nexport function isAstNode(value: unknown): value is AstNode {\n return isObjectLike(value) && typeof value.type === 'string';\n}\n\nexport function walkAst(node: unknown, visit: (node: AstNode) => void): void {\n if (!isAstNode(node)) {\n return;\n }\n\n visit(node);\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n walkAst(child, visit);\n }\n } else if (isAstNode(value)) {\n walkAst(value, visit);\n }\n }\n}\n"],"mappings":";;AAkEA,SAAgB,UAAU,OAAkC;CAC1D,OAAO,aAAa,KAAK,KAAK,OAAO,MAAM,SAAS;AACtD;AAEA,SAAgB,QAAQ,MAAe,OAAsC;CAC3E,IAAI,CAAC,UAAU,IAAI,GACjB;CAGF,MAAM,IAAI;CAEV,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GACpC,IAAI,MAAM,QAAQ,KAAK,GACrB,KAAK,MAAM,SAAS,OAClB,QAAQ,OAAO,KAAK;MAEjB,IAAI,UAAU,KAAK,GACxB,QAAQ,OAAO,KAAK;AAG1B"}
|
|
@@ -1,89 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getStringName } from
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isAstNode, isObjectLike, walkAst } from "./component-annotation-oxc-ast.js";
|
|
2
|
+
import { getStringName } from "./component-annotation-oxc-jsx.js";
|
|
3
|
+
// src/core/component-annotation-oxc-fragments.ts
|
|
5
4
|
function collectFragmentContext(ast) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const context = {
|
|
6
|
+
fragmentAliases: /* @__PURE__ */ new Set(),
|
|
7
|
+
reactNamespaceAliases: /* @__PURE__ */ new Set(["React"])
|
|
8
|
+
};
|
|
9
|
+
walkAst(ast, (node) => {
|
|
10
|
+
collectFragmentAliasesFromImport(node, context);
|
|
11
|
+
collectFragmentAliasesFromVariableDeclarator(node, context);
|
|
12
|
+
});
|
|
13
|
+
return context;
|
|
15
14
|
}
|
|
16
15
|
function collectFragmentAliasesFromImport(node, context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
const localName = getStringName(specifier.local);
|
|
30
|
-
if (!localName) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportNamespaceSpecifier") {
|
|
34
|
-
context.reactNamespaceAliases.add(localName);
|
|
35
|
-
} else if (isImportedReactFragment(specifier)) {
|
|
36
|
-
context.fragmentAliases.add(localName);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
16
|
+
if (node.type !== "ImportDeclaration" || !isObjectLike(node.source)) return;
|
|
17
|
+
const source = node.source.value;
|
|
18
|
+
if (source !== "react" && source !== "React") return;
|
|
19
|
+
const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];
|
|
20
|
+
for (const specifier of specifiers) {
|
|
21
|
+
if (!isAstNode(specifier) || !isObjectLike(specifier.local)) continue;
|
|
22
|
+
const localName = getStringName(specifier.local);
|
|
23
|
+
if (!localName) continue;
|
|
24
|
+
if (specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportNamespaceSpecifier") context.reactNamespaceAliases.add(localName);
|
|
25
|
+
else if (isImportedReactFragment(specifier)) context.fragmentAliases.add(localName);
|
|
26
|
+
}
|
|
39
27
|
}
|
|
40
28
|
function collectFragmentAliasesFromVariableDeclarator(node, context) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (node.id.type === "ObjectPattern") {
|
|
49
|
-
collectFragmentAliasFromObjectPattern(node.id, node.init, context);
|
|
50
|
-
}
|
|
29
|
+
if (node.type !== "VariableDeclarator" || !isObjectLike(node.id) || !isObjectLike(node.init)) return;
|
|
30
|
+
if (node.id.type === "Identifier") {
|
|
31
|
+
collectFragmentAliasFromIdentifier(node.id, node.init, context);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (node.id.type === "ObjectPattern") collectFragmentAliasFromObjectPattern(node.id, node.init, context);
|
|
51
35
|
}
|
|
52
36
|
function collectFragmentAliasFromIdentifier(id, init, context) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (init.type === "Identifier" && context.fragmentAliases.has(getStringName(init) ?? "")) {
|
|
58
|
-
context.fragmentAliases.add(localName);
|
|
59
|
-
}
|
|
60
|
-
if (isReactFragmentMemberExpression(init, context)) {
|
|
61
|
-
context.fragmentAliases.add(localName);
|
|
62
|
-
}
|
|
37
|
+
const localName = getStringName(id);
|
|
38
|
+
if (!localName) return;
|
|
39
|
+
if (init.type === "Identifier" && context.fragmentAliases.has(getStringName(init) ?? "")) context.fragmentAliases.add(localName);
|
|
40
|
+
if (isReactFragmentMemberExpression(init, context)) context.fragmentAliases.add(localName);
|
|
63
41
|
}
|
|
64
42
|
function collectFragmentAliasFromObjectPattern(id, init, context) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
const localName = getStringName(property.value);
|
|
73
|
-
if (localName) {
|
|
74
|
-
context.fragmentAliases.add(localName);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
43
|
+
if (init.type !== "Identifier" || !context.reactNamespaceAliases.has(getStringName(init) ?? "") || !Array.isArray(id.properties)) return;
|
|
44
|
+
for (const property of id.properties) {
|
|
45
|
+
if (!isFragmentObjectPatternProperty(property)) continue;
|
|
46
|
+
const localName = getStringName(property.value);
|
|
47
|
+
if (localName) context.fragmentAliases.add(localName);
|
|
48
|
+
}
|
|
77
49
|
}
|
|
78
50
|
function isImportedReactFragment(specifier) {
|
|
79
|
-
|
|
51
|
+
return specifier.type === "ImportSpecifier" && isObjectLike(specifier.imported) && getStringName(specifier.imported) === "Fragment";
|
|
80
52
|
}
|
|
81
53
|
function isReactFragmentMemberExpression(init, context) {
|
|
82
|
-
|
|
54
|
+
return init.type === "MemberExpression" && isObjectLike(init.object) && isObjectLike(init.property) && context.reactNamespaceAliases.has(getStringName(init.object) ?? "") && getStringName(init.property) === "Fragment";
|
|
83
55
|
}
|
|
84
56
|
function isFragmentObjectPatternProperty(property) {
|
|
85
|
-
|
|
57
|
+
return isObjectLike(property) && (property.type === "Property" || property.type === "ObjectProperty") && isObjectLike(property.key) && getStringName(property.key) === "Fragment" && isObjectLike(property.value);
|
|
86
58
|
}
|
|
87
|
-
|
|
88
59
|
export { collectFragmentContext };
|
|
89
|
-
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=component-annotation-oxc-fragments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-fragments.js","sources":["../../../src/core/component-annotation-oxc-fragments.ts"],"sourcesContent":["import type { AstNode, FragmentContext } from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { getStringName } from './component-annotation-oxc-jsx';\n\nexport function collectFragmentContext(ast: AstNode): FragmentContext {\n const context: FragmentContext = {\n fragmentAliases: new Set<string>(),\n reactNamespaceAliases: new Set<string>(['React']),\n };\n\n walkAst(ast, node => {\n collectFragmentAliasesFromImport(node, context);\n collectFragmentAliasesFromVariableDeclarator(node, context);\n });\n\n return context;\n}\n\nfunction collectFragmentAliasesFromImport(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'ImportDeclaration' || !isObjectLike(node.source)) {\n return;\n }\n\n const source = node.source.value;\n if (source !== 'react' && source !== 'React') {\n return;\n }\n\n const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];\n\n for (const specifier of specifiers) {\n if (!isAstNode(specifier) || !isObjectLike(specifier.local)) {\n continue;\n }\n\n const localName = getStringName(specifier.local);\n if (!localName) {\n continue;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportNamespaceSpecifier') {\n context.reactNamespaceAliases.add(localName);\n } else if (isImportedReactFragment(specifier)) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction collectFragmentAliasesFromVariableDeclarator(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'VariableDeclarator' || !isObjectLike(node.id) || !isObjectLike(node.init)) {\n return;\n }\n\n if (node.id.type === 'Identifier') {\n collectFragmentAliasFromIdentifier(node.id, node.init, context);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectFragmentAliasFromObjectPattern(node.id, node.init, context);\n }\n}\n\nfunction collectFragmentAliasFromIdentifier(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n const localName = getStringName(id);\n if (!localName) {\n return;\n }\n\n if (init.type === 'Identifier' && context.fragmentAliases.has(getStringName(init) ?? '')) {\n context.fragmentAliases.add(localName);\n }\n\n if (isReactFragmentMemberExpression(init, context)) {\n context.fragmentAliases.add(localName);\n }\n}\n\nfunction collectFragmentAliasFromObjectPattern(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n if (\n init.type !== 'Identifier' ||\n !context.reactNamespaceAliases.has(getStringName(init) ?? '') ||\n !Array.isArray(id.properties)\n ) {\n return;\n }\n\n for (const property of id.properties) {\n if (!isFragmentObjectPatternProperty(property)) {\n continue;\n }\n\n const localName = getStringName(property.value);\n if (localName) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction isImportedReactFragment(specifier: AstNode): boolean {\n return (\n specifier.type === 'ImportSpecifier' &&\n isObjectLike(specifier.imported) &&\n getStringName(specifier.imported) === 'Fragment'\n );\n}\n\nfunction isReactFragmentMemberExpression(init: Record<string, unknown>, context: FragmentContext): boolean {\n return (\n init.type === 'MemberExpression' &&\n isObjectLike(init.object) &&\n isObjectLike(init.property) &&\n context.reactNamespaceAliases.has(getStringName(init.object) ?? '') &&\n getStringName(init.property) === 'Fragment'\n );\n}\n\nfunction isFragmentObjectPatternProperty(property: unknown): property is { value: unknown } {\n return (\n isObjectLike(property) &&\n (property.type === 'Property' || property.type === 'ObjectProperty') &&\n isObjectLike(property.key) &&\n getStringName(property.key) === 'Fragment' &&\n isObjectLike(property.value)\n );\n}\n"],"
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-fragments.js","names":[],"sources":["../../../src/core/component-annotation-oxc-fragments.ts"],"sourcesContent":["import type { AstNode, FragmentContext } from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { getStringName } from './component-annotation-oxc-jsx';\n\nexport function collectFragmentContext(ast: AstNode): FragmentContext {\n const context: FragmentContext = {\n fragmentAliases: new Set<string>(),\n reactNamespaceAliases: new Set<string>(['React']),\n };\n\n walkAst(ast, node => {\n collectFragmentAliasesFromImport(node, context);\n collectFragmentAliasesFromVariableDeclarator(node, context);\n });\n\n return context;\n}\n\nfunction collectFragmentAliasesFromImport(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'ImportDeclaration' || !isObjectLike(node.source)) {\n return;\n }\n\n const source = node.source.value;\n if (source !== 'react' && source !== 'React') {\n return;\n }\n\n const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];\n\n for (const specifier of specifiers) {\n if (!isAstNode(specifier) || !isObjectLike(specifier.local)) {\n continue;\n }\n\n const localName = getStringName(specifier.local);\n if (!localName) {\n continue;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportNamespaceSpecifier') {\n context.reactNamespaceAliases.add(localName);\n } else if (isImportedReactFragment(specifier)) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction collectFragmentAliasesFromVariableDeclarator(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'VariableDeclarator' || !isObjectLike(node.id) || !isObjectLike(node.init)) {\n return;\n }\n\n if (node.id.type === 'Identifier') {\n collectFragmentAliasFromIdentifier(node.id, node.init, context);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectFragmentAliasFromObjectPattern(node.id, node.init, context);\n }\n}\n\nfunction collectFragmentAliasFromIdentifier(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n const localName = getStringName(id);\n if (!localName) {\n return;\n }\n\n if (init.type === 'Identifier' && context.fragmentAliases.has(getStringName(init) ?? '')) {\n context.fragmentAliases.add(localName);\n }\n\n if (isReactFragmentMemberExpression(init, context)) {\n context.fragmentAliases.add(localName);\n }\n}\n\nfunction collectFragmentAliasFromObjectPattern(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n if (\n init.type !== 'Identifier' ||\n !context.reactNamespaceAliases.has(getStringName(init) ?? '') ||\n !Array.isArray(id.properties)\n ) {\n return;\n }\n\n for (const property of id.properties) {\n if (!isFragmentObjectPatternProperty(property)) {\n continue;\n }\n\n const localName = getStringName(property.value);\n if (localName) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction isImportedReactFragment(specifier: AstNode): boolean {\n return (\n specifier.type === 'ImportSpecifier' &&\n isObjectLike(specifier.imported) &&\n getStringName(specifier.imported) === 'Fragment'\n );\n}\n\nfunction isReactFragmentMemberExpression(init: Record<string, unknown>, context: FragmentContext): boolean {\n return (\n init.type === 'MemberExpression' &&\n isObjectLike(init.object) &&\n isObjectLike(init.property) &&\n context.reactNamespaceAliases.has(getStringName(init.object) ?? '') &&\n getStringName(init.property) === 'Fragment'\n );\n}\n\nfunction isFragmentObjectPatternProperty(property: unknown): property is { value: unknown } {\n return (\n isObjectLike(property) &&\n (property.type === 'Property' || property.type === 'ObjectProperty') &&\n isObjectLike(property.key) &&\n getStringName(property.key) === 'Fragment' &&\n isObjectLike(property.value)\n );\n}\n"],"mappings":";;;AAIA,SAAgB,uBAAuB,KAA+B;CACpE,MAAM,UAA2B;EAC/B,iCAAiB,IAAI,IAAY;EACjC,uCAAuB,IAAI,IAAY,CAAC,OAAO,CAAC;CAClD;CAEA,QAAQ,MAAK,SAAQ;EACnB,iCAAiC,MAAM,OAAO;EAC9C,6CAA6C,MAAM,OAAO;CAC5D,CAAC;CAED,OAAO;AACT;AAEA,SAAS,iCAAiC,MAAe,SAAgC;CACvF,IAAI,KAAK,SAAS,uBAAuB,CAAC,aAAa,KAAK,MAAM,GAChE;CAGF,MAAM,SAAS,KAAK,OAAO;CAC3B,IAAI,WAAW,WAAW,WAAW,SACnC;CAGF,MAAM,aAAa,MAAM,QAAQ,KAAK,UAAU,IAAI,KAAK,aAAa,CAAC;CAEvE,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,CAAC,UAAU,SAAS,KAAK,CAAC,aAAa,UAAU,KAAK,GACxD;EAGF,MAAM,YAAY,cAAc,UAAU,KAAK;EAC/C,IAAI,CAAC,WACH;EAGF,IAAI,UAAU,SAAS,4BAA4B,UAAU,SAAS,4BACpE,QAAQ,sBAAsB,IAAI,SAAS;OACtC,IAAI,wBAAwB,SAAS,GAC1C,QAAQ,gBAAgB,IAAI,SAAS;CAEzC;AACF;AAEA,SAAS,6CAA6C,MAAe,SAAgC;CACnG,IAAI,KAAK,SAAS,wBAAwB,CAAC,aAAa,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GACzF;CAGF,IAAI,KAAK,GAAG,SAAS,cAAc;EACjC,mCAAmC,KAAK,IAAI,KAAK,MAAM,OAAO;EAC9D;CACF;CAEA,IAAI,KAAK,GAAG,SAAS,iBACnB,sCAAsC,KAAK,IAAI,KAAK,MAAM,OAAO;AAErE;AAEA,SAAS,mCACP,IACA,MACA,SACM;CACN,MAAM,YAAY,cAAc,EAAE;CAClC,IAAI,CAAC,WACH;CAGF,IAAI,KAAK,SAAS,gBAAgB,QAAQ,gBAAgB,IAAI,cAAc,IAAI,KAAK,EAAE,GACrF,QAAQ,gBAAgB,IAAI,SAAS;CAGvC,IAAI,gCAAgC,MAAM,OAAO,GAC/C,QAAQ,gBAAgB,IAAI,SAAS;AAEzC;AAEA,SAAS,sCACP,IACA,MACA,SACM;CACN,IACE,KAAK,SAAS,gBACd,CAAC,QAAQ,sBAAsB,IAAI,cAAc,IAAI,KAAK,EAAE,KAC5D,CAAC,MAAM,QAAQ,GAAG,UAAU,GAE5B;CAGF,KAAK,MAAM,YAAY,GAAG,YAAY;EACpC,IAAI,CAAC,gCAAgC,QAAQ,GAC3C;EAGF,MAAM,YAAY,cAAc,SAAS,KAAK;EAC9C,IAAI,WACF,QAAQ,gBAAgB,IAAI,SAAS;CAEzC;AACF;AAEA,SAAS,wBAAwB,WAA6B;CAC5D,OACE,UAAU,SAAS,qBACnB,aAAa,UAAU,QAAQ,KAC/B,cAAc,UAAU,QAAQ,MAAM;AAE1C;AAEA,SAAS,gCAAgC,MAA+B,SAAmC;CACzG,OACE,KAAK,SAAS,sBACd,aAAa,KAAK,MAAM,KACxB,aAAa,KAAK,QAAQ,KAC1B,QAAQ,sBAAsB,IAAI,cAAc,KAAK,MAAM,KAAK,EAAE,KAClE,cAAc,KAAK,QAAQ,MAAM;AAErC;AAEA,SAAS,gCAAgC,UAAmD;CAC1F,OACE,aAAa,QAAQ,MACpB,SAAS,SAAS,cAAc,SAAS,SAAS,qBACnD,aAAa,SAAS,GAAG,KACzB,cAAc,SAAS,GAAG,MAAM,cAChC,aAAa,SAAS,KAAK;AAE/B"}
|
|
@@ -1,187 +1,148 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isAstNode } from
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME, getComponentAnnotationAttributes } from "../babel-plugin/component-annotation.js";
|
|
2
|
+
import { isAstNode, isObjectLike } from "./component-annotation-oxc-ast.js";
|
|
3
|
+
// src/core/component-annotation-oxc-jsx.ts
|
|
5
4
|
const UNKNOWN_ELEMENT_NAME = "unknown";
|
|
6
5
|
const REACT_NATIVE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
"Image",
|
|
7
|
+
"Text",
|
|
8
|
+
"View",
|
|
9
|
+
"ScrollView",
|
|
10
|
+
"TextInput",
|
|
11
|
+
"TouchableOpacity",
|
|
12
|
+
"TouchableHighlight",
|
|
13
|
+
"TouchableWithoutFeedback",
|
|
14
|
+
"FlatList",
|
|
15
|
+
"SectionList",
|
|
16
|
+
"ActivityIndicator",
|
|
17
|
+
"Button",
|
|
18
|
+
"Switch",
|
|
19
|
+
"Modal",
|
|
20
|
+
"SafeAreaView",
|
|
21
|
+
"StatusBar",
|
|
22
|
+
"KeyboardAvoidingView",
|
|
23
|
+
"RefreshControl",
|
|
24
|
+
"Picker",
|
|
25
|
+
"Slider"
|
|
27
26
|
]);
|
|
28
|
-
const WEB_ATTRIBUTE_NAMES = [
|
|
27
|
+
const WEB_ATTRIBUTE_NAMES = [
|
|
28
|
+
WEB_ELEMENT_NAME,
|
|
29
|
+
WEB_COMPONENT_NAME,
|
|
30
|
+
WEB_SOURCE_FILE_NAME
|
|
31
|
+
];
|
|
29
32
|
const WEB_ATTRIBUTE_NAME_SET = new Set(WEB_ATTRIBUTE_NAMES);
|
|
30
33
|
function isJSXElement(value) {
|
|
31
|
-
|
|
34
|
+
return isAstNode(value) && value.type === "JSXElement";
|
|
32
35
|
}
|
|
33
36
|
function isJSXFragment(value) {
|
|
34
|
-
|
|
37
|
+
return isAstNode(value) && value.type === "JSXFragment";
|
|
35
38
|
}
|
|
36
39
|
function isJSXRoot(value) {
|
|
37
|
-
|
|
40
|
+
return isJSXElement(value) || isJSXFragment(value);
|
|
38
41
|
}
|
|
39
42
|
function getStringName(node) {
|
|
40
|
-
|
|
43
|
+
return isObjectLike(node) && typeof node.name === "string" ? node.name : null;
|
|
41
44
|
}
|
|
42
45
|
function getJSXName(name) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
if (name.type === "JSXNamespacedName") {
|
|
50
|
-
return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;
|
|
51
|
-
}
|
|
52
|
-
if (name.type === "JSXMemberExpression") {
|
|
53
|
-
const objectName = getJSXName(name.object);
|
|
54
|
-
const propertyName = getJSXName(name.property);
|
|
55
|
-
return `${objectName}.${propertyName}`;
|
|
56
|
-
}
|
|
57
|
-
return UNKNOWN_ELEMENT_NAME;
|
|
46
|
+
if (!isAstNode(name)) return UNKNOWN_ELEMENT_NAME;
|
|
47
|
+
if (name.type === "JSXIdentifier") return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;
|
|
48
|
+
if (name.type === "JSXNamespacedName") return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;
|
|
49
|
+
if (name.type === "JSXMemberExpression") return `${getJSXName(name.object)}.${getJSXName(name.property)}`;
|
|
50
|
+
return UNKNOWN_ELEMENT_NAME;
|
|
58
51
|
}
|
|
59
52
|
function getInsertionOffset(code, openingElement) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
let offset = openingElement.end - 2;
|
|
67
|
-
while (offset > 0 && /\s/.test(code[offset] ?? "")) {
|
|
68
|
-
offset -= 1;
|
|
69
|
-
}
|
|
70
|
-
return code[offset] === "/" ? offset : openingElement.end - 1;
|
|
53
|
+
if (typeof openingElement.end !== "number") return null;
|
|
54
|
+
if (!openingElement.selfClosing) return openingElement.end - 1;
|
|
55
|
+
let offset = openingElement.end - 2;
|
|
56
|
+
while (offset > 0 && /\s/.test(code[offset] ?? "")) offset -= 1;
|
|
57
|
+
return code[offset] === "/" ? offset : openingElement.end - 1;
|
|
71
58
|
}
|
|
72
59
|
function isReactFragment(openingElement, fragmentContext) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const objectName = getJSXName(openingElement.name.object);
|
|
82
|
-
const propertyName = getJSXName(openingElement.name.property);
|
|
83
|
-
return propertyName === "Fragment" && (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName));
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
60
|
+
const elementName = getJSXName(openingElement.name);
|
|
61
|
+
if (elementName === "Fragment" || elementName === "React.Fragment") return true;
|
|
62
|
+
if (fragmentContext.fragmentAliases.has(elementName)) return true;
|
|
63
|
+
if (isObjectLike(openingElement.name) && openingElement.name.type === "JSXMemberExpression") {
|
|
64
|
+
const objectName = getJSXName(openingElement.name.object);
|
|
65
|
+
return getJSXName(openingElement.name.property) === "Fragment" && (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName));
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
86
68
|
}
|
|
87
69
|
function addPendingAttributes(code, openingElement, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const insertion = getOrCreateInsertion(insertionsByOffset, offset);
|
|
110
|
-
for (const [name, value] of attributes) {
|
|
111
|
-
insertion.attributeValues.set(name, value);
|
|
112
|
-
}
|
|
70
|
+
const offset = getInsertionOffset(code, openingElement);
|
|
71
|
+
if (offset === null) return;
|
|
72
|
+
const pendingInsertion = insertionsByOffset.get(offset);
|
|
73
|
+
const existingAttributes = getExistingAttributeNames(openingElement);
|
|
74
|
+
for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) existingAttributes.add(attributeName);
|
|
75
|
+
const attributes = getComponentAnnotationAttributes({
|
|
76
|
+
attributeNames: [
|
|
77
|
+
WEB_COMPONENT_NAME,
|
|
78
|
+
WEB_ELEMENT_NAME,
|
|
79
|
+
WEB_SOURCE_FILE_NAME
|
|
80
|
+
],
|
|
81
|
+
componentName,
|
|
82
|
+
elementName: getJSXName(openingElement.name),
|
|
83
|
+
existingAttributes,
|
|
84
|
+
ignoredComponents,
|
|
85
|
+
isFragment: isReactFragment(openingElement, fragmentContext),
|
|
86
|
+
sourceFileName
|
|
87
|
+
});
|
|
88
|
+
if (attributes.length === 0) return;
|
|
89
|
+
const insertion = getOrCreateInsertion(insertionsByOffset, offset);
|
|
90
|
+
for (const [name, value] of attributes) insertion.attributeValues.set(name, value);
|
|
113
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns `true` when the element is an HTML element, because HTML mode only
|
|
94
|
+
* annotates the first HTML elements below a component root.
|
|
95
|
+
*/
|
|
114
96
|
function addPendingHtmlAttribute(code, openingElement, componentName, ignoredComponents, fragmentContext, insertionsByOffset) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
const offset = getInsertionOffset(code, openingElement);
|
|
126
|
-
if (offset === null) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
if (getExistingAttributeNames(openingElement).has(WEB_COMPONENT_NAME) || insertionsByOffset.get(offset)?.attributeValues.has(WEB_COMPONENT_NAME)) {
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(WEB_COMPONENT_NAME, componentName);
|
|
133
|
-
return true;
|
|
97
|
+
if (isReactFragment(openingElement, fragmentContext)) return false;
|
|
98
|
+
const elementName = getJSXName(openingElement.name);
|
|
99
|
+
if (!isHtmlElement(elementName)) return false;
|
|
100
|
+
if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) return true;
|
|
101
|
+
const offset = getInsertionOffset(code, openingElement);
|
|
102
|
+
if (offset === null) return true;
|
|
103
|
+
if (getExistingAttributeNames(openingElement).has("data-sentry-component") || insertionsByOffset.get(offset)?.attributeValues.has("data-sentry-component")) return true;
|
|
104
|
+
getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(WEB_COMPONENT_NAME, componentName);
|
|
105
|
+
return true;
|
|
134
106
|
}
|
|
135
107
|
function isHtmlElement(elementName) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
return REACT_NATIVE_ELEMENTS.has(elementName);
|
|
108
|
+
if (elementName === UNKNOWN_ELEMENT_NAME) return false;
|
|
109
|
+
if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) return true;
|
|
110
|
+
return REACT_NATIVE_ELEMENTS.has(elementName);
|
|
143
111
|
}
|
|
144
112
|
function getOrCreateInsertion(insertionsByOffset, offset) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
113
|
+
let insertion = insertionsByOffset.get(offset);
|
|
114
|
+
if (!insertion) {
|
|
115
|
+
insertion = {
|
|
116
|
+
offset,
|
|
117
|
+
attributeValues: /* @__PURE__ */ new Map()
|
|
118
|
+
};
|
|
119
|
+
insertionsByOffset.set(offset, insertion);
|
|
120
|
+
}
|
|
121
|
+
return insertion;
|
|
151
122
|
}
|
|
152
123
|
function toAttributeInsertions(insertionsByOffset) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
124
|
+
return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({
|
|
125
|
+
offset,
|
|
126
|
+
attributes: getOrderedAttributes(attributeValues)
|
|
127
|
+
}));
|
|
157
128
|
}
|
|
158
129
|
function getExistingAttributeNames(openingElement) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return names;
|
|
130
|
+
const names = /* @__PURE__ */ new Set();
|
|
131
|
+
for (const attribute of openingElement.attributes ?? []) if (attribute.type === "JSXAttribute") {
|
|
132
|
+
const name = getStringName(attribute.name);
|
|
133
|
+
if (name) names.add(name);
|
|
134
|
+
}
|
|
135
|
+
return names;
|
|
169
136
|
}
|
|
170
137
|
function getOrderedAttributes(attributeValues) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
for (const [name, value] of attributeValues) {
|
|
179
|
-
if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {
|
|
180
|
-
attributes.push([name, value]);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return attributes;
|
|
138
|
+
const attributes = [];
|
|
139
|
+
for (const name of WEB_ATTRIBUTE_NAMES) {
|
|
140
|
+
const value = attributeValues.get(name);
|
|
141
|
+
if (value !== void 0) attributes.push([name, value]);
|
|
142
|
+
}
|
|
143
|
+
for (const [name, value] of attributeValues) if (!WEB_ATTRIBUTE_NAME_SET.has(name)) attributes.push([name, value]);
|
|
144
|
+
return attributes;
|
|
184
145
|
}
|
|
185
|
-
|
|
186
146
|
export { addPendingAttributes, addPendingHtmlAttribute, getInsertionOffset, getJSXName, getStringName, isJSXElement, isJSXFragment, isJSXRoot, isReactFragment, toAttributeInsertions };
|
|
187
|
-
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=component-annotation-oxc-jsx.js.map
|