TyrealHu / acorn-typescript

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

SyntaxError: Assigning to rvalue #38

Closed bpstrngr closed 1 year ago

bpstrngr commented 1 year ago

Got an interesting one:

export const getHashPlaceholderGenerator = (): HashPlaceholderGenerator => {
        let nextIndex = 0;
        return (optionName: string, hashSize: number = defaultHashSize) => {}
                                            ^
}
SyntaxError: Assigning to rvalue (17:37)
    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:4990:44)
    at TypeScriptParser.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4996:29)
    at pp.toAssignable (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/lval.js:82:12)
    at TypeScriptParser.toAssignable (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4288:38)
    at TypeScriptParser.parseMaybeAssignOrigin (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4023:37)
    at TypeScriptParser.parseMaybeAssign (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4078:33)
    at TypeScriptParser.parseParenAndDistinguishExpression (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4396:48)
    at pp.parseExprAtom (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/expression.js:467:41)
    at TypeScriptParser.parseExprAtom (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3459:34) {
  pos: 660,
  loc: Position { line: 17, column: 37 },
  raisedAt: 670
}

looks like the argument subscript of the arrow function being returned is prematurely mistaken for comma-operator expression due to the default assignment happening.

TyrealHu commented 1 year ago

fixed in version 1.4.4