Commit Graph

17 Commits

Author SHA1 Message Date
mattgodbolt-molty
39723aa78d refactor: simplify and deduplicate
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)
2026-02-22 18:03:17 -06:00
mattgodbolt-molty
fd6b46fc99 fix: address third Copilot round — postJson error body + setBackendApi
- 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)
2026-02-22 17:53:53 -06:00
mattgodbolt-molty
d3f9c82320 refactor: replace $.ajax with fetch; address second Copilot round
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)
2026-02-22 16:15:34 -06:00
mattgodbolt-molty
9e0e4e8e7d fix: address Copilot feedback and behavioural review
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)
2026-02-22 15:59:17 -06:00
mattgodbolt-molty
51ff48ebe0 refactor: address second round of review feedback
- 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)
2026-02-22 15:44:14 -06:00
mattgodbolt-molty
f659dbc594 refactor: address review feedback on BackendApi PR
- 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)
2026-02-22 15:29:39 -06:00
mattgodbolt-molty
92fd9f5dfc refactor: extract BackendApi interface from CompilerService and friends
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)
2026-02-22 15:14:28 -06:00
Patrick Quist
b707712ac6 Remember asm docs in browser (#8216) 2025-10-28 09:45:26 +01:00
Mats Jun Larsen
5eea63328f Migrate to Biome for linting and formatting (#7033) 2025-02-02 17:54:31 +00:00
Mats Jun Larsen
633eb82d18 Transition to ECMAScript Modules (#4780)
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>
2023-02-27 18:06:38 -06:00
Mats Larsen
4f9a34c511 Also enable prettier for recursive directories in static (#3539)
* Also enable prettier for recursive directories in static

* Fix formatting

* Fixes
2022-04-24 19:11:48 +02:00
Jeremy Rifkin
0bffd4ec0f Resolve @typescript-eslint/no-unnecessary-condition for static/*.ts files (#3511) 2022-04-16 00:36:00 +02:00
Rubén Rincón Blanco
42c7b2b694 Make eslint work on static ts files (#3304) 2022-02-03 18:04:50 +01:00
Rubén Rincón Blanco
f4315c561b Move static/settings.js to TypeScript (#3297)
* Rename settings.js to ts

* Move Settings to TS

* Remove underscore from settings

* Update static/settings.ts

Co-authored-by: Mats Larsen <me@supergrecko.com>

* Update static/settings.ts

Co-authored-by: Mats Larsen <me@supergrecko.com>

* Improve Settings implementation

* Move Settings interfaces to same file

* Update static/settings.ts

Co-authored-by: Mats Larsen <me@supergrecko.com>

Co-authored-by: Mats Larsen <me@supergrecko.com>
2022-01-29 02:00:10 +01:00
Mats Larsen
da1a3ab7dc Make it possible to share types in /types directory between front and backend (#3211)
* Make it possible to share types in /types directory between front and backend

* Add new tsconfig files to gh-dist-files
2021-12-28 15:53:34 +01:00
Mats Larsen
112df32116 Use api.ts file for formatter api requests (#3160) 2021-12-15 19:30:03 +01:00
Mats Larsen
d7c4eecbf7 Refactor and return 404 from AsmDocs APIs (#3143)
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.
2021-12-07 11:43:08 +01:00