Пример #1
0
        public (string fileName, AstToplevel content) ResolveAndLoad(JsModule module)
        {
            var fileName = ResolveImport(module.ImportedFrom, module.Name);

            if (fileName == null || fileName == "?")
            {
                return(null, null);
            }
            if (_currentlyTranspiling.Owner.FullPath == fileName)
            {
                return(null, null);
            }
            Result.Path2FileInfo.TryGetValue(module.ImportedFrom, out var sourceInfo);
            var info = CrawlFile(fileName);

            _currentlyTranspiling.ReportTranspilationDependency(sourceInfo.Owner.HashOfContent, module.Name, info.Owner.HashOfContent);
            if (_parsedCache.TryGetValue(fileName, out var toplevel))
            {
                return(fileName, toplevel);
            }
            if (info.Type == FileCompilationType.Json)
            {
                _parsedCache.Add(fileName, null);
                return(fileName, null);
            }
            try
            {
                var parser = new Parser(new Options(), info.Output);
                toplevel = parser.Parse();
                toplevel.FigureOutScope();
                _parsedCache.Add(fileName, toplevel);
                return(fileName, toplevel);
            }
            catch
            {
                return(fileName, null);
            }
        }
Пример #2
0
        void CrawlInfo(TSFileAdditionalInfo info)
        {
            if (info.Owner.ChangeId != info.ChangeId)
            {
                info.ChangeId = info.Owner.ChangeId;
                Result.RecompiledIncrementaly.Add(info);
                var oldDependencies = new StructList <string>();
                if (_noDependencyCheck)
                {
                    oldDependencies.TransferFrom(ref info.Dependencies);
                }
                info.StartCompiling();
                switch (info.Type)
                {
                case FileCompilationType.Json:
                    info.Output     = null;
                    info.MapLink    = null;
                    info.SourceInfo = null;
                    break;

                case FileCompilationType.EsmJavaScript:
                case FileCompilationType.TypeScript:
                    info.HasError = false;
                    if (!TryToResolveFromBuildCache(info))
                    {
                        info.Output     = null;
                        info.MapLink    = null;
                        info.SourceInfo = null;
                        Transpile(info);
                    }
                    break;

                case FileCompilationType.JavaScriptAsset:
                case FileCompilationType.JavaScript:
                    info.Output  = info.Owner.Utf8Content;
                    info.MapLink = SourceMap.Identity(info.Output, info.Owner.FullPath);
                    break;

                case FileCompilationType.Resource:
                    break;

                case FileCompilationType.Css:
                case FileCompilationType.ImportedCss:
                    if (!TryToResolveFromBuildCacheCss(info))
                    {
                        var cssProcessor = BuildCtx.CompilerPool.GetCss();
                        try
                        {
                            info.Output = info.Owner.Utf8Content;
                            cssProcessor.ProcessCss(info.Owner.Utf8Content,
                                                    ((TSFileAdditionalInfo)info).Owner.FullPath, (string url, string from) =>
                            {
                                var urlJustName = url.Split('?', '#')[0];
                                info.ReportTranspilationDependency(null, urlJustName, null);
                                return(url);
                            }).Wait();
                        }
                        finally
                        {
                            BuildCtx.CompilerPool.ReleaseCss(cssProcessor);
                        }
                    }
                    ReportDependenciesFromCss(info);
                    break;
                }
                if (_noDependencyCheck)
                {
                    if (!info.Dependencies.SequenceEqual(oldDependencies))
                    {
                        if (BuildCtx.Verbose)
                        {
                            Owner.Logger.Info("Dependency change detected " + info.Owner.FullPath);
                        }
                        _noDependencyCheck = false;
                    }
                }
            }
        }