angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.73k stars 11.98k forks source link

Angular 17 compiler errors have zero-based column, but one-based column would be more expected #26783

Closed segrey closed 8 months ago

segrey commented 8 months ago

Command

build

Is this a regression?

The previous version in which this bug was not present was

16

Description

Since Angular 17, compilation errors have zero-based column while having one-based line. It would be more natural to have both line and column one-based.

Minimal Reproduction

  1. Generate an example Angular 17 app
  2. Make an intentional compilation error, e.g. change src/app/app.component.html to
    <span>{{ title.foo }} app is running!</span>
  3. Run ng serve. The error with zero-based column (15) will appear:

    ✘ [ERROR] NG9: Property 'foo' does not exist on type 'string'. [plugin angular-compiler]
    
    src/app/app.component.html:1:15:
      1 │ <span>{{ title.foo }} app is running!</span>
        ╵                ~~~

Previously, in Angular 16, columns in errors were one-based:

Error: src/app/app.component.html:1:16 - error TS2339: Property 'foo' does not exist on type 'string'.

1 <span>{{ title.foo }} app is running!</span>
                 ~~~

Exception or Error

No response

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 17.0.8
Node: 18.19.0
Package Manager: npm 10.2.3
OS: darwin arm64

Angular: 17.0.8
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.8
@angular-devkit/build-angular   17.0.8
@angular-devkit/core            17.0.8
@angular-devkit/schematics      17.0.8
@schematics/angular             17.0.8
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else relevant?

No response

segrey commented 8 months ago

Seems like the problem is that the column received from typescript is not incremented, while the line is incremented:

https://github.com/angular/angular-cli/blob/5bf0a0797c368f343674861c4fbec711afcaf130/packages/angular_devkit/build_angular/src/tools/esbuild/angular/diagnostics.ts#L43

alan-agius4 commented 8 months ago

This is working as expected.

Esbuild expects columns to be zero based while line numbers are 1 based.

See: https://github.com/evanw/esbuild/blob/35c0d65b9d4f29a26176404d2890d1b499634e9f/pkg/api/api.go#L192-L193

Unless this is changed in esbuild, changing the column to a one-base would cause would cause error messages to be formatted incorrectly.

angular-automatic-lock-bot[bot] commented 7 months ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.