pwscript

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pwscript reads a component's script block far enough to answer the two questions generation asks of it: which handlers the component publishes, and which of its parameters the block asked to be given.

It exists here rather than upstream because the block is authored browser code and this framework owns the browser half. The module reports the bytes and takes the answer back as a compile option, and reading them is ours.

It is not a JavaScript parser and does not pretend to be one. It scans, which means it skips the four things a pattern match gets wrong — a string, a template literal, a comment, and a regular expression literal — and then reads structure only where the structure is the idiomatic one. Anything else is reported as unread rather than guessed at, because a wrong answer here publishes a handler that does not exist or a value nobody meant to disclose.

Index

Constants

View Source
const PropertyBagKey = "props"

PropertyBagKey is the key a setup destructures its component's parameters from. It is one key rather than flat names so that a parameter cannot collide with a capability the bag also carries, and so that a capability added later breaks nothing.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// Handlers are the names the returned object publishes, in source order.
	Handlers []string
	// Parameters are the component parameters the setup pattern destructured.
	Parameters []string
	// Unread says why a question could not be answered, empty when both were.
	//
	// It is a reason rather than a flag because it reaches a build log, where
	// "setup returns a variable" tells an author what to change and "could not
	// read the block" tells them to file a bug.
	Unread string
}

Block is what one component's script block says about itself.

func Read

func Read(source string) (Block, error)

Read scans one block.

An error is returned only for a source this scanner cannot walk at all, such as one whose quoting never closes. A block it walks but cannot understand comes back with Unread set and both lists empty, which is the answer that makes generation check nothing rather than refuse everything.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL