@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 @@
|
|
|
1
|
+
export declare const normalizeRuntimeCode: (code: string, filename: string) => string;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import { parseSync } from 'oxc-parser';
|
|
3
|
+
const parseOxc = (code, filename) => {
|
|
4
|
+
const parsed = parseSync(filename, code, {
|
|
5
|
+
astType: filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',
|
|
6
|
+
range: true,
|
|
7
|
+
sourceType: 'module',
|
|
8
|
+
});
|
|
9
|
+
const fatalError = parsed.errors.find((error) => error.severity === 'Error');
|
|
10
|
+
if (fatalError) {
|
|
11
|
+
throw new Error(fatalError.message);
|
|
12
|
+
}
|
|
13
|
+
return parsed.program;
|
|
14
|
+
};
|
|
15
|
+
const applyReplacements = (code, replacements) => {
|
|
16
|
+
let result = code;
|
|
17
|
+
replacements
|
|
18
|
+
.sort((a, b) => b.start - a.start)
|
|
19
|
+
.forEach((replacement) => {
|
|
20
|
+
result =
|
|
21
|
+
result.slice(0, replacement.start) +
|
|
22
|
+
replacement.value +
|
|
23
|
+
result.slice(replacement.end);
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
const shouldTerminateWithSemicolon = (node, parent, key) => {
|
|
28
|
+
if (node.type === 'VariableDeclaration' && parent) {
|
|
29
|
+
if ((parent.type === 'ForStatement' ||
|
|
30
|
+
parent.type === 'ForInStatement' ||
|
|
31
|
+
parent.type === 'ForOfStatement') &&
|
|
32
|
+
key &&
|
|
33
|
+
['init', 'left'].includes(key)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (parent.type === 'ExportNamedDeclaration') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (node.type === 'ImportDeclaration' ||
|
|
41
|
+
node.type === 'ExpressionStatement' ||
|
|
42
|
+
node.type === 'ReturnStatement' ||
|
|
43
|
+
node.type === 'ThrowStatement' ||
|
|
44
|
+
node.type === 'VariableDeclaration') {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
48
|
+
if (node.declaration) {
|
|
49
|
+
return node.declaration.type === 'VariableDeclaration';
|
|
50
|
+
}
|
|
51
|
+
return Array.isArray(node.specifiers) && node.specifiers.length > 0;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
const getChildren = (node) => {
|
|
56
|
+
const result = [];
|
|
57
|
+
const record = node;
|
|
58
|
+
Object.keys(record).forEach((key) => {
|
|
59
|
+
if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const value = record[key];
|
|
63
|
+
if (value && typeof value === 'object' && 'type' in value) {
|
|
64
|
+
result.push({ key, node: value });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
value.forEach((item) => {
|
|
69
|
+
if (item && typeof item === 'object' && 'type' in item) {
|
|
70
|
+
result.push({ key, node: item });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
const getLineIndent = (code, offset) => {
|
|
78
|
+
const lineStart = code.lastIndexOf('\n', offset - 1) + 1;
|
|
79
|
+
let idx = lineStart;
|
|
80
|
+
while (idx < code.length && (code[idx] === ' ' || code[idx] === '\t')) {
|
|
81
|
+
idx += 1;
|
|
82
|
+
}
|
|
83
|
+
return code.slice(lineStart, idx).replace(/\t/g, ' ');
|
|
84
|
+
};
|
|
85
|
+
const isPlainObjectProperty = (property) => property.type === 'Property' &&
|
|
86
|
+
property.kind === 'init' &&
|
|
87
|
+
property.method !== true;
|
|
88
|
+
const isFormattableObjectExpression = (node) => node.type === 'ObjectExpression' &&
|
|
89
|
+
node.properties.every((property) => property.type === 'SpreadElement' || isPlainObjectProperty(property));
|
|
90
|
+
const hasNestedObjectValue = (node) => node.type === 'ObjectExpression' &&
|
|
91
|
+
node.properties.some((property) => isPlainObjectProperty(property) &&
|
|
92
|
+
property.value.type === 'ObjectExpression');
|
|
93
|
+
const printFormattedObjectExpression = (node, code, baseIndent) => {
|
|
94
|
+
if (node.type !== 'ObjectExpression' ||
|
|
95
|
+
node.properties.length === 0 ||
|
|
96
|
+
!isFormattableObjectExpression(node)) {
|
|
97
|
+
return code.slice(node.start, node.end);
|
|
98
|
+
}
|
|
99
|
+
const lines = node.properties.map((property) => {
|
|
100
|
+
if (property.type === 'SpreadElement') {
|
|
101
|
+
return `${baseIndent} ...${code.slice(property.argument.start, property.argument.end)}`;
|
|
102
|
+
}
|
|
103
|
+
const keySource = property.computed
|
|
104
|
+
? `[${code.slice(property.key.start, property.key.end)}]`
|
|
105
|
+
: code.slice(property.key.start, property.key.end);
|
|
106
|
+
const valueSource = property.value.type === 'ObjectExpression'
|
|
107
|
+
? printFormattedObjectExpression(property.value, code, `${baseIndent} `)
|
|
108
|
+
: code.slice(property.value.start, property.value.end).trim();
|
|
109
|
+
return `${baseIndent} ${keySource}: ${valueSource}`;
|
|
110
|
+
});
|
|
111
|
+
return `{\n${lines.join(',\n')}\n${baseIndent}}`;
|
|
112
|
+
};
|
|
113
|
+
const formatRuntimeObjectLiterals = (code, filename) => {
|
|
114
|
+
const replacements = [];
|
|
115
|
+
const walk = (node, parent = null) => {
|
|
116
|
+
if (node.type === 'ObjectExpression') {
|
|
117
|
+
const shouldFormat = (parent?.type === 'VariableDeclarator' && hasNestedObjectValue(node)) ||
|
|
118
|
+
parent?.type === 'CallExpression';
|
|
119
|
+
if (shouldFormat) {
|
|
120
|
+
replacements.push({
|
|
121
|
+
end: node.end,
|
|
122
|
+
start: node.start,
|
|
123
|
+
value: printFormattedObjectExpression(node, code, getLineIndent(code, node.start)),
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
getChildren(node).forEach((child) => walk(child.node, node));
|
|
129
|
+
};
|
|
130
|
+
walk(parseOxc(code, filename));
|
|
131
|
+
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
132
|
+
};
|
|
133
|
+
const collapseRuntimeBlankLines = (code) => {
|
|
134
|
+
const lines = code.split('\n');
|
|
135
|
+
const result = [];
|
|
136
|
+
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
137
|
+
const line = lines[idx];
|
|
138
|
+
if (line.trim() !== '') {
|
|
139
|
+
result.push(line);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
let nextIdx = idx;
|
|
143
|
+
while (nextIdx < lines.length && lines[nextIdx]?.trim() === '') {
|
|
144
|
+
nextIdx += 1;
|
|
145
|
+
}
|
|
146
|
+
const previousNonEmpty = [...result]
|
|
147
|
+
.reverse()
|
|
148
|
+
.find((entry) => entry.trim() !== '');
|
|
149
|
+
const nextNonEmpty = lines
|
|
150
|
+
.slice(nextIdx)
|
|
151
|
+
.find((entry) => entry.trim() !== '');
|
|
152
|
+
if (previousNonEmpty && nextNonEmpty) {
|
|
153
|
+
const trimmedPrevious = previousNonEmpty.trim();
|
|
154
|
+
if (trimmedPrevious.startsWith('//') ||
|
|
155
|
+
trimmedPrevious.endsWith('*/')) {
|
|
156
|
+
result.push('');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
idx = nextIdx - 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result.join('\n');
|
|
163
|
+
};
|
|
164
|
+
const ensureBlankLineAfterLeadingBlockComment = (code) => code.replace(/^(\/\*[\s\S]*?\*\/)\n(?!\n)/, '$1\n\n');
|
|
165
|
+
const insertMissingSemicolons = (code, filename) => {
|
|
166
|
+
const replacements = [];
|
|
167
|
+
const hasTrailingSemicolon = (node) => code.slice(node.start, node.end).trimEnd().endsWith(';');
|
|
168
|
+
const walk = (node, parent = null, key = null) => {
|
|
169
|
+
if (shouldTerminateWithSemicolon(node, parent, key) &&
|
|
170
|
+
!hasTrailingSemicolon(node)) {
|
|
171
|
+
replacements.push({
|
|
172
|
+
end: node.end,
|
|
173
|
+
start: node.end,
|
|
174
|
+
value: ';',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
getChildren(node).forEach((child) => walk(child.node, node, child.key));
|
|
178
|
+
};
|
|
179
|
+
walk(parseOxc(code, filename));
|
|
180
|
+
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
181
|
+
};
|
|
182
|
+
export const normalizeRuntimeCode = (code, filename) => insertMissingSemicolons(ensureBlankLineAfterLeadingBlockComment(collapseRuntimeBlankLines(formatRuntimeObjectLiterals(code
|
|
183
|
+
.replace(/^\n+/, '')
|
|
184
|
+
.replace(/\n+$/, '')
|
|
185
|
+
.replace(/[ \t]+\n/g, '\n'), filename))), filename);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { SourceMapGenerator } from 'source-map';
|
|
3
|
+
const remapping = createRequire(import.meta.url)('@jridgewell/remapping');
|
|
4
|
+
const countLines = (code) => code.split('\n').length;
|
|
5
|
+
const createLineSourceMap = (generatedCode, originalCode, filename) => {
|
|
6
|
+
const generator = new SourceMapGenerator({
|
|
7
|
+
file: filename,
|
|
8
|
+
});
|
|
9
|
+
const generatedLines = countLines(generatedCode);
|
|
10
|
+
const originalLines = countLines(originalCode);
|
|
11
|
+
for (let line = 1; line <= generatedLines; line += 1) {
|
|
12
|
+
generator.addMapping({
|
|
13
|
+
generated: {
|
|
14
|
+
column: 0,
|
|
15
|
+
line,
|
|
16
|
+
},
|
|
17
|
+
original: {
|
|
18
|
+
column: 0,
|
|
19
|
+
line: Math.min(line, originalLines),
|
|
20
|
+
},
|
|
21
|
+
source: filename,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
generator.setSourceContent(filename, originalCode);
|
|
25
|
+
return generator.toJSON();
|
|
26
|
+
};
|
|
27
|
+
export const createComposedRuntimeSourceMap = (generatedCode, originalCode, filename, inputSourceMap) => {
|
|
28
|
+
const runtimeMap = createLineSourceMap(generatedCode, originalCode, filename);
|
|
29
|
+
if (!inputSourceMap) {
|
|
30
|
+
return runtimeMap;
|
|
31
|
+
}
|
|
32
|
+
const composed = remapping([runtimeMap, inputSourceMap], () => null);
|
|
33
|
+
return {
|
|
34
|
+
...composed,
|
|
35
|
+
file: runtimeMap.file,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StrictOptions } from '@wyw-in-js/shared';
|
|
2
|
+
import type { RawSourceMap } from 'source-map';
|
|
3
|
+
import type { WYWTransformMetadata } from '../TransformMetadata';
|
|
4
|
+
export type OxcCollectOptions = Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'eval' | 'extensions' | 'tagResolver' | 'variableNameConfig'> & {
|
|
5
|
+
preserveSideEffectImportLocals?: Set<string>;
|
|
6
|
+
};
|
|
7
|
+
export type OxcCollectResult = {
|
|
8
|
+
code: string;
|
|
9
|
+
map: RawSourceMap;
|
|
10
|
+
metadata: WYWTransformMetadata | null;
|
|
11
|
+
};
|
|
12
|
+
export type RuntimeReplacement = {
|
|
13
|
+
end: number;
|
|
14
|
+
start: number;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { ValueCache } from '@wyw-in-js/processor-utils';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type { WYWTransformMetadata } from './TransformMetadata';
|
|
5
|
-
type OxcCollectOptions = Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'extensions' | 'tagResolver' | 'variableNameConfig'> & {
|
|
6
|
-
preserveSideEffectImportLocals?: Set<string>;
|
|
7
|
-
};
|
|
8
|
-
type OxcCollectResult = {
|
|
9
|
-
code: string;
|
|
10
|
-
map: RawSourceMap;
|
|
11
|
-
metadata: WYWTransformMetadata | null;
|
|
12
|
-
};
|
|
2
|
+
import type { RawSourceMap } from 'source-map';
|
|
3
|
+
import type { OxcCollectOptions, OxcCollectResult } from './collectOxcRuntime/types';
|
|
13
4
|
export declare const collectOxcRuntime: (code: string, filename: string, root: string, options: OxcCollectOptions, values: ValueCache, inputSourceMap?: RawSourceMap) => OxcCollectResult;
|
|
14
|
-
export {};
|
|
@@ -1,226 +1,6 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
import { parseSync } from 'oxc-parser';
|
|
4
|
-
import { SourceMapGenerator } from 'source-map';
|
|
5
1
|
import { applyOxcProcessors } from './applyOxcProcessors';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const parseOxc = (code, filename) => {
|
|
9
|
-
const parsed = parseSync(filename, code, {
|
|
10
|
-
astType: filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',
|
|
11
|
-
range: true,
|
|
12
|
-
sourceType: 'module',
|
|
13
|
-
});
|
|
14
|
-
const fatalError = parsed.errors.find((error) => error.severity === 'Error');
|
|
15
|
-
if (fatalError) {
|
|
16
|
-
throw new Error(fatalError.message);
|
|
17
|
-
}
|
|
18
|
-
return parsed.program;
|
|
19
|
-
};
|
|
20
|
-
const applyReplacements = (code, replacements) => {
|
|
21
|
-
let result = code;
|
|
22
|
-
replacements
|
|
23
|
-
.sort((a, b) => b.start - a.start)
|
|
24
|
-
.forEach((replacement) => {
|
|
25
|
-
result =
|
|
26
|
-
result.slice(0, replacement.start) +
|
|
27
|
-
replacement.value +
|
|
28
|
-
result.slice(replacement.end);
|
|
29
|
-
});
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
const shouldTerminateWithSemicolon = (node, parent, key) => {
|
|
33
|
-
if (node.type === 'VariableDeclaration' && parent) {
|
|
34
|
-
if ((parent.type === 'ForStatement' ||
|
|
35
|
-
parent.type === 'ForInStatement' ||
|
|
36
|
-
parent.type === 'ForOfStatement') &&
|
|
37
|
-
key &&
|
|
38
|
-
['init', 'left'].includes(key)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if (parent.type === 'ExportNamedDeclaration') {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (node.type === 'ImportDeclaration' ||
|
|
46
|
-
node.type === 'ExpressionStatement' ||
|
|
47
|
-
node.type === 'ReturnStatement' ||
|
|
48
|
-
node.type === 'ThrowStatement' ||
|
|
49
|
-
node.type === 'VariableDeclaration') {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if (node.type === 'ExportNamedDeclaration') {
|
|
53
|
-
if (node.declaration) {
|
|
54
|
-
return node.declaration.type === 'VariableDeclaration';
|
|
55
|
-
}
|
|
56
|
-
return Array.isArray(node.specifiers) && node.specifiers.length > 0;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
const getChildren = (node) => {
|
|
61
|
-
const result = [];
|
|
62
|
-
const record = node;
|
|
63
|
-
Object.keys(record).forEach((key) => {
|
|
64
|
-
if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const value = record[key];
|
|
68
|
-
if (value && typeof value === 'object' && 'type' in value) {
|
|
69
|
-
result.push({ key, node: value });
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (Array.isArray(value)) {
|
|
73
|
-
value.forEach((item) => {
|
|
74
|
-
if (item && typeof item === 'object' && 'type' in item) {
|
|
75
|
-
result.push({ key, node: item });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return result;
|
|
81
|
-
};
|
|
82
|
-
const getLineIndent = (code, offset) => {
|
|
83
|
-
const lineStart = code.lastIndexOf('\n', offset - 1) + 1;
|
|
84
|
-
let idx = lineStart;
|
|
85
|
-
while (idx < code.length && (code[idx] === ' ' || code[idx] === '\t')) {
|
|
86
|
-
idx += 1;
|
|
87
|
-
}
|
|
88
|
-
return code.slice(lineStart, idx).replace(/\t/g, ' ');
|
|
89
|
-
};
|
|
90
|
-
const isPlainObjectProperty = (property) => property.type === 'Property' &&
|
|
91
|
-
property.kind === 'init' &&
|
|
92
|
-
property.method !== true;
|
|
93
|
-
const isFormattableObjectExpression = (node) => node.type === 'ObjectExpression' &&
|
|
94
|
-
node.properties.every((property) => property.type === 'SpreadElement' || isPlainObjectProperty(property));
|
|
95
|
-
const hasNestedObjectValue = (node) => node.type === 'ObjectExpression' &&
|
|
96
|
-
node.properties.some((property) => isPlainObjectProperty(property) &&
|
|
97
|
-
property.value.type === 'ObjectExpression');
|
|
98
|
-
const printFormattedObjectExpression = (node, code, baseIndent) => {
|
|
99
|
-
if (node.type !== 'ObjectExpression' ||
|
|
100
|
-
node.properties.length === 0 ||
|
|
101
|
-
!isFormattableObjectExpression(node)) {
|
|
102
|
-
return code.slice(node.start, node.end);
|
|
103
|
-
}
|
|
104
|
-
const lines = node.properties.map((property) => {
|
|
105
|
-
if (property.type === 'SpreadElement') {
|
|
106
|
-
return `${baseIndent} ...${code.slice(property.argument.start, property.argument.end)}`;
|
|
107
|
-
}
|
|
108
|
-
const keySource = property.computed
|
|
109
|
-
? `[${code.slice(property.key.start, property.key.end)}]`
|
|
110
|
-
: code.slice(property.key.start, property.key.end);
|
|
111
|
-
const valueSource = property.value.type === 'ObjectExpression'
|
|
112
|
-
? printFormattedObjectExpression(property.value, code, `${baseIndent} `)
|
|
113
|
-
: code.slice(property.value.start, property.value.end).trim();
|
|
114
|
-
return `${baseIndent} ${keySource}: ${valueSource}`;
|
|
115
|
-
});
|
|
116
|
-
return `{\n${lines.join(',\n')}\n${baseIndent}}`;
|
|
117
|
-
};
|
|
118
|
-
const formatRuntimeObjectLiterals = (code, filename) => {
|
|
119
|
-
const replacements = [];
|
|
120
|
-
const walk = (node, parent = null) => {
|
|
121
|
-
if (node.type === 'ObjectExpression') {
|
|
122
|
-
const shouldFormat = (parent?.type === 'VariableDeclarator' && hasNestedObjectValue(node)) ||
|
|
123
|
-
parent?.type === 'CallExpression';
|
|
124
|
-
if (shouldFormat) {
|
|
125
|
-
replacements.push({
|
|
126
|
-
end: node.end,
|
|
127
|
-
start: node.start,
|
|
128
|
-
value: printFormattedObjectExpression(node, code, getLineIndent(code, node.start)),
|
|
129
|
-
});
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
getChildren(node).forEach((child) => walk(child.node, node));
|
|
134
|
-
};
|
|
135
|
-
walk(parseOxc(code, filename));
|
|
136
|
-
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
137
|
-
};
|
|
138
|
-
const collapseRuntimeBlankLines = (code) => {
|
|
139
|
-
const lines = code.split('\n');
|
|
140
|
-
const result = [];
|
|
141
|
-
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
142
|
-
const line = lines[idx];
|
|
143
|
-
if (line.trim() !== '') {
|
|
144
|
-
result.push(line);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
let nextIdx = idx;
|
|
148
|
-
while (nextIdx < lines.length && lines[nextIdx]?.trim() === '') {
|
|
149
|
-
nextIdx += 1;
|
|
150
|
-
}
|
|
151
|
-
const previousNonEmpty = [...result]
|
|
152
|
-
.reverse()
|
|
153
|
-
.find((entry) => entry.trim() !== '');
|
|
154
|
-
const nextNonEmpty = lines
|
|
155
|
-
.slice(nextIdx)
|
|
156
|
-
.find((entry) => entry.trim() !== '');
|
|
157
|
-
if (previousNonEmpty && nextNonEmpty) {
|
|
158
|
-
const trimmedPrevious = previousNonEmpty.trim();
|
|
159
|
-
if (trimmedPrevious.startsWith('//') ||
|
|
160
|
-
trimmedPrevious.endsWith('*/')) {
|
|
161
|
-
result.push('');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
idx = nextIdx - 1;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return result.join('\n');
|
|
168
|
-
};
|
|
169
|
-
const ensureBlankLineAfterLeadingBlockComment = (code) => code.replace(/^(\/\*[\s\S]*?\*\/)\n(?!\n)/, '$1\n\n');
|
|
170
|
-
const insertMissingSemicolons = (code, filename) => {
|
|
171
|
-
const replacements = [];
|
|
172
|
-
const hasTrailingSemicolon = (node) => code.slice(node.start, node.end).trimEnd().endsWith(';');
|
|
173
|
-
const walk = (node, parent = null, key = null) => {
|
|
174
|
-
if (shouldTerminateWithSemicolon(node, parent, key) &&
|
|
175
|
-
!hasTrailingSemicolon(node)) {
|
|
176
|
-
replacements.push({
|
|
177
|
-
end: node.end,
|
|
178
|
-
start: node.end,
|
|
179
|
-
value: ';',
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
getChildren(node).forEach((child) => walk(child.node, node, child.key));
|
|
183
|
-
};
|
|
184
|
-
walk(parseOxc(code, filename));
|
|
185
|
-
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
186
|
-
};
|
|
187
|
-
const createLineSourceMap = (generatedCode, originalCode, filename) => {
|
|
188
|
-
const generator = new SourceMapGenerator({
|
|
189
|
-
file: filename,
|
|
190
|
-
});
|
|
191
|
-
const generatedLines = countLines(generatedCode);
|
|
192
|
-
const originalLines = countLines(originalCode);
|
|
193
|
-
for (let line = 1; line <= generatedLines; line += 1) {
|
|
194
|
-
generator.addMapping({
|
|
195
|
-
generated: {
|
|
196
|
-
column: 0,
|
|
197
|
-
line,
|
|
198
|
-
},
|
|
199
|
-
original: {
|
|
200
|
-
column: 0,
|
|
201
|
-
line: Math.min(line, originalLines),
|
|
202
|
-
},
|
|
203
|
-
source: filename,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
generator.setSourceContent(filename, originalCode);
|
|
207
|
-
return generator.toJSON();
|
|
208
|
-
};
|
|
209
|
-
const createComposedRuntimeSourceMap = (generatedCode, originalCode, filename, inputSourceMap) => {
|
|
210
|
-
const runtimeMap = createLineSourceMap(generatedCode, originalCode, filename);
|
|
211
|
-
if (!inputSourceMap) {
|
|
212
|
-
return runtimeMap;
|
|
213
|
-
}
|
|
214
|
-
const composed = remapping([runtimeMap, inputSourceMap], () => null);
|
|
215
|
-
return {
|
|
216
|
-
...composed,
|
|
217
|
-
file: runtimeMap.file,
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
const normalizeRuntimeCode = (code, filename) => insertMissingSemicolons(ensureBlankLineAfterLeadingBlockComment(collapseRuntimeBlankLines(formatRuntimeObjectLiterals(code
|
|
221
|
-
.replace(/^\n+/, '')
|
|
222
|
-
.replace(/\n+$/, '')
|
|
223
|
-
.replace(/[ \t]+\n/g, '\n'), filename))), filename);
|
|
2
|
+
import { normalizeRuntimeCode } from './collectOxcRuntime/normalizeRuntimeCode';
|
|
3
|
+
import { createComposedRuntimeSourceMap } from './collectOxcRuntime/sourceMap';
|
|
224
4
|
export const collectOxcRuntime = (code, filename, root, options, values, inputSourceMap) => {
|
|
225
5
|
const result = applyOxcProcessors(code, {
|
|
226
6
|
filename,
|
|
@@ -230,16 +10,17 @@ export const collectOxcRuntime = (code, filename, root, options, values, inputSo
|
|
|
230
10
|
processor.doRuntimeReplacement();
|
|
231
11
|
}, true);
|
|
232
12
|
const normalizedCode = normalizeRuntimeCode(result.code, filename);
|
|
13
|
+
const map = createComposedRuntimeSourceMap(normalizedCode, code, filename, inputSourceMap);
|
|
233
14
|
if (result.processors.length === 0) {
|
|
234
15
|
return {
|
|
235
16
|
code: normalizedCode,
|
|
236
|
-
map
|
|
17
|
+
map,
|
|
237
18
|
metadata: null,
|
|
238
19
|
};
|
|
239
20
|
}
|
|
240
21
|
return {
|
|
241
22
|
code: normalizedCode,
|
|
242
|
-
map
|
|
23
|
+
map,
|
|
243
24
|
metadata: {
|
|
244
25
|
dependencies: [],
|
|
245
26
|
processors: result.processors,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExpressionSpan, StaticBindings, TemplateExtractionResult } from './types';
|
|
2
|
+
export declare const isOxcStaticSerializableValue: (value: unknown) => boolean;
|
|
3
|
+
export declare const evaluateOxcStaticExpressionAt: (code: string, filename: string, expressionSpan: ExpressionSpan, env?: Map<string, unknown>, staticBindings?: StaticBindings) => unknown | undefined;
|
|
4
|
+
export declare const evaluateOxcStaticExpression: (source: string, filename: string, env?: Map<string, unknown>, staticBindings?: StaticBindings) => unknown | undefined;
|
|
5
|
+
export declare const collectOxcExpressionDependencies: (code: string, filename: string, evaluate?: boolean, targetExpressionSpans?: ExpressionSpan[], staticBindings?: StaticBindings) => TemplateExtractionResult;
|
|
6
|
+
export declare const collectOxcTemplateDependencies: (code: string, filename: string, evaluate?: boolean, targetTemplateSpans?: ExpressionSpan[]) => TemplateExtractionResult;
|