Skip to content

Align parser and Issue classes with hed-typescript; fix five bugs - #933

Merged
VisLab merged 3 commits into
hed-standard:mainfrom
VisLab:align_to_ts
Oct 22, 2026
Merged

VisLab merged 3 commits into
hed-standard:mainfrom
VisLab:align_to_ts

Conversation

@VisLab

@VisLab VisLab commented Oct 21, 2026

Copy link
Copy Markdown
Member

Phases 1 and 2 of the hed-typescript realignment: the parser layer and the Issue classes now follow hed-typescript's idioms. Where the two repositories behave differently, the hed-javascript behavior is kept.

Parser:

  • ParsedHedTag has value, splitValue, remainder, takesValue and hasUnitClass getters and a two-argument constructor. Other classes no longer read its private fields.
  • The tokenizer keeps the last delimiter as two fields. GroupSpec defaults end to -1 and children to [].
  • The splitter caches its result.
  • recursiveMap takes (array, fn). New iteratePairwiseCombinations and src/utils/types.js.
  • ParsedHedString, ParsedHedSubstring and ParsedHedColumnSplice have a default export only.
  • normalized keeps the code-unit sort order, written as toSorted().

Issues:

  • Issue.message is computed from the current parameters. addParameters keeps an existing parameter instead of overwriting it, and generateMessage is now a no-op.
  • addIssueParameters replaces updateIssueParameters, which stays as an alias.
  • New IssueError.generateAndRethrow.
  • issueMessageTemplate replaces stringTemplate.
  • unmatchedLibrarySchema takes a prefix parameter instead of library.
  • BidsHedIssue gains toString and a static addIssueParameters, copies with cloneDeep, and turns unrecognized input into an internal error.
  • datasetParser and paths throw IssueError instead of Error.
  • types/index.d.ts and types/test.ts updated to match.

Fixed:

  • ParsedHedTag.unitClasses was always empty.
  • ParsedHedTag.checkValue accepted a value for a tag that takes none.
  • parseHedStrings ignored fullValidation.
  • subParsedGroupIterator(tagName) yielded every group.
  • The sidecar validator's second error check never stopped validation.
  • BidsDataset.create reported an internal error as a plain object without a severity.

21 new tests. npm test: 903 passed (was 882). npm run testSpecs: 1251 passed, 1 skipped (unchanged).

Phases 1 and 2 of the hed-typescript realignment: the parser layer and the
Issue classes now follow hed-typescript's idioms. Where the two repositories
behave differently, the hed-javascript behavior is kept.

Parser:
- ParsedHedTag has value, splitValue, remainder, takesValue and hasUnitClass
  getters and a two-argument constructor. Other classes no longer read its
  private fields.
- The tokenizer keeps the last delimiter as two fields. GroupSpec defaults
  end to -1 and children to [].
- The splitter caches its result.
- recursiveMap takes (array, fn). New iteratePairwiseCombinations and
  src/utils/types.js.
- ParsedHedString, ParsedHedSubstring and ParsedHedColumnSplice have a
  default export only.
- normalized keeps the code-unit sort order, written as toSorted().

Issues:
- Issue.message is computed from the current parameters. addParameters keeps
  an existing parameter instead of overwriting it, and generateMessage is now
  a no-op.
- addIssueParameters replaces updateIssueParameters, which stays as an alias.
- New IssueError.generateAndRethrow.
- issueMessageTemplate replaces stringTemplate.
- unmatchedLibrarySchema takes a prefix parameter instead of library.
- BidsHedIssue gains toString and a static addIssueParameters, copies with
  cloneDeep, and turns unrecognized input into an internal error.
- datasetParser and paths throw IssueError instead of Error.
- types/index.d.ts and types/test.ts updated to match.

Fixed:
- ParsedHedTag.unitClasses was always empty.
- ParsedHedTag.checkValue accepted a value for a tag that takes none.
- parseHedStrings ignored fullValidation.
- subParsedGroupIterator(tagName) yielded every group.
- The sidecar validator's second error check never stopped validation.
- BidsDataset.create reported an internal error as a plain object without a
  severity.

