Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 328259f

Browse files
JamesHenrynzakas
authored andcommitted
New: Add param decorators to the AST (fixes #68) (#69)
1 parent 8b97fe7 commit 328259f

14 files changed

+3359
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ coverage
33
node_modules
44
npm-debug.log
55
_test.js
6-
6+
.DS_Store

lib/ast-converter.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ module.exports = function(ast, extra) {
956956
method = {
957957
type: "FunctionExpression",
958958
id: null,
959-
params: node.parameters.map(convertChild),
960959
generator: false,
961960
expression: false,
962961
body: convertChild(node.body),
@@ -975,6 +974,9 @@ module.exports = function(ast, extra) {
975974
}
976975

977976
if (parent.kind === SyntaxKind.ObjectLiteralExpression) {
977+
978+
method.params = node.parameters.map(convertChild);
979+
978980
assign(result, {
979981
type: "Property",
980982
key: convertChild(node.name),
@@ -986,7 +988,20 @@ module.exports = function(ast, extra) {
986988
});
987989

988990
} else { // class
991+
992+
/**
993+
* Unlinke in object literal methods, class method params can have decorators
994+
*/
995+
method.params = node.parameters.map(function(param) {
996+
var convertedParam = convertChild(param);
997+
convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) {
998+
return convertChild(d.expression);
999+
}) : [];
1000+
return convertedParam;
1001+
});
1002+
9891003
var methodNameIsComputed = (node.name.kind === SyntaxKind.ComputedPropertyName);
1004+
9901005
assign(result, {
9911006
type: "MethodDefinition",
9921007
key: convertChild(node.name),
@@ -998,6 +1013,7 @@ module.exports = function(ast, extra) {
9981013
return convertChild(d.expression);
9991014
}) : []
10001015
});
1016+
10011017
}
10021018

10031019
if (node.kind === SyntaxKind.GetAccessor) {
@@ -1020,7 +1036,13 @@ module.exports = function(ast, extra) {
10201036
constructor = {
10211037
type: "FunctionExpression",
10221038
id: null,
1023-
params: node.parameters.map(convertChild),
1039+
params: node.parameters.map(function(param) {
1040+
var convertedParam = convertChild(param);
1041+
convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) {
1042+
return convertChild(d.expression);
1043+
}) : [];
1044+
return convertedParam;
1045+
}),
10241046
generator: false,
10251047
expression: false,
10261048
body: convertChild(node.body),

tests/fixtures/ecma-features/classes/class-accessor-properties.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ module.exports = {
221221
25,
222222
26
223223
],
224-
"name": "c"
224+
"name": "c",
225+
"decorators": []
225226
}
226227
],
227228
"body": {

tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ module.exports = {
299299
52,
300300
53
301301
],
302-
"name": "b"
302+
"name": "b",
303+
"decorators": []
303304
}
304305
],
305306
"body": {

0 commit comments

Comments
 (0)