acornjs / acorn-stage3 Goto Github PK
View Code? Open in Web Editor NEWSupport for stage 3 proposals in acorn
License: MIT License
Support for stage 3 proposals in acorn
License: MIT License
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)
acorn
:
npm i acorn@7
acorn-stage3
:
npm i acorn-stage3@2
acorn-stage3.js
file with the code:
const acorn = require('acorn');
const stage3 = require('acorn-stage3');
acorn.Parser.extend(stage3)
node acorn-stage3.js
It seems like acorn-stage3
fails to parse a module from the fast-glob
package called sync.js
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);
/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)
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);
TC39 added the .?
operator for null safe object access. Can this be added to Acorn?
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!
@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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.