TyrealHu / acorn-typescript

Alternative, TypeScript parser
https://www.npmjs.com/package/acorn-typescript?activeTab=readme
MIT License
145 stars 18 forks source link

SyntaxError: Unexpected token at non-null assertion in body expression of an object literal's arrow function value #43

Closed bpstrngr closed 1 year ago

bpstrngr commented 1 year ago

Parsed file: rollup/rollup/src/ast/nodes/BinaryExpression.ts

const binaryOperators: {
        [operator in Operator]?: (left: LiteralValue, right: LiteralValue) => LiteralValueOrUnknown;
} = {
        '!=': (left, right) => left != right,
        '!==': (left, right) => left !== right,
        '%': (left: any, right: any) => left % right,
        '&': (left: any, right: any) => left & right,
        '*': (left: any, right: any) => left * right,
        // At the moment, "**" will be transpiled to Math.pow
        '**': (left: any, right: any) => left ** right,
        '+': (left: any, right: any) => left + right,
        '-': (left: any, right: any) => left - right,
        '/': (left: any, right: any) => left / right,
        '<': (left, right) => left! < right!,
//                                ^
        // ...further methods
};

Error:

SyntaxError: Unexpected token (57:29)
    at pp.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/location.js:15:13)
    at TypeScriptParser.raiseCommonCheck (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:5008:44)
    at TypeScriptParser.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:5014:29)
    at pp.unexpected (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:111:8)
    at pp.expect (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:105:26)
    at pp.parseObj (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/expression.js:749:12)
    at pp.parseExprAtom (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/expression.js:484:17)
    at TypeScriptParser.parseExprAtom (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3473:34)
    at pp.parseExprSubscripts (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/expression.js:292:19)
    at pp.parseMaybeUnary (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/expression.js:258:17) {
  pos: 1644,
  loc: Position { line: 57, column: 29 },
  raisedAt: 1645
}
bpstrngr commented 1 year ago

actually i think the token it complains about is the "<" (try{super.parseExprAtom()}catch(){console.log(this.type)} gives

  TokenType {
    label: 'jsxTagStart',
    keyword: undefined,
    beforeExpr: false,
    startsExpr: true,
    isLoop: false,
    isAssign: false,
    prefix: false,
    postfix: false,
    binop: null,
    updateContext: [Function (anonymous)]
  }

)

TyrealHu commented 1 year ago

fix in acorn-typescript@1.4.7