forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): query
<template>
elements before their children. (an…
…gular#13677) Fixes angular#13118 Closes angular#13167
- Loading branch information
Showing
7 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
modules/@angular/compiler/src/view_compiler/query_binder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {CompileQueryMetadata, CompileTokenMetadata, tokenReference} from '../compile_metadata'; | ||
import * as o from '../output/output_ast'; | ||
|
||
import {CompileElement} from './compile_element'; | ||
import {CompileQuery} from './compile_query'; | ||
|
||
|
||
// Note: We can't do this when we create the CompileElements already, | ||
// as we create embedded views before the <template> elements themselves. | ||
export function bindQueryValues(ce: CompileElement) { | ||
const queriesWithReads: _QueryWithRead[] = []; | ||
ce.getProviderTokens().forEach((token) => { | ||
const queriesForProvider = ce.getQueriesFor(token); | ||
queriesWithReads.push(...queriesForProvider.map(query => new _QueryWithRead(query, token))); | ||
}); | ||
Object.keys(ce.referenceTokens).forEach(varName => { | ||
const token = ce.referenceTokens[varName]; | ||
const varToken = {value: varName}; | ||
queriesWithReads.push( | ||
...ce.getQueriesFor(varToken).map(query => new _QueryWithRead(query, varToken))); | ||
}); | ||
queriesWithReads.forEach((queryWithRead) => { | ||
let value: o.Expression; | ||
if (queryWithRead.read.identifier) { | ||
// query for an identifier | ||
value = ce.instances.get(tokenReference(queryWithRead.read)); | ||
} else { | ||
// query for a reference | ||
const token = ce.referenceTokens[queryWithRead.read.value]; | ||
if (token) { | ||
value = ce.instances.get(tokenReference(token)); | ||
} else { | ||
value = ce.elementRef; | ||
} | ||
} | ||
if (value) { | ||
queryWithRead.query.addValue(value, ce.view); | ||
} | ||
}); | ||
} | ||
|
||
class _QueryWithRead { | ||
public read: CompileTokenMetadata; | ||
constructor(public query: CompileQuery, match: CompileTokenMetadata) { | ||
this.read = query.meta.read || match; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters