jsii-rosetta 5.4.32-dev.4 → 5.5.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/commands/convert.js +1 -2
  2. package/lib/commands/convert.js.map +1 -1
  3. package/lib/commands/coverage.js +1 -2
  4. package/lib/commands/coverage.js.map +1 -1
  5. package/lib/commands/extract.js +2 -3
  6. package/lib/commands/extract.js.map +1 -1
  7. package/lib/commands/infuse.js +2 -2
  8. package/lib/commands/infuse.js.map +1 -1
  9. package/lib/commands/read.js +1 -2
  10. package/lib/commands/read.js.map +1 -1
  11. package/lib/commands/transliterate.js +1 -2
  12. package/lib/commands/transliterate.js.map +1 -1
  13. package/lib/commands/trim-cache.js +1 -2
  14. package/lib/commands/trim-cache.js.map +1 -1
  15. package/lib/find-utils.js +4 -5
  16. package/lib/find-utils.js.map +1 -1
  17. package/lib/fixtures.js +1 -2
  18. package/lib/fixtures.js.map +1 -1
  19. package/lib/jsii/assemblies.js +9 -9
  20. package/lib/jsii/assemblies.js.map +1 -1
  21. package/lib/jsii/jsii-types.js +2 -3
  22. package/lib/jsii/jsii-types.js.map +1 -1
  23. package/lib/jsii/jsii-utils.js +15 -16
  24. package/lib/jsii/jsii-utils.js.map +1 -1
  25. package/lib/jsii/packages.js +1 -2
  26. package/lib/jsii/packages.js.map +1 -1
  27. package/lib/json.d.ts +0 -2
  28. package/lib/json.js +2 -3
  29. package/lib/json.js.map +1 -1
  30. package/lib/languages/target-language.js +3 -3
  31. package/lib/languages/target-language.js.map +1 -1
  32. package/lib/logging.js +6 -6
  33. package/lib/logging.js.map +1 -1
  34. package/lib/markdown/escapes.js +2 -3
  35. package/lib/markdown/escapes.js.map +1 -1
  36. package/lib/markdown/extract-snippets.js +1 -2
  37. package/lib/markdown/extract-snippets.js.map +1 -1
  38. package/lib/markdown/index.js +3 -4
  39. package/lib/markdown/index.js.map +1 -1
  40. package/lib/markdown/markdown-renderer.js +5 -5
  41. package/lib/markdown/markdown-renderer.js.map +1 -1
  42. package/lib/markdown/markdown.js +5 -6
  43. package/lib/markdown/markdown.js.map +1 -1
  44. package/lib/o-tree.js +2 -2
  45. package/lib/o-tree.js.map +1 -1
  46. package/lib/renderer.js +2 -2
  47. package/lib/renderer.js.map +1 -1
  48. package/lib/rosetta-reader.d.ts +0 -1
  49. package/lib/snippet-dependencies.js +5 -6
  50. package/lib/snippet-dependencies.js.map +1 -1
  51. package/lib/snippet-selectors.js +4 -5
  52. package/lib/snippet-selectors.js.map +1 -1
  53. package/lib/snippet.js +11 -11
  54. package/lib/snippet.js.map +1 -1
  55. package/lib/strict.js +1 -2
  56. package/lib/strict.js.map +1 -1
  57. package/lib/support.js +1 -2
  58. package/lib/support.js.map +1 -1
  59. package/lib/tablets/key.js +1 -2
  60. package/lib/tablets/key.js.map +1 -1
  61. package/lib/translate.js +4 -4
  62. package/lib/translate.js.map +1 -1
  63. package/lib/translate_all.js +1 -2
  64. package/lib/translate_all.js.map +1 -1
  65. package/lib/translate_all_worker.js +1 -2
  66. package/lib/translate_all_worker.js.map +1 -1
  67. package/lib/typescript/ast-utils.d.ts +1 -1
  68. package/lib/typescript/ast-utils.js +23 -23
  69. package/lib/typescript/ast-utils.js.map +1 -1
  70. package/lib/typescript/imports.d.ts +2 -2
  71. package/lib/typescript/imports.js +2 -3
  72. package/lib/typescript/imports.js.map +1 -1
  73. package/lib/typescript/types.js +16 -17
  74. package/lib/typescript/types.js.map +1 -1
  75. package/lib/typescript/visible-spans.js +4 -4
  76. package/lib/typescript/visible-spans.js.map +1 -1
  77. package/lib/util.d.ts +0 -1
  78. package/lib/util.js +19 -19
  79. package/lib/util.js.map +1 -1
  80. package/package.json +3 -3
  81. package/releases.json +2 -2
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeJavaEscaper = exports.makeXmlEscaper = void 0;
3
+ exports.makeXmlEscaper = makeXmlEscaper;
4
+ exports.makeJavaEscaper = makeJavaEscaper;
4
5
  /**
5
6
  * Make a generic XML escaper
6
7
  */
@@ -12,7 +13,6 @@ function makeXmlEscaper() {
12
13
  text2attr: (x) => escapeText(ATTR_ADDL, x),
13
14
  };
14
15
  }
15
- exports.makeXmlEscaper = makeXmlEscaper;
16
16
  /**
17
17
  * Make a Java specific escaper
18
18
  *
@@ -28,7 +28,6 @@ function makeJavaEscaper() {
28
28
  text2attr: (x) => escapeText(ATTR_ADDL, x),
29
29
  };
30
30
  }
31
- exports.makeJavaEscaper = makeJavaEscaper;
32
31
  const TEXT = [
33
32
  [new RegExp('&', 'g'), '&'],
34
33
  [new RegExp('<', 'g'), '&lt;'],
@@ -1 +1 @@
1
- {"version":3,"file":"escapes.js","sourceRoot":"","sources":["../../src/markdown/escapes.ts"],"names":[],"mappings":";;;AAoBA;;GAEG;AACH,SAAgB,cAAc;IAC5B,MAAM,IAAI,GAAY,CAAC,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAChC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACrC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;KAC3C,CAAC;AACJ,CAAC;AARD,wCAQC;AAED;;;;;GAKG;AACH,SAAgB,eAAe;IAC7B,MAAM,QAAQ,GAAY,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAY,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;KAC3C,CAAC;AACJ,CAAC;AATD,0CASC;AAID,MAAM,IAAI,GAAY;IACpB,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAC/B,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAC9B,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,mGAAmG;AACnG,MAAM,SAAS,GAAY;IACzB,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC;IAChC,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC;CACjC,CAAC;AAEF,SAAS,UAAU,CAAC,GAAY,EAAE,IAAmB;IACnD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["export interface Escaper {\n /**\n * Escape for use in XML/HTML text\n */\n text(x: string | null): string;\n\n /**\n * Escape for use in XML/HTML attributes\n */\n attribute(x: string | null): string;\n\n /**\n * Re-escape a string that has been escaped for text to be escaped for attributes\n *\n * Conceptually this unescapes text back to raw and re-escapes for attributes,\n * but for speed in practice we just do the additional escapes.\n */\n text2attr(x: string | null): string;\n}\n\n/**\n * Make a generic XML escaper\n */\nexport function makeXmlEscaper(): Escaper {\n const attr: Escapes = [...TEXT, ...ATTR_ADDL];\n\n return {\n text: (x) => escapeText(TEXT, x),\n attribute: (x) => escapeText(attr, x),\n text2attr: (x) => escapeText(ATTR_ADDL, x),\n };\n}\n\n/**\n * Make a Java specific escaper\n *\n * This one also escapes '@' because that triggers parsing of comment directives\n * in Java.\n */\nexport function makeJavaEscaper(): Escaper {\n const javaText: Escapes = [...TEXT, [new RegExp('@', 'g'), '&#64;']];\n const javaAttr: Escapes = [...javaText, ...ATTR_ADDL];\n\n return {\n text: (x) => escapeText(javaText, x),\n attribute: (x) => escapeText(javaAttr, x),\n text2attr: (x) => escapeText(ATTR_ADDL, x),\n };\n}\n\ntype Escapes = Array<[RegExp, string]>;\n\nconst TEXT: Escapes = [\n [new RegExp('&', 'g'), '&amp;'],\n [new RegExp('<', 'g'), '&lt;'],\n [new RegExp('>', 'g'), '&gt;'],\n];\n\n// Additional escapes (in addition to the text escapes) which need to be escaped inside attributes.\nconst ATTR_ADDL: Escapes = [\n [new RegExp('\"', 'g'), '&quot;'],\n [new RegExp(\"'\", 'g'), '&apos;'],\n];\n\nfunction escapeText(set: Escapes, what: string | null): string {\n if (!what) {\n return '';\n }\n\n for (const [re, repl] of set) {\n what = what.replace(re, repl);\n }\n\n return what;\n}\n"]}
1
+ {"version":3,"file":"escapes.js","sourceRoot":"","sources":["../../src/markdown/escapes.ts"],"names":[],"mappings":";;AAuBA,wCAQC;AAQD,0CASC;AA5BD;;GAEG;AACH,SAAgB,cAAc;IAC5B,MAAM,IAAI,GAAY,CAAC,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAChC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;Q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,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["export interface Escaper {\n /**\n * Escape for use in XML/HTML text\n */\n text(x: string | null): string;\n\n /**\n * Escape for use in XML/HTML attributes\n */\n attribute(x: string | null): string;\n\n /**\n * Re-escape a string that has been escaped for text to be escaped for attributes\n *\n * Conceptually this unescapes text back to raw and re-escapes for attributes,\n * but for speed in practice we just do the additional escapes.\n */\n text2attr(x: string | null): string;\n}\n\n/**\n * Make a generic XML escaper\n */\nexport function makeXmlEscaper(): Escaper {\n const attr: Escapes = [...TEXT, ...ATTR_ADDL];\n\n return {\n text: (x) => escapeText(TEXT, x),\n attribute: (x) => escapeText(attr, x),\n text2attr: (x) => escapeText(ATTR_ADDL, x),\n };\n}\n\n/**\n * Make a Java specific escaper\n *\n * This one also escapes '@' because that triggers parsing of comment directives\n * in Java.\n */\nexport function makeJavaEscaper(): Escaper {\n const javaText: Escapes = [...TEXT, [new RegExp('@', 'g'), '&#64;']];\n const javaAttr: Escapes = [...javaText, ...ATTR_ADDL];\n\n return {\n text: (x) => escapeText(javaText, x),\n attribute: (x) => escapeText(javaAttr, x),\n text2attr: (x) => escapeText(ATTR_ADDL, x),\n };\n}\n\ntype Escapes = Array<[RegExp, string]>;\n\nconst TEXT: Escapes = [\n [new RegExp('&', 'g'), '&amp;'],\n [new RegExp('<', 'g'), '&lt;'],\n [new RegExp('>', 'g'), '&gt;'],\n];\n\n// Additional escapes (in addition to the text escapes) which need to be escaped inside attributes.\nconst ATTR_ADDL: Escapes = [\n [new RegExp('\"', 'g'), '&quot;'],\n [new RegExp(\"'\", 'g'), '&apos;'],\n];\n\nfunction escapeText(set: Escapes, what: string | null): string {\n if (!what) {\n return '';\n }\n\n for (const [re, repl] of set) {\n what = what.replace(re, repl);\n }\n\n return what;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractTypescriptSnippetsFromMarkdown = void 0;
3
+ exports.extractTypescriptSnippetsFromMarkdown = extractTypescriptSnippetsFromMarkdown;
4
4
  const cm = require("commonmark");
5
5
  const replace_typescript_transform_1 = require("./replace-typescript-transform");
6
6
  const markdown_1 = require("../markdown/markdown");
@@ -14,5 +14,4 @@ function extractTypescriptSnippetsFromMarkdown(markdown, location, strict) {
14
14
  }));
