@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/cache.js +7 -0
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +35 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +230 -89
- package/esm/eval/broker.js.map +1 -1
- package/esm/eval/protocol.js.map +1 -1
- package/esm/eval/runner.js +143 -24
- package/esm/eval/runner.js.map +1 -1
- package/esm/module.js +70 -43
- package/esm/module.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +35 -20
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +48 -2
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +57 -45
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +33 -4
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform.js +3 -1
- package/esm/transform.js.map +1 -1
- package/esm/utils/EventEmitter.js +42 -9
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
- package/esm/utils/applyOxcProcessors/displayName.js +93 -0
- package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/shared.js +29 -0
- package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
- package/esm/utils/applyOxcProcessors/types.js +2 -0
- package/esm/utils/applyOxcProcessors/types.js.map +1 -0
- package/esm/utils/applyOxcProcessors.js +1 -1216
- package/esm/utils/applyOxcProcessors.js.map +1 -1
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
- package/esm/utils/collectOxcRuntime/types.js +2 -0
- package/esm/utils/collectOxcRuntime/types.js.map +1 -0
- package/esm/utils/collectOxcRuntime.js +5 -193
- package/esm/utils/collectOxcRuntime.js.map +1 -1
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
- package/esm/utils/nativeResolver.js +93 -0
- package/esm/utils/nativeResolver.js.map +1 -0
- package/esm/utils/oxc/ast.js +28 -0
- package/esm/utils/oxc/ast.js.map +1 -0
- package/esm/utils/oxc/parse.js +3 -0
- package/esm/utils/oxc/parse.js.map +1 -0
- package/esm/utils/oxc/replacements.js +14 -0
- package/esm/utils/oxc/replacements.js.map +1 -0
- package/esm/utils/oxc/sourceLocations.js +59 -0
- package/esm/utils/oxc/sourceLocations.js.map +1 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
- package/esm/utils/oxcPreevalStage/processors.js +17 -0
- package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
- package/esm/utils/oxcPreevalStage/types.js +2 -0
- package/esm/utils/oxcPreevalStage/types.js.map +1 -0
- package/esm/utils/oxcPreevalStage.js +17 -73
- package/esm/utils/oxcPreevalStage.js.map +1 -1
- package/esm/utils/oxcPreevalTransforms.js +12 -1
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +3 -3
- package/esm/utils/resolveWithConditions.js.map +1 -1
- package/package.json +4 -3
- package/types/cache.js +8 -0
- package/types/debug/fileReporter.js +46 -1
- package/types/eval/broker.d.ts +6 -2
- package/types/eval/broker.js +244 -95
- package/types/eval/protocol.d.ts +15 -1
- package/types/module.d.ts +4 -1
- package/types/module.js +97 -48
- package/types/transform/Entrypoint.types.d.ts +3 -0
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +49 -2
- package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
- package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
- package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
- package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +63 -49
- package/types/transform/helpers/loadWywOptions.js +23 -3
- package/types/transform.js +3 -1
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +44 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
- package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
- package/types/utils/applyOxcProcessors/displayName.js +113 -0
- package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
- package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
- package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
- package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
- package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
- package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
- package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
- package/types/utils/applyOxcProcessors/shared.js +37 -0
- package/types/utils/applyOxcProcessors/types.d.ts +88 -0
- package/types/utils/applyOxcProcessors/types.js +1 -0
- package/types/utils/applyOxcProcessors.d.ts +1 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
- package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
- package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
- package/types/utils/collectOxcRuntime/types.d.ts +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +2 -12
- package/types/utils/collectOxcRuntime.js +5 -224
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
- package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
- package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
- package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
- package/types/utils/collectOxcTemplateDependencies.js +3 -1580
- package/types/utils/nativeResolver.d.ts +13 -0
- package/types/utils/nativeResolver.js +91 -0
- package/types/utils/oxc/ast.d.ts +4 -0
- package/types/utils/oxc/ast.js +37 -0
- package/types/utils/oxc/parse.d.ts +3 -0
- package/types/utils/oxc/parse.js +2 -0
- package/types/utils/oxc/replacements.d.ts +12 -0
- package/types/utils/oxc/replacements.js +18 -0
- package/types/utils/oxc/sourceLocations.d.ts +5 -0
- package/types/utils/oxc/sourceLocations.js +63 -0
- package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
- package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
- package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
- package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
- package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
- package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
- package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
- package/types/utils/oxcPreevalStage/processors.js +16 -0
- package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
- package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
- package/types/utils/oxcPreevalStage/types.d.ts +22 -0
- package/types/utils/oxcPreevalStage/types.js +1 -0
- package/types/utils/oxcPreevalStage.d.ts +2 -18
- package/types/utils/oxcPreevalStage.js +17 -79
- package/types/utils/oxcPreevalTransforms.js +14 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { dirname, isAbsolute, resolve as resolvePath } from "path";
|
|
3
|
+
import { oxcShaker } from "../../../shaker.js";
|
|
4
|
+
import { getOxcNodeChildren } from "../../../utils/oxc/ast.js";
|
|
5
|
+
import { stripQueryAndHash } from "../../../utils/parseRequest.js";
|
|
6
|
+
import { hashStaticContent, getStaticMetadataPreevalResult } from "./cache.js";
|
|
7
|
+
import { resolveDependency } from "./dependencies.js";
|
|
8
|
+
import { parseProgram } from "./environment.js";
|
|
9
|
+
import { findExportTarget } from "./exportTargets.js";
|
|
10
|
+
import { findTopLevelConstExpression, functionReturnExpression, isTopLevelFunctionOrClass } from "./programAnalysis.js";
|
|
11
|
+
import { collectWYWMetaExtendsExpressionsDeep, isStaticMetaObjectExpression } from "./processorStaticModel.js";
|
|
12
|
+
import { collectImportBindings, isSafeStaticExpression, unwrapExpression } from "./staticExpression.js";
|
|
13
|
+
import { rootIdentifierName } from "./staticExpressionDependencies.js";
|
|
14
|
+
export const isKnownOpaqueRuntimeWrapperImport = (binding) => {
|
|
15
|
+
if (!binding) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return binding.imported === "observer" && (binding.source === "mobx-react" || binding.source === "mobx-react-lite");
|
|
19
|
+
};
|
|
20
|
+
export const isKnownOpaqueRuntimeWrapperCallee = (expr, imports) => {
|
|
21
|
+
const callee = unwrapExpression(expr);
|
|
22
|
+
if (callee.type === "Identifier") {
|
|
23
|
+
return isKnownOpaqueRuntimeWrapperImport(imports.get(callee.name));
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
};
|
|
27
|
+
export const isKnownOpaqueRuntimeImportSource = (source) => /\.svg(?:$|[?#])/.test(source);
|
|
28
|
+
export const isKnownExternalRuntimeComponentImportSource = (source) => source.startsWith("@radix-ui/react-");
|
|
29
|
+
export const isOpaqueRuntimeComponentExpression = (program, expr, opaqueImportNames = new Set(), seen = new Set()) => {
|
|
30
|
+
const imports = collectImportBindings(program, { includeNamespace: true });
|
|
31
|
+
const unwrapped = unwrapExpression(expr);
|
|
32
|
+
if (isStaticMetaObjectExpression(unwrapped)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (unwrapped.type === "ArrowFunctionExpression" || unwrapped.type === "FunctionExpression" || unwrapped.type === "ClassExpression") {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (unwrapped.type === "CallExpression" && unwrapped.arguments.length === 1 && isKnownOpaqueRuntimeWrapperCallee(unwrapped.callee, imports)) {
|
|
39
|
+
const [argument] = unwrapped.arguments;
|
|
40
|
+
return argument.type !== "SpreadElement" ? isOpaqueRuntimeComponentExpression(program, argument, opaqueImportNames, seen) : false;
|
|
41
|
+
}
|
|
42
|
+
if (unwrapped.type === "CallExpression" && unwrapped.callee.type === "Identifier") {
|
|
43
|
+
const allowParams = unwrapped.arguments.every((argument) => argument.type !== "SpreadElement" && isSafeStaticExpression(argument));
|
|
44
|
+
const local = findTopLevelConstExpression(program, unwrapped.callee.name);
|
|
45
|
+
const returned = local ? functionReturnExpression(local, { allowParams }) : null;
|
|
46
|
+
return returned ? isOpaqueRuntimeComponentExpression(program, returned, opaqueImportNames, seen) : false;
|
|
47
|
+
}
|
|
48
|
+
if (unwrapped.type === "MemberExpression" && !unwrapped.computed) {
|
|
49
|
+
const name = rootIdentifierName(unwrapped);
|
|
50
|
+
const imported = name ? imports.get(name) : undefined;
|
|
51
|
+
return !!name && !!imported && (opaqueImportNames.has(name) || isKnownExternalRuntimeComponentImportSource(imported.source));
|
|
52
|
+
}
|
|
53
|
+
if (unwrapped.type !== "Identifier") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const { name } = unwrapped;
|
|
57
|
+
if (seen.has(name)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
seen.add(name);
|
|
61
|
+
const imported = imports.get(name);
|
|
62
|
+
if (imported) {
|
|
63
|
+
return opaqueImportNames.has(name) || isKnownOpaqueRuntimeImportSource(imported.source) || isKnownExternalRuntimeComponentImportSource(imported.source);
|
|
64
|
+
}
|
|
65
|
+
if (isTopLevelFunctionOrClass(program, name)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const local = findTopLevelConstExpression(program, name);
|
|
69
|
+
return local ? isOpaqueRuntimeComponentExpression(program, local, opaqueImportNames, seen) : false;
|
|
70
|
+
};
|
|
71
|
+
export const collectOpaqueRuntimeReferenceNames = (program, expr, names, seenHelpers = new Set()) => {
|
|
72
|
+
const unwrapped = unwrapExpression(expr);
|
|
73
|
+
if (unwrapped.type === "CallExpression" && unwrapped.callee.type === "Identifier") {
|
|
74
|
+
const allowParams = unwrapped.arguments.every((argument) => argument.type !== "SpreadElement" && isSafeStaticExpression(argument));
|
|
75
|
+
if (seenHelpers.has(unwrapped.callee.name)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const local = findTopLevelConstExpression(program, unwrapped.callee.name);
|
|
79
|
+
const returned = local ? functionReturnExpression(local, { allowParams }) : null;
|
|
80
|
+
if (returned) {
|
|
81
|
+
seenHelpers.add(unwrapped.callee.name);
|
|
82
|
+
collectOpaqueRuntimeReferenceNames(program, returned, names, seenHelpers);
|
|
83
|
+
seenHelpers.delete(unwrapped.callee.name);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (unwrapped.type === "Identifier") {
|
|
88
|
+
names.add(unwrapped.name);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
getOxcNodeChildren(unwrapped).forEach((child) => collectOpaqueRuntimeReferenceNames(program, child, names, seenHelpers));
|
|
92
|
+
};
|
|
93
|
+
export function* resolveExportAsOpaqueRuntimeImport(action, filename, exportedName, stack, memo) {
|
|
94
|
+
const memoKey = `${filename}\0${exportedName}`;
|
|
95
|
+
if (memo.has(memoKey)) {
|
|
96
|
+
return memo.get(memoKey) ?? null;
|
|
97
|
+
}
|
|
98
|
+
if (stack.has(memoKey)) {
|
|
99
|
+
memo.set(memoKey, null);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
stack.add(memoKey);
|
|
103
|
+
const loadedAndParsed = action.services.loadAndParseFn(action.services, filename, undefined, action.services.log);
|
|
104
|
+
if (loadedAndParsed.evaluator === "ignored" || loadedAndParsed.evaluator !== oxcShaker) {
|
|
105
|
+
memo.set(memoKey, null);
|
|
106
|
+
stack.delete(memoKey);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const codeHash = hashStaticContent(loadedAndParsed.code);
|
|
110
|
+
const preevalResult = getStaticMetadataPreevalResult(action, filename, loadedAndParsed.code, codeHash);
|
|
111
|
+
const program = parseProgram(preevalResult?.baseCode ?? loadedAndParsed.code, filename);
|
|
112
|
+
const target = findExportTarget(program, exportedName);
|
|
113
|
+
if (!target) {
|
|
114
|
+
memo.set(memoKey, null);
|
|
115
|
+
stack.delete(memoKey);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (target.kind === "import") {
|
|
119
|
+
const resolved = yield* resolveImportAsOpaqueRuntime(action, filename, target, stack, memo);
|
|
120
|
+
memo.set(memoKey, resolved);
|
|
121
|
+
stack.delete(memoKey);
|
|
122
|
+
return resolved;
|
|
123
|
+
}
|
|
124
|
+
if (isOpaqueRuntimeComponentExpression(program, target.expression)) {
|
|
125
|
+
const resolved = {
|
|
126
|
+
dependencies: [filename],
|
|
127
|
+
names: new Set()
|
|
128
|
+
};
|
|
129
|
+
memo.set(memoKey, resolved);
|
|
130
|
+
stack.delete(memoKey);
|
|
131
|
+
return resolved;
|
|
132
|
+
}
|
|
133
|
+
const imports = collectImportBindings(program, { includeNamespace: true });
|
|
134
|
+
const referencedNames = new Set();
|
|
135
|
+
collectOpaqueRuntimeReferenceNames(program, target.expression, referencedNames);
|
|
136
|
+
const opaqueImportNames = new Set();
|
|
137
|
+
const dependencies = new Set([filename]);
|
|
138
|
+
for (const name of referencedNames) {
|
|
139
|
+
const binding = imports.get(name);
|
|
140
|
+
if (!binding || binding.source === "react" || isKnownOpaqueRuntimeWrapperImport(binding)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const proof = yield* resolveImportAsOpaqueRuntime(action, filename, binding, stack, memo);
|
|
144
|
+
if (!proof) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
opaqueImportNames.add(name);
|
|
148
|
+
proof.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
149
|
+
}
|
|
150
|
+
const resolved = isOpaqueRuntimeComponentExpression(program, target.expression, opaqueImportNames) ? {
|
|
151
|
+
dependencies: [...dependencies],
|
|
152
|
+
names: opaqueImportNames
|
|
153
|
+
} : null;
|
|
154
|
+
memo.set(memoKey, resolved);
|
|
155
|
+
stack.delete(memoKey);
|
|
156
|
+
return resolved;
|
|
157
|
+
}
|
|
158
|
+
export const knownOpaqueRuntimeSourceDependency = (importer, source) => {
|
|
159
|
+
if (!isKnownOpaqueRuntimeImportSource(source)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
const request = stripQueryAndHash(source);
|
|
163
|
+
if (isAbsolute(request)) {
|
|
164
|
+
return request;
|
|
165
|
+
}
|
|
166
|
+
return request.startsWith(".") ? resolvePath(dirname(importer), request) : null;
|
|
167
|
+
};
|
|
168
|
+
export function* resolveImportAsOpaqueRuntime(action, importer, binding, stack, memo) {
|
|
169
|
+
const knownSourceDependency = knownOpaqueRuntimeSourceDependency(importer, binding.source);
|
|
170
|
+
if (knownSourceDependency) {
|
|
171
|
+
return {
|
|
172
|
+
dependencies: [knownSourceDependency],
|
|
173
|
+
names: new Set()
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (isKnownExternalRuntimeComponentImportSource(binding.source)) {
|
|
177
|
+
return {
|
|
178
|
+
dependencies: [],
|
|
179
|
+
names: new Set()
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const dependency = yield* resolveDependency(action, importer, binding.source, binding.imported);
|
|
183
|
+
if (!dependency?.resolved) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (isKnownOpaqueRuntimeImportSource(binding.source) || isKnownOpaqueRuntimeImportSource(dependency.resolved)) {
|
|
187
|
+
return {
|
|
188
|
+
dependencies: [dependency.resolved],
|
|
189
|
+
names: new Set()
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const resolved = yield* resolveExportAsOpaqueRuntimeImport(action, dependency.resolved, binding.imported, stack, memo);
|
|
193
|
+
return resolved ? {
|
|
194
|
+
dependencies: [dependency.resolved, ...resolved.dependencies.filter((item) => item !== dependency.resolved)],
|
|
195
|
+
names: resolved.names
|
|
196
|
+
} : null;
|
|
197
|
+
}
|
|
198
|
+
export function* collectOpaqueRuntimeImportProof(action, filename, program, expression) {
|
|
199
|
+
const extendsExpressions = collectWYWMetaExtendsExpressionsDeep(program, expression);
|
|
200
|
+
if (extendsExpressions.length === 0) {
|
|
201
|
+
return {
|
|
202
|
+
dependencies: [],
|
|
203
|
+
names: new Set()
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const imports = collectImportBindings(program, { includeNamespace: true });
|
|
207
|
+
const referencedNames = new Set();
|
|
208
|
+
extendsExpressions.forEach((extendsExpression) => collectOpaqueRuntimeReferenceNames(program, extendsExpression, referencedNames));
|
|
209
|
+
const dependencies = new Set();
|
|
210
|
+
const names = new Set();
|
|
211
|
+
const memo = new Map();
|
|
212
|
+
for (const name of referencedNames) {
|
|
213
|
+
const binding = imports.get(name);
|
|
214
|
+
if (!binding || binding.source === "react") {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const proof = yield* resolveImportAsOpaqueRuntime(action, filename, binding, new Set(), memo);
|
|
218
|
+
if (!proof) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
names.add(name);
|
|
222
|
+
proof.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
dependencies: [...dependencies],
|
|
226
|
+
names
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=opaqueRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,SAAS,YAAY,WAAW,mBAAmB;AAI5D,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAElC,SAAS,mBAAmB,sCAAsC;AAClE,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SACE,6BACA,0BACA,iCACK;AACP,SACE,sCACA,oCACK;AACP,SACE,uBACA,wBACA,wBACK;AACP,SAAS,0BAA0B;AAGnC,OAAO,MAAM,qCACX,YACY;AACZ,KA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Q,OAAO,IAChD,iCAAiC,WAAW,SAAS,EACrD;AACA,SAAO;GACL,cAAc,CAAC,WAAW,SAAS;GACnC,OAAO,IAAI,KAAK;GACjB;;CAGH,MAAM,WAAW,OAAO,mCACtB,QACA,WAAW,UACX,QAAQ,UACR,OACA,KACD;AACD,QAAO,WACH;EACE,cAAc,CACZ,WAAW,UACX,GAAG,SAAS,aAAa,QACtB,SAAS,SAAS,WAAW,SAC/B,CACF;EACD,OAAO,SAAS;EACjB,GACD;;AAGN,OAAO,UAAU,gCACf,QACA,UACA,SACA,YAC2C;CAC3C,MAAM,qBAAqB,qCACzB,SACA,WACD;AACD,KAAI,mBAAmB,WAAW,GAAG;AACnC,SAAO;GACL,cAAc,EAAE;GAChB,OAAO,IAAI,KAAK;GACjB;;CAGH,MAAM,UAAU,sBAAsB,SAAS,EAAE,kBAAkB,MAAM,CAAC;CAC1E,MAAM,kBAAkB,IAAI,KAAa;AACzC,oBAAmB,SAAS,sBAC1B,mCACE,SACA,mBACA,gBACD,CACF;CAED,MAAM,eAAe,IAAI,KAAa;CACtC,MAAM,QAAQ,IAAI,KAAa;CAC/B,MAAM,OAAO,IAAI,KAA8C;AAE/D,MAAK,MAAM,QAAQ,iBAAiB;EAClC,MAAM,UAAU,QAAQ,IAAI,KAAK;AACjC,MAAI,CAAC,WAAW,QAAQ,WAAW,SAAS;AAC1C;;EAGF,MAAM,QAAQ,OAAO,6BACnB,QACA,UACA,SACA,IAAI,KAAK,EACT,KACD;AACD,MAAI,CAAC,OAAO;AACV;;AAGF,QAAM,IAAI,KAAK;AACf,QAAM,aAAa,SAAS,eAAe,aAAa,IAAI,WAAW,CAAC;;AAG1E,QAAO;EACL,cAAc,CAAC,GAAG,aAAa;EAC/B;EACD","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/opaqueRuntime.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { dirname, isAbsolute, resolve as resolvePath } from 'path';\n\nimport type { Expression, Node, Program } from 'oxc-parser';\n\nimport { oxcShaker } from '../../../shaker';\nimport { getOxcNodeChildren } from '../../../utils/oxc/ast';\nimport { stripQueryAndHash } from '../../../utils/parseRequest';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport { hashStaticContent, getStaticMetadataPreevalResult } from './cache';\nimport { resolveDependency } from './dependencies';\nimport { parseProgram } from './environment';\nimport { findExportTarget } from './exportTargets';\nimport {\n findTopLevelConstExpression,\n functionReturnExpression,\n isTopLevelFunctionOrClass,\n} from './programAnalysis';\nimport {\n collectWYWMetaExtendsExpressionsDeep,\n isStaticMetaObjectExpression,\n} from './processorStaticModel';\nimport {\n collectImportBindings,\n isSafeStaticExpression,\n unwrapExpression,\n} from './staticExpression';\nimport { rootIdentifierName } from './staticExpressionDependencies';\nimport type { ImportBinding, OpaqueRuntimeImportProof } from './types';\n\nexport const isKnownOpaqueRuntimeWrapperImport = (\n binding: ImportBinding | undefined\n): boolean => {\n if (!binding) {\n return false;\n }\n\n return (\n binding.imported === 'observer' &&\n (binding.source === 'mobx-react' || binding.source === 'mobx-react-lite')\n );\n};\n\nexport const isKnownOpaqueRuntimeWrapperCallee = (\n expr: Node,\n imports: Map<string, ImportBinding>\n): boolean => {\n const callee = unwrapExpression(expr);\n if (callee.type === 'Identifier') {\n return isKnownOpaqueRuntimeWrapperImport(imports.get(callee.name));\n }\n\n return false;\n};\n\nexport const isKnownOpaqueRuntimeImportSource = (source: string): boolean =>\n /\\.svg(?:$|[?#])/.test(source);\n\nexport const isKnownExternalRuntimeComponentImportSource = (\n source: string\n): boolean => source.startsWith('@radix-ui/react-');\n\nexport const isOpaqueRuntimeComponentExpression = (\n program: Program,\n expr: Node,\n opaqueImportNames: Set<string> = new Set(),\n seen: Set<string> = new Set()\n): boolean => {\n const imports = collectImportBindings(program, { includeNamespace: true });\n const unwrapped = unwrapExpression(expr);\n\n if (isStaticMetaObjectExpression(unwrapped)) {\n return false;\n }\n\n if (\n unwrapped.type === 'ArrowFunctionExpression' ||\n unwrapped.type === 'FunctionExpression' ||\n unwrapped.type === 'ClassExpression'\n ) {\n return true;\n }\n\n if (\n unwrapped.type === 'CallExpression' &&\n unwrapped.arguments.length === 1 &&\n isKnownOpaqueRuntimeWrapperCallee(unwrapped.callee, imports)\n ) {\n const [argument] = unwrapped.arguments;\n return argument.type !== 'SpreadElement'\n ? isOpaqueRuntimeComponentExpression(\n program,\n argument,\n opaqueImportNames,\n seen\n )\n : false;\n }\n\n if (\n unwrapped.type === 'CallExpression' &&\n unwrapped.callee.type === 'Identifier'\n ) {\n const allowParams = unwrapped.arguments.every(\n (argument) =>\n argument.type !== 'SpreadElement' && isSafeStaticExpression(argument)\n );\n const local = findTopLevelConstExpression(program, unwrapped.callee.name);\n const returned = local\n ? functionReturnExpression(local, { allowParams })\n : null;\n return returned\n ? isOpaqueRuntimeComponentExpression(\n program,\n returned,\n opaqueImportNames,\n seen\n )\n : false;\n }\n\n if (unwrapped.type === 'MemberExpression' && !unwrapped.computed) {\n const name = rootIdentifierName(unwrapped);\n const imported = name ? imports.get(name) : undefined;\n return (\n !!name &&\n !!imported &&\n (opaqueImportNames.has(name) ||\n isKnownExternalRuntimeComponentImportSource(imported.source))\n );\n }\n\n if (unwrapped.type !== 'Identifier') {\n return false;\n }\n\n const { name } = unwrapped;\n if (seen.has(name)) {\n return false;\n }\n seen.add(name);\n\n const imported = imports.get(name);\n if (imported) {\n return (\n opaqueImportNames.has(name) ||\n isKnownOpaqueRuntimeImportSource(imported.source) ||\n isKnownExternalRuntimeComponentImportSource(imported.source)\n );\n }\n\n if (isTopLevelFunctionOrClass(program, name)) {\n return true;\n }\n\n const local = findTopLevelConstExpression(program, name);\n return local\n ? isOpaqueRuntimeComponentExpression(\n program,\n local,\n opaqueImportNames,\n seen\n )\n : false;\n};\n\nexport const collectOpaqueRuntimeReferenceNames = (\n program: Program,\n expr: Node,\n names: Set<string>,\n seenHelpers: Set<string> = new Set()\n): void => {\n const unwrapped = unwrapExpression(expr);\n\n if (\n unwrapped.type === 'CallExpression' &&\n unwrapped.callee.type === 'Identifier'\n ) {\n const allowParams = unwrapped.arguments.every(\n (argument) =>\n argument.type !== 'SpreadElement' && isSafeStaticExpression(argument)\n );\n if (seenHelpers.has(unwrapped.callee.name)) {\n return;\n }\n\n const local = findTopLevelConstExpression(program, unwrapped.callee.name);\n const returned = local\n ? functionReturnExpression(local, { allowParams })\n : null;\n if (returned) {\n seenHelpers.add(unwrapped.callee.name);\n collectOpaqueRuntimeReferenceNames(program, returned, names, seenHelpers);\n seenHelpers.delete(unwrapped.callee.name);\n return;\n }\n }\n\n if (unwrapped.type === 'Identifier') {\n names.add(unwrapped.name);\n return;\n }\n\n getOxcNodeChildren(unwrapped).forEach((child) =>\n collectOpaqueRuntimeReferenceNames(program, child, names, seenHelpers)\n );\n};\nexport function* resolveExportAsOpaqueRuntimeImport(\n action: ITransformAction,\n filename: string,\n exportedName: string,\n stack: Set<string>,\n memo: Map<string, OpaqueRuntimeImportProof | null>\n): SyncScenarioFor<OpaqueRuntimeImportProof | null> {\n const memoKey = `${filename}\\0${exportedName}`;\n if (memo.has(memoKey)) {\n return memo.get(memoKey) ?? null;\n }\n\n if (stack.has(memoKey)) {\n memo.set(memoKey, null);\n return null;\n }\n\n stack.add(memoKey);\n\n const loadedAndParsed = action.services.loadAndParseFn(\n action.services,\n filename,\n undefined,\n action.services.log\n );\n if (\n loadedAndParsed.evaluator === 'ignored' ||\n loadedAndParsed.evaluator !== oxcShaker\n ) {\n memo.set(memoKey, null);\n stack.delete(memoKey);\n return null;\n }\n\n const codeHash = hashStaticContent(loadedAndParsed.code);\n const preevalResult = getStaticMetadataPreevalResult(\n action,\n filename,\n loadedAndParsed.code,\n codeHash\n );\n const program = parseProgram(\n preevalResult?.baseCode ?? loadedAndParsed.code,\n filename\n );\n const target = findExportTarget(program, exportedName);\n if (!target) {\n memo.set(memoKey, null);\n stack.delete(memoKey);\n return null;\n }\n\n if (target.kind === 'import') {\n const resolved = yield* resolveImportAsOpaqueRuntime(\n action,\n filename,\n target,\n stack,\n memo\n );\n memo.set(memoKey, resolved);\n stack.delete(memoKey);\n return resolved;\n }\n\n if (isOpaqueRuntimeComponentExpression(program, target.expression)) {\n const resolved = {\n dependencies: [filename],\n names: new Set<string>(),\n };\n memo.set(memoKey, resolved);\n stack.delete(memoKey);\n return resolved;\n }\n\n const imports = collectImportBindings(program, { includeNamespace: true });\n const referencedNames = new Set<string>();\n collectOpaqueRuntimeReferenceNames(\n program,\n target.expression,\n referencedNames\n );\n const opaqueImportNames = new Set<string>();\n const dependencies = new Set<string>([filename]);\n\n for (const name of referencedNames) {\n const binding = imports.get(name);\n if (\n !binding ||\n binding.source === 'react' ||\n isKnownOpaqueRuntimeWrapperImport(binding)\n ) {\n continue;\n }\n\n const proof = yield* resolveImportAsOpaqueRuntime(\n action,\n filename,\n binding,\n stack,\n memo\n );\n if (!proof) {\n continue;\n }\n\n opaqueImportNames.add(name);\n proof.dependencies.forEach((dependency) => dependencies.add(dependency));\n }\n\n const resolved = isOpaqueRuntimeComponentExpression(\n program,\n target.expression,\n opaqueImportNames\n )\n ? {\n dependencies: [...dependencies],\n names: opaqueImportNames,\n }\n : null;\n memo.set(memoKey, resolved);\n stack.delete(memoKey);\n return resolved;\n}\n\nexport const knownOpaqueRuntimeSourceDependency = (\n importer: string,\n source: string\n): string | null => {\n if (!isKnownOpaqueRuntimeImportSource(source)) {\n return null;\n }\n\n const request = stripQueryAndHash(source);\n if (isAbsolute(request)) {\n return request;\n }\n\n return request.startsWith('.')\n ? resolvePath(dirname(importer), request)\n : null;\n};\n\nexport function* resolveImportAsOpaqueRuntime(\n action: ITransformAction,\n importer: string,\n binding: Pick<ImportBinding, 'imported' | 'source'>,\n stack: Set<string>,\n memo: Map<string, OpaqueRuntimeImportProof | null>\n): SyncScenarioFor<OpaqueRuntimeImportProof | null> {\n const knownSourceDependency = knownOpaqueRuntimeSourceDependency(\n importer,\n binding.source\n );\n if (knownSourceDependency) {\n return {\n dependencies: [knownSourceDependency],\n names: new Set(),\n };\n }\n\n if (isKnownExternalRuntimeComponentImportSource(binding.source)) {\n return {\n dependencies: [],\n names: new Set(),\n };\n }\n\n const dependency = yield* resolveDependency(\n action,\n importer,\n binding.source,\n binding.imported\n );\n if (!dependency?.resolved) {\n return null;\n }\n\n if (\n isKnownOpaqueRuntimeImportSource(binding.source) ||\n isKnownOpaqueRuntimeImportSource(dependency.resolved)\n ) {\n return {\n dependencies: [dependency.resolved],\n names: new Set(),\n };\n }\n\n const resolved = yield* resolveExportAsOpaqueRuntimeImport(\n action,\n dependency.resolved,\n binding.imported,\n stack,\n memo\n );\n return resolved\n ? {\n dependencies: [\n dependency.resolved,\n ...resolved.dependencies.filter(\n (item) => item !== dependency.resolved\n ),\n ],\n names: resolved.names,\n }\n : null;\n}\n\nexport function* collectOpaqueRuntimeImportProof(\n action: ITransformAction,\n filename: string,\n program: Program,\n expression: Expression\n): SyncScenarioFor<OpaqueRuntimeImportProof> {\n const extendsExpressions = collectWYWMetaExtendsExpressionsDeep(\n program,\n expression\n );\n if (extendsExpressions.length === 0) {\n return {\n dependencies: [],\n names: new Set(),\n };\n }\n\n const imports = collectImportBindings(program, { includeNamespace: true });\n const referencedNames = new Set<string>();\n extendsExpressions.forEach((extendsExpression) =>\n collectOpaqueRuntimeReferenceNames(\n program,\n extendsExpression,\n referencedNames\n )\n );\n\n const dependencies = new Set<string>();\n const names = new Set<string>();\n const memo = new Map<string, OpaqueRuntimeImportProof | null>();\n\n for (const name of referencedNames) {\n const binding = imports.get(name);\n if (!binding || binding.source === 'react') {\n continue;\n }\n\n const proof = yield* resolveImportAsOpaqueRuntime(\n action,\n filename,\n binding,\n new Set(),\n memo\n );\n if (!proof) {\n continue;\n }\n\n names.add(name);\n proof.dependencies.forEach((dependency) => dependencies.add(dependency));\n }\n\n return {\n dependencies: [...dependencies],\n names,\n };\n}\n"],"file":"opaqueRuntime.js"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { evaluateOxcStaticExpressionAt, isOxcStaticSerializableValue } from "../../../utils/collectOxcTemplateDependencies.js";
|
|
2
|
+
import { getStaticMetadataPreevalResult } from "./cache.js";
|
|
3
|
+
import { debugStaticResolve, getStaticBindings, isLocalStaticMetadataFile, parseProgram } from "./environment.js";
|
|
4
|
+
import { findExportTarget } from "./exportTargets.js";
|
|
5
|
+
import { collectOpaqueRuntimeImportProof } from "./opaqueRuntime.js";
|
|
6
|
+
import { mergeStaticObjectAssignAliases, objectAssignAliasExpressionsForTarget, resolveObjectAssignAliasValues, resolveObjectAssignProcessorExpression } from "./objectAssign.js";
|
|
7
|
+
import { prepareProcessorTarget } from "./processorTarget.js";
|
|
8
|
+
import { collectProcessorImportLocals, isKnownProcessorClassValue, isProcessorClassValue, isSelectorOnlyProcessorValue, processorClassNameRuntimeValue, isStaticWYWMetaTreeValue, isStaticWYWMetaValue } from "./processorStaticModel.js";
|
|
9
|
+
import { bindStaticResolvedValue } from "./staticExpression.js";
|
|
10
|
+
export function* resolveProcessorStaticExport(action, filename, code, codeHash, program, exportedName, stack, memo, resolvers) {
|
|
11
|
+
const root = action.services.options.root ?? process.cwd();
|
|
12
|
+
if (!isLocalStaticMetadataFile(filename, root)) {
|
|
13
|
+
debugStaticResolve(action, {
|
|
14
|
+
exported: exportedName,
|
|
15
|
+
filename,
|
|
16
|
+
phase: "processor-metadata",
|
|
17
|
+
reason: "outside-root",
|
|
18
|
+
status: "rejected"
|
|
19
|
+
});
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (collectProcessorImportLocals(action, program, code, filename).size === 0) {
|
|
23
|
+
debugStaticResolve(action, {
|
|
24
|
+
exported: exportedName,
|
|
25
|
+
filename,
|
|
26
|
+
phase: "processor-metadata",
|
|
27
|
+
reason: "no-processor-imports",
|
|
28
|
+
status: "rejected"
|
|
29
|
+
});
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const preevalResult = getStaticMetadataPreevalResult(action, filename, code, codeHash);
|
|
33
|
+
if (!preevalResult) {
|
|
34
|
+
debugStaticResolve(action, {
|
|
35
|
+
exported: exportedName,
|
|
36
|
+
filename,
|
|
37
|
+
phase: "processor-metadata",
|
|
38
|
+
reason: "metadata-preeval-failed",
|
|
39
|
+
status: "rejected"
|
|
40
|
+
});
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!preevalResult.metadata) {
|
|
44
|
+
debugStaticResolve(action, {
|
|
45
|
+
exported: exportedName,
|
|
46
|
+
filename,
|
|
47
|
+
phase: "processor-metadata",
|
|
48
|
+
reason: "metadata-missing",
|
|
49
|
+
status: "rejected"
|
|
50
|
+
});
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const preevalCode = preevalResult.baseCode;
|
|
54
|
+
const preevalProgram = parseProgram(preevalCode, filename);
|
|
55
|
+
const target = findExportTarget(preevalProgram, exportedName);
|
|
56
|
+
if (!target || target.kind === "import") {
|
|
57
|
+
debugStaticResolve(action, {
|
|
58
|
+
exported: exportedName,
|
|
59
|
+
filename,
|
|
60
|
+
phase: "processor-metadata",
|
|
61
|
+
reason: "processor-target-missing",
|
|
62
|
+
status: "rejected"
|
|
63
|
+
});
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const processorObjectAssignAliases = objectAssignAliasExpressionsForTarget(preevalProgram, target);
|
|
67
|
+
const processorExpression = resolveObjectAssignProcessorExpression(preevalProgram, target.expression);
|
|
68
|
+
const opaqueRuntimeImportProof = yield* collectOpaqueRuntimeImportProof(action, filename, preevalProgram, processorExpression);
|
|
69
|
+
const preparedTarget = prepareProcessorTarget(preevalCode, filename, preevalProgram, target, exportedName, opaqueRuntimeImportProof.names);
|
|
70
|
+
if (!preparedTarget) {
|
|
71
|
+
debugStaticResolve(action, {
|
|
72
|
+
exported: exportedName,
|
|
73
|
+
filename,
|
|
74
|
+
phase: "processor-metadata",
|
|
75
|
+
reason: "unsupported-processor-expression",
|
|
76
|
+
status: "rejected"
|
|
77
|
+
});
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const env = new Map();
|
|
81
|
+
const dependencies = new Set([filename]);
|
|
82
|
+
const sideEffectDependencies = new Set();
|
|
83
|
+
opaqueRuntimeImportProof.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
84
|
+
for (const binding of preparedTarget.dependencies.imports) {
|
|
85
|
+
const resolved = yield* resolvers.resolveImportValue(action, filename, binding, stack, memo);
|
|
86
|
+
if (!resolved) {
|
|
87
|
+
debugStaticResolve(action, {
|
|
88
|
+
exported: exportedName,
|
|
89
|
+
filename,
|
|
90
|
+
imported: binding.imported,
|
|
91
|
+
phase: "processor-metadata",
|
|
92
|
+
reason: "resolve-failed",
|
|
93
|
+
source: binding.source,
|
|
94
|
+
status: "rejected"
|
|
95
|
+
});
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (!bindStaticResolvedValue(env, preparedTarget.expression, binding.local, resolved, { wrapNonCallable: true })) {
|
|
99
|
+
debugStaticResolve(action, {
|
|
100
|
+
exported: exportedName,
|
|
101
|
+
filename,
|
|
102
|
+
imported: binding.imported,
|
|
103
|
+
phase: "processor-metadata",
|
|
104
|
+
reason: "callable-usage-unsupported",
|
|
105
|
+
source: binding.source,
|
|
106
|
+
status: "rejected"
|
|
107
|
+
});
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
resolved.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
111
|
+
resolved.sideEffectDependencies?.forEach((dependency) => sideEffectDependencies.add(dependency));
|
|
112
|
+
}
|
|
113
|
+
const value = preparedTarget.evaluationCode && preparedTarget.evaluationSpan ? evaluateOxcStaticExpressionAt(preparedTarget.evaluationCode, filename, preparedTarget.evaluationSpan, env, getStaticBindings(action)) : evaluateOxcStaticExpressionAt(preevalCode, filename, {
|
|
114
|
+
end: preparedTarget.expression.end,
|
|
115
|
+
start: preparedTarget.expression.start
|
|
116
|
+
}, env, getStaticBindings(action));
|
|
117
|
+
if (!isOxcStaticSerializableValue(value)) {
|
|
118
|
+
debugStaticResolve(action, {
|
|
119
|
+
exported: exportedName,
|
|
120
|
+
filename,
|
|
121
|
+
phase: "processor-metadata",
|
|
122
|
+
reason: "non-serializable",
|
|
123
|
+
status: "rejected"
|
|
124
|
+
});
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
let resolvedValue = value;
|
|
128
|
+
if (processorObjectAssignAliases && isStaticWYWMetaValue(value)) {
|
|
129
|
+
const aliasValues = yield* resolveObjectAssignAliasValues(action, filename, preevalCode, preevalProgram, processorObjectAssignAliases, stack, memo, resolvers);
|
|
130
|
+
const mergedValue = aliasValues ? mergeStaticObjectAssignAliases(value, aliasValues.values) : null;
|
|
131
|
+
if (mergedValue) {
|
|
132
|
+
resolvedValue = mergedValue;
|
|
133
|
+
aliasValues?.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
134
|
+
aliasValues?.sideEffectDependencies.forEach((dependency) => sideEffectDependencies.add(dependency));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const isStaticMeta = isStaticWYWMetaValue(resolvedValue);
|
|
138
|
+
const isStaticMetaTree = !isStaticMeta && isStaticWYWMetaTreeValue(resolvedValue);
|
|
139
|
+
const processors = preevalResult.metadata.processors;
|
|
140
|
+
const processorClassNames = new Set(processors.map((processor) => processorClassNameRuntimeValue(processor)));
|
|
141
|
+
const isSelectorOnly = !isStaticMeta && !isStaticMetaTree && isSelectorOnlyProcessorValue(resolvedValue, processors, new Map());
|
|
142
|
+
const isSideEffectClassValue = !isStaticMeta && !isStaticMetaTree && !isSelectorOnly && (isProcessorClassValue(resolvedValue, processors, new Map()) || isKnownProcessorClassValue(resolvedValue, processorClassNames));
|
|
143
|
+
if (!isStaticMeta && !isStaticMetaTree && !isSelectorOnly && !isSideEffectClassValue) {
|
|
144
|
+
debugStaticResolve(action, {
|
|
145
|
+
exported: exportedName,
|
|
146
|
+
filename,
|
|
147
|
+
phase: "processor-metadata",
|
|
148
|
+
reason: "non-empty-css-artifact",
|
|
149
|
+
status: "rejected"
|
|
150
|
+
});
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
let resolvedReason;
|
|
154
|
+
if (preparedTarget.opaqueRuntimeBase) {
|
|
155
|
+
resolvedReason = "opaque-runtime-component";
|
|
156
|
+
} else if (isSideEffectClassValue) {
|
|
157
|
+
resolvedReason = "non-empty-css-artifact-side-effect";
|
|
158
|
+
}
|
|
159
|
+
debugStaticResolve(action, {
|
|
160
|
+
exported: exportedName,
|
|
161
|
+
filename,
|
|
162
|
+
phase: "processor-metadata",
|
|
163
|
+
reason: resolvedReason,
|
|
164
|
+
status: "resolved"
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
dependencies: [...dependencies],
|
|
168
|
+
sideEffectDependencies: isSideEffectClassValue ? [filename, ...sideEffectDependencies] : [...sideEffectDependencies],
|
|
169
|
+
value: resolvedValue
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=processorStaticExport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAIA,SACE,+BACA,oCACK;AAEP,SAAS,sCAAsC;AAC/C,SACE,oBACA,mBACA,2BACA,oBACK;AACP,SAAS,wBAAwB;AACjC,SAAS,uCAAuC;AAChD,SACE,gCACA,uCACA,gCACA,8CACK;AACP,SAAS,8BAA8B;AACvC,SACE,8BACA,4BACA,uBACA,8BACA,gCACA,0BACA,4BAEK;AACP,SAAS,+BAA+B;AAGxC,OAAO,UAAU,6BACf,QACA,UACA,MACA,UACA,SACA,cACA,OACA,MACA,WAC4C;CAC5C,MAAM,OAAO,OAAO,SAAS,QAAQ,QAAQ,QAAQ,KAAK;AAC1D,KAAI,CAAC,0BAA0B,UAAU,KAAK,EAAE;AAC9C,qBAAmB,QAAQ;GACzB,UAAU;GACV;GACA,OAAO;GACP,QAAQ;GACR,QAAQ;GACT,CAAC;AACF,SAAO;;AAGT,KACE,6BAA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L,MAAM,eAAe,qBAAqB,cAAc;CACxD,MAAM,mBACJ,CAAC,gBAAgB,yBAAyB,cAAc;CAC1D,MAAM,aAAa,cAAc,SAC9B;CACH,MAAM,sBAAsB,IAAI,IAC9B,WAAW,KAAK,cAAc,+BAA+B,UAAU,CAAC,CACzE;CACD,MAAM,iBACJ,CAAC,gBACD,CAAC,oBACD,6BAA6B,eAAe,YAAY,IAAI,KAAK,CAAC;CACpE,MAAM,yBACJ,CAAC,gBACD,CAAC,oBACD,CAAC,mBACA,sBAAsB,eAAe,YAAY,IAAI,KAAK,CAAC,IAC1D,2BAA2B,eAAe,oBAAoB;AAClE,KACE,CAAC,gBACD,CAAC,oBACD,CAAC,kBACD,CAAC,wBACD;AACA,qBAAmB,QAAQ;GACzB,UAAU;GACV;GACA,OAAO;GACP,QAAQ;GACR,QAAQ;GACT,CAAC;AACF,SAAO;;CAGT,IAAI;AACJ,KAAI,eAAe,mBAAmB;AACpC,mBAAiB;YACR,wBAAwB;AACjC,mBAAiB;;AAGnB,oBAAmB,QAAQ;EACzB,UAAU;EACV;EACA,OAAO;EACP,QAAQ;EACR,QAAQ;EACT,CAAC;AAEF,QAAO;EACL,cAAc,CAAC,GAAG,aAAa;EAC/B,wBAAwB,yBACpB,CAAC,UAAU,GAAG,uBAAuB,GACrC,CAAC,GAAG,uBAAuB;EAC/B,OAAO;EACR","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/processorStaticExport.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { Program } from 'oxc-parser';\n\nimport {\n evaluateOxcStaticExpressionAt,\n isOxcStaticSerializableValue,\n} from '../../../utils/collectOxcTemplateDependencies';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport { getStaticMetadataPreevalResult } from './cache';\nimport {\n debugStaticResolve,\n getStaticBindings,\n isLocalStaticMetadataFile,\n parseProgram,\n} from './environment';\nimport { findExportTarget } from './exportTargets';\nimport { collectOpaqueRuntimeImportProof } from './opaqueRuntime';\nimport {\n mergeStaticObjectAssignAliases,\n objectAssignAliasExpressionsForTarget,\n resolveObjectAssignAliasValues,\n resolveObjectAssignProcessorExpression,\n} from './objectAssign';\nimport { prepareProcessorTarget } from './processorTarget';\nimport {\n collectProcessorImportLocals,\n isKnownProcessorClassValue,\n isProcessorClassValue,\n isSelectorOnlyProcessorValue,\n processorClassNameRuntimeValue,\n isStaticWYWMetaTreeValue,\n isStaticWYWMetaValue,\n type StaticProcessorInstance,\n} from './processorStaticModel';\nimport { bindStaticResolvedValue } from './staticExpression';\nimport type { StaticExportResolverContext, StaticExportResult } from './types';\n\nexport function* resolveProcessorStaticExport(\n action: ITransformAction,\n filename: string,\n code: string,\n codeHash: string,\n program: Program,\n exportedName: string,\n stack: Set<string>,\n memo: Map<string, StaticExportResult | null>,\n resolvers: StaticExportResolverContext\n): SyncScenarioFor<StaticExportResult | null> {\n const root = action.services.options.root ?? process.cwd();\n if (!isLocalStaticMetadataFile(filename, root)) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'outside-root',\n status: 'rejected',\n });\n return null;\n }\n\n if (\n collectProcessorImportLocals(action, program, code, filename).size === 0\n ) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'no-processor-imports',\n status: 'rejected',\n });\n return null;\n }\n\n const preevalResult = getStaticMetadataPreevalResult(\n action,\n filename,\n code,\n codeHash\n );\n if (!preevalResult) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'metadata-preeval-failed',\n status: 'rejected',\n });\n return null;\n }\n\n if (!preevalResult.metadata) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'metadata-missing',\n status: 'rejected',\n });\n return null;\n }\n\n const preevalCode = preevalResult.baseCode;\n const preevalProgram = parseProgram(preevalCode, filename);\n const target = findExportTarget(preevalProgram, exportedName);\n if (!target || target.kind === 'import') {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'processor-target-missing',\n status: 'rejected',\n });\n return null;\n }\n\n const processorObjectAssignAliases = objectAssignAliasExpressionsForTarget(\n preevalProgram,\n target\n );\n const processorExpression = resolveObjectAssignProcessorExpression(\n preevalProgram,\n target.expression\n );\n const opaqueRuntimeImportProof = yield* collectOpaqueRuntimeImportProof(\n action,\n filename,\n preevalProgram,\n processorExpression\n );\n const preparedTarget = prepareProcessorTarget(\n preevalCode,\n filename,\n preevalProgram,\n target,\n exportedName,\n opaqueRuntimeImportProof.names\n );\n if (!preparedTarget) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'unsupported-processor-expression',\n status: 'rejected',\n });\n return null;\n }\n\n const env = new Map<string, unknown>();\n const dependencies = new Set<string>([filename]);\n const sideEffectDependencies = new Set<string>();\n opaqueRuntimeImportProof.dependencies.forEach((dependency) =>\n dependencies.add(dependency)\n );\n\n for (const binding of preparedTarget.dependencies.imports) {\n const resolved = yield* resolvers.resolveImportValue(\n action,\n filename,\n binding,\n stack,\n memo\n );\n if (!resolved) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n imported: binding.imported,\n phase: 'processor-metadata',\n reason: 'resolve-failed',\n source: binding.source,\n status: 'rejected',\n });\n return null;\n }\n\n if (\n !bindStaticResolvedValue(\n env,\n preparedTarget.expression,\n binding.local,\n resolved,\n {\n wrapNonCallable: true,\n }\n )\n ) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n imported: binding.imported,\n phase: 'processor-metadata',\n reason: 'callable-usage-unsupported',\n source: binding.source,\n status: 'rejected',\n });\n return null;\n }\n\n resolved.dependencies.forEach((dependency) => dependencies.add(dependency));\n resolved.sideEffectDependencies?.forEach((dependency) =>\n sideEffectDependencies.add(dependency)\n );\n }\n\n const value =\n preparedTarget.evaluationCode && preparedTarget.evaluationSpan\n ? evaluateOxcStaticExpressionAt(\n preparedTarget.evaluationCode,\n filename,\n preparedTarget.evaluationSpan,\n env,\n getStaticBindings(action)\n )\n : evaluateOxcStaticExpressionAt(\n preevalCode,\n filename,\n {\n end: preparedTarget.expression.end,\n start: preparedTarget.expression.start,\n },\n env,\n getStaticBindings(action)\n );\n if (!isOxcStaticSerializableValue(value)) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'non-serializable',\n status: 'rejected',\n });\n return null;\n }\n\n let resolvedValue = value;\n if (processorObjectAssignAliases && isStaticWYWMetaValue(value)) {\n const aliasValues = yield* resolveObjectAssignAliasValues(\n action,\n filename,\n preevalCode,\n preevalProgram,\n processorObjectAssignAliases,\n stack,\n memo,\n resolvers\n );\n const mergedValue = aliasValues\n ? mergeStaticObjectAssignAliases(value, aliasValues.values)\n : null;\n\n if (mergedValue) {\n resolvedValue = mergedValue;\n aliasValues?.dependencies.forEach((dependency) =>\n dependencies.add(dependency)\n );\n aliasValues?.sideEffectDependencies.forEach((dependency) =>\n sideEffectDependencies.add(dependency)\n );\n }\n }\n\n const isStaticMeta = isStaticWYWMetaValue(resolvedValue);\n const isStaticMetaTree =\n !isStaticMeta && isStaticWYWMetaTreeValue(resolvedValue);\n const processors = preevalResult.metadata\n .processors as unknown as StaticProcessorInstance[];\n const processorClassNames = new Set(\n processors.map((processor) => processorClassNameRuntimeValue(processor))\n );\n const isSelectorOnly =\n !isStaticMeta &&\n !isStaticMetaTree &&\n isSelectorOnlyProcessorValue(resolvedValue, processors, new Map());\n const isSideEffectClassValue =\n !isStaticMeta &&\n !isStaticMetaTree &&\n !isSelectorOnly &&\n (isProcessorClassValue(resolvedValue, processors, new Map()) ||\n isKnownProcessorClassValue(resolvedValue, processorClassNames));\n if (\n !isStaticMeta &&\n !isStaticMetaTree &&\n !isSelectorOnly &&\n !isSideEffectClassValue\n ) {\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: 'non-empty-css-artifact',\n status: 'rejected',\n });\n return null;\n }\n\n let resolvedReason: string | undefined;\n if (preparedTarget.opaqueRuntimeBase) {\n resolvedReason = 'opaque-runtime-component';\n } else if (isSideEffectClassValue) {\n resolvedReason = 'non-empty-css-artifact-side-effect';\n }\n\n debugStaticResolve(action, {\n exported: exportedName,\n filename,\n phase: 'processor-metadata',\n reason: resolvedReason,\n status: 'resolved',\n });\n\n return {\n dependencies: [...dependencies],\n sideEffectDependencies: isSideEffectClassValue\n ? [filename, ...sideEffectDependencies]\n : [...sideEffectDependencies],\n value: resolvedValue,\n };\n}\n"],"file":"processorStaticExport.js"}
|