Exemple #1
0
 /**
  * A transformer which operates on ts.SourceFiles and applies changes from an `IvyCompilation`.
  */
 function transformIvySourceFile(compilation, context, reflector, coreImportsFrom, file) {
     var importManager = new translator_1.ImportManager(coreImportsFrom !== null);
     // Recursively scan through the AST and perform any updates requested by the IvyCompilation.
     var sf = visitor_1.visit(file, new IvyVisitor(compilation, reflector, importManager, coreImportsFrom !== null), context);
     // Generate the import statements to prepend.
     var imports = importManager.getAllImports(file.fileName, coreImportsFrom).map(function (i) {
         return ts.createImportDeclaration(undefined, undefined, ts.createImportClause(undefined, ts.createNamespaceImport(ts.createIdentifier(i.as))), ts.createLiteral(i.name));
     });
     // Prepend imports if needed.
     if (imports.length > 0) {
         sf.statements = ts.createNodeArray(tslib_1.__spread(imports, sf.statements));
     }
     return sf;
 }
 /**
  * A transformer which operates on ts.SourceFiles and applies changes from an `IvyCompilation`.
  */
 function transformIvySourceFile(compilation, context, reflector, importRewriter, file, isCore, isClosureCompilerEnabled, defaultImportRecorder) {
     var constantPool = new compiler_1.ConstantPool();
     var importManager = new translator_1.ImportManager(importRewriter);
     // Recursively scan through the AST and perform any updates requested by the IvyCompilation.
     var visitor = new IvyVisitor(compilation, reflector, importManager, defaultImportRecorder, isCore, constantPool);
     var sf = visitor_1.visit(file, visitor, context);
     // Generate the constant statements first, as they may involve adding additional imports
     // to the ImportManager.
     var constants = constantPool.statements.map(function (stmt) { return translator_1.translateStatement(stmt, importManager, defaultImportRecorder); });
     // Preserve @fileoverview comments required by Closure, since the location might change as a
     // result of adding extra imports and constant pool statements.
     var fileOverviewMeta = isClosureCompilerEnabled ? getFileOverviewComment(sf.statements) : null;
     // Add new imports for this file.
     sf = utils_1.addImports(importManager, sf, constants);
     if (fileOverviewMeta !== null) {
         setFileOverviewComment(sf, fileOverviewMeta);
     }
     return sf;
 }