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

Commit

Permalink
New: Add class decorators to AST (fixes #66) (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and nzakas committed Aug 25, 2016
1 parent 7364cb9 commit 8b97fe7
Show file tree
Hide file tree
Showing 49 changed files with 715 additions and 12 deletions.
5 changes: 4 additions & 1 deletion lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,10 @@ module.exports = function(ast, extra) {
loc: getLocFor(openBrace.getStart(), node.end, ast)
},
superClass: (superClass ? convertChild(superClass.types[0].expression) : null),
implements: hasImplements ? heritageClauses[0].types.map(convertClassImplements) : []
implements: hasImplements ? heritageClauses[0].types.map(convertClassImplements) : [],
decorators: (node.decorators) ? node.decorators.map(function(d) {
return convertChild(d.expression);
}) : []
});

var filteredMembers = node.members.filter(isESTreeClassMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": null,
"superClass": null,
"implements": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "Foo",
Expand Down Expand Up @@ -331,4 +332,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "Foo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "Foo",
Expand Down Expand Up @@ -349,4 +350,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": null,
"superClass": {
"type": "Identifier",
Expand Down Expand Up @@ -251,4 +252,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand Down Expand Up @@ -198,4 +199,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "foo",
Expand Down Expand Up @@ -286,4 +287,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "foo",
Expand Down Expand Up @@ -233,4 +234,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportNamedDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "foo",
Expand Down Expand Up @@ -270,4 +271,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"type": "ExportNamedDeclaration",
"declaration": {
"type": "ClassDeclaration",
"decorators": [],
"id": {
"type": "Identifier",
"name": "foo",
Expand Down Expand Up @@ -217,4 +218,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
],
"expression": {
"type": "ClassExpression",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
},
"init": {
"type": "ClassExpression",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
],
"expression": {
"type": "ClassExpression",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/classes/empty-class.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"body": [
{
"type": "ClassDeclaration",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
],
"expression": {
"type": "ClassExpression",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
],
"expression": {
"type": "ClassExpression",
"decorators": [],
"loc": {
"start": {
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
"column": 1
}
},
"decorators": [],
"id": {
"type": "Identifier",
"range": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
"column": 1
}
},
"decorators": [],
"id": {
"type": "Identifier",
"range": [
Expand Down Expand Up @@ -153,7 +154,7 @@ module.exports = {
}
},
"name": "S"
},
}
}
]
}
Expand Down Expand Up @@ -326,4 +327,4 @@ module.exports = {
}
}
]
};
};
Loading

0 comments on commit 8b97fe7

Please sign in to comment.