internal void ApplyReferenceProcessor(ReferenceProcessorBase refProcessor = null) { if (refProcessor == null) { return; } var references = References.References; references = refProcessor.FilterReferences(references, this); if (references == null) { references = new RtReference[0]; } _refinedReferences = references; var imports = References.Imports; imports = refProcessor.FilterImports(imports, this); if (imports == null) { imports = new RtImport[0]; } _refinedImports = imports; }
/// <summary> /// Ensures that imports for specified type presents in specified file /// </summary> /// <param name="t">Type to import</param> /// <param name="typeName">Type name (probably overriden)</param> /// <returns>Import AST node or null if no import needed. Returns existing import in case if type is already imported</returns> internal RtImport EnsureImport(Type t, string typeName) { if (TypesToExport.Contains(t)) { return(null); } var bp = _context.Project.Blueprint(t); if (bp.ThirdParty != null) { foreach (var tpi in bp.ThirdPartyImports) { References.AddImport(tpi); } return(null); } if (AllTypesIsSingleFile) { return(null); } var relPath = GetRelativePathForType(t, FileName); if (string.IsNullOrEmpty(relPath)) { return(null); } RtImport result = null; if (References.StarImports.ContainsKey(relPath)) { return(References.StarImports[relPath]); } if (_context.Global.DiscardNamespacesWhenUsingModules) { var target = string.Format("{{ {0} }}", typeName); result = new RtImport() { From = relPath, Target = target }; References.AddImport(result); } else { var alias = Path.GetFileNameWithoutExtension(relPath); var target = string.Format("* as {0}", alias); result = new RtImport() { From = relPath, Target = target }; References.AddImport(result); } return(result); }
protected virtual void ExportCore(StreamWriter tw, ExportedFile file, ReferenceProcessorBase refProcessor = null) { var visitor = Context.Global.ExportPureTypings ? new TypingsExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers) : new TypeScriptExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers); WriteWarning(tw); var references = file.References.References; if (refProcessor != null) { references = refProcessor.FilterReferences(references, file); if (references == null) { references = new RtReference[0]; } } bool hasReferences = false; foreach (var rtReference in references) { visitor.Visit(rtReference); hasReferences = true; } var imports = file.References.Imports; if (refProcessor != null) { imports = refProcessor.FilterImports(imports, file); if (imports == null) { imports = new RtImport[0]; } } bool hasImports = false; foreach (var rtImport in imports) { visitor.Visit(rtImport); hasImports = true; } if (hasReferences || hasImports) { tw.WriteLine(); } foreach (var fileNamespace in file.Namespaces) { visitor.Visit(fileNamespace); } }
internal RtImport ToImport() { if (_import == null) { _import = new RtImport() { Target = ImportTarget, From = ImportSource, IsRequire = ImportRequire } } ; return(_import); } }
/// <summary> /// Attaches new import to existing ones /// </summary> /// <param name="import">Import</param> public void AddImport(RtImport import) { if (import.IsWildcard) { if (_starImportsAs.ContainsKey(import.From)) { return; } _imports.RemoveWhere(c => c.From == import.From); _imports.Add(import); _starImportsAs[import.From] = import; } else { _imports.AddIfNotExists(import); } }
/// <summary> /// Ensures that imports for specified type presents in specified file /// </summary> /// <param name="t">Type to import</param> /// <param name="typeName">Type name (probably overriden)</param> /// <param name="file">Exported file</param> /// <returns>Import AST node or null if no import needed. Returns existing import in case if type is already imported</returns> public RtImport EnsureImport(Type t, string typeName, ExportedFile file) { if (file.TypesToExport.Contains(t)) { return(null); } if (file.AllTypesIsSingleFile) { return(null); } var relPath = GetRelativePathForType(t, file.FileName); if (string.IsNullOrEmpty(relPath)) { return(null); } RtImport result = null; if (file.References.StarImports.ContainsKey(relPath)) { return(file.References.StarImports[relPath]); } if (_context.Global.DiscardNamespacesWhenUsingModules) { var target = string.Format("{{ {0} }}", typeName); result = new RtImport() { From = relPath, Target = target }; file.References.AddImport(result); } else { var alias = Path.GetFileNameWithoutExtension(relPath); var target = string.Format("* as {0}", alias); result = new RtImport() { From = relPath, Target = target }; file.References.AddImport(result); } return(result); }
public override void Visit(RtImport node) { Write("import "); if (node.Target != null) { Write(node.Target); Write(" "); if (node.IsRequire) { WriteLine(string.Format("= require('{0}');", node.From)); } else { WriteLine(string.Format("from '{0}';", node.From)); } } else { WriteLine(string.Format("'{0}';", node.From)); } }
public abstract void Visit(RtImport node);
public override void Visit(RtImport node) { }
public abstract T Visit(RtImport node);