SourceTextModule

external class SourceTextModule : Module(source)

This feature is only available with the --experimental-vm-modules command flag enabled.

The vm.SourceTextModule class provides the Source Text Module Record as defined in the ECMAScript specification.

Since

v9.6.0

Constructors

Link copied to clipboard
constructor(code: String, options: SourceTextModuleOptions = definedExternally)

Creates a new SourceTextModule instance.

Properties

Link copied to clipboard
external var context: Context
Link copied to clipboard
Link copied to clipboard
external var error: Any?

If the module.status is 'errored', this property contains the exception thrown by the module during evaluation. If the status is anything else, accessing this property will result in a thrown exception.

Link copied to clipboard
external var identifier: String

The identifier of the current module, as set in the constructor.

Link copied to clipboard

The requested import dependencies of this module. The returned array is frozen to disallow any changes to it.

Link copied to clipboard
external var namespace: Any

The namespace object of the module. This is only available after linking (module.link()) has completed.

Link copied to clipboard
external var status: ModuleStatus

The current status of the module. Will be one of:

Functions

Link copied to clipboard
suspend external fun evaluate(options: ModuleEvaluateOptions = definedExternally): Void
Link copied to clipboard
external fun evaluateAsync(options: ModuleEvaluateOptions = definedExternally): Promise<Void>

Evaluate the module and its depenendencies. Corresponds to the Evaluate() concrete method field of Cyclic Module Records in the ECMAScript specification.

Link copied to clipboard
external fun hasAsyncGraph(): Boolean

Iterates over the dependency graph and returns true if any module in its dependencies or this module itself contains top-level await expressions, otherwise returns false.

Link copied to clipboard
external fun hasTopLevelAwait(): Boolean

Returns whether the module itself contains any top-level await expressions.

Link copied to clipboard
external fun instantiate()

Instantiate the module with the linked requested modules.

Link copied to clipboard
suspend external fun link(linker: ModuleLinker): Void
Link copied to clipboard
external fun linkAsync(linker: ModuleLinker): Promise<Void>

Link module dependencies. This method must be called before evaluation, and can only be called once per module.

Link copied to clipboard
external fun linkRequests(modules: ReadonlyArray<Module>)

Link module dependencies. This method must be called before evaluation, and can only be called once per module.