private void ConvertExportsFile(IModuleRegistry moduleRegistry, ParsedModule module, Package package) { var exportsFileModule = ModuleLiteral.CreateFileModule( m_javaScriptWorkspaceResolver.ExportsFile, moduleRegistry, package, module.Specs[m_javaScriptWorkspaceResolver.ExportsFile].LineMap); // For each symbol defined in the resolver settings for exports, add all specified project outputs int pos = 1; foreach (var export in Exports) { FrontEndUtilities.AddEvaluationCallbackToFileModule( exportsFileModule, (context, moduleLiteral, evaluationStackFrame) => CollectProjectOutputsAsync(module.Definition.Specs, moduleLiteral.Qualifier.QualifierId, export, context.EvaluationScheduler), export.FullSymbol, pos); pos += 2; } var moduleInfo = new UninstantiatedModuleInfo( // We can register an empty one since we have the module populated properly new Script.SourceFile( m_javaScriptWorkspaceResolver.ExportsFile, new Declaration[] { }), exportsFileModule, Context.QualifierTable.EmptyQualifierSpaceId); moduleRegistry.AddUninstantiatedModuleInfo(moduleInfo); }
private FileModuleLiteral ConvertAndRegisterSourceFile(RuntimeModelContext runtimeModelContext, Workspace workspace, ISourceFile sourceFile, AbsolutePath path, bool isConfig) { var moduleLiteral = ModuleLiteral.CreateFileModule(path, FrontEndHost.ModuleRegistry, runtimeModelContext.Package, sourceFile.LineMap); var conversionContext = new AstConversionContext(runtimeModelContext, path, sourceFile, moduleLiteral); var converter = AstConverter.Create(Context.QualifierTable, conversionContext, ConversionConfiguration, workspace); Script.SourceFile convertedSourceFile = null; if (!isConfig) { convertedSourceFile = converter.ConvertSourceFile().SourceFile; } else if (Kind == ConfigurationKind.PrimaryConfig) { converter.ConvertConfiguration(); } else if (Kind == ConfigurationKind.ModuleConfig) { converter.ConvertPackageConfiguration(); } else { throw Contract.AssertFailure(UnimplementedOperationForConfigKindErrorMessage); } runtimeModelContext.Package.AddParsedProject(path); if (!Logger.HasErrors) { RegisterSuccessfullyParsedModule(convertedSourceFile, moduleLiteral, runtimeModelContext.Package); } return(moduleLiteral); }
/// <inheritdoc/> public Task <bool?> TryConvertModuleToEvaluationAsync(IModuleRegistry moduleRegistry, ParsedModule module, IWorkspace workspace) { // This resolver owns only one module. if (!module.Definition.Equals(ModuleDefinition)) { return(Task.FromResult <bool?>(null)); } var exportsFileModule = ModuleLiteral.CreateFileModule( m_javaScriptWorkspaceResolver.ExportsFile, moduleRegistry, FrontEndUtilities.CreatePackage(module.Definition, Context.StringTable), module.Specs[m_javaScriptWorkspaceResolver.ExportsFile].LineMap); // For each symbol defined in the resolver settings for exports, add all specified project outputs int pos = 1; foreach (var export in Exports) { FrontEndUtilities.AddEvaluationCallbackToFileModule( exportsFileModule, (context, moduleLiteral, evaluationStackFrame) => CollectProjectOutputsAsync(module.Definition.Specs, moduleLiteral.Qualifier.QualifierId, export), export.FullSymbol, pos); pos += 2; } var moduleInfo = new UninstantiatedModuleInfo( // We can register an empty one since we have the module populated properly new SourceFile( m_javaScriptWorkspaceResolver.ExportsFile, new Declaration[] {}), exportsFileModule, Context.QualifierTable.EmptyQualifierSpaceId); moduleRegistry.AddUninstantiatedModuleInfo(moduleInfo); return(Task.FromResult <bool?>(true)); }
/// <inheritdoc /> public Task <bool?> TryConvertModuleToEvaluationAsync(IModuleRegistry moduleRegistry, ParsedModule module, IWorkspace workspace) { if (!string.Equals(module.Descriptor.ResolverName, Name, StringComparison.Ordinal)) { return(Task.FromResult <bool?>(null)); } var downloadData = m_workspaceResolver.Downloads[module.Descriptor.Name]; var package = CreatePackage(module.Definition); Contract.Assert(module.Specs.Count == 1, "This resolver generated the module, so we expect a single spec."); var sourceKv = module.Specs.First(); var sourceFilePath = sourceKv.Key; var sourceFile = sourceKv.Value; var currentFileModule = ModuleLiteral.CreateFileModule( sourceFilePath, moduleRegistry, package, sourceFile.LineMap); // Download var downloadSymbol = FullSymbol.Create(m_context.SymbolTable, "download"); var downloadResolvedEntry = new ResolvedEntry( downloadSymbol, (Context context, ModuleLiteral env, EvaluationStackFrame args) => DownloadFile(downloadData), // The following position is a contract right now iwtht he generated ast in the workspace resolver // we have to find a nicer way to handle and register these. TypeScript.Net.Utilities.LineInfo.FromLineAndPosition(0, 1) ); currentFileModule.AddResolvedEntry(downloadSymbol, downloadResolvedEntry); currentFileModule.AddResolvedEntry(new FilePosition(1, sourceFilePath), downloadResolvedEntry); // Contents.All var extractedSymbol = FullSymbol.Create(m_context.SymbolTable, "extracted"); var contentsResolvedEntry = new ResolvedEntry( extractedSymbol, (Context context, ModuleLiteral env, EvaluationStackFrame args) => ExtractFile(downloadData), // The following position is a contract right now iwtht he generated ast in the workspace resolver // we have to find a nicer way to handle and register these. TypeScript.Net.Utilities.LineInfo.FromLineAndPosition(0, 3) ); currentFileModule.AddResolvedEntry(extractedSymbol, contentsResolvedEntry); currentFileModule.AddResolvedEntry(new FilePosition(3, sourceFilePath), contentsResolvedEntry); var moduleInfo = new UninstantiatedModuleInfo( // We can register an empty one since we have the module populated properly new SourceFile( sourceFilePath, new Declaration[] { }), currentFileModule, m_context.QualifierTable.EmptyQualifierSpaceId); moduleRegistry.AddUninstantiatedModuleInfo(moduleInfo); return(Task.FromResult <bool?>(true)); }
private IAstConverter CreateAstConverter(ISourceFile sourceFile, RuntimeModelContext runtimeModelContext, AbsolutePath path, AstConversionConfiguration conversionConfiguration, Workspace workspace) { var module = ModuleLiteral.CreateFileModule(path, runtimeModelContext.FrontEndHost.ModuleRegistry, runtimeModelContext.Package, sourceFile.LineMap); return(CreateAstConverter(sourceFile, module, runtimeModelContext, path, conversionConfiguration, workspace)); }