@sentry/bundler-plugins 11.0.0-beta.2 → 11.0.0-rc.1

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 (103) 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/debug-id-upload.js +77 -2
  12. package/build/cjs/core/debug-id-upload.js.map +1 -1
  13. package/build/cjs/core/index.js +2 -0
  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 +17 -2
  20. package/build/cjs/esbuild/index.js.map +1 -1
  21. package/build/cjs/rollup/index.js +33 -22
  22. package/build/cjs/rollup/index.js.map +1 -1
  23. package/build/cjs/webpack/index.js +200 -11
  24. package/build/cjs/webpack/index.js.map +1 -1
  25. package/build/esm/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
  26. package/build/esm/core/component-annotation-oxc-ast.js.map +1 -0
  27. package/build/esm/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +3 -3
  28. package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -0
  29. package/build/esm/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +2 -2
  30. package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -0
  31. package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +6 -6
  32. package/build/esm/core/component-annotation-oxc-walk.js.map +1 -0
  33. package/build/esm/core/{component-annotation-vite.js → component-annotation-oxc.js} +25 -10
  34. package/build/esm/core/component-annotation-oxc.js.map +1 -0
  35. package/build/esm/core/debug-id-upload.js +76 -3
  36. package/build/esm/core/debug-id-upload.js.map +1 -1
  37. package/build/esm/core/index.js +1 -1
  38. package/build/esm/core/index.js.map +1 -1
  39. package/build/esm/core/sentry/telemetry.js +4 -1
  40. package/build/esm/core/sentry/telemetry.js.map +1 -1
  41. package/build/esm/core/version.js +1 -1
  42. package/build/esm/core/version.js.map +1 -1
  43. package/build/esm/esbuild/index.js +19 -4
  44. package/build/esm/esbuild/index.js.map +1 -1
  45. package/build/esm/package.json +1 -1
  46. package/build/esm/rollup/index.js +34 -23
  47. package/build/esm/rollup/index.js.map +1 -1
  48. package/build/esm/webpack/index.js +186 -11
  49. package/build/esm/webpack/index.js.map +1 -1
  50. package/build/types/core/{component-annotation-vite-ast.d.ts → component-annotation-oxc-ast.d.ts} +1 -1
  51. package/build/types/core/component-annotation-oxc-ast.d.ts.map +1 -0
  52. package/build/types/core/{component-annotation-vite-fragments.d.ts → component-annotation-oxc-fragments.d.ts} +2 -2
  53. package/build/types/core/component-annotation-oxc-fragments.d.ts.map +1 -0
  54. package/build/types/core/{component-annotation-vite-jsx.d.ts → component-annotation-oxc-jsx.d.ts} +2 -2
  55. package/build/types/core/component-annotation-oxc-jsx.d.ts.map +1 -0
  56. package/build/types/core/component-annotation-oxc-walk.d.ts +3 -0
  57. package/build/types/core/component-annotation-oxc-walk.d.ts.map +1 -0
  58. package/build/types/core/component-annotation-oxc.d.ts +7 -0
  59. package/build/types/core/component-annotation-oxc.d.ts.map +1 -0
  60. package/build/types/core/debug-id-upload.d.ts +28 -0
  61. package/build/types/core/debug-id-upload.d.ts.map +1 -1
  62. package/build/types/core/index.d.ts +1 -1
  63. package/build/types/core/index.d.ts.map +1 -1
  64. package/build/types/core/sentry/telemetry.d.ts.map +1 -1
  65. package/build/types/core/types.d.ts +7 -2
  66. package/build/types/core/types.d.ts.map +1 -1
  67. package/build/types/core/version.d.ts +1 -1
  68. package/build/types/core/version.d.ts.map +1 -1
  69. package/build/types/esbuild/index.d.ts.map +1 -1
  70. package/build/types/rollup/index.d.ts +17 -26
  71. package/build/types/rollup/index.d.ts.map +1 -1
  72. package/build/types/webpack/index.d.ts +14 -2
  73. package/build/types/webpack/index.d.ts.map +1 -1
  74. package/package.json +4 -9
  75. package/build/cjs/core/component-annotation-vite-ast.js.map +0 -1
  76. package/build/cjs/core/component-annotation-vite-fragments.js.map +0 -1
  77. package/build/cjs/core/component-annotation-vite-jsx.js.map +0 -1
  78. package/build/cjs/core/component-annotation-vite-walk.js.map +0 -1
  79. package/build/cjs/core/component-annotation-vite.js.map +0 -1
  80. package/build/cjs/webpack/webpack4and5.js +0 -185
  81. package/build/cjs/webpack/webpack4and5.js.map +0 -1
  82. package/build/cjs/webpack/webpack5.js +0 -9
  83. package/build/cjs/webpack/webpack5.js.map +0 -1
  84. package/build/esm/core/component-annotation-vite-ast.js.map +0 -1
  85. package/build/esm/core/component-annotation-vite-fragments.js.map +0 -1
  86. package/build/esm/core/component-annotation-vite-jsx.js.map +0 -1
  87. package/build/esm/core/component-annotation-vite-walk.js.map +0 -1
  88. package/build/esm/core/component-annotation-vite.js.map +0 -1
  89. package/build/esm/webpack/webpack4and5.js +0 -168
  90. package/build/esm/webpack/webpack4and5.js.map +0 -1
  91. package/build/esm/webpack/webpack5.js +0 -7
  92. package/build/esm/webpack/webpack5.js.map +0 -1
  93. package/build/types/core/component-annotation-vite-ast.d.ts.map +0 -1
  94. package/build/types/core/component-annotation-vite-fragments.d.ts.map +0 -1
  95. package/build/types/core/component-annotation-vite-jsx.d.ts.map +0 -1
  96. package/build/types/core/component-annotation-vite-walk.d.ts +0 -3
  97. package/build/types/core/component-annotation-vite-walk.d.ts.map +0 -1
  98. package/build/types/core/component-annotation-vite.d.ts +0 -6
  99. package/build/types/core/component-annotation-vite.d.ts.map +0 -1
  100. package/build/types/webpack/webpack4and5.d.ts +0 -99
  101. package/build/types/webpack/webpack4and5.d.ts.map +0 -1
  102. package/build/types/webpack/webpack5.d.ts +0 -4
  103. 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) === '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AAC1F,EAAA,OACEF,iBAAA,CAAa,QAAQ,CAAA,KACpB,QAAA,CAAS,SAAS,UAAA,IAAc,QAAA,CAAS,SAAS,gBAAA,CAAA,IACnDA,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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 +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,QAA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,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;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,E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AE7C,QAAA,IAAI,CAAC,aAAA,EAAe;AAClB,UAAA,OAAO,KAAA,CAAA;AAAA,QACT;AAEA,QAAA,OAAO,MAAM,qBAAA,CAAsB,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;;;;;"}
