Exemple #1
0
        public string GenerateSourceMap(string fileName, string content, Action<SourceMapBuilder> before = null)
        {
            if (AssemblyInfo.SourceMap.Enabled)
            {
                var projectPath = Path.GetDirectoryName(Location);

                SourceMapGenerator.Generate(fileName, projectPath, ref content,
                    before,
                    (sourceRelativePath) =>
                    {
                        string path = null;
                        ParsedSourceFile sourceFile = null;

                        try
                        {
                            path = Path.Combine(projectPath, sourceRelativePath);
                            sourceFile = ParsedSourceFiles.First(pf => pf.ParsedFile.FileName == path);

                            return sourceFile.SyntaxTree.TextSource ?? sourceFile.SyntaxTree.ToString(GetFormatter());
                        }
                        catch (Exception ex)
                        {
                            throw (TranslatorException)TranslatorException.Create(
                                "Could not get ParsedSourceFile for SourceMap. Exception: {0}; projectPath: {1}; sourceRelativePath: {2}; path: {3}.",
                                ex.ToString(), projectPath, sourceRelativePath, path);
                        }

                    },
                    new string[0], SourceFiles, AssemblyInfo.SourceMap.Eol
                );
            }

            return content;
        }
Exemple #2
0
        public virtual List <TranslatorOutputItem> Emit()
        {
            using (new Measure(Logger, "Emitting JavaScript code"))
            {
                var blocks = GetBlocks();
                foreach (var block in blocks)
                {
                    CancellationToken.ThrowIfCancellationRequested();

                    JsDoc.Init();

                    Logger.ZLogTrace("Emitting block {0}", block.GetType());

                    block.Emit();
                }

                if (AutoStartupMethods.Count > 1)
                {
                    var autoMethods = string.Join(", ", AutoStartupMethods);

                    Logger.LogError("Program has more than one entry point defined - {0}", autoMethods);

                    throw (TranslatorException)TranslatorException.Create("Program has more than one entry point defined - {0}", autoMethods);
                }

                return(TransformOutputs());
            }
        }