@sentry/bundler-plugins 11.0.0-rc.0 → 11.0.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.
Files changed (99) hide show
  1. package/build/cjs/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
  2. package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -0
  3. package/build/cjs/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +13 -13
  4. package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -0
  5. package/build/cjs/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +5 -5
  6. package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -0
  7. package/build/cjs/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +24 -24
  8. package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -0
  9. package/build/cjs/core/{component-annotation-vite.js → component-annotation-oxc.js} +27 -11
  10. package/build/cjs/core/component-annotation-oxc.js.map +1 -0
  11. package/build/cjs/core/get-code-injection-position.js +87 -0
  12. package/build/cjs/core/get-code-injection-position.js.map +1 -0
  13. package/build/cjs/core/index.js +2 -5
  14. package/build/cjs/core/index.js.map +1 -1
  15. package/build/cjs/core/sentry/telemetry.js +4 -1
  16. package/build/cjs/core/sentry/telemetry.js.map +1 -1
  17. package/build/cjs/core/version.js +1 -1
  18. package/build/cjs/core/version.js.map +1 -1
  19. package/build/cjs/esbuild/index.js.map +1 -1
  20. package/build/cjs/rollup/index.js +15 -15
  21. package/build/cjs/rollup/index.js.map +1 -1
  22. package/build/cjs/webpack/index.js +228 -11
  23. package/build/cjs/webpack/index.js.map +1 -1
  24. package/build/esm/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
  25. package/build/esm/core/component-annotation-oxc-ast.js.map +1 -0
  26. package/build/esm/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +3 -3
  27. package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -0
  28. package/build/esm/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +2 -2
  29. package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -0
  30. package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +6 -6
  31. package/build/esm/core/component-annotation-oxc-walk.js.map +1 -0
  32. package/build/esm/core/{component-annotation-vite.js → component-annotation-oxc.js} +25 -10
  33. package/build/esm/core/component-annotation-oxc.js.map +1 -0
  34. package/build/esm/core/get-code-injection-position.js +85 -0
  35. package/build/esm/core/get-code-injection-position.js.map +1 -0
  36. package/build/esm/core/index.js +2 -5
  37. package/build/esm/core/index.js.map +1 -1
  38. package/build/esm/core/sentry/telemetry.js +4 -1
  39. package/build/esm/core/sentry/telemetry.js.map +1 -1
  40. package/build/esm/core/version.js +1 -1
  41. package/build/esm/core/version.js.map +1 -1
  42. package/build/esm/esbuild/index.js.map +1 -1
  43. package/build/esm/package.json +1 -1
  44. package/build/esm/rollup/index.js +16 -16
  45. package/build/esm/rollup/index.js.map +1 -1
  46. package/build/esm/webpack/index.js +214 -11
  47. package/build/esm/webpack/index.js.map +1 -1
  48. package/build/types/core/{component-annotation-vite-ast.d.ts → component-annotation-oxc-ast.d.ts} +1 -1
  49. package/build/types/core/component-annotation-oxc-ast.d.ts.map +1 -0
  50. package/build/types/core/{component-annotation-vite-fragments.d.ts → component-annotation-oxc-fragments.d.ts} +2 -2
  51. package/build/types/core/component-annotation-oxc-fragments.d.ts.map +1 -0
  52. package/build/types/core/{component-annotation-vite-jsx.d.ts → component-annotation-oxc-jsx.d.ts} +2 -2
  53. package/build/types/core/component-annotation-oxc-jsx.d.ts.map +1 -0
  54. package/build/types/core/component-annotation-oxc-walk.d.ts +3 -0
  55. package/build/types/core/component-annotation-oxc-walk.d.ts.map +1 -0
  56. package/build/types/core/component-annotation-oxc.d.ts +7 -0
  57. package/build/types/core/component-annotation-oxc.d.ts.map +1 -0
  58. package/build/types/core/get-code-injection-position.d.ts +2 -0
  59. package/build/types/core/get-code-injection-position.d.ts.map +1 -0
  60. package/build/types/core/index.d.ts +1 -1
  61. package/build/types/core/index.d.ts.map +1 -1
  62. package/build/types/core/sentry/telemetry.d.ts.map +1 -1
  63. package/build/types/core/version.d.ts +1 -1
  64. package/build/types/core/version.d.ts.map +1 -1
  65. package/build/types/esbuild/index.d.ts.map +1 -1
  66. package/build/types/rollup/index.d.ts +1 -1
  67. package/build/types/rollup/index.d.ts.map +1 -1
  68. package/build/types/webpack/index.d.ts +14 -2
  69. package/build/types/webpack/index.d.ts.map +1 -1
  70. package/package.json +4 -9
  71. package/build/cjs/core/component-annotation-vite-ast.js.map +0 -1
  72. package/build/cjs/core/component-annotation-vite-fragments.js.map +0 -1
  73. package/build/cjs/core/component-annotation-vite-jsx.js.map +0 -1
  74. package/build/cjs/core/component-annotation-vite-walk.js.map +0 -1
  75. package/build/cjs/core/component-annotation-vite.js.map +0 -1
  76. package/build/cjs/webpack/webpack4and5.js +0 -219
  77. package/build/cjs/webpack/webpack4and5.js.map +0 -1
  78. package/build/cjs/webpack/webpack5.js +0 -9
  79. package/build/cjs/webpack/webpack5.js.map +0 -1
  80. package/build/esm/core/component-annotation-vite-ast.js.map +0 -1
  81. package/build/esm/core/component-annotation-vite-fragments.js.map +0 -1
  82. package/build/esm/core/component-annotation-vite-jsx.js.map +0 -1
  83. package/build/esm/core/component-annotation-vite-walk.js.map +0 -1
  84. package/build/esm/core/component-annotation-vite.js.map +0 -1
  85. package/build/esm/webpack/webpack4and5.js +0 -202
  86. package/build/esm/webpack/webpack4and5.js.map +0 -1
  87. package/build/esm/webpack/webpack5.js +0 -7
  88. package/build/esm/webpack/webpack5.js.map +0 -1
  89. package/build/types/core/component-annotation-vite-ast.d.ts.map +0 -1
  90. package/build/types/core/component-annotation-vite-fragments.d.ts.map +0 -1
  91. package/build/types/core/component-annotation-vite-jsx.d.ts.map +0 -1
  92. package/build/types/core/component-annotation-vite-walk.d.ts +0 -3
  93. package/build/types/core/component-annotation-vite-walk.d.ts.map +0 -1
  94. package/build/types/core/component-annotation-vite.d.ts +0 -6
  95. package/build/types/core/component-annotation-vite.d.ts.map +0 -1
  96. package/build/types/webpack/webpack4and5.d.ts +0 -98
  97. package/build/types/webpack/webpack4and5.d.ts.map +0 -1
  98. package/build/types/webpack/webpack5.d.ts +0 -4
  99. package/build/types/webpack/webpack5.d.ts.map +0 -1