15
15
  return ret;
16
16
  }
17
- exports.extractTypescriptSnippetsFromMarkdown = extractTypescriptSnippetsFromMarkdown;
18
17
  //# sourceMappingURL=extract-snippets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-snippets.js","sourceRoot":"","sources":["../../src/markdown/extract-snippets.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,iFAA4E;AAE5E,mDAA2D;AAK3D,SAAgB,qCAAqC,CACnD,QAAgB,EAChB,QAAqB,EACrB,MAAe;IAEf,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnC,MAAM,GAAG,GAAwB,EAAE,CAAC;IAEpC,IAAA,8BAAmB,EACjB,GAAG,EACH,IAAI,yDAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE;QACtD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAnBD,sFAmBC","sourcesContent":["import * as cm from 'commonmark';\n\nimport { ReplaceTypeScriptTransform } from './replace-typescript-transform';\nimport { CodeBlock } from './types';\nimport { visitCommonMarkTree } from '../markdown/markdown';\nimport { TypeScriptSnippet, ApiLocation } from '../snippet';\n\nexport type TypeScriptReplacer = (code: TypeScriptSnippet) => CodeBlock | undefined;\n\nexport function extractTypescriptSnippetsFromMarkdown(\n markdown: string,\n location: ApiLocation,\n strict: boolean,\n): TypeScriptSnippet[] {\n const parser = new cm.Parser();\n const doc = parser.parse(markdown);\n\n const ret: TypeScriptSnippet[] = [];\n\n visitCommonMarkTree(\n doc,\n new ReplaceTypeScriptTransform(location, strict, (ts) => {\n ret.push(ts);\n return undefined;\n }),\n );\n\n return ret;\n}\n"]}
