@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,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findMatchingParen,
|
|
3
|
+
identifierRegExp,
|
|
4
|
+
namespacesForDeclarationKind,
|
|
5
|
+
nextSignificantCharIndex,
|
|
6
|
+
typeNamespace,
|
|
7
|
+
uniqueBindings,
|
|
8
|
+
valueNamespace
|
|
9
|
+
} from './js-ts-semantic-scope-use-def-utils.js';
|
|
10
|
+
import {
|
|
11
|
+
findStatementBoundary,
|
|
12
|
+
hasTypeAliasAssignment,
|
|
13
|
+
nextIdentifierToken
|
|
14
|
+
} from './js-ts-semantic-scope-use-def-scan.js';
|
|
15
|
+
|
|
16
|
+
const bindingKeywordKinds = Object.freeze({
|
|
17
|
+
function: 'function',
|
|
18
|
+
class: 'class',
|
|
19
|
+
interface: 'interface',
|
|
20
|
+
type: 'type',
|
|
21
|
+
enum: 'enum',
|
|
22
|
+
namespace: 'namespace',
|
|
23
|
+
module: 'module'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function collectBindings(code, tokens, depthAt) {
|
|
27
|
+
const bindings = [];
|
|
28
|
+
collectImportBindings(code, bindings, depthAt);
|
|
29
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
30
|
+
const token = tokens[index];
|
|
31
|
+
if (bindingKeywordKinds[token.value]) {
|
|
32
|
+
collectDeclarationBinding(code, tokens, index, bindings, depthAt);
|
|
33
|
+
if (token.value === 'function') collectFunctionParameters(code, token, bindings, depthAt);
|
|
34
|
+
} else if (token.value === 'const' || token.value === 'let' || token.value === 'var') {
|
|
35
|
+
collectVariableBindings(code, token, bindings, depthAt);
|
|
36
|
+
} else if (token.value === 'catch') {
|
|
37
|
+
collectCatchBinding(code, token, bindings, depthAt);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
collectArrowFunctionBindings(code, bindings, depthAt);
|
|
41
|
+
return uniqueBindings(bindings);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function collectDeclarationBinding(code, tokens, index, bindings, depthAt) {
|
|
45
|
+
const keyword = tokens[index];
|
|
46
|
+
const kind = bindingKeywordKinds[keyword.value];
|
|
47
|
+
const name = nextIdentifierToken(tokens, index + 1);
|
|
48
|
+
if (!name || !identifierRegExp.test(name.value)) return;
|
|
49
|
+
if (kind === 'type' && !hasTypeAliasAssignment(code, name.end)) return;
|
|
50
|
+
bindings.push({
|
|
51
|
+
kind,
|
|
52
|
+
name: name.value,
|
|
53
|
+
start: name.start,
|
|
54
|
+
end: name.end,
|
|
55
|
+
depth: depthAt[name.start] ?? 0,
|
|
56
|
+
namespaces: namespacesForDeclarationKind(kind)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function collectFunctionParameters(code, functionToken, bindings, depthAt) {
|
|
61
|
+
const open = code.indexOf('(', functionToken.end);
|
|
62
|
+
if (open === -1) return;
|
|
63
|
+
const close = findMatchingParen(code, open);
|
|
64
|
+
if (close === -1) return;
|
|
65
|
+
const bodyStart = nextSignificantCharIndex(code, close + 1);
|
|
66
|
+
if (bodyStart === -1 || code[bodyStart] !== '{') return;
|
|
67
|
+
collectParameterListBindings(code.slice(open + 1, close), open + 1, bindings, depthAt, 'param');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function collectVariableBindings(code, token, bindings, depthAt) {
|
|
71
|
+
const end = findStatementBoundary(code, token.end);
|
|
72
|
+
const text = code.slice(token.end, end);
|
|
73
|
+
const bindingDepth = depthAt[token.start] ?? 0;
|
|
74
|
+
for (const declarator of splitTopLevelComma(text, token.end)) {
|
|
75
|
+
collectVariableDeclaratorBinding(declarator.text, declarator.offset, token.value, bindings, depthAt, bindingDepth);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function collectVariableDeclaratorBinding(text, baseOffset, kind, bindings, depthAt, bindingDepth) {
|
|
80
|
+
const assignment = topLevelCharIndex(text, '=');
|
|
81
|
+
const pattern = assignment === -1 ? text : text.slice(0, assignment);
|
|
82
|
+
collectBindingPatternBindings(pattern, baseOffset, kind, bindings, depthAt, bindingDepth);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function collectBindingPatternBindings(text, baseOffset, kind, bindings, depthAt, bindingDepth) {
|
|
86
|
+
const start = firstSignificantIndex(text);
|
|
87
|
+
if (start === -1) return;
|
|
88
|
+
if (text.slice(start).startsWith('...')) {
|
|
89
|
+
collectBindingPatternBindings(text.slice(start + 3), baseOffset + start + 3, kind, bindings, depthAt, bindingDepth);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const char = text[start];
|
|
93
|
+
if (char === '{') {
|
|
94
|
+
const end = findMatchingDelimiter(text, start, '{', '}');
|
|
95
|
+
if (end !== -1) collectObjectPatternBindings(text.slice(start + 1, end), baseOffset + start + 1, kind, bindings, depthAt, bindingDepth);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (char === '[') {
|
|
99
|
+
const end = findMatchingDelimiter(text, start, '[', ']');
|
|
100
|
+
if (end !== -1) collectArrayPatternBindings(text.slice(start + 1, end), baseOffset + start + 1, kind, bindings, depthAt, bindingDepth);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
collectIdentifierBinding(text, baseOffset, start, kind, bindings, depthAt, bindingDepth);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function collectObjectPatternBindings(text, baseOffset, kind, bindings, depthAt, bindingDepth) {
|
|
107
|
+
for (const property of splitTopLevelComma(text, baseOffset)) {
|
|
108
|
+
const start = firstSignificantIndex(property.text);
|
|
109
|
+
if (start === -1) continue;
|
|
110
|
+
if (property.text.slice(start).startsWith('...')) {
|
|
111
|
+
collectBindingPatternBindings(property.text.slice(start + 3), property.offset + start + 3, kind, bindings, depthAt, bindingDepth);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const colon = topLevelCharIndex(property.text, ':');
|
|
115
|
+
if (colon !== -1) {
|
|
116
|
+
collectBindingPatternBindings(property.text.slice(colon + 1), property.offset + colon + 1, kind, bindings, depthAt, bindingDepth);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
collectIdentifierBinding(property.text, property.offset, start, kind, bindings, depthAt, bindingDepth);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function collectArrayPatternBindings(text, baseOffset, kind, bindings, depthAt, bindingDepth) {
|
|
124
|
+
for (const element of splitTopLevelComma(text, baseOffset)) {
|
|
125
|
+
const start = firstSignificantIndex(element.text);
|
|
126
|
+
if (start === -1) continue;
|
|
127
|
+
if (element.text.slice(start).startsWith('...')) {
|
|
128
|
+
collectBindingPatternBindings(element.text.slice(start + 3), element.offset + start + 3, kind, bindings, depthAt, bindingDepth);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
collectBindingPatternBindings(element.text, element.offset, kind, bindings, depthAt, bindingDepth);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function collectIdentifierBinding(text, baseOffset, start, kind, bindings, depthAt, bindingDepth) {
|
|
136
|
+
const match = /^[A-Za-z_$][\w$]*/.exec(text.slice(start));
|
|
137
|
+
if (!match) return;
|
|
138
|
+
const name = match[0];
|
|
139
|
+
const offset = baseOffset + start;
|
|
140
|
+
bindings.push({
|
|
141
|
+
kind,
|
|
142
|
+
name,
|
|
143
|
+
start: offset,
|
|
144
|
+
end: offset + name.length,
|
|
145
|
+
depth: bindingDepth ?? depthAt[offset] ?? 0,
|
|
146
|
+
namespaces: [valueNamespace]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function splitTopLevelComma(text, baseOffset) {
|
|
151
|
+
const parts = [];
|
|
152
|
+
let start = 0;
|
|
153
|
+
const depth = { brace: 0, bracket: 0, paren: 0 };
|
|
154
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
155
|
+
updateDelimiterDepth(depth, text[index]);
|
|
156
|
+
if (text[index] === ',' && depth.brace === 0 && depth.bracket === 0 && depth.paren === 0) {
|
|
157
|
+
parts.push({ text: text.slice(start, index), offset: baseOffset + start });
|
|
158
|
+
start = index + 1;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
parts.push({ text: text.slice(start), offset: baseOffset + start });
|
|
162
|
+
return parts;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function topLevelCharIndex(text, target) {
|
|
166
|
+
const depth = { brace: 0, bracket: 0, paren: 0 };
|
|
167
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
168
|
+
if (text[index] === target && depth.brace === 0 && depth.bracket === 0 && depth.paren === 0) return index;
|
|
169
|
+
updateDelimiterDepth(depth, text[index]);
|
|
170
|
+
}
|
|
171
|
+
return -1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function findMatchingDelimiter(text, open, openChar, closeChar) {
|
|
175
|
+
let depth = 0;
|
|
176
|
+
for (let index = open; index < text.length; index += 1) {
|
|
177
|
+
if (text[index] === openChar) depth += 1;
|
|
178
|
+
else if (text[index] === closeChar) {
|
|
179
|
+
depth -= 1;
|
|
180
|
+
if (depth === 0) return index;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return -1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function updateDelimiterDepth(depth, char) {
|
|
187
|
+
if (char === '{') depth.brace += 1;
|
|
188
|
+
else if (char === '}') depth.brace = Math.max(0, depth.brace - 1);
|
|
189
|
+
else if (char === '[') depth.bracket += 1;
|
|
190
|
+
else if (char === ']') depth.bracket = Math.max(0, depth.bracket - 1);
|
|
191
|
+
else if (char === '(') depth.paren += 1;
|
|
192
|
+
else if (char === ')') depth.paren = Math.max(0, depth.paren - 1);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function firstSignificantIndex(text) {
|
|
196
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
197
|
+
if (!/\s/.test(text[index])) return index;
|
|
198
|
+
}
|
|
199
|
+
return -1;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function collectCatchBinding(code, token, bindings, depthAt) {
|
|
203
|
+
const open = nextSignificantCharIndex(code, token.end);
|
|
204
|
+
if (open === -1 || code[open] !== '(') return;
|
|
205
|
+
const close = findMatchingParen(code, open);
|
|
206
|
+
if (close === -1) return;
|
|
207
|
+
const text = code.slice(open + 1, close).trim();
|
|
208
|
+
if (!identifierRegExp.test(text)) return;
|
|
209
|
+
const start = code.indexOf(text, open + 1);
|
|
210
|
+
bindings.push({ kind: 'catch', name: text, start, end: start + text.length, depth: (depthAt[start] ?? 0) + 1, namespaces: [valueNamespace] });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function collectImportBindings(code, bindings, depthAt) {
|
|
214
|
+
for (const match of code.matchAll(/\bimport\b[\s\S]*?(?:;|$)/g)) {
|
|
215
|
+
const text = match[0];
|
|
216
|
+
if (!/\bfrom\b/.test(text)) continue;
|
|
217
|
+
const typeOnly = /\bimport\s+type\b/.test(text);
|
|
218
|
+
const fromIndex = text.search(/\bfrom\b/);
|
|
219
|
+
const clause = text.slice('import'.length, fromIndex).trim().replace(/^type\b/, '').trim();
|
|
220
|
+
collectImportClauseBindings(clause, match.index + text.indexOf(clause), typeOnly, bindings, depthAt);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function collectImportClauseBindings(clause, baseOffset, typeOnly, bindings, depthAt) {
|
|
225
|
+
const namespace = clause.match(/\*\s+as\s+([A-Za-z_$][\w$]*)/);
|
|
226
|
+
if (namespace) {
|
|
227
|
+
bindings.push(importBinding(namespace[1], baseOffset + namespace.index + namespace[0].lastIndexOf(namespace[1]), typeOnly, depthAt));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const namedStart = clause.indexOf('{');
|
|
231
|
+
if (namedStart === -1) {
|
|
232
|
+
const defaultName = clause.replace(/,.*/, '').trim();
|
|
233
|
+
if (identifierRegExp.test(defaultName)) bindings.push(importBinding(defaultName, baseOffset + clause.indexOf(defaultName), typeOnly, depthAt));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const beforeNamed = clause.slice(0, namedStart).replace(/,$/, '').trim();
|
|
237
|
+
if (identifierRegExp.test(beforeNamed)) bindings.push(importBinding(beforeNamed, baseOffset + clause.indexOf(beforeNamed), typeOnly, depthAt));
|
|
238
|
+
const namedEnd = clause.indexOf('}', namedStart + 1);
|
|
239
|
+
if (namedEnd === -1) return;
|
|
240
|
+
let offset = baseOffset + namedStart + 1;
|
|
241
|
+
for (const rawPart of clause.slice(namedStart + 1, namedEnd).split(',')) {
|
|
242
|
+
const part = rawPart.trim();
|
|
243
|
+
const clean = part.replace(/^type\s+/, '').trim();
|
|
244
|
+
const local = clean.match(/\bas\s+([A-Za-z_$][\w$]*)$/)?.[1] ?? clean.match(/^([A-Za-z_$][\w$]*)/)?.[1];
|
|
245
|
+
if (local) bindings.push(importBinding(local, offset + rawPart.indexOf(local), typeOnly || part.startsWith('type '), depthAt));
|
|
246
|
+
offset += rawPart.length + 1;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function importBinding(name, start, typeOnly, depthAt) {
|
|
251
|
+
return {
|
|
252
|
+
kind: 'import',
|
|
253
|
+
name,
|
|
254
|
+
start,
|
|
255
|
+
end: start + name.length,
|
|
256
|
+
depth: depthAt[start] ?? 0,
|
|
257
|
+
namespaces: typeOnly ? [typeNamespace] : [valueNamespace, typeNamespace]
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function collectArrowFunctionBindings(code, bindings, depthAt) {
|
|
262
|
+
for (const match of code.matchAll(/\(([^()]*)\)\s*=>/g)) {
|
|
263
|
+
collectParameterListBindings(match[1], match.index + 1, bindings, depthAt, 'param');
|
|
264
|
+
}
|
|
265
|
+
for (const match of code.matchAll(/\b([A-Za-z_$][\w$]*)\s*=>/g)) {
|
|
266
|
+
bindings.push({ kind: 'param', name: match[1], start: match.index, end: match.index + match[1].length, depth: (depthAt[match.index] ?? 0) + 1, namespaces: [valueNamespace] });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function collectParameterListBindings(text, baseOffset, bindings, depthAt, kind) {
|
|
271
|
+
for (const parameter of splitTopLevelComma(text, baseOffset)) {
|
|
272
|
+
const pattern = parameterBindingPattern(parameter.text);
|
|
273
|
+
const start = firstSignificantIndex(pattern);
|
|
274
|
+
if (start === -1) continue;
|
|
275
|
+
const bindingDepth = (depthAt[parameter.offset + start] ?? 0) + 1;
|
|
276
|
+
collectBindingPatternBindings(pattern, parameter.offset, kind, bindings, depthAt, bindingDepth);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function parameterBindingPattern(text) {
|
|
281
|
+
const typeAnnotation = topLevelCharIndex(text, ':');
|
|
282
|
+
const initializer = topLevelCharIndex(text, '=');
|
|
283
|
+
const end = [typeAnnotation, initializer].filter((index) => index !== -1).sort((left, right) => left - right)[0];
|
|
284
|
+
return end === undefined ? text : text.slice(0, end);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export { collectBindings };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { identifierTokenRegExp } from './js-ts-semantic-scope-use-def-utils.js';
|
|
2
|
+
|
|
3
|
+
function maskNonCode(sourceText) {
|
|
4
|
+
const text = String(sourceText ?? '');
|
|
5
|
+
const chars = [...text];
|
|
6
|
+
let unsupportedTemplateLiteral = false;
|
|
7
|
+
const templateExpressionRanges = [];
|
|
8
|
+
for (let index = 0; index < chars.length; index += 1) {
|
|
9
|
+
const char = chars[index];
|
|
10
|
+
const next = chars[index + 1];
|
|
11
|
+
if (char === '/' && next === '/') {
|
|
12
|
+
index = maskUntilLineEnd(chars, index);
|
|
13
|
+
} else if (char === '/' && next === '*') {
|
|
14
|
+
index = maskBlockComment(chars, index);
|
|
15
|
+
} else if (char === '\'' || char === '"') {
|
|
16
|
+
index = maskQuotedString(chars, index, char);
|
|
17
|
+
} else if (char === '`') {
|
|
18
|
+
const result = maskTemplateLiteral(chars, text, index, templateExpressionRanges, templateTag(text, index));
|
|
19
|
+
unsupportedTemplateLiteral ||= result.unsupported;
|
|
20
|
+
index = result.index;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { code: chars.join(''), unsupportedTemplateLiteral, templateExpressionRanges };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function tokenize(code) {
|
|
27
|
+
return [...code.matchAll(identifierTokenRegExp)]
|
|
28
|
+
.map((match) => ({ value: match[0], start: match.index, end: match.index + match[0].length }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createBraceDepthIndex(code) {
|
|
32
|
+
const depthAt = new Array(code.length + 1);
|
|
33
|
+
let depth = 0;
|
|
34
|
+
for (let index = 0; index <= code.length; index += 1) {
|
|
35
|
+
depthAt[index] = depth;
|
|
36
|
+
const char = code[index];
|
|
37
|
+
if (char === '{') depth += 1;
|
|
38
|
+
else if (char === '}') depth = Math.max(0, depth - 1);
|
|
39
|
+
}
|
|
40
|
+
return depthAt;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isPropertyAccess(code, start) {
|
|
44
|
+
let index = start - 1;
|
|
45
|
+
while (index >= 0 && /\s/.test(code[index])) index -= 1;
|
|
46
|
+
return code[index] === '.' || code[index] === '#';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function findStatementBoundary(code, start) {
|
|
50
|
+
let depth = 0;
|
|
51
|
+
for (let index = start; index < code.length; index += 1) {
|
|
52
|
+
const char = code[index];
|
|
53
|
+
if (char === '(' || char === '[' || char === '{') depth += 1;
|
|
54
|
+
else if (char === ')' || char === ']' || char === '}') depth = Math.max(0, depth - 1);
|
|
55
|
+
else if ((char === ';' || char === '\n') && depth === 0) return index;
|
|
56
|
+
}
|
|
57
|
+
return code.length;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function nextIdentifierToken(tokens, startIndex) {
|
|
61
|
+
for (let index = startIndex; index < tokens.length; index += 1) {
|
|
62
|
+
if (!isDeclarationModifier(tokens[index].value)) return tokens[index];
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function previousIdentifierToken(tokens, startIndex) {
|
|
68
|
+
for (let index = startIndex; index >= 0; index -= 1) return tokens[index];
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function likelyTypeReference(code, tokens, index) {
|
|
73
|
+
const previous = previousIdentifierToken(tokens, index - 1)?.value;
|
|
74
|
+
if (previous === 'type' || previous === 'interface' || previous === 'implements' || previous === 'extends' || previous === 'as' || previous === 'satisfies') {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const before = code.slice(Math.max(0, tokens[index].start - 4), tokens[index].start);
|
|
78
|
+
return /[:<]\s*$/.test(before);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function hasTypeAliasAssignment(code, start) {
|
|
82
|
+
for (let index = start; index < code.length; index += 1) {
|
|
83
|
+
const char = code[index];
|
|
84
|
+
if (char === '=') return true;
|
|
85
|
+
if (char === ';' || char === '\n' || char === '{') return false;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function maskUntilLineEnd(chars, start) {
|
|
91
|
+
let index = start;
|
|
92
|
+
while (index < chars.length && chars[index] !== '\n') {
|
|
93
|
+
chars[index] = ' ';
|
|
94
|
+
index += 1;
|
|
95
|
+
}
|
|
96
|
+
return index - 1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function maskBlockComment(chars, start) {
|
|
100
|
+
let index = start;
|
|
101
|
+
while (index < chars.length) {
|
|
102
|
+
const done = chars[index] === '*' && chars[index + 1] === '/';
|
|
103
|
+
if (chars[index] !== '\n') chars[index] = ' ';
|
|
104
|
+
if (done) {
|
|
105
|
+
chars[index + 1] = ' ';
|
|
106
|
+
return index + 1;
|
|
107
|
+
}
|
|
108
|
+
index += 1;
|
|
109
|
+
}
|
|
110
|
+
return chars.length - 1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function maskQuotedString(chars, start, quote) {
|
|
114
|
+
let index = start;
|
|
115
|
+
chars[index] = ' ';
|
|
116
|
+
index += 1;
|
|
117
|
+
while (index < chars.length) {
|
|
118
|
+
const char = chars[index];
|
|
119
|
+
if (char === '\\') {
|
|
120
|
+
chars[index] = ' ';
|
|
121
|
+
if (chars[index + 1] && chars[index + 1] !== '\n') chars[index + 1] = ' ';
|
|
122
|
+
index += 2;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (char === quote) {
|
|
126
|
+
chars[index] = ' ';
|
|
127
|
+
return index;
|
|
128
|
+
}
|
|
129
|
+
if (char !== '\n') chars[index] = ' ';
|
|
130
|
+
index += 1;
|
|
131
|
+
}
|
|
132
|
+
return chars.length - 1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function maskTemplateLiteral(chars, sourceText, start, templateExpressionRanges, tag) {
|
|
136
|
+
const templateContext = templateRangeContext(start, tag);
|
|
137
|
+
let index = start;
|
|
138
|
+
chars[index] = ' ';
|
|
139
|
+
index += 1;
|
|
140
|
+
while (index < chars.length) {
|
|
141
|
+
const char = chars[index];
|
|
142
|
+
const next = chars[index + 1];
|
|
143
|
+
if (char === '\\') {
|
|
144
|
+
chars[index] = ' ';
|
|
145
|
+
if (chars[index + 1] && chars[index + 1] !== '\n') chars[index + 1] = ' ';
|
|
146
|
+
index += 2;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (char === '`') {
|
|
150
|
+
chars[index] = ' ';
|
|
151
|
+
return { index, unsupported: false };
|
|
152
|
+
}
|
|
153
|
+
if (char === '$' && next === '{') {
|
|
154
|
+
const expressionStart = index + 2;
|
|
155
|
+
chars[index] = ' ';
|
|
156
|
+
chars[index + 1] = ' ';
|
|
157
|
+
const result = preserveTemplateExpression(chars, sourceText, expressionStart, templateExpressionRanges);
|
|
158
|
+
if (result.unsupported) return result;
|
|
159
|
+
templateExpressionRanges.push({ start: expressionStart, end: result.index, ...templateContext });
|
|
160
|
+
index = result.index + 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (char !== '\n') chars[index] = ' ';
|
|
164
|
+
index += 1;
|
|
165
|
+
}
|
|
166
|
+
return { index: chars.length - 1, unsupported: true };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function templateRangeContext(templateStart, tag) {
|
|
170
|
+
return {
|
|
171
|
+
templateStart,
|
|
172
|
+
templateKind: tag ? 'tagged-template' : 'template-literal',
|
|
173
|
+
templateTagText: tag?.text,
|
|
174
|
+
templateTagRoot: tag?.root,
|
|
175
|
+
templateTagMemberName: tag?.memberName,
|
|
176
|
+
templateTagStart: tag?.start,
|
|
177
|
+
templateTagEnd: tag?.end
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function templateTag(sourceText, start) {
|
|
182
|
+
const prefix = String(sourceText ?? '').slice(0, start);
|
|
183
|
+
const match = /([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)\s*$/.exec(prefix);
|
|
184
|
+
if (!match) return undefined;
|
|
185
|
+
const text = match[1].replace(/\s*\.\s*/g, '.');
|
|
186
|
+
const parts = text.split('.');
|
|
187
|
+
return { text, root: parts[0], memberName: parts.length > 1 ? parts[parts.length - 1] : undefined, start: match.index, end: match.index + match[1].length };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function preserveTemplateExpression(chars, sourceText, start, templateExpressionRanges) {
|
|
191
|
+
let depth = 0;
|
|
192
|
+
for (let index = start; index < chars.length; index += 1) {
|
|
193
|
+
const char = chars[index];
|
|
194
|
+
const next = chars[index + 1];
|
|
195
|
+
if (char === '/' && next === '/') {
|
|
196
|
+
index = maskUntilLineEnd(chars, index);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (char === '/' && next === '*') {
|
|
200
|
+
index = maskBlockComment(chars, index);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (char === '\'' || char === '"') {
|
|
204
|
+
index = maskQuotedString(chars, index, char);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (char === '`') {
|
|
208
|
+
const result = maskTemplateLiteral(chars, sourceText, index, templateExpressionRanges, templateTag(sourceText, index));
|
|
209
|
+
if (result.unsupported) return result;
|
|
210
|
+
index = result.index;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (char === '{') {
|
|
214
|
+
depth += 1;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (char !== '}') continue;
|
|
218
|
+
if (depth === 0) {
|
|
219
|
+
chars[index] = ' ';
|
|
220
|
+
return { index, unsupported: false };
|
|
221
|
+
}
|
|
222
|
+
depth -= 1;
|
|
223
|
+
}
|
|
224
|
+
return { index: chars.length - 1, unsupported: true };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function isDeclarationModifier(value) {
|
|
228
|
+
return value === 'export' || value === 'default' || value === 'declare' || value === 'abstract' || value === 'async';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export {
|
|
232
|
+
createBraceDepthIndex,
|
|
233
|
+
findStatementBoundary,
|
|
234
|
+
hasTypeAliasAssignment,
|
|
235
|
+
isPropertyAccess,
|
|
236
|
+
likelyTypeReference,
|
|
237
|
+
maskNonCode,
|
|
238
|
+
nextIdentifierToken,
|
|
239
|
+
previousIdentifierToken,
|
|
240
|
+
tokenize
|
|
241
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const identifierRegExp = /^[A-Za-z_$][\w$]*$/;
|
|
2
|
+
const identifierTokenRegExp = /[A-Za-z_$][\w$]*/g;
|
|
3
|
+
const valueNamespace = 'value';
|
|
4
|
+
const typeNamespace = 'type';
|
|
5
|
+
|
|
6
|
+
const LexicalUseDefReasonCodes = Object.freeze({
|
|
7
|
+
noLiveReferences: 'lexical-use-def-no-live-references',
|
|
8
|
+
invalidIdentifier: 'lexical-scope-invalid-identifier',
|
|
9
|
+
templateLiteralUnsupported: 'lexical-scope-template-literal-unsupported',
|
|
10
|
+
liveReference: 'lexical-scope-live-reference',
|
|
11
|
+
closureReference: 'lexical-scope-closure-reference',
|
|
12
|
+
shadowedBinding: 'lexical-scope-shadowed-binding',
|
|
13
|
+
bindingConflict: 'lexical-scope-binding-conflict',
|
|
14
|
+
typeValueNamespaceConflict: 'lexical-scope-type-value-namespace-conflict',
|
|
15
|
+
namespaceComputedMemberUnsupported: 'lexical-scope-namespace-computed-member-unsupported',
|
|
16
|
+
namespaceMemberWriteUnsupported: 'lexical-scope-namespace-member-write-unsupported',
|
|
17
|
+
importAliasTargetUnresolved: 'lexical-scope-import-alias-target-unresolved'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const declarationNamespaceByKind = Object.freeze({
|
|
21
|
+
function: [valueNamespace],
|
|
22
|
+
variable: [valueNamespace],
|
|
23
|
+
class: [valueNamespace, typeNamespace],
|
|
24
|
+
enum: [valueNamespace, typeNamespace],
|
|
25
|
+
type: [typeNamespace],
|
|
26
|
+
interface: [typeNamespace],
|
|
27
|
+
module: [valueNamespace, typeNamespace],
|
|
28
|
+
namespace: [valueNamespace, typeNamespace]
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function namespacesForDeclarationKind(kind) {
|
|
32
|
+
return declarationNamespaceByKind[kind] ?? [valueNamespace];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function namespacesForImportRemoval(input) {
|
|
36
|
+
return input.typeOnly ? [typeNamespace] : [valueNamespace, typeNamespace];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeNamespaces(value) {
|
|
40
|
+
const raw = Array.isArray(value) ? value : [value ?? valueNamespace];
|
|
41
|
+
const namespaces = uniqueStrings(raw
|
|
42
|
+
.map((item) => String(item))
|
|
43
|
+
.filter((item) => item === valueNamespace || item === typeNamespace));
|
|
44
|
+
return namespaces.length ? namespaces : [valueNamespace];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function namespaceOverlap(left, right) {
|
|
48
|
+
return left.some((namespace) => right.includes(namespace));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeRanges(ranges) {
|
|
52
|
+
return (ranges ?? []).filter((range) => Number.isInteger(range?.start) && Number.isInteger(range?.end));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function spanRange(entry) {
|
|
56
|
+
return Number.isInteger(entry?.start) && Number.isInteger(entry?.end)
|
|
57
|
+
? { start: entry.start, end: entry.end }
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function rangeAllowed(record, ranges) {
|
|
62
|
+
return ranges.some((range) => record.start >= range.start && record.end <= range.end);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function rangeKey(record) {
|
|
66
|
+
return `${record.start}:${record.end}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function compactRecord(record) {
|
|
70
|
+
return Object.fromEntries(Object.entries(record ?? {}).filter(([, value]) => value !== undefined));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function uniqueStrings(values) {
|
|
74
|
+
return [...new Set((values ?? []).filter((value) => typeof value === 'string' && value.length > 0))];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function uniqueBindings(bindings) {
|
|
78
|
+
const seen = new Set();
|
|
79
|
+
const result = [];
|
|
80
|
+
for (const binding of bindings) {
|
|
81
|
+
const key = `${binding.kind}:${binding.name}:${binding.start}:${binding.end}:${binding.namespaces.join('|')}`;
|
|
82
|
+
if (seen.has(key)) continue;
|
|
83
|
+
seen.add(key);
|
|
84
|
+
result.push(binding);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function lineNumber(sourceText, offset) {
|
|
90
|
+
return String(sourceText ?? '').slice(0, offset).split('\n').length;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function nextSignificantCharIndex(code, start) {
|
|
94
|
+
for (let index = start; index < code.length; index += 1) {
|
|
95
|
+
if (!/\s/.test(code[index])) return index;
|
|
96
|
+
}
|
|
97
|
+
return -1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function findMatchingParen(code, open) {
|
|
101
|
+
let depth = 0;
|
|
102
|
+
for (let index = open; index < code.length; index += 1) {
|
|
103
|
+
if (code[index] === '(') depth += 1;
|
|
104
|
+
else if (code[index] === ')') {
|
|
105
|
+
depth -= 1;
|
|
106
|
+
if (depth === 0) return index;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export {
|
|
113
|
+
LexicalUseDefReasonCodes,
|
|
114
|
+
compactRecord,
|
|
115
|
+
findMatchingParen,
|
|
116
|
+
identifierRegExp,
|
|
117
|
+
identifierTokenRegExp,
|
|
118
|
+
lineNumber,
|
|
119
|
+
namespaceOverlap,
|
|
120
|
+
namespacesForDeclarationKind,
|
|
121
|
+
namespacesForImportRemoval,
|
|
122
|
+
nextSignificantCharIndex,
|
|
123
|
+
normalizeNamespaces,
|
|
124
|
+
normalizeRanges,
|
|
125
|
+
rangeAllowed,
|
|
126
|
+
rangeKey,
|
|
127
|
+
spanRange,
|
|
128
|
+
typeNamespace,
|
|
129
|
+
uniqueBindings,
|
|
130
|
+
uniqueStrings,
|
|
131
|
+
valueNamespace
|
|
132
|
+
};
|