Skip to content

Instantly share code, notes, and snippets.

@conartist6
Last active February 18, 2023 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conartist6/fa679c9dc118bd7723f0f4c1d55b83da to your computer and use it in GitHub Desktop.
Save conartist6/fa679c9dc118bd7723f0f4c1d55b83da to your computer and use it in GitHub Desktop.
https://github.com/js-cst-tokens/cst-tokens comment attachment example
function /*1*/ foo /*2*/ (/*3*/) /*4*/ {/*5*/} /*6*/
{
"type": "CSTFragment",
"cstTokens": [
{ "type": "Reference", "value": "fragment" },
{ "type": "Literal", "value": " " },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "6" },
{ "type": "CommentEnd", "value": "*/" }
],
"fragment": {
"type": "Program",
"cstTokens": [
{ "type": "Reference", "value": "body" }
],
"sourceType": "module",
"body": [
{
"type": "FunctionDeclaration",
"cstTokens": [
{ "type": "Keyword", "value": "function" },
{ "type": "Literal", "value": " " },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "1" },
{ "type": "CommentEnd", "value": "*/" },
{ "type": "Literal", "value": " " },
{ "type": "Reference", "value": "id" },
{ "type": "Literal", "value": " " },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "2" },
{ "type": "CommentEnd", "value": "*/" },
{ "type": "Literal", "value": " " },
{ "type": "LeftPunctuator", "value": "(" },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "3" },
{ "type": "CommentEnd", "value": "*/" },
{ "type": "RightPunctuator", "value": ")" },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "4" },
{ "type": "CommentEnd", "value": "*/" },
{ "type": "Literal", "value": " " },
{ "type": "Reference", "value": "body" }
],
"id": {
"type": "Identifier",
"cstTokens": [
{ "type": "SymbolDefinition", "value": "foo" }
],
"name": "foo"
},
"params": [],
"body": {
"type": "BlockStatement",
"cstTokens": [
{ "type": "LeftPunctuator", "value": "{" },
{ "type": "CommentStart", "value": "/*" },
{ "type": "Literal", "value": "5" },
{ "type": "CommentEnd", "value": "*/" },
{ "type": "RightPunctuator", "value": "}" }
],
"body": []
},
"async": false,
"generator": false
}
]
}
}
function /*1*/ foo /*2*/ (/*3*/) /*4*/ {/*5*/} /*6*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment