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

Commit

Permalink
New: Add param decorators to the AST (fixes #68) (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and nzakas committed Aug 25, 2016
1 parent 8b97fe7 commit 328259f
Show file tree
Hide file tree
Showing 14 changed files with 3,359 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ coverage
node_modules
npm-debug.log
_test.js

.DS_Store
26 changes: 24 additions & 2 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ module.exports = function(ast, extra) {
method = {
type: "FunctionExpression",
id: null,
params: node.parameters.map(convertChild),
generator: false,
expression: false,
body: convertChild(node.body),
Expand All @@ -975,6 +974,9 @@ module.exports = function(ast, extra) {
}

if (parent.kind === SyntaxKind.ObjectLiteralExpression) {

method.params = node.parameters.map(convertChild);

assign(result, {
type: "Property",
key: convertChild(node.name),
Expand All @@ -986,7 +988,20 @@ module.exports = function(ast, extra) {
});

} else { // class

/**
* Unlinke in object literal methods, class method params can have decorators
*/
method.params = node.parameters.map(function(param) {
var convertedParam = convertChild(param);
convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) {
return convertChild(d.expression);
}) : [];
return convertedParam;
});

var methodNameIsComputed = (node.name.kind === SyntaxKind.ComputedPropertyName);

assign(result, {
type: "MethodDefinition",
key: convertChild(node.name),
Expand All @@ -998,6 +1013,7 @@ module.exports = function(ast, extra) {
return convertChild(d.expression);
}) : []
});

}

if (node.kind === SyntaxKind.GetAccessor) {
Expand All @@ -1020,7 +1036,13 @@ module.exports = function(ast, extra) {
constructor = {
type: "FunctionExpression",
id: null,
params: node.parameters.map(convertChild),
params: node.parameters.map(function(param) {
var convertedParam = convertChild(param);
convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) {
return convertChild(d.expression);
}) : [];
return convertedParam;
}),
generator: false,
expression: false,
body: convertChild(node.body),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ module.exports = {
25,
26
],
"name": "c"
"name": "c",
"decorators": []
}
],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ module.exports = {
52,
53
],
"name": "b"
"name": "b",
"decorators": []
}
],
"body": {
Expand Down
Loading

0 comments on commit 328259f

Please sign in to comment.