public override void CodeGen(OutputContext output) { output.Print("switch"); output.Space(); Expression.Print(output, true); output.Space(); if (Body.Count == 0) { output.Print("{}"); } else { output.Print("{"); output.Newline(); output.Indentation += output.Options.IndentLevel; for (var i = 0u; i < Body.Count; i++) { var branch = (AstSwitchBranch)Body[i]; output.Indent(true); branch.Print(output); if (i < Body.Count - 1 && branch.Body.Count > 0) { output.Newline(); } } output.Indentation -= output.Options.IndentLevel; output.Indent(); output.Print("}"); }; }
public override void CodeGen(OutputContext output) { output.Print("["); var len = Elements.Count; if (len > 0) { output.Space(); } for (var i = 0u; i < Elements.Count; i++) { if (i > 0) { output.Comma(); } var exp = Elements[i]; exp.Print(output); // If the final element is a hole, we need to make sure it // doesn't look like a trailing comma, by inserting an actual // trailing comma. if (i == len - 1 && exp is AstHole) { output.Comma(); } } if (len > 0) { output.Space(); } output.Print("]"); }
public override void CodeGen(OutputContext output) { if (Properties.Count > 0) { output.Print("{"); output.Newline(); output.Indentation += output.Options.IndentLevel; for (var i = 0u; i < Properties.Count; i++) { if (i > 0) { output.Print(","); output.Newline(); } output.Indent(); Properties[i].Print(output); } output.Newline(); output.Indentation -= output.Options.IndentLevel; output.Indent(); output.Print("}"); } else { output.Print("{}"); } }
public override void CodeGen(OutputContext output) { Expression.Print(output); if (this is AstNew && !output.NeedConstructorParens(this)) { return; } if (Expression is AstCall or AstLambda) { output.AddMapping(Expression.Source, Start, false); } if (Optional) { output.Print("?."); } output.Print("("); for (var i = 0u; i < Args.Count; i++) { if (i > 0) { output.Comma(); } Args[i].Print(output); } output.Print(")"); }
protected void PrintGetterSetter(OutputContext output, string type, bool @static) { if (@static) { output.Print("static"); output.Space(); } if (type != null) { output.Print(type); output.Space(); } if (Key is AstSymbolMethod symbolMethod) { output.PrintPropertyName(symbolMethod.Name); } else { output.Print("["); ((AstNode)Key).Print(output); output.Print("]"); } ((AstLambda)Value).DoPrint(output, true); }
public void Print(OutputContext output, bool forceParens = false) { output.PushNode(this); if (this is AstToplevel) { output.AddMapping(null, new Position(), true); } else { output.AddMapping(Source, Start, true); } if (forceParens || NeedParens(output)) { output.Print("("); CodeGen(output); output.Print(")"); } else { CodeGen(output); } output.PopNode(); }
public override void CodeGen(OutputContext output) { Expression.Print(output); output.Print("["); ((AstNode)Property).Print(output); output.Print("]"); }
public override void CodeGen(OutputContext output) { output.Print("class"); output.Space(); if (Name != null) { Name.Print(output); output.Space(); } if (Extends != null) { var parens = !(Extends is AstSymbolRef) && !(Extends is AstPropAccess) && !(Extends is AstClassExpression) && !(Extends is AstFunction); output.Print("extends"); if (!parens) { output.Space(); } Extends.Print(output, parens); if (!parens) { output.Space(); } } if (Properties.Count > 0) { output.Print("{"); output.Newline(); output.Indentation += output.Options.IndentLevel; output.Indent(); for (var i = 0u; i < Properties.Count; i++) { if (i > 0) { output.Newline(); } output.Indent(); Properties[i].Print(output); } output.Newline(); output.Indentation -= output.Options.IndentLevel; output.Indent(); output.Print("}"); } else { output.Print("{}"); } }
public override void CodeGen(OutputContext output) { output.Print("with"); output.Space(); output.Print("("); Expression.Print(output); output.Print(")"); output.Space(); output.PrintBody(Body); }
public override void CodeGen(OutputContext output) { output.Print("while"); output.Space(); output.Print("("); Condition.Print(output); output.Print(")"); output.Space(); output.PrintBody(Body); }
public override void CodeGen(OutputContext output) { output.Print("/"); output.Print(Value.Pattern); output.Print("/"); var f = Value.Flags; if (f.HasFlag(RegExpFlags.GlobalMatch)) { output.Print("g"); } if (f.HasFlag(RegExpFlags.IgnoreCase)) { output.Print("i"); } if (f.HasFlag(RegExpFlags.Multiline)) { output.Print("m"); } if (f.HasFlag(RegExpFlags.Sticky)) { output.Print("y"); } if (f.HasFlag(RegExpFlags.Unicode)) { output.Print("u"); } if (f.HasFlag(RegExpFlags.DotAll)) { output.Print("s"); } }
public override void CodeGen(OutputContext output) { Expression.Print(output, Expression is AstBinary && output.NeedNodeParens(Expression)); if (output.NeedDotAfterNumber()) { output.Print("."); } output.AddMapping(Expression.Source, Expression.End, false); output.Print("."); output.Print((string)Property); }
public override void CodeGen(OutputContext output) { if (!output.Options.ShortenBooleans) { output.Print("true"); } else { output.Print("!0"); output.SetNeedDotAfterNumber(); } }
public override void CodeGen(OutputContext output) { output.Print("do"); output.Space(); output.MakeBlock(Body); output.Space(); output.Print("while"); output.Space(); output.Print("("); Condition.Print(output); output.Print(")"); output.Semicolon(); }
public override void CodeGen(OutputContext output) { var isTagged = output.Parent() is AstPrefixedTemplateString; output.Print("`"); for (var i = 0u; i < Segments.Count; i++) { if (!(Segments[i] is AstTemplateSegment seg)) { output.Print("${"); Segments[i].Print(output); output.Print("}"); }
public override void CodeGen(OutputContext output) { Expression.Print(output); if (output.NeedDotAfterNumber()) { output.Print("."); } output.Print("."); // the name after dot would be mapped about here. output.AddMapping(End); output.Print((string)Property); }
public override void CodeGen(OutputContext output) { output.Print("case"); output.Space(); Expression.Print(output); output.Print(":"); output.Newline(); for (var i = 0u; i < Body.Count; i++) { output.Indent(); Body[i].Print(output); output.Newline(); } }
public override void CodeGen(OutputContext output) { output.Print("import"); output.Space(); ImportedName?.Print(output); if (ImportedName != null && ImportedNames.Count > 0) { output.Print(","); output.Space(); } if (ImportedNames.Count > 0) { if (ImportedNames.Count == 1 && ImportedNames[0].ForeignName.Name == "*") { ImportedNames[0].Print(output); } else { output.Print("{"); for (var i = 0u; i < ImportedNames.Count; i++) { if (i > 0) { output.Comma(); } else { output.Space(); } ImportedNames[i].Print(output); } output.Space(); output.Print("}"); } } if (ImportedName != null || ImportedNames.Count > 0) { output.Space(); output.Print("from"); output.Space(); } ModuleName.Print(output); output.Semicolon(); }
public void Print(OutputContext output, bool forceParens = false) { output.PushNode(this); if (forceParens || !output.HasParens() && NeedParens(output)) { output.Print("("); CodeGen(output); output.Print(")"); } else { CodeGen(output); } output.PopNode(); }
protected void DoPrint(OutputContext output, string kind) { output.Print(kind); output.Space(); for (var i = 0u; i < Definitions.Count; i++) { if (i > 0) { output.Comma(); } Definitions[i].Print(output); } var p = output.Parent(); if (p is AstFor astFor && astFor.Init == this) { return; } if (p is AstForIn astForIn && astForIn.Init == this) { return; } if (p == null) { return; } output.Semicolon(); }
public override void CodeGen(OutputContext output) { output.Print(IsStar ? "yield*" : "yield"); if (Expression != null) { output.Space(); Expression.Print(output); } }
public override void CodeGen(OutputContext output) { var parenthesizeTag = Prefix is AstArrow || Prefix is AstBinary || Prefix is AstConditional || Prefix is AstSequence || Prefix is AstUnary; if (parenthesizeTag) { output.Print("("); } Prefix.Print(output); if (parenthesizeTag) { output.Print(")"); } TemplateString.Print(output); }
public override void CodeGen(OutputContext output) { output.Print("default:"); output.Newline(); for (var i = 0u; i < Body.Count; i++) { output.Indent(); Body[i].Print(output); output.Newline(); } }
public override void CodeGen(OutputContext output) { output.Print(this is AstReturn ? "return" : "throw"); if (Value != null) { output.Space(); Value.Print(output); } output.Semicolon(); }
public override void CodeGen(OutputContext output) { Condition.Print(output); output.Space(); output.Print("?"); output.Space(); Consequent.Print(output); output.Space(); output.Colon(); Alternative.Print(output); }
public override void CodeGen(OutputContext output) { output.Print("for"); if (Await) { output.Space(); output.Print("await"); } output.Space(); output.Print("("); Init.Print(output); output.Space(); output.Print(this is AstForOf ? "of" : "in"); output.Space(); Object.Print(output); output.Print(")"); output.Space(); output.PrintBody(Body); }
public override void CodeGen(OutputContext output) { var op = Operator; Left.Print(output, Left is AstBinary && output.NeedNodeParens(Left)); if (OutputContext.OperatorToString(op)[0] == '>' && /* ">>" ">>>" ">" ">=" */ Left is AstUnaryPostfix leftPostfix && leftPostfix.Operator == Operator.DecrementPostfix) { // space is mandatory to avoid outputting --> output.Print(" "); }
public override void CodeGen(OutputContext output) { output.Print("catch"); if (Argname != null) { output.Space(); Argname.Print(output, true); } output.Space(); output.PrintBraced(this, false); }
public override void CodeGen(OutputContext output) { output.Print(this is AstBreak ? "break" : "continue"); if (Label != null) { output.Space(); var name = Label.Thedef?.MangledName ?? Label.Thedef?.Name ?? Label.Name; output.PrintName(name); } output.Semicolon(); }
public override void CodeGen(OutputContext output) { output.Print(Operator); if (OutputContext.OperatorStartsWithLetter(Operator) || OutputContext.OperatorEndsWithPlusOrMinus(Operator) && Expression is AstUnaryPrefix nestedUnary && OutputContext.OperatorStartsWithPlusOrMinus(nestedUnary.Operator)) { output.Space(); } Expression.Print(output); }