@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/collect.js +1 -0
- package/esm/transform/generators/collect.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 +272 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +184 -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 +58 -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 +55 -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 +517 -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/collectOxcExportsAndImports.js +8 -0
- package/esm/utils/collectOxcExportsAndImports.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 +58 -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 +106 -66
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/parseOxc.js +6 -1
- package/esm/utils/parseOxc.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 +6 -5
- 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 +4 -0
- package/types/transform/generators/collect.js +1 -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 +312 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +198 -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 +64 -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 +57 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +9 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +169 -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 +567 -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/collectOxcExportsAndImports.js +8 -0
- 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 +17 -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 +61 -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 +111 -75
- package/types/utils/parseOxc.js +6 -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,10 @@
|
|
|
1
|
+
import type { SourceLocation } from '@wyw-in-js/processor-utils';
|
|
2
|
+
import type { Program } from 'oxc-parser';
|
|
3
|
+
import { type AddedImport } from '../oxcAstService';
|
|
4
|
+
import { type OxcLocationLookup } from '../oxc/sourceLocations';
|
|
5
|
+
export declare const GENERATED_HELPER_NAME_RE: RegExp;
|
|
6
|
+
export declare const WYW_META_EXTENDS_HELPER_RE: RegExp;
|
|
7
|
+
export declare const JS_IDENTIFIER_RE: RegExp;
|
|
8
|
+
export declare const parseOxc: (code: string, filename: string) => Program;
|
|
9
|
+
export declare const insertAddedImports: (code: string, program: Program, addedImports: AddedImport[]) => string;
|
|
10
|
+
export declare const getSourceLocation: (start: number, end: number, loc: OxcLocationLookup, filename?: string | null) => SourceLocation;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { printOxcAstServiceImport } from '../oxcAstService';
|
|
2
|
+
import { parseOxcProgram } from '../oxc/parse';
|
|
3
|
+
import { createOxcSourceLocation, } from '../oxc/sourceLocations';
|
|
4
|
+
export const GENERATED_HELPER_NAME_RE = /^_exp\d*$/;
|
|
5
|
+
export const WYW_META_EXTENDS_HELPER_RE = /(?:\bextends|["']extends["'])\s*:\s*(_exp\d*)\s*\(\s*\)/g;
|
|
6
|
+
export const JS_IDENTIFIER_RE = /[$A-Z_a-z][$\w]*/g;
|
|
7
|
+
export const parseOxc = (code, filename) => {
|
|
8
|
+
return parseOxcProgram(code, filename, 'module');
|
|
9
|
+
};
|
|
10
|
+
export const insertAddedImports = (code, program, addedImports) => {
|
|
11
|
+
if (addedImports.length === 0) {
|
|
12
|
+
return code;
|
|
13
|
+
}
|
|
14
|
+
const uniqueImports = [
|
|
15
|
+
...new Map(addedImports.map((item) => [
|
|
16
|
+
`${item.source}\0${item.imported}\0${item.local}`,
|
|
17
|
+
item,
|
|
18
|
+
])).values(),
|
|
19
|
+
];
|
|
20
|
+
const importBlock = uniqueImports.map(printOxcAstServiceImport).join('\n');
|
|
21
|
+
const lastImport = [...program.body]
|
|
22
|
+
.reverse()
|
|
23
|
+
.find((statement) => statement.type === 'ImportDeclaration');
|
|
24
|
+
const hashbangEnd = code.startsWith('#!')
|
|
25
|
+
? (() => {
|
|
26
|
+
const newline = code.indexOf('\n');
|
|
27
|
+
return newline === -1 ? code.length : newline + 1;
|
|
28
|
+
})()
|
|
29
|
+
: 0;
|
|
30
|
+
const insertionPoint = lastImport?.end ?? hashbangEnd;
|
|
31
|
+
const prefix = code.slice(0, insertionPoint);
|
|
32
|
+
const suffix = code.slice(insertionPoint);
|
|
33
|
+
const leadingBreak = prefix.length > 0 && !prefix.endsWith('\n') ? '\n' : '';
|
|
34
|
+
const trailingBreak = suffix.length > 0 && !suffix.startsWith('\n') ? '\n' : '';
|
|
35
|
+
return `${prefix}${leadingBreak}${importBlock}${trailingBreak}${suffix}`;
|
|
36
|
+
};
|
|
37
|
+
export const getSourceLocation = (start, end, loc, filename) => createOxcSourceLocation(start, end, loc, filename);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { BaseProcessor } from '@wyw-in-js/processor-utils';
|
|
2
|
+
import type { CallExpression, Expression, Node, TaggedTemplateExpression } from 'oxc-parser';
|
|
3
|
+
import type { OxcStaticValue, OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';
|
|
4
|
+
import type { OxcAstService } from '../oxcAstService';
|
|
5
|
+
import type { OxcValueReplacement } from '../oxc/replacements';
|
|
6
|
+
import type { OxcLocationLookup } from '../oxc/sourceLocations';
|
|
7
|
+
import type { ProcessorClass } from '../processorLookup';
|
|
8
|
+
export type DefinedProcessor = [
|
|
9
|
+
ProcessorClass,
|
|
10
|
+
{
|
|
11
|
+
imported: string;
|
|
12
|
+
source: string;
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
export type Replacement = OxcValueReplacement;
|
|
16
|
+
export type ApplyOxcProcessorsResult = {
|
|
17
|
+
code: string;
|
|
18
|
+
processorClassNamesByLocal: Map<string, string>;
|
|
19
|
+
processors: BaseProcessor[];
|
|
20
|
+
staticValueCandidates: OxcStaticValueCandidate[];
|
|
21
|
+
staticValues: OxcStaticValue[];
|
|
22
|
+
};
|
|
23
|
+
export type AnyNode = Node & Record<string, unknown>;
|
|
24
|
+
export type OxcIdentifier = Expression & {
|
|
25
|
+
name: string;
|
|
26
|
+
type: 'Identifier';
|
|
27
|
+
};
|
|
28
|
+
export type ProcessorUsage = {
|
|
29
|
+
ancestors: Node[];
|
|
30
|
+
callee: Expression;
|
|
31
|
+
collapseQualifiedCallee: boolean;
|
|
32
|
+
definedProcessor: DefinedProcessor;
|
|
33
|
+
kind: 'call';
|
|
34
|
+
replacementTarget: Expression;
|
|
35
|
+
target: CallExpression;
|
|
36
|
+
} | {
|
|
37
|
+
ancestors: Node[];
|
|
38
|
+
callee: Expression;
|
|
39
|
+
collapseQualifiedCallee: boolean;
|
|
40
|
+
definedProcessor: DefinedProcessor;
|
|
41
|
+
kind: 'template';
|
|
42
|
+
replacementTarget: Expression;
|
|
43
|
+
target: TaggedTemplateExpression;
|
|
44
|
+
};
|
|
45
|
+
export type ExpressionSpan = {
|
|
46
|
+
end: number;
|
|
47
|
+
start: number;
|
|
48
|
+
};
|
|
49
|
+
export type CreatedProcessor = {
|
|
50
|
+
astService: OxcAstService;
|
|
51
|
+
processor: BaseProcessor;
|
|
52
|
+
};
|
|
53
|
+
export type QualifiedExpression = Expression & {
|
|
54
|
+
expressions?: Expression[];
|
|
55
|
+
};
|
|
56
|
+
export type CallExpressionLike = Expression & {
|
|
57
|
+
arguments: Node[];
|
|
58
|
+
callee: Expression;
|
|
59
|
+
type: 'CallExpression';
|
|
60
|
+
};
|
|
61
|
+
export type SequenceExpressionLike = Expression & {
|
|
62
|
+
expressions: Expression[];
|
|
63
|
+
type: 'SequenceExpression';
|
|
64
|
+
};
|
|
65
|
+
export type LocationLookup = OxcLocationLookup;
|
|
66
|
+
export type TopLevelStatementInfo = {
|
|
67
|
+
bindings: Set<string>;
|
|
68
|
+
node: Node;
|
|
69
|
+
references: Set<string>;
|
|
70
|
+
};
|
|
71
|
+
export type ScopedBindingKind = 'function' | 'import' | 'param' | 'variable';
|
|
72
|
+
export type ScopedBindingInfo = {
|
|
73
|
+
declaration: Node;
|
|
74
|
+
dependencies: Set<string>;
|
|
75
|
+
externalReferences: number;
|
|
76
|
+
id: string;
|
|
77
|
+
incomingFromBindings: Set<string>;
|
|
78
|
+
kind: ScopedBindingKind;
|
|
79
|
+
name: string;
|
|
80
|
+
};
|
|
81
|
+
export type ScopedCleanupScope = {
|
|
82
|
+
bindings: Map<string, string>;
|
|
83
|
+
parent: ScopedCleanupScope | null;
|
|
84
|
+
};
|
|
85
|
+
export type SameFileProcessorObject = {
|
|
86
|
+
properties: Map<string, BaseProcessor>;
|
|
87
|
+
propertyNames: Set<string>;
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IFileContext } from '@wyw-in-js/processor-utils';
|
|
3
|
-
import type { StrictOptions } from '@wyw-in-js/shared';
|
|
4
|
-
import { EventEmitter } from './EventEmitter';
|
|
5
|
-
import { type OxcStaticValue, type OxcStaticValueCandidate } from './collectOxcTemplateDependencies';
|
|
6
|
-
type ApplyOxcProcessorsResult = {
|
|
7
|
-
code: string;
|
|
8
|
-
processors: BaseProcessor[];
|
|
9
|
-
staticValueCandidates: OxcStaticValueCandidate[];
|
|
10
|
-
staticValues: OxcStaticValue[];
|
|
11
|
-
};
|
|
12
|
-
export declare const applyOxcProcessors: (code: string, fileContext: IFileContext, options: Pick<StrictOptions, "classNameSlug" | "displayName" | "extensions" | "evaluate" | "tagResolver"> & {
|
|
13
|
-
eventEmitter?: EventEmitter;
|
|
14
|
-
preserveSideEffectImportLocals?: Set<string>;
|
|
15
|
-
}, callback: (processor: BaseProcessor) => void, cleanupUnused?: boolean) => ApplyOxcProcessorsResult;
|
|
16
|
-
export {};
|
|
1
|
+
export { applyOxcProcessors } from './applyOxcProcessors/applyOxcProcessors';
|