@shapeshift-labs/frontier-lang-compiler 0.2.150 → 0.2.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +5 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +170 -171
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { nativeExportDeclaration } from './native-region-scanner-core.js';
|
|
2
|
+
|
|
3
|
+
export function jsCommonJsExportDeclarations(input, lineNumber, trimmed) {
|
|
4
|
+
let match = trimmed.match(/^Object\.assign\(\s*(?:module\.)?exports\s*,\s*(\{.*\})\s*\)\s*;?$/);
|
|
5
|
+
if (match) return jsCommonJsObjectLiteralExportDeclarations(input, lineNumber, match[1]);
|
|
6
|
+
match = trimmed.match(/^Object\.defineProperties\(\s*(?:module\.)?exports\s*,\s*(\{.*\})\s*\)\s*;?$/);
|
|
7
|
+
if (match) return jsCommonJsDefinePropertiesExportDeclarations(input, lineNumber, match[1]);
|
|
8
|
+
match = trimmed.match(/^Object\.defineProperty\(\s*(?:module\.)?exports\s*,\s*(['"])([^'"]+)\1\s*,\s*(\{.*\})\s*\)\s*;?$/);
|
|
9
|
+
if (match) return jsCommonJsDescriptorExportDeclaration(input, lineNumber, match[2], match[3]);
|
|
10
|
+
match = trimmed.match(/^module\.exports\s*=\s*(.+?)\s*;?$/);
|
|
11
|
+
if (match) {
|
|
12
|
+
const localName = jsCommonJsExportLocalName(match[1]);
|
|
13
|
+
const assignment = nativeExportDeclaration(input, lineNumber, 'module.exports', 'CommonJsExportAssignment', {
|
|
14
|
+
exportKind: 'assignment',
|
|
15
|
+
...(localName ? { localName } : {}),
|
|
16
|
+
commonJs: true
|
|
17
|
+
}, {
|
|
18
|
+
name: 'module.exports',
|
|
19
|
+
metadata: {
|
|
20
|
+
exportKind: 'assignment',
|
|
21
|
+
exportedName: 'module.exports',
|
|
22
|
+
...(localName ? { localName } : {}),
|
|
23
|
+
commonJs: true,
|
|
24
|
+
publicContract: true
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return [assignment, ...jsCommonJsObjectLiteralExportDeclarations(input, lineNumber, match[1])];
|
|
28
|
+
}
|
|
29
|
+
match = trimmed.match(/^(?:module\.)?exports(?:\.([A-Za-z_$][\w$]*)|\[\s*(['"])([^'"]+)\2\s*\])\s*=\s*(.+?)\s*;?$/);
|
|
30
|
+
if (!match) return [];
|
|
31
|
+
const exportedName = match[1] ?? match[3];
|
|
32
|
+
if (exportedName === '__esModule') return [];
|
|
33
|
+
const localName = jsCommonJsExportLocalName(match[4]);
|
|
34
|
+
return [nativeExportDeclaration(input, lineNumber, exportedName, 'CommonJsNamedExportAssignment', {
|
|
35
|
+
exportKind: 'commonjs-named',
|
|
36
|
+
...(localName ? { localName } : {}),
|
|
37
|
+
commonJs: true
|
|
38
|
+
}, {
|
|
39
|
+
name: exportedName,
|
|
40
|
+
metadata: {
|
|
41
|
+
exportKind: 'commonjs-named',
|
|
42
|
+
exportedName,
|
|
43
|
+
...(localName ? { localName } : {}),
|
|
44
|
+
commonJs: true,
|
|
45
|
+
publicContract: true
|
|
46
|
+
}
|
|
47
|
+
})];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function jsCommonJsDescriptorExportDeclaration(input, lineNumber, exportedName, descriptorSource) {
|
|
51
|
+
if (exportedName === '__esModule') return [];
|
|
52
|
+
const localName = jsCommonJsDescriptorLocalName(descriptorSource);
|
|
53
|
+
return [nativeExportDeclaration(input, lineNumber, exportedName, 'CommonJsDescriptorExportProperty', {
|
|
54
|
+
exportKind: 'commonjs-named',
|
|
55
|
+
...(localName ? { localName } : {}),
|
|
56
|
+
commonJs: true
|
|
57
|
+
}, {
|
|
58
|
+
name: exportedName,
|
|
59
|
+
metadata: {
|
|
60
|
+
exportKind: 'commonjs-named',
|
|
61
|
+
exportedName,
|
|
62
|
+
...(localName ? { localName } : {}),
|
|
63
|
+
commonJs: true,
|
|
64
|
+
publicContract: true
|
|
65
|
+
}
|
|
66
|
+
})];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function jsCommonJsDescriptorLocalName(source) {
|
|
70
|
+
const text = String(source ?? '');
|
|
71
|
+
return jsCommonJsExportLocalName(text.match(/\bvalue\s*:\s*([^,}]+)/)?.[1])
|
|
72
|
+
?? jsCommonJsExportLocalName(text.match(/\bget\s*:\s*\(\)\s*=>\s*\{\s*return\s+([^;}]+)/)?.[1])
|
|
73
|
+
?? jsCommonJsExportLocalName(text.match(/\bget\s*:\s*\(\)\s*=>\s*([^,}]+)/)?.[1])
|
|
74
|
+
?? jsCommonJsExportLocalName(text.match(/\bget\s*:\s*function(?:\s+[A-Za-z_$][\w$]*)?\s*\(\)\s*\{\s*return\s+([^;}]+)/)?.[1])
|
|
75
|
+
?? jsCommonJsExportLocalName(text.match(/\bget\s*\(\)\s*\{\s*return\s+([^;}]+)/)?.[1]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function jsCommonJsObjectLiteralExportDeclarations(input, lineNumber, source) {
|
|
79
|
+
const text = String(source ?? '').trim();
|
|
80
|
+
if (!text.startsWith('{') || !text.endsWith('}')) return [];
|
|
81
|
+
return splitTopLevelObjectProperties(text.slice(1, -1))
|
|
82
|
+
.map((entry) => jsCommonJsObjectLiteralExport(input, lineNumber, entry))
|
|
83
|
+
.filter(Boolean);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function jsCommonJsObjectLiteralExport(input, lineNumber, entry) {
|
|
87
|
+
if (!entry || entry.startsWith('...') || entry.startsWith('[')) return undefined;
|
|
88
|
+
const match = entry.match(/^((?:[A-Za-z_$][\w$]*)|(?:"[^"]+"|'[^']+'))\s*(?::\s*(.+))?$/);
|
|
89
|
+
if (!match) return undefined;
|
|
90
|
+
const exportedName = unquote(match[1]);
|
|
91
|
+
if (exportedName === '__esModule') return undefined;
|
|
92
|
+
const localName = match[2] ? jsCommonJsExportLocalName(match[2]) : /^[A-Za-z_$]/.test(exportedName) ? exportedName : undefined;
|
|
93
|
+
return nativeExportDeclaration(input, lineNumber, exportedName, 'CommonJsObjectExportProperty', {
|
|
94
|
+
exportKind: 'commonjs-named',
|
|
95
|
+
...(localName ? { localName } : {}),
|
|
96
|
+
commonJs: true
|
|
97
|
+
}, {
|
|
98
|
+
name: exportedName,
|
|
99
|
+
metadata: {
|
|
100
|
+
exportKind: 'commonjs-named',
|
|
101
|
+
exportedName,
|
|
102
|
+
...(localName ? { localName } : {}),
|
|
103
|
+
commonJs: true,
|
|
104
|
+
publicContract: true
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function jsCommonJsDefinePropertiesExportDeclarations(input, lineNumber, source) {
|
|
110
|
+
const text = String(source ?? '').trim();
|
|
111
|
+
if (!text.startsWith('{') || !text.endsWith('}')) return [];
|
|
112
|
+
return splitTopLevelObjectProperties(text.slice(1, -1))
|
|
113
|
+
.map((entry) => jsCommonJsDefinePropertiesExport(input, lineNumber, entry))
|
|
114
|
+
.filter(Boolean);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function jsCommonJsDefinePropertiesExport(input, lineNumber, entry) {
|
|
118
|
+
if (!entry || entry.startsWith('...') || entry.startsWith('[')) return undefined;
|
|
119
|
+
const match = entry.match(/^((?:[A-Za-z_$][\w$]*)|(?:"[^"]+"|'[^']+'))\s*:\s*(\{.*\})$/);
|
|
120
|
+
if (!match) return undefined;
|
|
121
|
+
return jsCommonJsDescriptorExportDeclaration(input, lineNumber, unquote(match[1]), match[2])[0];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function splitTopLevelObjectProperties(body) {
|
|
125
|
+
const entries = [];
|
|
126
|
+
let start = 0, depth = 0, quote;
|
|
127
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
128
|
+
const char = body[index], previous = body[index - 1];
|
|
129
|
+
if (quote) {
|
|
130
|
+
if (char === quote && previous !== '\\') quote = undefined;
|
|
131
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
132
|
+
else if (char === '{' || char === '[' || char === '(') depth += 1;
|
|
133
|
+
else if (char === '}' || char === ']' || char === ')') depth = Math.max(0, depth - 1);
|
|
134
|
+
else if (char === ',' && depth === 0) {
|
|
135
|
+
entries.push(body.slice(start, index).trim());
|
|
136
|
+
start = index + 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
entries.push(body.slice(start).trim());
|
|
140
|
+
return entries;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function jsCommonJsExportLocalName(source) {
|
|
144
|
+
const text = String(source ?? '').trim();
|
|
145
|
+
return text.match(/^(?:async\s+)?function\*?\s+([A-Za-z_$][\w$]*)/)?.[1]
|
|
146
|
+
?? text.match(/^(?:abstract\s+)?class\s+([A-Za-z_$][\w$]*)/)?.[1]
|
|
147
|
+
?? text.match(/^([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\b/)?.[1];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function unquote(value) {
|
|
151
|
+
const text = String(value ?? '');
|
|
152
|
+
return (text.startsWith('"') && text.endsWith('"')) || (text.startsWith("'") && text.endsWith("'"))
|
|
153
|
+
? text.slice(1, -1)
|
|
154
|
+
: text;
|
|
155
|
+
}
|
|
@@ -3,9 +3,17 @@ import {
|
|
|
3
3
|
nativeImportBindingDeclaration,
|
|
4
4
|
nativeImportDeclaration
|
|
5
5
|
} from './native-region-scanner-core.js';
|
|
6
|
+
import { jsCommonJsExportDeclarations } from './native-region-scanner-js-commonjs.js';
|
|
7
|
+
import { jsCommonJsHelperImportDeclarations } from './native-region-scanner-js-ts-helpers.js';
|
|
8
|
+
import { jsCommonJsReExportDeclarations } from './native-region-scanner-js-reexports.js';
|
|
6
9
|
import { idFragment } from './native-import-utils.js';
|
|
10
|
+
import { importAttributeMetadataFromSource } from './internal/index-impl/moduleImportAttributeMetadata.js';
|
|
7
11
|
|
|
8
12
|
export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
13
|
+
const commonJsReExport = jsCommonJsReExportDeclarations(input, lineNumber, trimmed);
|
|
14
|
+
if (commonJsReExport.length) return commonJsReExport;
|
|
15
|
+
const commonJsHelperImport = jsCommonJsHelperImportDeclarations(input, lineNumber, trimmed);
|
|
16
|
+
if (commonJsHelperImport.length) return commonJsHelperImport;
|
|
9
17
|
const importEquals = trimmed.match(/^import\s+(type\s+)?([A-Za-z_$][\w$]*)\s*=\s*require\s*\(\s*(['"])([^'"]+)\3\s*\)/);
|
|
10
18
|
if (importEquals) return jsImportModuleDeclarations(input, lineNumber, importEquals[4], 'ImportEqualsDeclaration', [{
|
|
11
19
|
localName: importEquals[2],
|
|
@@ -19,7 +27,7 @@ export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
|
19
27
|
const importPath = importMatch[4];
|
|
20
28
|
const clause = importMatch[2]?.trim();
|
|
21
29
|
const bindings = clause ? jsImportBindingsFromClause(clause, { typeOnly }) : [];
|
|
22
|
-
return jsImportModuleDeclarations(input, lineNumber, importPath, 'ImportDeclaration', bindings, { typeOnly, sideEffectOnly: bindings.length === 0 });
|
|
30
|
+
return jsImportModuleDeclarations(input, lineNumber, importPath, 'ImportDeclaration', bindings, { typeOnly, sideEffectOnly: bindings.length === 0, importKind: bindings.length === 0 ? 'side-effect' : 'module', ...importAttributeMetadataFromSource(trimmed) });
|
|
23
31
|
}
|
|
24
32
|
const exportMatch = trimmed.match(/^export\s+(type\s+)?(?:(\*)\s+from|\*\s+as\s+([A-Za-z_$][\w$]*)\s+from|\{([^}]+)\}\s+from)\s+(['"])([^'"]+)\5/);
|
|
25
33
|
if (exportMatch) {
|
|
@@ -31,24 +39,31 @@ export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
|
31
39
|
? jsNamedImportBindings(exportMatch[4], { typeOnly, reexport: true })
|
|
32
40
|
: [];
|
|
33
41
|
return [
|
|
34
|
-
...jsImportModuleDeclarations(input, lineNumber, importPath, 'ExportFromDeclaration', bindings, { typeOnly, reexport: true, exportStar: Boolean(exportMatch[2]) }),
|
|
35
|
-
...jsExportModuleDeclarations(input, lineNumber, importPath, bindings, { typeOnly, exportStar: Boolean(exportMatch[2]) })
|
|
42
|
+
...jsImportModuleDeclarations(input, lineNumber, importPath, 'ExportFromDeclaration', bindings, { typeOnly, reexport: true, exportStar: Boolean(exportMatch[2]), ...importAttributeMetadataFromSource(trimmed) }),
|
|
43
|
+
...jsExportModuleDeclarations(input, lineNumber, importPath, bindings, { typeOnly, exportStar: Boolean(exportMatch[2]), ...importAttributeMetadataFromSource(trimmed) })
|
|
36
44
|
];
|
|
37
45
|
}
|
|
38
46
|
const destructuredRequireMatch = trimmed.match(/^(?:const|let|var)\s+\{([^}]+)\}\s*=\s*(?:await\s+)?(require|import)\s*\(\s*(['"])([^'"]+)\3\s*\)/);
|
|
39
47
|
if (destructuredRequireMatch) {
|
|
40
|
-
const
|
|
48
|
+
const dynamicImport = destructuredRequireMatch[2] === 'import';
|
|
49
|
+
const importKind = dynamicImport ? 'dynamic-import-binding' : 'commonjs-require';
|
|
41
50
|
const bindings = jsDestructuredImportBindings(destructuredRequireMatch[1], importKind);
|
|
42
51
|
if (bindings.length) {
|
|
43
|
-
return jsImportModuleDeclarations(input, lineNumber, destructuredRequireMatch[4], 'DestructuredRequireDeclaration', bindings, {
|
|
52
|
+
return jsImportModuleDeclarations(input, lineNumber, destructuredRequireMatch[4], 'DestructuredRequireDeclaration', bindings, {
|
|
53
|
+
destructured: true,
|
|
54
|
+
...(dynamicImport ? jsDynamicImportMetadata() : {})
|
|
55
|
+
});
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
|
-
const requireMatch = trimmed.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+)?(
|
|
47
|
-
if (requireMatch)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const requireMatch = trimmed.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+)?(require|import)\s*\(\s*(['"])([^'"]+)\3\s*\)/);
|
|
59
|
+
if (requireMatch) {
|
|
60
|
+
const dynamicImport = requireMatch[2] === 'import';
|
|
61
|
+
return jsImportModuleDeclarations(input, lineNumber, requireMatch[4], dynamicImport ? 'DynamicImportBindingDeclaration' : 'CommonJsRequireDeclaration', [{
|
|
62
|
+
localName: requireMatch[1],
|
|
63
|
+
importedName: 'default',
|
|
64
|
+
importKind: dynamicImport ? 'dynamic-import-binding' : 'commonjs-require'
|
|
65
|
+
}], dynamicImport ? jsDynamicImportMetadata() : {});
|
|
66
|
+
}
|
|
52
67
|
const sideEffectRequireMatch = trimmed.match(/^require\s*\(\s*(['"])([^'"]+)\1\s*\)\s*;?$/);
|
|
53
68
|
if (sideEffectRequireMatch) {
|
|
54
69
|
return jsImportModuleDeclarations(input, lineNumber, sideEffectRequireMatch[2], 'CommonJsSideEffectRequireDeclaration', [], {
|
|
@@ -56,10 +71,14 @@ export function jsImportDeclarations(input, lineNumber, trimmed) {
|
|
|
56
71
|
importKind: 'commonjs-require'
|
|
57
72
|
});
|
|
58
73
|
}
|
|
74
|
+
const dynamicImportMatch = trimmed.match(/^import\s*\(\s*(['"])([^'"]+)\1\s*(?:,\s*(.+))?\)\s*;?$/);
|
|
75
|
+
if (dynamicImportMatch) return jsImportModuleDeclarations(input, lineNumber, dynamicImportMatch[2], 'DynamicImportExpression', [], jsDynamicImportMetadata(dynamicImportMatch[3]));
|
|
59
76
|
return [];
|
|
60
77
|
}
|
|
61
78
|
|
|
62
79
|
export function jsExportDeclarations(input, lineNumber, trimmed) {
|
|
80
|
+
const commonJsExport = jsCommonJsExportDeclarations(input, lineNumber, trimmed);
|
|
81
|
+
if (commonJsExport.length) return commonJsExport;
|
|
63
82
|
if (/^export\s+(?:type\s+)?(?:\*|\{[^}]+\}\s+from\b)/.test(trimmed)) return [];
|
|
64
83
|
const named = trimmed.match(/^export\s+(type\s+)?\{([^}]+)\}\s*;?$/);
|
|
65
84
|
if (named) return jsLocalExportDeclarations(input, lineNumber, named[2], { typeOnly: Boolean(named[1]) });
|
|
@@ -71,7 +90,15 @@ export function jsExportDeclarations(input, lineNumber, trimmed) {
|
|
|
71
90
|
if (assignment) return [nativeExportDeclaration(input, lineNumber, 'module.exports', 'ExportAssignment', {
|
|
72
91
|
exportKind: 'assignment',
|
|
73
92
|
localName: assignment[1]
|
|
74
|
-
}, {
|
|
93
|
+
}, {
|
|
94
|
+
name: 'module.exports',
|
|
95
|
+
metadata: {
|
|
96
|
+
exportKind: 'assignment',
|
|
97
|
+
exportedName: 'module.exports',
|
|
98
|
+
localName: assignment[1],
|
|
99
|
+
publicContract: true
|
|
100
|
+
}
|
|
101
|
+
})];
|
|
75
102
|
if (!trimmed.startsWith('export ')) return [];
|
|
76
103
|
const defaultMatch = trimmed.match(/^export\s+default\s+(.+)$/);
|
|
77
104
|
if (defaultMatch) return [nativeExportDeclaration(input, lineNumber, 'default', 'ExportDefaultDeclaration', {
|
|
@@ -109,6 +136,7 @@ function jsImportModuleDeclarations(input, lineNumber, importPath, languageKind,
|
|
|
109
136
|
localName: binding.localName,
|
|
110
137
|
importedName: binding.importedName,
|
|
111
138
|
importKind: binding.importKind,
|
|
139
|
+
...(binding.namespace ? { namespace: binding.namespace } : {}),
|
|
112
140
|
...(binding.exportedName ? { exportedName: binding.exportedName } : {}),
|
|
113
141
|
...(binding.typeOnly ? { typeOnly: true } : {})
|
|
114
142
|
}));
|
|
@@ -121,7 +149,9 @@ function jsImportModuleDeclarations(input, lineNumber, importPath, languageKind,
|
|
|
121
149
|
...(metadata.sideEffectOnly ? { sideEffectOnly: true } : {}),
|
|
122
150
|
...(metadata.reexport ? { reexport: true } : {}),
|
|
123
151
|
...(metadata.exportStar ? { exportStar: true } : {}),
|
|
124
|
-
...(metadata.destructured ? { destructured: true } : {})
|
|
152
|
+
...(metadata.destructured ? { destructured: true } : {}),
|
|
153
|
+
...(metadata.dynamicImport ? { dynamicImport: true } : {}),
|
|
154
|
+
...(metadata.hasImportAttributes ? { hasImportAttributes: true } : {})
|
|
125
155
|
},
|
|
126
156
|
metadata: {
|
|
127
157
|
moduleOnly: true,
|
|
@@ -133,6 +163,14 @@ function jsImportModuleDeclarations(input, lineNumber, importPath, languageKind,
|
|
|
133
163
|
];
|
|
134
164
|
}
|
|
135
165
|
|
|
166
|
+
function jsDynamicImportMetadata(attributesSource) {
|
|
167
|
+
return {
|
|
168
|
+
importKind: 'dynamic-import',
|
|
169
|
+
dynamicImport: true,
|
|
170
|
+
...importAttributeMetadataFromSource(attributesSource)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
136
174
|
function jsExportModuleDeclarations(input, lineNumber, importPath, bindings = [], metadata = {}) {
|
|
137
175
|
const exports = bindings.map((binding) => ({
|
|
138
176
|
localName: binding.importedName,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nativeExportDeclaration,
|
|
3
|
+
nativeImportBindingDeclaration,
|
|
4
|
+
nativeImportDeclaration
|
|
5
|
+
} from './native-region-scanner-core.js';
|
|
6
|
+
|
|
7
|
+
export function jsCommonJsReExportDeclarations(input, lineNumber, trimmed) {
|
|
8
|
+
const exportStar = trimmed.match(/^(?:[A-Za-z_$][\w$]*\s*\.\s*)?__exportStar\(\s*require\(\s*(['"])([^'"]+)\1\s*\)\s*,\s*(?:module\.)?exports\s*\)\s*;?$/);
|
|
9
|
+
if (exportStar) return commonJsExportStarDeclarations(input, lineNumber, exportStar[2]);
|
|
10
|
+
const binding = trimmed.match(/^(?:[A-Za-z_$][\w$]*\s*\.\s*)?__createBinding\(\s*(?:module\.)?exports\s*,\s*require\(\s*(['"])([^'"]+)\1\s*\)\s*,\s*(['"])([^'"]+)\3(?:\s*,\s*(['"])([^'"]+)\5)?\s*\)\s*;?$/);
|
|
11
|
+
if (binding) return commonJsCreateBindingDeclarations(input, lineNumber, binding[2], binding[4], binding[6] ?? binding[4]);
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function commonJsExportStarDeclarations(input, lineNumber, importPath) {
|
|
16
|
+
const metadata = commonJsReExportMetadata({ exportStar: true, importKind: 'reexport' });
|
|
17
|
+
return [
|
|
18
|
+
...importModuleDeclarations(input, lineNumber, importPath, 'CommonJsExportStarRequireDeclaration', [], metadata),
|
|
19
|
+
...exportModuleDeclarations(input, lineNumber, importPath, [], { ...metadata, exportKind: 'export-star' })
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function commonJsCreateBindingDeclarations(input, lineNumber, importPath, importedName, exportedName) {
|
|
24
|
+
if (!importedName || !exportedName || exportedName === '__esModule') return [];
|
|
25
|
+
const binding = {
|
|
26
|
+
localName: exportedName,
|
|
27
|
+
importedName,
|
|
28
|
+
exportedName,
|
|
29
|
+
importKind: 'reexport',
|
|
30
|
+
exportKind: 'named',
|
|
31
|
+
commonJs: true
|
|
32
|
+
};
|
|
33
|
+
const metadata = commonJsReExportMetadata({ importKind: 'reexport', bindingCount: 1 });
|
|
34
|
+
return [
|
|
35
|
+
...importModuleDeclarations(input, lineNumber, importPath, 'CommonJsCreateBindingRequireDeclaration', [binding], metadata),
|
|
36
|
+
...exportModuleDeclarations(input, lineNumber, importPath, [binding], { ...metadata, exportKind: 'named' })
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function importModuleDeclarations(input, lineNumber, importPath, languageKind, bindings, metadata) {
|
|
41
|
+
return [
|
|
42
|
+
nativeImportDeclaration(input, lineNumber, importPath, languageKind, 'module', {
|
|
43
|
+
fields: { moduleOnly: true, importBindings: bindings, reexport: true, commonJs: true, ...(metadata.exportStar ? { exportStar: true } : {}) },
|
|
44
|
+
metadata: { moduleOnly: true, bindingCount: bindings.length, ...metadata }
|
|
45
|
+
}),
|
|
46
|
+
...bindings.map((binding) => nativeImportBindingDeclaration(input, lineNumber, importPath, binding))
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function exportModuleDeclarations(input, lineNumber, importPath, bindings, metadata) {
|
|
51
|
+
const exports = bindings.map((binding) => ({
|
|
52
|
+
localName: binding.importedName,
|
|
53
|
+
importedName: binding.importedName,
|
|
54
|
+
exportedName: binding.exportedName ?? binding.localName,
|
|
55
|
+
exportKind: binding.exportKind ?? binding.importKind,
|
|
56
|
+
commonJs: true
|
|
57
|
+
}));
|
|
58
|
+
return [
|
|
59
|
+
nativeExportDeclaration(input, lineNumber, metadata.exportStar ? `* from ${importPath}` : `{${exports.map((binding) => binding.exportedName).join(',')}} from ${importPath}`, 'ExportFromDeclaration', {
|
|
60
|
+
importPath: String(importPath),
|
|
61
|
+
exportBindings: exports,
|
|
62
|
+
...(metadata.exportStar ? { exportStar: true } : {})
|
|
63
|
+
}, { symbolKind: 'module', metadata }),
|
|
64
|
+
...exports.map((binding) => nativeExportDeclaration(input, lineNumber, binding.exportedName, 'ExportBinding', {
|
|
65
|
+
...binding,
|
|
66
|
+
importPath: String(importPath)
|
|
67
|
+
}, { metadata: { ...binding, importPath: String(importPath) } }))
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function commonJsReExportMetadata(extra = {}) {
|
|
72
|
+
return {
|
|
73
|
+
commonJs: true,
|
|
74
|
+
reexport: true,
|
|
75
|
+
reExport: true,
|
|
76
|
+
publicContract: true,
|
|
77
|
+
...extra
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nativeImportBindingDeclaration,
|
|
3
|
+
nativeImportDeclaration
|
|
4
|
+
} from './native-region-scanner-core.js';
|
|
5
|
+
|
|
6
|
+
export function jsCommonJsHelperImportDeclarations(input, lineNumber, trimmed) {
|
|
7
|
+
const match = trimmed.match(/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:[A-Za-z_$][\w$]*\s*\.\s*)?__(importStar|importDefault)\(\s*require\(\s*(['"])([^'"]+)\3\s*\)\s*\)\s*;?$/);
|
|
8
|
+
if (!match) return [];
|
|
9
|
+
const localName = match[1], helper = `__${match[2]}`, importPath = match[4];
|
|
10
|
+
const binding = helper === '__importStar'
|
|
11
|
+
? { localName, importedName: '*', namespace: localName, importKind: 'namespace' }
|
|
12
|
+
: { localName, importedName: 'default', importKind: 'default' };
|
|
13
|
+
const metadata = { commonJs: true, interopHelper: helper, importKind: binding.importKind };
|
|
14
|
+
return [
|
|
15
|
+
nativeImportDeclaration(input, lineNumber, importPath, 'CommonJsInteropHelperRequireDeclaration', 'module', {
|
|
16
|
+
fields: { moduleOnly: true, importBindings: [binding], commonJs: true, interopHelper: helper },
|
|
17
|
+
metadata: { moduleOnly: true, bindingCount: 1, ...metadata }
|
|
18
|
+
}),
|
|
19
|
+
nativeImportBindingDeclaration(input, lineNumber, importPath, binding, {
|
|
20
|
+
metadata
|
|
21
|
+
})
|
|
22
|
+
];
|
|
23
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const regexStartKeywords = new Set(['case', 'delete', 'else', 'in', 'instanceof', 'new', 'return', 'throw', 'typeof', 'void', 'yield']);
|
|
2
2
|
|
|
3
3
|
export function isSourceMapComment(text) {
|
|
4
|
-
return /^(?:\/\/|\/\*)[#@]\s*
|
|
4
|
+
return /^(?:\/\/|\/\*)[#@]\s*source(?:Mapping)?URL=/.test(String(text).trim());
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export function readToLineEnd(text, start) {
|
|
@@ -81,9 +81,7 @@ export function scanJavaScriptTypeScriptSourceLedger(sourceText, input = {}) {
|
|
|
81
81
|
const next = sourceText[offset + 1];
|
|
82
82
|
if (offset === 0 && char === '#' && next === '!') {
|
|
83
83
|
const part = consume(readToLineEnd(sourceText, offset));
|
|
84
|
-
|
|
85
|
-
push(ledger.comments, 'shebang', 'comment', part.text, part.start, part.end);
|
|
86
|
-
ledger.shebangs.push(sourceLedgerSpan({
|
|
84
|
+
const entry = sourceLedgerSpan({
|
|
87
85
|
index: ledger.spans.length,
|
|
88
86
|
kind: 'shebang',
|
|
89
87
|
role: 'directive',
|
|
@@ -91,9 +89,12 @@ export function scanJavaScriptTypeScriptSourceLedger(sourceText, input = {}) {
|
|
|
91
89
|
start: part.start,
|
|
92
90
|
end: part.end,
|
|
93
91
|
sourceHash,
|
|
94
|
-
sourcePath: input.sourcePath
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
sourcePath: input.sourcePath,
|
|
93
|
+
metadata: { language: input.language ?? 'javascript' }
|
|
94
|
+
});
|
|
95
|
+
ledger.spans.push(entry);
|
|
96
|
+
ledger.shebangs.push(entry);
|
|
97
|
+
ledger.directives.push(entry);
|
|
97
98
|
previous = undefined;
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
@@ -110,8 +111,8 @@ export function scanJavaScriptTypeScriptSourceLedger(sourceText, input = {}) {
|
|
|
110
111
|
}
|
|
111
112
|
if (char === '/' && next === '/') {
|
|
112
113
|
const part = consume(readToLineEnd(sourceText, offset));
|
|
113
|
-
const kind =
|
|
114
|
-
const metadata = kind
|
|
114
|
+
const kind = preservedCommentKind(part.text);
|
|
115
|
+
const metadata = commentMetadata(kind);
|
|
115
116
|
push(ledger.trivia, kind, 'trivia', part.text, part.start, part.end, metadata);
|
|
116
117
|
push(ledger.comments, kind, 'comment', part.text, part.start, part.end, metadata);
|
|
117
118
|
previous = undefined;
|
|
@@ -119,8 +120,8 @@ export function scanJavaScriptTypeScriptSourceLedger(sourceText, input = {}) {
|
|
|
119
120
|
}
|
|
120
121
|
if (char === '/' && next === '*') {
|
|
121
122
|
const part = consume(readBlockCommentEnd(sourceText, offset));
|
|
122
|
-
const kind =
|
|
123
|
-
const metadata = kind
|
|
123
|
+
const kind = preservedCommentKind(part.text);
|
|
124
|
+
const metadata = commentMetadata(kind);
|
|
124
125
|
push(ledger.trivia, kind, 'trivia', part.text, part.start, part.end, metadata);
|
|
125
126
|
push(ledger.comments, kind, 'comment', part.text, part.start, part.end, metadata);
|
|
126
127
|
previous = undefined;
|
|
@@ -189,6 +190,7 @@ export function scanJavaScriptTypeScriptSourceLedger(sourceText, input = {}) {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
for (const directive of sourceLedgerDirectives(sourceText, input, sourceHash)) {
|
|
193
|
+
if (directive.kind === 'shebang' && ledger.shebangs.some((entry) => entry.span.start === directive.span.start && entry.span.end === directive.span.end)) continue;
|
|
192
194
|
if (ledger.spans.length >= maxSpans) {
|
|
193
195
|
truncated = true;
|
|
194
196
|
break;
|
|
@@ -304,3 +306,15 @@ function directiveKind(trimmed) {
|
|
|
304
306
|
if (/^(?:import|export)\b/.test(trimmed)) return 'module-directive';
|
|
305
307
|
return undefined;
|
|
306
308
|
}
|
|
309
|
+
|
|
310
|
+
function preservedCommentKind(text) {
|
|
311
|
+
const value = String(text ?? '');
|
|
312
|
+
if (isSourceMapComment(value)) return 'source-map-comment';
|
|
313
|
+
if (value.startsWith('/**') && value[3] !== '/') return 'jsdoc-comment';
|
|
314
|
+
if (value.startsWith('/*')) return 'block-comment';
|
|
315
|
+
return 'comment';
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function commentMetadata(kind) {
|
|
319
|
+
return kind === 'source-map-comment' ? { sourceMap: true } : kind === 'jsdoc-comment' ? { jsdoc: true } : kind === 'block-comment' ? { blockComment: true } : {};
|
|
320
|
+
}
|