AST in 7.0 (was Undefined Tag [cfmail] - 7.1.0.9-ALPHA)

Hello,

I’m using the AST functions, and I’m getting this error:

{“message”:“undefined tag [cfmail]; Failed at [path removed]”,“detail”:“”,“type”:“Error”}

I’m also not seeing the Mail setting in Services in the Server Admin UI. Am I missing something or is this a bug?

Thanks!

  • Ian

It’s flagged as -ALPHA for a reason! :slight_smile:

it’s very, very bleeding edge

7.1 is in the early move and fast and break stuff phase

stick to the 7.0 for now

Mail (and other stuff) are being moved out extensions, Lucee is going on a diet

1 Like

Understood, thanks!

how are you finding the AST stuff?

So far so good!

Only complaint is that it doesn’t process comments, but I already have a workaround for re-printing those.

I’m also noticing just now that attributes for cffunction and cfargument tags aren’t appearing in the tree. Now I’m running v 7.0.0.395

image

use the RC!!! it has some important AST fixes

1 Like

Switch to that version. Attributes are still empty:

image

1 Like

the code is in place to do that… digging…

<cfscript>

// Test AST captures function attributes
code = 'function zac() output=false { return 1; }';
ast = astFromString( code, "script" );
systemOutput( serializeJSON( var=ast, compact=false ), true );
</cfscript>

it’s under body?

