Skip to content

Commit 8886ac6

Browse files
committed
Switch from babylon to babel-core. Fixes #201
1 parent 63c0ca6 commit 8886ac6

13 files changed

+247
-32
lines changed

lib/parsers/javascript.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var babylon = require('babylon'),
3+
var babel = require('babel-core'),
44
types = require('ast-types'),
55
extend = require('extend'),
66
isJSDocComment = require('../../lib/is_jsdoc_comment'),
@@ -20,21 +20,10 @@ function commentShebang(code) {
2020
}
2121

2222
var parseOpts = {
23-
allowImportExportEverywhere: true,
24-
allowReturnOutsideFunction: true,
25-
allowHashBang: true,
26-
ecmaVersion: 7,
27-
strictMode: true,
28-
sourceType: 'module',
23+
code: false,
24+
stage: 0,
2925
locations: true,
30-
ranges: true,
31-
features: {
32-
'es7.classProperties': true
33-
},
34-
plugins: {
35-
jsx: true,
36-
flow: true
37-
}
26+
ranges: true
3827
};
3928

4029
/**
@@ -48,7 +37,7 @@ var parseOpts = {
4837
module.exports = function (data) {
4938
var results = [];
5039
var code = commentShebang(data.source),
51-
ast = babylon.parse(code, parseOpts);
40+
ast = babel.parse(code, parseOpts);
5241

5342
var visited = {};
5443

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"ast-types": "^0.8.12",
1919
"babelify": "^6.3.0",
20-
"babylon": "^5.8.23",
20+
"babel-core": "^5.0.0",
2121
"brfs": "^1.4.0",
2222
"concat-stream": "^1.5.0",
2323
"doctrine": "^0.7.0",
@@ -74,6 +74,7 @@
7474
},
7575
"scripts": {
7676
"lint": "eslint bin lib index.js test",
77+
"doc": "documentation index.js -f md > docs/NODE_API.md",
7778
"test": "npm run lint && tap --coverage test/*.js test/lib test/misc test/streams"
7879
}
7980
}

test/fixture/bad/syntax.output.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
"line": 1,
55
"column": 0
66
},
7-
"_babel": true,
8-
"codeFrame": "> 1 | *\n | ^\n 2 | "
9-
}
7+
"_babel": true
8+
}

test/fixture/es6-import.output.custom.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ This method says hello
3232

3333

3434

35+
# foo
36+
37+
This is an async method
38+
39+
40+
3541
# multiply
3642

3743
This function returns the number one.

test/fixture/es6-import.output.json

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"column": 1
2424
}
2525
},
26-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
26+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
2727
},
2828
"errors": [],
2929
"name": "Sink",
@@ -75,7 +75,7 @@
7575
"column": 3
7676
}
7777
},
78-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
78+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
7979
},
8080
"errors": [],
8181
"params": [
@@ -137,7 +137,7 @@
137137
"column": 3
138138
}
139139
},
140-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
140+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
141141
},
142142
"errors": [],
143143
"name": "empty",
@@ -179,7 +179,7 @@
179179
"column": 3
180180
}
181181
},
182-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
182+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
183183
},
184184
"errors": [],
185185
"name": "hello",
@@ -201,6 +201,43 @@
201201
"Sink"
202202
]
203203
},
204+
{
205+
"description": "This is an async method",
206+
"tags": [],
207+
"loc": {
208+
"start": {
209+
"line": 40,
210+
"column": 0
211+
},
212+
"end": {
213+
"line": 42,
214+
"column": 3
215+
}
216+
},
217+
"context": {
218+
"loc": {
219+
"start": {
220+
"line": 43,
221+
"column": 0
222+
},
223+
"end": {
224+
"line": 43,
225+
"column": 24
226+
}
227+
},
228+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
229+
},
230+
"errors": [],
231+
"name": "foo",
232+
"kind": "function",
233+
"members": {
234+
"instance": [],
235+
"static": []
236+
},
237+
"path": [
238+
"foo"
239+
]
240+
},
204241
{
205242
"description": "This function returns the number one.",
206243
"tags": [
@@ -235,7 +272,7 @@
235272
"column": 31
236273
}
237274
},
238-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
275+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
239276
},
240277
"errors": [],
241278
"returns": [
@@ -360,7 +397,7 @@
360397
"column": 18
361398
}
362399
},
363-
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\nexport default multiply;\n"
400+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n"
364401
},
365402
"errors": [],
366403
"name": "staticProp",

test/fixture/es6-import.output.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ This method says hello
3232

3333

3434

35+
# foo
36+
37+
This is an async method
38+
39+
40+
3541
# multiply
3642

3743
This function returns the number one.

test/fixture/es6-import.output.md.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,67 @@
397397
}
398398
]
399399
},
400+
{
401+
"type": "root",
402+
"children": [
403+
{
404+
"depth": 1,
405+
"type": "heading",
406+
"children": [
407+
{
408+
"type": "text",
409+
"value": "foo"
410+
}
411+
]
412+
},
413+
{
414+
"type": "root",
415+
"children": [
416+
{
417+
"type": "paragraph",
418+
"children": [
419+
{
420+
"type": "text",
421+
"value": "This is an async method",
422+
"position": {
423+
"start": {
424+
"line": 1,
425+
"column": 1
426+
},
427+
"end": {
428+
"line": 1,
429+
"column": 24
430+
},
431+
"indent": []
432+
}
433+
}
434+
],
435+
"position": {
436+
"start": {
437+
"line": 1,
438+
"column": 1
439+
},
440+
"end": {
441+
"line": 1,
442+
"column": 24
443+
},
444+
"indent": []
445+
}
446+
}
447+
],
448+
"position": {
449+
"start": {
450+
"line": 1,
451+
"column": 1
452+
},
453+
"end": {
454+
"line": 1,
455+
"column": 24
456+
}
457+
}
458+
}
459+
]
460+
},
400461
{
401462
"type": "root",
402463
"children": [

test/fixture/es6.input.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ class Sink {
3737
}
3838
}
3939

40+
/**
41+
* This is an async method
42+
*/
43+
async function foo() { }
44+
4045
export default multiply;

test/fixture/es6.output.custom.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ This method says hello
3232

3333

3434

35+
# foo
36+
37+
This is an async method
38+
39+
40+
3541
# multiply
3642

3743
This function returns the number one.

0 commit comments

Comments
 (0)