Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start babel 6 upgrade #218

Closed
wants to merge 19 commits into from
Closed

Start babel 6 upgrade #218

wants to merge 19 commits into from

Conversation

tmcw
Copy link
Member

@tmcw tmcw commented Nov 3, 2015

Fixes #211

Traversal with ast-types is broken because babel is departing from ESTree benjamn/ast-types#132

Going to test out babel's own traversal.

stage: 0,
locations: true,
ranges: true
presets: ['es2015', 'stage-0', 'react']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need to parse the ast correct? You can just use babylon for that and use the seperate babel-traverse package.

Example of what I did with babylon options: https://github.com/cst/cst/blob/master/src/Parser.js#L73-L94

@jamiebuilds
Copy link

You can use babel-types instead of this btw.

@RobinQu
Copy link

RobinQu commented Dec 1, 2015

Hi, guys

What's status of this branch now?

Still failed to generate docs for babel@6 projects.

/Workspace/src/nodejs/documentation/bin/documentation.js:21
    throw err;
    ^

Error: did not recognize object of type "ObjectProperty"
    at Object.getFieldNames (/Workspace/src/nodejs/documentation/node_modules/ast-types/lib/types.js:659:15)
    at visitChildren (/Workspace/src/nodejs/documentation/node_modules/ast-types/lib/path-visitor.js:221:32)
    at Visitor.PVp.visitWithoutReset (/Workspace/src/nodejs/documentation/node_modules/ast-types/lib/path-visitor.js:202:16)
    at Visitor.PVp.visit (/Workspace/src/nodejs/documentation/node_modules/ast-types/lib/path-visitor.js:131:25)
    at Object.visit (/Workspace/src/nodejs/documentation/node_modules/ast-types/lib/path-visitor.js:99:51)
    at Object.inferName (/Workspace/src/nodejs/documentation/lib/infer/name.js:52:11)
    at /Workspace/src/nodejs/documentation/index.js:31:28
    at Array.map (native)
    at /Workspace/src/nodejs/documentation/index.js:94:16
    at /Workspace/src/nodejs/documentation/lib/input/dependency.js:42:5

@tmcw
Copy link
Member Author

tmcw commented Dec 1, 2015

@RobinQu I got stuck on the previously-noted issue: benjamn/ast-types#132 - given that ast-types doesn't support everything Babel now outputs, and Babel's traversal is quite a bit different, this is more than a swap-in upgrade. I'll switch back onto this task after the --access flag is done, and possibly node v5 support.

@tmcw
Copy link
Member Author

tmcw commented Dec 1, 2015

Just pushed some updates: now uses babylon, tries to use traverse. Any ideas from @hzoo @thejameskyle would be much appreciated; it doesn't seem like babylon or babel-traverse have any documentation and are pretty tricky to decipher.

@hzoo
Copy link

hzoo commented Dec 1, 2015


var visited = {};

function walkComments(ast, type, includeContext) {
types.visit(ast, {
visitNode: function (path) {
traverse(ast, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this throws with

Error: You must pass a scope and parentPath unless traversing a Program/File got a undefined node
    at traverse (/Users/tmcw/src/documentation/node_modules/babel-traverse/lib/index.js:55:13)
    at walkComments (/Users/tmcw/src/documentation/lib/parsers/javascript.js:47:5)
    at parseJavaScript (/Users/tmcw/src/documentation/lib/parsers/javascript.js:96:3)

@tmcw
Copy link
Member Author

tmcw commented Dec 1, 2015

Parsing with babylon is working, but traversing the generated AST doesn't work and I can't find a simple example of using babel-traverse for doing so.

@@ -28,7 +28,7 @@ module.exports = function () {
}
}

types.visit(comment.context.ast, {
babel.traverse(comment.context.ast, {
visitClassDeclaration: function () {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The traverse api uses the nodes as the keys like ClassDeclaration

{
    visitor: {
      BinaryExpression(path) {
        // ...
      }
    }
  };```

@tmcw
Copy link
Member Author

tmcw commented Dec 1, 2015

Trying to configure babelify with presets fails with

/Users/tmcw/src/documentation/bin/documentation.js:32
    throw err;
    ^

ReferenceError: Unknown plugin "es2015" specified in "base" at 0, attempted to resolve relative to "/Users/tmcw/src/documentation/test/fixture" while parsing file: /Users/tmcw/src/documentation/test/fixture/es6.input.js
    at /Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/options/option-manager.js:193:17
    at Array.map (native)
    at Function.normalisePlugins (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
    at OptionManager.mergeOptions (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
    at OptionManager.init (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
    at File.initOptions (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/index.js:190:75)
    at new File (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/file/index.js:121:22)
    at Pipeline.transform (/Users/tmcw/src/documentation/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
    at Babelify._flush (/Users/tmcw/src/documentation/node_modules/babelify/index.js:28:24)
    at Babelify.<anonymous> (_stream_transform.js:118:12)

No notes about a relative dir in the babelify readme.

@@ -26,7 +26,7 @@ function dependencyStream(indexes, options, callback) {
},
transform: [babelify.configure({
sourceMap: false,
stage: 0
plugins: ['es2015', 'stage-0', 'react']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presets here

@tmcw
Copy link
Member Author

tmcw commented Dec 2, 2015

Upstream issue for enter() method: https://phabricator.babeljs.io/T6740

visitTypeAlias: function () {
FunctionDeclaration: visitFunction,
FunctionExpression: visitFunction,
ArrowFunctionExpression: visitFunction,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can also visit any node with the Function alias including ClassMethod and ObjectMethod (in addition to what you have)

@tmcw
Copy link
Member Author

tmcw commented Dec 6, 2015

Upstream for failure to use deepEqual: https://phabricator.babeljs.io/T6775?workflow=create#R - removeProperties does not provide a JSON-serializable output.

@tmcw tmcw mentioned this pull request Dec 18, 2015
@tmcw
Copy link
Member Author

tmcw commented Jan 24, 2016

Going to give this a second try now that we use traversal less.

@tmcw tmcw closed this Jan 24, 2016
@tmcw tmcw deleted the babel-6 branch January 24, 2016 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants