Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: improve typescript error message format #57598

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot commented Mar 23, 2025

This is an automated update of amaro to 0.5.0.

Fixes: #56830

This PR improves the error messages generated by the transpiler.

Node.js v23.9.0:

marcoippolito@marcos-MacBook-Pro node % node --input-type=commonjs-typescript -p "enum Foo"
node:internal/modules/typescript:69
        throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);
        ^

SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]:   x Expected '{', got '<eof>'
   ,----
 1 | enum Foo
   :      ^^^
   `----

    at parseTypeScript (node:internal/modules/typescript:69:15)
    at processTypeScriptCode (node:internal/modules/typescript:129:42)
    at stripTypeScriptModuleTypes (node:internal/modules/typescript:196:22)
    at parseAndEvalCommonjsTypeScript (node:internal/process/execution:369:26)
    at node:internal/main/eval_string:71:3 {
  code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}

This PR:

marcoippolito@marcos-MacBook-Pro node % ./node --input-type=commonjs-typescript -p "enum Foo"
[eval]:1   
        
     enum Foo
          ^^^
        
SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: Expected '{', got '<eof>'
    at parseTypeScript (node:internal/modules/typescript:71:36)
    at processTypeScriptCode (node:internal/modules/typescript:145:42)
    at stripTypeScriptModuleTypes (node:internal/modules/typescript:212:22)
    at parseAndEvalCommonjsTypeScript (node:internal/process/execution:375:26)
    at node:internal/main/eval_string:71:3 {
  code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}

It removes the internal file path:

node:internal/modules/typescript:69
        throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);

Removes the padding boxing the message:

   ,----
 1 | enum Foo
   :      ^^^
   `----

In general it blends better with Node.js error style.
There is still an improvement to make that involves removing the whitespace around:

        
     enum Foo
          ^^^
        

This depends from SWC and its currently being fixed.

@nodejs-github-bot nodejs-github-bot added dependencies Pull requests that update a dependency file. strip-types Issues or PRs related to strip-types support labels Mar 23, 2025
@nodejs-github-bot
Copy link
Collaborator Author

nodejs-github-bot commented Mar 23, 2025

Review requested:

  • @nodejs/security-wg
  • @nodejs/typescript
  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 23, 2025
@marco-ippolito marco-ippolito marked this pull request as draft March 23, 2025 17:12
@marco-ippolito marco-ippolito added the wip Issues and PRs that are still a work in progress. label Mar 23, 2025
@marco-ippolito marco-ippolito self-assigned this Mar 23, 2025
@marco-ippolito marco-ippolito changed the title deps: update amaro to 0.5.0 module: improve typescript error message format Mar 23, 2025
@marco-ippolito marco-ippolito added the module Issues and PRs related to the module subsystem. label Mar 23, 2025
@marco-ippolito marco-ippolito marked this pull request as ready for review March 23, 2025 18:24
@marco-ippolito marco-ippolito added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 23, 2025
Copy link

codecov bot commented Mar 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.23%. Comparing base (a6d3585) to head (e9ea0c6).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57598      +/-   ##
==========================================
- Coverage   90.23%   90.23%   -0.01%     
==========================================
  Files         630      630              
  Lines      185129   185147      +18     
  Branches    36234    36230       -4     
==========================================
+ Hits       167049   167065      +16     
- Misses      11037    11040       +3     
+ Partials     7043     7042       -1     
Files with missing lines Coverage Δ
lib/internal/modules/typescript.js 97.51% <100.00%> (+0.17%) ⬆️
lib/internal/process/execution.js 94.81% <100.00%> (+0.02%) ⬆️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. dependencies Pull requests that update a dependency file. lib / src Issues and PRs related to general changes in the lib or src directory. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR. strip-types Issues or PRs related to strip-types support wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide more information when there is a SyntaxError
5 participants