Repository navigation
Conversation
access that starts with a `.` (`.name = "x"`, `.save()`, `print .name`) refers to the target, so a series of operations on one object doesn't have to repeat its name on every line. The block itself produces no BrightScript. When the target is a plain variable it is used directly (`with order` / `.id = 1` becomes `order.id = 1`). Any other target (a property chain, a call, a literal, a nested `.member`) is evaluated once into a local, `__bsc_tmp_with<n>`, so the expression doesn't run again for every member. Nested blocks that each need a local get distinct names; sibling blocks reuse the same one. Parsing: - `with` is not a reserved word in BrightScript, so existing code may use it as a variable or function. `with = 1`, `print with`, `with.foo`, `with(1)` and `with[0]` still parse as before. When `with` is followed by `.`, `(` or `[`, only the whitespace tells a block (`with .foo`, `with (a)`) from a variable (`with.foo`, `with(a)`), the same way `? [` and `?[` are already told apart. - A leading `.` becomes a `WithContextExpression` wrapped in the usual `DottedGetExpression`, so type checking, hover, completions and the transpiler work on `.member` with no special casing. The node resolves its block by walking up to the innermost enclosing `WithStatement`, skipping the block's own target (`with .inner` refers to the outer block) and stopping at a function boundary. - The parser tracks `with` depth per function. Outside a block a leading `.` is still a syntax error that discards the line, so error recovery for stray dots is unchanged; in `.bs` files it gets a specific message. Validation: - `.member` outside a `with` block, or inside a function defined within the block (BrightScript functions can't see the containing function's locals), is an error. - `goto` into a `with` block from outside it is an error, since that would skip the step that evaluates the target. - `with` in a `.brs` file is flagged like other BrighterScript-only features. Also: - `end with` / `endwith` tokens, `BlockTerminators`, visitor and reflection entries for the two new AST nodes. - Completions after a leading `.` list the target's members. - Comments on and around the block are preserved in the output. - Docs: docs/with-statement.md, linked from the docs index and README.
with <target> ... end with block. Inside the body, any member
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # src/bscPlugin/validation/BrsFileValidator.ts Co-authored-by: iObject <2446955+iObject@users.noreply.github.com>
iObject
marked this pull request as ready for review
October 16, 2026 12:34
Contributor
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # src/bscPlugin/validation/BrsFileValidator.ts Co-authored-by: iObject <2446955+iObject@users.noreply.github.com>
Contributor
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # src/bscPlugin/validation/BrsFileValidator.ts Co-authored-by: iObject <2446955+iObject@users.noreply.github.com>
Contributor
…with` body Any other statement (print, plain function calls, local assignments, if, loops, goto, labels) is flagged as an unexpected token on its first token.
A `with` block can now be the entire value of a local assignment (`x = with target ... end with`) or a return (`return with target ... end with`), as well as a standalone statement. Assignments run the body against the assigned variable; returns run the body and then return the target. Also use a temp local for a variable target that doesn't transpile to its own name (such as an inlined const), which previously produced a reference to a variable that doesn't exist at runtime.
A `with` block can now be the entire value of a local assignment (`x = with target ... end with`) or a return (`return with target ... end with`), as well as a standalone statement. Assignments run the body against the assigned variable; returns run the body and then return the target. Also use a temp local for a variable target that doesn't transpile to its own name (such as an inlined const), which previously produced a reference to a variable that doesn't exist at runtime.
…brighterscript into 19-support-with-statement
Rename the doc and its README links, call the feature a with expression in the docs and the .brs-file warning, and use a utils.getScene() namespace example instead of promises.
Remove isReturnValue (unused) and make isAssignmentValue, usesTempVariable and getTempVariableName private. getContextName and getWithExpression stay public since ReturnStatement, WithContextExpression and BrsFileValidator use them.
# Conflicts: # src/bscPlugin/validation/BrsFileValidator.ts # src/lexer/TokenKind.ts
TwitchBronBron
force-pushed
the
19-support-with-statement
branch
from
November 13, 2026 18:49
c793186 to
abfa406
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #19
Adds a
with <target> ... end withexpression (BrighterScript only). Inside the body,.memberrefers to the target, and the body can contain any statement. It's modeled on VB'sWith...End With. Docs are in docs/with-expression.md.WithExpression(target plus aBlockbody) andWithContextExpression(the implicit object of a leading.member). Awithcan stand alone (wrapped in anExpressionStatement), or be the entire value of a local assignment (x = with ...) or areturn.__bsc_tmp_with<n>, unless it's a plain variable that the body never reassigns. Then the variable is used directly..memberworks in any expression position, with type checking, hover, go-to-definition, semantic tokens and completions.with-member-outside-with-block,with-member-in-nested-function,goto-into-with-block,expected-expression-after-with..brsfileswith/endwithstay ordinary identifiers. Onlywith <identifier>(never valid BrightScript) is parsed as a block, so it can reportbs-feature-not-supported. In.bsfiles,with.x,with(1),with = 1and similar forms still readwithas a variable. Only the whitespace separateswith (a)fromwith(a).Risks:
WithExpressionis an expression that holds statements. Statement-only walks still reach the body, becauseAssignmentStatement,ExpressionStatementandReturnStatementwalk awithvalue in statement mode. Plugins that assumeExpressionStatement.expressionis a call will now also see aWithExpression.brighterscript-formatterindentation, the TextMate grammar invscode-brightscript-language, and a check of bslint's code-flow rules against the new node.Verified with
npm run test:nocoverandnpm run lint.🤖 Generated with Claude Code