Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then( (translations: string ) => [
{ provide: TRANSLATIONS, useValue: translations },
{ provide: TRANSLATIONS_FORMAT, useValue: 'xlf' },
{ provide: LOCALE_ID, useValue: locale },
// #enddocregion without-missing-translation
{ provide: CompilerConfig, useValue: new CompilerConfig({ missingTranslation: MissingTranslationStrategy.Error }) }
// #docregion without-missing-translation
])
.catch(() => noProviders); // ignore if file not found
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;
var parseResult = parser.tryParseHtml(htmlResult, metadata, directives, pipes, schemas);
result = {
Extractor.create = function (options, translationsFormat, program, compilerHost, htmlParser, reflectorHostContext) {
var resourceLoader = {
get: function (s) {
if (!compilerHost.fileExists(s)) {
// TODO: We should really have a test for error cases like this!
throw new Error("Compilation failed. Resource file not found: " + s);
}
return Promise.resolve(compilerHost.readFile(s));
}
};
var urlResolver = compiler.createOfflineCompileUrlResolver();
var reflectorHost = 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 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);
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), null, null);
// TODO(vicb): implicit tags & attributes
var messageBundle = new compiler.MessageBundle(htmlParser, [], {});
return new Extractor(program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer, offlineCompiler);
};
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 =
resolvedDirectives.filter(d => d !== null).map(d => d.metadata.toSummary());
const pipes = ngModule.transitiveModule.pipes.map(
I18NHtmlParser, ɵConsole]
},
{ provide: DirectiveNormalizer, deps: [ResourceLoader, UrlResolver, HtmlParser, CompilerConfig] },
{ provide: CompileMetadataResolver, deps: [CompilerConfig, HtmlParser, NgModuleResolver,
DirectiveResolver, PipeResolver,
SummaryResolver,
ElementSchemaRegistry,
DirectiveNormalizer, ɵConsole,
[Optional, StaticSymbolCache],
CompileReflector,
[Optional, ERROR_COLLECTOR_TOKEN]] },
DEFAULT_PACKAGE_URL_PROVIDER,
{ provide: StyleCompiler, deps: [UrlResolver] },
{ provide: ViewCompiler, deps: [CompileReflector] },
{ provide: NgModuleCompiler, deps: [CompileReflector] },
{ provide: CompilerConfig, useValue: new CompilerConfig() },
{ provide: Compiler, useClass: CompilerImpl, deps: [Injector, CompileMetadataResolver,
TemplateParser, StyleCompiler,
ViewCompiler, NgModuleCompiler,
SummaryResolver, CompileReflector, CompilerConfig,
ɵConsole] },
{ provide: DomElementSchemaRegistry, deps: [] },
{ provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry },
{ provide: UrlResolver, deps: [PACKAGE_ROOT_URL] },
{ provide: DirectiveResolver, deps: [CompileReflector] },
{ provide: PipeResolver, deps: [CompileReflector] },
{ provide: NgModuleResolver, deps: [CompileReflector] },
]));
/**
* \@publicApi
*/
class JitCompilerFactory {
}
transContent = readFileSync(transFile, 'utf8');
}
const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver();
if (!reflectorHost) {
const usePathMapping = !!options.rootDirs && options.rootDirs.length > 0;
reflectorHost = usePathMapping ?
new PathMappedReflectorHost(program, compilerHost, options, reflectorHostContext) :
new ReflectorHost(program, compilerHost, options, reflectorHostContext);
}
const staticReflector = new StaticReflector(reflectorHost);
StaticAndDynamicReflectionCapabilities.install(staticReflector);
const htmlParser =
new compiler.I18NHtmlParser(new compiler.HtmlParser(), transContent, cliOptions.i18nFormat);
const config = new compiler.CompilerConfig({
genDebugInfo: options.debug === true,
defaultEncapsulation: ViewEncapsulation.Emulated,
logBindingUpdate: false,
useJit: false
});
const normalizer =
new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
const expressionParser = new compiler.Parser(new compiler.Lexer());
const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
const console = new Console();
const tmplParser = new compiler.TemplateParser(
expressionParser, elementSchemaRegistry, htmlParser, console, []);
const resolver = new compiler.CompileMetadataResolver(
new compiler.NgModuleResolver(staticReflector),
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
elementSchemaRegistry, normalizer, staticReflector);
I18NHtmlParser, ɵConsole]
},
{ provide: DirectiveNormalizer, deps: [ResourceLoader, UrlResolver, HtmlParser, CompilerConfig] },
{ provide: CompileMetadataResolver, deps: [CompilerConfig, HtmlParser, NgModuleResolver,
DirectiveResolver, PipeResolver,
SummaryResolver,
ElementSchemaRegistry,
DirectiveNormalizer, ɵConsole,
[Optional, StaticSymbolCache],
CompileReflector,
[Optional, ERROR_COLLECTOR_TOKEN]] },
DEFAULT_PACKAGE_URL_PROVIDER,
{ provide: StyleCompiler, deps: [UrlResolver] },
{ provide: ViewCompiler, deps: [CompileReflector] },
{ provide: NgModuleCompiler, deps: [CompileReflector] },
{ provide: CompilerConfig, useValue: new CompilerConfig() },
{ provide: Compiler, useClass: CompilerImpl, deps: [Injector, CompileMetadataResolver,
TemplateParser, StyleCompiler,
ViewCompiler, NgModuleCompiler,
SummaryResolver, CompileReflector, CompilerConfig,
ɵConsole] },
{ provide: DomElementSchemaRegistry, deps: [] },
{ provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry },
{ provide: UrlResolver, deps: [PACKAGE_ROOT_URL] },
{ provide: DirectiveResolver, deps: [CompileReflector] },
{ provide: PipeResolver, deps: [CompileReflector] },
{ provide: NgModuleResolver, deps: [CompileReflector] },
]);
/**
* \@experimental
*/
class JitCompilerFactory {