@sentry/bundler-plugins 11.12.0 → 11.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
- package/build/cjs/babel-plugin/component-annotation.js +14 -32
- package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
- package/build/cjs/babel-plugin/constants.js +140 -122
- package/build/cjs/babel-plugin/constants.js.map +1 -1
- package/build/cjs/babel-plugin/experimental.js +204 -307
- package/build/cjs/babel-plugin/experimental.js.map +1 -1
- package/build/cjs/babel-plugin/index.js +315 -437
- package/build/cjs/babel-plugin/index.js.map +1 -1
- package/build/cjs/bun/index.js +81 -117
- package/build/cjs/bun/index.js.map +1 -1
- package/build/cjs/core/build-plugin-manager.js +626 -702
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/cli.js +134 -129
- package/build/cjs/core/cli.js.map +1 -1
- package/build/cjs/core/component-annotate-hooks.js +16 -27
- package/build/cjs/core/component-annotate-hooks.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc.js +68 -103
- package/build/cjs/core/component-annotation-oxc.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +223 -234
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/get-code-injection-position.js +59 -74
- package/build/cjs/core/get-code-injection-position.js.map +1 -1
- package/build/cjs/core/glob.js +9 -7
- package/build/cjs/core/glob.js.map +1 -1
- package/build/cjs/core/index.js +77 -61
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/logger.js +17 -26
- package/build/cjs/core/logger.js.map +1 -1
- package/build/cjs/core/options-mapping.js +95 -117
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +90 -105
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sentry/transports.js +92 -99
- package/build/cjs/core/sentry/transports.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +98 -61
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/upload-filter.js +41 -46
- package/build/cjs/core/upload-filter.js.map +1 -1
- package/build/cjs/core/utils.js +228 -221
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +4 -5
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +183 -213
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/loader-utils/index.js +5 -10
- package/build/cjs/rollup/debug-id-injection.js +22 -38
- package/build/cjs/rollup/debug-id-injection.js.map +1 -1
- package/build/cjs/rollup/debug-id-stamping.js +14 -24
- package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
- package/build/cjs/rollup/index.js +192 -246
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +151 -175
- package/build/cjs/rollup/source-map-handling.js.map +1 -1
- package/build/cjs/vite/index.js +19 -21
- package/build/cjs/vite/index.js.map +1 -1
- package/build/cjs/vite/source-map-hooks.js +112 -89
- package/build/cjs/vite/source-map-hooks.js.map +1 -1
- package/build/cjs/webpack/component-annotation-transform.js +20 -26
- package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
- package/build/cjs/webpack/index.js +271 -340
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/esm/_virtual/_rolldown/runtime.js +2 -0
- package/build/esm/babel-plugin/component-annotation.js +13 -29
- package/build/esm/babel-plugin/component-annotation.js.map +1 -1
- package/build/esm/babel-plugin/constants.js +140 -120
- package/build/esm/babel-plugin/constants.js.map +1 -1
- package/build/esm/babel-plugin/experimental.js +204 -305
- package/build/esm/babel-plugin/experimental.js.map +1 -1
- package/build/esm/babel-plugin/index.js +311 -434
- package/build/esm/babel-plugin/index.js.map +1 -1
- package/build/esm/bun/index.js +76 -101
- package/build/esm/bun/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +621 -683
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/cli.js +134 -127
- package/build/esm/core/cli.js.map +1 -1
- package/build/esm/core/component-annotate-hooks.js +16 -25
- package/build/esm/core/component-annotate-hooks.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js +9 -19
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-walk.js +61 -121
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/esm/core/component-annotation-oxc.js +65 -96
- package/build/esm/core/component-annotation-oxc.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +218 -213
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/get-code-injection-position.js +59 -72
- package/build/esm/core/get-code-injection-position.js.map +1 -1
- package/build/esm/core/glob.js +9 -5
- package/build/esm/core/glob.js.map +1 -1
- package/build/esm/core/index.js +62 -47
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/logger.js +17 -24
- package/build/esm/core/logger.js.map +1 -1
- package/build/esm/core/options-mapping.js +95 -115
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +89 -102
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sentry/transports.js +90 -83
- package/build/esm/core/sentry/transports.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +96 -59
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/upload-filter.js +39 -30
- package/build/esm/core/upload-filter.js.map +1 -1
- package/build/esm/core/utils.js +221 -211
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +4 -3
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +179 -197
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/loader-utils/index.js +4 -3
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/debug-id-injection.js +22 -36
- package/build/esm/rollup/debug-id-injection.js.map +1 -1
- package/build/esm/rollup/debug-id-stamping.js +14 -22
- package/build/esm/rollup/debug-id-stamping.js.map +1 -1
- package/build/esm/rollup/index.js +189 -226
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +149 -159
- package/build/esm/rollup/source-map-handling.js.map +1 -1
- package/build/esm/vite/index.js +19 -18
- package/build/esm/vite/index.js.map +1 -1
- package/build/esm/vite/source-map-hooks.js +109 -72
- package/build/esm/vite/source-map-hooks.js.map +1 -1
- package/build/esm/webpack/component-annotation-transform.js +17 -24
- package/build/esm/webpack/component-annotation-transform.js.map +1 -1
- package/build/esm/webpack/index.js +268 -322
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts +16 -5
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/cli.d.ts +6 -1
- package/build/types/core/cli.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +7 -4
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +3 -3
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +4 -3
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +10 -1
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +25 -1
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/utils.d.ts +4 -0
- package/build/types/core/utils.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts +2 -2
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +2 -2
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts.map +1 -1
- package/build/types/vite/index.d.ts +3 -3
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/source-map-hooks.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts +7 -3
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +8 -15
- package/build/cjs/loader-utils/index.js.map +0 -1
- package/build/esm/loader-utils/index.js.map +0 -1
|
@@ -1,126 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
-
const MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
|
|
14
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_constants = require("../babel-plugin/constants.js");
|
|
3
|
+
const require_utils = require("./utils.js");
|
|
4
|
+
const require_component_annotation_oxc_ast = require("./component-annotation-oxc-ast.js");
|
|
5
|
+
const require_component_annotation_oxc_walk = require("./component-annotation-oxc-walk.js");
|
|
6
|
+
let magic_string = require("magic-string");
|
|
7
|
+
magic_string = require_runtime.__toESM(magic_string);
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
node_path = require_runtime.__toESM(node_path);
|
|
10
|
+
// src/core/component-annotation-oxc.ts
|
|
15
11
|
let oxcParseAstAsyncPromise;
|
|
16
12
|
function getOxcParseAstAsync() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return oxcParseAstAsyncPromise;
|
|
13
|
+
if (!oxcParseAstAsyncPromise) oxcParseAstAsyncPromise = import("oxc-parser").then(({ parse }) => {
|
|
14
|
+
return async (code, { lang }) => {
|
|
15
|
+
const { program, errors } = await parse(`component.${lang}`, code, {
|
|
16
|
+
lang,
|
|
17
|
+
preserveParens: false
|
|
18
|
+
});
|
|
19
|
+
if (errors.length > 0) throw new Error(errors[0]?.message);
|
|
20
|
+
return program;
|
|
21
|
+
};
|
|
22
|
+
}).catch(() => null);
|
|
23
|
+
return oxcParseAstAsyncPromise;
|
|
29
24
|
}
|
|
30
25
|
const JSX_TAG_START_REGEXP = /<[$_\p{ID_Start}][$_\u200c\u200d\p{ID_Continue}.:-]*|<>/u;
|
|
31
26
|
const JSX_FILE_REGEXP = /\.[jt]sx$/;
|
|
32
27
|
function isAnnotationFile(idWithoutQueryAndHash) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);
|
|
28
|
+
if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) return false;
|
|
29
|
+
return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);
|
|
37
30
|
}
|
|
38
31
|
function shouldTryParse(code) {
|
|
39
|
-
|
|
32
|
+
return JSX_TAG_START_REGEXP.test(code);
|
|
40
33
|
}
|
|
41
34
|
function shouldSkipIncompatibleFile(idWithoutQueryAndHash) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
return require_constants.KNOWN_INCOMPATIBLE_PLUGINS.some((pluginName) => {
|
|
36
|
+
return idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) || idWithoutQueryAndHash.includes(`\\node_modules\\${pluginName}\\`);
|
|
37
|
+
});
|
|
45
38
|
}
|
|
46
39
|
function escapeAttributeValue(value) {
|
|
47
|
-
|
|
40
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
48
41
|
}
|
|
49
42
|
function makeAttributeText(code, insertionOffset, attributes) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return `${prefix}${attributeText}${suffix}`;
|
|
43
|
+
const previousCharIsWhitespace = insertionOffset > 0 && /\s/.test(code[insertionOffset - 1] ?? "");
|
|
44
|
+
const prefix = previousCharIsWhitespace ? "" : " ";
|
|
45
|
+
const suffix = previousCharIsWhitespace && code[insertionOffset] === "/" ? " " : "";
|
|
46
|
+
return `${prefix}${attributes.map(([name, value]) => `${name}="${escapeAttributeValue(value)}"`).join(" ")}${suffix}`;
|
|
55
47
|
}
|
|
56
48
|
function getMagicString(code, meta) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
if (meta?.magicString) return {
|
|
50
|
+
magicString: meta.magicString,
|
|
51
|
+
isNative: true
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
magicString: new magic_string.default(code),
|
|
55
|
+
isNative: false
|
|
56
|
+
};
|
|
61
57
|
}
|
|
62
58
|
async function annotateWithOxcParser(code, idWithoutQueryAndHash, ignoredComponents, parseAstAsync, injectIntoHtml, meta) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
const { magicString, isNative } = getMagicString(code, meta);
|
|
80
|
-
for (const insertion of insertions) {
|
|
81
|
-
magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));
|
|
82
|
-
}
|
|
83
|
-
if (isNative) {
|
|
84
|
-
return { code: magicString };
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
code: magicString.toString(),
|
|
88
|
-
// No `file`, because magic-string would then make `source` relative to it
|
|
89
|
-
// and drop the directory from `sources`.
|
|
90
|
-
map: magicString.generateMap?.({
|
|
91
|
-
source: idWithoutQueryAndHash,
|
|
92
|
-
includeContent: true,
|
|
93
|
-
hires: true
|
|
94
|
-
})
|
|
95
|
-
};
|
|
59
|
+
const ast = await parseAstAsync(code, { lang: idWithoutQueryAndHash.endsWith(".jsx") ? "jsx" : "tsx" });
|
|
60
|
+
if (!require_component_annotation_oxc_ast.isAstNode(ast)) return null;
|
|
61
|
+
const insertions = require_component_annotation_oxc_walk.collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, node_path.default.basename(idWithoutQueryAndHash), injectIntoHtml);
|
|
62
|
+
if (insertions.length === 0) return null;
|
|
63
|
+
const { magicString, isNative } = getMagicString(code, meta);
|
|
64
|
+
for (const insertion of insertions) magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));
|
|
65
|
+
if (isNative) return { code: magicString };
|
|
66
|
+
return {
|
|
67
|
+
code: magicString.toString(),
|
|
68
|
+
map: magicString.generateMap?.({
|
|
69
|
+
source: idWithoutQueryAndHash,
|
|
70
|
+
includeContent: true,
|
|
71
|
+
hires: true
|
|
72
|
+
})
|
|
73
|
+
};
|
|
96
74
|
}
|
|
97
75
|
function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync, injectIntoHtml = false) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return await annotateWithOxcParser(
|
|
110
|
-
code,
|
|
111
|
-
idWithoutQueryAndHash,
|
|
112
|
-
ignoredComponents,
|
|
113
|
-
parseAstAsync,
|
|
114
|
-
injectIntoHtml,
|
|
115
|
-
meta
|
|
116
|
-
);
|
|
117
|
-
} catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
76
|
+
return { async transform(code, id, meta) {
|
|
77
|
+
const idWithoutQueryAndHash = require_utils.stripQueryAndHashFromPath(id);
|
|
78
|
+
if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) return null;
|
|
79
|
+
try {
|
|
80
|
+
const parseAstAsync = await getParseAstAsync();
|
|
81
|
+
if (!parseAstAsync) return null;
|
|
82
|
+
return await annotateWithOxcParser(code, idWithoutQueryAndHash, ignoredComponents, parseAstAsync, injectIntoHtml, meta);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
} };
|
|
122
87
|
}
|
|
123
|
-
|
|
124
88
|
exports.createOxcComponentNameAnnotateHooks = createOxcComponentNameAnnotateHooks;
|
|
125
89
|
exports.getOxcParseAstAsync = getOxcParseAstAsync;
|
|
126
|
-
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=component-annotation-oxc.js.map
|
|
@@ -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 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"],"
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc.js","names":["KNOWN_INCOMPATIBLE_PLUGINS","MagicString","isAstNode","collectOxcComponentAnnotationInsertions","path","stripQueryAndHashFromPath"],"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"],"mappings":"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"}
|