@sentry/bundler-plugins 11.0.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -11
- package/build/cjs/core/component-annotate-hooks.js +32 -0
- package/build/cjs/core/component-annotate-hooks.js.map +1 -0
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-jsx.js +64 -6
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-walk.js +23 -2
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc.js +21 -12
- package/build/cjs/core/component-annotation-oxc.js.map +1 -1
- package/build/cjs/core/index.js +2 -61
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/loader-utils/index.js +10 -0
- package/build/cjs/loader-utils/index.js.map +1 -0
- package/build/cjs/rollup/index.js +10 -31
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/webpack/index.js +4 -2
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/core/component-annotate-hooks.js +30 -0
- package/build/esm/core/component-annotate-hooks.js.map +1 -0
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-jsx.js +65 -8
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-walk.js +24 -3
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/esm/core/component-annotation-oxc.js +21 -12
- package/build/esm/core/component-annotation-oxc.js.map +1 -1
- package/build/esm/core/index.js +3 -62
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/loader-utils/index.js +3 -0
- package/build/esm/loader-utils/index.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/index.js +10 -31
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/webpack/index.js +4 -2
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/component-annotate-hooks.d.ts +9 -0
- package/build/types/core/component-annotate-hooks.d.ts.map +1 -0
- package/build/types/core/component-annotation-oxc-ast.d.ts +1 -1
- package/build/types/core/component-annotation-oxc-ast.d.ts.map +1 -1
- package/build/types/core/component-annotation-oxc-jsx.d.ts +5 -0
- package/build/types/core/component-annotation-oxc-jsx.d.ts.map +1 -1
- package/build/types/core/component-annotation-oxc-walk.d.ts +1 -1
- package/build/types/core/component-annotation-oxc-walk.d.ts.map +1 -1
- package/build/types/core/component-annotation-oxc.d.ts +1 -1
- package/build/types/core/component-annotation-oxc.d.ts.map +1 -1
- package/build/types/core/index.d.ts +1 -17
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/loader-utils/index.d.ts +3 -0
- package/build/types/loader-utils/index.d.ts.map +1 -0
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +17 -8
package/README.md
CHANGED
|
@@ -15,17 +15,11 @@ Check out the individual packages for more information and examples:
|
|
|
15
15
|
- [esbuild](https://www.npmjs.com/package/@sentry/esbuild-plugin)
|
|
16
16
|
- [Webpack](https://www.npmjs.com/package/@sentry/webpack-plugin)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Documentation
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
- [Uploading source maps](https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/)
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
- Release creation in Sentry
|
|
24
|
-
- Automatic release name discovery (based on CI environment - Vercel, AWS, Heroku, CircleCI, or current Git SHA)
|
|
25
|
-
- Automatically associate errors with releases (Release injection)
|
|
22
|
+
## Support
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- [Sentry Documentation](https://docs.sentry.io/quickstart/)
|
|
30
|
-
- [Sentry Discord](https://discord.gg/Ww9hbqr)
|
|
31
|
-
- [Sentry Stackoverflow](http://stackoverflow.com/questions/tagged/sentry)
|
|
24
|
+
- [Report a bug](https://github.com/getsentry/sentry-javascript/issues/new/choose)
|
|
25
|
+
- [Contributing](https://github.com/getsentry/sentry-javascript/blob/develop/CONTRIBUTING.md)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const componentAnnotationOxc = require('./component-annotation-oxc.js');
|
|
4
|
+
|
|
5
|
+
const PARSER_UNAVAILABLE_MESSAGE = "Could not load `oxc-parser` for this platform. React components will not be annotated.";
|
|
6
|
+
let warnedParserUnavailable = false;
|
|
7
|
+
function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml, options = {}) {
|
|
8
|
+
const hooks = componentAnnotationOxc.createOxcComponentNameAnnotateHooks(
|
|
9
|
+
ignoredComponents,
|
|
10
|
+
async () => {
|
|
11
|
+
const parseAstAsync = await options.getParseAstAsync?.() ?? await componentAnnotationOxc.getOxcParseAstAsync();
|
|
12
|
+
if (!parseAstAsync && !warnedParserUnavailable) {
|
|
13
|
+
warnedParserUnavailable = true;
|
|
14
|
+
if (options.logger) {
|
|
15
|
+
options.logger.warn(PARSER_UNAVAILABLE_MESSAGE);
|
|
16
|
+
} else {
|
|
17
|
+
console.warn(`[@sentry/bundler-plugins] ${PARSER_UNAVAILABLE_MESSAGE}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return parseAstAsync;
|
|
21
|
+
},
|
|
22
|
+
injectIntoHtml
|
|
23
|
+
);
|
|
24
|
+
return {
|
|
25
|
+
transform(code, id, meta) {
|
|
26
|
+
return hooks.transform(code, id, meta);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
|
|
32
|
+
//# sourceMappingURL=component-annotate-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotate-hooks.js","sources":["../../../src/core/component-annotate-hooks.ts"],"sourcesContent":["import { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync } from './component-annotation-oxc';\nimport type { ComponentAnnotationTransformMeta, ParseAstAsync } from './component-annotation-oxc-ast';\nimport type { Logger } from './logger';\n\nconst PARSER_UNAVAILABLE_MESSAGE =\n 'Could not load `oxc-parser` for this platform. React components will not be annotated.';\n\n// Module level, because the Turbopack loader creates new hooks for\n// every file.\nlet warnedParserUnavailable = false;\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(\n ignoredComponents: string[],\n injectIntoHtml: boolean,\n options: { getParseAstAsync?: () => Promise<ParseAstAsync | null>; logger?: Logger } = {},\n) {\n const hooks = createOxcComponentNameAnnotateHooks(\n ignoredComponents,\n async () => {\n const parseAstAsync = (await options.getParseAstAsync?.()) ?? (await getOxcParseAstAsync());\n\n if (!parseAstAsync && !warnedParserUnavailable) {\n warnedParserUnavailable = true;\n if (options.logger) {\n options.logger.warn(PARSER_UNAVAILABLE_MESSAGE);\n } else {\n // eslint-disable-next-line no-console\n console.warn(`[@sentry/bundler-plugins] ${PARSER_UNAVAILABLE_MESSAGE}`);\n }\n }\n\n return parseAstAsync;\n },\n injectIntoHtml,\n );\n\n return {\n transform(this: void, code: string, id: string, meta?: ComponentAnnotationTransformMeta) {\n return hooks.transform(code, id, meta);\n },\n };\n}\n"],"names":["createOxcComponentNameAnnotateHooks","getOxcParseAstAsync"],"mappings":";;;;AAIA,MAAM,0BAAA,GACJ,wFAAA;AAIF,IAAI,uBAAA,GAA0B,KAAA;AAGvB,SAAS,gCAAA,CACd,iBAAA,EACA,cAAA,EACA,OAAA,GAAuF,EAAC,EACxF;AACA,EAAA,MAAM,KAAA,GAAQA,0DAAA;AAAA,IACZ,iBAAA;AAAA,IACA,YAAY;AACV,MAAA,MAAM,gBAAiB,MAAM,OAAA,CAAQ,gBAAA,IAAmB,IAAO,MAAMC,0CAAA,EAAoB;AAEzF,MAAA,IAAI,CAAC,aAAA,IAAiB,CAAC,uBAAA,EAAyB;AAC9C,QAAA,uBAAA,GAA0B,IAAA;AAC1B,QAAA,IAAI,QAAQ,MAAA,EAAQ;AAClB,UAAA,OAAA,CAAQ,MAAA,CAAO,KAAK,0BAA0B,CAAA;AAAA,QAChD,CAAA,MAAO;AAEL,UAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,0BAAA,EAA6B,0BAA0B,CAAA,CAAE,CAAA;AAAA,QACxE;AAAA,MACF;AAEA,MAAA,OAAO,aAAA;AAAA,IACT,CAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO;AAAA,IACL,SAAA,CAAsB,IAAA,EAAc,EAAA,EAAY,IAAA,EAAyC;AACvF,MAAA,OAAO,KAAA,CAAM,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI,IAAI,CAAA;AAAA,IACvC;AAAA,GACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-ast.js","sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-ast.js","sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult = {\n code: string;\n map?: SourceMap | string;\n} | null;\n\nexport function isAstNode(value: unknown): value is AstNode {\n return isObjectLike(value) && typeof value.type === 'string';\n}\n\nexport function walkAst(node: unknown, visit: (node: AstNode) => void): void {\n if (!isAstNode(node)) {\n return;\n }\n\n visit(node);\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n walkAst(child, visit);\n }\n } else if (isAstNode(value)) {\n walkAst(value, visit);\n }\n }\n}\n"],"names":["isObjectLike"],"mappings":";;;;AAkEO,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;;;;;;"}
|
|
@@ -5,6 +5,28 @@ 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
|
+
const REACT_NATIVE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
9
|
+
"Image",
|
|
10
|
+
"Text",
|
|
11
|
+
"View",
|
|
12
|
+
"ScrollView",
|
|
13
|
+
"TextInput",
|
|
14
|
+
"TouchableOpacity",
|
|
15
|
+
"TouchableHighlight",
|
|
16
|
+
"TouchableWithoutFeedback",
|
|
17
|
+
"FlatList",
|
|
18
|
+
"SectionList",
|
|
19
|
+
"ActivityIndicator",
|
|
20
|
+
"Button",
|
|
21
|
+
"Switch",
|
|
22
|
+
"Modal",
|
|
23
|
+
"SafeAreaView",
|
|
24
|
+
"StatusBar",
|
|
25
|
+
"KeyboardAvoidingView",
|
|
26
|
+
"RefreshControl",
|
|
27
|
+
"Picker",
|
|
28
|
+
"Slider"
|
|
29
|
+
]);
|
|
8
30
|
const WEB_ATTRIBUTE_NAMES = [componentAnnotation.WEB_ELEMENT_NAME, componentAnnotation.WEB_COMPONENT_NAME, componentAnnotation.WEB_SOURCE_FILE_NAME];
|
|
9
31
|
const WEB_ATTRIBUTE_NAME_SET = new Set(WEB_ATTRIBUTE_NAMES);
|
|
10
32
|
function isJSXElement(value) {
|
|
@@ -86,13 +108,48 @@ function addPendingAttributes(code, openingElement, componentName, ignoredCompon
|
|
|
86
108
|
if (attributes.length === 0) {
|
|
87
109
|
return;
|
|
88
110
|
}
|
|
89
|
-
const insertion =
|
|
90
|
-
offset,
|
|
91
|
-
attributeValues: /* @__PURE__ */ new Map()
|
|
92
|
-
}).get(offset);
|
|
111
|
+
const insertion = getOrCreateInsertion(insertionsByOffset, offset);
|
|
93
112
|
for (const [name, value] of attributes) {
|
|
94
|
-
insertion
|
|
113
|
+
insertion.attributeValues.set(name, value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function addPendingHtmlAttribute(code, openingElement, componentName, ignoredComponents, fragmentContext, insertionsByOffset) {
|
|
117
|
+
if (isReactFragment(openingElement, fragmentContext)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const elementName = getJSXName(openingElement.name);
|
|
121
|
+
if (!isHtmlElement(elementName)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const offset = getInsertionOffset(code, openingElement);
|
|
128
|
+
if (offset === null) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (getExistingAttributeNames(openingElement).has(componentAnnotation.WEB_COMPONENT_NAME) || insertionsByOffset.get(offset)?.attributeValues.has(componentAnnotation.WEB_COMPONENT_NAME)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(componentAnnotation.WEB_COMPONENT_NAME, componentName);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
function isHtmlElement(elementName) {
|
|
138
|
+
if (elementName === UNKNOWN_ELEMENT_NAME) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return REACT_NATIVE_ELEMENTS.has(elementName);
|
|
145
|
+
}
|
|
146
|
+
function getOrCreateInsertion(insertionsByOffset, offset) {
|
|
147
|
+
let insertion = insertionsByOffset.get(offset);
|
|
148
|
+
if (!insertion) {
|
|
149
|
+
insertion = { offset, attributeValues: /* @__PURE__ */ new Map() };
|
|
150
|
+
insertionsByOffset.set(offset, insertion);
|
|
95
151
|
}
|
|
152
|
+
return insertion;
|
|
96
153
|
}
|
|
97
154
|
function toAttributeInsertions(insertionsByOffset) {
|
|
98
155
|
return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({
|
|
@@ -116,7 +173,7 @@ function getOrderedAttributes(attributeValues) {
|
|
|
116
173
|
const attributes = [];
|
|
117
174
|
for (const name of WEB_ATTRIBUTE_NAMES) {
|
|
118
175
|
const value = attributeValues.get(name);
|
|
119
|
-
if (value) {
|
|
176
|
+
if (value !== void 0) {
|
|
120
177
|
attributes.push([name, value]);
|
|
121
178
|
}
|
|
122
179
|
}
|
|
@@ -129,6 +186,7 @@ function getOrderedAttributes(attributeValues) {
|
|
|
129
186
|
}
|
|
130
187
|
|
|
131
188
|
exports.addPendingAttributes = addPendingAttributes;
|
|
189
|
+
exports.addPendingHtmlAttribute = addPendingHtmlAttribute;
|
|
132
190
|
exports.getInsertionOffset = getInsertionOffset;
|
|
133
191
|
exports.getJSXName = getJSXName;
|
|
134
192
|
exports.getStringName = getStringName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-jsx.js","sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst 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,S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CAAI,IAAI,CAAA,EAAG;AACrC,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,OAAO,UAAA;AACT;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-jsx.js","sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst REACT_NATIVE_ELEMENTS = new Set([\n 'Image',\n 'Text',\n 'View',\n 'ScrollView',\n 'TextInput',\n 'TouchableOpacity',\n 'TouchableHighlight',\n 'TouchableWithoutFeedback',\n 'FlatList',\n 'SectionList',\n 'ActivityIndicator',\n 'Button',\n 'Switch',\n 'Modal',\n 'SafeAreaView',\n 'StatusBar',\n 'KeyboardAvoidingView',\n 'RefreshControl',\n 'Picker',\n 'Slider',\n]);\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion = getOrCreateInsertion(insertionsByOffset, offset);\n\n for (const [name, value] of attributes) {\n insertion.attributeValues.set(name, value);\n }\n}\n\n/**\n * Returns `true` when the element is an HTML element, because HTML mode only\n * annotates the first HTML elements below a component root.\n */\nexport function addPendingHtmlAttribute(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, PendingInsertion>,\n): boolean {\n if (isReactFragment(openingElement, fragmentContext)) {\n return false;\n }\n\n const elementName = getJSXName(openingElement.name);\n\n if (!isHtmlElement(elementName)) {\n return false;\n }\n\n if (ignoredComponents.includes(componentName) || ignoredComponents.includes(elementName)) {\n return true;\n }\n\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return true;\n }\n\n if (\n getExistingAttributeNames(openingElement).has(WEB_COMPONENT_NAME) ||\n insertionsByOffset.get(offset)?.attributeValues.has(WEB_COMPONENT_NAME)\n ) {\n return true;\n }\n\n getOrCreateInsertion(insertionsByOffset, offset).attributeValues.set(WEB_COMPONENT_NAME, componentName);\n\n return true;\n}\n\nfunction isHtmlElement(elementName: string): boolean {\n if (elementName === UNKNOWN_ELEMENT_NAME) {\n return false;\n }\n\n if (elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {\n return true;\n }\n\n return REACT_NATIVE_ELEMENTS.has(elementName);\n}\n\nfunction getOrCreateInsertion(insertionsByOffset: Map<number, PendingInsertion>, offset: number): PendingInsertion {\n let insertion = insertionsByOffset.get(offset);\n\n if (!insertion) {\n insertion = { offset, attributeValues: new Map() };\n insertionsByOffset.set(offset, insertion);\n }\n\n return insertion;\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n // HTML mode writes an empty component name for anonymous classes.\n if (value !== undefined) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"names":["WEB_ELEMENT_NAME","WEB_COMPONENT_NAME","WEB_SOURCE_FILE_NAME","isAstNode","isObjectLike","getComponentAnnotationAttributes"],"mappings":";;;;;;AAiBA,MAAM,oBAAA,GAAuB,SAAA;AAC7B,MAAM,qBAAA,uBAA4B,GAAA,CAAI;AAAA,EACpC,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,0BAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA;AAAA,EACA,mBAAA;AAAA,EACA,QAAA;AAAA,E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,aAA6C,EAAC;AAEpD,EAAA,KAAA,MAAW,QAAQ,mBAAA,EAAqB;AACtC,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA;AAEtC,IAAA,IAAI,UAAU,MAAA,EAAW;AACvB,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;;;;;;;;;;;;;"}
|
|
@@ -5,17 +5,38 @@ const componentAnnotationOxcAst = require('./component-annotation-oxc-ast.js');
|
|
|
5
5
|
const componentAnnotationOxcFragments = require('./component-annotation-oxc-fragments.js');
|
|
6
6
|
const core = require('@sentry/core');
|
|
7
7
|
|
|
8
|
-
function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
|
|
8
|
+
function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName, injectIntoHtml) {
|
|
9
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) {
|
|
13
13
|
for (const root of component.roots) {
|
|
14
|
-
|
|
14
|
+
if (injectIntoHtml) {
|
|
15
|
+
processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
16
|
+
} else {
|
|
17
|
+
processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
return componentAnnotationOxcJsx.toAttributeInsertions(insertionsByOffset);
|
|
18
22
|
}
|
|
23
|
+
function processHtmlJSX(code, node, componentName, ignoredComponents, fragmentContext, insertionsByOffset) {
|
|
24
|
+
if (componentAnnotationOxcJsx.isJSXElement(node) && componentAnnotationOxcJsx.addPendingHtmlAttribute(
|
|
25
|
+
code,
|
|
26
|
+
node.openingElement,
|
|
27
|
+
componentName,
|
|
28
|
+
ignoredComponents,
|
|
29
|
+
fragmentContext,
|
|
30
|
+
insertionsByOffset
|
|
31
|
+
)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const child of node.children ?? []) {
|
|
35
|
+
if (componentAnnotationOxcJsx.isJSXRoot(child)) {
|
|
36
|
+
processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
19
40
|
function getJSXRootsFromReturnArgument(argument) {
|
|
20
41
|
if (componentAnnotationOxcJsx.isJSXRoot(argument)) {
|
|
21
42
|
return [argument];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-annotation-oxc-walk.js","sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n 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,MA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EA,SAAS,WACP,IAAA,EACA,IAAA,EACA,eACA,iBAAA,EACA,eAAA,EACA,gBACA,kBAAA,EACM;AACN,EAAA,IAAIG,sCAAA,CAAa,IAAI,CAAA,EAAG;AACtB,IAAAC,8CAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA,CAAK,cAAA;AAAA,MACL,aAAA;AAAA,MACA,iBAAA;AAAA,MACA,eAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAIN,mCAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-walk.js","sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n addPendingHtmlAttribute,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-oxc-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { collectFragmentContext } from './component-annotation-oxc-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectOxcComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n injectIntoHtml: boolean,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n if (injectIntoHtml) {\n processHtmlJSX(code, root, component.name, ignoredComponents, fragmentContext, insertionsByOffset);\n } else {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction processHtmlJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (\n isJSXElement(node) &&\n addPendingHtmlAttribute(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n insertionsByOffset,\n )\n ) {\n return;\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processHtmlJSX(code, child, componentName, ignoredComponents, fragmentContext, insertionsByOffset);\n }\n }\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"names":["collectFragmentContext","toAttributeInsertions","isJSXElement","addPendingHtmlAttribute","isJSXRoot","isObj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AAA;AAAA,MACL,aAAA;AAAA,MACA,iBAAA;AAAA,MACA,eAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAIL,mCAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
|
|
@@ -59,22 +59,19 @@ function getMagicString(code, meta) {
|
|
|
59
59
|
}
|
|
60
60
|
return { magicString: new MagicString__default(code), isNative: false };
|
|
61
61
|
}
|
|
62
|
-
async function annotateWithOxcParser(code,
|
|
63
|
-
const idWithoutQueryAndHash = utils.stripQueryAndHashFromPath(id);
|
|
64
|
-
if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
62
|
+
async function annotateWithOxcParser(code, idWithoutQueryAndHash, ignoredComponents, parseAstAsync, injectIntoHtml, meta) {
|
|
67
63
|
const ast = await parseAstAsync(code, {
|
|
68
64
|
lang: idWithoutQueryAndHash.endsWith(".jsx") ? "jsx" : "tsx"
|
|
69
65
|
});
|
|
70
66
|
if (!componentAnnotationOxcAst.isAstNode(ast)) {
|
|
71
|
-
return
|
|
67
|
+
return null;
|
|
72
68
|
}
|
|
73
69
|
const insertions = componentAnnotationOxcWalk.collectOxcComponentAnnotationInsertions(
|
|
74
70
|
code,
|
|
75
71
|
ast,
|
|
76
72
|
ignoredComponents,
|
|
77
|
-
path__default.basename(idWithoutQueryAndHash)
|
|
73
|
+
path__default.basename(idWithoutQueryAndHash),
|
|
74
|
+
injectIntoHtml
|
|
78
75
|
);
|
|
79
76
|
if (insertions.length === 0) {
|
|
80
77
|
return null;
|
|
@@ -88,25 +85,37 @@ async function annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync,
|
|
|
88
85
|
}
|
|
89
86
|
return {
|
|
90
87
|
code: magicString.toString(),
|
|
88
|
+
// No `file`, because magic-string would then make `source` relative to it
|
|
89
|
+
// and drop the directory from `sources`.
|
|
91
90
|
map: magicString.generateMap?.({
|
|
92
|
-
file: id,
|
|
93
91
|
source: idWithoutQueryAndHash,
|
|
94
92
|
includeContent: true,
|
|
95
93
|
hires: true
|
|
96
94
|
})
|
|
97
95
|
};
|
|
98
96
|
}
|
|
99
|
-
function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
|
|
97
|
+
function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync, injectIntoHtml = false) {
|
|
100
98
|
return {
|
|
101
99
|
async transform(code, id, meta) {
|
|
100
|
+
const idWithoutQueryAndHash = utils.stripQueryAndHashFromPath(id);
|
|
101
|
+
if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
102
104
|
try {
|
|
103
105
|
const parseAstAsync = await getParseAstAsync();
|
|
104
106
|
if (!parseAstAsync) {
|
|
105
|
-
return
|
|
107
|
+
return null;
|
|
106
108
|
}
|
|
107
|
-
return await annotateWithOxcParser(
|
|
109
|
+
return await annotateWithOxcParser(
|
|
110
|
+
code,
|
|
111
|
+
idWithoutQueryAndHash,
|
|
112
|
+
ignoredComponents,
|
|
113
|
+
parseAstAsync,
|
|
114
|
+
injectIntoHtml,
|
|
115
|
+
meta
|
|
116
|
+
);
|
|
108
117
|
} catch {
|
|
109
|
-
return
|
|
118
|
+
return null;
|
|
110
119
|
}
|
|
111
120
|
}
|
|
112
121
|
};
|
|
@@ -1 +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
|
|
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 all JSX tag starts, because a miss skips the file.\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, '&').replace(/\"/g, '"');\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 idWithoutQueryAndHash: string,\n ignoredComponents: string[],\n parseAstAsync: ParseAstAsync,\n injectIntoHtml: boolean,\n meta?: ComponentAnnotationTransformMeta,\n): Promise<ComponentAnnotationTransformResult> {\n const ast = await parseAstAsync(code, {\n lang: idWithoutQueryAndHash.endsWith('.jsx') ? 'jsx' : 'tsx',\n });\n\n if (!isAstNode(ast)) {\n return null;\n }\n\n const insertions = collectOxcComponentAnnotationInsertions(\n code,\n ast,\n ignoredComponents,\n path.basename(idWithoutQueryAndHash),\n injectIntoHtml,\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 // No `file`, because magic-string would then make `source` relative to it\n // and drop the directory from `sources`.\n map: magicString.generateMap?.({\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 injectIntoHtml = false,\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 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 try {\n const parseAstAsync = await getParseAstAsync();\n\n if (!parseAstAsync) {\n return null;\n }\n\n return await annotateWithOxcParser(\n code,\n idWithoutQueryAndHash,\n ignoredComponents,\n parseAstAsync,\n injectIntoHtml,\n meta,\n );\n } catch {\n // Leave files the parser cannot read unchanged. The bundler reports the syntax error.\n return null;\n }\n },\n };\n}\n"],"names":["KNOWN_INCOMPATIBLE_PLUGINS","MagicString","isAstNode","collectOxcComponentAnnotationInsertions","path","stripQueryAndHashFromPath"],"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,IAAI,CAAA,CAAA,EAAI,IAAA,EAAM,EAAE,IAAA,EAAM,cAAA,EAAgB,OAAO,CAAA;AAElG,QAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,UAAA,MAAM,IAAI,KAAA,CAAM,MAAA,CAAO,CAAC,GAAG,OAAO,CAAA;AAAA,QACpC;AAEA,QAAA,OAAO,OAAA;AAAA,MACT,CAAA;AAAA,IACF,CAAC,CAAA,CACA,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,EACrB;AAEA,EAAA,OAAO,uBAAA;AACT;AAGA,MAAM,oBAAA,GAAuB,0DAAA;AAC7B,MAAM,eAAA,GAAkB,WAAA;AAExB,SAAS,iBAAiB,qBAAA,EAAw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;AAAA,EAClD;AAEA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,YAAY,QAAA,EAAS;AAAA;AAAA;AAAA,IAG3B,GAAA,EAAK,YAAY,WAAA,GAAc;AAAA,MAC7B,MAAA,EAAQ,qBAAA;AAAA,MACR,cAAA,EAAgB,IAAA;AAAA,MAChB,KAAA,EAAO;AAAA,KACR;AAAA,GACH;AACF;AAEO,SAAS,mCAAA,CACd,iBAAA,EACA,gBAAA,EACA,cAAA,GAAiB,KAAA,EAOjB;AACA,EAAA,OAAO;AAAA,IACL,MAAM,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI,IAAA,EAAM;AAC9B,MAAA,MAAM,qBAAA,GAAwBC,gCAA0B,EAAE,CAAA;AAE1D,MAAA,IACE,CAAC,qBAAA,IACD,CAAC,gBAAA,CAAiB,qBAAqB,CAAA,IACvC,CAAC,cAAA,CAAe,IAAI,CAAA,IACpB,0BAAA,CAA2B,qBAAqB,CAAA,EAChD;AACA,QAAA,OAAO,IAAA;AAAA,MACT;AAEA,MAAA,IAAI;AACF,QAAA,MAAM,aAAA,GAAgB,MAAM,gBAAA,EAAiB;AAE7C,QAAA,IAAI,CAAC,aAAA,EAAe;AAClB,UAAA,OAAO,IAAA;AAAA,QACT;AAEA,QAAA,OAAO,MAAM,qBAAA;AAAA,UACX,IAAA;AAAA,UACA,qBAAA;AAAA,UACA,iBAAA;AAAA,UACA,aAAA;AAAA,UACA,cAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF,CAAA,CAAA,MAAQ;AAEN,QAAA,OAAO,IAAA;AAAA,MACT;AAAA,IACF;AAAA,GACF;AACF;;;;;"}
|
package/build/cjs/core/index.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const core = require('@sentry/core');
|
|
4
3
|
const utils = require('./utils.js');
|
|
5
4
|
const glob = require('./glob.js');
|
|
6
5
|
const getCodeInjectionPosition = require('./get-code-injection-position.js');
|
|
6
|
+
const componentAnnotateHooks = require('./component-annotate-hooks.js');
|
|
7
7
|
const buildPluginManager = require('./build-plugin-manager.js');
|
|
8
8
|
const debugIdUpload = require('./debug-id-upload.js');
|
|
9
9
|
|
|
10
|
-
let babelAnnotationRuntimePromise;
|
|
11
|
-
function loadBabelAnnotationRuntime() {
|
|
12
|
-
if (!babelAnnotationRuntimePromise) {
|
|
13
|
-
babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), Promise.resolve().then(() => require('../babel-plugin/index.js'))]).then(
|
|
14
|
-
([babel, babelPlugin]) => {
|
|
15
|
-
return {
|
|
16
|
-
transformAsync: babel.transformAsync,
|
|
17
|
-
componentNameAnnotatePlugin: babelPlugin.default,
|
|
18
|
-
experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return babelAnnotationRuntimePromise;
|
|
24
|
-
}
|
|
25
10
|
function isJsFile(fileName) {
|
|
26
11
|
const cleanFileName = utils.stripQueryAndHashFromPath(fileName);
|
|
27
12
|
return [".js", ".mjs", ".cjs"].some((ext) => cleanFileName.endsWith(ext));
|
|
@@ -35,50 +20,6 @@ function shouldSkipCodeInjection(code, facadeModuleId) {
|
|
|
35
20
|
}
|
|
36
21
|
return false;
|
|
37
22
|
}
|
|
38
|
-
function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
|
|
39
|
-
return {
|
|
40
|
-
async transform(code, id) {
|
|
41
|
-
const idWithoutQueryAndHash = utils.stripQueryAndHashFromPath(id);
|
|
42
|
-
if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
if (![".jsx", ".tsx"].some((ending) => idWithoutQueryAndHash.endsWith(ending))) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const parserPlugins = [];
|
|
49
|
-
if (idWithoutQueryAndHash.endsWith(".jsx")) {
|
|
50
|
-
parserPlugins.push("jsx");
|
|
51
|
-
} else if (idWithoutQueryAndHash.endsWith(".tsx")) {
|
|
52
|
-
parserPlugins.push("jsx", "typescript");
|
|
53
|
-
}
|
|
54
|
-
const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } = await loadBabelAnnotationRuntime();
|
|
55
|
-
const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;
|
|
56
|
-
try {
|
|
57
|
-
const result = await transformAsync(code, {
|
|
58
|
-
plugins: [[plugin, { ignoredComponents }]],
|
|
59
|
-
filename: id,
|
|
60
|
-
sourceFileName: idWithoutQueryAndHash,
|
|
61
|
-
parserOpts: {
|
|
62
|
-
sourceType: "module",
|
|
63
|
-
allowAwaitOutsideFunction: true,
|
|
64
|
-
plugins: parserPlugins
|
|
65
|
-
},
|
|
66
|
-
generatorOpts: {
|
|
67
|
-
decoratorsBeforeExport: true
|
|
68
|
-
},
|
|
69
|
-
sourceMaps: true
|
|
70
|
-
});
|
|
71
|
-
return {
|
|
72
|
-
code: result?.code ?? code,
|
|
73
|
-
map: result?.map
|
|
74
|
-
};
|
|
75
|
-
} catch (e) {
|
|
76
|
-
core.debug.error(`Failed to apply react annotate plugin`, e);
|
|
77
|
-
}
|
|
78
|
-
return { code };
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
23
|
function getDebugIdSnippet(debugId) {
|
|
83
24
|
return new utils.CodeInjection(
|
|
84
25
|
`var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}");`
|
|
@@ -92,11 +33,11 @@ exports.replaceBooleanFlagsInCode = utils.replaceBooleanFlagsInCode;
|
|
|
92
33
|
exports.stringToUUID = utils.stringToUUID;
|
|
93
34
|
exports.globFiles = glob.globFiles;
|
|
94
35
|
exports.getCodeInjectionPosition = getCodeInjectionPosition.getCodeInjectionPosition;
|
|
36
|
+
exports.createComponentNameAnnotateHooks = componentAnnotateHooks.createComponentNameAnnotateHooks;
|
|
95
37
|
exports.createSentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager;
|
|
96
38
|
exports.addDebugIdToEmittedArtifacts = debugIdUpload.addDebugIdToEmittedArtifacts;
|
|
97
39
|
exports.createDebugIdUploadFunction = debugIdUpload.createDebugIdUploadFunction;
|
|
98
40
|
exports.stampDebugId = debugIdUpload.stampDebugId;
|
|
99
|
-
exports.createComponentNameAnnotateHooks = createComponentNameAnnotateHooks;
|
|
100
41
|
exports.getDebugIdSnippet = getDebugIdSnippet;
|
|
101
42
|
exports.isJsFile = isJsFile;
|
|
102
43
|
exports.shouldSkipCodeInjection = shouldSkipCodeInjection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\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\nexport { createComponentNameAnnotateHooks } from './component-annotate-hooks';\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","CodeInjection"],"mappings":";;;;;;;;;AAMO,SAAS,SAAS,QAAA,EAA2B;AAClD,EAAA,MAAM,aAAA,GAAgBA,gCAA0B,QAAQ,CAAA;AACxD,EAAA,OAAO,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,GAAA,KAAO,aAAA,CAAc,QAAA,CAAS,GAAG,CAAC,CAAA;AACxE;AAgBO,SAAS,uBAAA,CAAwB,MAAc,cAAA,EAAoD;AAExG,EAAA,IAAI,IAAA,CAAK,IAAA,EAAK,CAAE,MAAA,KAAW,CAAA,EAAG;AAC5B,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,kBAAkBA,+BAAA,CAA0B,cAAc,CAAA,CAAE,QAAA,CAAS,OAAO,CAAA,EAAG;AACjF,IAAA,OAAOC,0BAAoB,IAAI,CAAA;AAAA,EACjC;AAEA,EAAA,OAAO,KAAA;AACT;AAOO,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.2.0\";\n"],"names":[],"mappings":";;AAAO,MAAM,WAAA,GAAc;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const getCodeInjectionPosition = require('../core/get-code-injection-position.js');
|
|
4
|
+
const componentAnnotateHooks = require('../core/component-annotate-hooks.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.getCodeInjectionPosition = getCodeInjectionPosition.getCodeInjectionPosition;
|
|
9
|
+
exports.createComponentNameAnnotateHooks = componentAnnotateHooks.createComponentNameAnnotateHooks;
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|