"type": "Program",
  "body": [
    {
      "start": {
        "line": 1,
        "column": 12,
        "offset": 12
      },
      "end": {
        "line": 1,
        "column": 41,
        "offset": 41
      },
      "type": "FunctionDeclaration",
      "name": {
        "type": "StringLiteral",
        "value": "zac",
        "raw": "\"zac\""
      },
      "access": "PUBLIC",
      "returnType": {
        "type": "StringLiteral",
        "value": "any",
        "raw": "\"any\""
      },
      "output": {
        "start": {
          "line": 1,
          "column": 22,
          "offset": 22
        },
        "end": {
          "line": 1,
          "column": 28,
          "offset": 28
        },
        "type": "BooleanLiteral",
        "value": false
      },

I’m using tag syntax if that makes a difference.

{
  "start": {
    "line": 1,
    "column": 0,
    "offset": 0
  },
  "end": {
    "line": 4,
    "column": 14,
    "offset": 228
  },
  "type": "Program",
  "body": [
    {
      "start": {
        "line": 1,
        "column": 0,
        "offset": 0
      },
      "end": {
        "line": 4,
        "column": 14,
        "offset": 228
      },
      "type": "CFMLTag",
      "isBuiltIn": true,
      "name": "function",
      "nameSpace": "cf",
      "nameSpaceSeparator": "",
      "fullname": "cffunction",
      "attributes": [],
      "body": {
        "type": "BlockStatement",
        "body": [
          {
            "start": {
              "line": 1,
              "column": 83,
              "offset": 83
            },
            "end": {
              "line": 2,
              "column": 5,
              "offset": 89
            },
            "type": "ExpressionStatement",
            "expression": {
              "start": {
                "line": 1,
                "column": 83,
                "offset": 83
              },
              "end": {
                "line": 2,
                "column": 5,
                "offset": 89
              },
              "type": "StringLiteral",
              "value": "\r\n    ",
              "raw": "\"\r\n    \""
            }
          },
          {
            "start": {
              "line": 2,
              "column": 5,
              "offset": 89
            },
            "end": {
              "line": 2,
              "column": 63,
              "offset": 147
            },
            "type": "CFMLTag",
            "isBuiltIn": true,
            "name": "argument",
            "nameSpace": "cf",
            "nameSpaceSeparator": "",
            "fullname": "cfargument",
            "attributes": []
          },
          {
            "start": {
              "line": 2,
              "column": 63,
              "offset": 147
            },
            "end": {
              "line": 3,
              "column": 5,
              "offset": 153
            },
            "type": "ExpressionStatement",
            "expression": {
              "start": {
                "line": 2,
                "column": 63,
                "offset": 147
              },
              "end": {
                "line": 3,
                "column": 5,
                "offset": 153
              },
              "type": "StringLiteral",
              "value": "\r\n    ",
              "raw": "\"\r\n    \""
            }
          },
          {
            "start": {
              "line": 3,
              "column": 5,
              "offset": 153
            },
            "end": {
              "line": 3,
              "column": 65,
              "offset": 213
            },
            "type": "CFMLTag",
            "isBuiltIn": true,
            "name": "return",
            "nameSpace": "cf",
            "nameSpaceSeparator": "",
            "fullname": "cfreturn",
            "attributes": [
              {
                "name": "expr",
                "type": "Attribute",
                "value": {
                  "start": {
                    "line": 3,
                    "column": 15,
                    "offset": 163
                  },
                  "end": {
                    "line": 3,
                    "column": 62,
                    "offset": 210
                  },
                  "type": "BinaryExpression",
                  "operator": "CONCAT",
                  "left": {
                    "start": {
                      "line": 3,
                      "column": 15,
                      "offset": 163
                    },
                    "end": {
                      "line": 3,
                      "column": 62,
                      "offset": 210
                    },
                    "type": "BinaryExpression",
                    "operator": "CONCAT",
                    "left": {
                      "start": {
                        "line": 3,
                        "column": 15,
                        "offset": 163
                      },
                      "end": {
                        "line": 3,
                        "column": 30,
                        "offset": 178
                      },
                      "type": "BinaryExpression",
                      "operator": "CONCAT",
                      "left": {
                        "start": {
                          "line": 3,
                          "column": 15,
                          "offset": 163
                        },
                        "end": {
                          "line": 3,
                          "column": 30,
                          "offset": 178
                        },
                        "type": "StringLiteral",
                        "value": "User ",
                        "raw": "\"User \""
                      },
                      "right": {
                        "start": {
                          "line": 3,
                          "column": 22,
                          "offset": 170
                        },
                        "end": {
                          "line": 3,
                          "column": 30,
                          "offset": 178
                        },
                        "type": "CastExpression",
                        "typeAnnotation": "string",
                        "argument": {
                          "start": {
                            "line": 3,
                            "column": 22,
                            "offset": 170
                          },
                          "end": {
                            "line": 3,
                            "column": 30,
                            "offset": 178
                          },
                          "type": "Identifier",
                          "name": "userName"
                        }
                      }
                    },
                    "right": {
                      "start": {
                        "line": 3,
                        "column": 15,
                        "offset": 163
                      },
                      "end": {
                        "line": 3,
                        "column": 62,
                        "offset": 210
                      },
                      "type": "StringLiteral",
                      "value": " has access level: ",
                      "raw": "\" has access level: \""
                    }
                  },
                  "right": {
                    "start": {
                      "line": 3,
                      "column": 51,
                      "offset": 199
                    },
                    "end": {
                      "line": 3,
                      "column": 62,
                      "offset": 210
                    },
                    "type": "CastExpression",
                    "typeAnnotation": "string",
                    "argument": {
                      "start": {
                        "line": 3,
                        "column": 51,
                        "offset": 199
                      },
                      "end": {
                        "line": 3,
                        "column": 62,
                        "offset": 210
                      },
                      "type": "Identifier",
                      "name": "accessLevel"
                    }
                  }
                }
              }
            ]
          },
          {
            "start": {
              "line": 3,
              "column": 65,
              "offset": 213
            },
            "end": {
              "line": 4,
              "column": 1,
              "offset": 215
            },
            "type": "ExpressionStatement",
            "expression": {
              "start": {
                "line": 3,
                "column": 65,
                "offset": 213
              },
              "end": {
                "line": 4,
                "column": 1,
                "offset": 215
              },
              "type": "StringLiteral",
              "value": "\r\n",
              "raw": "\"\r\n\""
            }
          }
        ]
      }
    }
  ]
}
<cffunction name="testFunction" access="public" returntype="string" output="false">
    <cfargument name="userName" type="string" required="true">
    <cfreturn "User #userName# has access level: #accessLevel#">
</cffunction>

ahhh, indeed there’s a bug with the tag syntax

https://luceeserver.atlassian.net/browse/LDEV-5969

1 Like

I believe I found another one:

AST loses the method name: ensureCapacity does not appear anywhere.

astFromString = astFromString( '<cfset buf.ensureCapacity(JavaCast("int", len+20))>' );
{
    "start": {
        "line": 1,
        "column": 0,
        "offset": 0
    },
    "end": {
        "line": 1,
        "column": 51,
        "offset": 51
    },
    "type": "Program",
    "body": [
        {
            "start": {
                "line": 1,
                "column": 0,
                "offset": 0
            },
            "end": {
                "line": 1,
                "column": 51,
                "offset": 51
            },
            "type": "CFMLTag",
            "isBuiltIn": true,
            "name": "set",
            "nameSpace": "cf",
            "nameSpaceSeparator": "",
            "fullname": "cfset",
            "attributes": [
                {
                    "name": "noname",
                    "type": "Attribute",
                    "value": {
                        "start": {
                            "line": 1,
                            "column": 7,
                            "offset": 7
                        },
                        "end": {
                            "line": 1,
                            "column": 10,
                            "offset": 10
                        },
                        "type": "CallExpression",
                        "callee": {
                            "type": "Identifier",
                            "name": "buf"
                        },
                        "arguments": [
                            {
                                "start": {
                                    "line": 1,
                                    "column": 26,
                                    "offset": 26
                                },
                                "end": {
                                    "line": 1,
                                    "column": 49,
                                    "offset": 49
                                },
                                "type": "CallExpression",
                                "isBuiltIn": true,
                                "callee": {
                                    "type": "Identifier",
                                    "name": "javacast"
                                },
                                "arguments": [
                                    {
                                        "start": {
                                            "line": 1,
                                            "column": 35,
                                            "offset": 35
                                        },
                                        "end": {
                                            "line": 1,
                                            "column": 40,
                                            "offset": 40
                                        },
                                        "type": "StringLiteral",
                                        "value": "int",
                                        "raw": "\"int\""
                                    },
                                    {
                                        "start": {
                                            "line": 1,
                                            "column": 42,
                                            "offset": 42
                                        },
                                        "end": {
                                            "line": 1,
                                            "column": 48,
                                            "offset": 48
                                        },
                                        "type": "BinaryExpression",
                                        "operator": "PLUS",
                                        "left": {
                                            "start": {
                                                "line": 1,
                                                "column": 42,
                                                "offset": 42
                                            },
                                            "end": {
                                                "line": 1,
                                                "column": 45,
                                                "offset": 45
                                            },
                                            "type": "Identifier",
                                            "name": "len"
                                        },
                                        "right": {
                                            "start": {
                                                "line": 1,
                                                "column": 46,
                                                "offset": 46
                                            },
                                            "end": {
                                                "line": 1,
                                                "column": 48,
                                                "offset": 48
                                            },
                                            "type": "NumberLiteral",
                                            "raw": "20",
                                            "value": 20
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

ok., keep em coming!

https://luceeserver.atlassian.net/browse/LDEV-5975

1 Like

found a few more…

LDEV-5969 AST does not capture cffunction/cfargument tag attributes
LDEV-5975 AST dump loses method name in chained method calls
LDEV-5977 AST Ternary expression alternate value duplicates consequent
LDEV-5978 AST queryExecute adds extra variable name argument
LDEV-5979 AST isDefined adds extra scope argument
LDEV-5980 AST BIF calls keep adding internal metadata

https://luceeserver.atlassian.net/browse/LDEV-5715

1 Like

NVM, I see the chained methods is already found by you :slight_smile:

1 Like

Hello again! Wondering if this is a bug or intended behavior. In example 1, the end offset is 65. In example 2, I add comments in the lines above each line, and the end offset becomes 46.

Example 1 - test.cfm:



Nothing but text here



Literally Nothing


No really

astFromPath() gives:

{
  "start": {
    "line": 1,
    "column": 0,
    "offset": 0
  },
  "end": {
    "line": 10,
    "column": 10,
    "offset": 65
  },
  "type": "Program",
  "body": [
    {
      "start": {
        "line": 1,
        "column": 0,
        "offset": 0
      },
      "end": {
        "line": 10,
        "column": 10,
        "offset": 65
      },
      "type": "ExpressionStatement",
      "expression": {
        "start": {
          "line": 1,
          "column": 0,
          "offset": 0
        },
        "end": {
          "line": 10,
          "column": 10,
          "offset": 65
        },
        "type": "StringLiteral",
        "value": "\r\n\r\nNothing but text here\r\n\r\n\r\n\r\nLiterally Nothing\r\n\r\n\r\nNo really",
        "raw": "\"\r\n\r\nNothing but text here\r\n\r\n\r\n\r\nLiterally Nothing\r\n\r\n\r\nNo really\""
      }
    }
  ]}

Example 2 - test.cfm:

<!--- Test 1 --->

Nothing but text here

<!--- Test 2 --->

Literally Nothing

<!--- Test 3 --->
No really

astFromPath() gives:

{
  "start": {
    "line": 1,
    "column": 17,
    "offset": 17
  },
  "end": {
    "line": 5,
    "column": 1,
    "offset": 46
  },
  "type": "Program",
  "body": [
    {
      "start": {
        "line": 1,
        "column": 17,
        "offset": 17
      },
      "end": {
        "line": 5,
        "column": 1,
        "offset": 46
      },
      "type": "ExpressionStatement",
      "expression": {
        "start": {
          "line": 1,
          "column": 17,
          "offset": 17
        },
        "end": {
          "line": 5,
          "column": 1,
          "offset": 46
        },
        "type": "StringLiteral",
        "value": "\r\n\r\nNothing but text here\r\n\r\n\r\n\r\nLiterally Nothing\r\n\r\n\r\nNo really",
        "raw": "\"\r\n\r\nNothing but text here\r\n\r\n\r\n\r\nLiterally Nothing\r\n\r\n\r\nNo really\""
      }
    }
  ]}