@shapeshift-labs/frontier-lang-compiler 0.2.149 → 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-patch-bundle-composition.d.ts +62 -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 +32 -0
- package/dist/index.js +6 -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/semanticPatchBundleComposition.js +166 -0
- 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-context.js +1 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +314 -0
- 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-plan.js +3 -1
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +49 -0
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +5 -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 +171 -172
- 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,294 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { idFragment } from '../../native-import-utils.js';
|
|
3
|
+
import { compilerAdvancedTypeShapes } from './typeScriptCompilerAdvancedTypeShapes.js';
|
|
4
|
+
import { compilerAssignabilityOracleRecord, hasFocusedCompilerApiShape } from './typeScriptCompilerAssignabilityOracle.js';
|
|
5
|
+
import { compilerClassApiRecord } from './typeScriptCompilerClassApi.js';
|
|
6
|
+
import { compilerEnumShapeRecord } from './typeScriptCompilerEnumShape.js';
|
|
7
|
+
import { compilerTypeInferenceSyntaxRecord } from './typeScriptCompilerInferenceSyntax.js';
|
|
8
|
+
import { compilerTypeReferenceTargets } from './typeScriptCompilerTypeReferenceTargets.js';
|
|
9
|
+
|
|
10
|
+
function typeScriptCompilerSymbolRecordForNode(node, input, options = {}, fallbackNode = undefined, idOptions = {}) {
|
|
11
|
+
const checker = options.typeChecker ?? options.checker ?? options.program?.getTypeChecker?.();
|
|
12
|
+
const symbol = safeCall(checker?.getSymbolAtLocation, checker, node) ?? safeCall(checker?.getSymbolAtLocation, checker, fallbackNode);
|
|
13
|
+
if (!symbol) return undefined;
|
|
14
|
+
const aliasedSymbol = safeCall(checker?.getAliasedSymbol, checker, symbol);
|
|
15
|
+
const targetSymbol = aliasedSymbol && aliasedSymbol !== symbol ? aliasedSymbol : undefined;
|
|
16
|
+
const identitySymbol = targetSymbol ?? symbol;
|
|
17
|
+
const fullyQualifiedName = stringValue(safeCall(checker?.getFullyQualifiedName, checker, identitySymbol));
|
|
18
|
+
const localName = compilerSymbolLocalName(symbol, node, options.ts);
|
|
19
|
+
const targetName = targetSymbol ? stringValue(targetSymbol.escapedName ?? targetSymbol.name) : undefined;
|
|
20
|
+
const identity = fullyQualifiedName ?? targetName ?? localName;
|
|
21
|
+
if (!identity) return undefined;
|
|
22
|
+
const compilerSymbol = compactRecord({
|
|
23
|
+
parser: options.parser,
|
|
24
|
+
localName,
|
|
25
|
+
targetName,
|
|
26
|
+
fullyQualifiedName,
|
|
27
|
+
flags: numberValue(symbol.flags),
|
|
28
|
+
targetFlags: numberValue(targetSymbol?.flags),
|
|
29
|
+
declarations: Array.isArray(identitySymbol.declarations) ? identitySymbol.declarations.length : undefined,
|
|
30
|
+
aliased: Boolean(targetSymbol)
|
|
31
|
+
});
|
|
32
|
+
const compilerType = typeScriptCompilerTypeRecordForNode(node, {
|
|
33
|
+
...options,
|
|
34
|
+
sourcePath: input.sourcePath,
|
|
35
|
+
sourceHash: input.sourceHash
|
|
36
|
+
}, fallbackNode, identitySymbol);
|
|
37
|
+
return {
|
|
38
|
+
identity,
|
|
39
|
+
compilerSymbol,
|
|
40
|
+
compilerSymbolIdentityHash: hashSemanticValue(compilerSymbol),
|
|
41
|
+
compilerType,
|
|
42
|
+
compilerTypeIdentityHash: compilerType ? hashSemanticValue(compilerType) : undefined,
|
|
43
|
+
symbolId: `symbol:${input.language}:compiler:${idOptions.importRole ? 'import:' : ''}${idFragment(identity)}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function typeScriptCompilerTypeRecordForNode(node, options = {}, fallbackNode = undefined, identitySymbol = undefined) {
|
|
48
|
+
const checker = options.typeChecker ?? options.checker ?? options.program?.getTypeChecker?.();
|
|
49
|
+
const type = safeCall(checker?.getTypeAtLocation, checker, node) ?? safeCall(checker?.getTypeAtLocation, checker, fallbackNode);
|
|
50
|
+
if (!type) return undefined;
|
|
51
|
+
const apparentType = safeCall(checker?.getApparentType, checker, type);
|
|
52
|
+
const typeText = stringValue(safeCall(checker?.typeToString, checker, type));
|
|
53
|
+
const apparentTypeText = stringValue(apparentType ? safeCall(checker?.typeToString, checker, apparentType) : undefined);
|
|
54
|
+
const apiSignature = compilerApiSignatureRecord(checker, type, apparentType, node, fallbackNode, options, identitySymbol);
|
|
55
|
+
return compactRecord({
|
|
56
|
+
parser: options.parser,
|
|
57
|
+
typeText,
|
|
58
|
+
apparentTypeText,
|
|
59
|
+
flags: numberValue(type.flags),
|
|
60
|
+
objectFlags: numberValue(type.objectFlags),
|
|
61
|
+
intrinsicName: stringValue(type.intrinsicName),
|
|
62
|
+
...apiSignature,
|
|
63
|
+
apiSignatureHash: hashSemanticValue({
|
|
64
|
+
kind: 'frontier.lang.typescript.compilerPublicApiSignature.v1',
|
|
65
|
+
parser: options.parser,
|
|
66
|
+
typeText,
|
|
67
|
+
apparentTypeText,
|
|
68
|
+
...canonicalApiSignatureRecord(apiSignature)
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function compilerApiSignatureRecord(checker, type, apparentType, node, fallbackNode, options, identitySymbol) {
|
|
74
|
+
const location = fallbackNode ?? node;
|
|
75
|
+
const signatureType = type ?? apparentType;
|
|
76
|
+
const propertyType = apparentType ?? type;
|
|
77
|
+
const typeParameters = compilerTypeParameterRecords(checker, identitySymbol, location, options.ts);
|
|
78
|
+
const callSignatures = compilerSignatureRecords(checker, signatureType, signatureKind(options.ts, 'Call', 0), location, options.ts);
|
|
79
|
+
const constructSignatures = compilerSignatureRecords(checker, signatureType, signatureKind(options.ts, 'Construct', 1), location, options.ts);
|
|
80
|
+
const properties = compilerPropertyRecords(checker, propertyType, location, options.ts);
|
|
81
|
+
const indexSignatures = compilerIndexSignatureRecords(checker, propertyType);
|
|
82
|
+
const advancedTypeShapes = compilerAdvancedTypeShapes(checker, identitySymbol, location, options.ts);
|
|
83
|
+
const typeReferenceTargets = compilerTypeReferenceTargets(checker, identitySymbol, location, options.ts);
|
|
84
|
+
const classApi = compilerClassApiRecord(checker, identitySymbol, location, options.ts);
|
|
85
|
+
const enumShape = compilerEnumShapeRecord(checker, identitySymbol, location, options.ts, options);
|
|
86
|
+
const typeInferenceSyntax = compilerTypeInferenceSyntaxRecord(checker, identitySymbol, location, options.ts);
|
|
87
|
+
const assignabilityOracle = hasFocusedCompilerApiShape({ typeParameters, callSignatures, constructSignatures, properties, indexSignatures, advancedTypeShapes, typeReferenceTargets, classApi, enumShape, typeInferenceSyntax })
|
|
88
|
+
? undefined
|
|
89
|
+
: compilerAssignabilityOracleRecord(checker, type, apparentType, identitySymbol, location, options.ts);
|
|
90
|
+
return compactRecord({
|
|
91
|
+
typeParameters: nonEmptyArray(typeParameters),
|
|
92
|
+
typeParameterCount: typeParameters.length || undefined,
|
|
93
|
+
typeParameterDefaultCount: typeParameters.filter((parameter) => parameter.hasDefault).length || undefined,
|
|
94
|
+
typeParameterConstraintCount: typeParameters.filter((parameter) => parameter.hasConstraint).length || undefined,
|
|
95
|
+
callSignatures: nonEmptyArray(callSignatures),
|
|
96
|
+
constructSignatures: nonEmptyArray(constructSignatures),
|
|
97
|
+
properties: nonEmptyArray(properties),
|
|
98
|
+
indexSignatures: nonEmptyArray(indexSignatures),
|
|
99
|
+
indexSignatureCount: indexSignatures.length || undefined,
|
|
100
|
+
indexSignatureReadonlyCount: indexSignatures.filter((signature) => signature.readonly === true).length || undefined,
|
|
101
|
+
advancedTypeShapes: nonEmptyArray(advancedTypeShapes),
|
|
102
|
+
advancedTypeShapeKinds: nonEmptyArray(uniqueStrings(advancedTypeShapes.map((shape) => shape.kind))),
|
|
103
|
+
advancedTypeShapeCount: advancedTypeShapes.length || undefined,
|
|
104
|
+
typeReferenceTargets: nonEmptyArray(typeReferenceTargets),
|
|
105
|
+
typeReferenceTargetCount: typeReferenceTargets.length || undefined,
|
|
106
|
+
conditionalTypeCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'conditional-type') || undefined,
|
|
107
|
+
mappedTypeCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'mapped-type') || undefined,
|
|
108
|
+
indexedAccessTypeCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'indexed-access-type') || undefined,
|
|
109
|
+
keyofTypeOperatorCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'keyof-type-operator') || undefined,
|
|
110
|
+
templateLiteralTypeCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'template-literal-type') || undefined,
|
|
111
|
+
inferTypeCount: countAdvancedTypeShapeKind(advancedTypeShapes, 'infer-type') || undefined,
|
|
112
|
+
...enumShape,
|
|
113
|
+
...typeInferenceSyntax,
|
|
114
|
+
assignabilityOracleCount: assignabilityOracle ? 1 : undefined,
|
|
115
|
+
assignabilityOracleDirectionCount: assignabilityOracle?.directionCount,
|
|
116
|
+
assignabilityOracleHash: assignabilityOracle ? hashSemanticValue({ kind: 'frontier.lang.typescript.compilerPublicApiAssignabilityOracle.v1', assignabilityOracle }) : undefined,
|
|
117
|
+
assignabilityOracle,
|
|
118
|
+
...classApi
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function compilerTypeParameterRecords(checker, identitySymbol, location, ts) {
|
|
123
|
+
const declaration = (Array.isArray(identitySymbol?.declarations) ? identitySymbol.declarations : [])
|
|
124
|
+
.find((item) => Array.isArray(item?.typeParameters) && item.typeParameters.length > 0);
|
|
125
|
+
if (!declaration) return [];
|
|
126
|
+
return declaration.typeParameters.map((parameter, ordinal) => {
|
|
127
|
+
const parameterSymbol = safeCall(checker?.getSymbolAtLocation, checker, parameter.name) ?? parameter.symbol;
|
|
128
|
+
const parameterType = safeCall(checker?.getTypeAtLocation, checker, parameter.name ?? parameter);
|
|
129
|
+
const constraintType = parameter.constraint ? safeCall(checker?.getTypeFromTypeNode, checker, parameter.constraint) : undefined;
|
|
130
|
+
const defaultType = parameter.default ? safeCall(checker?.getTypeFromTypeNode, checker, parameter.default) : undefined;
|
|
131
|
+
return compactRecord({
|
|
132
|
+
name: stringValue(parameter.name?.escapedText ?? parameter.name?.text),
|
|
133
|
+
ordinal,
|
|
134
|
+
typeText: parameterType ? stringValue(safeCall(checker?.typeToString, checker, parameterType)) : undefined,
|
|
135
|
+
constraintTypeText: constraintType ? stringValue(safeCall(checker?.typeToString, checker, constraintType)) : undefined,
|
|
136
|
+
defaultTypeText: defaultType ? stringValue(safeCall(checker?.typeToString, checker, defaultType)) : undefined,
|
|
137
|
+
flags: numberValue(parameterSymbol?.flags),
|
|
138
|
+
hasConstraint: parameter.constraint ? true : undefined,
|
|
139
|
+
hasDefault: parameter.default ? true : undefined,
|
|
140
|
+
variance: typeParameterVariance(ts, parameter)
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function compilerSignatureRecords(checker, type, kind, location, ts) {
|
|
146
|
+
const signatures = safeCall(checker?.getSignaturesOfType, checker, type, kind);
|
|
147
|
+
if (!Array.isArray(signatures) || !signatures.length) return [];
|
|
148
|
+
return signatures.map((signature) => compactRecord({
|
|
149
|
+
signatureText: stringValue(safeCall(checker?.signatureToString, checker, signature)),
|
|
150
|
+
returnTypeText: compilerReturnTypeText(checker, signature),
|
|
151
|
+
parameters: nonEmptyArray(compilerSignatureParameterRecords(checker, signature, location, ts))
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function compilerSignatureParameterRecords(checker, signature, location, ts) {
|
|
156
|
+
const parameters = Array.isArray(signature?.parameters)
|
|
157
|
+
? signature.parameters
|
|
158
|
+
: safeCall(signature?.getParameters, signature);
|
|
159
|
+
if (!Array.isArray(parameters)) return [];
|
|
160
|
+
return parameters.map((parameter) => {
|
|
161
|
+
const parameterType = safeCall(checker?.getTypeOfSymbolAtLocation, checker, parameter, location);
|
|
162
|
+
return compactRecord({
|
|
163
|
+
name: stringValue(parameter.escapedName ?? parameter.name),
|
|
164
|
+
typeText: parameterType ? stringValue(safeCall(checker?.typeToString, checker, parameterType)) : undefined,
|
|
165
|
+
flags: numberValue(parameter.flags),
|
|
166
|
+
optional: hasSymbolFlag(parameter, ts, 'Optional')
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function compilerReturnTypeText(checker, signature) {
|
|
172
|
+
const returnType = safeCall(checker?.getReturnTypeOfSignature, checker, signature);
|
|
173
|
+
return returnType ? stringValue(safeCall(checker?.typeToString, checker, returnType)) : undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function compilerPropertyRecords(checker, type, location, ts) {
|
|
177
|
+
const properties = safeCall(checker?.getPropertiesOfType, checker, type);
|
|
178
|
+
if (!Array.isArray(properties) || !properties.length) return [];
|
|
179
|
+
return properties
|
|
180
|
+
.map((property) => {
|
|
181
|
+
const declaration = Array.isArray(property.declarations) ? property.declarations[0] : undefined;
|
|
182
|
+
const propertyType = safeCall(checker?.getTypeOfSymbolAtLocation, checker, property, declaration ?? location);
|
|
183
|
+
return compactRecord({
|
|
184
|
+
name: stringValue(property.escapedName ?? property.name),
|
|
185
|
+
typeText: propertyType ? stringValue(safeCall(checker?.typeToString, checker, propertyType)) : undefined,
|
|
186
|
+
flags: numberValue(property.flags),
|
|
187
|
+
optional: hasSymbolFlag(property, ts, 'Optional'),
|
|
188
|
+
readonly: compilerPropertyReadonly(property, ts),
|
|
189
|
+
declarations: Array.isArray(property.declarations) ? property.declarations.length : undefined
|
|
190
|
+
});
|
|
191
|
+
})
|
|
192
|
+
.sort((left, right) => String(left.name ?? '').localeCompare(String(right.name ?? '')));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function compilerIndexSignatureRecords(checker, type) {
|
|
196
|
+
const indexInfos = safeCall(checker?.getIndexInfosOfType, checker, type);
|
|
197
|
+
if (!Array.isArray(indexInfos) || !indexInfos.length) return [];
|
|
198
|
+
return indexInfos.map((info, ordinal) => compactRecord({
|
|
199
|
+
ordinal,
|
|
200
|
+
keyTypeText: info?.keyType ? stringValue(safeCall(checker?.typeToString, checker, info.keyType)) : undefined,
|
|
201
|
+
valueTypeText: info?.type ? stringValue(safeCall(checker?.typeToString, checker, info.type)) : undefined,
|
|
202
|
+
readonly: typeof info?.isReadonly === 'boolean' ? info.isReadonly : undefined,
|
|
203
|
+
declarationText: nodeText(info?.declaration)
|
|
204
|
+
})).sort((left, right) => String(left.keyTypeText ?? '').localeCompare(String(right.keyTypeText ?? '')));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function countAdvancedTypeShapeKind(records, kind) { return records.filter((record) => record.kind === kind).length; }
|
|
208
|
+
|
|
209
|
+
function safeCall(fn, receiver, ...args) {
|
|
210
|
+
if (typeof fn !== 'function') return undefined;
|
|
211
|
+
try { return fn.apply(receiver, args); } catch { return undefined; }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function stringValue(value) {
|
|
215
|
+
return value === undefined || value === null || value === '' ? undefined : String(value);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function numberValue(value) { return Number.isFinite(value) ? value : undefined; }
|
|
219
|
+
function compilerSymbolLocalName(symbol, node, ts) {
|
|
220
|
+
return isPrivateIdentifier(node, ts)
|
|
221
|
+
? nodeText(node)
|
|
222
|
+
: stringValue(symbol.escapedName ?? symbol.name);
|
|
223
|
+
}
|
|
224
|
+
function signatureKind(ts, name, fallback) { return numberValue(ts?.SignatureKind?.[name]) ?? fallback; }
|
|
225
|
+
function typeParameterVariance(ts, parameter) {
|
|
226
|
+
const modifiers = Array.isArray(parameter?.modifiers) ? parameter.modifiers : [];
|
|
227
|
+
const inKeyword = numberValue(ts?.SyntaxKind?.InKeyword);
|
|
228
|
+
const outKeyword = numberValue(ts?.SyntaxKind?.OutKeyword);
|
|
229
|
+
const hasIn = inKeyword !== undefined && modifiers.some((modifier) => modifier.kind === inKeyword);
|
|
230
|
+
const hasOut = outKeyword !== undefined && modifiers.some((modifier) => modifier.kind === outKeyword);
|
|
231
|
+
if (hasIn && hasOut) return 'in out';
|
|
232
|
+
if (hasIn) return 'in';
|
|
233
|
+
if (hasOut) return 'out';
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
function compilerPropertyReadonly(property, ts) {
|
|
237
|
+
const readonlyFlag = numberValue(ts?.ModifierFlags?.Readonly);
|
|
238
|
+
const modifierFlags = numberValue(safeCall(ts?.getDeclarationModifierFlagsFromSymbol, ts, property));
|
|
239
|
+
if (readonlyFlag !== undefined && modifierFlags !== undefined) return Boolean(modifierFlags & readonlyFlag);
|
|
240
|
+
const declarations = Array.isArray(property?.declarations) ? property.declarations : [];
|
|
241
|
+
const readonlyKeyword = numberValue(ts?.SyntaxKind?.ReadonlyKeyword);
|
|
242
|
+
if (readonlyKeyword === undefined || !declarations.length) return undefined;
|
|
243
|
+
return declarations.some((declaration) => (
|
|
244
|
+
Array.isArray(declaration?.modifiers)
|
|
245
|
+
&& declaration.modifiers.some((modifier) => modifier.kind === readonlyKeyword)
|
|
246
|
+
));
|
|
247
|
+
}
|
|
248
|
+
function hasSymbolFlag(symbol, ts, flagName) {
|
|
249
|
+
const flag = numberValue(ts?.SymbolFlags?.[flagName]);
|
|
250
|
+
return flag !== undefined && numberValue(symbol?.flags) !== undefined ? Boolean(symbol.flags & flag) : undefined;
|
|
251
|
+
}
|
|
252
|
+
function canonicalApiSignatureRecord(record) {
|
|
253
|
+
return compactRecord({
|
|
254
|
+
...record,
|
|
255
|
+
typeParameters: nonEmptyArray(arrayValue(record.typeParameters).map(({ flags: _flags, ...parameter }) => parameter)),
|
|
256
|
+
callSignatures: nonEmptyArray(arrayValue(record.callSignatures).map(canonicalSignatureRecord)),
|
|
257
|
+
constructSignatures: nonEmptyArray(arrayValue(record.constructSignatures).map(canonicalSignatureRecord)),
|
|
258
|
+
properties: nonEmptyArray(arrayValue(record.properties).map(({ flags: _flags, ...property }) => property)),
|
|
259
|
+
indexSignatures: nonEmptyArray(arrayValue(record.indexSignatures)),
|
|
260
|
+
typeReferenceTargets: nonEmptyArray(arrayValue(record.typeReferenceTargets).map(canonicalTypeReferenceTargetRecord))
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function canonicalTypeReferenceTargetRecord(target) {
|
|
264
|
+
return compactRecord({
|
|
265
|
+
kind: target.kind,
|
|
266
|
+
typeReferenceName: target.typeReferenceName,
|
|
267
|
+
targetStatus: target.targetStatus,
|
|
268
|
+
targetAliased: target.targetAliased,
|
|
269
|
+
targetSymbolName: target.targetSymbolName,
|
|
270
|
+
targetFullyQualifiedName: target.targetFullyQualifiedName,
|
|
271
|
+
targetSymbolFlags: target.targetSymbolFlags,
|
|
272
|
+
targetDeclarationKind: target.targetDeclarationKind,
|
|
273
|
+
typeArgumentCount: target.typeArgumentCount
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function canonicalSignatureRecord(signature) {
|
|
277
|
+
return compactRecord({
|
|
278
|
+
...signature,
|
|
279
|
+
parameters: nonEmptyArray(arrayValue(signature.parameters).map(({ flags: _flags, ...parameter }) => parameter))
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function nonEmptyArray(value) { return Array.isArray(value) && value.length ? value : undefined; }
|
|
283
|
+
function arrayValue(value) { return Array.isArray(value) ? value : []; }
|
|
284
|
+
function nodeText(node) { return stringValue(safeCall(node?.getText, node)); }
|
|
285
|
+
function isPrivateIdentifier(node, ts) {
|
|
286
|
+
const privateIdentifier = numberValue(ts?.SyntaxKind?.PrivateIdentifier);
|
|
287
|
+
return privateIdentifier !== undefined
|
|
288
|
+
? node?.kind === privateIdentifier
|
|
289
|
+
: nodeText(node)?.startsWith('#') === true;
|
|
290
|
+
}
|
|
291
|
+
function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
|
|
292
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
293
|
+
|
|
294
|
+
export { typeScriptCompilerSymbolRecordForNode };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
import { spanFromTypeScriptNode } from './spanFromTypeScriptNode.js';
|
|
3
|
+
|
|
4
|
+
function compilerTypeReferenceTargets(checker, identitySymbol, location, ts) {
|
|
5
|
+
const declarations = Array.isArray(identitySymbol?.declarations) ? identitySymbol.declarations : [];
|
|
6
|
+
const records = [];
|
|
7
|
+
for (const declaration of declarations) {
|
|
8
|
+
visitTypeNodes(ts, declaration, (node) => {
|
|
9
|
+
if (!isSyntaxKind(ts, node, 'TypeReference')) return;
|
|
10
|
+
const record = typeReferenceTargetRecord(checker, node, location, ts);
|
|
11
|
+
if (record) records.push(record);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return uniqueRecords(records, (record) => [
|
|
15
|
+
record.typeReferenceName,
|
|
16
|
+
record.nodeText,
|
|
17
|
+
record.targetFullyQualifiedName,
|
|
18
|
+
record.targetDeclarationTextHash
|
|
19
|
+
].join('\0'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function typeReferenceTargetRecord(checker, node, location, ts) {
|
|
23
|
+
const symbol = safeCall(checker?.getSymbolAtLocation, checker, node.typeName);
|
|
24
|
+
const aliasedSymbol = safeCall(checker?.getAliasedSymbol, checker, symbol);
|
|
25
|
+
const targetSymbol = aliasedSymbol && aliasedSymbol !== symbol ? aliasedSymbol : symbol;
|
|
26
|
+
const declaration = targetDeclaration(targetSymbol);
|
|
27
|
+
if (!targetSymbol || !declaration) return undefined;
|
|
28
|
+
const referenceSpan = spanForNode(node, location);
|
|
29
|
+
const declarationSpan = spanForNode(declaration, location);
|
|
30
|
+
const declarationTextHash = declarationSourceHash(declaration, declarationSpan);
|
|
31
|
+
const targetSymbolIdentityHash = targetSymbol ? hashSemanticValue({
|
|
32
|
+
kind: 'frontier.lang.typescript.compilerTypeReferenceTargetSymbol.v1',
|
|
33
|
+
name: stringValue(targetSymbol.escapedName ?? targetSymbol.name),
|
|
34
|
+
fullyQualifiedName: stringValue(safeCall(checker?.getFullyQualifiedName, checker, targetSymbol)),
|
|
35
|
+
flags: numberValue(targetSymbol.flags),
|
|
36
|
+
declarationKind: syntaxKindName(ts, declaration?.kind),
|
|
37
|
+
declarationSpan,
|
|
38
|
+
declarationTextHash
|
|
39
|
+
}) : undefined;
|
|
40
|
+
const targetProof = compactRecord({
|
|
41
|
+
kind: 'frontier.lang.typescript.compilerPublicApiTypeReferenceTargetProof.v1',
|
|
42
|
+
typeReferenceName: nodeText(node.typeName),
|
|
43
|
+
targetSymbolName: stringValue(targetSymbol?.escapedName ?? targetSymbol?.name),
|
|
44
|
+
targetFullyQualifiedName: stringValue(targetSymbol ? safeCall(checker?.getFullyQualifiedName, checker, targetSymbol) : undefined),
|
|
45
|
+
targetSymbolFlags: numberValue(targetSymbol?.flags),
|
|
46
|
+
targetDeclarationKind: syntaxKindName(ts, declaration?.kind),
|
|
47
|
+
targetDeclarationSourcePath: declarationSpan?.path ?? sourcePathForNode(declaration),
|
|
48
|
+
targetDeclarationSpan: declarationSpan,
|
|
49
|
+
targetDeclarationTextHash: declarationTextHash,
|
|
50
|
+
targetSymbolIdentityHash
|
|
51
|
+
});
|
|
52
|
+
return compactRecord({
|
|
53
|
+
kind: 'type-reference-target',
|
|
54
|
+
syntaxKind: syntaxKindName(ts, node.kind),
|
|
55
|
+
nodeText: nodeText(node),
|
|
56
|
+
typeText: typeTextFromTypeNode(checker, node, location),
|
|
57
|
+
typeReferenceName: nodeText(node.typeName),
|
|
58
|
+
sourceSpan: referenceSpan,
|
|
59
|
+
typeArgumentCount: arrayValue(node.typeArguments).length || undefined,
|
|
60
|
+
targetStatus: 'resolved',
|
|
61
|
+
targetAliased: aliasedSymbol && aliasedSymbol !== symbol ? true : undefined,
|
|
62
|
+
targetSymbolName: targetProof.targetSymbolName,
|
|
63
|
+
targetFullyQualifiedName: targetProof.targetFullyQualifiedName,
|
|
64
|
+
targetSymbolFlags: targetProof.targetSymbolFlags,
|
|
65
|
+
targetSymbolIdentityHash,
|
|
66
|
+
targetDeclarationKind: targetProof.targetDeclarationKind,
|
|
67
|
+
targetDeclarationSourcePath: targetProof.targetDeclarationSourcePath,
|
|
68
|
+
targetDeclarationSpan: declarationSpan,
|
|
69
|
+
targetDeclarationTextHash: declarationTextHash,
|
|
70
|
+
typeReferenceTargetProofHash: hashSemanticValue(targetProof),
|
|
71
|
+
autoMergeClaim: false,
|
|
72
|
+
semanticEquivalenceClaim: false,
|
|
73
|
+
runtimeEquivalenceClaim: false
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function targetDeclaration(symbol) {
|
|
78
|
+
return symbol?.valueDeclaration ?? arrayValue(symbol?.declarations)[0];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function declarationSourceHash(node, span) {
|
|
82
|
+
const text = nodeText(node);
|
|
83
|
+
if (!text) return undefined;
|
|
84
|
+
return hashSemanticValue({
|
|
85
|
+
kind: 'frontier.lang.typescript.compilerTypeReferenceTargetDeclarationSource.v1',
|
|
86
|
+
sourcePath: span?.path ?? sourcePathForNode(node),
|
|
87
|
+
span,
|
|
88
|
+
text
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function spanForNode(node, fallback) {
|
|
93
|
+
if (!node || typeof node !== 'object') return undefined;
|
|
94
|
+
const sourceFile = safeCall(node.getSourceFile, node) ?? safeCall(fallback?.getSourceFile, fallback);
|
|
95
|
+
return sourceFile ? spanFromTypeScriptNode(node, sourceFile) : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function sourcePathForNode(node) {
|
|
99
|
+
return stringValue(safeCall(node?.getSourceFile, node)?.fileName);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function visitTypeNodes(ts, node, visit) {
|
|
103
|
+
if (!node || typeof node !== 'object') return;
|
|
104
|
+
visit(node);
|
|
105
|
+
if (typeof ts?.forEachChild === 'function') {
|
|
106
|
+
ts.forEachChild(node, (child) => visitTypeNodes(ts, child, visit));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const value of Object.values(node)) {
|
|
110
|
+
if (Array.isArray(value)) value.forEach((child) => visitTypeNodes(ts, child, visit));
|
|
111
|
+
else if (value && typeof value === 'object' && Number.isFinite(value.kind)) visitTypeNodes(ts, value, visit);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function typeTextFromTypeNode(checker, node, location) {
|
|
116
|
+
const type = safeCall(checker?.getTypeFromTypeNode, checker, node) ?? safeCall(checker?.getTypeAtLocation, checker, node ?? location);
|
|
117
|
+
return type ? stringValue(safeCall(checker?.typeToString, checker, type)) : nodeText(node);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function syntaxKind(ts, name) { return numberValue(ts?.SyntaxKind?.[name]); }
|
|
121
|
+
function isSyntaxKind(ts, node, name) { return node?.kind === syntaxKind(ts, name); }
|
|
122
|
+
function syntaxKindName(ts, kind) { return stringValue(ts?.SyntaxKind?.[kind]) ?? (Number.isFinite(kind) ? String(kind) : undefined); }
|
|
123
|
+
function nodeText(node) { return stringValue(safeCall(node?.getText, node)); }
|
|
124
|
+
function safeCall(fn, receiver, ...args) {
|
|
125
|
+
if (typeof fn !== 'function') return undefined;
|
|
126
|
+
try { return fn.apply(receiver, args); } catch { return undefined; }
|
|
127
|
+
}
|
|
128
|
+
function stringValue(value) { return value === undefined || value === null || value === '' ? undefined : String(value); }
|
|
129
|
+
function numberValue(value) { return Number.isFinite(value) ? value : undefined; }
|
|
130
|
+
function arrayValue(value) { return Array.isArray(value) ? value : []; }
|
|
131
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
132
|
+
function uniqueRecords(records, keyFn) {
|
|
133
|
+
const seen = new Set();
|
|
134
|
+
return records.filter((record) => {
|
|
135
|
+
const key = keyFn(record);
|
|
136
|
+
if (seen.has(key)) return false;
|
|
137
|
+
seen.add(key);
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { compilerTypeReferenceTargets };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import{hashSemanticValue}from'@shapeshift-labs/frontier-lang-kernel';
|
|
1
|
+
import{hashSemanticValue}from'@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import{declarationRecord}from'./declarationRecord.js';import{namedDeclaration}from'./namedDeclaration.js';import{stringFromTsExpression}from'./stringFromTsExpression.js';import{typeScriptExportedDeclarationEntries}from'./typeScriptExportedDeclarationEntries.js';import{typeScriptModuleDeclarationEntries}from'./typeScriptModuleDeclarationEntries.js';
|
|
3
|
+
import{typeScriptCompilerSymbolRecordForNode}from'./typeScriptCompilerSymbolIdentity.js';
|
|
3
4
|
export function typeScriptDeclaration(node, kind, nativeNodeId, input, options = {}) {
|
|
4
5
|
const enrich = (declaration, symbolNode = node.name ?? node) => enrichTypeScriptDeclaration(node, symbolNode, declaration, input, options);
|
|
5
6
|
const moduleEntries = typeScriptModuleDeclarationEntries(node, kind, nativeNodeId, input);
|
|
@@ -41,51 +42,22 @@ function moduleDeclaration(input, nativeNodeId, node) {
|
|
|
41
42
|
|
|
42
43
|
function enrichTypeScriptDeclaration(node, symbolNode, declaration, input, options) {
|
|
43
44
|
if (!declaration) return declaration;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
if (!symbol) return declaration;
|
|
47
|
-
const aliasedSymbol = safeCall(checker?.getAliasedSymbol, checker, symbol);
|
|
48
|
-
const targetSymbol = aliasedSymbol && aliasedSymbol !== symbol ? aliasedSymbol : undefined;
|
|
49
|
-
const identitySymbol = targetSymbol ?? symbol;
|
|
50
|
-
const fullyQualifiedName = stringValue(safeCall(checker?.getFullyQualifiedName, checker, identitySymbol));
|
|
51
|
-
const localName = stringValue(symbol.escapedName ?? symbol.name) ?? declaration.name;
|
|
52
|
-
const targetName = targetSymbol ? stringValue(targetSymbol.escapedName ?? targetSymbol.name) : undefined;
|
|
53
|
-
const identity = fullyQualifiedName ?? targetName ?? localName;
|
|
54
|
-
const compilerSymbol = compactRecord({
|
|
55
|
-
parser: options.parser,
|
|
56
|
-
localName,
|
|
57
|
-
targetName,
|
|
58
|
-
fullyQualifiedName,
|
|
59
|
-
flags: numberValue(symbol.flags),
|
|
60
|
-
targetFlags: numberValue(targetSymbol?.flags),
|
|
61
|
-
declarations: Array.isArray(identitySymbol.declarations) ? identitySymbol.declarations.length : undefined,
|
|
62
|
-
aliased: Boolean(targetSymbol)
|
|
63
|
-
});
|
|
45
|
+
const compiler = typeScriptCompilerSymbolRecordForNode(symbolNode, input, options, node.name, { importRole: declaration.role === 'import' });
|
|
46
|
+
if (!compiler) return declaration;
|
|
64
47
|
return {
|
|
65
48
|
...declaration,
|
|
66
|
-
symbolId:
|
|
67
|
-
signatureHash: hashSemanticValue([input.language, declaration.symbolKind, identity, compilerSymbol]),
|
|
49
|
+
symbolId: compiler.symbolId,
|
|
50
|
+
signatureHash: hashSemanticValue([input.language, declaration.symbolKind, compiler.identity, compiler.compilerSymbol, compiler.compilerType]),
|
|
68
51
|
metadata: {
|
|
69
52
|
...declaration.metadata,
|
|
70
|
-
compilerSymbol,
|
|
71
|
-
compilerSymbolIdentityHash:
|
|
53
|
+
compilerSymbol: compiler.compilerSymbol,
|
|
54
|
+
compilerSymbolIdentityHash: compiler.compilerSymbolIdentityHash,
|
|
55
|
+
compilerType: compiler.compilerType,
|
|
56
|
+
compilerTypeIdentityHash: compiler.compilerTypeIdentityHash
|
|
72
57
|
}
|
|
73
58
|
};
|
|
74
59
|
}
|
|
75
60
|
|
|
76
|
-
function safeCall(fn, receiver, ...args) {
|
|
77
|
-
if (typeof fn !== 'function') return undefined;
|
|
78
|
-
try { return fn.apply(receiver, args); } catch { return undefined; }
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function stringValue(value) {
|
|
82
|
-
return value === undefined || value === null || value === '' ? undefined : String(value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function numberValue(value) {
|
|
86
|
-
return Number.isFinite(value) ? value : undefined;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
61
|
function compactRecord(record) {
|
|
90
62
|
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
91
63
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import{idFragment}from'../../native-import-utils.js';
|
|
2
|
-
import{declarationRecord}from'./declarationRecord.js';import{identifierName}from'./identifierName.js';import{stringFromTsExpression}from'./stringFromTsExpression.js';
|
|
2
|
+
import{declarationRecord}from'./declarationRecord.js';import{dynamicImportExpressionMetadata}from'./dynamicImportExpressionMetadata.js';import{identifierName}from'./identifierName.js';import{hostModuleDependencyMetadata}from'./importMetaUrlDependencyMetadata.js';import{moduleImportAttributeMetadata}from'./moduleImportAttributeMetadata.js';import{stringFromTsExpression}from'./stringFromTsExpression.js';
|
|
3
3
|
export function typeScriptModuleDeclarationEntries(node, kind, nativeNodeId, input) {
|
|
4
4
|
if (kind === 'ImportDeclaration') return importDeclarationEntries(node, nativeNodeId, input);
|
|
5
5
|
if (kind === 'ImportEqualsDeclaration') return importEqualsDeclarationEntries(node, nativeNodeId, input);
|
|
6
|
-
if (kind === '
|
|
7
|
-
if (kind === '
|
|
6
|
+
if (kind === 'CallExpression' && isDynamicImportCall(node)) return dynamicImportExpressionEntries(node, nativeNodeId, input);
|
|
7
|
+
if (kind === 'CallExpression' || kind === 'NewExpression') { const dependencies = hostModuleDependencyMetadata(node, { kind }); if (dependencies.length) return dependencies.flatMap((dependency) => importModuleEntries(input, nativeNodeId, dependency.moduleSpecifier, 'HostModuleDependency', [], dependency.metadata)); }
|
|
8
|
+
if (kind === 'ExportDeclaration') return exportDeclarationEntries(node, nativeNodeId, input); if (kind === 'ExportAssignment') return exportAssignmentEntries(node, nativeNodeId, input);
|
|
8
9
|
return undefined;
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -16,7 +17,8 @@ function importDeclarationEntries(node, nativeNodeId, input) {
|
|
|
16
17
|
return importModuleEntries(input, nativeNodeId, moduleSpecifier, 'ImportDeclaration', bindings, {
|
|
17
18
|
typeOnly,
|
|
18
19
|
sideEffectOnly: bindings.length === 0,
|
|
19
|
-
importKind: bindings.length === 0 ? 'side-effect' : 'module'
|
|
20
|
+
importKind: bindings.length === 0 ? 'side-effect' : 'module',
|
|
21
|
+
...moduleImportAttributeMetadata(node)
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -34,6 +36,16 @@ function importEqualsDeclarationEntries(node, nativeNodeId, input) {
|
|
|
34
36
|
}], { typeOnly, importKind: 'commonjs-require' });
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
function dynamicImportExpressionEntries(node, nativeNodeId, input) {
|
|
40
|
+
const firstArgument = node.arguments?.[0], moduleSpecifier = firstArgument ? stringLiteralFromTsExpression(firstArgument) ?? '<dynamic-import>' : undefined;
|
|
41
|
+
if (!moduleSpecifier) return [];
|
|
42
|
+
return importModuleEntries(input, nativeNodeId, moduleSpecifier, 'DynamicImportExpression', [], {
|
|
43
|
+
importKind: 'dynamic-import',
|
|
44
|
+
dynamicImport: true, ...dynamicImportExpressionMetadata(firstArgument, moduleSpecifier),
|
|
45
|
+
...moduleImportAttributeMetadata(node)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
function exportDeclarationEntries(node, nativeNodeId, input) {
|
|
38
50
|
const moduleSpecifier = stringFromTsExpression(node.moduleSpecifier);
|
|
39
51
|
const typeOnly = Boolean(node.isTypeOnly);
|
|
@@ -46,14 +58,16 @@ function exportDeclarationEntries(node, nativeNodeId, input) {
|
|
|
46
58
|
reexport: true,
|
|
47
59
|
exportStar,
|
|
48
60
|
namespaceReExport,
|
|
49
|
-
importKind: exportStar ? 'reexport' : 'reexport'
|
|
61
|
+
importKind: exportStar ? 'reexport' : 'reexport',
|
|
62
|
+
...moduleImportAttributeMetadata(node)
|
|
50
63
|
}) : []),
|
|
51
64
|
...exportModuleEntries(input, nativeNodeId, moduleSpecifier, bindings, {
|
|
52
65
|
typeOnly,
|
|
53
66
|
exportStar,
|
|
54
67
|
reExport: Boolean(moduleSpecifier),
|
|
55
68
|
namespaceReExport,
|
|
56
|
-
exportKind: exportStar ? 'export-star' : 'named'
|
|
69
|
+
exportKind: exportStar ? 'export-star' : 'named',
|
|
70
|
+
...moduleImportAttributeMetadata(node)
|
|
57
71
|
})
|
|
58
72
|
];
|
|
59
73
|
}
|
|
@@ -177,10 +191,10 @@ function importModuleEntries(input, nativeNodeId, moduleSpecifier, _languageKind
|
|
|
177
191
|
metadata: moduleMetadata('typescript-import', bindings, metadata)
|
|
178
192
|
})
|
|
179
193
|
};
|
|
180
|
-
return [moduleEntry, ...bindings.map((binding) => importBindingEntry(input, nativeNodeId, moduleSpecifier, binding))];
|
|
194
|
+
return [moduleEntry, ...bindings.map((binding) => importBindingEntry(input, nativeNodeId, moduleSpecifier, binding, metadata))];
|
|
181
195
|
}
|
|
182
196
|
|
|
183
|
-
function importBindingEntry(input, nativeNodeId, moduleSpecifier, binding) {
|
|
197
|
+
function importBindingEntry(input, nativeNodeId, moduleSpecifier, binding, metadata = {}) {
|
|
184
198
|
const declaration = compactRecord({
|
|
185
199
|
...declarationRecord(input, nativeNodeId, binding.localName, 'import', 'import'),
|
|
186
200
|
symbolId: `symbol:${input.language}:import:${idFragment(`${moduleSpecifier}:${binding.localName}:${binding.importedName}`)}`,
|
|
@@ -202,7 +216,7 @@ function importBindingEntry(input, nativeNodeId, moduleSpecifier, binding) {
|
|
|
202
216
|
namespace: binding.namespace,
|
|
203
217
|
importKind: binding.importKind,
|
|
204
218
|
isTypeOnly: binding.isTypeOnly,
|
|
205
|
-
typeOnly: binding.isTypeOnly
|
|
219
|
+
typeOnly: binding.isTypeOnly, hasImportAttributes: metadata.hasImportAttributes, importAttributeCount: metadata.importAttributeCount, importAttributeKeys: metadata.importAttributeKeys, importAttributeHash: metadata.importAttributeHash, importAttributes: metadata.importAttributes
|
|
206
220
|
})
|
|
207
221
|
});
|
|
208
222
|
return { declaration, symbolNode: binding.symbolNode };
|
|
@@ -225,10 +239,10 @@ function exportModuleEntries(input, nativeNodeId, moduleSpecifier, bindings, met
|
|
|
225
239
|
metadata: moduleMetadata('typescript-export', bindings, metadata)
|
|
226
240
|
})
|
|
227
241
|
};
|
|
228
|
-
return [statement, ...bindings.map((binding) => exportBindingEntry(input, nativeNodeId, moduleSpecifier, binding))];
|
|
242
|
+
return [statement, ...bindings.map((binding) => exportBindingEntry(input, nativeNodeId, moduleSpecifier, binding, metadata))];
|
|
229
243
|
}
|
|
230
244
|
|
|
231
|
-
function exportBindingEntry(input, nativeNodeId, moduleSpecifier, binding) {
|
|
245
|
+
function exportBindingEntry(input, nativeNodeId, moduleSpecifier, binding, metadata = {}) {
|
|
232
246
|
const declaration = compactRecord({
|
|
233
247
|
...declarationRecord(input, nativeNodeId, binding.exportedName, 'export', 'export'),
|
|
234
248
|
symbolId: `symbol:${input.language}:export:${idFragment(`${moduleSpecifier ?? 'local'}:${binding.exportedName}:${binding.localName}`)}`,
|
|
@@ -254,7 +268,7 @@ function exportBindingEntry(input, nativeNodeId, moduleSpecifier, binding) {
|
|
|
254
268
|
isTypeOnly: binding.isTypeOnly,
|
|
255
269
|
typeOnly: binding.isTypeOnly,
|
|
256
270
|
reExport: binding.reExport,
|
|
257
|
-
publicContract: true
|
|
271
|
+
publicContract: true, hasImportAttributes: metadata.hasImportAttributes, importAttributeCount: metadata.importAttributeCount, importAttributeKeys: metadata.importAttributeKeys, importAttributeHash: metadata.importAttributeHash, importAttributes: metadata.importAttributes
|
|
258
272
|
})
|
|
259
273
|
});
|
|
260
274
|
return { declaration, symbolNode: binding.symbolNode };
|
|
@@ -269,7 +283,13 @@ function moduleMetadata(scan, bindings, metadata) {
|
|
|
269
283
|
exportKind: metadata.exportKind,
|
|
270
284
|
isTypeOnly: metadata.typeOnly,
|
|
271
285
|
typeOnly: metadata.typeOnly,
|
|
272
|
-
sideEffectOnly: metadata.sideEffectOnly,
|
|
286
|
+
sideEffectOnly: metadata.sideEffectOnly, dynamicImport: metadata.dynamicImport,
|
|
287
|
+
dynamicImportSpecifierKind: metadata.dynamicImportSpecifierKind, dynamicImportExpressionText: metadata.dynamicImportExpressionText, dynamicImportExpressionHash: metadata.dynamicImportExpressionHash, dynamicImportStaticSpecifierEvidence: metadata.dynamicImportStaticSpecifierEvidence, dynamicImportRuntimeResolutionClaim: metadata.dynamicImportRuntimeResolutionClaim, dynamicImportResolutionProofRequired: metadata.dynamicImportResolutionProofRequired, hostDependency: metadata.hostDependency, hostDependencyKind: metadata.hostDependencyKind, hostDependencyBase: metadata.hostDependencyBase, hostDependencyExpressionText: metadata.hostDependencyExpressionText, hostDependencyExpressionHash: metadata.hostDependencyExpressionHash, hostDependencyStaticSpecifierEvidence: metadata.hostDependencyStaticSpecifierEvidence, hostDependencyRuntimeResolutionClaim: metadata.hostDependencyRuntimeResolutionClaim, hostDependencyResolutionProofRequired: metadata.hostDependencyResolutionProofRequired,
|
|
288
|
+
hasImportAttributes: metadata.hasImportAttributes,
|
|
289
|
+
importAttributeCount: metadata.importAttributeCount,
|
|
290
|
+
importAttributeKeys: metadata.importAttributeKeys,
|
|
291
|
+
importAttributeHash: metadata.importAttributeHash,
|
|
292
|
+
importAttributes: metadata.importAttributes,
|
|
273
293
|
reexport: metadata.reexport,
|
|
274
294
|
reExport: metadata.reExport,
|
|
275
295
|
namespaceReExport: metadata.namespaceReExport,
|
|
@@ -278,6 +298,23 @@ function moduleMetadata(scan, bindings, metadata) {
|
|
|
278
298
|
});
|
|
279
299
|
}
|
|
280
300
|
|
|
281
|
-
function compactRecord(record) {
|
|
282
|
-
|
|
301
|
+
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
302
|
+
|
|
303
|
+
function isDynamicImportCall(node) {
|
|
304
|
+
return Array.isArray(node?.arguments) && node.arguments.length > 0 && typeScriptExpressionText(node.expression) === 'import';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function typeScriptExpressionText(node) {
|
|
308
|
+
if (!node) return undefined;
|
|
309
|
+
if (typeof node.getText === 'function') {
|
|
310
|
+
try { return node.getText(); } catch {}
|
|
311
|
+
}
|
|
312
|
+
if (typeof node.kindName === 'string') return node.kindName === 'ImportKeyword' ? 'import' : node.kindName;
|
|
313
|
+
if (node.kind === 'ImportKeyword') return 'import';
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function stringLiteralFromTsExpression(node) {
|
|
318
|
+
if (!node) return undefined; if (typeof node.value === 'string') return node.value;
|
|
319
|
+
const rawText = typeof node.text === 'string' && typeof node.escapedText !== 'string' ? typeScriptExpressionText(node) : undefined; return rawText && /^['"`]/.test(rawText) ? node.text : undefined;
|
|
283
320
|
}
|