1
+ {"version":3,"file":"extract-snippets.js","sourceRoot":"","sources":["../../src/markdown/extract-snippets.ts"],"names":[],"mappings":";;AASA,sFAmBC;AA5BD,iCAAiC;AAEjC,iFAA4E;AAE5E,mDAA2D;AAK3D,SAAgB,qCAAqC,CACnD,QAAgB,EAChB,QAAqB,EACrB,MAAe;IAEf,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnC,MAAM,GAAG,GAAwB,EAAE,CAAC;IAEpC,IAAA,8BAAmB,EACjB,GAAG,EACH,IAAI,yDAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE;QACtD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import * as cm from 'commonmark';\n\nimport { ReplaceTypeScriptTransform } from './replace-typescript-transform';\nimport { CodeBlock } from './types';\nimport { visitCommonMarkTree } from '../markdown/markdown';\nimport { TypeScriptSnippet, ApiLocation } from '../snippet';\n\nexport type TypeScriptReplacer = (code: TypeScriptSnippet) => CodeBlock | undefined;\n\nexport function extractTypescriptSnippetsFromMarkdown(\n markdown: string,\n location: ApiLocation,\n strict: boolean,\n): TypeScriptSnippet[] {\n const parser = new cm.Parser();\n const doc = parser.parse(markdown);\n\n const ret: TypeScriptSnippet[] = [];\n\n visitCommonMarkTree(\n doc,\n new ReplaceTypeScriptTransform(location, strict, (ts) => {\n ret.push(ts);\n return undefined;\n }),\n );\n\n return ret;\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.markDownToXmlDoc = exports.markDownToJavaDoc = exports.markDownToStructure = void 0;
3
+ exports.markDownToStructure = markDownToStructure;
4
+ exports.markDownToJavaDoc = markDownToJavaDoc;
5
+ exports.markDownToXmlDoc = markDownToXmlDoc;
4
6
  const javadoc_renderer_1 = require("./javadoc-renderer");
5
7
  const markdown_1 = require("./markdown");
6
8
  const structure_renderer_1 = require("./structure-renderer");
@@ -16,13 +18,10 @@ const xml_comment_renderer_1 = require("./xml-comment-renderer");
16
18
  function markDownToStructure(source) {
17
19
  return (0, markdown_1.transformMarkdown)(source, new structure_renderer_1.StructureRenderer());
18
20
  }
19
- exports.markDownToStructure = markDownToStructure;
20
21
  function markDownToJavaDoc(source) {
21
22
  return (0, markdown_1.transformMarkdown)(source, new javadoc_renderer_1.JavaDocRenderer());
22
23
  }
23
- exports.markDownToJavaDoc = markDownToJavaDoc;
24
24
  function markDownToXmlDoc(source) {
25
25
  return (0, markdown_1.transformMarkdown)(source, new xml_comment_renderer_1.CSharpXmlCommentRenderer());
26
26
  }
27
- exports.markDownToXmlDoc = markDownToXmlDoc;
28
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,yCAA+C;AAC/C,6DAAyD;AACzD,iEAAkE;AAElE;;;;;;;GAOG;AAEH,SAAgB,mBAAmB,CAAC,MAAc;IAChD,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,sCAAiB,EAAE,CAAC,CAAC;AAC5D,CAAC;AAFD,kDAEC;AAED,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,kCAAe,EAAE,CAAC,CAAC;AAC1D,CAAC;AAFD,8CAEC;AAED,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,+CAAwB,EAAE,CAAC,CAAC;AACnE,CAAC;AAFD,4CAEC","sourcesContent":["import { JavaDocRenderer } from './javadoc-renderer';\nimport { transformMarkdown } from './markdown';\nimport { StructureRenderer } from './structure-renderer';\nimport { CSharpXmlCommentRenderer } from './xml-comment-renderer';\n\n/**\n * All the visitors in this module expose CommonMark types in their API\n *\n * We want to keep CommonMark as a private dependency (so we don't have to\n * mark it as peerDependency and can keep its @types in devDependencies),\n * so we re-expose the main functionality needed by pacmak as functions\n * that operate on basic types here.\n */\n\nexport function markDownToStructure(source: string) {\n return transformMarkdown(source, new StructureRenderer());\n}\n\nexport function markDownToJavaDoc(source: string) {\n return transformMarkdown(source, new JavaDocRenderer());\n}\n\nexport function markDownToXmlDoc(source: string) {\n return transformMarkdown(source, new CSharpXmlCommentRenderer());\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":";;AAcA,kDAEC;AAED,8CAEC;AAED,4CAEC;AAxBD,yDAAqD;AACrD,yCAA+C;AAC/C,6DAAyD;AACzD,iEAAkE;AAElE;;;;;;;GAOG;AAEH,SAAgB,mBAAmB,CAAC,MAAc;IAChD,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,sCAAiB,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,kCAAe,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAO,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,+CAAwB,EAAE,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { JavaDocRenderer } from './javadoc-renderer';\nimport { transformMarkdown } from './markdown';\nimport { StructureRenderer } from './structure-renderer';\nimport { CSharpXmlCommentRenderer } from './xml-comment-renderer';\n\n/**\n * All the visitors in this module expose CommonMark types in their API\n *\n * We want to keep CommonMark as a private dependency (so we don't have to\n * mark it as peerDependency and can keep its @types in devDependencies),\n * so we re-expose the main functionality needed by pacmak as functions\n * that operate on basic types here.\n */\n\nexport function markDownToStructure(source: string) {\n return transformMarkdown(source, new StructureRenderer());\n}\n\nexport function markDownToJavaDoc(source: string) {\n return transformMarkdown(source, new JavaDocRenderer());\n}\n\nexport function markDownToXmlDoc(source: string) {\n return transformMarkdown(source, new CSharpXmlCommentRenderer());\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripTrailingWhitespace = exports.stripPara = exports.collapsePara = exports.para = exports.MarkdownRenderer = void 0;
3
+ exports.MarkdownRenderer = void 0;
4
+ exports.para = para;
5
+ exports.collapsePara = collapsePara;
6
+ exports.stripPara = stripPara;
7
+ exports.stripTrailingWhitespace = stripTrailingWhitespace;
4
8
  const markdown_1 = require("./markdown");
5
9
  /**
6
10
  * A renderer that will render a CommonMark tree back to MarkDown
@@ -85,7 +89,6 @@ const PARA_BREAK = '\u001d';
85
89
  function para(x) {
86
90
  return `${PARA_BREAK}${x}${PARA_BREAK}`;
87
91
  }
88
- exports.para = para;
89
92
  /**
90
93
  * Collapse paragraph markers
91
94
  */
@@ -97,7 +100,6 @@ function collapsePara(x, brk = '\n\n') {
97
100
  .replace(/\u001d+/g, brk);
98
101
  /* eslint-enable no-control-regex */
99
102
  }
100
- exports.collapsePara = collapsePara;
101
103
  /**
102
104
  * Strip paragraph markers from start and end
103
105
  */
@@ -105,7 +107,6 @@ function stripPara(x) {
105
107
  /* eslint-disable-next-line no-control-regex */
106
108
  return x.replace(/^\u001d+/, '').replace(/\u001d+$/, '');
107
109
  }
108
- exports.stripPara = stripPara;
109
110
  function determineItemPrefix(listNode, index) {
110
111
  if (listNode.listType === 'bullet') {
111
112
  return '* ';
@@ -115,5 +116,4 @@ function determineItemPrefix(listNode, index) {
115
116
  function stripTrailingWhitespace(x) {
116
117
  return x.replace(/[ \t]+$/gm, '');
117
118
  }
118
- exports.stripTrailingWhitespace = stripTrailingWhitespace;
119
119
  //# sourceMappingURL=markdown-renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-renderer.js","sourceRoot":"","sources":["../../src/markdown/markdown-renderer.ts"],"names":[],"mappings":";;;AAEA,yCAA8F;AAE9F;;GAEG;AACH,MAAa,gBAAgB;IACpB,WAAW,CAAC,KAAc,EAAE,OAAwB;QACzD,OAAO,IAAI,CAAC,IAAA,sBAAW,EAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,IAAI,CAAC,IAAa,EAAE,QAAyB;QAClD,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,CAAC;IAC/B,CAAC;IAEM,UAAU,CAAC,IAAa,EAAE,QAAyB;QACxD,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC;IACjE,CAAC;IAEM,IAAI,CAAC,IAAa,EAAE,QAAyB;QAClD,OAAO,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAC5B,CAAC;IAEM,SAAS,CAAC,KAAc,EAAE,QAAyB;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,SAAS,CAAC,KAAc,EAAE,QAAyB;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,IAAI,CAAC,KAAc,EAAE,OAAwB;QAClD,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAA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EAAE,CAAC;SACvB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC5B,oCAAoC;AACtC,CAAC;AAPD,oCAOC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,CAAS;IACjC,+CAA+C;IAC/C,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC3D,CAAC;AAHD,8BAGC;AAED,SAAS,mBAAmB,CAAC,QAAiB,EAAE,KAAa;IAC3D,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC,aAAa,GAAG,CAAC;AAC9C,CAAC;AAED,SAAgB,uBAAuB,CAAC,CAAS;IAC/C,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC;AAFD,0DAEC","sourcesContent":["import * as cm from 'commonmark';\n\nimport { cmNodeChildren, CommonMarkRenderer, prefixLines, RendererContext } from './markdown';\n\n/**\n * A renderer that will render a CommonMark tree back to MarkDown\n */\nexport class MarkdownRenderer implements CommonMarkRenderer {\n public block_quote(_node: cm.Node, context: RendererContext) {\n return para(prefixLines('> ', collapsePara(context.content())));\n }\n\n public code(node: cm.Node, _context: RendererContext) {\n return `\\`${node.literal}\\``;\n }\n\n public code_block(node: cm.Node, _context: RendererContext) {\n return para(`\\`\\`\\`${node.info ?? ''}\\n${node.literal}\\`\\`\\``);\n }\n\n public text(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public softbreak(_node: cm.Node, _context: RendererContext) {\n return '\\n';\n }\n\n public linebreak(_node: cm.Node, _context: RendererContext) {\n return '\\\\\\n';\n }\n\n public emph(_node: cm.Node, context: RendererContext) {\n return `*${context.content()}*`;\n }\n\n public strong(_node: cm.Node, context: RendererContext) {\n return `**${context.content()}**`;\n }\n\n public html_inline(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public html_block(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public link(node: cm.Node, context: RendererContext) {\n return `[${context.content()}](${node.destination ?? ''})`;\n }\n\n public image(node: cm.Node, context: RendererContext) {\n return `![${context.content()}](${node.destination ?? ''})`;\n }\n\n public document(_node: cm.Node, context: RendererContext) {\n return stripTrailingWhitespace(collapsePara(context.content()));\n }\n\n public paragraph(_node: cm.Node, context: RendererContext) {\n return para(context.content());\n }\n\n public list(node: cm.Node, context: RendererContext) {\n // A list is not wrapped in a paragraph, but items may contain paragraphs.\n // All elements of a list are definitely 'item's.\n const items = [];\n\n let i = 1;\n for (const item of cmNodeChildren(node)) {\n const firstLinePrefix = determineItemPrefix(node, i);\n const hangingPrefix = ' '.repeat(firstLinePrefix.length);\n\n const rendered = context.recurse(item);\n // Prefix the first line with a different text than subsequent lines\n const prefixed = firstLinePrefix + prefixLines(hangingPrefix, rendered).slice(hangingPrefix.length);\n\n items.push(prefixed);\n\n i += 1;\n }\n\n return para(items.join('\\n'));\n }\n\n public item(_node: cm.Node, context: RendererContext) {\n return collapsePara(context.content());\n }\n\n public heading(node: cm.Node, context: RendererContext) {\n return para(`${'#'.repeat(node.level)} ${context.content()}`);\n }\n\n public thematic_break(_node: cm.Node, _context: RendererContext) {\n return '---\\n';\n }\n\n public custom_block(_node: cm.Node, context: RendererContext) {\n return `<custom>${context.content()}</custom>`;\n }\n\n public custom_inline(_node: cm.Node, context: RendererContext) {\n return `<custom>${context.content()}</custom>`;\n }\n}\n\nconst PARA_BREAK = '\\u001d';\n\nexport function para(x: string) {\n return `${PARA_BREAK}${x}${PARA_BREAK}`;\n}\n\n/**\n * Collapse paragraph markers\n */\nexport function collapsePara(x: string, brk = '\\n\\n') {\n /* eslint-disable no-control-regex */\n return x\n .replace(/^\\u001d+/, '')\n .replace(/\\u001d+$/, '')\n .replace(/\\u001d+/g, brk);\n /* eslint-enable no-control-regex */\n}\n\n/**\n * Strip paragraph markers from start and end\n */\nexport function stripPara(x: string) {\n /* eslint-disable-next-line no-control-regex */\n return x.replace(/^\\u001d+/, '').replace(/\\u001d+$/, '');\n}\n\nfunction determineItemPrefix(listNode: cm.Node, index: number) {\n if (listNode.listType === 'bullet') {\n return '* ';\n }\n return `${index}${listNode.listDelimiter} `;\n}\n\nexport function stripTrailingWhitespace(x: string) {\n return x.replace(/[ \\t]+$/gm, '');\n}\n"]}
1
+ {"version":3,"file":"markdown-renderer.js","sourceRoot":"","sources":["../../src/markdown/markdown-renderer.ts"],"names":[],"mappings":";;;AA6GA,oBAEC;AAKD,oCAOC;AAKD,8BAGC;AASD,0DAEC;AA5ID,yCAA8F;AAE9F;;GAEG;AACH,MAAa,gBAAgB;IACpB,WAAW,CAAC,KAAc,EAAE,OAAwB;QACzD,OAAO,IAAI,CAAC,IAAA,sBAAW,EAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,IAAI,CAAC,IAAa,EAAE,QAAyB;QAClD,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,CAAC;IAC/B,CAAC;IAEM,UAAU,CAAC,IAAa,EAAE,QAAyB;QACxD,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC;IACjE,CAAC;IAEM,IAAI,CAAC,IAAa,EAAE,QAAyB;QAClD,OAAO,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAC5B,CAAC;IAEM,SAAS,CAAC,KAAc,EAAE,QAAyB;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,SAAS,CAAC,KAAc,EAAE,QAAyB;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,IAAI,CAAC,KAAc,EAAE,OAAwB;QAClD,OAAO,IAAI,OAAO,CAAC,OAAO,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E,CAAC;SACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC5B,oCAAoC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,CAAS;IACjC,+CAA+C;IAC/C,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAiB,EAAE,KAAa;IAC3D,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC,aAAa,GAAG,CAAC;AAC9C,CAAC;AAED,SAAgB,uBAAuB,CAAC,CAAS;IAC/C,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import * as cm from 'commonmark';\n\nimport { cmNodeChildren, CommonMarkRenderer, prefixLines, RendererContext } from './markdown';\n\n/**\n * A renderer that will render a CommonMark tree back to MarkDown\n */\nexport class MarkdownRenderer implements CommonMarkRenderer {\n public block_quote(_node: cm.Node, context: RendererContext) {\n return para(prefixLines('> ', collapsePara(context.content())));\n }\n\n public code(node: cm.Node, _context: RendererContext) {\n return `\\`${node.literal}\\``;\n }\n\n public code_block(node: cm.Node, _context: RendererContext) {\n return para(`\\`\\`\\`${node.info ?? ''}\\n${node.literal}\\`\\`\\``);\n }\n\n public text(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public softbreak(_node: cm.Node, _context: RendererContext) {\n return '\\n';\n }\n\n public linebreak(_node: cm.Node, _context: RendererContext) {\n return '\\\\\\n';\n }\n\n public emph(_node: cm.Node, context: RendererContext) {\n return `*${context.content()}*`;\n }\n\n public strong(_node: cm.Node, context: RendererContext) {\n return `**${context.content()}**`;\n }\n\n public html_inline(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public html_block(node: cm.Node, _context: RendererContext) {\n return node.literal ?? '';\n }\n\n public link(node: cm.Node, context: RendererContext) {\n return `[${context.content()}](${node.destination ?? ''})`;\n }\n\n public image(node: cm.Node, context: RendererContext) {\n return `![${context.content()}](${node.destination ?? ''})`;\n }\n\n public document(_node: cm.Node, context: RendererContext) {\n return stripTrailingWhitespace(collapsePara(context.content()));\n }\n\n public paragraph(_node: cm.Node, context: RendererContext) {\n return para(context.content());\n }\n\n public list(node: cm.Node, context: RendererContext) {\n // A list is not wrapped in a paragraph, but items may contain paragraphs.\n // All elements of a list are definitely 'item's.\n const items = [];\n\n let i = 1;\n for (const item of cmNodeChildren(node)) {\n const firstLinePrefix = determineItemPrefix(node, i);\n const hangingPrefix = ' '.repeat(firstLinePrefix.length);\n\n const rendered = context.recurse(item);\n // Prefix the first line with a different text than subsequent lines\n const prefixed = firstLinePrefix + prefixLines(hangingPrefix, rendered).slice(hangingPrefix.length);\n\n items.push(prefixed);\n\n i += 1;\n }\n\n return para(items.join('\\n'));\n }\n\n public item(_node: cm.Node, context: RendererContext) {\n return collapsePara(context.content());\n }\n\n public heading(node: cm.Node, context: RendererContext) {\n return para(`${'#'.repeat(node.level)} ${context.content()}`);\n }\n\n public thematic_break(_node: cm.Node, _context: RendererContext) {\n return '---\\n';\n }\n\n public custom_block(_node: cm.Node, context: RendererContext) {\n return `<custom>${context.content()}</custom>`;\n }\n\n public custom_inline(_node: cm.Node, context: RendererContext) {\n return `<custom>${context.content()}</custom>`;\n }\n}\n\nconst PARA_BREAK = '\\u001d';\n\nexport function para(x: string) {\n return `${PARA_BREAK}${x}${PARA_BREAK}`;\n}\n\n/**\n * Collapse paragraph markers\n */\nexport function collapsePara(x: string, brk = '\\n\\n') {\n /* eslint-disable no-control-regex */\n return x\n .replace(/^\\u001d+/, '')\n .replace(/\\u001d+$/, '')\n .replace(/\\u001d+/g, brk);\n /* eslint-enable no-control-regex */\n}\n\n/**\n * Strip paragraph markers from start and end\n */\nexport function stripPara(x: string) {\n /* eslint-disable-next-line no-control-regex */\n return x.replace(/^\\u001d+/, '').replace(/\\u001d+$/, '');\n}\n\nfunction determineItemPrefix(listNode: cm.Node, index: number) {\n if (listNode.listType === 'bullet') {\n return '* ';\n }\n return `${index}${listNode.listDelimiter} `;\n}\n\nexport function stripTrailingWhitespace(x: string) {\n return x.replace(/[ \\t]+$/gm, '');\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cmNodeChildren = exports.prefixLines = exports.visitCommonMarkTree = exports.renderCommonMarkTree = exports.transformMarkdown = void 0;
3
+ exports.transformMarkdown = transformMarkdown;
4
+ exports.renderCommonMarkTree = renderCommonMarkTree;
5
+ exports.visitCommonMarkTree = visitCommonMarkTree;
6
+ exports.prefixLines = prefixLines;
7
+ exports.cmNodeChildren = cmNodeChildren;
4
8
  const cm = require("commonmark");
5
9
  function transformMarkdown(source, renderer, transform) {
6
10
  const parser = new cm.Parser();
@@ -10,7 +14,6 @@ function transformMarkdown(source, renderer, transform) {
10
14
  }
11
15
  return renderCommonMarkTree(doc, renderer);
12
16
  }
13
- exports.transformMarkdown = transformMarkdown;
14
17
  function renderCommonMarkTree(node, renderer) {
15
18
  const context = {
16
19
  recurse(n) {
@@ -29,25 +32,21 @@ function renderCommonMarkTree(node, renderer) {
29
32
  };
30
33
  return renderer[node.type](node, context);
31
34
  }
32
- exports.renderCommonMarkTree = renderCommonMarkTree;
33
35
  function visitCommonMarkTree(node, visitor) {
34
36
  visitor[node.type](node);
35
37
  for (const child of cmNodeChildren(node)) {
36
38
  visitCommonMarkTree(child, visitor);
37
39
  }
38
40
  }
39
- exports.visitCommonMarkTree = visitCommonMarkTree;
40
41
  function prefixLines(prefix, x) {
41
42
  return x
42
43
  .split('\n')
43
44
  .map((l) => prefix + l)
44
45
  .join('\n');
45
46
  }
46
- exports.prefixLines = prefixLines;
47
47
  function* cmNodeChildren(node) {
48
48
  for (let child = node.firstChild; child !== null; child = child.next) {
49
49
  yield child;
50
50
  }
51
51
  }
52
- exports.cmNodeChildren = cmNodeChildren;
53
52
  //# sourceMappingURL=markdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/markdown/markdown.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,SAAgB,iBAAiB,CAAC,MAAc,EAAE,QAA4B,EAAE,SAA6B;IAC3G,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAPD,8CAOC;AA+BD,SAAgB,oBAAoB,CAAC,IAAa,EAAE,QAA4B;IAC9E,MAAM,OAAO,GAAoB;QAC/B,OAAO,CAAC,CAAU;YAChB,OAAO,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO;YACL,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClC,CAAC;QAED,QAAQ;YACN,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;YACpD,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AApBD,oDAoBC;AAED,SAAgB,mBAAmB,CAAC,IAAa,EAAE,OAA0B;IAC3E,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AALD,kDAKC;AAED,SAAgB,WAAW,CAAC,MAAc,EAAE,CAAS;IACnD,OAAO,CAAC;SACL,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;SACtB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AALD,kCAKC;AAED,QAAe,CAAC,CAAC,cAAc,CAAC,IAAa;IAC3C,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAJD,wCAIC","sourcesContent":["import * as cm from 'commonmark';\n\nexport function transformMarkdown(source: string, renderer: CommonMarkRenderer, transform?: CommonMarkVisitor) {\n const parser = new cm.Parser();\n const doc = parser.parse(source);\n if (transform) {\n visitCommonMarkTree(doc, transform);\n }\n return renderCommonMarkTree(doc, renderer);\n}\n\nexport interface RendererContext {\n recurse(node: cm.Node): string;\n children(): string[];\n content(): string;\n}\n\nexport interface CommonMarkRenderer {\n block_quote(node: cm.Node, context: RendererContext): string;\n code(node: cm.Node, context: RendererContext): string;\n code_block(node: cm.Node, context: RendererContext): string;\n text(node: cm.Node, context: RendererContext): string;\n softbreak(node: cm.Node, context: RendererContext): string;\n linebreak(node: cm.Node, context: RendererContext): string;\n emph(node: cm.Node, context: RendererContext): string;\n strong(node: cm.Node, context: RendererContext): string;\n html_inline(node: cm.Node, context: RendererContext): string;\n html_block(node: cm.Node, context: RendererContext): string;\n link(node: cm.Node, context: RendererContext): string;\n image(node: cm.Node, context: RendererContext): string;\n document(node: cm.Node, context: RendererContext): string;\n paragraph(node: cm.Node, context: RendererContext): string;\n list(node: cm.Node, context: RendererContext): string;\n item(node: cm.Node, context: RendererContext): string;\n heading(node: cm.Node, context: RendererContext): string;\n thematic_break(node: cm.Node, context: RendererContext): string;\n custom_block(node: cm.Node, context: RendererContext): string;\n custom_inline(node: cm.Node, context: RendererContext): string;\n}\n\nexport function renderCommonMarkTree(node: cm.Node, renderer: CommonMarkRenderer) {\n const context: RendererContext = {\n recurse(n: cm.Node): string {\n return renderCommonMarkTree(n, renderer);\n },\n\n content() {\n return this.children().join('');\n },\n\n children() {\n const parts = [];\n for (const child of cmNodeChildren(node)) {\n parts.push(renderCommonMarkTree(child, renderer));\n }\n return parts;\n },\n };\n\n return renderer[node.type](node, context);\n}\n\nexport function visitCommonMarkTree(node: cm.Node, visitor: CommonMarkVisitor) {\n visitor[node.type](node);\n for (const child of cmNodeChildren(node)) {\n visitCommonMarkTree(child, visitor);\n }\n}\n\nexport function prefixLines(prefix: string, x: string) {\n return x\n .split('\\n')\n .map((l) => prefix + l)\n .join('\\n');\n}\n\nexport function* cmNodeChildren(node: cm.Node): IterableIterator<cm.Node> {\n for (let child = node.firstChild; child !== null; child = child.next) {\n yield child;\n }\n}\n\nexport interface CommonMarkVisitor {\n block_quote(node: cm.Node): void;\n code(node: cm.Node): void;\n code_block(node: cm.Node): void;\n text(node: cm.Node): void;\n softbreak(node: cm.Node): void;\n linebreak(node: cm.Node): void;\n emph(node: cm.Node): void;\n strong(node: cm.Node): void;\n html_inline(node: cm.Node): void;\n html_block(node: cm.Node): void;\n link(node: cm.Node): void;\n image(node: cm.Node): void;\n document(node: cm.Node): void;\n paragraph(node: cm.Node): void;\n list(node: cm.Node): void;\n item(node: cm.Node): void;\n heading(node: cm.Node): void;\n thematic_break(node: cm.Node): void;\n custom_block(node: cm.Node): void;\n custom_inline(node: cm.Node): void;\n}\n"]}
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/markdown/markdown.ts"],"names":[],"mappings":";;AAEA,8CAOC;AA+BD,oDAoBC;AAED,kDAKC;AAED,kCAKC;AAED,wCAIC;AAhFD,iCAAiC;AAEjC,SAAgB,iBAAiB,CAAC,MAAc,EAAE,QAA4B,EAAE,SAA6B;IAC3G,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AA+BD,SAAgB,oBAAoB,CAAC,IAAa,EAAE,QAA4B;IAC9E,MAAM,OAAO,GAAoB;QAC/B,OAAO,CAAC,CAAU;YAChB,OAAO,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO;YACL,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClC,CAAC;QAED,QAAQ;YACN,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;YACpD,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAa,EAAE,OAA0B;IAC3E,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAgB,WAAW,CAAC,MAAc,EAAE,CAAS;IACnD,OAAO,CAAC;SACL,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;SACtB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,QAAe,CAAC,CAAC,cAAc,CAAC,IAAa;IAC3C,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import * as cm from 'commonmark';\n\nexport function transformMarkdown(source: string, renderer: CommonMarkRenderer, transform?: CommonMarkVisitor) {\n const parser = new cm.Parser();\n const doc = parser.parse(source);\n if (transform) {\n visitCommonMarkTree(doc, transform);\n }\n return renderCommonMarkTree(doc, renderer);\n}\n\nexport interface RendererContext {\n recurse(node: cm.Node): string;\n children(): string[];\n content(): string;\n}\n\nexport interface CommonMarkRenderer {\n block_quote(node: cm.Node, context: RendererContext): string;\n code(node: cm.Node, context: RendererContext): string;\n code_block(node: cm.Node, context: RendererContext): string;\n text(node: cm.Node, context: RendererContext): string;\n softbreak(node: cm.Node, context: RendererContext): string;\n linebreak(node: cm.Node, context: RendererContext): string;\n emph(node: cm.Node, context: RendererContext): string;\n strong(node: cm.Node, context: RendererContext): string;\n html_inline(node: cm.Node, context: RendererContext): string;\n html_block(node: cm.Node, context: RendererContext): string;\n link(node: cm.Node, context: RendererContext): string;\n image(node: cm.Node, context: RendererContext): string;\n document(node: cm.Node, context: RendererContext): string;\n paragraph(node: cm.Node, context: RendererContext): string;\n list(node: cm.Node, context: RendererContext): string;\n item(node: cm.Node, context: RendererContext): string;\n heading(node: cm.Node, context: RendererContext): string;\n thematic_break(node: cm.Node, context: RendererContext): string;\n custom_block(node: cm.Node, context: RendererContext): string;\n custom_inline(node: cm.Node, context: RendererContext): string;\n}\n\nexport function renderCommonMarkTree(node: cm.Node, renderer: CommonMarkRenderer) {\n const context: RendererContext = {\n recurse(n: cm.Node): string {\n return renderCommonMarkTree(n, renderer);\n },\n\n content() {\n return this.children().join('');\n },\n\n children() {\n const parts = [];\n for (const child of cmNodeChildren(node)) {\n parts.push(renderCommonMarkTree(child, renderer));\n }\n return parts;\n },\n };\n\n return renderer[node.type](node, context);\n}\n\nexport function visitCommonMarkTree(node: cm.Node, visitor: CommonMarkVisitor) {\n visitor[node.type](node);\n for (const child of cmNodeChildren(node)) {\n visitCommonMarkTree(child, visitor);\n }\n}\n\nexport function prefixLines(prefix: string, x: string) {\n return x\n .split('\\n')\n .map((l) => prefix + l)\n .join('\\n');\n}\n\nexport function* cmNodeChildren(node: cm.Node): IterableIterator<cm.Node> {\n for (let child = node.firstChild; child !== null; child = child.next) {\n yield child;\n }\n}\n\nexport interface CommonMarkVisitor {\n block_quote(node: cm.Node): void;\n code(node: cm.Node): void;\n code_block(node: cm.Node): void;\n text(node: cm.Node): void;\n softbreak(node: cm.Node): void;\n linebreak(node: cm.Node): void;\n emph(node: cm.Node): void;\n strong(node: cm.Node): void;\n html_inline(node: cm.Node): void;\n html_block(node: cm.Node): void;\n link(node: cm.Node): void;\n image(node: cm.Node): void;\n document(node: cm.Node): void;\n paragraph(node: cm.Node): void;\n list(node: cm.Node): void;\n item(node: cm.Node): void;\n heading(node: cm.Node): void;\n thematic_break(node: cm.Node): void;\n custom_block(node: cm.Node): void;\n custom_inline(node: cm.Node): void;\n}\n"]}
package/lib/o-tree.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderTree = exports.OTreeSink = exports.UnknownSyntax = exports.NO_SYNTAX = exports.OTree = void 0;
3
+ exports.OTreeSink = exports.UnknownSyntax = exports.NO_SYNTAX = exports.OTree = void 0;
4
+ exports.renderTree = renderTree;
4
5
  /**
5
6
  * "Output" Tree
6
7
  *
@@ -226,7 +227,6 @@ function renderTree(tree, options) {
226
227
  tree.write(sink);
227
228
  return sink.toString();
228
229
  }
229
- exports.renderTree = renderTree;
230
230
  function containsNewline(x) {
231
231
  return x.includes('\n');
232
232
  }
package/lib/o-tree.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"o-tree.js","sourceRoot":"","sources":["../src/o-tree.ts"],"names":[],"mappings":";;;AAuDA;;;;;GAKG;AACH,MAAa,KAAK;IACT,MAAM,CAAC,QAAQ,CAAC,EAAqC;QAC1D,OAAO,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAQD,YACE,MAAyC,EACzC,QAA4C,EAC3B,UAAwB,EAAE;QAA1B,YAAO,GAAP,OAAO,CAAmB;QAE3C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,KAAa,EAAE,GAAW;QACvC,IAAI,CAAC,IAAI,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,IAAe;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3C,OAAO;QACT,CAAC;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ACH,CAAC;IAED,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAzJD,8BAyJC;AAED,SAAS,YAAY,CAAI,CAAgB;IACvC,OAAO,CAAC,KAAK,SAAS,CAAC;AACzB,CAAC;AAED,SAAS,QAAQ,CAAC,CAAiB;IACjC,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AACpD,CAAC;AAED,SAAgB,UAAU,CAAC,IAAW,EAAE,OAA0B;IAChE,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC;AAJD,gCAIC;AAED,SAAS,eAAe,CAAC,CAAS;IAChC,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import { Spans } from './typescript/visible-spans';\n\nexport interface OTreeOptions {\n /**\n * Adjust indentation with the given number\n *\n * Indentation affects children.\n *\n * @default 0\n */\n indent?: number;\n\n /**\n * Separate children with the given string\n *\n * @default ''\n */\n separator?: string;\n\n /**\n * Whether trailing separators should be output. This imples children will be\n * writen each on a new line.\n *\n * @default false\n */\n trailingSeparator?: boolean;\n\n /**\n * Suffix the token after outdenting\n *\n * @default ''\n */\n suffix?: string;\n\n /**\n * Whether this part of the generated syntax is okay to insert newlines and comments\n *\n * @default false\n */\n canBreakLine?: boolean;\n\n /**\n * If set, a unique key which will cause only one node with the given key to be rendered.\n *\n * The outermost key is the one that will be rendered.\n *\n * Used to make it easier to keep the state necessary to render comments\n * only once in the output tree, rather than keep the state in the\n * language rendered.\n *\n * @default No conditional rendering\n */\n renderOnce?: string;\n}\n\n/**\n * \"Output\" Tree\n *\n * Tree-like structure that holds sequences of trees and strings, which\n * can be rendered to an output sink.\n */\nexport class OTree implements OTree {\n public static simplify(xs: Array<OTree | string | undefined>): Array<OTree | string> {\n return xs.filter(notUndefined).filter(notEmpty);\n }\n\n public readonly attachComment: boolean;\n\n private readonly prefix: Array<OTree | string>;\n private readonly children: Array<OTree | string>;\n private span?: Span;\n\n public constructor(\n prefix: Array<OTree | string | undefined>,\n children?: Array<OTree | string | undefined>,\n private readonly options: OTreeOptions = {},\n ) {\n this.prefix = OTree.simplify(prefix);\n this.children = OTree.simplify(children ?? []);\n this.attachComment = !!options.canBreakLine;\n }\n\n /**\n * Set the span in the source file this tree node relates to\n */\n public setSpan(start: number, end: number) {\n this.span = { start, end };\n }\n\n public write(sink: OTreeSink) {\n if (!sink.tagOnce(this.options.renderOnce)) {\n return;\n }\n\n const meVisible = sink.renderingForSpan(this.span);\n\n for (const x of this.prefix) {\n sink.write(x);\n }\n\n const popIndent = sink.requestIndentChange(meVisible ? this.options.indent ?? 0 : 0);\n let mark = sink.mark();\n\n for (const child of this.children ?? []) {\n if (this.options.separator) {\n if (this.options.trailingSeparator) {\n sink.ensureNewLine();\n } else if (mark.wroteNonWhitespaceSinceMark) {\n sink.write(this.options.separator);\n }\n }\n mark = sink.mark();\n\n sink.write(child);\n\n if (this.options.separator && this.options.trailingSeparator) {\n sink.write(this.options.separator.trimEnd());\n }\n }\n\n popIndent();\n\n if (this.options.suffix) {\n if (this.options.separator && this.options.trailingSeparator) {\n sink.ensureNewLine();\n }\n sink.renderingForSpan(this.span);\n sink.write(this.options.suffix);\n }\n }\n\n public get isEmpty() {\n return this.prefix.length + this.children.length === 0;\n }\n\n public toString() {\n return `<INCORRECTLY STRINGIFIED ${this.prefix.toString()}>`;\n }\n}\n\nexport const NO_SYNTAX = new OTree([]);\n\nexport class UnknownSyntax extends OTree {}\n\nexport interface SinkMark {\n readonly wroteNonWhitespaceSinceMark: boolean;\n}\n\nexport interface OTreeSinkOptions {\n /**\n * @default ' '\n */\n indentChar?: ' ' | '\\t';\n visibleSpans?: Spans;\n}\n\ninterface ConditionalNewLine {\n readonly conditionalNewLine: {\n readonly indent: number;\n };\n}\n\n/**\n * Output sink for OTree objects\n *\n * Maintains state about what has been rendered supports suppressing code\n * fragments based on their tagged source location.\n *\n * Basically: manages the state that was too hard to manage in the\n * tree :).\n */\nexport class OTreeSink {\n private readonly indentChar: ' ' | '\\t';\n private readonly indentLevels: number[] = [0];\n private readonly fragments = new Array<string | ConditionalNewLine>();\n private readonly singletonsRendered = new Set<string>();\n private pendingIndentChange = 0;\n private rendering = true;\n\n public constructor(private readonly options: OTreeSinkOptions = {}) {\n this.indentChar = options.indentChar ?? ' ';\n }\n\n public tagOnce(key: string | undefined): boolean {\n if (key === undefined) {\n return true;\n }\n if (this.singletonsRendered.has(key)) {\n return false;\n }\n this.singletonsRendered.add(key);\n return true;\n }\n\n /**\n * Get a mark for the current sink output location\n *\n * Marks can be used to query about things that have been written to output.\n */\n public mark(): SinkMark {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const markIndex = this.fragments.length;\n\n return {\n get wroteNonWhitespaceSinceMark(): boolean {\n return self.fragments.slice(markIndex).some((s) => typeof s !== 'object' && /[^\\s]/.exec(s) != null);\n },\n };\n }\n\n public write(text: string | OTree) {\n if (text instanceof OTree) {\n text.write(this);\n } else {\n if (!this.rendering) {\n return;\n }\n\n if (containsNewline(text)) {\n this.applyPendingIndentChange();\n }\n this.append(text.replace(/\\n/g, `\\n${this.indentChar.repeat(this.currentIndent)}`));\n }\n }\n\n /**\n * Ensures the following tokens will be output on a new line (emits a new line\n * and indent unless immediately preceded or followed by a newline, ignoring\n * surrounding white space).\n */\n public ensureNewLine(): void {\n this.applyPendingIndentChange();\n this.fragments.push({ conditionalNewLine: { indent: this.currentIndent } });\n }\n\n public renderingForSpan(span?: Span): boolean {\n if (span && this.options.visibleSpans) {\n this.rendering = this.options.visibleSpans.fullyContainsSpan(span);\n }\n return this.rendering;\n }\n\n public requestIndentChange(x: number): () => void {\n if (x === 0) {\n return () => undefined;\n }\n\n this.pendingIndentChange = x;\n const currentIndentState = this.indentLevels.length;\n\n // Return a pop function which will reset to the current indent state,\n // regardless of whether the indent was actually applied or not.\n return () => {\n this.indentLevels.splice(currentIndentState);\n this.pendingIndentChange = 0;\n };\n }\n\n public toString() {\n // Strip trailing whitespace from every line, and empty lines from the start and end\n return this.fragments\n .map((item, index, fragments) => {\n if (typeof item !== 'object') {\n return item;\n }\n const ignore = '';\n\n const leading = fragments.slice(0, index).reverse();\n for (const fragment of leading) {\n if (typeof fragment === 'object') {\n // We don't emit if there was already a conditional newline just before\n return ignore;\n }\n // If there's a trailing newline, then we don't emit this one\n if (/\\n\\s*$/m.exec(fragment)) {\n return ignore;\n }\n // If it contained non-whitespace characters, we need to check trailing data...\n if (/[^\\s]/.exec(fragment)) {\n break;\n }\n }\n\n const newlineAndIndent = `\\n${this.indentChar.repeat(item.conditionalNewLine.indent)}`;\n\n const trailing = fragments.slice(index + 1);\n for (const fragment of trailing) {\n if (typeof fragment === 'object') {\n // We're the first of a sequence, so we must emit (unless we returned earlier, of course)\n return newlineAndIndent;\n }\n // If there's a leading newline, then we don't emit this one\n if (/^\\s*\\n/m.exec(fragment)) {\n return ignore;\n }\n // If it contained non-whitespace characters, we emit this one\n if (/[^\\s]/.exec(fragment)) {\n return newlineAndIndent;\n }\n }\n\n return ignore;\n })\n .join('')\n .replace(/[ \\t]+$/gm, '')\n .replace(/^\\n+/, '')\n .replace(/\\n+$/, '');\n }\n\n private append(x: string) {\n this.fragments.push(x);\n }\n\n private applyPendingIndentChange() {\n if (this.pendingIndentChange !== 0) {\n this.indentLevels.push(this.currentIndent + this.pendingIndentChange);\n this.pendingIndentChange = 0;\n }\n }\n\n private get currentIndent() {\n return this.indentLevels[this.indentLevels.length - 1];\n }\n}\n\nfunction notUndefined<T>(x: T | undefined): x is T {\n return x !== undefined;\n}\n\nfunction notEmpty(x: OTree | string) {\n return x instanceof OTree ? !x.isEmpty : x !== '';\n}\n\nexport function renderTree(tree: OTree, options?: OTreeSinkOptions): string {\n const sink = new OTreeSink(options);\n tree.write(sink);\n return sink.toString();\n}\n\nfunction containsNewline(x: string) {\n return x.includes('\\n');\n}\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n"]}
1
+ {"version":3,"file":"o-tree.js","sourceRoot":"","sources":["../src/o-tree.ts"],"names":[],"mappings":";;;AA8UA,gCAIC;AA3RD;;;;;GAKG;AACH,MAAa,KAAK;IACT,MAAM,CAAC,QAAQ,CAAC,EAAqC;QAC1D,OAAO,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAQD,YACE,MAAyC,EACzC,QAA4C,EAC3B,UAAwB,EAAE;QAA1B,YAAO,GAAP,OAAO,CAAmB;QAE3C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,KAAa,EAAE,GAAW;QACvC,IAAI,CAAC,IAAI,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,IAAe;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3C,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEnD,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,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CAAI,CAAgB;IACvC,OAAO,CAAC,KAAK,SAAS,CAAC;AACzB,CAAC;AAED,SAAS,QAAQ,CAAC,CAAiB;IACjC,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AACpD,CAAC;AAED,SAAgB,UAAU,CAAC,IAAW,EAAE,OAA0B;IAChE,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC;AAED,SAAS,eAAe,CAAC,CAAS;IAChC,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import { Spans } from './typescript/visible-spans';\n\nexport interface OTreeOptions {\n /**\n * Adjust indentation with the given number\n *\n * Indentation affects children.\n *\n * @default 0\n */\n indent?: number;\n\n /**\n * Separate children with the given string\n *\n * @default ''\n */\n separator?: string;\n\n /**\n * Whether trailing separators should be output. This imples children will be\n * writen each on a new line.\n *\n * @default false\n */\n trailingSeparator?: boolean;\n\n /**\n * Suffix the token after outdenting\n *\n * @default ''\n */\n suffix?: string;\n\n /**\n * Whether this part of the generated syntax is okay to insert newlines and comments\n *\n * @default false\n */\n canBreakLine?: boolean;\n\n /**\n * If set, a unique key which will cause only one node with the given key to be rendered.\n *\n * The outermost key is the one that will be rendered.\n *\n * Used to make it easier to keep the state necessary to render comments\n * only once in the output tree, rather than keep the state in the\n * language rendered.\n *\n * @default No conditional rendering\n */\n renderOnce?: string;\n}\n\n/**\n * \"Output\" Tree\n *\n * Tree-like structure that holds sequences of trees and strings, which\n * can be rendered to an output sink.\n */\nexport class OTree implements OTree {\n public static simplify(xs: Array<OTree | string | undefined>): Array<OTree | string> {\n return xs.filter(notUndefined).filter(notEmpty);\n }\n\n public readonly attachComment: boolean;\n\n private readonly prefix: Array<OTree | string>;\n private readonly children: Array<OTree | string>;\n private span?: Span;\n\n public constructor(\n prefix: Array<OTree | string | undefined>,\n children?: Array<OTree | string | undefined>,\n private readonly options: OTreeOptions = {},\n ) {\n this.prefix = OTree.simplify(prefix);\n this.children = OTree.simplify(children ?? []);\n this.attachComment = !!options.canBreakLine;\n }\n\n /**\n * Set the span in the source file this tree node relates to\n */\n public setSpan(start: number, end: number) {\n this.span = { start, end };\n }\n\n public write(sink: OTreeSink) {\n if (!sink.tagOnce(this.options.renderOnce)) {\n return;\n }\n\n const meVisible = sink.renderingForSpan(this.span);\n\n for (const x of this.prefix) {\n sink.write(x);\n }\n\n const popIndent = sink.requestIndentChange(meVisible ? this.options.indent ?? 0 : 0);\n let mark = sink.mark();\n\n for (const child of this.children ?? []) {\n if (this.options.separator) {\n if (this.options.trailingSeparator) {\n sink.ensureNewLine();\n } else if (mark.wroteNonWhitespaceSinceMark) {\n sink.write(this.options.separator);\n }\n }\n mark = sink.mark();\n\n sink.write(child);\n\n if (this.options.separator && this.options.trailingSeparator) {\n sink.write(this.options.separator.trimEnd());\n }\n }\n\n popIndent();\n\n if (this.options.suffix) {\n if (this.options.separator && this.options.trailingSeparator) {\n sink.ensureNewLine();\n }\n sink.renderingForSpan(this.span);\n sink.write(this.options.suffix);\n }\n }\n\n public get isEmpty() {\n return this.prefix.length + this.children.length === 0;\n }\n\n public toString() {\n return `<INCORRECTLY STRINGIFIED ${this.prefix.toString()}>`;\n }\n}\n\nexport const NO_SYNTAX = new OTree([]);\n\nexport class UnknownSyntax extends OTree {}\n\nexport interface SinkMark {\n readonly wroteNonWhitespaceSinceMark: boolean;\n}\n\nexport interface OTreeSinkOptions {\n /**\n * @default ' '\n */\n indentChar?: ' ' | '\\t';\n visibleSpans?: Spans;\n}\n\ninterface ConditionalNewLine {\n readonly conditionalNewLine: {\n readonly indent: number;\n };\n}\n\n/**\n * Output sink for OTree objects\n *\n * Maintains state about what has been rendered supports suppressing code\n * fragments based on their tagged source location.\n *\n * Basically: manages the state that was too hard to manage in the\n * tree :).\n */\nexport class OTreeSink {\n private readonly indentChar: ' ' | '\\t';\n private readonly indentLevels: number[] = [0];\n private readonly fragments = new Array<string | ConditionalNewLine>();\n private readonly singletonsRendered = new Set<string>();\n private pendingIndentChange = 0;\n private rendering = true;\n\n public constructor(private readonly options: OTreeSinkOptions = {}) {\n this.indentChar = options.indentChar ?? ' ';\n }\n\n public tagOnce(key: string | undefined): boolean {\n if (key === undefined) {\n return true;\n }\n if (this.singletonsRendered.has(key)) {\n return false;\n }\n this.singletonsRendered.add(key);\n return true;\n }\n\n /**\n * Get a mark for the current sink output location\n *\n * Marks can be used to query about things that have been written to output.\n */\n public mark(): SinkMark {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const markIndex = this.fragments.length;\n\n return {\n get wroteNonWhitespaceSinceMark(): boolean {\n return self.fragments.slice(markIndex).some((s) => typeof s !== 'object' && /[^\\s]/.exec(s) != null);\n },\n };\n }\n\n public write(text: string | OTree) {\n if (text instanceof OTree) {\n text.write(this);\n } else {\n if (!this.rendering) {\n return;\n }\n\n if (containsNewline(text)) {\n this.applyPendingIndentChange();\n }\n this.append(text.replace(/\\n/g, `\\n${this.indentChar.repeat(this.currentIndent)}`));\n }\n }\n\n /**\n * Ensures the following tokens will be output on a new line (emits a new line\n * and indent unless immediately preceded or followed by a newline, ignoring\n * surrounding white space).\n */\n public ensureNewLine(): void {\n this.applyPendingIndentChange();\n this.fragments.push({ conditionalNewLine: { indent: this.currentIndent } });\n }\n\n public renderingForSpan(span?: Span): boolean {\n if (span && this.options.visibleSpans) {\n this.rendering = this.options.visibleSpans.fullyContainsSpan(span);\n }\n return this.rendering;\n }\n\n public requestIndentChange(x: number): () => void {\n if (x === 0) {\n return () => undefined;\n }\n\n this.pendingIndentChange = x;\n const currentIndentState = this.indentLevels.length;\n\n // Return a pop function which will reset to the current indent state,\n // regardless of whether the indent was actually applied or not.\n return () => {\n this.indentLevels.splice(currentIndentState);\n this.pendingIndentChange = 0;\n };\n }\n\n public toString() {\n // Strip trailing whitespace from every line, and empty lines from the start and end\n return this.fragments\n .map((item, index, fragments) => {\n if (typeof item !== 'object') {\n return item;\n }\n const ignore = '';\n\n const leading = fragments.slice(0, index).reverse();\n for (const fragment of leading) {\n if (typeof fragment === 'object') {\n // We don't emit if there was already a conditional newline just before\n return ignore;\n }\n // If there's a trailing newline, then we don't emit this one\n if (/\\n\\s*$/m.exec(fragment)) {\n return ignore;\n }\n // If it contained non-whitespace characters, we need to check trailing data...\n if (/[^\\s]/.exec(fragment)) {\n break;\n }\n }\n\n const newlineAndIndent = `\\n${this.indentChar.repeat(item.conditionalNewLine.indent)}`;\n\n const trailing = fragments.slice(index + 1);\n for (const fragment of trailing) {\n if (typeof fragment === 'object') {\n // We're the first of a sequence, so we must emit (unless we returned earlier, of course)\n return newlineAndIndent;\n }\n // If there's a leading newline, then we don't emit this one\n if (/^\\s*\\n/m.exec(fragment)) {\n return ignore;\n }\n // If it contained non-whitespace characters, we emit this one\n if (/[^\\s]/.exec(fragment)) {\n return newlineAndIndent;\n }\n }\n\n return ignore;\n })\n .join('')\n .replace(/[ \\t]+$/gm, '')\n .replace(/^\\n+/, '')\n .replace(/\\n+$/, '');\n }\n\n private append(x: string) {\n this.fragments.push(x);\n }\n\n private applyPendingIndentChange() {\n if (this.pendingIndentChange !== 0) {\n this.indentLevels.push(this.currentIndent + this.pendingIndentChange);\n this.pendingIndentChange = 0;\n }\n }\n\n private get currentIndent() {\n return this.indentLevels[this.indentLevels.length - 1];\n }\n}\n\nfunction notUndefined<T>(x: T | undefined): x is T {\n return x !== undefined;\n}\n\nfunction notEmpty(x: OTree | string) {\n return x instanceof OTree ? !x.isEmpty : x !== '';\n}\n\nexport function renderTree(tree: OTree, options?: OTreeSinkOptions): string {\n const sink = new OTreeSink(options);\n tree.write(sink);\n return sink.toString();\n}\n\nfunction containsNewline(x: string) {\n return x.includes('\\n');\n}\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n"]}
package/lib/renderer.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nimpl = exports.AstRenderer = void 0;
3
+ exports.AstRenderer = void 0;
4
+ exports.nimpl = nimpl;
4
5
  const ts = require("typescript");
5
6
  const o_tree_1 = require("./o-tree");
6
7
  const ast_utils_1 = require("./typescript/ast-utils");
@@ -368,7 +369,6 @@ function nimpl(node, context, options = {}) {
368
369
  canBreakLine: true,
369
370
  });
370
371
  }
371
- exports.nimpl = nimpl;
372
372
  function filterVisible(nodes) {
373
373
  return assignVisibility(nodes)
374
374
  .map((c) => (c.visible ? c.node : c.maskingVoid))
@@ -1 +1 @@
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,C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Tree, 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"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;;AAyeA,sBAqBC;AA9fD,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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,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"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as spec from '@jsii/spec';
3
2
  import { TargetLanguage } from './languages';
4
3
  import { CodeBlock } from './markdown/types';
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareDependencyDirectory = exports.validateAvailableDependencies = exports.resolveDependenciesFromPackageJson = exports.expandWithTransitiveDependencies = exports.collectDependencies = void 0;
3
+ exports.collectDependencies = collectDependencies;
4
+ exports.expandWithTransitiveDependencies = expandWithTransitiveDependencies;
5
+ exports.resolveDependenciesFromPackageJson = resolveDependenciesFromPackageJson;
6
+ exports.validateAvailableDependencies = validateAvailableDependencies;
7
+ exports.prepareDependencyDirectory = prepareDependencyDirectory;
4
8
  const cp = require("node:child_process");
5
9
  const node_fs_1 = require("node:fs");
6
10
  const fs = require("node:fs");
@@ -27,7 +31,6 @@ function collectDependencies(snippets) {
27
31
  }
28
32
  return ret;
29
33
  }
30
- exports.collectDependencies = collectDependencies;
31
34
  /**
32
35
  * Add transitive dependencies of concrete dependencies to the array
33
36
  *
@@ -64,7 +67,6 @@ async function expandWithTransitiveDependencies(deps) {
64
67
  }
65
68
  }
66
69
  }
67
- exports.expandWithTransitiveDependencies = expandWithTransitiveDependencies;
68
70
  /**
69
71
  * Find the corresponding package directories for all dependencies in a package.json
70
72
  */
@@ -80,7 +82,6 @@ async function resolveDependenciesFromPackageJson(packageJson, directory) {
80
82
  },
81
83
  ])));
82
84
  }
83
- exports.resolveDependenciesFromPackageJson = resolveDependenciesFromPackageJson;
84
85
  function resolveConflict(name, a, b) {
85
86
  if (!b) {
86
87
  return a;
@@ -131,7 +132,6 @@ async function validateAvailableDependencies(directory, deps) {
131
132
  logging.warn(`${directory}: packages necessary to compile examples missing from supplied directory: ${failures.join(', ')}`);
132
133
  }
133
134
  }
134
- exports.validateAvailableDependencies = validateAvailableDependencies;
135
135
  /**
136
136
  * Intersect two semver ranges
137
137
  *
@@ -201,7 +201,6 @@ async function prepareDependencyDirectory(deps) {
201
201
  cp.execSync(`npm install --force --loglevel error`, { cwd: tmpDir, encoding: 'utf-8' });
202
202
  return tmpDir;
203
203
  }
204
- exports.prepareDependencyDirectory = prepareDependencyDirectory;
205
204
  /**
206
205
  * Map package name to directory
207
206
  */