acornjs / acorn-stage3

Support for stage 3 proposals in acorn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to parse `fast-glob`

styfle opened this issue · comments

It seems like acorn-stage3 fails to parse a module from the fast-glob package called sync.js

Steps to reproduce

const code = `"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fsStat = require("@nodelib/fs.stat");
const fsWalk = require("@nodelib/fs.walk");
const reader_1 = require("./reader");
class ReaderSync extends reader_1.default {
    constructor() {
        super(...arguments);
        this._walkSync = fsWalk.walkSync;
        this._statSync = fsStat.statSync;
    }
    dynamic(root, options) {
        return this._walkSync(root, options);
    }
    static(patterns, options) {
        const entries = [];
        for (const pattern of patterns) {
            const filepath = this._getFullEntryPath(pattern);
            const entry = this._getEntry(filepath, pattern, options);
            if (entry === null || !options.entryFilter(entry)) {
                continue;
            }
            entries.push(entry);
        }
        return entries;
    }
    _getEntry(filepath, pattern, options) {
        try {
            const stats = this._getStat(filepath);
            return this._makeEntry(stats, pattern);
        }
        catch (error) {
            if (options.errorFilter(error)) {
                return null;
            }
            throw error;
        }
    }
    _getStat(filepath) {
        return this._statSync(filepath, this._fsStatSettings);
    }
}
exports.default = ReaderSync;
`;
let acorn = require('acorn');
const stage3 = require('acorn-stage3');
acorn = acorn.Parser.extend(stage3);
var ast = acorn.parse(code, { allowReturnOutsideFunction: true });
console.log(ast);

Error

/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:2827
    throw err
    ^

SyntaxError: Unexpected token (15:10)
    at Object.pp$4.raise (/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:2825:15)
    at Object.pp.unexpected (/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:689:10)
    at Object.pp$3.parseIdent (/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:2776:12)
    at Object.parseIdent (/Users/styfle/Code/foo/acorn-example/node_modules/acorn-class-fields/index.js:54:27)
    at Object.parseIdent (/Users/styfle/Code/foo/acorn-example/node_modules/acorn-static-class-features/index.js:121:27)
    at Object.pp$3.parsePropertyName (/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:2582:107)
    at Object.parsePropertyName (/Users/styfle/Code/foo/acorn-example/node_modules/acorn-private-methods/index.js:21:36)
    at Object.pp$1.parseClassElement (/Users/styfle/Code/foo/acorn-example/node_modules/acorn/dist/acorn.js:1363:29)
    at Object.parseClassElement (/Users/styfle/Code/foo/acorn-example/node_modules/acorn-class-fields/index.js:49:38)
    at Object.parseClassElement (/Users/styfle/Code/foo/acorn-example/node_modules/acorn-static-class-features/index.js:43:56)

Minimal Steps To Reproduce

const code = `class Foo {
  static(text) {
    console.log(text);
  }
}`;
let acorn = require('acorn');
const stage3 = require('acorn-stage3');
acorn = acorn.Parser.extend(stage3);
const ast = acorn.parse(code, { allowReturnOutsideFunction: true });
console.log(ast);

Works for me now.