Skip to content

Commit ea59527

Browse files
committed
fix: Support banana in a box.
The output was invalid javascript. Ex: `ɵɵtwoWayBindingSet(ctx.test, $event) || (ctx.test = $event);` The parenthesis were missing on the right hand side of the boolean operator.
1 parent 429b17e commit ea59527

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

angular.json

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
"outputPath": "dist/angular-compiler-output",
1717
"index": "src/index.html",
1818
"browser": "src/main.ts",
19-
"polyfills": [
20-
"zone.js"
21-
],
2219
"tsConfig": "tsconfig.app.json",
2320
"assets": [
2421
{

src/app/app.component.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Component,
44
effect,
55
ElementRef,
6-
Host,
76
HostListener,
87
inject,
98
signal,
@@ -12,7 +11,7 @@ import {
1211
} from '@angular/core';
1312
import { FormsModule } from '@angular/forms';
1413
import { ActivatedRoute, Router } from '@angular/router';
15-
import { MatIcon, MatIconRegistry } from '@angular/material/icon';
14+
import { MatIcon } from '@angular/material/icon';
1615

1716
import { compileFormatAndHighlight } from './compile';
1817
import { formatAngularTemplate } from './prettier';
@@ -110,7 +109,12 @@ import { unzip, zip } from './zip';
110109
<ul>
111110
<li>&#64;Defer is not supported yet</li>
112111
<li>i18n is not supported yet</li>
113-
<li><a href="https://github.com/JeanMeche/angular-compiler-output/issues">Probably some other issues</a>...</li>
112+
<li>
113+
<a
114+
href="https://github.com/JeanMeche/angular-compiler-output/issues"
115+
>Probably some other issues</a
116+
>...
117+
</li>
114118
</ul>
115119
<h2>More on the Angular compiler</h2>
116120
<p>
@@ -121,7 +125,12 @@ import { unzip, zip } from './zip';
121125
</div>
122126
123127
<br /><br /><br />
124-
<p>Repo <a href="https://github.com/jeanmeche/angular-compiler-output">here</a></p>
128+
<p>
129+
Repo
130+
<a href="https://github.com/jeanmeche/angular-compiler-output"
131+
>here</a
132+
>
133+
</p>
125134
<span class="twitter">
126135
Built by
127136
<a href="https://twitter.com/Jean__meche">&#64;JeanMeche</a> with the
@@ -144,8 +153,7 @@ export class AppComponent {
144153
read: ElementRef,
145154
});
146155

147-
constructor(private matIconReg: MatIconRegistry) {
148-
this.matIconReg.setDefaultFontSetClass('material-symbols-outlined');
156+
constructor() {
149157
effect(() => {
150158
this.compileTemplate(this.template());
151159
});

src/app/app.config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import {
22
APP_INITIALIZER,
33
ApplicationConfig,
4+
ENVIRONMENT_INITIALIZER,
5+
inject,
46
provideExperimentalZonelessChangeDetection,
57
} from '@angular/core';
68
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
79
import { provideRouter } from '@angular/router';
810
import { initHightlighter } from './compile';
11+
import { MatIconRegistry } from '@angular/material/icon';
912

1013
export const appConfig: ApplicationConfig = {
1114
providers: [
@@ -17,5 +20,14 @@ export const appConfig: ApplicationConfig = {
1720
useValue: async () => await initHightlighter(),
1821
multi: true,
1922
},
23+
{
24+
provide: ENVIRONMENT_INITIALIZER,
25+
useFactory: () => () => {
26+
const matIconReg = inject(MatIconRegistry);
27+
matIconReg.setDefaultFontSetClass('material-symbols-outlined');
28+
},
29+
multi: true,
30+
deps: [MatIconRegistry],
31+
},
2032
],
2133
};

src/app/printer.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class Printer implements ng.ExpressionVisitor, ng.StatementVisitor {
8686
}
8787

8888
visitIfStmt(stmt: ng.IfStmt, context: Context): string {
89-
console.log(stmt);
9089
let ifStmt = 'if (';
9190
ifStmt += stmt.condition.visitExpression(this, context);
9291
ifStmt +=
@@ -390,7 +389,9 @@ export class Printer implements ng.ExpressionVisitor, ng.StatementVisitor {
390389
return (
391390
ast.lhs.visitExpression(this, context) +
392391
BINARY_OPERATORS.get(ast.operator)! +
393-
ast.rhs.visitExpression(this, context)
392+
'(' +
393+
ast.rhs.visitExpression(this, context) +
394+
')'
394395
);
395396
}
396397

src/app/templates/banana.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const bananaBoxTemplate = `<app [(myVar)]="myProp"/>`

src/app/templates/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { asyncPipeTemplate } from "./async-pipe";
2+
import { bananaBoxTemplate } from "./banana";
23
import { childComponentTemplate } from "./child-component";
34
import { defaultTemplate } from "./default";
45
import { eventBindingsTemplate } from "./event-bindings";
@@ -18,8 +19,9 @@ export const templates: Template[] = [
1819
{ label: '@for vs ngFor', content: forLoopsTemplate },
1920
{ label: 'ngIf/else w/ template reference', content: ifElseReferenceTemplate },
2021
{ label: 'event bindings', content: eventBindingsTemplate },
21-
// { label: 'ng-model', content: NgModelTemplate }, // @see: https://github.com/JeanMeche/angular-compiler-output/issues/2
22+
{ label: 'ng-model', content: NgModelTemplate },
2223
{ label: 'async pipe', content: asyncPipeTemplate },
2324
{ label: 'child component', content: childComponentTemplate },
24-
{ label: 'simple @let', content: simpleAtLet}
25+
{ label: 'simple @let', content: simpleAtLet},
26+
{ label: 'double binding (banna in a box)', content: bananaBoxTemplate },
2527
];

0 commit comments

Comments
 (0)