@@ -95,6 +95,80 @@ function addDebugIdToBundleSource(bundleSource, debugId) {
95
95
  //# debugId=${debugId}`;
96
96
  }
97
97
  }
98
+ function setDebugIdOnSourceMap(map, debugId) {
99
+ map["debug_id"] = debugId;
100
+ map["debugId"] = debugId;
101
+ }
102
+ function parseSourceMap(sourceMapSource) {
103
+ let map;
104
+ try {
105
+ map = JSON.parse(sourceMapSource);
106
+ } catch {
107
+ return void 0;
108
+ }
109
+ return map && typeof map === "object" ? map : void 0;
110
+ }
111
+ function stampDebugId(bundleSource, sourceMapSource) {
112
+ const debugId = determineDebugIdFromBundleSource(bundleSource);
113
+ if (debugId === void 0) {
114
+ return void 0;
115
+ }
116
+ if (sourceMapSource === void 0) {
117
+ if (!bundleHasInlineSourceMap(bundleSource)) {
118
+ return void 0;
119
+ }
120
+ return { bundleSource: addDebugIdToBundleSource(bundleSource, debugId), sourceMapSource: void 0 };
121
+ }
122
+ const map = parseSourceMap(sourceMapSource);
123
+ if (!map) {
124
+ return void 0;
125
+ }
126
+ setDebugIdOnSourceMap(map, debugId);
127
+ return {
128
+ bundleSource: addDebugIdToBundleSource(bundleSource, debugId),
129
+ sourceMapSource: JSON.stringify(map)
130
+ };
131
+ }
132
+ async function addDebugIdToEmittedArtifacts(bundleFilePath, logger, resolveSourceMapHook) {
133
+ let bundleSource;
134
+ try {
135
+ bundleSource = await fs__default.promises.readFile(bundleFilePath, "utf8");
136
+ } catch (e) {
137
+ logger.error(`Could not read bundle to stamp debug ID: ${bundleFilePath}`, e);
138
+ return;
139
+ }
140
+ const sourceMapPath = await determineSourceMapPathFromBundle(
141
+ bundleFilePath,
142
+ bundleSource,
143
+ logger,
144
+ resolveSourceMapHook
145
+ );
146
+ let sourceMapSource;
147
+ if (sourceMapPath) {
148
+ try {
149
+ sourceMapSource = await fs__default.promises.readFile(sourceMapPath, "utf8");
150
+ } catch (e) {
151
+ logger.error(`Could not read source map to stamp debug ID: ${sourceMapPath}`, e);
152
+ return;
153
+ }
154
+ }
155
+ const stamped = stampDebugId(bundleSource, sourceMapSource);
156
+ if (!stamped) {
157
+ logger.debug(
158
+ `Could not stamp debug ID (no debug ID in bundle, no source map, or invalid source map): ${bundleFilePath}`
159
+ );
160
+ return;
161
+ }
162
+ const writes = [fs__default.promises.writeFile(bundleFilePath, stamped.bundleSource, "utf8")];
163
+ if (sourceMapPath && stamped.sourceMapSource !== void 0) {
164
+ writes.push(fs__default.promises.writeFile(sourceMapPath, stamped.sourceMapSource, "utf8"));
165
+ }
166
+ try {
167
+ await Promise.all(writes);
168
+ } catch (e) {
169
+ logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);
170
+ }
171
+ }
98
172
  function bundleHasInlineSourceMap(bundleSource) {
99
173
  return /^\s*\/\/# sourceMappingURL=data:/m.test(bundleSource);
100
174
  }
@@ -153,8 +227,7 @@ async function prepareSourceMapForDebugIdUpload(sourceMapPath, targetPath, debug
153
227
  let map;
154
228
  try {
155
229
  map = JSON.parse(sourceMapFileContent);
156
- map["debug_id"] = debugId;
157
- map["debugId"] = debugId;
230
+ setDebugIdOnSourceMap(map, debugId);
158
231
  } catch {
159
232
  logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);
160
233
  return;
@@ -181,8 +254,10 @@ function defaultRewriteSourcesHook(source) {
181
254
  }
182
255
  }
183
256
 
257
+ exports.addDebugIdToEmittedArtifacts = addDebugIdToEmittedArtifacts;
184
258
  exports.createDebugIdUploadFunction = createDebugIdUploadFunction;
185
259
  exports.defaultRewriteSourcesHook = defaultRewriteSourcesHook;
186
260
  exports.determineSourceMapPathFromBundle = determineSourceMapPathFromBundle;
187
261
  exports.prepareBundleForDebugIdUpload = prepareBundleForDebugIdUpload;
262
+ exports.stampDebugId = stampDebugId;
188
263
  //# sourceMappingURL=debug-id-upload.js.map