Skip to content

Design: strict import mode and scopes for component statements #1959

Open

Description

@chrisdp

Design note for strict import mode (#374) and component statements (#575), on top of code segments (#1934).

Scopes keep two lists

  • Loaded: the transitive closure, as today. Used for duplicate checks and the output <script> list. The first pass still flags duplicates rather than fixing them.
  • Visible: per file, itself plus its direct imports. Used for name resolution under strict mode.

The dependency graph needs to expose each file's direct imports.

Strict mode (a setting, default TBD)

  • Every file is strict, including .brs.
  • .bs files: direct imports. .brs files and CDATA blocks: direct ' bs:import "..." comments.
  • xml <script> tags count as strict. Scripts in the same xml don't see each other.
  • Global functions and Library statements stay visible.
  • bs:import requires an import; it doesn't perform one. It's an error if the component doesn't load the target.
Diagnostic Quick fix
Cannot find X Add import / ' bs:import
Import of Z isn't loaded by component Y Add <script> to Y's xml

Migration: add a fix-all for missing imports, and allow bs:disable for files not converted yet.

Component statements

The #575 proposal doc already defines the scope: the component body, the file's other functions, the file's imports and the parent. That's an XmlScope whose root is a statement instead of an xml file.

  • One component per file (diagnostic otherwise), so the file stays one code segment.
  • Pull the component definition (name, parent, interface, children) out of XmlScope, so an xml file and a statement can both provide it.
  • Create scopes from statements using the provideScope events.
  • Generate the xml and codebehind at build time, not as virtual:/ files.

Open questions

  • Should interface functions and onChange handlers resolve only against the component's direct scripts?
  • Strict mode default.
  • Component statements in source/.

Order

  1. Two-list scopes.
  2. Strict mode, then bs:import.
  3. Pull the component definition out of XmlScope.
  4. Component statements.

Later: resolve import-only files once per file instead of per scope.

Related: #374, #575, #971, #1934, #445, #848, #1851

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions