예제 #1
0
        /// <summary>
        /// Some statements are filtered based on visibility
        /// </summary>
        public override void VisitSourceFile(TypeScript.Net.Types.SourceFile node)
        {
            if (node.Statements.IsNullOrEmpty())
            {
                return;
            }

            var filteredStatements = FilterStatements(node.Statements);

            AppendSourceFileStatements(node, filteredStatements);
        }
예제 #2
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));
        }
예제 #3
0
        /// <summary>
        /// Exposes a declaration of the form '@@public export identifier : type = undefined' at the specified (pos, end) location
        /// </summary>
        /// <remarks>
        /// Line map of the source file is not set
        /// </remarks>
        public static void AddExportToSourceFile(TypeScript.Net.Types.SourceFile sourceFile, string identifier, ITypeNode type, int pos, int end)
        {
            // A value representing all output directories of the project
            var outputDeclaration = new VariableDeclaration(identifier, Identifier.CreateUndefined(), type);

            outputDeclaration.Flags |= NodeFlags.Export | NodeFlags.Public | NodeFlags.ScriptPublic;
            outputDeclaration.Pos    = pos;
            outputDeclaration.End    = end;

            // Final source file looks like
            //   @@public export outputs: type[] = undefined;
            // The 'undefined' part is not really important here. The value at runtime has its own special handling in the resolver.
            sourceFile.Statements.Add(new VariableStatement()
            {
                DeclarationList = new VariableDeclarationList(
                    NodeFlags.Const,
                    outputDeclaration)
            });
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Parses an arbitrary string returning a corresponding ISourceFile.
        /// </summary>
        /// <returns>Whether parsing succeded</returns>
        public static bool TryParseSourceFile(FrontEndContext context, AbsolutePath sourceFilePath, string sourceFileContent, out TypeScript.Net.Types.SourceFile sourceFile)
        {
            var parser = new DScriptParser(context.PathTable);

            sourceFile = (TypeScript.Net.Types.SourceFile)parser.ParseSourceFileContent(sourceFilePath.ToString(context.PathTable), sourceFileContent, ParsingOptions.DefaultParsingOptions);

            return(sourceFile.ParseDiagnostics.Count != 0);
        }
예제 #6
0
        /// <summary>
        /// Parses and binds an arbitrary string returning a corresponding ISourceFile.
        /// </summary>
        /// <returns>Whether parsing and binding succeded</returns>
        public static bool TryParseAndBindSourceFile(FrontEndHost host, FrontEndContext context, AbsolutePath sourceFilePath, string sourceFileContent, out TypeScript.Net.Types.SourceFile sourceFile)
        {
            if (!TryParseSourceFile(context, sourceFilePath, sourceFileContent, out sourceFile))
            {
                return(false);
            }

            Binder binder = new Binder();

            binder.BindSourceFile(sourceFile, CompilerOptions.Empty);

            if (sourceFile.BindDiagnostics.Count != 0)
            {
                return(false);
            }

            return(true);
        }