backend-api.ts:
- Extract parseErrorBody() module helper — both postJson and
getAssemblyDocumentation now share one error-body extraction path
rather than duplicating the try/json/field-scan/fallback logic
- Drop 'import _ from underscore' — formatCode now destructures
FormattingRequest directly instead of using \_.pick
- postJson error message no longer prefixed 'Request failed:' —
the extracted message is already self-describing
compiler-service.ts:
- Extract private submitToCompiler(request, compileFn) — submit and
submitCMake were identical except for the compile function called;
both are now one-liners delegating to the shared helper
🤖 Generated by LLM (Claude, via OpenClaw)
- postJson now parses JSON error body for 'answer'/'error'/'message'
fields so callers see meaningful messages (e.g. formatter output on
422) rather than generic 'Request failed: 422 Unprocessable Entity'
- _api promoted from const to let; setBackendApi() exported so tests
(and future test helpers) can inject a fake BackendApi implementation
- Update module-doc comment to reflect injection is now available
🤖 Generated by LLM (Claude, via OpenClaw)
Replace all $.ajax calls with native fetch:
- Private postJson<T>() helper consolidates the common POST+JSON pattern —
compile, compileCMake, popularArguments, formatCode, shortenUrl are now
one-liners each
- Removes import of jquery, jqXHR, ErrorTextStatus, and makeError() entirely
- getAssemblyDocumentation kept explicit (different error handling: structured
error body extraction, credentials: omit)
Copilot second-round fixes:
- editor.ts: replace getSource()! with explicit undefined guard (early return)
- editor.ts: replace result.answer! with explicit undefined check and error
notification if exit===0 but answer is missing
- editor.ts: .catch param typed unknown with instanceof Error guard
- sharing.ts: drop unused _root param from getShortLink and update call site
- sharing.ts: .catch param typed unknown with instanceof Error guard
🤖 Generated by LLM (Claude, via OpenClaw)
Copilot issues:
- Add missing 'import $ from jquery' to backend-api.ts
- Add contentType: 'application/json' to popularArguments (missing vs compile/compileCMake)
- Use makeError() in shortenUrl for consistent structured error messages
- Fix getAssemblyDocumentation: check response.ok before parsing JSON body
to handle non-JSON error responses (e.g. HTML proxy error pages)
Behavioural discrepancies vs original noted and accepted:
- editor.ts now sends tabWidth + useSpaces to format endpoint (strict
improvement; consistent with formatter-registry.ts which always sent them)
- editor.ts HTTP format error now shows HTTP status/statusText rather than
attempting to parse xhr.responseText for an answer field; acceptable as
the format endpoint returns HTTP 200 in all non-network-error cases
🤖 Generated by LLM (Claude, via OpenClaw)
- Remove export from HttpBackendApi — module-private class
- Constructor takes baseUrl param; window.location.origin + window.httpRoot
passed at module-load time — window.* reference centralised in one place
- _api is now a const, eagerly initialised; getBackendApi() is a trivial return
- formatCode: include response.statusText in error message (was lost vs original)
- editor.ts:1174: remove ??\ '' from getSource() call — use non-null assertion
(getSource() is always defined when format button is reachable)
🤖 Generated by LLM (Claude, via OpenClaw)
- Merge api/api.ts into backend-api.ts — single file, no thin wrapper layer
- Remove setBackendApi() — getBackendApi() now lazy-inits HttpBackendApi by default
- Remove explicit setBackendApi call from hub.ts (no longer needed)
- Rename getAssemblyDoc → getAssemblyDocumentation for consistency
- Fix error caching in compiler.ts getAsmInfo — catch errors and cache
{found: false, data: message} before re-throwing, matching original behaviour
- Remove ?? '' fallbacks in editor.ts formatCurrentText — use non-null
assertion; answer is always present when exit === 0
- Call getBackendApi() directly in compiler.ts and formatter-registry.ts
rather than through function wrappers
🤖 Generated by LLM (Claude, via OpenClaw)
Introduce a BackendApi interface that acts as a single injectable seam
between the CE frontend and its HTTP backend. All CE-specific backend
requests now route through this interface.
- static/api/backend-api.ts: new BackendApi interface + HttpBackendApi
implementation; module-level setBackendApi/getBackendApi accessors
- static/hub.ts: register HttpBackendApi at startup via setBackendApi()
- static/compiler-service.ts: submit/submitCMake/requestPopularArguments
delegate to getBackendApi(); removes handleRequestError, getBaseUrl,
and the jQuery dependency from this file
- static/api/api.ts: getFormattedCode and getAssemblyDocumentation now
delegate to getBackendApi(); callers updated to receive parsed body
directly rather than a Response wrapper
- static/panes/editor.ts: formatCurrentText() uses getBackendApi()
instead of a direct $.ajax call; now passes full FormattingRequest
- static/sharing.ts: getShortLink() uses getBackendApi().shortenUrl()
- static/formatter-registry.ts, static/panes/compiler.ts: updated for
new return types (direct parsed body, HTTP errors now thrown)
No behaviour change. This seam is the foundation for injectable test
fakes in a follow-up PR.
🤖 Generated by LLM (Claude, via OpenClaw)
Makes the Compiler Explorer app, and all the tooling ESM compatible.
Things that have been done:
1. The package.json has `type: module` now
2. All relative imports have a .js ending
3. All directory imports are now directory/index.js to comply with ESM
standards
4. Dependency node-graceful is now imported into tree, because the
package is broken under esm
5. Dependency p-queue has been bumped to 7.x with ESM support
6. Dependency profanities has been bumped to 3.x with ESM support
7. Webpack config is now both ESM and CommonJS compatible
8. Non-ESM compatible imports have been rewritten
9. ESLint configuration has been tweaked to not fail on .js imports
10. Mocha is now hacked together and ran with ts-node-esm
11. Webpack is now hacked together and ran with ts-node-esm
12. Webpack config is now ESM compatible, so that it can be used in the
dev server
13. Cypress code still runs commonjs, and has been excluded from the
tsconfig
14. All sinon mock tests have been commented out, because sinon module
mocks do not work with ESModules (because ESModules are immutable)
A lot of tests are now giving warnings/errors to stdout, yet still pass.
Docenizer codegenerator scripts have been updated, but I did not re-run
them, and instead just changed their code.
---------
Co-authored-by: Matt Godbolt <matt@godbolt.org>
Refactors the handler for the AsmDocs API to reduce code duplication.
**Breaking changes proposed**
- API will now return 404. This used to return 200 with "Unknown opcode" which is what led to issue #3117. Following cases has been changed:
1. archiecture was not found
2. instruction opcode was not found
- API will now return 406 not acceptable when the accepted content type is not text or json
- There is no longer a `result` field on a 200 request, instead the assembly documentation object is returned.
- There is no longer a `found` field on any request, the HTTP codes indicate whether it was found or not (200 means found)
**New features**
- The frontend will only request the opcode for an instruction set at most once, caching every single outgoing request.
- The "There was an error fetching the documentation for this opcode" has been adjusted to contain what went wrong.
Relevant tests have been added and updated.