Skip to content

chore(transpiler): prune dead code from Phase 2 cleanup - #851

Merged
dcoutinho1328 merged 1 commit into
developmentfrom
chore/transpiler-dead-code-cleanup
Jun 8, 2026
Merged

chore(transpiler): prune dead code from Phase 2 cleanup#851
dcoutinho1328 merged 1 commit into
developmentfrom
chore/transpiler-dead-code-cleanup

Conversation

@dcoutinho1328

@dcoutinho1328 dcoutinho1328 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #843. The Phase 2 transpiler consolidation left a few unreached surfaces — this PR removes them and aligns naming.

Changes

  • Drop @xmldom/xmldom dep. Added for the DOM walker Phase 2d retired. Zero src/ consumers remain (verified with grep). Removed from package.json, package-lock.json regenerated. 8 transitive packages drop with it.

  • Delete the CTN-globals plugin API. Removes:

    • helpers/ctn-globals.ts types CtnGlobalEntry, CtnGlobalVarTuple, ConfigurationExtraVariablesProvider
    • The three corresponding re-exports from index.ts
    • emit/configuration.ts: the extraVarsProvider option in GenerateConfigurationOptions, the collectConfigGlobals helper, the tupleTypeToIr helper
    • transpileToSt's options parameter (was only ever extraVarsProvider)

    The API was forward-looking — no caller in either repo wires up a provider. The surviving constant PLC_BASE_TYPES (used by emit/pou-graphical.ts and emit/pou-textual.ts) moves to helpers/base-types.ts since ctn-globals was named after the API that just disappeared.

  • Delete isOfType + getSubTypes from helpers/type-hierarchy.ts. getSubTypes was the only isOfType consumer, and getSubTypes itself has no callers. Both were placeholders for an overload-resolution path that never materialised. TypeHierarchy constant stays — emit/value.ts still uses it.

  • Delete computePouTransitionName + computePouActionName from helpers/text-helpers.ts. SFC-only naming helpers; SFC support was dropped in Phase 2d (from-schema.ts throws at projection time).

Diff

-218 / +56 lines on this side, matched on the web side.

Verification

  • npx tsc --noEmit clean (modulo pre-existing strucpp module errors that exist on development too).
  • npx eslint src/backend/shared/transpilers/st-transpiler/ — 0 errors.
  • npx prettier --check src/backend/shared/transpilers/st-transpiler/ clean.
  • Editor st-transpiler/ byte-identical to web's. Paired with openplc-web equivalent: chore/transpiler-dead-code-cleanup.

