const AstNode = require('./ast-node');

class Variable extends AstNode {
  type() {
    return 'var';
  }

  /**
   * @param {ParseContext} context
   * @return {AstNodeParseResult}
   */
  parse(context) {
    const tm = context.sourceTextManager();

    tm.whitespace();
    const parsed = tm.next('$') + tm.consumeWhile(/[\w.]/);

    if (/^\$$|^\$\.|\.$|\.\./.test(parsed)) {
      throw new Error('invalid variable expression');
    }

    return {
      type: this.type(),
      keys: parsed.slice(1).split('.'),
    };
  }
}

module.exports = Variable;

@@ -266,16 +266,35 @@
 pace();%0A
+    tm.next('$');%0A%0A
     cons
@@ -307,23 +307,8 @@
 ed =
- tm.next('$') +
  tm.
@@ -343,17 +343,27 @@
 if (
-/%5E%5C$$%7C%5E%5C$
+parsed === '' %7C%7C /%5E
 %5C.%7C%5C
@@ -509,17 +509,8 @@
 sed.
-slice(1).
 spli

Rewrite Variable.parse()