Skip to content

Commit

Permalink
fix: compatible with Angular 4.1.3
Browse files Browse the repository at this point in the history
Fix #319
  • Loading branch information
mgechev committed Jun 9, 2017
1 parent 572b0b7 commit b608296
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/angular/templates/recursiveAngularExpressionVisitor.ts
Expand Up @@ -22,6 +22,11 @@ export class RecursiveAngularExpressionVisitor extends SourceMappingVisitor impl
return null;
}

visitNonNullAssert(ast: e.NonNullAssert, context: any) {
ast.visit(this);
return null;
}

visitBinary(ast: e.Binary, context: any): any {
ast.left.visit(this);
ast.right.visit(this);
Expand Down
33 changes: 32 additions & 1 deletion src/angular/templates/templateParser.ts
Expand Up @@ -66,9 +66,13 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
tmplParser =
new TemplateParser(config, expressionParser, elementSchemaRegistry, htmlParser, ngConsole, []);
})
.else(() => {
.elseIf.lt('4.1.0', () => {
tmplParser =
new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, ngConsole, []);
}).else(() => {
const config = new compiler.CompilerConfig({});
tmplParser =
new TemplateParser(config, new compiler.JitReflector(), expressionParser, elementSchemaRegistry, htmlParser, ngConsole, []);
});

const interpolation = Config.interpolation;
Expand Down Expand Up @@ -112,13 +116,37 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
identifier: null
};
let result = null;
try {
SemVerDSL.lt('4.1.0', () => {
result = tmplParser.tryParse(
(compiler.CompileDirectiveMetadata as any).create({
type,
template: templateMetadata
}),
template, defaultDirectives, [], [NO_ERRORS_SCHEMA], '').templateAst;
}).elseIf.lt('4.1.3', () => {
result = tmplParser.tryParse(
compiler.CompileDirectiveMetadata.create({
type,
template: templateMetadata,
isHost: true,
isComponent: true,
selector: '',
exportAs: '',
changeDetection: ChangeDetectionStrategy.Default,
inputs: [],
outputs: [],
host: {},
providers: [],
viewProviders: [],
queries: [],
viewQueries: [],
entryComponents: [],
componentViewType: null,
rendererType: null,
componentFactory: null
}),
template, defaultDirectives, [], [NO_ERRORS_SCHEMA], '').templateAst;
}).else(() => {
result = tmplParser.tryParse(
compiler.CompileDirectiveMetadata.create({
Expand All @@ -143,5 +171,8 @@ export const parseTemplate = (template: string, directives: DirectiveDeclaration
}),
template, defaultDirectives, [], [NO_ERRORS_SCHEMA], '').templateAst;
});
} catch (e) {
console.log(e);
}
return result;
};

0 comments on commit b608296

Please sign in to comment.