@@ -24,4 +24,4 @@ function walkAst(node, visit) {
24
24
  exports.isObjectLike = core.isObjectLike;
25
25
  exports.isAstNode = isAstNode;
26
26
  exports.walkAst = walkAst;
27
- //# sourceMappingURL=component-annotation-vite-ast.js.map
27
+ //# sourceMappingURL=component-annotation-oxc-ast.js.map
@@ -0,0 +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 | {\n code: string;\n map?: SourceMap | string;\n }\n | null\n | undefined;\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"],"names":["isObjectLike"],"mappings":";;;;AAqEO,SAAS,UAAU,KAAA,EAAkC;AAC1D,EAAA,OAAOA,iBAAA,CAAa,KAAK,CAAA,IAAK,OAAO,MAAM,IAAA,KAAS,QAAA;AACtD;AAEO,SAAS,OAAA,CAAQ,MAAe,KAAA,EAAsC;AAC3E,EAAA,IAAI,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AAEA,EAAA,KAAA,CAAM,IAAI,CAAA;AAEV,EAAA,KAAA,MAAW,KAAA,IAAS,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,EAAG;AACvC,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,KAAA,MAAW,SAAS,KAAA,EAAO;AACzB,QAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,MACtB;AAAA,IACF,CAAA,MAAA,IAAW,SAAA,CAAU,KAAK,CAAA,EAAG;AAC3B,MAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,IACtB;AAAA,EACF;AACF;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
4
- const componentAnnotationViteJsx = require('./component-annotation-vite-jsx.js');
3
+ const componentAnnotationOxcAst = require('./component-annotation-oxc-ast.js');
4
+ const componentAnnotationOxcJsx = require('./component-annotation-oxc-jsx.js');
5
5
  const core = require('@sentry/core');
6
6
 
7
7
  function collectFragmentContext(ast) {
@@ -9,7 +9,7 @@ function collectFragmentContext(ast) {
9
9
  fragmentAliases: /* @__PURE__ */ new Set(),
10
10
  reactNamespaceAliases: /* @__PURE__ */ new Set(["React"])
11
11
  };
12
- componentAnnotationViteAst.walkAst(ast, (node) => {
12
+ componentAnnotationOxcAst.walkAst(ast, (node) => {
13
13
  collectFragmentAliasesFromImport(node, context);
14
14
  collectFragmentAliasesFromVariableDeclarator(node, context);
15
15
  });
@@ -25,10 +25,10 @@ function collectFragmentAliasesFromImport(node, context) {
25
25
  }
26
26
  const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];
27
27
  for (const specifier of specifiers) {
28
- if (!componentAnnotationViteAst.isAstNode(specifier) || !core.isObjectLike(specifier.local)) {
28
+ if (!componentAnnotationOxcAst.isAstNode(specifier) || !core.isObjectLike(specifier.local)) {
29
29
  continue;
30
30
  }
31
- const localName = componentAnnotationViteJsx.getStringName(specifier.local);
31
+ const localName = componentAnnotationOxcJsx.getStringName(specifier.local);
32
32
  if (!localName) {
33
33
  continue;
34
34
  }
@@ -52,11 +52,11 @@ function collectFragmentAliasesFromVariableDeclarator(node, context) {
52
52
  }
53
53
  }
54
54
  function collectFragmentAliasFromIdentifier(id, init, context) {
55
- const localName = componentAnnotationViteJsx.getStringName(id);
55
+ const localName = componentAnnotationOxcJsx.getStringName(id);
56
56
  if (!localName) {
57
57
  return;
58
58
  }
59
- if (init.type === "Identifier" && context.fragmentAliases.has(componentAnnotationViteJsx.getStringName(init) ?? "")) {
59
+ if (init.type === "Identifier" && context.fragmentAliases.has(componentAnnotationOxcJsx.getStringName(init) ?? "")) {
60
60
  context.fragmentAliases.add(localName);
61
61
  }
62
62
  if (isReactFragmentMemberExpression(init, context)) {
@@ -64,28 +64,28 @@ function collectFragmentAliasFromIdentifier(id, init, context) {
64
64
  }
65
65
  }
66
66
  function collectFragmentAliasFromObjectPattern(id, init, context) {
67
- if (init.type !== "Identifier" || !context.reactNamespaceAliases.has(componentAnnotationViteJsx.getStringName(init) ?? "") || !Array.isArray(id.properties)) {
67
+ if (init.type !== "Identifier" || !context.reactNamespaceAliases.has(componentAnnotationOxcJsx.getStringName(init) ?? "") || !Array.isArray(id.properties)) {
68
68
  return;
69
69
  }
70
70
  for (const property of id.properties) {
71
71
  if (!isFragmentObjectPatternProperty(property)) {
72
72
  continue;
73
73
  }
74
- const localName = componentAnnotationViteJsx.getStringName(property.value);
74
+ const localName = componentAnnotationOxcJsx.getStringName(property.value);
75
75
  if (localName) {
76
76
  context.fragmentAliases.add(localName);
77
77
  }
78
78
  }
79
79
  }
80
80
  function isImportedReactFragment(specifier) {
81
- return specifier.type === "ImportSpecifier" && core.isObjectLike(specifier.imported) && componentAnnotationViteJsx.getStringName(specifier.imported) === "Fragment";
81
+ return specifier.type === "ImportSpecifier" && core.isObjectLike(specifier.imported) && componentAnnotationOxcJsx.getStringName(specifier.imported) === "Fragment";
82
82
  }
83
83
  function isReactFragmentMemberExpression(init, context) {
84
- return init.type === "MemberExpression" && core.isObjectLike(init.object) && core.isObjectLike(init.property) && context.reactNamespaceAliases.has(componentAnnotationViteJsx.getStringName(init.object) ?? "") && componentAnnotationViteJsx.getStringName(init.property) === "Fragment";
84
+ return init.type === "MemberExpression" && core.isObjectLike(init.object) && core.isObjectLike(init.property) && context.reactNamespaceAliases.has(componentAnnotationOxcJsx.getStringName(init.object) ?? "") && componentAnnotationOxcJsx.getStringName(init.property) === "Fragment";
85
85
  }
86
86
  function isFragmentObjectPatternProperty(property) {
87
- return core.isObjectLike(property) && (property.type === "Property" || property.type === "ObjectProperty") && core.isObjectLike(property.key) && componentAnnotationViteJsx.getStringName(property.key) === "Fragment" && core.isObjectLike(property.value);
87
+ return core.isObjectLike(property) && (property.type === "Property" || property.type === "ObjectProperty") && core.isObjectLike(property.key) && componentAnnotationOxcJsx.getStringName(property.key) === "Fragment" && core.isObjectLike(property.value);
88
88
  }
89
89
 
90
90
  exports.collectFragmentContext = collectFragmentContext;
91
- //# sourceMappingURL=component-annotation-vite-fragments.js.map
91
+ //# sourceMappingURL=component-annotation-oxc-fragments.js.map
@@ -0,0 +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"],"names":["walkAst","isObjectLike","isAstNode","getStringName"],"mappings":";;;;;;AAIO,SAAS,uBAAuB,GAAA,EAA+B;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nDA,iBAAA,CAAa,SAAS,GAAG,CAAA,IACzBE,wCAAc,QAAA,CAAS,GAAG,MAAM,UAAA,IAChCF,iBAAA,CAAa,SAAS,KAAK,CAAA;AAE/B;;;;"}
@@ -1,17 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const componentAnnotation = require('../babel-plugin/component-annotation.js');
4
- const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
4
+ const componentAnnotationOxcAst = require('./component-annotation-oxc-ast.js');
5
5
  const core = require('@sentry/core');
6
6
 
7
7
  const UNKNOWN_ELEMENT_NAME = "unknown";
8
8
  const WEB_ATTRIBUTE_NAMES = [componentAnnotation.WEB_ELEMENT_NAME, componentAnnotation.WEB_COMPONENT_NAME, componentAnnotation.WEB_SOURCE_FILE_NAME];
9
9
  const WEB_ATTRIBUTE_NAME_SET = new Set(WEB_ATTRIBUTE_NAMES);
10
10
  function isJSXElement(value) {
11
- return componentAnnotationViteAst.isAstNode(value) && value.type === "JSXElement";
11
+ return componentAnnotationOxcAst.isAstNode(value) && value.type === "JSXElement";
12
12
  }
13
13
  function isJSXFragment(value) {
14
- return componentAnnotationViteAst.isAstNode(value) && value.type === "JSXFragment";
14
+ return componentAnnotationOxcAst.isAstNode(value) && value.type === "JSXFragment";
15
15
  }
16
16
  function isJSXRoot(value) {
17
17
  return isJSXElement(value) || isJSXFragment(value);
@@ -20,7 +20,7 @@ function getStringName(node) {
20
20
  return core.isObjectLike(node) && typeof node.name === "string" ? node.name : null;
21
21
  }
22
22
  function getJSXName(name) {
23
- if (!componentAnnotationViteAst.isAstNode(name)) {
23
+ if (!componentAnnotationOxcAst.isAstNode(name)) {
24
24
  return UNKNOWN_ELEMENT_NAME;
25
25
  }
26
26
  if (name.type === "JSXIdentifier") {
@@ -137,4 +137,4 @@ exports.isJSXFragment = isJSXFragment;
137
137
  exports.isJSXRoot = isJSXRoot;
138
138
  exports.isReactFragment = isReactFragment;
139
139
  exports.toAttributeInsertions = toAttributeInsertions;
140
- //# sourceMappingURL=component-annotation-vite-jsx.js.map
140
+ //# sourceMappingURL=component-annotation-oxc-jsx.js.map
@@ -0,0 +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 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 =\n pendingInsertion ??\n insertionsByOffset\n .set(offset, {\n offset,\n attributeValues: new Map(),\n })\n .get(offset);\n\n for (const [name, value] of attributes) {\n insertion?.attributeValues.set(name, value);\n }\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 if (value) {\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,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,IAAK,KAAA,CAAM,IAAA,KAAS,YAAA;AAC5C;AAEO,SAAS,cAAc,KAAA,EA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AA,EAAQ,eAAA,EAAgB,MAAO;AAAA,IAC5E,MAAA;AAAA,IACA,UAAA,EAAY,qBAAqB,eAAe;AAAA,GAClD,CAAE,CAAA;AACJ;AAEA,SAAS,0BAA0B,cAAA,EAAoD;AACrF,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAE9B,EAAA,KAAA,MAAW,SAAA,IAAa,cAAA,CAAe,UAAA,IAAc,EAAC,EAAG;AACvD,IAAA,IAAI,SAAA,CAAU,SAAS,cAAA,EAAgB;AACrC,MAAA,MAAM,IAAA,GAAO,aAAA,CAAc,SAAA,CAAU,IAAI,CAAA;AACzC,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,qBAAqB,eAAA,EAA8E;AAC1G,EAAA,MAAM,aAA6C,EAAC;AAEpD,EAAA,KAAA,MAAW,QAAQ,mBAAA,EAAqB;AACtC,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,eAAA,EAAiB;AAC3C,IAAA,IAAI,CAAC,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,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const componentAnnotationViteJsx = require('./component-annotation-vite-jsx.js');
4
- const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
5
- const componentAnnotationViteFragments = require('./component-annotation-vite-fragments.js');
3
+ const componentAnnotationOxcJsx = require('./component-annotation-oxc-jsx.js');
4
+ const componentAnnotationOxcAst = require('./component-annotation-oxc-ast.js');
5
+ const componentAnnotationOxcFragments = require('./component-annotation-oxc-fragments.js');
6
6
  const core = require('@sentry/core');
7
7
 
8
- function collectViteComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
9
- const fragmentContext = componentAnnotationViteFragments.collectFragmentContext(ast);
8
+ function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
9
+ const fragmentContext = componentAnnotationOxcFragments.collectFragmentContext(ast);
10
10
  const components = collectComponentJSXRoots(ast);
11
11
  const insertionsByOffset = /* @__PURE__ */ new Map();
12
12
  for (const component of components) {
@@ -14,20 +14,20 @@ function collectViteComponentAnnotationInsertions(code, ast, ignoredComponents,
14
14
  processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
15
15
  }
16
16
  }
17
- return componentAnnotationViteJsx.toAttributeInsertions(insertionsByOffset);
17
+ return componentAnnotationOxcJsx.toAttributeInsertions(insertionsByOffset);
18
18
  }
19
19
  function getJSXRootsFromReturnArgument(argument) {
20
- if (componentAnnotationViteJsx.isJSXRoot(argument)) {
20
+ if (componentAnnotationOxcJsx.isJSXRoot(argument)) {
21
21
  return [argument];
22
22
  }
23
23
  if (core.isObjectLike(argument) && argument.type === "ConditionalExpression") {
24
- return [argument.consequent, argument.alternate].filter(componentAnnotationViteJsx.isJSXRoot);
24
+ return [argument.consequent, argument.alternate].filter(componentAnnotationOxcJsx.isJSXRoot);
25
25
  }
26
26
  return [];
27
27
  }
28
28
  function getReturnedJSXFromFunction(functionNode) {
29
29
  const body = functionNode.body;
30
- if (componentAnnotationViteJsx.isJSXRoot(body)) {
30
+ if (componentAnnotationOxcJsx.isJSXRoot(body)) {
31
31
  return [body];
32
32
  }
33
33
  if (!core.isObjectLike(body) || body.type !== "BlockStatement") {
@@ -35,12 +35,12 @@ function getReturnedJSXFromFunction(functionNode) {
35
35
  }
36
36
  const bodyStatements = Array.isArray(body.body) ? body.body : [];
37
37
  const returnStatement = bodyStatements.find((statement) => {
38
- return componentAnnotationViteAst.isAstNode(statement) && statement.type === "ReturnStatement";
38
+ return componentAnnotationOxcAst.isAstNode(statement) && statement.type === "ReturnStatement";
39
39
  });
40
40
  return core.isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];
41
41
  }
42
42
  function pushFunctionComponent(components, nameNode, functionNode) {
43
- const name = componentAnnotationViteJsx.getStringName(nameNode);
43
+ const name = componentAnnotationOxcJsx.getStringName(nameNode);
44
44
  if (name) {
45
45
  components.push({
46
46
  name,
@@ -50,13 +50,13 @@ function pushFunctionComponent(components, nameNode, functionNode) {
50
50
  }
51
51
  function collectComponentJSXRoots(ast) {
52
52
  const components = [];
53
- componentAnnotationViteAst.walkAst(ast, (node) => {
53
+ componentAnnotationOxcAst.walkAst(ast, (node) => {
54
54
  if (node.type === "FunctionDeclaration" && core.isObjectLike(node.id)) {
55
55
  pushFunctionComponent(components, node.id, node);
56
56
  return;
57
57
  }
58
58
  if (node.type === "VariableDeclarator" && core.isObjectLike(node.id)) {
59
- if (componentAnnotationViteAst.isAstNode(node.init) && node.init.type === "ArrowFunctionExpression") {
59
+ if (componentAnnotationOxcAst.isAstNode(node.init) && node.init.type === "ArrowFunctionExpression") {
60
60
  pushFunctionComponent(components, node.id, node.init);
61
61
  }
62
62
  return;
@@ -73,13 +73,13 @@ function pushClassComponent(components, node) {
73
73
  return;
74
74
  }
75
75
  const roots = [];
76
- componentAnnotationViteAst.walkAst(renderMethodBody, (child) => {
77
- if (child.type === "ReturnStatement" && componentAnnotationViteJsx.isJSXRoot(child.argument)) {
76
+ componentAnnotationOxcAst.walkAst(renderMethodBody, (child) => {
77
+ if (child.type === "ReturnStatement" && componentAnnotationOxcJsx.isJSXRoot(child.argument)) {
78
78
  roots.push(child.argument);
79
79
  }
80
80
  });
81
81
  components.push({
82
- name: componentAnnotationViteJsx.getStringName(node.id) ?? "",
82
+ name: componentAnnotationOxcJsx.getStringName(node.id) ?? "",
83
83
  roots
84
84
  });
85
85
  }
@@ -88,19 +88,19 @@ function getClassRenderMethodBody(node) {
88
88
  return null;
89
89
  }
90
90
  const renderMethod = node.body.body.find((member) => {
91
- return core.isObjectLike(member) && core.isObjectLike(member.key) && componentAnnotationViteJsx.getStringName(member.key) === "render" && (core.isObjectLike(member.value) || core.isObjectLike(member.body));
91
+ return core.isObjectLike(member) && core.isObjectLike(member.key) && componentAnnotationOxcJsx.getStringName(member.key) === "render" && (core.isObjectLike(member.value) || core.isObjectLike(member.body));
92
92
  });
93
93
  if (!core.isObjectLike(renderMethod)) {
94
94
  return null;
95
95
  }
96
- if (componentAnnotationViteAst.isAstNode(renderMethod.value)) {
96
+ if (componentAnnotationOxcAst.isAstNode(renderMethod.value)) {
97
97
  return renderMethod.value;
98
98
  }
99
- return componentAnnotationViteAst.isAstNode(renderMethod) ? renderMethod : null;
99
+ return componentAnnotationOxcAst.isAstNode(renderMethod) ? renderMethod : null;
100
100
  }
101
101
  function processJSX(code, node, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
102
- if (componentAnnotationViteJsx.isJSXElement(node)) {
103
- componentAnnotationViteJsx.addPendingAttributes(
102
+ if (componentAnnotationOxcJsx.isJSXElement(node)) {
103
+ componentAnnotationOxcJsx.addPendingAttributes(
104
104
  code,
105
105
  node.openingElement,
106
106
  componentName,
@@ -111,11 +111,11 @@ function processJSX(code, node, componentName, ignoredComponents, fragmentContex
111
111
  );
112
112
  }
113
113
  for (const child of node.children ?? []) {
114
- if (componentAnnotationViteJsx.isJSXRoot(child)) {
114
+ if (componentAnnotationOxcJsx.isJSXRoot(child)) {
115
115
  processJSX(code, child, "", ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
116
116
  }
117
117
  }
118
118
  }
119
119
 
120
- exports.collectViteComponentAnnotationInsertions = collectViteComponentAnnotationInsertions;
121
- //# sourceMappingURL=component-annotation-vite-walk.js.map
120
+ exports.collectOxcComponentAnnotationInsertions = collectOxcComponentAnnotationInsertions;
121
+ //# sourceMappingURL=component-annotation-oxc-walk.js.map
@@ -0,0 +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 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): 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 processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\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","isJSXRoot","isObjectLike","isAstNode","getStringName","walkAst","isJSXElement","addPendingAttributes"],"mappings":";;;;;;;AAaO,SAAS,uCAAA,CACd,IAAA,EACA,GAAA,EACA,iBAAA,EACA,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,UAAA,CAAW,MAAM,IAAA,EAAM,SAAA,CAAU,MAAM,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IAC/G;AAAA,EACF;AAEA,EAAA,OAAOC,gDAAsB,kBAAkB,CAAA;AACjD;AAEA,SAAS,8BAA8B,QAAA,EAAkC;AACvE,EAAA,IAAIC,mCAAA,CAAU,QAAQ,CAAA,EAAG;AACvB,IAAA,OAAO,CAAC,QAAQ,CAAA;AAAA,EAClB;AAEA,EAAA,IAAIC,iBAAA,CAAa,QAAQ,CAAA,IAAK,QAAA,CAAS,SAAS,uBAAA,EAAyB;AACvE,IAAA,OAAO,CAAC,QAAA,CAAS,UAAA,EAAY,SAAS,SAAS,CAAA,CAAE,OAAOD,mCAAS,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A;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
@@ -4,17 +4,32 @@ const path = require('node:path');
4
4
  const MagicString = require('magic-string');
5
5
  const constants = require('../babel-plugin/constants.js');
6
6
  const utils = require('./utils.js');
7
- const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
8
- const componentAnnotationViteWalk = require('./component-annotation-vite-walk.js');
7
+ const componentAnnotationOxcAst = require('./component-annotation-oxc-ast.js');
8
+ const componentAnnotationOxcWalk = require('./component-annotation-oxc-walk.js');
9
9
 
10
10
  const _interopDefault = e => e && e.__esModule ? e.default : e;
11
11
 
12
12
  const path__default = /*#__PURE__*/_interopDefault(path);
13
13
  const MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
14
14
 
15
+ let oxcParseAstAsyncPromise;
16
+ function getOxcParseAstAsync() {
17
+ if (!oxcParseAstAsyncPromise) {
18
+ oxcParseAstAsyncPromise = import('oxc-parser').then(({ parse }) => {
19
+ return async (code, { lang }) => {
20
+ const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });
21
+ if (errors.length > 0) {
22
+ throw new Error(errors[0]?.message);
23
+ }
24
+ return program;
25
+ };
26
+ }).catch(() => null);
27
+ }
28
+ return oxcParseAstAsyncPromise;
29
+ }
15
30
  const JSX_TAG_START_REGEXP = /<[$_\p{ID_Start}][$_\u200c\u200d\p{ID_Continue}.:-]*|<>/u;
16
31
  const JSX_FILE_REGEXP = /\.[jt]sx$/;
17
- function isViteAnnotationFile(idWithoutQueryAndHash) {
32
+ function isAnnotationFile(idWithoutQueryAndHash) {
18
33
  if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
19
34
  return false;
20
35
  }
@@ -44,18 +59,18 @@ function getMagicString(code, meta) {
44
59
  }
45
60
  return { magicString: new MagicString__default(code), isNative: false };
46
61
  }
47
- async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync, meta) {
62
+ async function annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta) {
48
63
  const idWithoutQueryAndHash = utils.stripQueryAndHashFromPath(id);
49
- if (!idWithoutQueryAndHash || !isViteAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
64
+ if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
50
65
  return null;
51
66
  }
52
67
  const ast = await parseAstAsync(code, {
53
68
  lang: idWithoutQueryAndHash.endsWith(".jsx") ? "jsx" : "tsx"
54
69
  });
55
- if (!componentAnnotationViteAst.isAstNode(ast)) {
70
+ if (!componentAnnotationOxcAst.isAstNode(ast)) {
56
71
  return void 0;
57
72
  }
58
- const insertions = componentAnnotationViteWalk.collectViteComponentAnnotationInsertions(
73
+ const insertions = componentAnnotationOxcWalk.collectOxcComponentAnnotationInsertions(
59
74
  code,
60
75
  ast,
61
76
  ignoredComponents,
@@ -81,7 +96,7 @@ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync
81
96
  })
82
97
  };
83
98
  }
84
- function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
99
+ function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
85
100
  return {
86
101
  async transform(code, id, meta) {
87
102
  try {
@@ -89,7 +104,7 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
89
104
  if (!parseAstAsync) {
90
105
  return void 0;
91
106
  }
92
- return await annotateWithViteParser(code, id, ignoredComponents, parseAstAsync, meta);
107
+ return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);
93
108
  } catch {
94
109
  return void 0;
95
110
  }
@@ -97,5 +112,6 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
97
112
  };
98
113
  }
99
114
 
100
- exports.createViteComponentNameAnnotateHooks = createViteComponentNameAnnotateHooks;
101
- //# sourceMappingURL=component-annotation-vite.js.map
115
+ exports.createOxcComponentNameAnnotateHooks = createOxcComponentNameAnnotateHooks;
116
+ exports.getOxcParseAstAsync = getOxcParseAstAsync;
117
+ //# sourceMappingURL=component-annotation-oxc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-annotation-oxc.js","sources":["../../../src/core/component-annotation-oxc.ts"],"sourcesContent":["import path from 'node:path';\n\nimport MagicString from 'magic-string';\n\nimport { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants';\nimport { stripQueryAndHashFromPath } from './utils';\nimport { isAstNode } from './component-annotation-oxc-ast';\nimport { collectOxcComponentAnnotationInsertions } from './component-annotation-oxc-walk';\nimport type {\n AttributeInsertion,\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n MagicStringLike,\n ParseAstAsync,\n} from './component-annotation-oxc-ast';\n\nexport type {\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n} from './component-annotation-oxc-ast';\n\nlet oxcParseAstAsyncPromise: Promise<ParseAstAsync | null> | undefined;\n\nexport function getOxcParseAstAsync(): Promise<ParseAstAsync | null> {\n if (!oxcParseAstAsyncPromise) {\n oxcParseAstAsyncPromise = import('oxc-parser')\n .then(({ parse }): ParseAstAsync => {\n return async (code, { lang }) => {\n // preserveParens: false matches the AST Vite 8 produces. The walker\n // does not look through ParenthesizedExpression nodes.\n const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });\n\n if (errors.length > 0) {\n throw new Error(errors[0]?.message);\n }\n\n return program;\n };\n })\n .catch(() => null);\n }\n\n return oxcParseAstAsyncPromise;\n}\n\n// Keep this as a superset of JSX tag starts Babel can annotate, because a miss suppresses Babel fallback.\nconst JSX_TAG_START_REGEXP = /<[$_\\p{ID_Start}][$_\\u200c\\u200d\\p{ID_Continue}.:-]*|<>/u;\nconst JSX_FILE_REGEXP = /\\.[jt]sx$/;\n\nfunction isAnnotationFile(idWithoutQueryAndHash: string): boolean {\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return false;\n }\n\n return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);\n}\n\nfunction shouldTryParse(code: string): boolean {\n return JSX_TAG_START_REGEXP.test(code);\n}\n\nfunction shouldSkipIncompatibleFile(idWithoutQueryAndHash: string): boolean {\n return KNOWN_INCOMPATIBLE_PLUGINS.some(pluginName => {\n return (\n idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) ||\n idWithoutQueryAndHash.includes(`\\\\node_modules\\\\${pluginName}\\\\`)\n );\n });\n}\n\nfunction escapeAttributeValue(value: string): string {\n return value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\n}\n\nfunction makeAttributeText(\n code: string,\n insertionOffset: number,\n attributes: AttributeInsertion['attributes'],\n): string {\n const previousCharIsWhitespace = insertionOffset > 0 && /\\s/.test(code[insertionOffset - 1] ?? '');\n const prefix = previousCharIsWhitespace ? '' : ' ';\n const suffix = previousCharIsWhitespace && code[insertionOffset] === '/' ? ' ' : '';\n const attributeText = attributes.map(([name, value]) => `${name}=\"${escapeAttributeValue(value)}\"`).join(' ');\n\n return `${prefix}${attributeText}${suffix}`;\n}\n\nfunction getMagicString(\n code: string,\n meta?: ComponentAnnotationTransformMeta,\n): { magicString: MagicStringLike; isNative: boolean } {\n if (meta?.magicString) {\n return { magicString: meta.magicString, isNative: true };\n }\n\n return { magicString: new MagicString(code), isNative: false };\n}\n\nasync function annotateWithOxcParser(\n code: string,\n id: string,\n ignoredComponents: string[],\n parseAstAsync: ParseAstAsync,\n meta?: ComponentAnnotationTransformMeta,\n): Promise<ComponentAnnotationTransformResult> {\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (\n !idWithoutQueryAndHash ||\n !isAnnotationFile(idWithoutQueryAndHash) ||\n !shouldTryParse(code) ||\n shouldSkipIncompatibleFile(idWithoutQueryAndHash)\n ) {\n return null;\n }\n\n const ast = await parseAstAsync(code, {\n lang: idWithoutQueryAndHash.endsWith('.jsx') ? 'jsx' : 'tsx',\n });\n\n // Fall through to the Babel fallback (return undefined, not null) when the parser yields an\n // unexpected result, mirroring the catch path — null would suppress Babel and drop annotations.\n if (!isAstNode(ast)) {\n return undefined;\n }\n\n const insertions = collectOxcComponentAnnotationInsertions(\n code,\n ast,\n ignoredComponents,\n path.basename(idWithoutQueryAndHash),\n );\n\n if (insertions.length === 0) {\n return null;\n }\n\n const { magicString, isNative } = getMagicString(code, meta);\n\n for (const insertion of insertions) {\n magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));\n }\n\n if (isNative) {\n return { code: magicString as unknown as string };\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap?.({\n file: id,\n source: idWithoutQueryAndHash,\n includeContent: true,\n hires: true,\n }),\n };\n}\n\nexport function createOxcComponentNameAnnotateHooks(\n ignoredComponents: string[],\n getParseAstAsync: () => Promise<ParseAstAsync | null>,\n): {\n transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<ComponentAnnotationTransformResult>;\n} {\n return {\n async transform(code, id, meta) {\n try {\n const parseAstAsync = await getParseAstAsync();\n\n if (!parseAstAsync) {\n return undefined;\n }\n\n return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);\n } catch {\n return undefined;\n }\n },\n };\n}\n"],"names":["KNOWN_INCOMPATIBLE_PLUGINS","MagicString","stripQueryAndHashFromPath","isAstNode","collectOxcComponentAnnotationInsertions","path"],"mappings":";;;;;;;;;;;;;;AAqBA,IAAI,uBAAA;AAEG,SAAS,mBAAA,GAAqD;AACnE,EAAA,IAAI,CAAC,uBAAA,EAAyB;AAC5B,IAAA,uBAAA,GAA0B,OAAO,YAAY,CAAA,CAC1C,KAAK,CAAC,EAAE,OAAM,KAAqB;AAClC,MAAA,OAAO,OAAO,IAAA,EAAM,EAAE,IAAA,EAAK,KAAM;AAG/B,QAAA,MAAM,EAAE,OAAA,EAAS,MAAA,EAAO,GAAI,MAAM,KAAA,CAAM,CAAA,UAAA,EAAa,I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IAAA,EAAM,EAAA,EAAI,iBAAA,EAAmB,eAAe,IAAI,CAAA;AAAA,MACrF,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,IACF;AAAA,GACF;AACF;;;;;"}
@@ -0,0 +1,87 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ function isLineTerminator(character) {
4
+ return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
5
+ }
6
+ function skipTrivia(code, start) {
7
+ let position = start;
8
+ let hasLineBreak = false;
9
+ while (position < code.length) {
10
+ const character = code[position];
11
+ if (/\s/.test(character || "")) {
12
+ hasLineBreak || (hasLineBreak = isLineTerminator(character));
13
+ position++;
14
+ } else if (code.startsWith("//", position) || position === 0 && code.startsWith("#!", position)) {
15
+ let lineEnd = position + 2;
16
+ while (lineEnd < code.length && !isLineTerminator(code[lineEnd])) {
17
+ lineEnd++;
18
+ }
19
+ if (lineEnd === code.length) {
20
+ return { end: code.length, hasLineBreak };
21
+ }
22
+ position = lineEnd + 1;
23
+ hasLineBreak = true;
24
+ } else if (code.startsWith("/*", position)) {
25
+ const commentEnd = code.indexOf("*/", position + 2);
26
+ if (commentEnd === -1) {
27
+ return { end: code.length, hasLineBreak };
28
+ }
29
+ const comment = code.slice(position, commentEnd + 2);
30
+ hasLineBreak || (hasLineBreak = /[\n\r\u2028\u2029]/.test(comment));
31
+ position = commentEnd + 2;
32
+ } else {
33
+ break;
34
+ }
35
+ }
36
+ return { end: position, hasLineBreak };
37
+ }
38
+ function findStringLiteralEnd(code, start) {
39
+ const quote = code[start];
40
+ if (quote !== '"' && quote !== "'") {
41
+ return void 0;
42
+ }
43
+ for (let position = start + 1; position < code.length; position++) {
44
+ const character = code[position];
45
+ if (character === "\\") {
46
+ position += code[position + 1] === "\r" && code[position + 2] === "\n" ? 2 : 1;
47
+ } else if (character === quote) {
48
+ return position + 1;
49
+ } else if (isLineTerminator(character)) {
50
+ return void 0;
51
+ }
52
+ }
53
+ return void 0;
54
+ }
55
+ function startsWithBinaryOperatorKeyword(remainder, keyword) {
56
+ return remainder.startsWith(keyword) && !/^[$_\\\u200C\u200D\p{ID_Continue}]/u.test(remainder.slice(keyword.length));
57
+ }
58
+ function canContinueStringExpression(code, position) {
59
+ const remainder = code.slice(position, position + "instanceof".length + 1);
60
+ if (/^(?:\+\+|--|!(?!=))/.test(remainder)) {
61
+ return false;
62
+ }
63
+ return /^!={1,2}/.test(remainder) || /^[([.`+\-*/%<>=&|^?,:]/.test(remainder) || ["in", "instanceof"].some((keyword) => startsWithBinaryOperatorKeyword(remainder, keyword));
64
+ }
65
+ function getCodeInjectionPosition(code) {
66
+ let position = skipTrivia(code, 0).end;
67
+ let prologueEnd = position;
68
+ while (position < code.length) {
69
+ const stringEnd = findStringLiteralEnd(code, position);
70
+ if (stringEnd === void 0) {
71
+ break;
72
+ }
73
+ const trailingTrivia = skipTrivia(code, stringEnd);
74
+ if (code[trailingTrivia.end] === ";") {
75
+ position = skipTrivia(code, trailingTrivia.end + 1).end;
76
+ } else if (trailingTrivia.end === code.length || trailingTrivia.hasLineBreak && !canContinueStringExpression(code, trailingTrivia.end)) {
77
+ position = trailingTrivia.end;
78
+ } else {
79
+ break;
80
+ }
81
+ prologueEnd = position;
82
+ }
83
+ return prologueEnd;
84
+ }
85
+
86
+ exports.getCodeInjectionPosition = getCodeInjectionPosition;
87
+ //# sourceMappingURL=get-code-injection-position.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-code-injection-position.js","sources":["../../../src/core/get-code-injection-position.ts"],"sourcesContent":["function isLineTerminator(character: string | undefined): boolean {\n return character === '\\n' || character === '\\r' || character === '\\u2028' || character === '\\u2029';\n}\n\nfunction skipTrivia(code: string, start: number): { end: number; hasLineBreak: boolean } {\n let position = start;\n let hasLineBreak = false;\n\n while (position < code.length) {\n const character = code[position];\n\n if (/\\s/.test(character || '')) {\n hasLineBreak ||= isLineTerminator(character);\n position++;\n } else if (code.startsWith('//', position) || (position === 0 && code.startsWith('#!', position))) {\n let lineEnd = position + 2;\n while (lineEnd < code.length && !isLineTerminator(code[lineEnd])) {\n lineEnd++;\n }\n if (lineEnd === code.length) {\n return { end: code.length, hasLineBreak };\n }\n position = lineEnd + 1;\n hasLineBreak = true;\n } else if (code.startsWith('/*', position)) {\n const commentEnd = code.indexOf('*/', position + 2);\n if (commentEnd === -1) {\n return { end: code.length, hasLineBreak };\n }\n const comment = code.slice(position, commentEnd + 2);\n hasLineBreak ||= /[\\n\\r\\u2028\\u2029]/.test(comment);\n position = commentEnd + 2;\n } else {\n break;\n }\n }\n\n return { end: position, hasLineBreak };\n}\n\nfunction findStringLiteralEnd(code: string, start: number): number | undefined {\n const quote = code[start];\n if (quote !== '\"' && quote !== \"'\") {\n return undefined;\n }\n\n for (let position = start + 1; position < code.length; position++) {\n const character = code[position];\n if (character === '\\\\') {\n position += code[position + 1] === '\\r' && code[position + 2] === '\\n' ? 2 : 1;\n } else if (character === quote) {\n return position + 1;\n } else if (isLineTerminator(character)) {\n return undefined;\n }\n }\n\n return undefined;\n}\n\nfunction startsWithBinaryOperatorKeyword(remainder: string, keyword: string): boolean {\n return remainder.startsWith(keyword) && !/^[$_\\\\\\u200C\\u200D\\p{ID_Continue}]/u.test(remainder.slice(keyword.length));\n}\n\nfunction canContinueStringExpression(code: string, position: number): boolean {\n const remainder = code.slice(position, position + 'instanceof'.length + 1);\n if (/^(?:\\+\\+|--|!(?!=))/.test(remainder)) {\n return false;\n }\n\n return (\n /^!={1,2}/.test(remainder) ||\n /^[([.`+\\-*/%<>=&|^?,:]/.test(remainder) ||\n ['in', 'instanceof'].some(keyword => startsWithBinaryOperatorKeyword(remainder, keyword))\n );\n}\n\nexport function getCodeInjectionPosition(code: string): number {\n let position = skipTrivia(code, 0).end;\n let prologueEnd = position;\n\n while (position < code.length) {\n const stringEnd = findStringLiteralEnd(code, position);\n if (stringEnd === undefined) {\n break;\n }\n\n const trailingTrivia = skipTrivia(code, stringEnd);\n if (code[trailingTrivia.end] === ';') {\n position = skipTrivia(code, trailingTrivia.end + 1).end;\n } else if (\n trailingTrivia.end === code.length ||\n (trailingTrivia.hasLineBreak && !canContinueStringExpression(code, trailingTrivia.end))\n ) {\n position = trailingTrivia.end;\n } else {\n break;\n }\n\n prologueEnd = position;\n }\n\n return prologueEnd;\n}\n"],"names":[],"mappings":";;AAAA,SAAS,iBAAiB,SAAA,EAAwC;AAChE,EAAA,OAAO,cAAc,IAAA,IAAQ,SAAA,KAAc,IAAA,IAAQ,SAAA,KAAc,YAAY,SAAA,KAAc,QAAA;AAC7F;AAEA,SAAS,UAAA,CAAW,MAAc,KAAA,EAAuD;AACvF,EAAA,IAAI,QAAA,GAAW,KAAA;AACf,EAAA,IAAI,YAAA,GAAe,KAAA;AAEnB,EAAA,OAAO,QAAA,GAAW,KAAK,MAAA,EAAQ;AAC7B,IAAA,MAAM,SAAA,GAAY,KAAK,QAAQ,CAAA;AAE/B,IAAA,IAAI,IAAA,CAAK,IAAA,CAAK,SAAA,IAAa,EAAE,CAAA,EAAG;AAC9B,MAAA,YAAA,KAAA,YAAA,GAAiB,iBAAiB,SAAS,CAAA,CAAA;AAC3C,MAAA,QAAA,EAAA;AAAA,IACF,CAAA,MAAA,IAAW,IAAA,CAAK,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAA,IAAM,QAAA,KAAa,CAAA,IAAK,IAAA,CAAK,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAA,EAAI;AACjG,MAAA,IAAI,UAAU,QAAA,GAAW,CAAA;AACzB,MAAA,OAAO,OAAA,GAAU,KAAK,MAAA,IAAU,CAAC,iBAAiB,IAAA,CAAK,OAAO,CAAC,CAAA,EAAG;AAChE,QAAA,OAAA,EAAA;AAAA,MACF;AACA,MAAA,IAAI,OAAA,KAAY,KAAK,MAAA,EAAQ;AAC3B,QAAA,OAAO,EAAE,GAAA,EAAK,IAAA,CAAK,MAAA,EAAQ,YAAA,EAAa;AAAA,MAC1C;AACA,MAA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SAAS,CAAA;AACjD,IAAA,IAAI,IAAA,CAAK,cAAA,CAAe,GAAG,CAAA,KAAM,GAAA,EAAK;AACpC,MAAA,QAAA,GAAW,UAAA,CAAW,IAAA,EAAM,cAAA,CAAe,GAAA,GAAM,CAAC,CAAA,CAAE,GAAA;AAAA,IACtD,CAAA,MAAA,IACE,cAAA,CAAe,GAAA,KAAQ,IAAA,CAAK,MAAA,IAC3B,cAAA,CAAe,YAAA,IAAgB,CAAC,2BAAA,CAA4B,IAAA,EAAM,cAAA,CAAe,GAAG,CAAA,EACrF;AACA,MAAA,QAAA,GAAW,cAAA,CAAe,GAAA;AAAA,IAC5B,CAAA,MAAO;AACL,MAAA;AAAA,IACF;AAEA,IAAA,WAAA,GAAc,QAAA;AAAA,EAChB;AAEA,EAAA,OAAO,WAAA;AACT;;;;"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const core = require('@sentry/core');
4
4
  const utils = require('./utils.js');
5
5
  const glob = require('./glob.js');
6
+ const getCodeInjectionPosition = require('./get-code-injection-position.js');
6
7
  const buildPluginManager = require('./build-plugin-manager.js');
7
8
  const debugIdUpload = require('./debug-id-upload.js');
8
9
 
@@ -21,10 +22,6 @@ function loadBabelAnnotationRuntime() {
21
22
  }
22
23
  return babelAnnotationRuntimePromise;
23
24
  }
24
- const COMMENT_USE_STRICT_REGEX = (
25
- // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
26
- /^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/
27
- );
28
25
  function isJsFile(fileName) {
29
26
  const cleanFileName = utils.stripQueryAndHashFromPath(fileName);
30
27
  return [".js", ".mjs", ".cjs"].some((ext) => cleanFileName.endsWith(ext));
@@ -94,11 +91,11 @@ exports.generateReleaseInjectorCode = utils.generateReleaseInjectorCode;
94
91
  exports.replaceBooleanFlagsInCode = utils.replaceBooleanFlagsInCode;
95
92
  exports.stringToUUID = utils.stringToUUID;
96
93
  exports.globFiles = glob.globFiles;
94
+ exports.getCodeInjectionPosition = getCodeInjectionPosition.getCodeInjectionPosition;
97
95
  exports.createSentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager;
98
96
  exports.addDebugIdToEmittedArtifacts = debugIdUpload.addDebugIdToEmittedArtifacts;
99
97
  exports.createDebugIdUploadFunction = debugIdUpload.createDebugIdUploadFunction;
100
98
  exports.stampDebugId = debugIdUpload.stampDebugId;
101
- exports.COMMENT_USE_STRICT_REGEX = COMMENT_USE_STRICT_REGEX;
102
99
  exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
103
100
  exports.getDebugIdSnippet = getDebugIdSnippet;
104
101
  exports.isJsFile = isJsFile;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\nimport type { transformAsync as babelTransformAsync } from '@babel/core';\nimport type componentNameAnnotatePlugin from '../babel-plugin';\nimport type { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\n\ntype BabelTransformAsync = typeof babelTransformAsync;\ntype BabelParserPlugins = NonNullable<NonNullable<Parameters<BabelTransformAsync>[1]>['parserOpts']>['plugins'];\ntype BabelAnnotationRuntime = {\n transformAsync: BabelTransformAsync;\n componentNameAnnotatePlugin: typeof componentNameAnnotatePlugin;\n experimentalComponentNameAnnotatePlugin: typeof experimentalComponentNameAnnotatePlugin;\n};\n\nlet babelAnnotationRuntimePromise: Promise<BabelAnnotationRuntime> | undefined;\n\nfunction loadBabelAnnotationRuntime(): Promise<BabelAnnotationRuntime> {\n if (!babelAnnotationRuntimePromise) {\n babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), import('../babel-plugin')]).then(\n ([babel, babelPlugin]) => {\n return {\n transformAsync: babel.transformAsync,\n componentNameAnnotatePlugin: babelPlugin.default,\n experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin,\n };\n },\n );\n }\n\n return babelAnnotationRuntimePromise;\n}\n\n// We need to be careful not to inject the snippet before any `\"use strict\";`s.\n// As an additional complication `\"use strict\";`s may come after any number of comments.\nexport const COMMENT_USE_STRICT_REGEX =\n // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.\n /^(?:\\s*|\\/\\*(?:.|\\r|\\n)*?\\*\\/|\\/\\/.*[\\n\\r])*(?:\"[^\"]*\";|'[^']*';)?/;\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport { globFiles } from './glob';\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(ignoredComponents: string[], injectIntoHtml: boolean) {\n return {\n async transform(this: void, code: string, id: string) {\n // id may contain query and hash which will trip up our file extension logic below\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return null;\n }\n\n // We will only apply this plugin on jsx and tsx files\n if (!['.jsx', '.tsx'].some(ending => idWithoutQueryAndHash.endsWith(ending))) {\n return null;\n }\n\n const parserPlugins: BabelParserPlugins = [];\n if (idWithoutQueryAndHash.endsWith('.jsx')) {\n parserPlugins.push('jsx');\n } else if (idWithoutQueryAndHash.endsWith('.tsx')) {\n parserPlugins.push('jsx', 'typescript');\n }\n\n const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } =\n await loadBabelAnnotationRuntime();\n const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;\n\n try {\n const result = await transformAsync(code, {\n plugins: [[plugin, { ignoredComponents }]],\n filename: id,\n sourceFileName: idWithoutQueryAndHash,\n parserOpts: {\n sourceType: 'module',\n allowAwaitOutsideFunction: true,\n plugins: parserPlugins,\n },\n generatorOpts: {\n decoratorsBeforeExport: true,\n },\n sourceMaps: true,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map,\n };\n } catch (e) {\n debug.error(`Failed to apply react annotate plugin`, e);\n }\n\n return { code };\n },\n };\n}\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport { createDebugIdUploadFunction, addDebugIdToEmittedArtifacts, stampDebugId } from './debug-id-upload';\n"],"names":["stripQueryAndHashFromPath","containsOnlyImports","debug","Code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AA;AAAA,UACtB,KAAK,MAAA,EAAQ;AAAA,SACf;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAAE,UAAA,CAAM,KAAA,CAAM,yCAAyC,CAAC,CAAA;AAAA,MACxD;AAEA,MAAA,OAAO,EAAE,IAAA,EAAK;AAAA,IAChB;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,OAAA,EAAgC;AAChE,EAAA,OAAO,IAAIC,mBAAA;AAAA,IACT,CAAA,4FAAA,EAA+F,OAAO,CAAA,0CAAA,EAA6C,OAAO,CAAA,GAAA;AAAA,GAC5J;AACF;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\nimport type { transformAsync as babelTransformAsync } from '@babel/core';\nimport type componentNameAnnotatePlugin from '../babel-plugin';\nimport type { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\n\ntype BabelTransformAsync = typeof babelTransformAsync;\ntype BabelParserPlugins = NonNullable<NonNullable<Parameters<BabelTransformAsync>[1]>['parserOpts']>['plugins'];\ntype BabelAnnotationRuntime = {\n transformAsync: BabelTransformAsync;\n componentNameAnnotatePlugin: typeof componentNameAnnotatePlugin;\n experimentalComponentNameAnnotatePlugin: typeof experimentalComponentNameAnnotatePlugin;\n};\n\nlet babelAnnotationRuntimePromise: Promise<BabelAnnotationRuntime> | undefined;\n\nfunction loadBabelAnnotationRuntime(): Promise<BabelAnnotationRuntime> {\n if (!babelAnnotationRuntimePromise) {\n babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), import('../babel-plugin')]).then(\n ([babel, babelPlugin]) => {\n return {\n transformAsync: babel.transformAsync,\n componentNameAnnotatePlugin: babelPlugin.default,\n experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin,\n };\n },\n );\n }\n\n return babelAnnotationRuntimePromise;\n}\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport { globFiles } from './glob';\nexport { getCodeInjectionPosition } from './get-code-injection-position';\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(ignoredComponents: string[], injectIntoHtml: boolean) {\n return {\n async transform(this: void, code: string, id: string) {\n // id may contain query and hash which will trip up our file extension logic below\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return null;\n }\n\n // We will only apply this plugin on jsx and tsx files\n if (!['.jsx', '.tsx'].some(ending => idWithoutQueryAndHash.endsWith(ending))) {\n return null;\n }\n\n const parserPlugins: BabelParserPlugins = [];\n if (idWithoutQueryAndHash.endsWith('.jsx')) {\n parserPlugins.push('jsx');\n } else if (idWithoutQueryAndHash.endsWith('.tsx')) {\n parserPlugins.push('jsx', 'typescript');\n }\n\n const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } =\n await loadBabelAnnotationRuntime();\n const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;\n\n try {\n const result = await transformAsync(code, {\n plugins: [[plugin, { ignoredComponents }]],\n filename: id,\n sourceFileName: idWithoutQueryAndHash,\n parserOpts: {\n sourceType: 'module',\n allowAwaitOutsideFunction: true,\n plugins: parserPlugins,\n },\n generatorOpts: {\n decoratorsBeforeExport: true,\n },\n sourceMaps: true,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map,\n };\n } catch (e) {\n debug.error(`Failed to apply react annotate plugin`, e);\n }\n\n return { code };\n },\n };\n}\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport { createDebugIdUploadFunction, addDebugIdToEmittedArtifacts, stampDebugId } from './debug-id-upload';\n"],"names":["stripQueryAndHashFromPath","containsOnlyImports","debug","CodeInjection"],"mappings":";;;;;;;;;AAcA,IAAI,6BAAA;AAEJ,SAAS,0BAAA,GAA8D;AACrE,EAAA,IAAI,CAAC,6BAAA,EAA+B;AAClC,IAAA,6BAAA,GAAgC,OAAA,CAAQ,GAAA,CAAI,CAAC,OAAO,aAAa,GAAG,qCAAO,0BAAiB,EAAC,CAAC,CAAA,CAAE,IAAA;AAAA,MAC9F,CAAC,CAAC,KAAA,EAAO,WAAW,CAAA,KAAM;AACxB,QAAA,OAAO;AAAA,UACL,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