Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getTemplateAst(template: TemplateSource, contextFile: string): AstResult {
let result: AstResult;
try {
const resolvedMetadata =
this.metadataResolver.getNonNormalizedDirectiveMetadata(template.type as any);
const metadata = resolvedMetadata && resolvedMetadata.metadata;
if (metadata) {
const rawHtmlParser = new HtmlParser();
const htmlParser = new I18NHtmlParser(rawHtmlParser);
const expressionParser = new Parser(new Lexer());
const config = new CompilerConfig();
const parser = new TemplateParser(
config, expressionParser, new DomElementSchemaRegistry(), htmlParser, null, []);
const htmlResult = htmlParser.parse(template.source, '');
const analyzedModules = this.host.getAnalyzedModules();
let errors: Diagnostic[] = undefined;
let ngModule = analyzedModules.ngModuleByPipeOrDirective.get(template.type);
if (!ngModule) {
// Reported by the the declaration diagnostics.
ngModule = findSuitableDefaultModule(analyzedModules);
}
if (ngModule) {
const resolvedDirectives = ngModule.transitiveModule.directives.map(
d => this.host.resolver.getNonNormalizedDirectiveMetadata(d.reference));
const directives =
var locale = cliOptions.locale;
var transContent = '';
if (transFile) {
if (!locale) {
throw new Error("The translation file (" + transFile + ") locale must be provided. Use the --locale option.");
}
transContent = nodeFs.readFileSync(transFile, 'utf8');
}
var urlResolver = compiler.createOfflineCompileUrlResolver();
var usePathMapping = !!options.rootDirs && options.rootDirs.length > 0;
var reflectorHost = usePathMapping ?
new path_mapped_reflector_host_1.PathMappedReflectorHost(program, compilerHost, options, reflectorHostContext) :
new reflector_host_1.ReflectorHost(program, compilerHost, options, reflectorHostContext);
var staticReflector = new static_reflector_1.StaticReflector(reflectorHost);
static_reflection_capabilities_1.StaticAndDynamicReflectionCapabilities.install(staticReflector);
var htmlParser = new compiler.I18NHtmlParser(new private_import_compiler_1.HtmlParser(), transContent, cliOptions.i18nFormat);
var config = new compiler.CompilerConfig({
genDebugInfo: options.debug === true,
defaultEncapsulation: core_1.ViewEncapsulation.Emulated,
logBindingUpdate: false,
useJit: false
});
var normalizer = new private_import_compiler_1.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
var expressionParser = new private_import_compiler_1.Parser(new private_import_compiler_1.Lexer());
var elementSchemaRegistry = new private_import_compiler_1.DomElementSchemaRegistry();
var console = new private_import_core_1.Console();
var tmplParser = new private_import_compiler_1.TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []);
var resolver = new private_import_compiler_1.CompileMetadataResolver(new compiler.NgModuleResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), elementSchemaRegistry, staticReflector);
// TODO(vicb): do not pass cliOptions.i18nFormat here
var offlineCompiler = new compiler.OfflineCompiler(resolver, normalizer, tmplParser, new private_import_compiler_1.StyleCompiler(urlResolver), new private_import_compiler_1.ViewCompiler(config), new private_import_compiler_1.NgModuleCompiler(), new private_import_compiler_1.TypeScriptEmitter(reflectorHost), cliOptions.locale, cliOptions.i18nFormat);
return new CodeGenerator(options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);
};
LanguageServiceImpl.prototype.getTemplateAst = function (template, contextFile) {
var _this = this;
var result = undefined;
try {
var resolvedMetadata = this.metadataResolver.getNonNormalizedDirectiveMetadata(template.type);
var metadata = resolvedMetadata && resolvedMetadata.metadata;
if (metadata) {
var rawHtmlParser = new compiler_1.HtmlParser();
var htmlParser = new compiler_1.I18NHtmlParser(rawHtmlParser);
var expressionParser = new compiler_1.Parser(new compiler_1.Lexer());
var config = new compiler_1.CompilerConfig();
var parser = new compiler_1.TemplateParser(config, this.host.resolver.getReflector(), expressionParser, new compiler_1.DomElementSchemaRegistry(), htmlParser, null, []);
var htmlResult = htmlParser.parse(template.source, '', true);
var analyzedModules = this.host.getAnalyzedModules();
var errors = undefined;
var ngModule = analyzedModules.ngModuleByPipeOrDirective.get(template.type);
if (!ngModule) {
// Reported by the the declaration diagnostics.
ngModule = findSuitableDefaultModule(analyzedModules);
}
if (ngModule) {
var resolvedDirectives = ngModule.transitiveModule.directives.map(function (d) { return _this.host.resolver.getNonNormalizedDirectiveMetadata(d.reference); });
var directives = removeMissing(resolvedDirectives).map(function (d) { return d.metadata.toSummary(); });
var pipes = ngModule.transitiveModule.pipes.map(function (p) { return _this.host.resolver.getOrLoadPipeMetadata(p.reference).toSummary(); });
var schemas = ngModule.schemas;
getTemplateAst(template: TemplateSource): AstResult|undefined {
const {type: classSymbol, fileName} = template;
const data = this.resolver.getNonNormalizedDirectiveMetadata(classSymbol);
if (!data) {
return;
}
const htmlParser = new I18NHtmlParser(new HtmlParser());
const expressionParser = new Parser(new Lexer());
const parser = new TemplateParser(
new CompilerConfig(), this.reflector, expressionParser, new DomElementSchemaRegistry(),
htmlParser,
null !, // console
[] // tranforms
);
const htmlResult = htmlParser.parse(template.source, fileName, {
tokenizeExpansionForms: true,
preserveLineEndings: true, // do not convert CRLF to LF
});
const {directives, pipes, schemas} = this.getModuleMetadataForDirective(classSymbol);
const parseResult = parser.tryParseHtml(htmlResult, data.metadata, directives, pipes, schemas);
if (!parseResult.templateAst) {
return;
}
templatesGenerated = true;
}
else {
visitor.generateTemplates(false);
}
containers += '' + compiler.visitAll(visitor, parsed.rootNodes).join('') + '';
}
else {
console.error(parsed.errors);
}
}
});
if(containers.length) {
let i18nHtmlParser = new compiler.I18NHtmlParser(htmlParser);
let parsed = i18nHtmlParser.parse(content, this.resourcePath, false);
if(1 > parsed.errors.length) {
if(!templatesGenerated) {
visitor.generateTemplates(true);
templatesGenerated = true;
}
else {
visitor.generateTemplates(false);
}
result =
containers +
'' + compiler.visitAll(visitor, parsed.rootNodes).join('') + '' +
visitor.getTemplates(true);
useFactory: function (parser, translations, format, config, console) {
translations = translations || '';
var missingTranslation = translations ? config.missingTranslation : MissingTranslationStrategy.Ignore;
return new I18NHtmlParser(parser, translations, format, missingTranslation, console);
},
deps: [
useFactory: (parser, translations, format, config, console) => {
translations = translations || '';
const /** @type {?} */ missingTranslation = translations ? /** @type {?} */ ((config.missingTranslation)) : MissingTranslationStrategy.Ignore;
return new I18NHtmlParser(parser, translations, format, missingTranslation, console);
},
deps: [
useFactory: function (parser, translations, format, config, console) {
translations = translations || '';
var /** @type {?} */ missingTranslation = translations ? /** @type {?} */ ((config.missingTranslation)) : MissingTranslationStrategy.Ignore;
return new I18NHtmlParser(parser, translations, format, missingTranslation, console);
},
deps: [