void ReportDependenciesFromCss(TsFileAdditionalInfo info) { if (info.TranspilationDependencies != null) { foreach (var dep in info.TranspilationDependencies) { var fullJustName = PathUtils.Join(info.Owner.Parent.FullPath, dep.Import); var fileAdditionalInfo = AutodetectAndAddDependency(fullJustName); if (fileAdditionalInfo == null) { info.ReportDiag(true, -3, "Missing dependency " + dep.Import, 0, 0, 0, 0); } info.ReportDependency(fullJustName); } } }
void Transpile(TsFileAdditionalInfo info) { ITSCompiler compiler = null; try { compiler = BuildCtx.CompilerPool.GetTs(Owner.DiskCache, BuildCtx.CompilerOptions); //_owner.Logger.Info("Transpiling " + info.Owner.FullPath); var result = compiler.Transpile(info.Owner.FullPath, info.Owner.Utf8Content); if (result.Diagnostics != null) { info.ReportDiag(result.Diagnostics); info.HasError = result.Diagnostics.Any(d => d.IsError); } else { info.HasError = false; } if (info.HasError) { info.Output = null; info.MapLink = null; } else { info.Output = SourceMap.RemoveLinkToSourceMap(result.JavaScript); info.MapLink = SourceMap.Parse(result.SourceMap, info.Owner.Parent.FullPath); } } finally { if (compiler != null) { BuildCtx.CompilerPool.ReleaseTs(compiler); } } if (info.HasError) { info.SourceInfo = null; return; } var backupCurrentlyTranspiling = _currentlyTranspiling; try { if (_currentlyTranspiling == null) { _currentlyTranspiling = info; } var parser = new Parser(new Options(), info.Output); var toplevel = parser.Parse(); toplevel.FigureOutScope(); var ctx = new ResolvingConstEvalCtx(info.Owner.FullPath, this); string Resolver(IConstEvalCtx myctx, string text) { return(ResolverWithPossibleForcingResource(myctx, text, false)); } string ResolverWithPossibleForcingResource(IConstEvalCtx myctx, string text, bool forceResource) { if (text.StartsWith("project:", StringComparison.Ordinal)) { var(pref, name) = SplitProjectAssetName(text); return(pref + ResolverWithPossibleForcingResource(myctx, name, true)); } if (text.StartsWith("resource:", StringComparison.Ordinal)) { return("resource:" + ResolverWithPossibleForcingResource(myctx, text.Substring("resource:".Length), true)); } if (text.StartsWith("node_modules/", StringComparison.Ordinal)) { var res2 = ResolveImport(info.Owner.FullPath, text.Substring("node_modules/".Length), false, true, forceResource, true); return(res2 == "?" ? text : res2); } var res = PathUtils.Join(PathUtils.Parent(myctx.SourceName), text); return(res); } var sourceInfo = GatherBobrilSourceInfo.Gather(toplevel, ctx, Resolver); info.SourceInfo = sourceInfo; AddDependenciesFromSourceInfo(info); } catch (SyntaxError error) { var pos = info.MapLink?.FindPosition(error.Position.Line, error.Position.Column) ?? new SourceCodePosition { Line = error.Position.Line, Col = error.Position.Column }; info.ReportDiag(true, -16, error.Message, pos.Line, pos.Col, pos.Line, pos.Col); info.SourceInfo = null; } finally { _currentlyTranspiling = backupCurrentlyTranspiling; } }
public void AddDependenciesFromSourceInfo(TsFileAdditionalInfo fileInfo) { var sourceInfo = fileInfo.SourceInfo; if (sourceInfo == null) { return; } sourceInfo.Imports?.ForEach(i => { var resolved = ResolveImport(fileInfo.Owner.FullPath, i.Name); if (resolved != null && resolved != "?") { fileInfo.ReportDependency(resolved); } else { fileInfo.ReportDiag(true, -3, "Missing import " + i.Name, i.StartLine, i.StartCol, i.EndLine, i.EndCol); } }); sourceInfo.Assets?.ForEach(a => { if (a.Name == null) { fileInfo.ReportDiag(true, -5, "First parameter of b.asset must be resolved as constant string", a.StartLine, a.StartCol, a.EndLine, a.EndCol); return; } var assetName = a.Name; if (assetName.StartsWith("project:")) { var(pref, name) = SplitProjectAssetName(assetName); if (pref.Length == 8) { name += "/package.json"; } if (!(Owner.DiskCache.TryGetItem(PathUtils.Join(Owner.Owner.FullPath, name)) is IFileCache)) { fileInfo.ReportDiag(true, -3, "Missing dependency " + assetName, a.StartLine, a.StartCol, a.EndLine, a.EndCol); } } else if (assetName.StartsWith("resource:")) { assetName = assetName.Substring(9); if (ReportDependency(fileInfo, AutodetectAndAddDependency(assetName, true)) == null) { fileInfo.ReportDiag(true, -3, "Missing dependency " + assetName, a.StartLine, a.StartCol, a.EndLine, a.EndCol); } } else { if (ReportDependency(fileInfo, AutodetectAndAddDependency(assetName)) == null) { fileInfo.ReportDiag(true, -3, "Missing dependency " + assetName, a.StartLine, a.StartCol, a.EndLine, a.EndCol); } } }); if (sourceInfo.Sprites != null) { if (Owner.ProjectOptions.SpriteGeneration) { var spriteHolder = Owner.ProjectOptions.SpriteGenerator; spriteHolder.Process(sourceInfo.Sprites); } else { sourceInfo.Sprites.ForEach(s => { if (s.Name == null) { return; } var assetName = s.Name; if (ReportDependency(fileInfo, AutodetectAndAddDependency(assetName)) == null) { fileInfo.ReportDiag(true, -3, "Missing dependency " + assetName, s.NameStartLine, s.NameStartCol, s.NameEndLine, s.NameEndCol); } }); } } if (sourceInfo.VdomTranslations != null) { var trdb = Owner.ProjectOptions.TranslationDb; if (trdb != null) { sourceInfo.VdomTranslations.ForEach(t => { if (t.Message == null) { return; } var err = trdb.CheckMessage(t.Message, t.KnownParams); if (err != null) { fileInfo.ReportDiag(false, -7, "Problem with translation message \"" + t.Message + "\" " + err, t.StartLine, t.StartCol, t.EndLine, t.EndCol); } }); } } if (sourceInfo.Translations != null) { var trdb = Owner.ProjectOptions.TranslationDb; if (trdb != null) { sourceInfo.Translations.ForEach(t => { if (t.Message == null) { return; } if (t.WithParams) { var err = trdb.CheckMessage(t.Message, t.KnownParams); if (err != null) { fileInfo.ReportDiag(false, -7, "Problem with translation message \"" + t.Message + "\" " + err, t.StartLine, t.StartCol, t.EndLine, t.EndCol); } } }); } } }