angular icon indicating copy to clipboard operation
angular copied to clipboard

[Solved] Very strange compilation errors... due to a single comma added to or removed from the end of a metedata declaration.

Open denis-beurive opened this issue 7 years ago • 4 comments

  • [ ] Dart SDK Version: Dart VM version: 2.1.0 (Unknown timestamp) on "linux_x64"
  • [ ] AngularDart Version: 5.0.0
  • [ ] Whether you are using Windows, macOS, or Linux: Linux
  • [ ] Whether you are using Chrome, Safari, Firefox, Edge (if applicable): this is not important.

EDIT:

I think this bug has already been reported : Sometimes webdev serve auto-rebuild broke the build files > #79

I found a very strange bug. This bug is not systematic. However, it occurred to me regularly.

The description is given on this page (on the section "Important note: please read"). However, I give you the description here:

Let's say that you instantiate a "metadata" (to implement a component or a directive, for example). You write something like:

@Component(
    selector: 'app-component',
    templateUrl: 'app_component.html',
    directives: [MyListerDirective]
)
class AppComponent {

}

Everything compiles... you are happy.

You change something in your code, in another file... And, suddenly, you get tons of errors ! Your first reaction is to look at your last changes. But everything seems OK. You restart the CLI command webdev serve... maybe there is something that needs to be reinitialised somewhere. Nothing changes. You still have tons of errors !

Then, your intuition tells you to add a comma in the declaration :

@Component(
    selector: 'app-component',
    templateUrl: 'app_component.html',
    directives: [MyListerDirective],
)
class AppComponent {

}

Do you see the difference ?

How does your intuition find out ? You have no idea. But the code compiles all right !

Everything compiles now !

And that's not the end of the story. Now you remove the comma you've just added.

@Component(
    selector: 'app-component',
    templateUrl: 'app_component.html',
    directives: [MyListerDirective]
)
class AppComponent {

}

And guess what : it compiles all right !

Please note that this is not the first time that the bug shows up. It showed up while I was working on the other examples that you can find here. I found the workaround because I first worked on very short code (I am learning). And I just tried to change things around to see what was happening.

Note : it seems that this bug appears after a compilation error (that has nothing to do with the added or removed comma). Thus my guess is that there is a "cache" somewhere that does not clear automatically. And the fact or adding or removing the comma just clears the cache directive-structural.zip .

denis-beurive avatar Dec 26 '18 16:12 denis-beurive

The problem pops up again. But, this time, the symptom is different.

Here what I did :

In the template file "lib/app_component.html" I added a line that was syntactically invalid :

<div *myLister="let list From ['a', 'b', 'c']; oddColor 'red'"></div>

Let's say that the code is in state "S1".

With this line webdev serve reports errors. OK, that's normal.

Thus I comment out the line :

<!--
<div *myLister="let list From ['a', 'b', 'c']; oddColor 'red'"></div>
-->

Let's say that the code is in state "S2".

Now webdev serve reports tons of errors. That is NOT normal (since the line is commented).

I try to restart the command ẁebdev serve: it does not work. I still have tons of errors.

Then, I remove the comment I've just added before from the template file.

Let's say that the code is in state "S3".

And... it works ! I have no error. That should be normal.

All rigth... so I do another experiment :

I put back the line that caused the error. Thus, the code goes back to state "S1".

<div *myLister="let list From ['a', 'b', 'c']; oddColor 'red'"></div>

webdev serve reports errors. OK. It is consistent.

Then I comment the line again. Thus, the code goes back to state "S2".

<!--
<div *myLister="let list From ['a', 'b', 'c']; oddColor 'red'"></div>
-->

As the result of this last action, I get tons of errors again. OK. It is consistent.

Then I did the manipulation with the comma in the file lib/app_component.dart.

I replace:

@Component(
    selector: 'app-component',
    templateUrl: 'app_component.html',
    directives: [MyListerDirective],
)

By (I removed the last comma):

@Component(
    selector: 'app-component',
    templateUrl: 'app_component.html',
    directives: [MyListerDirective]
)

Let's say that the code is in state "S4".

The tons of errors still show up. OK. It is consistent (since the comma should have no impact).

Then I restart the command ẁebdev serve.

The tons of errors still show up.

Thus I remove the invalid line from the template. But I leave the comment tags:

<!--
-->

Let's say that the code is in state "S5".

Result : the errors are gone. This is weird.

Then I put back the commented line:

<!--
<div *myLister="let list From ['a', 'b', 'c']; oddColor 'red'"></div>
-->

Let's say that the code is in state "S6".

Result : no errors ! This is weird

Do you see the inconsistency ? State "S6" is identical to state "S2" (same code - except for the comma, but it should not matter). State "S2" triggers tons of errors... however state "S6" does not trigger any error !

I tried to put back the last comma (just to make sure...):

@Component(
     selector: 'app-component',
     templateUrl: 'app_component.html',
     directives: [MyListerDirective],
)

Let's say that the code is in state "S7".

Result : no error.

State "S7" is strictly identical to state "S2". A "diff" of the source files shows no difference at all. However :

  • State "S2" triggers tons of errors.
  • State "S7" (with "S2" === "S7") triggers no error.

I give you "ALL" the files.

directive-structural.tar.gz

denis-beurive avatar Dec 27 '18 08:12 denis-beurive

Just to let you know. The problem shows up again on yet another scenario.

I modify something in the template file that produces (through "webdev serve") tons of errors. I remove the previous modifications (that I made in the template file), but this action does not eliminate the errors. I restart "webdev serve", but this action does not eliminate the errors either.

I remove or add the last comma of the @component instantiation. This action finally eliminates the error.

Conclusion : there is something that does not work with a cache somewhere, I think. A cache is not cleared as it should be.

This problem is really bad because when an error occurred, you don't really know what's wrong. Your code may be OK (since you remove the last modification you did that caused the error), however, you've got tons of errors. Thus - because you know that something behaves in a weird fashion - you "modify things around" in order to "reinitiate" something along the compilation process.

Note that I get alerted when I suddenly see tons of "unintelligible" errors coming from "webdev serve". This is a symptom that lets me know that I should modify something within the Dart code although the error came from the HTML template.

denis-beurive avatar Dec 27 '18 09:12 denis-beurive

OK... I've seen this bug report.

I've checked the version of build_runner_core as requested.

$ pub deps | grep build_runner
|-- build_runner 0.9.2
|   |-- build_runner_core 0.2.2+2

It is older than 0.3.1.

pub upgrade does not upgrade it.

Thus I upgraded build_runner through "pubspec.yaml".

dev_dependencies:
  angular_test: ^2.0.0-beta+2
  build_runner: ^1.1.2
  build_test: ^0.10.3+1
  build_web_compilers: ^0.4.1
  pageloader: ^3.0.0-beta
  test: ^1.3.0

Then:

$ pub upgrade
$ pub deps | grep build_runner
|-- build_runner 1.1.2
|   |-- build_runner_core 1.1.2

That should be OK then. I'll test right now.

denis-beurive avatar Dec 27 '18 10:12 denis-beurive

OK, updating build_runner solved the problem.

denis-beurive avatar Dec 27 '18 11:12 denis-beurive