@scriptc/compiler 0.2.6 → 0.2.7
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/ambient/scriptc-node-fallback.d.ts +5 -18
- package/dist/backend/cycle-analysis.d.ts +21 -9
- package/dist/backend/cycle-analysis.js +139 -67
- package/dist/backend/cycle-analysis.js.map +1 -1
- package/dist/backend/cycle-analysis.test.js +283 -3
- package/dist/backend/cycle-analysis.test.js.map +1 -1
- package/dist/backend/cycle-mutability.d.ts +39 -0
- package/dist/backend/cycle-mutability.js +205 -0
- package/dist/backend/cycle-mutability.js.map +1 -0
- package/dist/backend/link-plan-core.d.ts +2 -1
- package/dist/backend/link-plan-core.js +15 -3
- package/dist/backend/link-plan-core.js.map +1 -1
- package/dist/backend/link-plan.d.ts +2 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/alloc.d.ts +40 -0
- package/dist/backend/llvm/alloc.js +205 -0
- package/dist/backend/llvm/alloc.js.map +1 -0
- package/dist/backend/llvm/alloc.test.d.ts +1 -0
- package/dist/backend/llvm/alloc.test.js +102 -0
- package/dist/backend/llvm/alloc.test.js.map +1 -0
- package/dist/backend/llvm/call-lifetimes.d.ts +15 -3
- package/dist/backend/llvm/call-lifetimes.js +42 -18
- package/dist/backend/llvm/call-lifetimes.js.map +1 -1
- package/dist/backend/llvm/call-lifetimes.test.js +170 -0
- package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +4 -1
- package/dist/backend/llvm/classes.js +35 -32
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +36 -3
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +13 -0
- package/dist/backend/llvm/common.js +30 -0
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/constant-callbacks.d.ts +19 -3
- package/dist/backend/llvm/constant-callbacks.js +289 -52
- package/dist/backend/llvm/constant-callbacks.js.map +1 -1
- package/dist/backend/llvm/constant-callbacks.test.js +140 -3
- package/dist/backend/llvm/constant-callbacks.test.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.d.ts +29 -0
- package/dist/backend/llvm/dense-array-access.js +335 -0
- package/dist/backend/llvm/dense-array-access.js.map +1 -0
- package/dist/backend/llvm/dense-array-access.test.d.ts +1 -0
- package/dist/backend/llvm/dense-array-access.test.js +149 -0
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +34 -0
- package/dist/backend/llvm/dyn.js +189 -1
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +124 -4
- package/dist/backend/llvm/emitter.js +623 -105
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +68 -6
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +58 -4
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-async.test.d.ts +1 -0
- package/dist/backend/llvm/expr-async.test.js +62 -0
- package/dist/backend/llvm/expr-async.test.js.map +1 -0
- package/dist/backend/llvm/expr-calls.js +64 -6
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +16 -5
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-control.js +92 -2
- package/dist/backend/llvm/expr-control.js.map +1 -1
- package/dist/backend/llvm/expr-dispatch.js +2 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +174 -25
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +52 -24
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +1 -1
- package/dist/backend/llvm/expr-records.js +3 -3
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +59 -2
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js +1 -1
- package/dist/backend/llvm/integer-remainder.d.ts +11 -0
- package/dist/backend/llvm/integer-remainder.js +91 -0
- package/dist/backend/llvm/integer-remainder.js.map +1 -1
- package/dist/backend/llvm/layouts.d.ts +2 -1
- package/dist/backend/llvm/layouts.js +3 -2
- package/dist/backend/llvm/layouts.js.map +1 -1
- package/dist/backend/llvm/lazy-captures.d.ts +16 -0
- package/dist/backend/llvm/lazy-captures.js +96 -0
- package/dist/backend/llvm/lazy-captures.js.map +1 -0
- package/dist/backend/llvm/lazy-captures.test.d.ts +1 -0
- package/dist/backend/llvm/lazy-captures.test.js +78 -0
- package/dist/backend/llvm/lazy-captures.test.js.map +1 -0
- package/dist/backend/llvm/lib-filesystem.js +3 -4
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.d.ts +5 -1
- package/dist/backend/llvm/local-array-reads.js +78 -17
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.test.js +78 -1
- package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.d.ts +5 -1
- package/dist/backend/llvm/local-union-storage.js +48 -6
- package/dist/backend/llvm/local-union-storage.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.test.js +91 -4
- package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
- package/dist/backend/llvm/map-read-lifetimes.test.js +1 -1
- package/dist/backend/llvm/nullable-fields.d.ts +28 -0
- package/dist/backend/llvm/nullable-fields.js +45 -0
- package/dist/backend/llvm/nullable-fields.js.map +1 -0
- package/dist/backend/llvm/nullable-fields.test.d.ts +1 -0
- package/dist/backend/llvm/nullable-fields.test.js +48 -0
- package/dist/backend/llvm/nullable-fields.test.js.map +1 -0
- package/dist/backend/llvm/serialized-ir-emission.test.d.ts +1 -0
- package/dist/backend/llvm/serialized-ir-emission.test.js +52 -0
- package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +69 -2
- package/dist/backend/llvm/shapes.js +259 -27
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/shapes.test.js +114 -5
- package/dist/backend/llvm/shapes.test.js.map +1 -1
- package/dist/backend/llvm/stack-callbacks.js +2 -3
- package/dist/backend/llvm/stack-callbacks.js.map +1 -1
- package/dist/backend/llvm/stack-captures.d.ts +3 -1
- package/dist/backend/llvm/stack-captures.js +5 -3
- package/dist/backend/llvm/stack-captures.js.map +1 -1
- package/dist/backend/llvm/stack-unions.test.js +38 -1
- package/dist/backend/llvm/stack-unions.test.js.map +1 -1
- package/dist/backend/llvm/string-construction.test.js +1 -1
- package/dist/backend/llvm/string-key-hash.d.ts +8 -0
- package/dist/backend/llvm/string-key-hash.js +59 -0
- package/dist/backend/llvm/string-key-hash.js.map +1 -0
- package/dist/backend/llvm/string-key-hash.test.d.ts +1 -0
- package/dist/backend/llvm/string-key-hash.test.js +34 -0
- package/dist/backend/llvm/string-key-hash.test.js.map +1 -0
- package/dist/backend/llvm/string-lifetimes.test.js +41 -4
- package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.js +1 -1
- package/dist/backend/llvm/switch-dispatch.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.test.js +2 -2
- package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
- package/dist/backend/may-throw.js +3 -0
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/may-throw.test.js +1 -1
- package/dist/backend/native/cache-warm.d.ts +2 -1
- package/dist/backend/native/cache-warm.js.map +1 -1
- package/dist/backend/native/contracts.d.ts +3 -2
- package/dist/backend/native/contracts.js.map +1 -1
- package/dist/backend/native/runtime-inputs.d.ts +1 -1
- package/dist/backend/native/runtime-inputs.js +1 -0
- package/dist/backend/native/runtime-inputs.js.map +1 -1
- package/dist/backend/native-codegen-core.d.ts +2 -1
- package/dist/backend/native-codegen-core.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +5 -0
- package/dist/backend/native-codegen.js +4 -0
- package/dist/backend/native-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +23 -0
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/native-link-info-core.d.ts +3 -2
- package/dist/backend/native-link-info-core.js.map +1 -1
- package/dist/backend/native-link-info.d.ts +2 -1
- package/dist/backend/native-link-info.js.map +1 -1
- package/dist/backend/native-link-info.test.js +2 -2
- package/dist/backend/native-link-info.test.js.map +1 -1
- package/dist/backend/native-tools.d.ts +3 -1
- package/dist/backend/native-tools.js +0 -1
- package/dist/backend/native-tools.js.map +1 -1
- package/dist/backend/optimization.d.ts +25 -0
- package/dist/backend/optimization.js +21 -0
- package/dist/backend/optimization.js.map +1 -0
- package/dist/backend/optimization.test.d.ts +1 -0
- package/dist/backend/optimization.test.js +24 -0
- package/dist/backend/optimization.test.js.map +1 -0
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-core.d.ts +15 -4
- package/dist/backend/runtime-pack-core.js +23 -12
- package/dist/backend/runtime-pack-core.js.map +1 -1
- package/dist/backend/runtime-pack-native.d.ts +7 -3
- package/dist/backend/runtime-pack-native.js +0 -3
- package/dist/backend/runtime-pack-native.js.map +1 -1
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack.d.ts +20 -2
- package/dist/backend/runtime-pack.js +23 -0
- package/dist/backend/runtime-pack.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +115 -2
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/target-diagnostics.test.js +1 -1
- package/dist/backend/targets.d.ts +2 -1
- package/dist/backend/targets.js +1 -1
- package/dist/backend/targets.js.map +1 -1
- package/dist/cli/command.js +5 -4
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/host.d.ts +2 -1
- package/dist/cli/usage.d.ts +1 -1
- package/dist/cli/usage.js +5 -2
- package/dist/cli/usage.js.map +1 -1
- package/dist/compile-types.d.ts +5 -2
- package/dist/diagnostics/diagnostic.js +10 -8
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +2 -2
- package/dist/executable/executable-cache.js +7 -4
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +20 -0
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/frontend/lowering/abstract-equality.js +5 -49
- package/dist/frontend/lowering/abstract-equality.js.map +1 -1
- package/dist/frontend/lowering/array-values.d.ts +23 -0
- package/dist/frontend/lowering/array-values.js +129 -0
- package/dist/frontend/lowering/array-values.js.map +1 -1
- package/dist/frontend/lowering/builtins/errors.js +17 -2
- package/dist/frontend/lowering/builtins/errors.js.map +1 -1
- package/dist/frontend/lowering/builtins/process.d.ts +6 -17
- package/dist/frontend/lowering/builtins/process.js +56 -29
- package/dist/frontend/lowering/builtins/process.js.map +1 -1
- package/dist/frontend/lowering/caught-value-dispatch.d.ts +11 -0
- package/dist/frontend/lowering/caught-value-dispatch.js +87 -0
- package/dist/frontend/lowering/caught-value-dispatch.js.map +1 -0
- package/dist/frontend/lowering/class-assertions.d.ts +4 -0
- package/dist/frontend/lowering/class-assertions.js +12 -4
- package/dist/frontend/lowering/class-assertions.js.map +1 -1
- package/dist/frontend/lowering/class-callbacks.d.ts +3 -3
- package/dist/frontend/lowering/class-callbacks.js +18 -5
- package/dist/frontend/lowering/class-callbacks.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +1 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.js +4 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-method-mutations.d.ts +5 -0
- package/dist/frontend/lowering/class-method-mutations.js +472 -0
- package/dist/frontend/lowering/class-method-mutations.js.map +1 -0
- package/dist/frontend/lowering/class-method-values.js +25 -5
- package/dist/frontend/lowering/class-method-values.js.map +1 -1
- package/dist/frontend/lowering/class-prototypes.js +8 -2
- package/dist/frontend/lowering/class-prototypes.js.map +1 -1
- package/dist/frontend/lowering/class-unions.d.ts +16 -0
- package/dist/frontend/lowering/class-unions.js +127 -0
- package/dist/frontend/lowering/class-unions.js.map +1 -0
- package/dist/frontend/lowering/coercions/builders.js +8 -1
- package/dist/frontend/lowering/coercions/builders.js.map +1 -1
- package/dist/frontend/lowering/coercions/function-adapters.js +2 -0
- package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
- package/dist/frontend/lowering/coercions/identity.d.ts +7 -0
- package/dist/frontend/lowering/coercions/identity.js +26 -0
- package/dist/frontend/lowering/coercions/identity.js.map +1 -0
- package/dist/frontend/lowering/coercions/structural.js +9 -6
- package/dist/frontend/lowering/coercions/structural.js.map +1 -1
- package/dist/frontend/lowering/collection-narrowing.d.ts +6 -0
- package/dist/frontend/lowering/collection-narrowing.js +31 -0
- package/dist/frontend/lowering/collection-narrowing.js.map +1 -0
- package/dist/frontend/lowering/containers/array-callback-call.d.ts +7 -0
- package/dist/frontend/lowering/containers/array-callback-call.js +52 -0
- package/dist/frontend/lowering/containers/array-callback-call.js.map +1 -0
- package/dist/frontend/lowering/containers/array-callbacks.d.ts +1 -1
- package/dist/frontend/lowering/containers/array-callbacks.js +363 -49
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-concat.d.ts +7 -0
- package/dist/frontend/lowering/containers/array-concat.js +130 -0
- package/dist/frontend/lowering/containers/array-concat.js.map +1 -0
- package/dist/frontend/lowering/containers/array-construction.d.ts +2 -0
- package/dist/frontend/lowering/containers/array-construction.js +95 -3
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.d.ts +1 -11
- package/dist/frontend/lowering/containers/array-methods.js +43 -132
- package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-methods.js +10 -1
- package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/indexed-objects.js +56 -70
- package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
- package/dist/frontend/lowering/cycle-initialization.d.ts +41 -0
- package/dist/frontend/lowering/cycle-initialization.js +277 -0
- package/dist/frontend/lowering/cycle-initialization.js.map +1 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js +4 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.js +138 -32
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/union-field-write.d.ts +4 -4
- package/dist/frontend/lowering/expressions/union-field-write.js +54 -44
- package/dist/frontend/lowering/expressions/union-field-write.js.map +1 -1
- package/dist/frontend/lowering/iterator-adapters.d.ts +20 -0
- package/dist/frontend/lowering/iterator-adapters.js +605 -0
- package/dist/frontend/lowering/iterator-adapters.js.map +1 -0
- package/dist/frontend/lowering/lower-array-sort.d.ts +1 -1
- package/dist/frontend/lowering/lower-array-sort.js +44 -5
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.test.d.ts +1 -0
- package/dist/frontend/lowering/lower-array-sort.test.js +31 -0
- package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -0
- package/dist/frontend/lowering/lower-assert.js +7 -0
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtin-values.js +1 -0
- package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +3 -3
- package/dist/frontend/lowering/lower-calls.js +162 -121
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +2 -0
- package/dist/frontend/lowering/lower-classes.js +45 -43
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +9 -2
- package/dist/frontend/lowering/lower-exprs.js +390 -157
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-functions.js +32 -19
- package/dist/frontend/lowering/lower-functions.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +26 -2
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +10 -2
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +46 -58
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +37 -0
- package/dist/frontend/lowering/lowerer.js +283 -18
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/native-ffi.js +3 -1
- package/dist/frontend/lowering/native-ffi.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-provenance.d.ts +15 -0
- package/dist/frontend/lowering/runtime-optional-provenance.js +40 -0
- package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -0
- package/dist/frontend/lowering/sanitize-class-types.test.js +2 -2
- package/dist/frontend/lowering/strict-equality.d.ts +9 -0
- package/dist/frontend/lowering/strict-equality.js +116 -0
- package/dist/frontend/lowering/strict-equality.js.map +1 -0
- package/dist/frontend/lowering/surfaces.js +3 -0
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/union-comparison.d.ts +5 -0
- package/dist/frontend/lowering/union-comparison.js +47 -0
- package/dist/frontend/lowering/union-comparison.js.map +1 -0
- package/dist/frontend/program.d.ts +38 -2
- package/dist/frontend/program.js +440 -59
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/program.test.js +59 -6
- package/dist/frontend/program.test.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +1 -1
- package/dist/frontend/type-mapper.js +89 -14
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/frontend/type-mapper.test.js +15 -3
- package/dist/frontend/type-mapper.test.js.map +1 -1
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +3 -1
- package/dist/ir/analysis.js +4 -0
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/builtin-signatures.js +2 -3
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/constant-tables.test.js +1 -1
- package/dist/ir/initializer-bindings.test.js +1 -1
- package/dist/ir/ir.d.ts +78 -15
- package/dist/ir/ir.js +20 -6
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/scalar-records.test.js +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +3 -3
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/traverse.js +8 -0
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/validate.js +118 -20
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +269 -8
- package/dist/ir/validate.test.js.map +1 -1
- package/dist/library/fence-eval.test.js +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/library-cache.test.js +5 -5
- package/dist/library/library-profile.d.ts +2 -1
- package/dist/library/library-profile.js +4 -3
- package/dist/library/library-profile.js.map +1 -1
- package/dist/native/compiler.js.map +1 -1
- package/dist/native/compiler.test.js +2 -2
- package/dist/native/library.d.ts +2 -1
- package/dist/native/library.js.map +1 -1
- package/dist/native/prepare.js +27 -3
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/sanitizer.d.ts +3 -2
- package/dist/native/sanitizer.js +3 -13
- package/dist/native/sanitizer.js.map +1 -1
- package/package.json +20 -20
- package/surface-manifest.json +8 -2
package/dist/frontend/program.js
CHANGED
|
@@ -1611,6 +1611,18 @@ function inTypePosition7(node) {
|
|
|
1611
1611
|
* callback-invoking builtin, a getter, an iterator, or an implicit
|
|
1612
1612
|
* coercion of a user object) disqualifies the module's cycles. */
|
|
1613
1613
|
function nonInertTopLevel7(program, sf) {
|
|
1614
|
+
const nonInert = topLevelInertness7(program);
|
|
1615
|
+
for (const stmt of sf.statements) {
|
|
1616
|
+
const offence = nonInert(stmt);
|
|
1617
|
+
if (offence !== null)
|
|
1618
|
+
return offence;
|
|
1619
|
+
}
|
|
1620
|
+
return null;
|
|
1621
|
+
}
|
|
1622
|
+
/** The per-statement form of nonInertTopLevel7: answers, for one
|
|
1623
|
+
* top-level statement, the first construct that could execute user code
|
|
1624
|
+
* while the statement runs, or null when the statement is inert. */
|
|
1625
|
+
function topLevelInertness7(program) {
|
|
1614
1626
|
const checker = program.getTypeChecker();
|
|
1615
1627
|
const PRIM = ts.TypeFlags.StringLike |
|
|
1616
1628
|
ts.TypeFlags.NumberLike |
|
|
@@ -1779,7 +1791,7 @@ function nonInertTopLevel7(program, sf) {
|
|
|
1779
1791
|
}
|
|
1780
1792
|
return false;
|
|
1781
1793
|
};
|
|
1782
|
-
|
|
1794
|
+
return (stmt) => {
|
|
1783
1795
|
if (ts.isImportDeclaration(stmt) ||
|
|
1784
1796
|
ts.isExportDeclaration(stmt) ||
|
|
1785
1797
|
ts.isImportEqualsDeclaration(stmt) ||
|
|
@@ -1790,20 +1802,13 @@ function nonInertTopLevel7(program, sf) {
|
|
|
1790
1802
|
(ts.getCombinedModifierFlags(stmt) &
|
|
1791
1803
|
ts.ModifierFlags.Ambient) !==
|
|
1792
1804
|
0) {
|
|
1793
|
-
|
|
1805
|
+
return null;
|
|
1794
1806
|
}
|
|
1795
1807
|
if (ts.isEnumDeclaration(stmt)) {
|
|
1796
|
-
|
|
1797
|
-
if (bad !== undefined)
|
|
1798
|
-
return bad;
|
|
1799
|
-
continue;
|
|
1800
|
-
}
|
|
1801
|
-
if (ts.isClassDeclaration(stmt)) {
|
|
1802
|
-
const bad = inertClass(stmt);
|
|
1803
|
-
if (bad !== null)
|
|
1804
|
-
return bad;
|
|
1805
|
-
continue;
|
|
1808
|
+
return stmt.members.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null;
|
|
1806
1809
|
}
|
|
1810
|
+
if (ts.isClassDeclaration(stmt))
|
|
1811
|
+
return inertClass(stmt);
|
|
1807
1812
|
if (ts.isVariableStatement(stmt)) {
|
|
1808
1813
|
for (const d of stmt.declarationList.declarations) {
|
|
1809
1814
|
if (!ts.isIdentifier(d.name))
|
|
@@ -1811,21 +1816,15 @@ function nonInertTopLevel7(program, sf) {
|
|
|
1811
1816
|
if (d.initializer !== undefined && !inert(d.initializer))
|
|
1812
1817
|
return d.initializer;
|
|
1813
1818
|
}
|
|
1814
|
-
|
|
1815
|
-
}
|
|
1816
|
-
if (ts.isExpressionStatement(stmt)) {
|
|
1817
|
-
if (!inert(stmt.expression))
|
|
1818
|
-
return stmt;
|
|
1819
|
-
continue;
|
|
1819
|
+
return null;
|
|
1820
1820
|
}
|
|
1821
|
+
if (ts.isExpressionStatement(stmt))
|
|
1822
|
+
return inert(stmt.expression) ? null : stmt;
|
|
1821
1823
|
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
1822
|
-
|
|
1823
|
-
return stmt;
|
|
1824
|
-
continue;
|
|
1824
|
+
return inert(stmt.expression) ? null : stmt;
|
|
1825
1825
|
}
|
|
1826
1826
|
return stmt;
|
|
1827
|
-
}
|
|
1828
|
-
return null;
|
|
1827
|
+
};
|
|
1829
1828
|
}
|
|
1830
1829
|
/** The head of a property/element-access chain. */
|
|
1831
1830
|
function chainRoot7(e) {
|
|
@@ -1891,13 +1890,16 @@ function backEdgeUseOffence7(program, stmt, occurrences) {
|
|
|
1891
1890
|
* e.dep already mid-initialization in a depth-first walk), answers null
|
|
1892
1891
|
* to ADMIT the cycle — the guarded %init calls reproduce Node's cache-hit
|
|
1893
1892
|
* order and nothing can observe the partial initialization — or the
|
|
1894
|
-
* human-readable reason it keeps the SC1016 fence.
|
|
1893
|
+
* human-readable reason it keeps the SC1016 fence. Three admission chances:
|
|
1895
1894
|
* - the CHEAP PER-EDGE rule: the closing statement binds nothing (a
|
|
1896
1895
|
* side-effect import) or binds only namespace objects whose every use
|
|
1897
1896
|
* is a bare expression statement — no read crosses the edge at all;
|
|
1898
1897
|
* - the DECLARATION-ONLY INIT WINDOW rule (the admission block above):
|
|
1899
1898
|
* every cluster member is an ES module with an inert top level, and
|
|
1900
|
-
* the closing edge's bindings are used only in deferred positions
|
|
1899
|
+
* the closing edge's bindings are used only in deferred positions;
|
|
1900
|
+
* - the EXACT INITIALIZATION rule (exactCycleRefusal7): partial
|
|
1901
|
+
* initialization is observable, but every observation is modeled —
|
|
1902
|
+
* the lowering checks each binding cycleEarlyBindings reports.
|
|
1901
1903
|
* Tarjan SCCs (lazy, rooted at each queried importer) and cluster
|
|
1902
1904
|
* verdicts are memoized across calls, so `edgesOf` must answer the same
|
|
1903
1905
|
* edges for the same file every time. */
|
|
@@ -1948,10 +1950,11 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1948
1950
|
const nsf = node.getSourceFile();
|
|
1949
1951
|
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf, node.getStart(nsf)).line + 1}`;
|
|
1950
1952
|
};
|
|
1951
|
-
// Cluster verdict memo (keyed by the component array identity):
|
|
1952
|
-
//
|
|
1953
|
-
// member passes the inert-top-level bar.
|
|
1953
|
+
// Cluster verdict memo (keyed by the component array identity): true
|
|
1954
|
+
// when every member is an ES module passing the inert-top-level bar.
|
|
1954
1955
|
const sccVerdict = new Map();
|
|
1956
|
+
// The exact-initialization verdict, same keying (exactCycleRefusal7).
|
|
1957
|
+
const exactVerdict = new Map();
|
|
1955
1958
|
// A module can close many cycle edges, each importing many bindings.
|
|
1956
1959
|
// Index its identifiers once for this admission pass. ASTs are immutable;
|
|
1957
1960
|
// the pass owns the index so it cannot retain a disposed program.
|
|
@@ -1997,31 +2000,405 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1997
2000
|
return "the cycle's module cluster could not be analyzed";
|
|
1998
2001
|
}
|
|
1999
2002
|
if (!sccVerdict.has(comp)) {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2003
|
+
sccVerdict.set(comp, comp.every((m) => !isCjsJsFile7(m, program) && nonInertTopLevel7(program, m) === null));
|
|
2004
|
+
}
|
|
2005
|
+
if (sccVerdict.get(comp) === true &&
|
|
2006
|
+
backEdgeUseOffence7(program, e.stmt, usesOf(importer)) === null) {
|
|
2007
|
+
return null;
|
|
2008
|
+
}
|
|
2009
|
+
// The EXACT INITIALIZATION rule: the cycle runs in Node's evaluation
|
|
2010
|
+
// order and every binding that can be observed before its declaration
|
|
2011
|
+
// runs carries an initialization check (cycleEarlyBindings).
|
|
2012
|
+
if (!exactVerdict.has(comp)) {
|
|
2013
|
+
const reason = exactCycleRefusal7(program, comp, lineOf);
|
|
2014
|
+
exactVerdict.set(comp, reason);
|
|
2015
|
+
if (reason === null) {
|
|
2016
|
+
let members = exactCycleMembers7.get(program);
|
|
2017
|
+
if (members === undefined) {
|
|
2018
|
+
members = new Set();
|
|
2019
|
+
exactCycleMembers7.set(program, members);
|
|
2010
2020
|
}
|
|
2021
|
+
for (const m of comp)
|
|
2022
|
+
members.add(m);
|
|
2011
2023
|
}
|
|
2012
|
-
sccVerdict.set(comp, reason);
|
|
2013
2024
|
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2025
|
+
return exactVerdict.get(comp) ?? null;
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
/* ── exact cyclic initialization ─────────────────────────────────────────
|
|
2029
|
+
* Cycles that fail the declaration-only rule still evaluate exactly like
|
|
2030
|
+
* Node when their shape is representable: the guarded %init calls already
|
|
2031
|
+
* run every module body in ES evaluation order (depth-first postorder,
|
|
2032
|
+
* a module mid-evaluation answered from the cache), function declarations
|
|
2033
|
+
* are callable from the start, and live bindings are shared globals. What
|
|
2034
|
+
* remains is the temporal dead zone: a let/const binding read before its
|
|
2035
|
+
* declaration ran throws ReferenceError. cycleEarlyBindings finds every
|
|
2036
|
+
* such binding whose read CAN run early; the lowering gives each one an
|
|
2037
|
+
* initialization flag and checks it at every read or write that can run
|
|
2038
|
+
* before the declaration. The shapes below have no such representation
|
|
2039
|
+
* and keep the SC1016 fence. */
|
|
2040
|
+
/** Program → the modules of every cycle the exact rule admitted. */
|
|
2041
|
+
const exactCycleMembers7 = new WeakMap();
|
|
2042
|
+
/** The modules of `program` whose import cycles were admitted by the
|
|
2043
|
+
* exact initialization rule (not the declaration-only rule). */
|
|
2044
|
+
export function exactCycleMembers(program) {
|
|
2045
|
+
return exactCycleMembers7.get(program) ?? new Set();
|
|
2046
|
+
}
|
|
2047
|
+
/** True when the module's top level (outside every function-like body)
|
|
2048
|
+
* contains `await` or `for await`. */
|
|
2049
|
+
function hasTopLevelAwait7(sf) {
|
|
2050
|
+
let found = false;
|
|
2051
|
+
ts.walkPreorder(sf, (node) => {
|
|
2052
|
+
if (found)
|
|
2053
|
+
return "stop";
|
|
2054
|
+
if (node !== sf && ts.isFunctionLike(node))
|
|
2055
|
+
return "skip";
|
|
2056
|
+
if (ts.isAwaitExpression(node) ||
|
|
2057
|
+
(ts.isForOfStatement(node) && node.awaitModifier !== undefined)) {
|
|
2058
|
+
found = true;
|
|
2059
|
+
return "stop";
|
|
2022
2060
|
}
|
|
2023
|
-
return
|
|
2061
|
+
return undefined;
|
|
2062
|
+
});
|
|
2063
|
+
return found;
|
|
2064
|
+
}
|
|
2065
|
+
/** The reason a strongly-connected module cluster cannot be initialized
|
|
2066
|
+
* exactly, or null when it can. */
|
|
2067
|
+
function exactCycleRefusal7(program, comp, lineOf) {
|
|
2068
|
+
const members = new Set(comp);
|
|
2069
|
+
const targetOf = (stmt) => {
|
|
2070
|
+
const spec = stmt.moduleSpecifier;
|
|
2071
|
+
if (spec === undefined || !ts.isStringLiteral(spec))
|
|
2072
|
+
return null;
|
|
2073
|
+
const sf = stmt.getSourceFile();
|
|
2074
|
+
return resolveImport7(program, sf, spec.text) ?? npmStaticDepSf7(program, sf, spec.text);
|
|
2024
2075
|
};
|
|
2076
|
+
for (const m of comp) {
|
|
2077
|
+
if (isCjsJsFile7(m, program) || /\.c[jt]s$/.test(m.fileName)) {
|
|
2078
|
+
return `${m.fileName} is a CommonJS module — cyclic initialization covers ES modules only`;
|
|
2079
|
+
}
|
|
2080
|
+
if (hasTopLevelAwait7(m)) {
|
|
2081
|
+
return `${m.fileName} uses top-level await inside the cycle`;
|
|
2082
|
+
}
|
|
2083
|
+
for (const stmt of m.statements) {
|
|
2084
|
+
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
2085
|
+
return `the default export expression at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2086
|
+
}
|
|
2087
|
+
if (ts.isExportDeclaration(stmt) &&
|
|
2088
|
+
!stmt.isTypeOnly &&
|
|
2089
|
+
(stmt.exportClause === undefined || ts.isNamespaceExport(stmt.exportClause))) {
|
|
2090
|
+
const dep = targetOf(stmt);
|
|
2091
|
+
if (dep !== null && members.has(dep)) {
|
|
2092
|
+
return `the namespace re-export at ${lineOf(stmt)} names a module of the cycle`;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
if (ts.isImportDeclaration(stmt) &&
|
|
2096
|
+
stmt.importClause !== undefined &&
|
|
2097
|
+
!stmt.importClause.isTypeOnly &&
|
|
2098
|
+
stmt.importClause.namedBindings !== undefined &&
|
|
2099
|
+
ts.isNamespaceImport(stmt.importClause.namedBindings)) {
|
|
2100
|
+
const dep = targetOf(stmt);
|
|
2101
|
+
const nsName = stmt.importClause.namedBindings.name;
|
|
2102
|
+
if (dep !== null &&
|
|
2103
|
+
members.has(dep) &&
|
|
2104
|
+
!nsBindingUsesAreBareStatements7(program, m, nsName)) {
|
|
2105
|
+
return `the namespace import '${nsName.text}' at ${lineOf(stmt)} names a module of the cycle`;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (ts.isClassDeclaration(stmt) && stmt.name === undefined) {
|
|
2109
|
+
return `the anonymous default class at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2110
|
+
}
|
|
2111
|
+
const ambient = (ts.getCombinedModifierFlags(stmt) &
|
|
2112
|
+
ts.ModifierFlags.Ambient) !==
|
|
2113
|
+
0;
|
|
2114
|
+
if (ambient)
|
|
2115
|
+
continue;
|
|
2116
|
+
if (ts.isEnumDeclaration(stmt) &&
|
|
2117
|
+
(ts.getCombinedModifierFlags(stmt) & ts.ModifierFlags.Const) === 0) {
|
|
2118
|
+
return `the enum '${stmt.name.text}' at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2119
|
+
}
|
|
2120
|
+
if (ts.isModuleDeclaration(stmt) && !typeOnlyNamespace7(stmt)) {
|
|
2121
|
+
return `the namespace at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
return null;
|
|
2126
|
+
}
|
|
2127
|
+
/** Every binding of the program's exactly-initialized cycles that can be
|
|
2128
|
+
* observed before its declaration executes. `order` is the compiled module
|
|
2129
|
+
* order; `singleRoot` is false when more than one module graph root runs
|
|
2130
|
+
* (fork or worker entries), so a cycle can be entered at different
|
|
2131
|
+
* members. With one root and a purely ES-module graph the evaluation order
|
|
2132
|
+
* is static and the analysis is precise up to "user code may run": a
|
|
2133
|
+
* binding needs its check when its declaration completes after some
|
|
2134
|
+
* top-level code that can call user functions and a deferred position
|
|
2135
|
+
* (function body, parameter default, instance field) references it, or
|
|
2136
|
+
* when the top level of a cycle member evaluated before it reads it.
|
|
2137
|
+
* Otherwise every deferred reference and every top-level reference from
|
|
2138
|
+
* another member counts. */
|
|
2139
|
+
export function cycleEarlyBindings(program, entry, order, singleRoot) {
|
|
2140
|
+
const exact = exactCycleMembers7.get(program);
|
|
2141
|
+
if (exact === undefined || exact.size === 0)
|
|
2142
|
+
return [];
|
|
2143
|
+
// Every lowering pass of one compile asks with the same inputs.
|
|
2144
|
+
const key = `${entry.fileName}\0${order.map((sf) => sf.fileName).join("\0")}\0${singleRoot}`;
|
|
2145
|
+
const memo = earlyBindingsMemo7.get(program);
|
|
2146
|
+
if (memo !== undefined && memo.key === key)
|
|
2147
|
+
return memo.bindings;
|
|
2148
|
+
const bindings = computeCycleEarlyBindings7(program, entry, order, singleRoot, exact);
|
|
2149
|
+
earlyBindingsMemo7.set(program, { key, bindings });
|
|
2150
|
+
return bindings;
|
|
2151
|
+
}
|
|
2152
|
+
const earlyBindingsMemo7 = new WeakMap();
|
|
2153
|
+
function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
2154
|
+
const inOrder = new Set(order);
|
|
2155
|
+
const members = [...exact].filter((m) => inOrder.has(m));
|
|
2156
|
+
if (members.length === 0)
|
|
2157
|
+
return [];
|
|
2158
|
+
const memberSet = new Set(members);
|
|
2159
|
+
const depsOf = (sf) => orderedImportsOf(program, sf).flatMap(({ dep }) => dep !== null && dep !== sf && inOrder.has(dep) ? [dep] : []);
|
|
2160
|
+
// Strongly-connected components among the exactly-initialized members.
|
|
2161
|
+
const comps = [];
|
|
2162
|
+
{
|
|
2163
|
+
const index = new Map();
|
|
2164
|
+
const low = new Map();
|
|
2165
|
+
const onStack = new Set();
|
|
2166
|
+
const stack = [];
|
|
2167
|
+
let next = 0;
|
|
2168
|
+
const connect = (v) => {
|
|
2169
|
+
index.set(v, next);
|
|
2170
|
+
low.set(v, next);
|
|
2171
|
+
next++;
|
|
2172
|
+
stack.push(v);
|
|
2173
|
+
onStack.add(v);
|
|
2174
|
+
for (const w of depsOf(v)) {
|
|
2175
|
+
if (!memberSet.has(w))
|
|
2176
|
+
continue;
|
|
2177
|
+
if (!index.has(w)) {
|
|
2178
|
+
connect(w);
|
|
2179
|
+
low.set(v, Math.min(low.get(v), low.get(w)));
|
|
2180
|
+
}
|
|
2181
|
+
else if (onStack.has(w)) {
|
|
2182
|
+
low.set(v, Math.min(low.get(v), index.get(w)));
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
if (low.get(v) === index.get(v)) {
|
|
2186
|
+
const comp = [];
|
|
2187
|
+
for (;;) {
|
|
2188
|
+
const w = stack.pop();
|
|
2189
|
+
onStack.delete(w);
|
|
2190
|
+
comp.push(w);
|
|
2191
|
+
if (w === v)
|
|
2192
|
+
break;
|
|
2193
|
+
}
|
|
2194
|
+
if (comp.length > 1)
|
|
2195
|
+
comps.push(comp);
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
for (const m of members)
|
|
2199
|
+
if (!index.has(m))
|
|
2200
|
+
connect(m);
|
|
2201
|
+
}
|
|
2202
|
+
if (comps.length === 0)
|
|
2203
|
+
return [];
|
|
2204
|
+
// The static evaluation order: Node's depth-first postorder from the
|
|
2205
|
+
// entry over ES import edges. Known only for one root and a graph with
|
|
2206
|
+
// no CommonJS module (a require() evaluates its target mid-body).
|
|
2207
|
+
const position = new Map();
|
|
2208
|
+
if (singleRoot &&
|
|
2209
|
+
!order.some((sf) => isCjsJsFile7(sf, program) || /\.c[jt]s$/.test(sf.fileName))) {
|
|
2210
|
+
const seen = new Set();
|
|
2211
|
+
const visit = (sf) => {
|
|
2212
|
+
seen.add(sf);
|
|
2213
|
+
for (const dep of depsOf(sf))
|
|
2214
|
+
if (!seen.has(dep))
|
|
2215
|
+
visit(dep);
|
|
2216
|
+
position.set(sf, position.size);
|
|
2217
|
+
};
|
|
2218
|
+
visit(entry);
|
|
2219
|
+
}
|
|
2220
|
+
const checker = program.getTypeChecker();
|
|
2221
|
+
const nonInert = topLevelInertness7(program);
|
|
2222
|
+
const out = [];
|
|
2223
|
+
for (const comp of comps) {
|
|
2224
|
+
const known = comp.every((m) => position.has(m));
|
|
2225
|
+
const evaluation = known
|
|
2226
|
+
? comp.slice().sort((a, b) => position.get(a) - position.get(b))
|
|
2227
|
+
: comp.slice();
|
|
2228
|
+
const candidates = new Map();
|
|
2229
|
+
const names = new Set();
|
|
2230
|
+
let dirty = !known;
|
|
2231
|
+
evaluation.forEach((m, rank) => {
|
|
2232
|
+
for (const stmt of m.statements) {
|
|
2233
|
+
const offence = nonInert(stmt);
|
|
2234
|
+
const exposed = dirty || offence !== null;
|
|
2235
|
+
const declared = [];
|
|
2236
|
+
if (ts.isVariableStatement(stmt) &&
|
|
2237
|
+
(ts.getCombinedModifierFlags(stmt) &
|
|
2238
|
+
ts.ModifierFlags.Ambient) ===
|
|
2239
|
+
0) {
|
|
2240
|
+
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2241
|
+
for (const d of stmt.declarationList.declarations) {
|
|
2242
|
+
for (const name of boundNames7(d.name)) {
|
|
2243
|
+
declared.push({ name, kind: lexical ? "lexical" : "var" });
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
else if (ts.isClassDeclaration(stmt) && stmt.name !== undefined) {
|
|
2248
|
+
declared.push({ name: stmt.name, kind: "class" });
|
|
2249
|
+
}
|
|
2250
|
+
for (const { name, kind } of declared) {
|
|
2251
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
2252
|
+
if (symbol === undefined)
|
|
2253
|
+
continue;
|
|
2254
|
+
candidates.set(symbol, {
|
|
2255
|
+
symbol,
|
|
2256
|
+
name,
|
|
2257
|
+
kind,
|
|
2258
|
+
module: m,
|
|
2259
|
+
exposed,
|
|
2260
|
+
rank,
|
|
2261
|
+
start: stmt.getStart(m),
|
|
2262
|
+
end: stmt.getEnd(),
|
|
2263
|
+
reference: null,
|
|
2264
|
+
folded: null,
|
|
2265
|
+
});
|
|
2266
|
+
names.add(name.text);
|
|
2267
|
+
}
|
|
2268
|
+
if (offence !== null)
|
|
2269
|
+
dirty = true;
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
if (candidates.size === 0)
|
|
2273
|
+
continue;
|
|
2274
|
+
const rankOf = new Map(evaluation.map((m, i) => [m, i]));
|
|
2275
|
+
// References: every identifier spelled like a candidate, resolved
|
|
2276
|
+
// through import aliases to the declaration's symbol.
|
|
2277
|
+
for (const sf of order) {
|
|
2278
|
+
const refs = [];
|
|
2279
|
+
ts.walkPreorder(sf, (node) => {
|
|
2280
|
+
if (ts.isImportDeclaration(node))
|
|
2281
|
+
return "skip";
|
|
2282
|
+
if (ts.isIdentifier(node) && names.has(node.text))
|
|
2283
|
+
refs.push(node);
|
|
2284
|
+
return undefined;
|
|
2285
|
+
});
|
|
2286
|
+
if (refs.length === 0)
|
|
2287
|
+
continue;
|
|
2288
|
+
checker.prefetchSymbolNodesExact(refs);
|
|
2289
|
+
for (const ref of refs) {
|
|
2290
|
+
const parent = ref.parent;
|
|
2291
|
+
if (parent !== undefined && ts.isExportSpecifier(parent))
|
|
2292
|
+
continue;
|
|
2293
|
+
if (inTypePosition7(ref))
|
|
2294
|
+
continue;
|
|
2295
|
+
let symbol = checker.getSymbolAtLocation(ref);
|
|
2296
|
+
if (parent !== undefined &&
|
|
2297
|
+
ts.isShorthandPropertyAssignment(parent) &&
|
|
2298
|
+
parent.name === ref) {
|
|
2299
|
+
symbol = checker.getShorthandAssignmentValueSymbol(parent) ?? symbol;
|
|
2300
|
+
}
|
|
2301
|
+
if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {
|
|
2302
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
2303
|
+
}
|
|
2304
|
+
const c = symbol === undefined ? undefined : candidates.get(symbol);
|
|
2305
|
+
if (c === undefined || ref === c.name)
|
|
2306
|
+
continue;
|
|
2307
|
+
if (c.folded === null && foldablePosition7(ref))
|
|
2308
|
+
c.folded = ref;
|
|
2309
|
+
if (c.reference !== null)
|
|
2310
|
+
continue;
|
|
2311
|
+
// A class body names its own inner binding, initialized throughout.
|
|
2312
|
+
if (c.kind === "class" &&
|
|
2313
|
+
sf === c.module &&
|
|
2314
|
+
ref.getStart(sf) >= c.start &&
|
|
2315
|
+
ref.getEnd() <= c.end)
|
|
2316
|
+
continue;
|
|
2317
|
+
let early;
|
|
2318
|
+
if (inDeferredPosition7(ref))
|
|
2319
|
+
early = c.exposed;
|
|
2320
|
+
else if (sf === c.module)
|
|
2321
|
+
early = ref.getStart(sf) < c.start;
|
|
2322
|
+
else if (!memberSet.has(sf) || !rankOf.has(sf))
|
|
2323
|
+
early = false;
|
|
2324
|
+
else
|
|
2325
|
+
early = !known || rankOf.get(sf) < c.rank;
|
|
2326
|
+
if (early)
|
|
2327
|
+
c.reference = ref;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
for (const c of candidates.values()) {
|
|
2331
|
+
if (c.reference === null)
|
|
2332
|
+
continue;
|
|
2333
|
+
const settled = new Set(order.filter((sf) => !rankOf.has(sf)));
|
|
2334
|
+
if (known)
|
|
2335
|
+
for (const m of evaluation.slice(c.rank + 1))
|
|
2336
|
+
settled.add(m);
|
|
2337
|
+
out.push({
|
|
2338
|
+
symbol: c.symbol,
|
|
2339
|
+
name: c.name,
|
|
2340
|
+
kind: c.kind,
|
|
2341
|
+
module: c.module,
|
|
2342
|
+
reference: c.reference,
|
|
2343
|
+
...(c.folded !== null ? { folded: c.folded } : {}),
|
|
2344
|
+
settled,
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return out;
|
|
2349
|
+
}
|
|
2350
|
+
/** True for a reference whose value the lowering can take from the
|
|
2351
|
+
* binding's checker type instead of its storage: a property key (element
|
|
2352
|
+
* access argument, computed name, `in` operand, through parentheses,
|
|
2353
|
+
* casts and template spans) or a `typeof` operand. */
|
|
2354
|
+
function foldablePosition7(ref) {
|
|
2355
|
+
let child = ref;
|
|
2356
|
+
for (let p = ref.parent; p !== undefined; p = p.parent) {
|
|
2357
|
+
if (ts.isParenthesizedExpression(p) ||
|
|
2358
|
+
ts.isAsExpression(p) ||
|
|
2359
|
+
ts.isSatisfiesExpression(p) ||
|
|
2360
|
+
ts.isNonNullExpression(p) ||
|
|
2361
|
+
ts.isTemplateSpan(p) ||
|
|
2362
|
+
ts.isTemplateExpression(p)) {
|
|
2363
|
+
child = p;
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
if (ts.isTypeOfExpression(p))
|
|
2367
|
+
return true;
|
|
2368
|
+
if (ts.isElementAccessExpression(p))
|
|
2369
|
+
return p.argumentExpression === child;
|
|
2370
|
+
if (ts.isComputedPropertyName(p))
|
|
2371
|
+
return true;
|
|
2372
|
+
if (ts.isBinaryExpression(p))
|
|
2373
|
+
return p.operatorToken.kind === ts.SyntaxKind.InKeyword && p.left === child;
|
|
2374
|
+
return false;
|
|
2375
|
+
}
|
|
2376
|
+
return false;
|
|
2377
|
+
}
|
|
2378
|
+
/** The identifiers a binding name (identifier or destructuring pattern)
|
|
2379
|
+
* declares. */
|
|
2380
|
+
function boundNames7(name) {
|
|
2381
|
+
if (ts.isIdentifier(name))
|
|
2382
|
+
return [name];
|
|
2383
|
+
const out = [];
|
|
2384
|
+
for (const el of name.elements) {
|
|
2385
|
+
if (ts.isOmittedExpression(el) || el.name === undefined)
|
|
2386
|
+
continue;
|
|
2387
|
+
out.push(...boundNames7(el.name));
|
|
2388
|
+
}
|
|
2389
|
+
return out;
|
|
2390
|
+
}
|
|
2391
|
+
/** A namespace declaration whose body holds only types (interfaces, type
|
|
2392
|
+
* aliases, nested type-only namespaces) — no runtime object exists. */
|
|
2393
|
+
function typeOnlyNamespace7(decl) {
|
|
2394
|
+
let body = decl.body;
|
|
2395
|
+
while (body !== undefined && ts.isModuleDeclaration(body))
|
|
2396
|
+
body = body.body;
|
|
2397
|
+
if (body === undefined || !ts.isModuleBlock(body))
|
|
2398
|
+
return true;
|
|
2399
|
+
return body.statements.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
2400
|
+
ts.isTypeAliasDeclaration(s) ||
|
|
2401
|
+
(ts.isModuleDeclaration(s) && typeOnlyNamespace7(s)));
|
|
2025
2402
|
}
|
|
2026
2403
|
/** Resolves an import specifier from `from` to a source file of the
|
|
2027
2404
|
* program, or null (unresolvable / outside the program). Exported (as
|
|
@@ -2450,10 +2827,9 @@ function preflight7(load) {
|
|
|
2450
2827
|
// benign-cycle admission block above). Node evaluates such cycles
|
|
2451
2828
|
// benignly (the revisited module is a cache hit, and no binding read
|
|
2452
2829
|
// can hit TDZ or a stale slot), so the guarded %init calls reproduce
|
|
2453
|
-
// its order exactly. Cycles that fail both
|
|
2454
|
-
//
|
|
2455
|
-
//
|
|
2456
|
-
// static story does not model.
|
|
2830
|
+
// its order exactly. Cycles that fail both are judged by the exact
|
|
2831
|
+
// initialization rule: admitted when every early read is modeled by an
|
|
2832
|
+
// initialization check, fenced with SC1016 otherwise.
|
|
2457
2833
|
const edges = new Map();
|
|
2458
2834
|
const refusals = new Map();
|
|
2459
2835
|
const depPositions = new Map();
|
|
@@ -2927,9 +3303,10 @@ function preflight7(load) {
|
|
|
2927
3303
|
// Node's evaluation order: depth-first postorder from the entry, each
|
|
2928
3304
|
// module once, back-edges answered from the cache (a module already
|
|
2929
3305
|
// evaluating is skipped) — which the guarded %init calls reproduce
|
|
2930
|
-
// exactly. Cycles are admitted
|
|
2931
|
-
// semantics are UNOBSERVABLE (JS's partial
|
|
2932
|
-
// silent-misbehavior trap, so SC1016
|
|
3306
|
+
// exactly. Cycles are admitted where Node's partially-initialized
|
|
3307
|
+
// semantics are UNOBSERVABLE or exactly modeled (JS's partial
|
|
3308
|
+
// initialization is otherwise a silent-misbehavior trap, so SC1016
|
|
3309
|
+
// stays for the rest):
|
|
2933
3310
|
// - a DIRECT SELF-IMPORT (the package self-name reference resolving to
|
|
2934
3311
|
// the importing module itself — Node's self-reference rule): the
|
|
2935
3312
|
// imported bindings alias the module's OWN top-level bindings with
|
|
@@ -2941,7 +3318,11 @@ function preflight7(load) {
|
|
|
2941
3318
|
// benign-cycle admission block: every module of the cycle's
|
|
2942
3319
|
// strongly-connected component has an inert top level and the
|
|
2943
3320
|
// closing edge's bindings are used only in deferred positions, so no
|
|
2944
|
-
// read can execute before every member initialized)
|
|
3321
|
+
// read can execute before every member initialized);
|
|
3322
|
+
// - the EXACT INITIALIZATION rule: an ES-module cluster whose early
|
|
3323
|
+
// reads are all let/const bindings with module storage — the
|
|
3324
|
+
// lowering checks each one (cycleEarlyBindings) and throws Node's
|
|
3325
|
+
// ReferenceError on a read before the declaration ran.
|
|
2945
3326
|
const cycleAdmissionReason = makeCycleAdmission(program, (sf) => edges.get(sf) ?? []);
|
|
2946
3327
|
const order = [];
|
|
2947
3328
|
const state = new Map();
|
|
@@ -2957,9 +3338,9 @@ function preflight7(load) {
|
|
|
2957
3338
|
continue;
|
|
2958
3339
|
if (s === "visiting") {
|
|
2959
3340
|
// A back-edge: Node answers it from the cache (the module is
|
|
2960
|
-
// already evaluating) —
|
|
2961
|
-
//
|
|
2962
|
-
//
|
|
3341
|
+
// already evaluating) — admitted by the cheap per-edge rule, the
|
|
3342
|
+
// declaration-only init window rule, or the exact initialization
|
|
3343
|
+
// rule.
|
|
2963
3344
|
const reason = cycleAdmissionReason(sf, e);
|
|
2964
3345
|
if (reason !== null) {
|
|
2965
3346
|
const cycleStart = stack.indexOf(e.dep.fileName);
|