question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not reset the template parser's error when using JIT compiler

See original GitHub issue

🐞 bug report

Affected Package

@angular/compiler

Is this a regression?

No sure, But got the same problem on v9-rc.4 and v8.2

Description

Background

I am using Angular to rewrite the front end of apache/zeppelin, it allows users to enter dynamic templates and run, so I trying to implement this feature using the JIT compiler but blocked by this problem.

Steps to reproduce

Open the live DEMO https://ng-jit-template-parse-errors.now.sh/ and browser’s console.

Enter the following code in the textarea.

<button (click)="i = i++">Click {{i}}</button>

Click the render button and we will see the following errors in the console, this is good because this error is expected.

vendor-es2015.js:40954 ERROR Error: Template parse errors:
Parser Error: Unexpected end of expression: i = i++ at the end of the expression [i = i++] in ng:////template.html@0:17 ("<button (click)="[ERROR ->]i = i++">Click {{i}}</button>"): ng:////template.html@0:17

Then enter the correct template into the textarea and click the render button again.

<button (click)="i = i + 1">Click {{i}}</button>

Expect no error, but still got the same error.

vendor-es2015.js:40954 ERROR Error: Template parse errors:
Parser Error: Unexpected end of expression: i = i++ at the end of the expression [i = i++] in ng:////template.html@0:17 ("<button (click)="[ERROR ->]i = i++">Click {{i}}</button>"): ng:////template.html@0:17

I guess the error was cached, so I called the method compiler.clearCache(), but it still didn’t work.

I tried using the Ι΅renderComponent method to render the dynamic component, the error is disappeared, but I can not use other modules (like FormsModule) feature in this component.

πŸ”¬ Minimal Reproduction

Stackblitz: https://stackblitz.com/github/hsuanxyz/ng-jit-template-parse-errors

Repo: https://github.com/hsuanxyz/ng-jit-template-parse-errors/

πŸ”₯ Exception or Error

vendor-es2015.js:40954 ERROR Error: Template parse errors:
Parser Error: Unexpected end of expression: i = i++ at the end of the expression [i = i++] in ng:////template.html@2:17 ("<input [(ngModel)]="name"> <span>{{name}}</span>
<br>
<button (click)="[ERROR ->]i = i++">Click {{i}}</button>"): ng:////template.html@2:17
Parser Error: Unexpected end of expression: i = i++ at the end of the expression [i = i++] in ng:////template.html@2:17 ("<input [(ngModel)]="name"> <span>{{name}}</span>
<br>
<button (click)="i = i++">[ERROR ->]Click {{i}}</button>"): ng:////template.html@2:26
    at syntaxError (vendor-es2015.js:10006)
    at htmlAstToRender3Ast (vendor-es2015.js:22123)
    at parseTemplate (vendor-es2015.js:24817)
    at CompilerFacadeImpl.compileComponent (vendor-es2015.js:25661)
    at Function.get (vendor-es2015.js:70705)
    at getComponentDef (vendor-es2015.js:37333)
    at assertComponentType (vendor-es2015.js:37743)
    at ComponentFactoryResolver$1.resolveComponentFactory (vendor-es2015.js:65766)
    at AppComponent.renderDynamicComponent (main-es2015.js:66)
    at AppComponent_Template_button_click_2_listener (main-es2015.js:83)

🌍 Your Environment

Angular Version:

Angular CLI: 9.0.0-rc.6
Node: 12.11.1
OS: darwin x64

Angular: 9.0.0-rc.6
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.6
@angular-devkit/build-angular     0.900.0-rc.6
@angular-devkit/build-optimizer   0.900.0-rc.6
@angular-devkit/build-webpack     0.900.0-rc.6
@angular-devkit/core              9.0.0-rc.6
@angular-devkit/schematics        9.0.0-rc.6
@ngtools/webpack                  9.0.0-rc.6
@schematics/angular               9.0.0-rc.6
@schematics/update                0.900.0-rc.6
rxjs                              6.5.3
typescript                        3.6.4
webpack                           4.41.2

Anything else relevant?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
hsuanxyzcommented, Dec 13, 2019

@EKashpersky Yeah, I know, but when I enter the correct expression, it still throws the previous error.

0reactions
alxhubcommented, May 27, 2020

Yeah, this is super subtle. As mentioned, the JIT compiler is not a template validator, and behavior after an error is encountered in a template is undefined.

I suggest you rely on private API a little, and import parseTemplate from @angular/compiler directly. Validate templates via that method before attempting to compile them via JIT.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Errors during JIT compilation - Stack Overflow
Error : Errors during JIT compilation of template for CategoryItemComponent: Parser Error: Unexpected token {, expected identifier, keyword,Β ...
Read more >
Identifying JIT compilation failures - IBM
For JIT compiler failures, analyze the z/TPF system dump to determine whether a failure occurs when the JIT compiler attempts to compile a...
Read more >
Automatically Extracting Templates for Testing Java JIT ...
create templates to be used with JITAttack's JIT compiler testing. JITTEMPLATER parses the Abstract Syntax Tree of the given Java file to convert...
Read more >
Just-in-time compilation - Wikipedia
Roughly, JIT compilation combines the speed of compiled code with the flexibility of interpretation, with the overhead of an interpreter and the additionalΒ ......
Read more >
Managed Profile-Guided Optimization Using Background JIT
Some performance optimizations performed by a compiler are always good. That is, no matter which code actually gets executed at run time, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found