@shapeshift-labs/frontier-lang-compiler 0.2.150 → 0.2.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +5 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +170 -171
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
import {
|
|
4
|
+
createPreservedSourceOwnershipAnchor,
|
|
5
|
+
preservedOwnershipAnchorKind,
|
|
6
|
+
preservedSourceSegmentRole
|
|
7
|
+
} from '../../native-source-preservation-ownership.js';
|
|
8
|
+
import { createNativeSourcePreservation } from './createNativeSourcePreservation.js';
|
|
9
|
+
|
|
10
|
+
export function createSyntaxAstSourcePreservation(ast, input, options = {}) {
|
|
11
|
+
if (!ast || typeof input.sourceText !== 'string') return undefined;
|
|
12
|
+
const sourceText = input.sourceText;
|
|
13
|
+
const sourceHash = hashSemanticValue(sourceText);
|
|
14
|
+
const parserEvidence = `${options.parser ?? input.parser ?? 'syntax-ast'}-parser-token-comment-ranges`;
|
|
15
|
+
const tokensAndTrivia = syntaxAstTokensAndTrivia(ast, input, {
|
|
16
|
+
...options,
|
|
17
|
+
parserEvidence,
|
|
18
|
+
sourceHash,
|
|
19
|
+
sourceText
|
|
20
|
+
});
|
|
21
|
+
if (!tokensAndTrivia?.exact) return undefined;
|
|
22
|
+
const adapterId = input.adapterId ?? options.adapterId ?? `${options.parser ?? input.parser ?? 'syntax'}-native-importer`;
|
|
23
|
+
return createNativeSourcePreservation({
|
|
24
|
+
language: input.language ?? options.language ?? 'javascript',
|
|
25
|
+
sourcePath: input.sourcePath,
|
|
26
|
+
sourceHash: input.sourceHash,
|
|
27
|
+
sourceText,
|
|
28
|
+
tokensAndTrivia,
|
|
29
|
+
includeTokens: options.includeTokens !== false,
|
|
30
|
+
includeTrivia: options.includeTrivia !== false,
|
|
31
|
+
parserTriviaEvidence: {
|
|
32
|
+
status: 'exact',
|
|
33
|
+
exactParserTrivia: true,
|
|
34
|
+
losslessCst: true,
|
|
35
|
+
sourceHash,
|
|
36
|
+
adapterId,
|
|
37
|
+
evidenceId: `${adapterId}:parser-token-comment:${idFragment(input.sourcePath ?? sourceHash)}`,
|
|
38
|
+
parserEvidence
|
|
39
|
+
},
|
|
40
|
+
metadata: {
|
|
41
|
+
parserTokenTriviaEvidence: parserEvidence,
|
|
42
|
+
parserTokenTriviaSource: options.astFormat ?? options.parser ?? 'syntax-ast'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function syntaxAstTokensAndTrivia(ast, input, options) {
|
|
48
|
+
const sourceText = options.sourceText;
|
|
49
|
+
const parserSegments = parserTokenCommentSegments(ast)
|
|
50
|
+
.map((entry, index) => segmentFromParserEntry(entry, index, input, options))
|
|
51
|
+
.filter(Boolean)
|
|
52
|
+
.sort((left, right) => left.span.start - right.span.start || left.span.end - right.span.end);
|
|
53
|
+
if (!parserSegments.length) return undefined;
|
|
54
|
+
const exact = parserSegmentsCoverSource(parserSegments, sourceText);
|
|
55
|
+
if (!exact) return { exact: false };
|
|
56
|
+
const whitespaceSegments = whitespaceTriviaSegments(parserSegments, input, options);
|
|
57
|
+
const allTrivia = [...parserSegments.filter((segment) => segment.role === 'trivia'), ...whitespaceSegments]
|
|
58
|
+
.sort((left, right) => left.span.start - right.span.start || left.span.end - right.span.end);
|
|
59
|
+
const tokens = limitRecords(parserSegments.filter((segment) => segment.role !== 'trivia'), options.maxTokens);
|
|
60
|
+
const trivia = limitRecords(allTrivia, options.maxTrivia);
|
|
61
|
+
return {
|
|
62
|
+
exact: true,
|
|
63
|
+
tokens: tokens.records,
|
|
64
|
+
trivia: trivia.records,
|
|
65
|
+
truncated: tokens.truncated || trivia.truncated,
|
|
66
|
+
parserEvidence: options.parserEvidence
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parserTokenCommentSegments(ast) {
|
|
71
|
+
return uniqueParserEntries([
|
|
72
|
+
...arrayValue(ast.tokens),
|
|
73
|
+
...arrayValue(ast.comments),
|
|
74
|
+
...arrayValue(ast.program?.tokens),
|
|
75
|
+
...arrayValue(ast.program?.comments)
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function segmentFromParserEntry(entry, index, input, options) {
|
|
80
|
+
const range = sourceRange(entry);
|
|
81
|
+
if (!range || range.end <= range.start || range.end > options.sourceText.length) return undefined;
|
|
82
|
+
const text = options.sourceText.slice(range.start, range.end);
|
|
83
|
+
if (!parserEntrySourceTextMatches(entry, text)) return undefined;
|
|
84
|
+
const parserKind = parserEntryKind(entry);
|
|
85
|
+
const kind = entryIsComment(entry, text) ? preservedCommentKind(text) : syntaxTokenKind(parserKind, text, input.sourcePath);
|
|
86
|
+
return preservedParserSegment({
|
|
87
|
+
index,
|
|
88
|
+
kind,
|
|
89
|
+
text,
|
|
90
|
+
start: range.start,
|
|
91
|
+
end: range.end,
|
|
92
|
+
sourceHash: options.sourceHash,
|
|
93
|
+
sourcePath: input.sourcePath,
|
|
94
|
+
sourceText: options.sourceText,
|
|
95
|
+
parserEvidence: options.parserEvidence,
|
|
96
|
+
parserKind
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function whitespaceTriviaSegments(parserSegments, input, options) {
|
|
101
|
+
const result = [];
|
|
102
|
+
let cursor = 0;
|
|
103
|
+
for (const segment of parserSegments) {
|
|
104
|
+
if (segment.span.start > cursor) {
|
|
105
|
+
result.push(...whitespaceSegmentsForText(options.sourceText.slice(cursor, segment.span.start), cursor, input, options, result.length));
|
|
106
|
+
}
|
|
107
|
+
cursor = Math.max(cursor, segment.span.end);
|
|
108
|
+
}
|
|
109
|
+
if (cursor < options.sourceText.length) {
|
|
110
|
+
result.push(...whitespaceSegmentsForText(options.sourceText.slice(cursor), cursor, input, options, result.length));
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function whitespaceSegmentsForText(text, baseOffset, input, options, startIndex) {
|
|
116
|
+
const records = [];
|
|
117
|
+
const matches = text.matchAll(/\r\n|\r|\n|[ \t\v\f]+/g);
|
|
118
|
+
for (const match of matches) {
|
|
119
|
+
const start = baseOffset + match.index;
|
|
120
|
+
const end = start + match[0].length;
|
|
121
|
+
records.push(preservedParserSegment({
|
|
122
|
+
index: startIndex + records.length,
|
|
123
|
+
kind: /\r|\n/.test(match[0]) ? 'newline' : 'whitespace',
|
|
124
|
+
text: match[0],
|
|
125
|
+
start,
|
|
126
|
+
end,
|
|
127
|
+
sourceHash: options.sourceHash,
|
|
128
|
+
sourcePath: input.sourcePath,
|
|
129
|
+
sourceText: options.sourceText,
|
|
130
|
+
parserEvidence: options.parserEvidence,
|
|
131
|
+
parserKind: 'source-gap'
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
return records;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function preservedParserSegment(input) {
|
|
138
|
+
const role = preservedSourceSegmentRole(input.kind);
|
|
139
|
+
const textHash = hashSemanticValue(input.text);
|
|
140
|
+
const span = {
|
|
141
|
+
sourceId: input.sourceHash,
|
|
142
|
+
path: input.sourcePath,
|
|
143
|
+
...sourceSpanPositions(input.start, input.end, input.sourceText)
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
id: `${input.kind}_${input.index + 1}_${idFragment(input.start)}`,
|
|
147
|
+
kind: input.kind,
|
|
148
|
+
role,
|
|
149
|
+
text: input.text,
|
|
150
|
+
textHash,
|
|
151
|
+
span,
|
|
152
|
+
ownershipAnchor: createPreservedSourceOwnershipAnchor({
|
|
153
|
+
kind: input.kind,
|
|
154
|
+
role,
|
|
155
|
+
text: input.text,
|
|
156
|
+
textHash,
|
|
157
|
+
sourcePath: input.sourcePath,
|
|
158
|
+
sourceHash: input.sourceHash,
|
|
159
|
+
span,
|
|
160
|
+
anchorKind: preservedOwnershipAnchorKind(input.kind, role),
|
|
161
|
+
parserEvidence: input.parserEvidence,
|
|
162
|
+
parserTriviaEvidence: {
|
|
163
|
+
status: 'exact',
|
|
164
|
+
exactParserTrivia: true,
|
|
165
|
+
losslessCst: true,
|
|
166
|
+
sourceHash: input.sourceHash,
|
|
167
|
+
parserEvidence: input.parserEvidence,
|
|
168
|
+
adapterId: 'syntax-ast'
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
metadata: { parserKind: input.parserKind, parserEvidence: input.parserEvidence }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function parserSegmentsCoverSource(segments, sourceText) {
|
|
176
|
+
let cursor = 0;
|
|
177
|
+
for (const segment of segments) {
|
|
178
|
+
if (segment.span.start < cursor) return false;
|
|
179
|
+
if (!/^[\s]*$/.test(sourceText.slice(cursor, segment.span.start))) return false;
|
|
180
|
+
cursor = segment.span.end;
|
|
181
|
+
}
|
|
182
|
+
return /^[\s]*$/.test(sourceText.slice(cursor));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function sourceSpanPositions(start, end, sourceText) {
|
|
186
|
+
const beforeStart = String(sourceText ?? '').slice(0, start);
|
|
187
|
+
const beforeEnd = String(sourceText ?? '').slice(0, end);
|
|
188
|
+
const startLine = lineCount(beforeStart);
|
|
189
|
+
const endLine = lineCount(beforeEnd);
|
|
190
|
+
return {
|
|
191
|
+
start,
|
|
192
|
+
end,
|
|
193
|
+
startLine,
|
|
194
|
+
startColumn: start - lastLineStart(beforeStart) + 1,
|
|
195
|
+
endLine,
|
|
196
|
+
endColumn: end - lastLineStart(beforeEnd) + 1
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function sourceRange(entry) {
|
|
201
|
+
if (Number.isFinite(entry?.start) && Number.isFinite(entry?.end)) return { start: entry.start, end: entry.end };
|
|
202
|
+
if (Array.isArray(entry?.range) && Number.isFinite(entry.range[0]) && Number.isFinite(entry.range[1])) {
|
|
203
|
+
return { start: entry.range[0], end: entry.range[1] };
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function parserEntryKind(entry) {
|
|
209
|
+
const type = entry?.type;
|
|
210
|
+
if (typeof type === 'string') return type;
|
|
211
|
+
return type?.label ?? type?.keyword ?? type?.name ?? entry?.kind ?? 'Token';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function parserEntrySourceTextMatches(entry, text) {
|
|
215
|
+
const expected = entry?.raw ?? entry?.extra?.raw ?? entry?.text ?? entry?.source;
|
|
216
|
+
return typeof expected === 'string' ? expected === text : true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function entryIsComment(entry, text) {
|
|
220
|
+
const kind = String(parserEntryKind(entry));
|
|
221
|
+
return kind.includes('Comment') || text.startsWith('//') || text.startsWith('/*');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function syntaxTokenKind(parserKind, text, sourcePath) {
|
|
225
|
+
const kind = String(parserKind);
|
|
226
|
+
if (kind === 'Identifier' || kind === 'name') return 'identifier';
|
|
227
|
+
if (kind === 'Keyword' || kind.endsWith('Keyword')) return 'keyword';
|
|
228
|
+
if (kind === 'String' || kind === 'StringLiteral' || kind === 'string') return 'string';
|
|
229
|
+
if (kind === 'Numeric' || kind === 'NumericLiteral' || kind === 'num') return 'number';
|
|
230
|
+
if (kind === 'RegularExpression' || kind === 'regexp') return 'regex-like';
|
|
231
|
+
if (kind.includes('Template') || text.startsWith('`')) return 'template';
|
|
232
|
+
if (kind.includes('JSX') || /\.(?:jsx|tsx)$/i.test(String(sourcePath ?? '')) && /^(?:<|<\/|\/>|>)$/.test(text)) return 'jsx';
|
|
233
|
+
if (/^[()[\]{};,]$/.test(text)) return 'punctuation';
|
|
234
|
+
if (/^[=+\-*/%&|^!<>?:.]+$/.test(text)) return 'operator';
|
|
235
|
+
return 'unknown';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function preservedCommentKind(text) {
|
|
239
|
+
const value = String(text ?? '');
|
|
240
|
+
if (/[#@]\s*sourceMappingURL=|[#@]\s*sourceURL=/.test(value)) return 'source-map-comment';
|
|
241
|
+
if (value.startsWith('/**') && value[3] !== '/') return 'jsdoc-comment';
|
|
242
|
+
if (value.startsWith('/*')) return 'block-comment';
|
|
243
|
+
return 'comment';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function limitRecords(records, maxValue) {
|
|
247
|
+
const max = Number.isFinite(maxValue) ? Math.max(0, maxValue) : 20000;
|
|
248
|
+
return { records: records.slice(0, max), truncated: records.length > max };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function uniqueParserEntries(entries) {
|
|
252
|
+
const seen = new Set();
|
|
253
|
+
return entries.filter((entry) => {
|
|
254
|
+
const range = sourceRange(entry);
|
|
255
|
+
if (!range) return false;
|
|
256
|
+
const key = `${range.start}:${range.end}`;
|
|
257
|
+
if (seen.has(key)) return false;
|
|
258
|
+
seen.add(key);
|
|
259
|
+
return true;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function arrayValue(value) {
|
|
264
|
+
return Array.isArray(value) ? value : [];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function lineCount(text) {
|
|
268
|
+
return text.split(/\r\n|\r|\n/).length;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function lastLineStart(text) {
|
|
272
|
+
return Math.max(text.lastIndexOf('\n') + 1, text.lastIndexOf('\r') + 1, 0);
|
|
273
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exportBindingEntry,
|
|
3
|
+
exportModuleEntries,
|
|
4
|
+
identifierName,
|
|
5
|
+
importModuleEntries,
|
|
6
|
+
sourceValue
|
|
7
|
+
} from './syntaxModuleEntryRecords.js';
|
|
8
|
+
|
|
9
|
+
export function commonJsRequireVariableEntries(node, nativeNodeId, input) {
|
|
10
|
+
const helper = commonJsInteropHelperRequireBinding(node);
|
|
11
|
+
if (helper) return importModuleEntries(input, nativeNodeId, helper.moduleSpecifier, [helper.binding], helper.metadata);
|
|
12
|
+
const moduleSpecifier = commonJsRequireModuleSpecifier(node.init);
|
|
13
|
+
if (!moduleSpecifier) return [];
|
|
14
|
+
const bindings = commonJsRequireBindings(node.id);
|
|
15
|
+
return importModuleEntries(input, nativeNodeId, moduleSpecifier, bindings, {
|
|
16
|
+
importKind: 'commonjs-require',
|
|
17
|
+
commonJs: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function commonJsRequireExpressionEntries(node, nativeNodeId, input) {
|
|
22
|
+
const moduleSpecifier = commonJsRequireModuleSpecifier(node.expression);
|
|
23
|
+
if (!moduleSpecifier) return [];
|
|
24
|
+
return importModuleEntries(input, nativeNodeId, moduleSpecifier, [], {
|
|
25
|
+
importKind: 'commonjs-require',
|
|
26
|
+
sideEffectOnly: true,
|
|
27
|
+
commonJs: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function commonJsExpressionStatementEntries(node, nativeNodeId, input) {
|
|
32
|
+
return [
|
|
33
|
+
...commonJsRequireExpressionEntries(node, nativeNodeId, input),
|
|
34
|
+
...commonJsExportStarExpressionEntries(node, nativeNodeId, input),
|
|
35
|
+
...commonJsCreateBindingReExportExpressionEntries(node, nativeNodeId, input),
|
|
36
|
+
...commonJsObjectAssignExportExpressionEntries(node, nativeNodeId, input),
|
|
37
|
+
...commonJsDefinePropertiesExportExpressionEntries(node, nativeNodeId, input),
|
|
38
|
+
...commonJsDefinePropertyExportExpressionEntries(node, nativeNodeId, input)
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function commonJsExportAssignmentEntries(node, nativeNodeId, input) {
|
|
43
|
+
if (node.operator && node.operator !== '=') return [];
|
|
44
|
+
const target = commonJsExportTarget(node.left);
|
|
45
|
+
if (!target) return [];
|
|
46
|
+
if (target.exportedName === '__esModule') return [];
|
|
47
|
+
const assignment = exportBindingEntry(input, nativeNodeId, undefined, {
|
|
48
|
+
localName: expressionExportLocalName(node.right),
|
|
49
|
+
exportedName: target.exportedName,
|
|
50
|
+
exportKind: target.exportKind,
|
|
51
|
+
isTypeOnly: false,
|
|
52
|
+
commonJs: true
|
|
53
|
+
});
|
|
54
|
+
return [
|
|
55
|
+
assignment,
|
|
56
|
+
...(target.exportedName === 'module.exports'
|
|
57
|
+
? commonJsObjectExpressionExportBindings(node.right).map((binding) => exportBindingEntry(input, nativeNodeId, undefined, binding))
|
|
58
|
+
: [])
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function commonJsObjectAssignExportExpressionEntries(node, nativeNodeId, input) {
|
|
63
|
+
const call = node.expression;
|
|
64
|
+
const kind = String(call?.type ?? call?.kind ?? '');
|
|
65
|
+
if (kind !== 'CallExpression') return [];
|
|
66
|
+
const callee = memberExpressionParts(call.callee);
|
|
67
|
+
if (callee?.objectName !== 'Object' || callee.propertyName !== 'assign') return [];
|
|
68
|
+
if (!commonJsObjectAssignExportTarget((call.arguments ?? [])[0])) return [];
|
|
69
|
+
return commonJsObjectExpressionExportBindings((call.arguments ?? [])[1])
|
|
70
|
+
.map((binding) => exportBindingEntry(input, nativeNodeId, undefined, binding));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function commonJsExportStarExpressionEntries(node, nativeNodeId, input) {
|
|
74
|
+
const call = node.expression;
|
|
75
|
+
const kind = String(call?.type ?? call?.kind ?? '');
|
|
76
|
+
if (kind !== 'CallExpression' || commonJsHelperName(call.callee) !== '__exportStar') return [];
|
|
77
|
+
if (!commonJsObjectAssignExportTarget((call.arguments ?? [])[1])) return [];
|
|
78
|
+
const moduleSpecifier = commonJsRequireModuleSpecifier((call.arguments ?? [])[0]);
|
|
79
|
+
if (!moduleSpecifier) return [];
|
|
80
|
+
const metadata = { commonJs: true, reexport: true, reExport: true, exportStar: true, importKind: 'reexport', interopHelper: commonJsHelperName(call.callee) };
|
|
81
|
+
return [
|
|
82
|
+
...importModuleEntries(input, nativeNodeId, moduleSpecifier, [], metadata),
|
|
83
|
+
...exportModuleEntries(input, nativeNodeId, moduleSpecifier, [], { ...metadata, exportKind: 'export-star' })
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function commonJsCreateBindingReExportExpressionEntries(node, nativeNodeId, input) {
|
|
88
|
+
const call = node.expression;
|
|
89
|
+
const kind = String(call?.type ?? call?.kind ?? '');
|
|
90
|
+
if (kind !== 'CallExpression' || commonJsHelperName(call.callee) !== '__createBinding') return [];
|
|
91
|
+
if (!commonJsObjectAssignExportTarget((call.arguments ?? [])[0])) return [];
|
|
92
|
+
const moduleSpecifier = commonJsRequireModuleSpecifier((call.arguments ?? [])[1]);
|
|
93
|
+
const importedName = sourceValue((call.arguments ?? [])[2]);
|
|
94
|
+
const exportedName = sourceValue((call.arguments ?? [])[3]) ?? importedName;
|
|
95
|
+
if (!moduleSpecifier || !importedName || !exportedName || exportedName === '__esModule') return [];
|
|
96
|
+
const binding = {
|
|
97
|
+
localName: exportedName,
|
|
98
|
+
importedName,
|
|
99
|
+
exportedName,
|
|
100
|
+
importKind: 'reexport',
|
|
101
|
+
exportKind: 'named',
|
|
102
|
+
isTypeOnly: false,
|
|
103
|
+
reExport: true,
|
|
104
|
+
commonJs: true
|
|
105
|
+
};
|
|
106
|
+
const metadata = { commonJs: true, reexport: true, reExport: true, importKind: 'reexport', interopHelper: commonJsHelperName(call.callee) };
|
|
107
|
+
return [
|
|
108
|
+
...importModuleEntries(input, nativeNodeId, moduleSpecifier, [binding], metadata),
|
|
109
|
+
...exportModuleEntries(input, nativeNodeId, moduleSpecifier, [binding], { ...metadata, exportKind: 'named' })
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function commonJsDefinePropertyExportExpressionEntries(node, nativeNodeId, input) {
|
|
114
|
+
const call = node.expression;
|
|
115
|
+
const kind = String(call?.type ?? call?.kind ?? '');
|
|
116
|
+
if (kind !== 'CallExpression') return [];
|
|
117
|
+
const callee = memberExpressionParts(call.callee);
|
|
118
|
+
if (callee?.objectName !== 'Object' || callee.propertyName !== 'defineProperty') return [];
|
|
119
|
+
if (!commonJsObjectAssignExportTarget((call.arguments ?? [])[0])) return [];
|
|
120
|
+
const exportedName = sourceValue((call.arguments ?? [])[1]);
|
|
121
|
+
if (!exportedName || exportedName === '__esModule') return [];
|
|
122
|
+
return [exportBindingEntry(input, nativeNodeId, undefined, {
|
|
123
|
+
localName: commonJsDescriptorLocalName((call.arguments ?? [])[2]),
|
|
124
|
+
exportedName,
|
|
125
|
+
exportKind: 'commonjs-named',
|
|
126
|
+
isTypeOnly: false,
|
|
127
|
+
commonJs: true
|
|
128
|
+
})];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function commonJsDefinePropertiesExportExpressionEntries(node, nativeNodeId, input) {
|
|
132
|
+
const call = node.expression;
|
|
133
|
+
const kind = String(call?.type ?? call?.kind ?? '');
|
|
134
|
+
if (kind !== 'CallExpression') return [];
|
|
135
|
+
const callee = memberExpressionParts(call.callee);
|
|
136
|
+
if (callee?.objectName !== 'Object' || callee.propertyName !== 'defineProperties') return [];
|
|
137
|
+
if (!commonJsObjectAssignExportTarget((call.arguments ?? [])[0])) return [];
|
|
138
|
+
return commonJsDefinePropertiesExportBindings((call.arguments ?? [])[1])
|
|
139
|
+
.map((binding) => exportBindingEntry(input, nativeNodeId, undefined, binding));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function commonJsDefinePropertiesExportBindings(node) {
|
|
143
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
144
|
+
if (kind !== 'ObjectExpression') return [];
|
|
145
|
+
return (node.properties ?? []).map(commonJsDefinePropertiesExportBinding).filter(Boolean);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function commonJsDefinePropertiesExportBinding(property) {
|
|
149
|
+
const kind = String(property?.type ?? property?.kind ?? '');
|
|
150
|
+
if (kind === 'SpreadElement' || kind === 'SpreadProperty') return undefined;
|
|
151
|
+
const exportedName = property.computed ? sourceValue(property.key) : memberPropertyName(property.key);
|
|
152
|
+
if (!exportedName || exportedName === '__esModule') return undefined;
|
|
153
|
+
return {
|
|
154
|
+
localName: commonJsDescriptorLocalName(property.value),
|
|
155
|
+
exportedName,
|
|
156
|
+
exportKind: 'commonjs-named',
|
|
157
|
+
isTypeOnly: false,
|
|
158
|
+
commonJs: true
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function commonJsObjectAssignExportTarget(node) {
|
|
163
|
+
if (identifierName(node) === 'exports') return true;
|
|
164
|
+
const member = memberExpressionParts(node);
|
|
165
|
+
return member?.objectName === 'module' && member.propertyName === 'exports';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function commonJsRequireModuleSpecifier(node) {
|
|
169
|
+
if (!isCommonJsRequireCall(node)) return undefined;
|
|
170
|
+
return sourceValue((node.arguments ?? [])[0]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isCommonJsRequireCall(node) {
|
|
174
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
175
|
+
return kind === 'CallExpression' && identifierName(node.callee) === 'require' && Array.isArray(node.arguments) && node.arguments.length > 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function commonJsRequireBindings(pattern) {
|
|
179
|
+
const localName = identifierName(pattern);
|
|
180
|
+
if (localName) return [{ localName, importedName: 'default', importKind: 'commonjs-require', commonJs: true }];
|
|
181
|
+
const kind = String(pattern?.type ?? pattern?.kind ?? '');
|
|
182
|
+
if (kind !== 'ObjectPattern') return [];
|
|
183
|
+
return (pattern.properties ?? []).map(commonJsDestructuredRequireBinding).filter(Boolean);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function commonJsInteropHelperRequireBinding(node) {
|
|
187
|
+
const localName = identifierName(node.id);
|
|
188
|
+
const init = node.init;
|
|
189
|
+
const kind = String(init?.type ?? init?.kind ?? '');
|
|
190
|
+
const helper = commonJsHelperName(init?.callee);
|
|
191
|
+
if (!localName || kind !== 'CallExpression' || (helper !== '__importStar' && helper !== '__importDefault')) return undefined;
|
|
192
|
+
const moduleSpecifier = commonJsRequireModuleSpecifier((init.arguments ?? [])[0]);
|
|
193
|
+
if (!moduleSpecifier) return undefined;
|
|
194
|
+
const binding = helper === '__importStar'
|
|
195
|
+
? { localName, importedName: '*', namespace: localName, importKind: 'namespace', commonJs: true }
|
|
196
|
+
: { localName, importedName: 'default', importKind: 'default', commonJs: true };
|
|
197
|
+
return {
|
|
198
|
+
moduleSpecifier,
|
|
199
|
+
binding,
|
|
200
|
+
metadata: { importKind: binding.importKind, commonJs: true, interopHelper: helper }
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function commonJsHelperName(node) {
|
|
205
|
+
const direct = identifierName(node);
|
|
206
|
+
return direct ?? memberExpressionParts(node)?.propertyName;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function commonJsDestructuredRequireBinding(property) {
|
|
210
|
+
const kind = String(property?.type ?? property?.kind ?? '');
|
|
211
|
+
if (kind === 'RestElement' || kind === 'RestProperty') return undefined;
|
|
212
|
+
const importedName = memberPropertyName(property.key);
|
|
213
|
+
const localName = identifierName(property.value) ?? identifierName(property.argument) ?? importedName;
|
|
214
|
+
if (!importedName || !localName) return undefined;
|
|
215
|
+
return { localName, importedName, importKind: 'commonjs-require', commonJs: true };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function commonJsExportTarget(node) {
|
|
219
|
+
const member = memberExpressionParts(node);
|
|
220
|
+
if (!member) return undefined;
|
|
221
|
+
if (member.objectName === 'module' && member.propertyName === 'exports') {
|
|
222
|
+
return { exportedName: 'module.exports', exportKind: 'assignment' };
|
|
223
|
+
}
|
|
224
|
+
if (member.objectName === 'exports') {
|
|
225
|
+
return { exportedName: member.propertyName, exportKind: 'commonjs-named' };
|
|
226
|
+
}
|
|
227
|
+
const nestedObject = memberExpressionParts(member.objectNode);
|
|
228
|
+
if (nestedObject?.objectName === 'module' && nestedObject.propertyName === 'exports') {
|
|
229
|
+
return { exportedName: member.propertyName, exportKind: 'commonjs-named' };
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function commonJsObjectExpressionExportBindings(node) {
|
|
235
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
236
|
+
if (kind !== 'ObjectExpression') return [];
|
|
237
|
+
return (node.properties ?? []).map(commonJsObjectExpressionExportBinding).filter(Boolean);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function commonJsObjectExpressionExportBinding(property) {
|
|
241
|
+
const kind = String(property?.type ?? property?.kind ?? '');
|
|
242
|
+
if (kind === 'SpreadElement' || kind === 'SpreadProperty') return undefined;
|
|
243
|
+
const exportedName = property.computed ? sourceValue(property.key) : memberPropertyName(property.key);
|
|
244
|
+
if (!exportedName || exportedName === '__esModule') return undefined;
|
|
245
|
+
return {
|
|
246
|
+
localName: property.shorthand ? exportedName : expressionExportLocalName(property.value),
|
|
247
|
+
exportedName,
|
|
248
|
+
exportKind: 'commonjs-named',
|
|
249
|
+
isTypeOnly: false,
|
|
250
|
+
commonJs: true
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function commonJsDescriptorLocalName(node) {
|
|
255
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
256
|
+
if (kind !== 'ObjectExpression') return undefined;
|
|
257
|
+
for (const property of node.properties ?? []) {
|
|
258
|
+
const key = property.computed ? sourceValue(property.key) : memberPropertyName(property.key);
|
|
259
|
+
if (key === 'value') return expressionExportLocalName(property.value);
|
|
260
|
+
if (key === 'get') return returnExpressionLocalName(property.value);
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function returnExpressionLocalName(node) {
|
|
266
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
267
|
+
if (kind === 'ArrowFunctionExpression') return returnBlockExpressionLocalName(node.body) ?? expressionExportLocalName(node.body);
|
|
268
|
+
if (kind !== 'FunctionExpression' && kind !== 'FunctionDeclaration') return undefined;
|
|
269
|
+
return returnBlockExpressionLocalName(node.body);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function returnBlockExpressionLocalName(node) {
|
|
273
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
274
|
+
if (kind !== 'BlockStatement') return undefined;
|
|
275
|
+
const statement = (node.body ?? []).find((entry) => String(entry?.type ?? entry?.kind ?? '') === 'ReturnStatement');
|
|
276
|
+
return expressionExportLocalName(statement?.argument);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function memberExpressionParts(node) {
|
|
280
|
+
const kind = String(node?.type ?? node?.kind ?? '');
|
|
281
|
+
if (kind !== 'MemberExpression' && kind !== 'OptionalMemberExpression') return undefined;
|
|
282
|
+
const objectName = expressionExportLocalName(node.object);
|
|
283
|
+
const propertyName = node.computed ? sourceValue(node.property) : memberPropertyName(node.property);
|
|
284
|
+
if (!objectName || !propertyName) return undefined;
|
|
285
|
+
return { objectName, propertyName, objectNode: node.object };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function memberPropertyName(node) {
|
|
289
|
+
return identifierName(node);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function expressionExportLocalName(node) {
|
|
293
|
+
const name = identifierName(node);
|
|
294
|
+
if (name) return name;
|
|
295
|
+
const member = memberExpressionParts(node);
|
|
296
|
+
return member ? `${member.objectName}.${member.propertyName}` : undefined;
|
|
297
|
+
}
|