21 new tests. npm test: 903 passed (was 882). npm run testSpecs: 1251
passed, 1 skipped (unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Public API mismatches, invalid-input handling, stale issue metadata, and quadratic pair allocation remain unresolved.

4 open issues
What changed in this PR

Aligns the HED validator’s parser and issue classes with hed-typescript while preserving project-specific validation behavior.

Changes:

  • Refactors parser state, tag accessors, normalization, and group traversal.
  • Updates issue construction, parameter handling, message generation, and BIDS error wrapping.
  • Adds regression tests and updates TypeScript declarations and release notes.
File Description
types/​test.ts Exercises the updated public types.
types/​index.d.ts Declares new accessors and issue helpers.
tests/​otherTests/​sidecarValidator.spec.js Tests early termination after validation errors.
tests/​otherTests/​parser.spec.js Covers parser fixes and tag accessors.
tests/​otherTests/​issues.spec.js Tests issue parameters, messages, and rethrowing.
tests/​otherTests/​dataset.spec.js Checks consistent dataset error wrapping.
tests/​otherTests/​bidsIssues.spec.js Tests BIDS issue copying and parameter handling.
src/​utils/​types.js Adds instance and numeric-pair checks.
src/​utils/​string.js Introduces the issue-message template helper.
src/​utils/​paths.js Refactors sidecar comparisons and error throwing.
src/​utils/​array.js Updates recursive mapping and adds pair iteration.
src/​parser/​tokenizer.js Refactors delimiter state and token specifications.
src/​parser/​tagConverter.js Updates schema access and conversion internals.
src/​parser/​splitter.js Caches splitting results and updates tag construction.
src/​parser/​reservedChecker.js Refactors singleton state and tag access.
src/​parser/​parseUtils.js Updates filtering and collection utilities.
src/​parser/​parser.js Forwards full validation for string lists.
src/​parser/​parsedHedTag.js Adds getters and corrects value/unit checks.
src/​parser/​parsedHedSubstring.js Standardizes the base class and default export.
src/​parser/​parsedHedString.js Updates tag collection and normalization.
src/​parser/​parsedHedGroup.js Fixes filtered traversal and updates normalization.
src/​parser/​parsedHedColumnSplice.js Standardizes exports and method signatures.
src/​parser/​eventManager.js Uses public tag accessors and structured errors.
src/​parser/​definitionManager.js Updates definition access and result handling.
src/​issues/​issues.js Computes messages dynamically and adds parameter helpers.
src/​issues/​data.js Migrates message templates and schema-prefix naming.
src/​bids/​validator/​sidecarValidator.js Fixes the second error check.
src/​bids/​types/​json.js Adopts the renamed issue-parameter helper.
src/​bids/​types/​issues.js Updates wrapping, copying, and parameter propagation.
src/​bids/​types/​dataset.js Returns consistent BIDS issues on creation failures.
src/​bids/​datasetParser.js Standardizes accessor failures as IssueError.
CHANGELOG.md Documents the realignment and fixes.

Review effort: Balanced

Comment thread src/bids/types/issues.js Resolved
Comment thread src/issues/issues.js Resolved
Comment thread src/parser/splitter.js Resolved
Comment thread src/utils/array.js Resolved
- BidsHedIssue.addIssueParameters refreshes line from the tsvLine parameter.
- Replacing Issue.parameters also clears the old bounds.
- The splitter again reports a HED string that is not a string as
  invalidTagString instead of throwing a TypeError.
- iteratePairwiseCombinations yields pairs lazily instead of building all of
  them first.

npm test: 905 passed. npm run testSpecs: 1251 passed, 1 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A missing runtime export and mismatched TypeScript contracts can cause consumer compilation failures or runtime errors.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

types/index.d.ts declared generateIssue, addIssueParameters and
updateIssueParameters as package exports, but index.js has never exported
them, so code that compiled against them failed at runtime. hed-typescript
does not export them either. They remain exported from src/issues/issues.js.

types/test.ts now builds its issues with the exported Issue constructor, and
npm run test-types runs to completion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VisLab

VisLab commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@copilot: Your last review "A missing runtime export and mismatched TypeScript contracts can cause consumer compilation failures or runtime errors." was did not give useful information.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Public type contracts still mismatch runtime behavior, and dataset creation errors lose their location context.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Preserve dataset path when wrapping errors

src/​bids/​types/​dataset.js:116

Passing null drops the dataset location previously included with unexpected errors. BidsHedIssue derives location from file?.path, so an error such as the new test's accessor failure now has neither the dataset path in its message nor a structured location. Pass the dataset-root path (or Uploaded files) when wrapping the error to preserve that diagnostic context.

Medium severity Return defined values for valueless tags

src/​parser/​parsedHedTag.js:358

For a tag without a value, such as Red, _handleRemainder() returns before assigning _value or _splitValue, so both new getters return undefined. Their public declarations promise string and string | null, allowing calls such as tag.value.length to type-check but throw at runtime. Return an empty string and null for absent values so the getters match their declared contract without changing the backing fields.

Review effort: Balanced

@VisLab
VisLab merged commit 8bb1959 into hed-standard:main Oct 22, 2026
13 checks passed
VisLab added a commit that referenced this pull request Oct 22, 2026
Addresses the two issues in Copilot's summary review of PR #933 at
0a4892e. BidsDataset.create wrapped a dataset-level error with no file,
so it lost the location it had before (the dataset root, or "Uploaded
files" for browser input); it now passes that location. ParsedHedTag's
value and splitValue getters returned undefined for a tag without a
value although they are declared string and string | null; they now
return '' and null, leaving the backing fields unchanged.
hed-typescript has the same getter gap (parsedHedTag.ts:220-225) and
passes null in BidsDataset.create (dataset.ts:121); both go on the port
list. Three regression tests and two CHANGELOG clauses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VisLab
VisLab deleted the align_to_ts branch October 26, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants