-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(parseTemplate): migrate to the new private API
1. Migrate to the newest private API. 2. Externalize the interpolation config.
- Loading branch information
Showing
4 changed files
with
28 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const INTERPOLATION: [string, string] = ['{{', '}}']; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
import { __core_private__ as r, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { INTERPOLATION } from './config'; | ||
import * as compiler from '@angular/compiler'; | ||
|
||
export const parseTemplate = (template: string) => { | ||
const _ = compiler.__compiler_private__; | ||
|
||
const TemplateParser = _.TemplateParser; | ||
const DomElementSchemaRegistry = _.DomElementSchemaRegistry; | ||
const expressionParser = new _.Parser(new _.Lexer()); | ||
const elementSchemaRegistry = new DomElementSchemaRegistry(); | ||
const elementSchemaRegistry = new _.DomElementSchemaRegistry(); | ||
const ngConsole = new r.Console(); | ||
const htmlParser = | ||
new compiler.I18NHtmlParser(new _.HtmlParser(), '', ''); | ||
new compiler.I18NHtmlParser(new _.HtmlParser()); | ||
const tmplParser = | ||
new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, ngConsole, []); | ||
const interpolation = INTERPOLATION; | ||
const templateMetadata = { | ||
encapsulation: 0, | ||
template: template, | ||
templateUrl: '', | ||
styles: [], | ||
styleUrls: [], | ||
ngContentSelectors: [], | ||
animations: [], | ||
externalStylesheets: [], | ||
interpolation | ||
}; | ||
const type = new compiler.CompileTypeMetadata({ diDeps: [] }); | ||
return tmplParser.tryParse( | ||
compiler.CompileDirectiveMetadata.create({ type }), | ||
template, [], [], [NO_ERRORS_SCHEMA], null).templateAst; | ||
compiler.CompileDirectiveMetadata.create({ type, template: templateMetadata }), | ||
template, [], [], [NO_ERRORS_SCHEMA], '').templateAst; | ||
}; |