Code Monkey home page Code Monkey logo

acorn-stage3's People

Contributors

adrianheine avatar dnalborczyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

acorn-stage3's Issues

Stage3 package doesn't work with Acorn v7.0.0

Problem

This package doesn't work with Acorn v7.0.0. An attempt to extend parser fails with such result:

/dev/esbundles/node_modules/acorn-private-class-elements/index.js:5
  throw new Error(`acorn-private-class-elements requires acorn@^6.1.0, not ${acorn.version}`)
  ^

Error: acorn-private-class-elements requires acorn@^6.1.0, not 7.1.0
    at Object.<anonymous> (/dev/esbundles/node_modules/acorn-private-class-elements/index.js:5:9)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/dev/esbundles/node_modules/acorn-class-fields/index.js:5:30)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)

Steps to reproduce

  1. Install acorn:
    npm i acorn@7
  2. Install acorn-stage3:
    npm i acorn-stage3@2
  3. Create acorn-stage3.js file with the code:
    const acorn = require('acorn');
    const stage3 = require('acorn-stage3');
    
    acorn.Parser.extend(stage3)
  4. Run node:
    node acorn-stage3.js

Fails to parse `fast-glob`

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);

Support for acorn-walk

The README states it's not compatible with acorn-walk, is there any plan to add support for this? I have a project that depends on that to be updated to [email protected]. Thanks!

MIT or Apache 2.0 open source license

@adrianheine Thank you for sharing this project!

We'd love to use it as part of the Mattermost open source project (https://www.mattermost.org/) in our Web App, which uses an Apache 2.0 license).

Would you be open to adding either an MIT or an Apache 2.0 license to your project?

If you use either an MIT license or an Apache 2.0 license it would make it easy to add your work to other open source projects, and we'd love to include your work in ours.

Thanks kindly for your consideration.

Unable to walk AST's parsed with stage3

I am trying to walk an AST parsed with the stage3 plugin, but both the injector and the decorated acorn instance throw an error.

The following code:

const acorn = require("acorn-stage3");
const walk = require("acorn/dist/walk");

const content = `
import("./module.js");
test("foo");
`;
const parsed = acorn.parse(content, { sourceType: 'module', plugins: { stage3: true } });

walk.simple(parsed, {
    CallExpression(node) { console.log(node) }
});

Will throw an error like:

TypeError: baseVisitor[type] is not a function
    at c (/private/tmp/prova/node_modules/acorn/dist/walk.js:29:22)
    at Object.skipThrough (/private/tmp/prova/node_modules/acorn/dist/walk.js:183:37)
    at c (/private/tmp/prova/node_modules/acorn/dist/walk.js:29:22)
    at Object.base.NewExpression.base.CallExpression (/private/tmp/prova/node_modules/acorn/dist/walk.js:374:3)
    at c (/private/tmp/prova/node_modules/acorn/dist/walk.js:29:22)
    at Object.skipThrough (/private/tmp/prova/node_modules/acorn/dist/walk.js:183:37)
    at c (/private/tmp/prova/node_modules/acorn/dist/walk.js:29:22)
    at Object.base.ExpressionStatement.base.ParenthesizedExpression (/private/tmp/prova/node_modules/acorn/dist/walk.js:201:35)
    at c (/private/tmp/prova/node_modules/acorn/dist/walk.js:29:22)
    at Object.skipThrough (/private/tmp/prova/node_modules/acorn/dist/walk.js:183:37)
> 

Using the injector will yield equal results:

const acorn = require("acorn");
const walk = require("acorn/dist/walk");
const injectAcornStage3 = require("acorn-stage3/inject");

const localAcorn = injectAcornStage3(acorn);

const content = `
import("./module.js");
test("foo");
`;
const parsed = localAcorn.parse(content, { sourceType: 'module', plugins: { stage3: true } });
console.log(parsed);

walk.simple(parsed, {
    CallExpression(node) { console.log(node) }
});

Same result.

Am I doing something wrong?
The same kind of problem also happens with "acorn-acorn-object-rest-spread"
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.