Beispiel #1
0
 public AstImport(Parser parser, Position startLoc, Position endLoc, AstString moduleName,
                  AstSymbolImport?importName, ref StructList <AstNameMapping> specifiers) : base(parser, startLoc, endLoc)
 {
     ModuleName   = moduleName;
     ImportedName = importName;
     ImportedNames.TransferFrom(ref specifiers);
 }
Beispiel #2
0
 public override void Transform(TreeTransformer tt)
 {
     base.Transform(tt);
     ModuleName = (AstString)tt.Transform(ModuleName);
     if (ImportedName != null)
     {
         ImportedName = (AstSymbolImport)tt.Transform(ImportedName);
     }
     tt.TransformList(ref ImportedNames);
 }
Beispiel #3
0
        public AstExport(Parser parser, Position startPos, Position endPos, AstString source, AstNode declaration,
                         ref StructList <AstNameMapping> specifiers) : base(parser, startPos, endPos)
        {
            ModuleName = source;
            if (declaration is AstDefun || declaration is AstDefinitions || declaration is AstDefClass)
            {
                ExportedDefinition = declaration;
            }
            else
            {
                ExportedValue = declaration;
            }

            ExportedNames.TransferFrom(ref specifiers);
        }
Beispiel #4
0
        public override void CodeGen(OutputContext output)
        {
            string GetName(AstSymbol symbol)
            {
                return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name);
            }

            var allowShortHand = output.Options.Shorthand;
            var keyString      = Key switch
            {
                AstString str => str.Value,
                AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
                AstSymbol key => GetName(key),
                _ => null
            };

            if (allowShortHand &&
                Value is AstSymbol && keyString != null &&
                GetName((AstSymbol)Value) == keyString &&
                OutputContext.IsIdentifierString(keyString) &&
                OutputContext.IsIdentifier(keyString)
                )
            {
                output.PrintPropertyName(keyString);
            }
            else if (allowShortHand &&
                     Value is AstDefaultAssign defAssign && keyString != null &&
                     defAssign.Left is AstSymbol &&
                     OutputContext.IsIdentifierString(keyString) &&
                     GetName((AstSymbol)defAssign.Left) == keyString
                     )
            {
                output.PrintPropertyName(keyString);
                output.Space();
                output.Print("=");
                output.Space();
                defAssign.Right.Print(output);
            }
Beispiel #5
0
        protected void PrintGetterSetter(OutputContext output, string?type, bool @static)
        {
            if (@static)
            {
                output.Print("static");
                output.Space();
            }

            if (type != null)
            {
                output.Print(type);
                output.Space();
            }

            var keyString = Key switch
            {
                AstString str => str.Value,
                AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
                AstSymbol key => key.Name,
                _ => null
            };

            if (keyString != null)
            {
                output.PrintPropertyName(keyString);
            }
            else
            {
                output.Print("[");
                Key.Print(output);
                output.Print("]");
            }

            ((AstLambda)Value).DoPrint(output, true);
        }
    }
Beispiel #6
0
 AstImport(string?source, Position startLoc, Position endLoc, AstString moduleName,
           AstSymbolImport?importName) : base(source, startLoc, endLoc)
 {
     ModuleName   = moduleName;
     ImportedName = importName;
 }