Ejemplo n.º 1
0
        /// <inheritdoc />
        public Task <Possible <ISourceFile> > TryParseAsync(AbsolutePath pathToParse, AbsolutePath moduleOrConfigPathPromptingParse, ParsingOptions parsingOption = null)
        {
            Contract.Assume(m_descriptorsBySpecPath != null, "Init must have been called");

            var pathToParseAsString = pathToParse.ToString(m_context.PathTable);

            if (!m_descriptorsBySpecPath.TryGetValue(pathToParse, out var descriptor))
            {
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            if (!Downloads.TryGetValue(descriptor.Name, out var downloadData))
            {
                Contract.Assert(false, "Inconsistent internal state of NugetWorkspaceResolver");
                return(Task.FromResult <Possible <ISourceFile> >(new SpecNotOwnedByResolverFailure(pathToParseAsString)));
            }

            var sourceFile = SourceFile.Create(pathToParseAsString);

            var downloadDeclaration = new VariableDeclaration("download", Identifier.CreateUndefined(), new TypeReferenceNode("File"));

            downloadDeclaration.Flags |= NodeFlags.Export | NodeFlags.Public | NodeFlags.ScriptPublic;
            downloadDeclaration.Pos    = 1;
            downloadDeclaration.End    = 2;

            var extractedDeclaration = new VariableDeclaration("extracted", Identifier.CreateUndefined(), new TypeReferenceNode("StaticDirectory"));

            extractedDeclaration.Flags |= NodeFlags.Export | NodeFlags.Public | NodeFlags.ScriptPublic;
            extractedDeclaration.Pos    = 3;
            extractedDeclaration.End    = 4;

            sourceFile.Statements.Add(
                new VariableStatement()
            {
                DeclarationList = new VariableDeclarationList(
                    NodeFlags.Const,
                    downloadDeclaration,
                    extractedDeclaration)
            }
                );

            // Needed for the binder to recurse.
            sourceFile.ExternalModuleIndicator = sourceFile;
            sourceFile.SetLineMap(new [] { 0, 2 });

            return(Task.FromResult <Possible <ISourceFile> >(sourceFile));
        }
Ejemplo n.º 2
0
        private SourceFile GetOrCreateSourceFile(AbsolutePath path)
        {
            Contract.Assert(path.IsValid);

            if (m_createdSourceFiles.TryGetValue(path, out SourceFile sourceFile))
            {
                return(sourceFile);
            }

            // This is the interop point to advertise values to other DScript specs
            // For now we just return an empty SourceFile
            sourceFile = SourceFile.Create(path.ToString(m_context.PathTable));

            // We need the binder to recurse
            sourceFile.ExternalModuleIndicator = sourceFile;
            sourceFile.SetLineMap(new int[0] {
            });

            m_createdSourceFiles.Add(path, sourceFile);
            return(sourceFile);
        }