jsii-rosetta 5.4.32-dev.3 → 5.4.32-dev.4

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -41,9 +41,9 @@ The current status of `jsii-rosetta` releases is:
41
41
 
42
42
  | Release | Status | EOS | Comment |
43
43
  | ------- | ----------- | -----------| ------------------------------------------------------------------------------------------------------- |
44
- | `5.4.x` | Current | TBD | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v5.4-latest?label=jsii-rosetta%40v5.4-latest&logo=npm) |
44
+ | `5.5.x` | Current | TBD | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v5.5-latest?label=jsii-rosetta%40v5.5-latest&logo=npm) |
45
+ | `5.4.x` | Maintenance | 2025-02-28 | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v5.4-latest?label=jsii-rosetta%40v5.4-latest&logo=npm) |
45
46
  | `5.3.x` | Maintenance | 2024-10-07 | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v5.3-latest?label=jsii-rosetta%40v5.3-latest&logo=npm) |
46
- | `5.2.x` | Maintenance | 2024-06-30 | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v5.2-latest?label=jsii-rosetta%40v5.2-latest&logo=npm) |
47
47
  | `1.x` | Maintenance | 2024-10-31 | ![npm](https://img.shields.io/npm/v/jsii-rosetta/v1?label=jsii-rosetta%40v1&logo=npm) |
48
48
 
49
49
  ## :gear: Contributing
package/lib/renderer.js CHANGED
@@ -292,6 +292,7 @@ class AstRenderer {
292
292
  return visitor.parenthesizedExpression(tree, this);
293
293
  case ts.SyntaxKind.VoidExpression:
294
294
  return visitor.maskingVoidExpression(tree, this);
295
+ case ts.SyntaxKind.JSDoc:
295
296
  case ts.SyntaxKind.JSDocComment:
296
297
  return visitor.jsDoc(tree, this);
297
298
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC,qCAAiE;AAEjE,sDAOgC;AAChC,kD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GAAG,IAAI,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAI,CAAgB;IACvC,OAAO,CAAC,KAAK,SAAS,CAAC;AACzB,CAAC;AAmBD,SAAS,6BAA6B,CAAC,GAAoB,EAAE,QAA0B;IACrF,OAAO;QACL,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;QACvC,UAAU,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import * as ts from 'typescript';\n\nimport { TargetLanguage } from './languages';\nimport { NO_SYNTAX, OTree, UnknownSyntax, Span } from './o-tree';\nimport { SubmoduleReference, SubmoduleReferenceMap } from './submodule-reference';\nimport {\n commentRangeFromTextRange,\n extractMaskingVoidExpression,\n extractShowingVoidExpression,\n nodeChildren,\n repeatNewlines,\n scanText,\n} from './typescript/ast-utils';\nimport { analyzeImportDeclaration, analyzeImportEquals, ImportStatement } from './typescript/imports';\nimport { typeOfExpression, inferredTypeOfExpression } from './typescript/types';\n\n/**\n * Render a TypeScript AST to some other representation (encoded in OTrees)\n *\n * Dispatch the actual conversion to a specific handler which will get the\n * appropriate method called for particular AST nodes. The handler may use\n * context to modify its own operations when traversing the tree hierarchy,\n * the type of which should be expressed via the C parameter.\n */\nexport class AstRenderer<C> {\n public readonly diagnostics = new Array<ts.Diagnostic>();\n public readonly currentContext: C;\n\n public constructor(\n private readonly sourceFile: ts.SourceFile,\n public readonly typeChecker: ts.TypeChecker,\n private readonly handler: AstHandler<C>,\n private readonly options: AstRendererOptions = {},\n public readonly submoduleReferences: SubmoduleReferenceMap = new Map(),\n ) {\n this.currentContext = handler.defaultContext;\n }\n\n /**\n * Merge the new context with the current context and create a new Converter from it\n */\n public updateContext(contextUpdate: Partial<C>): AstRenderer<C> {\n const newContext = this.handler.mergeContext(this.currentContext, contextUpdate);\n\n // Use prototypal inheritance to create a version of 'this' in which only\n // 'currentContext' is updated.\n return Object.assign(Object.create(this), {\n currentContext: newContext,\n });\n }\n\n /**\n * Convert a single node to an OTree\n */\n public convert(node: ts.Node | undefined): OTree {\n if (node === undefined) {\n return NO_SYNTAX;\n }\n\n // Basic transform of node\n const transformed = this.dispatch(node);\n transformed.setSpan(node.getStart(this.sourceFile), node.getEnd());\n if (!transformed.attachComment) {\n return transformed;\n }\n\n const withTrivia = this.attachLeadingTrivia(node, transformed);\n withTrivia.setSpan(node.getStart(this.sourceFile), node.getEnd());\n return withTrivia;\n }\n\n /**\n * Convert a set of nodes, filtering out hidden nodes\n */\n public convertAll(nodes: readonly ts.Node[]): OTree[] {\n return filterVisible(nodes).map(this.convert.bind(this));\n }\n\n public convertWithModifier(\n nodes: readonly ts.Node[],\n makeContext: (context: this, node: ts.Node, index: number) => AstRenderer<C>,\n ): OTree[] {\n const vis = assignVisibility(nodes);\n const result = new Array<OTree>();\n for (const [idx, { node, visible, maskingVoid }] of vis.entries()) {\n const renderedNode = visible ? node : maskingVoid;\n if (renderedNode) {\n const context = makeContext(this, renderedNode, idx);\n result.push(context.convert(renderedNode));\n }\n }\n return result;\n }\n\n /**\n * Convert a set of nodes, but update the context for the last one.\n *\n * Takes visibility into account.\n */\n public convertLastDifferently(nodes: readonly ts.Node[], lastContext: C): OTree[] {\n const lastConverter = this.updateContext(lastContext);\n\n const convert = this.convert.bind(this);\n const lastConvert = lastConverter.convert.bind(lastConverter);\n\n const ret: OTree[] = [];\n\n const vis = assignVisibility(nodes);\n for (let i = 0; i < vis.length; i++) {\n const whichConvert = i === vis.length - 1 ? lastConvert : convert;\n\n const node = vis[i].visible ? vis[i].node : vis[i].maskingVoid;\n if (node) {\n ret.push(whichConvert(node));\n }\n }\n\n return ret;\n }\n\n public getPosition(node: ts.Node): Span {\n return {\n start: node.getStart(this.sourceFile),\n end: node.getEnd(),\n };\n }\n\n public textOf(node: ts.Node): string {\n return node.getText(this.sourceFile);\n }\n\n public textAt(pos: number, end: number): string {\n return this.sourceFile.text.substring(pos, end);\n }\n\n /**\n * Infer type of expression by the argument it is assigned to\n *\n * If the type of the expression can include undefined (if the value is\n * optional), `undefined` will be removed from the union.\n *\n * (Will return undefined for object literals not unified with a declared type)\n *\n * @deprecated Use `inferredTypeOfExpression` instead\n */\n public inferredTypeOfExpression(node: ts.Expression) {\n return inferredTypeOfExpression(this.typeChecker, node);\n }\n\n /**\n * Type of expression from the text of the expression\n *\n * (Will return a map type for object literals)\n *\n * @deprecated Use `typeOfExpression` directly\n */\n public typeOfExpression(node: ts.Expression): ts.Type {\n return typeOfExpression(this.typeChecker, node);\n }\n\n public typeOfType(node: ts.TypeNode): ts.Type {\n return this.typeChecker.getTypeFromTypeNode(node);\n }\n\n public typeToString(type: ts.Type) {\n return this.typeChecker.typeToString(type);\n }\n\n public report(node: ts.Node, messageText: string, category: ts.DiagnosticCategory = ts.DiagnosticCategory.Error) {\n this.diagnostics.push({\n category,\n code: 0,\n source: 'rosetta',\n messageText,\n file: this.sourceFile,\n start: node.getStart(this.sourceFile),\n length: node.getWidth(this.sourceFile),\n });\n }\n\n public reportUnsupported(node: ts.Node, language: TargetLanguage | undefined): void {\n const nodeKind = ts.SyntaxKind[node.kind];\n // tslint:disable-next-line:max-line-length\n if (language) {\n this.report(\n node,\n `This TypeScript feature (${nodeKind}) is not supported in examples because we cannot translate it to ${language}. Please rewrite this example.`,\n );\n } else {\n this.report(\n node,\n `This TypeScript feature (${nodeKind}) is not supported in examples. Please rewrite this example.`,\n );\n }\n }\n\n /**\n * Whether there is non-whitespace on the same line before the given position\n */\n public codeOnLineBefore(pos: number) {\n const text = this.sourceFile.text;\n while (pos > 0) {\n const c = text[--pos];\n if (c === '\\n') {\n return false;\n }\n if (c !== ' ' && c !== '\\r' && c !== '\\t') {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Return a newline if the given node is preceded by at least one newline\n *\n * Used to mirror newline use between matchin brackets (such as { ... } and [ ... ]).\n */\n public mirrorNewlineBefore(viz?: ts.Node, suffix = '', otherwise = ''): string {\n if (viz === undefined) {\n return suffix;\n }\n\n // Return a newline if the given node is preceded by newlines\n const leadingRanges = scanText(this.sourceFile.text, viz.getFullStart(), viz.getStart(this.sourceFile));\n const newlines = [];\n\n for (const range of leadingRanges) {\n if (range.type === 'other') {\n newlines.push(repeatNewlines(this.sourceFile.text.substring(range.pos, range.end)));\n }\n }\n\n return (newlines.join('').length > 0 ? '\\n' : otherwise) + suffix;\n }\n\n /**\n * Dispatch node to handler\n */\n private dispatch(tree: ts.Node): OTree {\n const visitor = this.handler;\n\n // Using a switch on tree.kind + forced down-casting, because this is significantly faster than\n // doing a cascade of `if` statements with the `ts.is<NodeType>` functions, since `tree.kind` is\n // effectively integers, and this switch statement is hence optimizable to a jump table. This is\n // a VERY significant enhancement to the debugging experience, too.\n switch (tree.kind) {\n case ts.SyntaxKind.EmptyStatement:\n // Additional semicolon where it doesn't belong.\n return NO_SYNTAX;\n case ts.SyntaxKind.SourceFile:\n return visitor.sourceFile(tree as ts.SourceFile, this);\n case ts.SyntaxKind.ImportEqualsDeclaration:\n return visitor.importStatement(analyzeImportEquals(tree as ts.ImportEqualsDeclaration, this), this);\n case ts.SyntaxKind.ImportDeclaration:\n return new OTree(\n [],\n analyzeImportDeclaration(tree as ts.ImportDeclaration, this, this.submoduleReferences).map((import_) =>\n visitor.importStatement(import_, this),\n ),\n { canBreakLine: true, separator: '\\n' },\n );\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return visitor.stringLiteral(tree as ts.StringLiteral | ts.NoSubstitutionTemplateLiteral, this);\n case ts.SyntaxKind.NumericLiteral:\n return visitor.numericLiteral(tree as ts.NumericLiteral, this);\n case ts.SyntaxKind.FunctionDeclaration:\n return visitor.functionDeclaration(tree as ts.FunctionDeclaration, this);\n case ts.SyntaxKind.Identifier:\n return visitor.identifier(tree as ts.Identifier, this);\n case ts.SyntaxKind.Block:\n return visitor.block(tree as ts.Block, this);\n case ts.SyntaxKind.Parameter:\n return visitor.parameterDeclaration(tree as ts.ParameterDeclaration, this);\n case ts.SyntaxKind.ReturnStatement:\n return visitor.returnStatement(tree as ts.ReturnStatement, this);\n case ts.SyntaxKind.BinaryExpression:\n return visitor.binaryExpression(tree as ts.BinaryExpression, this);\n case ts.SyntaxKind.IfStatement:\n return visitor.ifStatement(tree as ts.IfStatement, this);\n case ts.SyntaxKind.PropertyAccessExpression:\n const submoduleReference = this.submoduleReferences?.get(tree as ts.PropertyAccessExpression);\n return visitor.propertyAccessExpression(tree as ts.PropertyAccessExpression, this, submoduleReference);\n case ts.SyntaxKind.AwaitExpression:\n return visitor.awaitExpression(tree as ts.AwaitExpression, this);\n case ts.SyntaxKind.CallExpression:\n return visitor.callExpression(tree as ts.CallExpression, this);\n case ts.SyntaxKind.ExpressionStatement:\n return visitor.expressionStatement(tree as ts.ExpressionStatement, this);\n case ts.SyntaxKind.ObjectLiteralExpression:\n return visitor.objectLiteralExpression(tree as ts.ObjectLiteralExpression, this);\n case ts.SyntaxKind.NewExpression:\n return visitor.newExpression(tree as ts.NewExpression, this);\n case ts.SyntaxKind.PropertyAssignment:\n return visitor.propertyAssignment(tree as ts.PropertyAssignment, this);\n case ts.SyntaxKind.VariableStatement:\n return visitor.variableStatement(tree as ts.VariableStatement, this);\n case ts.SyntaxKind.VariableDeclarationList:\n return visitor.variableDeclarationList(tree as ts.VariableDeclarationList, this);\n case ts.SyntaxKind.VariableDeclaration:\n return visitor.variableDeclaration(tree as ts.VariableDeclaration, this);\n case ts.SyntaxKind.ArrayLiteralExpression:\n return visitor.arrayLiteralExpression(tree as ts.ArrayLiteralExpression, this);\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n return visitor.shorthandPropertyAssignment(tree as ts.ShorthandPropertyAssignment, this);\n case ts.SyntaxKind.ForOfStatement:\n return visitor.forOfStatement(tree as ts.ForOfStatement, this);\n case ts.SyntaxKind.ClassDeclaration:\n return visitor.classDeclaration(tree as ts.ClassDeclaration, this);\n case ts.SyntaxKind.Constructor:\n return visitor.constructorDeclaration(tree as ts.ConstructorDeclaration, this);\n case ts.SyntaxKind.PropertyDeclaration:\n return visitor.propertyDeclaration(tree as ts.PropertyDeclaration, this);\n case ts.SyntaxKind.ComputedPropertyName:\n return visitor.computedPropertyName((tree as ts.ComputedPropertyName).expression, this);\n case ts.SyntaxKind.MethodDeclaration:\n return visitor.methodDeclaration(tree as ts.MethodDeclaration, this);\n case ts.SyntaxKind.InterfaceDeclaration:\n return visitor.interfaceDeclaration(tree as ts.InterfaceDeclaration, this);\n case ts.SyntaxKind.PropertySignature:\n return visitor.propertySignature(tree as ts.PropertySignature, this);\n case ts.SyntaxKind.MethodSignature:\n return visitor.methodSignature(tree as ts.MethodSignature, this);\n case ts.SyntaxKind.AsExpression:\n return visitor.asExpression(tree as ts.AsExpression, this);\n case ts.SyntaxKind.PrefixUnaryExpression:\n return visitor.prefixUnaryExpression(tree as ts.PrefixUnaryExpression, this);\n case ts.SyntaxKind.SpreadAssignment:\n if (this.textOf(tree) === '...') {\n return visitor.ellipsis(tree as ts.SpreadAssignment, this);\n }\n return visitor.spreadAssignment(tree as ts.SpreadAssignment, this);\n case ts.SyntaxKind.SpreadElement:\n if (this.textOf(tree) === '...') {\n return visitor.ellipsis(tree as ts.SpreadElement, this);\n }\n return visitor.spreadElement(tree as ts.SpreadElement, this);\n case ts.SyntaxKind.ElementAccessExpression:\n return visitor.elementAccessExpression(tree as ts.ElementAccessExpression, this);\n case ts.SyntaxKind.TemplateExpression:\n return visitor.templateExpression(tree as ts.TemplateExpression, this);\n case ts.SyntaxKind.NonNullExpression:\n return visitor.nonNullExpression(tree as ts.NonNullExpression, this);\n case ts.SyntaxKind.ParenthesizedExpression:\n return visitor.parenthesizedExpression(tree as ts.ParenthesizedExpression, this);\n case ts.SyntaxKind.VoidExpression:\n return visitor.maskingVoidExpression(tree as ts.VoidExpression, this);\n case ts.SyntaxKind.JSDocComment:\n return visitor.jsDoc(tree as ts.JSDoc, this);\n default:\n if (ts.isToken(tree)) {\n return visitor.token(tree, this);\n }\n this.reportUnsupported(tree, undefined);\n }\n\n if (this.options.bestEffort !== false) {\n // When doing best-effort conversion and we don't understand the node type, just return the complete text of it as-is\n return new OTree([this.textOf(tree)]);\n }\n // Otherwise, show a placeholder indicating we don't recognize the type\n const nodeKind = ts.SyntaxKind[tree.kind];\n return new UnknownSyntax(\n [`<${nodeKind} ${this.textOf(tree)}>`],\n ['\\n', ...nodeChildren(tree).map(this.convert.bind(this))],\n {\n indent: 2,\n },\n );\n }\n\n /**\n * Attach any leading whitespace and comments to the given output tree\n *\n * Regardless of whether it's declared to be able to accept such or not.\n */\n private attachLeadingTrivia(node: ts.Node, transformed: OTree): OTree {\n // Add comments and leading whitespace\n const leadingRanges = scanText(this.sourceFile.text, node.getFullStart(), node.getStart(this.sourceFile));\n\n const precede: OTree[] = [];\n for (const range of leadingRanges) {\n let trivia: OTree | undefined = undefined;\n switch (range.type) {\n case 'other':\n trivia = new OTree([repeatNewlines(this.sourceFile.text.substring(range.pos, range.end))], [], {\n renderOnce: `ws-${range.pos}`,\n });\n break;\n case 'linecomment':\n case 'blockcomment':\n trivia = this.handler.commentRange(\n commentSyntaxFromCommentRange(commentRangeFromTextRange(range), this),\n this,\n );\n break;\n\n case 'directive':\n break;\n }\n if (trivia != null) {\n // Set spans on comments to make sure their visibility is toggled correctly.\n trivia.setSpan(range.pos, range.end);\n precede.push(trivia);\n }\n }\n\n // FIXME: No trailing comments for now, they're too tricky\n\n if (precede.length > 0 && !transformed.isEmpty) {\n return new OTree([...precede, transformed], [], { canBreakLine: true });\n }\n return transformed;\n }\n}\n\n/**\n * Interface for AST handlers\n *\n * C is the type of hierarchical context the handler uses. Context\n * needs 2 operations: a constructor for a default context, and a\n * merge operation to combine 2 contexts to yield a new one.\n *\n * Otherwise, the handler should return an OTree for every type\n * of AST node.\n */\nexport interface AstHandler<C> {\n readonly language: TargetLanguage;\n\n readonly defaultContext: C;\n readonly indentChar?: ' ' | '\\t';\n mergeContext(old: C, update: Partial<C>): C;\n\n sourceFile(node: ts.SourceFile, context: AstRenderer<C>): OTree;\n commentRange(node: CommentSyntax, context: AstRenderer<C>): OTree;\n importStatement(node: ImportStatement, context: AstRenderer<C>): OTree;\n stringLiteral(node: ts.StringLiteral | ts.NoSubstitutionTemplateLiteral, children: AstRenderer<C>): OTree;\n numericLiteral(node: ts.NumericLiteral, children: AstRenderer<C>): OTree;\n functionDeclaration(node: ts.FunctionDeclaration, children: AstRenderer<C>): OTree;\n identifier(node: ts.Identifier, children: AstRenderer<C>): OTree;\n block(node: ts.Block, children: AstRenderer<C>): OTree;\n parameterDeclaration(node: ts.ParameterDeclaration, children: AstRenderer<C>): OTree;\n returnStatement(node: ts.ReturnStatement, context: AstRenderer<C>): OTree;\n binaryExpression(node: ts.BinaryExpression, context: AstRenderer<C>): OTree;\n ifStatement(node: ts.IfStatement, context: AstRenderer<C>): OTree;\n propertyAccessExpression(\n node: ts.PropertyAccessExpression,\n context: AstRenderer<C>,\n submoduleReference: SubmoduleReference | undefined,\n ): OTree;\n awaitExpression(node: ts.AwaitExpression, context: AstRenderer<C>): OTree;\n callExpression(node: ts.CallExpression, context: AstRenderer<C>): OTree;\n expressionStatement(node: ts.ExpressionStatement, context: AstRenderer<C>): OTree;\n token<A extends ts.SyntaxKind>(node: ts.Token<A>, context: AstRenderer<C>): OTree;\n objectLiteralExpression(node: ts.ObjectLiteralExpression, context: AstRenderer<C>): OTree;\n newExpression(node: ts.NewExpression, context: AstRenderer<C>): OTree;\n propertyAssignment(node: ts.PropertyAssignment, context: AstRenderer<C>): OTree;\n variableStatement(node: ts.VariableStatement, context: AstRenderer<C>): OTree;\n variableDeclarationList(node: ts.VariableDeclarationList, context: AstRenderer<C>): OTree;\n variableDeclaration(node: ts.VariableDeclaration, context: AstRenderer<C>): OTree;\n jsDoc(node: ts.JSDoc, context: AstRenderer<C>): OTree;\n arrayLiteralExpression(node: ts.ArrayLiteralExpression, context: AstRenderer<C>): OTree;\n shorthandPropertyAssignment(node: ts.ShorthandPropertyAssignment, context: AstRenderer<C>): OTree;\n forOfStatement(node: ts.ForOfStatement, context: AstRenderer<C>): OTree;\n classDeclaration(node: ts.ClassDeclaration, context: AstRenderer<C>): OTree;\n constructorDeclaration(node: ts.ConstructorDeclaration, context: AstRenderer<C>): OTree;\n propertyDeclaration(node: ts.PropertyDeclaration, context: AstRenderer<C>): OTree;\n computedPropertyName(node: ts.Expression, context: AstRenderer<C>): OTree;\n methodDeclaration(node: ts.MethodDeclaration, context: AstRenderer<C>): OTree;\n interfaceDeclaration(node: ts.InterfaceDeclaration, context: AstRenderer<C>): OTree;\n propertySignature(node: ts.PropertySignature, context: AstRenderer<C>): OTree;\n methodSignature(node: ts.MethodSignature, context: AstRenderer<C>): OTree;\n asExpression(node: ts.AsExpression, context: AstRenderer<C>): OTree;\n prefixUnaryExpression(node: ts.PrefixUnaryExpression, context: AstRenderer<C>): OTree;\n spreadElement(node: ts.SpreadElement, context: AstRenderer<C>): OTree;\n spreadAssignment(node: ts.SpreadAssignment, context: AstRenderer<C>): OTree;\n templateExpression(node: ts.TemplateExpression, context: AstRenderer<C>): OTree;\n nonNullExpression(node: ts.NonNullExpression, context: AstRenderer<C>): OTree;\n parenthesizedExpression(node: ts.ParenthesizedExpression, context: AstRenderer<C>): OTree;\n maskingVoidExpression(node: ts.VoidExpression, context: AstRenderer<C>): OTree;\n elementAccessExpression(node: ts.ElementAccessExpression, context: AstRenderer<C>): OTree;\n\n // Not a node, called when we recognize a spread element/assignment that is only\n // '...' and nothing else.\n ellipsis(node: ts.SpreadElement | ts.SpreadAssignment, context: AstRenderer<C>): OTree;\n}\n\nexport function nimpl<C>(node: ts.Node, context: AstRenderer<C>, options: { additionalInfo?: string } = {}) {\n const children = nodeChildren(node).map((c) => context.convert(c));\n\n let syntaxKind = ts.SyntaxKind[node.kind];\n if (syntaxKind === 'FirstPunctuation') {\n // These have the same identifier but this name is more descriptive\n syntaxKind = 'OpenBraceToken';\n }\n\n const parts = [`(${syntaxKind}`];\n if (options.additionalInfo) {\n parts.push(`{${options.additionalInfo}}`);\n }\n parts.push(context.textOf(node));\n\n return new UnknownSyntax([parts.join(' ')], children.length > 0 ? ['\\n', ...children] : [], {\n indent: 2,\n suffix: ')',\n separator: '\\n',\n canBreakLine: true,\n });\n}\n\nexport interface AstRendererOptions {\n /**\n * If enabled, don't translate the text of unknown nodes\n *\n * @default true\n */\n bestEffort?: boolean;\n}\n\ninterface ClassifiedNode {\n node: ts.Node;\n visible: boolean;\n maskingVoid?: ts.VoidExpression;\n}\n\nfunction filterVisible(nodes: readonly ts.Node[]): ts.Node[] {\n return assignVisibility(nodes)\n .map((c) => (c.visible ? c.node : c.maskingVoid))\n .filter(notUndefined);\n}\n\nfunction assignVisibility(nodes: readonly ts.Node[]): ClassifiedNode[] {\n const ret: ClassifiedNode[] = [];\n\n let visible = true;\n for (const node of nodes) {\n const maskingVoid = extractMaskingVoidExpression(node);\n if (visible && maskingVoid) {\n visible = false;\n }\n\n ret.push({ node, maskingVoid, visible });\n\n if (!visible) {\n const showing = extractShowingVoidExpression(node);\n if (showing) {\n visible = true;\n }\n }\n }\n\n return ret;\n}\n\nfunction notUndefined<A>(x: A | undefined): x is A {\n return x !== undefined;\n}\n\n/**\n * Our own representation of comments\n *\n * (So we can synthesize 'em\n */\nexport interface CommentSyntax {\n pos: number;\n text: string;\n hasTrailingNewLine?: boolean;\n kind: ts.CommentKind;\n\n /**\n * Whether it's at the end of a code line (so we can render a separating space)\n */\n isTrailing?: boolean;\n}\n\nfunction commentSyntaxFromCommentRange(rng: ts.CommentRange, renderer: AstRenderer<any>): CommentSyntax {\n return {\n hasTrailingNewLine: rng.hasTrailingNewLine,\n kind: rng.kind,\n pos: rng.pos,\n text: renderer.textAt(rng.pos, rng.end),\n isTrailing: renderer.codeOnLineBefore(rng.pos),\n };\n}\n"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC,qCAAiE;AAEjE,sDAOgC;AAChC,kDAAsG;AACtG,8CAAgF;AAEhF;;;;;;;GAOG;AACH,MAAa,WAAW;IAItB,YACmB,UAAyB,EAC1B,WAA2B,EAC1B,OAAsB,EACtB,UAA8B,EAAE,EACjC,sBAA6C,IAAI,GAAG,EAAE;QAJrD,eAAU,GAAV,UAAU,CAAe;QAC1B,gBAAW,GAAX,WAAW,CAAgB;QAC1B,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAAyB;QACjC,wBAAmB,GAAnB,mBAAmB,CAAmC;QARxD,gBAAW,GAAG,IAAI,KAAK,EAAiB,CAAC;QAUvD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,aAAyB;QAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAEjF,yEAAyE;QACzE,+BAA+B;QAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACxC,cAAc,EAAE,UAAU;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAyB;QACtC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,kBAAS,CAAC;QACnB,CAAC;QAED,0BAA0B;QAC1B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,C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;YAC3B,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QAED,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;QAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,IAAA,wCAA4B,EAAC,IAAI,CAAC,CAAC;YACnD,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAI,CAAgB;IACvC,OAAO,CAAC,KAAK,SAAS,CAAC;AACzB,CAAC;AAmBD,SAAS,6BAA6B,CAAC,GAAoB,EAAE,QAA0B;IACrF,OAAO;QACL,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;QACvC,UAAU,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import * as ts from 'typescript';\n\nimport { TargetLanguage } from './languages';\nimport { NO_SYNTAX, OTree, UnknownSyntax, Span } from './o-tree';\nimport { SubmoduleReference, SubmoduleReferenceMap } from './submodule-reference';\nimport {\n commentRangeFromTextRange,\n extractMaskingVoidExpression,\n extractShowingVoidExpression,\n nodeChildren,\n repeatNewlines,\n scanText,\n} from './typescript/ast-utils';\nimport { analyzeImportDeclaration, analyzeImportEquals, ImportStatement } from './typescript/imports';\nimport { typeOfExpression, inferredTypeOfExpression } from './typescript/types';\n\n/**\n * Render a TypeScript AST to some other representation (encoded in OTrees)\n *\n * Dispatch the actual conversion to a specific handler which will get the\n * appropriate method called for particular AST nodes. The handler may use\n * context to modify its own operations when traversing the tree hierarchy,\n * the type of which should be expressed via the C parameter.\n */\nexport class AstRenderer<C> {\n public readonly diagnostics = new Array<ts.Diagnostic>();\n public readonly currentContext: C;\n\n public constructor(\n private readonly sourceFile: ts.SourceFile,\n public readonly typeChecker: ts.TypeChecker,\n private readonly handler: AstHandler<C>,\n private readonly options: AstRendererOptions = {},\n public readonly submoduleReferences: SubmoduleReferenceMap = new Map(),\n ) {\n this.currentContext = handler.defaultContext;\n }\n\n /**\n * Merge the new context with the current context and create a new Converter from it\n */\n public updateContext(contextUpdate: Partial<C>): AstRenderer<C> {\n const newContext = this.handler.mergeContext(this.currentContext, contextUpdate);\n\n // Use prototypal inheritance to create a version of 'this' in which only\n // 'currentContext' is updated.\n return Object.assign(Object.create(this), {\n currentContext: newContext,\n });\n }\n\n /**\n * Convert a single node to an OTree\n */\n public convert(node: ts.Node | undefined): OTree {\n if (node === undefined) {\n return NO_SYNTAX;\n }\n\n // Basic transform of node\n const transformed = this.dispatch(node);\n transformed.setSpan(node.getStart(this.sourceFile), node.getEnd());\n if (!transformed.attachComment) {\n return transformed;\n }\n\n const withTrivia = this.attachLeadingTrivia(node, transformed);\n withTrivia.setSpan(node.getStart(this.sourceFile), node.getEnd());\n return withTrivia;\n }\n\n /**\n * Convert a set of nodes, filtering out hidden nodes\n */\n public convertAll(nodes: readonly ts.Node[]): OTree[] {\n return filterVisible(nodes).map(this.convert.bind(this));\n }\n\n public convertWithModifier(\n nodes: readonly ts.Node[],\n makeContext: (context: this, node: ts.Node, index: number) => AstRenderer<C>,\n ): OTree[] {\n const vis = assignVisibility(nodes);\n const result = new Array<OTree>();\n for (const [idx, { node, visible, maskingVoid }] of vis.entries()) {\n const renderedNode = visible ? node : maskingVoid;\n if (renderedNode) {\n const context = makeContext(this, renderedNode, idx);\n result.push(context.convert(renderedNode));\n }\n }\n return result;\n }\n\n /**\n * Convert a set of nodes, but update the context for the last one.\n *\n * Takes visibility into account.\n */\n public convertLastDifferently(nodes: readonly ts.Node[], lastContext: C): OTree[] {\n const lastConverter = this.updateContext(lastContext);\n\n const convert = this.convert.bind(this);\n const lastConvert = lastConverter.convert.bind(lastConverter);\n\n const ret: OTree[] = [];\n\n const vis = assignVisibility(nodes);\n for (let i = 0; i < vis.length; i++) {\n const whichConvert = i === vis.length - 1 ? lastConvert : convert;\n\n const node = vis[i].visible ? vis[i].node : vis[i].maskingVoid;\n if (node) {\n ret.push(whichConvert(node));\n }\n }\n\n return ret;\n }\n\n public getPosition(node: ts.Node): Span {\n return {\n start: node.getStart(this.sourceFile),\n end: node.getEnd(),\n };\n }\n\n public textOf(node: ts.Node): string {\n return node.getText(this.sourceFile);\n }\n\n public textAt(pos: number, end: number): string {\n return this.sourceFile.text.substring(pos, end);\n }\n\n /**\n * Infer type of expression by the argument it is assigned to\n *\n * If the type of the expression can include undefined (if the value is\n * optional), `undefined` will be removed from the union.\n *\n * (Will return undefined for object literals not unified with a declared type)\n *\n * @deprecated Use `inferredTypeOfExpression` instead\n */\n public inferredTypeOfExpression(node: ts.Expression) {\n return inferredTypeOfExpression(this.typeChecker, node);\n }\n\n /**\n * Type of expression from the text of the expression\n *\n * (Will return a map type for object literals)\n *\n * @deprecated Use `typeOfExpression` directly\n */\n public typeOfExpression(node: ts.Expression): ts.Type {\n return typeOfExpression(this.typeChecker, node);\n }\n\n public typeOfType(node: ts.TypeNode): ts.Type {\n return this.typeChecker.getTypeFromTypeNode(node);\n }\n\n public typeToString(type: ts.Type) {\n return this.typeChecker.typeToString(type);\n }\n\n public report(node: ts.Node, messageText: string, category: ts.DiagnosticCategory = ts.DiagnosticCategory.Error) {\n this.diagnostics.push({\n category,\n code: 0,\n source: 'rosetta',\n messageText,\n file: this.sourceFile,\n start: node.getStart(this.sourceFile),\n length: node.getWidth(this.sourceFile),\n });\n }\n\n public reportUnsupported(node: ts.Node, language: TargetLanguage | undefined): void {\n const nodeKind = ts.SyntaxKind[node.kind];\n // tslint:disable-next-line:max-line-length\n if (language) {\n this.report(\n node,\n `This TypeScript feature (${nodeKind}) is not supported in examples because we cannot translate it to ${language}. Please rewrite this example.`,\n );\n } else {\n this.report(\n node,\n `This TypeScript feature (${nodeKind}) is not supported in examples. Please rewrite this example.`,\n );\n }\n }\n\n /**\n * Whether there is non-whitespace on the same line before the given position\n */\n public codeOnLineBefore(pos: number) {\n const text = this.sourceFile.text;\n while (pos > 0) {\n const c = text[--pos];\n if (c === '\\n') {\n return false;\n }\n if (c !== ' ' && c !== '\\r' && c !== '\\t') {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Return a newline if the given node is preceded by at least one newline\n *\n * Used to mirror newline use between matchin brackets (such as { ... } and [ ... ]).\n */\n public mirrorNewlineBefore(viz?: ts.Node, suffix = '', otherwise = ''): string {\n if (viz === undefined) {\n return suffix;\n }\n\n // Return a newline if the given node is preceded by newlines\n const leadingRanges = scanText(this.sourceFile.text, viz.getFullStart(), viz.getStart(this.sourceFile));\n const newlines = [];\n\n for (const range of leadingRanges) {\n if (range.type === 'other') {\n newlines.push(repeatNewlines(this.sourceFile.text.substring(range.pos, range.end)));\n }\n }\n\n return (newlines.join('').length > 0 ? '\\n' : otherwise) + suffix;\n }\n\n /**\n * Dispatch node to handler\n */\n private dispatch(tree: ts.Node): OTree {\n const visitor = this.handler;\n\n // Using a switch on tree.kind + forced down-casting, because this is significantly faster than\n // doing a cascade of `if` statements with the `ts.is<NodeType>` functions, since `tree.kind` is\n // effectively integers, and this switch statement is hence optimizable to a jump table. This is\n // a VERY significant enhancement to the debugging experience, too.\n switch (tree.kind) {\n case ts.SyntaxKind.EmptyStatement:\n // Additional semicolon where it doesn't belong.\n return NO_SYNTAX;\n case ts.SyntaxKind.SourceFile:\n return visitor.sourceFile(tree as ts.SourceFile, this);\n case ts.SyntaxKind.ImportEqualsDeclaration:\n return visitor.importStatement(analyzeImportEquals(tree as ts.ImportEqualsDeclaration, this), this);\n case ts.SyntaxKind.ImportDeclaration:\n return new OTree(\n [],\n analyzeImportDeclaration(tree as ts.ImportDeclaration, this, this.submoduleReferences).map((import_) =>\n visitor.importStatement(import_, this),\n ),\n { canBreakLine: true, separator: '\\n' },\n );\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return visitor.stringLiteral(tree as ts.StringLiteral | ts.NoSubstitutionTemplateLiteral, this);\n case ts.SyntaxKind.NumericLiteral:\n return visitor.numericLiteral(tree as ts.NumericLiteral, this);\n case ts.SyntaxKind.FunctionDeclaration:\n return visitor.functionDeclaration(tree as ts.FunctionDeclaration, this);\n case ts.SyntaxKind.Identifier:\n return visitor.identifier(tree as ts.Identifier, this);\n case ts.SyntaxKind.Block:\n return visitor.block(tree as ts.Block, this);\n case ts.SyntaxKind.Parameter:\n return visitor.parameterDeclaration(tree as ts.ParameterDeclaration, this);\n case ts.SyntaxKind.ReturnStatement:\n return visitor.returnStatement(tree as ts.ReturnStatement, this);\n case ts.SyntaxKind.BinaryExpression:\n return visitor.binaryExpression(tree as ts.BinaryExpression, this);\n case ts.SyntaxKind.IfStatement:\n return visitor.ifStatement(tree as ts.IfStatement, this);\n case ts.SyntaxKind.PropertyAccessExpression:\n const submoduleReference = this.submoduleReferences?.get(tree as ts.PropertyAccessExpression);\n return visitor.propertyAccessExpression(tree as ts.PropertyAccessExpression, this, submoduleReference);\n case ts.SyntaxKind.AwaitExpression:\n return visitor.awaitExpression(tree as ts.AwaitExpression, this);\n case ts.SyntaxKind.CallExpression:\n return visitor.callExpression(tree as ts.CallExpression, this);\n case ts.SyntaxKind.ExpressionStatement:\n return visitor.expressionStatement(tree as ts.ExpressionStatement, this);\n case ts.SyntaxKind.ObjectLiteralExpression:\n return visitor.objectLiteralExpression(tree as ts.ObjectLiteralExpression, this);\n case ts.SyntaxKind.NewExpression:\n return visitor.newExpression(tree as ts.NewExpression, this);\n case ts.SyntaxKind.PropertyAssignment:\n return visitor.propertyAssignment(tree as ts.PropertyAssignment, this);\n case ts.SyntaxKind.VariableStatement:\n return visitor.variableStatement(tree as ts.VariableStatement, this);\n case ts.SyntaxKind.VariableDeclarationList:\n return visitor.variableDeclarationList(tree as ts.VariableDeclarationList, this);\n case ts.SyntaxKind.VariableDeclaration:\n return visitor.variableDeclaration(tree as ts.VariableDeclaration, this);\n case ts.SyntaxKind.ArrayLiteralExpression:\n return visitor.arrayLiteralExpression(tree as ts.ArrayLiteralExpression, this);\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n return visitor.shorthandPropertyAssignment(tree as ts.ShorthandPropertyAssignment, this);\n case ts.SyntaxKind.ForOfStatement:\n return visitor.forOfStatement(tree as ts.ForOfStatement, this);\n case ts.SyntaxKind.ClassDeclaration:\n return visitor.classDeclaration(tree as ts.ClassDeclaration, this);\n case ts.SyntaxKind.Constructor:\n return visitor.constructorDeclaration(tree as ts.ConstructorDeclaration, this);\n case ts.SyntaxKind.PropertyDeclaration:\n return visitor.propertyDeclaration(tree as ts.PropertyDeclaration, this);\n case ts.SyntaxKind.ComputedPropertyName:\n return visitor.computedPropertyName((tree as ts.ComputedPropertyName).expression, this);\n case ts.SyntaxKind.MethodDeclaration:\n return visitor.methodDeclaration(tree as ts.MethodDeclaration, this);\n case ts.SyntaxKind.InterfaceDeclaration:\n return visitor.interfaceDeclaration(tree as ts.InterfaceDeclaration, this);\n case ts.SyntaxKind.PropertySignature:\n return visitor.propertySignature(tree as ts.PropertySignature, this);\n case ts.SyntaxKind.MethodSignature:\n return visitor.methodSignature(tree as ts.MethodSignature, this);\n case ts.SyntaxKind.AsExpression:\n return visitor.asExpression(tree as ts.AsExpression, this);\n case ts.SyntaxKind.PrefixUnaryExpression:\n return visitor.prefixUnaryExpression(tree as ts.PrefixUnaryExpression, this);\n case ts.SyntaxKind.SpreadAssignment:\n if (this.textOf(tree) === '...') {\n return visitor.ellipsis(tree as ts.SpreadAssignment, this);\n }\n return visitor.spreadAssignment(tree as ts.SpreadAssignment, this);\n case ts.SyntaxKind.SpreadElement:\n if (this.textOf(tree) === '...') {\n return visitor.ellipsis(tree as ts.SpreadElement, this);\n }\n return visitor.spreadElement(tree as ts.SpreadElement, this);\n case ts.SyntaxKind.ElementAccessExpression:\n return visitor.elementAccessExpression(tree as ts.ElementAccessExpression, this);\n case ts.SyntaxKind.TemplateExpression:\n return visitor.templateExpression(tree as ts.TemplateExpression, this);\n case ts.SyntaxKind.NonNullExpression:\n return visitor.nonNullExpression(tree as ts.NonNullExpression, this);\n case ts.SyntaxKind.ParenthesizedExpression:\n return visitor.parenthesizedExpression(tree as ts.ParenthesizedExpression, this);\n case ts.SyntaxKind.VoidExpression:\n return visitor.maskingVoidExpression(tree as ts.VoidExpression, this);\n case ts.SyntaxKind.JSDoc:\n case ts.SyntaxKind.JSDocComment:\n return visitor.jsDoc(tree as ts.JSDoc, this);\n default:\n if (ts.isToken(tree)) {\n return visitor.token(tree, this);\n }\n this.reportUnsupported(tree, undefined);\n }\n\n if (this.options.bestEffort !== false) {\n // When doing best-effort conversion and we don't understand the node type, just return the complete text of it as-is\n return new OTree([this.textOf(tree)]);\n }\n // Otherwise, show a placeholder indicating we don't recognize the type\n const nodeKind = ts.SyntaxKind[tree.kind];\n return new UnknownSyntax(\n [`<${nodeKind} ${this.textOf(tree)}>`],\n ['\\n', ...nodeChildren(tree).map(this.convert.bind(this))],\n {\n indent: 2,\n },\n );\n }\n\n /**\n * Attach any leading whitespace and comments to the given output tree\n *\n * Regardless of whether it's declared to be able to accept such or not.\n */\n private attachLeadingTrivia(node: ts.Node, transformed: OTree): OTree {\n // Add comments and leading whitespace\n const leadingRanges = scanText(this.sourceFile.text, node.getFullStart(), node.getStart(this.sourceFile));\n\n const precede: OTree[] = [];\n for (const range of leadingRanges) {\n let trivia: OTree | undefined = undefined;\n switch (range.type) {\n case 'other':\n trivia = new OTree([repeatNewlines(this.sourceFile.text.substring(range.pos, range.end))], [], {\n renderOnce: `ws-${range.pos}`,\n });\n break;\n case 'linecomment':\n case 'blockcomment':\n trivia = this.handler.commentRange(\n commentSyntaxFromCommentRange(commentRangeFromTextRange(range), this),\n this,\n );\n break;\n\n case 'directive':\n break;\n }\n if (trivia != null) {\n // Set spans on comments to make sure their visibility is toggled correctly.\n trivia.setSpan(range.pos, range.end);\n precede.push(trivia);\n }\n }\n\n // FIXME: No trailing comments for now, they're too tricky\n\n if (precede.length > 0 && !transformed.isEmpty) {\n return new OTree([...precede, transformed], [], { canBreakLine: true });\n }\n return transformed;\n }\n}\n\n/**\n * Interface for AST handlers\n *\n * C is the type of hierarchical context the handler uses. Context\n * needs 2 operations: a constructor for a default context, and a\n * merge operation to combine 2 contexts to yield a new one.\n *\n * Otherwise, the handler should return an OTree for every type\n * of AST node.\n */\nexport interface AstHandler<C> {\n readonly language: TargetLanguage;\n\n readonly defaultContext: C;\n readonly indentChar?: ' ' | '\\t';\n mergeContext(old: C, update: Partial<C>): C;\n\n sourceFile(node: ts.SourceFile, context: AstRenderer<C>): OTree;\n commentRange(node: CommentSyntax, context: AstRenderer<C>): OTree;\n importStatement(node: ImportStatement, context: AstRenderer<C>): OTree;\n stringLiteral(node: ts.StringLiteral | ts.NoSubstitutionTemplateLiteral, children: AstRenderer<C>): OTree;\n numericLiteral(node: ts.NumericLiteral, children: AstRenderer<C>): OTree;\n functionDeclaration(node: ts.FunctionDeclaration, children: AstRenderer<C>): OTree;\n identifier(node: ts.Identifier, children: AstRenderer<C>): OTree;\n block(node: ts.Block, children: AstRenderer<C>): OTree;\n parameterDeclaration(node: ts.ParameterDeclaration, children: AstRenderer<C>): OTree;\n returnStatement(node: ts.ReturnStatement, context: AstRenderer<C>): OTree;\n binaryExpression(node: ts.BinaryExpression, context: AstRenderer<C>): OTree;\n ifStatement(node: ts.IfStatement, context: AstRenderer<C>): OTree;\n propertyAccessExpression(\n node: ts.PropertyAccessExpression,\n context: AstRenderer<C>,\n submoduleReference: SubmoduleReference | undefined,\n ): OTree;\n awaitExpression(node: ts.AwaitExpression, context: AstRenderer<C>): OTree;\n callExpression(node: ts.CallExpression, context: AstRenderer<C>): OTree;\n expressionStatement(node: ts.ExpressionStatement, context: AstRenderer<C>): OTree;\n token<A extends ts.SyntaxKind>(node: ts.Token<A>, context: AstRenderer<C>): OTree;\n objectLiteralExpression(node: ts.ObjectLiteralExpression, context: AstRenderer<C>): OTree;\n newExpression(node: ts.NewExpression, context: AstRenderer<C>): OTree;\n propertyAssignment(node: ts.PropertyAssignment, context: AstRenderer<C>): OTree;\n variableStatement(node: ts.VariableStatement, context: AstRenderer<C>): OTree;\n variableDeclarationList(node: ts.VariableDeclarationList, context: AstRenderer<C>): OTree;\n variableDeclaration(node: ts.VariableDeclaration, context: AstRenderer<C>): OTree;\n jsDoc(node: ts.JSDoc, context: AstRenderer<C>): OTree;\n arrayLiteralExpression(node: ts.ArrayLiteralExpression, context: AstRenderer<C>): OTree;\n shorthandPropertyAssignment(node: ts.ShorthandPropertyAssignment, context: AstRenderer<C>): OTree;\n forOfStatement(node: ts.ForOfStatement, context: AstRenderer<C>): OTree;\n classDeclaration(node: ts.ClassDeclaration, context: AstRenderer<C>): OTree;\n constructorDeclaration(node: ts.ConstructorDeclaration, context: AstRenderer<C>): OTree;\n propertyDeclaration(node: ts.PropertyDeclaration, context: AstRenderer<C>): OTree;\n computedPropertyName(node: ts.Expression, context: AstRenderer<C>): OTree;\n methodDeclaration(node: ts.MethodDeclaration, context: AstRenderer<C>): OTree;\n interfaceDeclaration(node: ts.InterfaceDeclaration, context: AstRenderer<C>): OTree;\n propertySignature(node: ts.PropertySignature, context: AstRenderer<C>): OTree;\n methodSignature(node: ts.MethodSignature, context: AstRenderer<C>): OTree;\n asExpression(node: ts.AsExpression, context: AstRenderer<C>): OTree;\n prefixUnaryExpression(node: ts.PrefixUnaryExpression, context: AstRenderer<C>): OTree;\n spreadElement(node: ts.SpreadElement, context: AstRenderer<C>): OTree;\n spreadAssignment(node: ts.SpreadAssignment, context: AstRenderer<C>): OTree;\n templateExpression(node: ts.TemplateExpression, context: AstRenderer<C>): OTree;\n nonNullExpression(node: ts.NonNullExpression, context: AstRenderer<C>): OTree;\n parenthesizedExpression(node: ts.ParenthesizedExpression, context: AstRenderer<C>): OTree;\n maskingVoidExpression(node: ts.VoidExpression, context: AstRenderer<C>): OTree;\n elementAccessExpression(node: ts.ElementAccessExpression, context: AstRenderer<C>): OTree;\n\n // Not a node, called when we recognize a spread element/assignment that is only\n // '...' and nothing else.\n ellipsis(node: ts.SpreadElement | ts.SpreadAssignment, context: AstRenderer<C>): OTree;\n}\n\nexport function nimpl<C>(node: ts.Node, context: AstRenderer<C>, options: { additionalInfo?: string } = {}) {\n const children = nodeChildren(node).map((c) => context.convert(c));\n\n let syntaxKind = ts.SyntaxKind[node.kind];\n if (syntaxKind === 'FirstPunctuation') {\n // These have the same identifier but this name is more descriptive\n syntaxKind = 'OpenBraceToken';\n }\n\n const parts = [`(${syntaxKind}`];\n if (options.additionalInfo) {\n parts.push(`{${options.additionalInfo}}`);\n }\n parts.push(context.textOf(node));\n\n return new UnknownSyntax([parts.join(' ')], children.length > 0 ? ['\\n', ...children] : [], {\n indent: 2,\n suffix: ')',\n separator: '\\n',\n canBreakLine: true,\n });\n}\n\nexport interface AstRendererOptions {\n /**\n * If enabled, don't translate the text of unknown nodes\n *\n * @default true\n */\n bestEffort?: boolean;\n}\n\ninterface ClassifiedNode {\n node: ts.Node;\n visible: boolean;\n maskingVoid?: ts.VoidExpression;\n}\n\nfunction filterVisible(nodes: readonly ts.Node[]): ts.Node[] {\n return assignVisibility(nodes)\n .map((c) => (c.visible ? c.node : c.maskingVoid))\n .filter(notUndefined);\n}\n\nfunction assignVisibility(nodes: readonly ts.Node[]): ClassifiedNode[] {\n const ret: ClassifiedNode[] = [];\n\n let visible = true;\n for (const node of nodes) {\n const maskingVoid = extractMaskingVoidExpression(node);\n if (visible && maskingVoid) {\n visible = false;\n }\n\n ret.push({ node, maskingVoid, visible });\n\n if (!visible) {\n const showing = extractShowingVoidExpression(node);\n if (showing) {\n visible = true;\n }\n }\n }\n\n return ret;\n}\n\nfunction notUndefined<A>(x: A | undefined): x is A {\n return x !== undefined;\n}\n\n/**\n * Our own representation of comments\n *\n * (So we can synthesize 'em\n */\nexport interface CommentSyntax {\n pos: number;\n text: string;\n hasTrailingNewLine?: boolean;\n kind: ts.CommentKind;\n\n /**\n * Whether it's at the end of a code line (so we can render a separating space)\n */\n isTrailing?: boolean;\n}\n\nfunction commentSyntaxFromCommentRange(rng: ts.CommentRange, renderer: AstRenderer<any>): CommentSyntax {\n return {\n hasTrailingNewLine: rng.hasTrailingNewLine,\n kind: rng.kind,\n pos: rng.pos,\n text: renderer.textAt(rng.pos, rng.end),\n isTrailing: renderer.codeOnLineBefore(rng.pos),\n };\n}\n"]}
package/package.json CHANGED
@@ -59,9 +59,9 @@
59
59
  "memfs": "^4.11.1",
60
60
  "mock-fs": "^5.2.0",
61
61
  "prettier": "^2.8.8",
62
- "projen": "^0.85.2",
62
+ "projen": "^0.86.0",
63
63
  "tar": "^6.2.1",
64
- "ts-jest": "^29.2.4",
64
+ "ts-jest": "^29.2.5",
65
65
  "ts-node": "^10.9.2"
66
66
  },
67
67
  "dependencies": {
@@ -88,7 +88,7 @@
88
88
  "publishConfig": {
89
89
  "access": "public"
90
90
  },
91
- "version": "5.4.32-dev.3",
91
+ "version": "5.4.32-dev.4",
92
92
  "types": "lib/index.d.ts",
93
93
  "exports": {
94
94
  ".": "./lib/index.js",
package/releases.json CHANGED
@@ -5,7 +5,8 @@
5
5
  "5.0": "2024-01-31T00:00:00.000Z",
6
6
  "5.1": "2024-04-30T00:00:00.000Z",
7
7
  "5.2": "2024-06-30T00:00:00.000Z",
8
- "5.3": "2024-10-15T00:00:00.000Z"
8
+ "5.3": "2024-10-15T00:00:00.000Z",
9
+ "5.4": "2025-02-28T00:00:00.000Z"
9
10
  },
10
11
  "//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
11
12
  }