Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <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));
        }