What this PR does NOT touch

  • compiler-adapter.ts's ladderToXml / fbdToXml consumers — those still feed the user-visible "Export Project to XML" feature.
  • compilerFetch in web-compiler-platform-port.ts — still used by /compile-arduino.
  • pou-emission-order.ts's textual scanning — alive for ST/IL bodies.
  • BlockIO / BlockInfos / BlockResolution exports — they're return-type shapes for resolveBlockType, kept for API discoverability.
  • Pre-existing broken shared tests in __tests__/{pipeline,library-build-orchestrator}.test.ts that reference transpileXmlToSt (renamed to transpileToSt in feat(compile): embed JSON→ST transpiler, retire xml2st binary #843). Those need a separate fix.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Simplified configuration generation API by removing optional parameters.
    • Streamlined type system by consolidating helper modules and removing unused utility functions.
    • Updated type hierarchy to exclude WSTRING.
  • Chores

    • Removed unused dependency.
    • Reorganized module imports.
    • Updated documentation for code generation walker.

The Phase 2 transpiler consolidation left a few unreached surfaces
that this commit removes:

- Drop `@xmldom/xmldom` dependency.  Was added for the DOM walker
  that Phase 2d retired; zero `src/` consumers remain.
- Delete the CTN-globals plugin API (`CtnGlobalEntry`,
  `CtnGlobalVarTuple`, `ConfigurationExtraVariablesProvider`).  No
  caller wires up a provider — the API was forward-looking only.
  `emit/configuration.ts` loses the `extraVarsProvider` option and
  the `collectConfigGlobals` / `tupleTypeToIr` helpers along with
  it; `transpileToSt`'s `options` parameter disappears as a
  consequence.  Rename the surviving constant's home from
  `helpers/ctn-globals.ts` to `helpers/base-types.ts` (the file
  was named after the API surface that just went away).
- Delete `isOfType` and `getSubTypes` from `helpers/type-hierarchy.ts`.
  Defined as a forward-looking overload-resolution helper, never
  called; `getSubTypes` was the only `isOfType` consumer.  The
  `TypeHierarchy` constant itself stays — `emit/value.ts` reads it.
- Delete `computePouTransitionName` and `computePouActionName` from
  `helpers/text-helpers.ts`.  SFC-only naming helpers; SFC support
  was dropped in Phase 2d.

`tsc --build`, `eslint`, and `prettier --check` clean.  Editor and
web `st-transpiler/` trees remain byte-identical for Shared Surface
Sync.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5af3ebdc-9fe4-47f4-9b0a-4d9c1f28affd

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa9dfc and dc70a92.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • package.json
  • src/backend/shared/transpilers/st-transpiler/emit/configuration.ts
  • src/backend/shared/transpilers/st-transpiler/emit/pou-graphical.ts
  • src/backend/shared/transpilers/st-transpiler/emit/pou-textual.ts
  • src/backend/shared/transpilers/st-transpiler/helpers/base-types.ts
  • src/backend/shared/transpilers/st-transpiler/helpers/ctn-globals.ts
  • src/backend/shared/transpilers/st-transpiler/helpers/text-helpers.ts
  • src/backend/shared/transpilers/st-transpiler/helpers/type-hierarchy.ts
  • src/backend/shared/transpilers/st-transpiler/index.ts
  • src/backend/shared/transpilers/st-transpiler/walker/README.md
💤 Files with no reviewable changes (3)
  • src/backend/shared/transpilers/st-transpiler/helpers/ctn-globals.ts
  • package.json
  • src/backend/shared/transpilers/st-transpiler/helpers/type-hierarchy.ts

Walkthrough

This PR removes the CTN globals provider infrastructure from the ST transpiler, consolidates PLC base type definitions into a dedicated module, and simplifies the public transpiler APIs by eliminating optional configuration parameters that previously allowed external injection of extra variables at transpile time.

Changes

CTN Globals Removal and API Simplification

Layer / File(s) Summary
PLC_BASE_TYPES extraction and relocation
src/backend/shared/transpilers/st-transpiler/helpers/base-types.ts, src/backend/shared/transpilers/st-transpiler/emit/pou-textual.ts, src/backend/shared/transpilers/st-transpiler/emit/pou-graphical.ts
Introduces base-types.ts with PLC_BASE_TYPES constant (IEC base type set excluding WSTRING), and updates pou-textual and pou-graphical imports to reference the new module instead of ctn-globals.
Configuration API simplification and IR-native global emission
src/backend/shared/transpilers/st-transpiler/emit/configuration.ts
Removes the optional options parameter from generateConfigurations, eliminates the CTN globals provider callback mechanism, updates global variable emission to use project.configuration.globalVariables directly, and removes helper functions collectConfigGlobals and tupleTypeToIr.
Transpiler entry-point API simplification
src/backend/shared/transpilers/st-transpiler/index.ts
Removes the optional options parameter from transpileToSt, eliminates the TranspileOptions type, removes re-exports of ConfigurationExtraVariablesProvider, CtnGlobalEntry, and CtnGlobalVarTuple, and updates the configuration emission call.
Helper function and type hierarchy cleanup
src/backend/shared/transpilers/st-transpiler/helpers/text-helpers.ts, src/backend/shared/transpilers/st-transpiler/helpers/type-hierarchy.ts
Removes exported functions computePouTransitionName and computePouActionName, removes WSTRING entry from TypeHierarchy to preserve Python TODO behavior, and updates text-helpers documentation.
Dependency removal and documentation updates
package.json, src/backend/shared/transpilers/st-transpiler/walker/README.md
Removes @xmldom/xmldom dependency and updates walker README to clarify module breakdown, responsibilities, and canonical reference to Python's xml2st generator.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement

Suggested reviewers

  • JoaoGSP
  • thiagoralves
  • DanielBorgesDev

Poem

🐰 A rabbit's refactoring delight,
CTN globals fade from sight!
Base types now dance in their own space,
Simpler APIs set the pace,
No more options to confuse the flow,
TypeScript defaults steal the show!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is comprehensive with detailed changes, verification steps, and scope boundaries, but does not follow the provided template structure with required sections like References, DOD checklist, and test coverage metrics. Consider structuring the description to match the repository template: add References section with issue #843, include DOD checklist items, and specify test coverage percentage if available.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore(transpiler): prune dead code from Phase 2 cleanup' accurately summarizes the main change—removing unused code from the transpiler module after Phase 2 consolidation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/transpiler-dead-code-cleanup

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dcoutinho1328
dcoutinho1328 merged commit 2ae973a into development Jun 8, 2026
12 checks passed
@dcoutinho1328
dcoutinho1328 deleted the chore/transpiler-dead-code-cleanup branch June 8, 2026 13:48
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.

1 participant