示例#1
0
        private static FunctionDeclaration CreateWithQualifierFunction(IIdentifier namespaceName, int pos, ISourceFile sourceFile)
        {
            // Observe the body is null, this is a 'declare' function
            var withQualifier = CreateInjectedNode <FunctionDeclaration>(SyntaxKind.FunctionDeclaration, pos, sourceFile);

            withQualifier.Name      = CreateIdentifier(Names.WithQualifierFunction, pos, sourceFile);
            withQualifier.Flags    |= NodeFlags.Ambient | NodeFlags.Export | NodeFlags.ScriptPublic;
            withQualifier.Modifiers = ModifiersArray.Create(withQualifier.Flags);
            withQualifier.Modifiers.Add(CreateInjectedNode <Modifier>(SyntaxKind.ExportKeyword, pos, sourceFile));
            withQualifier.Modifiers.Add(CreateInjectedNode <Modifier>(SyntaxKind.DeclareKeyword, pos, sourceFile));
            withQualifier.Parameters = CreateWithQualifierParameters(pos, sourceFile);
            withQualifier.Type       = CreateTypeOfExpression(namespaceName.Text, pos, sourceFile);
            withQualifier.Decorators = new NodeArray <IDecorator>(CreatePublicDecorator(pos, sourceFile));

            return(withQualifier);
        }
示例#2
0
        /// <summary>
        /// Injects a default qualifier declaration as a top level statement
        /// </summary>
        /// <remarks>
        /// The created function has the following shape:
        ///
        /// export declare const qualifier : {};
        ///
        /// The identifier count and node count that the parser mantains is not updated! But nobody is consuming that information so far.
        /// The declaration is created at position 0. This should not be visible to the user though.
        /// </remarks>
        public static void AddDefaultQualifierDeclaration(this ISourceFile sourceFile)
        {
            var variableStatement = CreateInjectedNode <VariableStatement>(SyntaxKind.VariableStatement, 0, sourceFile);

            // Flags and modifiers for the statement are set to 'export declare'
            variableStatement.Flags    |= NodeFlags.Ambient | NodeFlags.Export;
            variableStatement.Modifiers = ModifiersArray.Create(variableStatement.Flags);
            variableStatement.Modifiers.Add(CreateInjectedNode <Modifier>(SyntaxKind.ExportKeyword, 0, sourceFile));
            variableStatement.Modifiers.Add(CreateInjectedNode <Modifier>(SyntaxKind.DeclareKeyword, 0, sourceFile));

            variableStatement.DeclarationList = CreateQualifierDeclaration(0, sourceFile);

            sourceFile.Statements.Insert(0, variableStatement);

            sourceFile.DeclaresRootQualifier = true;
        }