Skip to content

fix(compiler): preserve nested None defaults (#103) - #115

Open
amazingjoe wants to merge 1 commit into
salesforce:mainfrom
amazingjoe:fix-issue-103
Open

amazingjoe wants to merge 1 commit into
salesforce:mainfrom
amazingjoe:fix-issue-103

Conversation

@amazingjoe

Copy link
Copy Markdown
Contributor

What

Preserve nested None values as JSON null in compiled variable defaults, retaining object properties, list lengths, and element positions.

Why

extractExpressionValue() did not handle NoneLiteral, so it returned undefined. Recursive dictionary extraction then omitted those properties, and list extraction filtered out those elements without emitting diagnostics.

Fixes #103

How

Recognize NoneLiteral in extractExpressionValue() and return JavaScript null. Existing dictionary and list extraction already preserve null values.

The production change is confined to packages/compiler/src/ast-helpers.ts. Regression tests were added to two existing compiler test files.

File Change / test names
packages/compiler/src/ast-helpers.ts Convert NoneLiteral to null, preserving nested object properties and list elements.
packages/compiler/test/ast-helpers.test.ts should extract NoneLiteral as JSON null
packages/compiler/test/state-variables.test.ts should preserve 'object properties containing None' in defaults
packages/compiler/test/state-variables.test.ts should preserve 'list positions containing None' in defaults
packages/compiler/test/state-variables.test.ts should preserve 'None inside an object containing a list and another object' in defaults
packages/compiler/test/state-variables.test.ts should preserve 'None inside a list containing another list and an object' in defaults
packages/compiler/test/state-variables.test.ts should preserve 'falsy values inside objects and lists' in defaults

Test Plan

Added six tests using the existing Vitest framework:

  • One helper regression verifying NoneLiteral becomes null.
  • Two variable-default regressions matching the issue’s object and list examples.
  • Two regressions covering null preservation through deeper object/list nesting.
  • One compatibility control verifying False, 0, and empty strings remain intact.

Existing tests and assertions were retained, including standalone None omission coverage.

Compiler tests Before fix After fix
Existing tests 1,327 passed; 3 skipped 1,327 passed; 3 skipped
New compatibility control 1 passed 1 passed
New bug regressions 5 failed 5 passed
Total 1,328 passed; 5 failed; 3 skipped 1,333 passed; 0 failed; 3 skipped

The exact issue reproduction now produces the expected defaults:

Variable Before fix After fix
payload {"kept":1} {"missing":null,"kept":1}
items [{"n":1}] [null,{"n":1},null]

The falsy-value control remains unchanged. The reproduction exited with status 1 before the fix and 0 afterward. Parsing succeeded and schema, lint, and compiler diagnostics were empty in both runs.

Additional validation:

  • Full monorepo pnpm test: 24/24 tasks successful.
  • Vitest suites: 6,937 passed; 1,001 skipped; 0 failed.
  • Native parser corpus: 206 successful parses; 0 failed.
  • Compiler build and compiler typecheck pass.
  • Formatting and git diff --check pass.

Repository-wide pnpm lint && pnpm typecheck has not been run.

  • Existing tests pass (pnpm test)
  • New/updated tests cover the change
  • Linting and type checks pass (pnpm lint && pnpm typecheck)

Checklist

  • My code follows the project's coding style
  • I have reviewed my own diff
  • I have added/updated documentation as needed — no public documentation changes needed
  • This change does not introduce new warnings

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Compiler drops nested None values from object and list defaults

1 participant