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

Bundle todo #23168

Closed
wants to merge 9 commits into from
Closed

Bundle todo #23168

wants to merge 9 commits into from

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Apr 4, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[ ] No

Other information

@@ -71,10 +71,14 @@ export function compileDirective(

// e.g. `attributes: ['role', 'listbox']`
field('attributes', createHostAttributesArray(directive, outputCtx));
console.error('=======', directive);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

/* These tests are codified version of the tests in compiler_canonical_spec.ts. Every
* test in compiler_canonical_spec.ts should have a corresponding test here.
*/
fdescribe('compiler compliance: listen()', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fdescribe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

## Compiler
- [ ] Remove ` tslib_1.__decorate([core_1.Input(), tslib_1.__metadata("design:type", Object)], TodoComponent.prototype, "todo", void 0);` from generated output.

- [ ] Allow compilation of `@angular/common` through ivy.

## Ivy Runtime
- [ ] Work on `ViewContainerRef` needs to cause change detection so that `todo` app renders correctly on first render.
- [ ] The todo input value box is not correctly rendering to checked for completed tasks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed by #23161, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@mhevery mhevery changed the title WIP: Bundle todo Bundle todo Apr 4, 2018
@mhevery mhevery added the target: major This PR is targeted for the next major release label Apr 4, 2018
@buildsize
Copy link

buildsize bot commented Apr 4, 2018

File name Previous Size New Size Change
bundle.min.js 52.9 KB 39.88 KB -13.02 KB (25%)
bundle.min.js.brotli 14.18 KB 11.26 KB -2.92 KB (21%)

@@ -1765,7 +1765,7 @@ export function wrapListenerWithDirtyLogic(view: LView, listenerFn: (e?: any) =>
*/
export function wrapListenerWithDirtyAndDefault(
view: LView, listenerFn: (e?: any) => any): EventListener {
return function(e: Event) {
return function wrapListenerIn_markViewDirty(e: Event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow CS wrapListenerInMarkViewDirty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this as is unless you feel strongly. Rest of the generated code follows this convention such as ToDoAppComponent_NgIf_NgForOf_NgIf_Template_6

return null;
}

function createOutputsObject(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factorize createInputsObject / createOutputsObject ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored

})
export class MyComponent {
@Input() name;
@Input('renamed') original;
Copy link
Contributor

@vicb vicb Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Input() input;
@Input('renamedInput') originalInput; 

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned up

selector: '[my-directive]',
})
export class MyDirective {
@Input() dirName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as for the cmp: consistency for I vs O names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import {compile, expectEmit} from './mock_compile';

/* These tests are codified version of the tests in compiler_canonical_spec.ts. Every
* test in compiler_canonical_spec.ts should have a corresponding test here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it the case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed comment

@vicb
Copy link
Contributor

vicb commented Apr 4, 2018

Commit message typo -> "statmentes" (es) -> "statements" (en)

const template = `
template:function MyComponent_Template(ctx:any,cm:boolean){
if (cm) {
i0.ɵC(0,MyComponent_NgForOf_Template_0,null,_c0);
Copy link
Contributor

@vicb vicb Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyComponent_NgForOf_Template_0, _c0, i0, ... should not be hardcoded
use IDENT or $matchingName$ instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import {MockDirectory, setup} from '../aot/test_util';
import {compile, expectEmit} from './mock_compile';

/* These tests are codified version of the tests in compiler_canonical_spec.ts. Every
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments in each commits

if (cm) {
i0.ɵE(0,'div');
i0.ɵL('click',function MyComponent_NgForOf_NgForOf_NgForOf_Template_1_div_click_listener($event:any){
const pd_b:any = ((<any>ctx.onClick($_r0$,$_r1$,$_r2$)) !== false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generated code doesn't match our canonical spec for listeners here. Is there a reason for that or is this just work that hasn't been done yet in the compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should convert the canonical specs to this format. Out of scope for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the generated code to match spec. It is a bit of a hack so please let take a look if you are OK with it.

@ngbot
Copy link

ngbot bot commented Apr 5, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mary-poppins
Copy link

You can preview 4560326 at https://pr23168-4560326.ngbuilds.io/.
You can preview 182c47f at https://pr23168-182c47f.ngbuilds.io/.
You can preview d64fa70 at https://pr23168-d64fa70.ngbuilds.io/.
You can preview 8ab9ba1 at https://pr23168-8ab9ba1.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 4579242 at https://pr23168-4579242.ngbuilds.io/.

function noop() {}

/**
* Function which is executed whenever a variable is refferenced for the first time in a given
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* - value `lhs` is the left hand side which is an AST representing `abc` which
* can be used in other places of the source code.
* - value `rhs` is the right hand side which is an AST representing `a.b.c` which
* can be used in other places of the source code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure to understand "which can be used in other places of the source code." ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a left over from previous behavior. I have removed it and I think it makes it clearer.


// The template should look like this (where IDENT is a wild card for an identifier):
const template = `
static ngComponentDef = i0.ɵdefineComponent({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i0 should not be hardcoded

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to IDENT

}
};

// The template should look like this (where IDENT is a wild card for an identifier):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no IDENT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now there is

@@ -0,0 +1,86 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a conformance test ? should it be moved to that folder ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think it is conformance. I think of it as unit test for the r3_view_compiler.ts but that test file is huge so i suffixed it by type intpu_outputs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think it is conformance

Because the only assertion you have here is about the compiler output.
Probably we should have a clear definition of the types of test and what they should do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed in person

@@ -193,7 +196,10 @@ export function compileComponent(
}

// e.g `inputs: {a: 'a'}`
field('inputs', createInputsObject(component, outputCtx));
field('inputs', createMapObjectLiteral(component.inputs, outputCtx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other fields are defined only when they should (ie features, directives, pipes, ...).
Should we do the same for inputs and outputs ?
It would be better for code size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed in person, it is OK.

set title(value: string) { this._title = value.trim(); }

constructor(title: string, completed: boolean = false) {
this.completed = completed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public completed = false in the args ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixe

constructor(title: string, completed: boolean = false) {
this.completed = completed;
this.editing = false;
this.title = title.trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to trim here (done in the setter)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Given
```
<div *ngFor=”…” (click)=“doSomething()”>
```

Before `doSomething` would execute on the inner template context, which
is incorrect. The correct behavior is to execute on the top level context
of the component.
When compiling templates the compiler would often bind to
closest context rather than the component context.

The only time one should be binding to the cont component is
in explicit cases where the inner template declares local variable.
@mary-poppins
Copy link

You can preview 2311600 at https://pr23168-2311600.ngbuilds.io/.

@mary-poppins
Copy link

You can preview f2e55de at https://pr23168-f2e55de.ngbuilds.io/.

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Apr 10, 2018
@IgorMinar IgorMinar closed this in 720031b Apr 10, 2018
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
Given
```
<div *ngFor=”…” (click)=“doSomething()”>
```

Before `doSomething` would execute on the inner template context, which
is incorrect. The correct behavior is to execute on the top level context
of the component.

PR Close #23168
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
When compiling templates the compiler would often bind to
closest context rather than the component context.

The only time one should be binding to the cont component is
in explicit cases where the inner template declares local variable.

PR Close #23168
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
IgorMinar pushed a commit that referenced this pull request Apr 10, 2018
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants