Skip to content

Commit 8ca0e08

Browse files
committed
Support ES7 class properties
1 parent 1eee5a8 commit 8ca0e08

11 files changed

+266
-39
lines changed

lib/input/dependency.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function dependencyStream(indexes, options, callback) {
2525
return !!options.external || moduleFilters.internalOnly(id);
2626
},
2727
transform: [babelify.configure({
28-
sourceMap: false
28+
sourceMap: false,
29+
stage: 0
2930
})],
3031
postFilter: moduleFilters.externals(indexes, options)
3132
});

lib/parsers/javascript.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ var parseOpts = {
2323
allowImportExportEverywhere: true,
2424
allowReturnOutsideFunction: true,
2525
allowHashBang: true,
26-
ecmaVersion: 6,
26+
ecmaVersion: 7,
2727
strictMode: true,
2828
sourceType: 'module',
2929
locations: true,
30-
features: {},
30+
ranges: true,
31+
features: {
32+
'es7.classProperties': true
33+
},
3134
plugins: {
3235
jsx: true,
3336
flow: true

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ Returns **Number** numberone
6565

6666

6767

68+
69+
# staticProp
70+
71+
This is a property of the sink.
72+
73+

test/fixture/es6-import.output.json

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"column": 0
2020
},
2121
"end": {
22-
"line": 33,
22+
"line": 38,
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 * 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\nexport default multiply;\n"
2727
},
2828
"errors": [],
2929
"name": "Sink",
@@ -56,26 +56,26 @@
5656
],
5757
"loc": {
5858
"start": {
59-
"line": 25,
59+
"line": 30,
6060
"column": 2
6161
},
6262
"end": {
63-
"line": 28,
63+
"line": 33,
6464
"column": 5
6565
}
6666
},
6767
"context": {
6868
"loc": {
6969
"start": {
70-
"line": 29,
70+
"line": 34,
7171
"column": 2
7272
},
7373
"end": {
74-
"line": 32,
74+
"line": 37,
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 * 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\nexport default multiply;\n"
7979
},
8080
"errors": [],
8181
"params": [
@@ -118,26 +118,26 @@
118118
"tags": [],
119119
"loc": {
120120
"start": {
121-
"line": 11,
121+
"line": 16,
122122
"column": 2
123123
},
124124
"end": {
125-
"line": 13,
125+
"line": 18,
126126
"column": 5
127127
}
128128
},
129129
"context": {
130130
"loc": {
131131
"start": {
132-
"line": 14,
132+
"line": 19,
133133
"column": 2
134134
},
135135
"end": {
136-
"line": 16,
136+
"line": 21,
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 * 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\nexport default multiply;\n"
141141
},
142142
"errors": [],
143143
"name": "empty",
@@ -160,26 +160,26 @@
160160
"tags": [],
161161
"loc": {
162162
"start": {
163-
"line": 18,
163+
"line": 23,
164164
"column": 2
165165
},
166166
"end": {
167-
"line": 20,
167+
"line": 25,
168168
"column": 5
169169
}
170170
},
171171
"context": {
172172
"loc": {
173173
"start": {
174-
"line": 21,
174+
"line": 26,
175175
"column": 2
176176
},
177177
"end": {
178-
"line": 23,
178+
"line": 28,
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 * 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\nexport default multiply;\n"
183183
},
184184
"errors": [],
185185
"name": "hello",
@@ -235,7 +235,7 @@
235235
"column": 31
236236
}
237237
},
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 * 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"
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"
239239
},
240240
"errors": [],
241241
"returns": [
@@ -335,5 +335,41 @@
335335
"path": [
336336
"multiplyTwice"
337337
]
338+
},
339+
{
340+
"description": "This is a property of the sink.",
341+
"tags": [],
342+
"loc": {
343+
"start": {
344+
"line": 11,
345+
"column": 2
346+
},
347+
"end": {
348+
"line": 13,
349+
"column": 5
350+
}
351+
},
352+
"context": {
353+
"loc": {
354+
"start": {
355+
"line": 14,
356+
"column": 2
357+
},
358+
"end": {
359+
"line": 14,
360+
"column": 18
361+
}
362+
},
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"
364+
},
365+
"errors": [],
366+
"name": "staticProp",
367+
"members": {
368+
"instance": [],
369+
"static": []
370+
},
371+
"path": [
372+
"staticProp"
373+
]
338374
}
339375
]

test/fixture/es6-import.output.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ Returns **Number** numberone
6565

6666

6767

68+
69+
# staticProp
70+
71+
This is a property of the sink.
72+
73+

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,67 @@
812812
]
813813
}
814814
]
815+
},
816+
{
817+
"type": "root",
818+
"children": [
819+
{
820+
"depth": 1,
821+
"type": "heading",
822+
"children": [
823+
{
824+
"type": "text",
825+
"value": "staticProp"
826+
}
827+
]
828+
},
829+
{
830+
"type": "root",
831+
"children": [
832+
{
833+
"type": "paragraph",
834+
"children": [
835+
{
836+
"type": "text",
837+
"value": "This is a property of the sink.",
838+
"position": {
839+
"start": {
840+
"line": 1,
841+
"column": 1
842+
},
843+
"end": {
844+
"line": 1,
845+
"column": 32
846+
},
847+
"indent": []
848+
}
849+
}
850+
],
851+
"position": {
852+
"start": {
853+
"line": 1,
854+
"column": 1
855+
},
856+
"end": {
857+
"line": 1,
858+
"column": 32
859+
},
860+
"indent": []
861+
}
862+
}
863+
],
864+
"position": {
865+
"start": {
866+
"line": 1,
867+
"column": 1
868+
},
869+
"end": {
870+
"line": 1,
871+
"column": 32
872+
}
873+
}
874+
}
875+
]
815876
}
816877
]
817878
}

test/fixture/es6.input.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ var multiply = (a, b) => a * b;
88
* This is a sink
99
*/
1010
class Sink {
11+
/**
12+
* This is a property of the sink.
13+
*/
14+
staticProp = 42;
15+
1116
/**
1217
* Is it empty
1318
*/

test/fixture/es6.output.custom.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ Returns **Number** numberone
4949

5050

5151

52+
53+
# staticProp
54+
55+
This is a property of the sink.
56+
57+

0 commit comments

Comments
 (0)