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

Commit 8b97fe7

Browse files
JamesHenrynzakas
authored andcommitted
New: Add class decorators to AST (fixes #66) (#67)
1 parent 7364cb9 commit 8b97fe7

File tree

49 files changed

+715
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+715
-12
lines changed

lib/ast-converter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,10 @@ module.exports = function(ast, extra) {
13171317
loc: getLocFor(openBrace.getStart(), node.end, ast)
13181318
},
13191319
superClass: (superClass ? convertChild(superClass.types[0].expression) : null),
1320-
implements: hasImplements ? heritageClauses[0].types.map(convertClassImplements) : []
1320+
implements: hasImplements ? heritageClauses[0].types.map(convertClassImplements) : [],
1321+
decorators: (node.decorators) ? node.decorators.map(function(d) {
1322+
return convertChild(d.expression);
1323+
}) : []
13211324
});
13221325

13231326
var filteredMembers = node.members.filter(isESTreeClassMember);

tests/fixtures/attach-comments/export-default-anonymous-class.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportDefaultDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": null,
910
"superClass": null,
1011
"implements": [],

tests/fixtures/ecma-features-mix/classes-and-generators/classes-and-generators.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
"body": [
44
{
55
"type": "ClassDeclaration",
6+
"decorators": [],
67
"id": {
78
"type": "Identifier",
89
"name": "Foo",
@@ -331,4 +332,4 @@ module.exports = {
331332
}
332333
}
333334
]
334-
};
335+
};

tests/fixtures/ecma-features-mix/classes-and-generators/computed-generator.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
"body": [
44
{
55
"type": "ClassDeclaration",
6+
"decorators": [],
67
"id": {
78
"type": "Identifier",
89
"name": "Foo",

tests/fixtures/ecma-features-mix/classes-and-generators/static-generators.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
"body": [
44
{
55
"type": "ClassDeclaration",
6+
"decorators": [],
67
"id": {
78
"type": "Identifier",
89
"name": "Foo",
@@ -349,4 +350,4 @@ module.exports = {
349350
}
350351
}
351352
]
352-
};
353+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default-anonymous-extends.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportDefaultDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": null,
910
"superClass": {
1011
"type": "Identifier",
@@ -251,4 +252,4 @@ module.exports = {
251252
}
252253
}
253254
]
254-
};
255+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default-anonymous.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportDefaultDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": null,
910
"superClass": null,
1011
"body": {
@@ -198,4 +199,4 @@ module.exports = {
198199
}
199200
}
200201
]
201-
};
202+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default-extends.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportDefaultDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": {
910
"type": "Identifier",
1011
"name": "foo",
@@ -286,4 +287,4 @@ module.exports = {
286287
}
287288
}
288289
]
289-
};
290+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-default.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportDefaultDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": {
910
"type": "Identifier",
1011
"name": "foo",
@@ -233,4 +234,4 @@ module.exports = {
233234
}
234235
}
235236
]
236-
};
237+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class-extends.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportNamedDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": {
910
"type": "Identifier",
1011
"name": "foo",
@@ -270,4 +271,4 @@ module.exports = {
270271
}
271272
}
272273
]
273-
};
274+
};

tests/fixtures/ecma-features-mix/modules-and-classes/class.result.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"type": "ExportNamedDeclaration",
66
"declaration": {
77
"type": "ClassDeclaration",
8+
"decorators": [],
89
"id": {
910
"type": "Identifier",
1011
"name": "foo",
@@ -217,4 +218,4 @@ module.exports = {
217218
}
218219
}
219220
]
220-
};
221+
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-computed-static-method.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-expression.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
],
3434
"expression": {
3535
"type": "ClassExpression",
36+
"decorators": [],
3637
"loc": {
3738
"start": {
3839
"line": 1,

tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-method-named-static.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-one-method-super.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-one-method.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-static-method.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-methods.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/class-with-constructor.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/derived-class-assign-to-var.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = {
6868
},
6969
"init": {
7070
"type": "ClassExpression",
71+
"decorators": [],
7172
"loc": {
7273
"start": {
7374
"line": 1,

tests/fixtures/ecma-features/classes/derived-class-expression.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
],
3434
"expression": {
3535
"type": "ClassExpression",
36+
"decorators": [],
3637
"loc": {
3738
"start": {
3839
"line": 1,

tests/fixtures/ecma-features/classes/empty-class-double-semi.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/empty-class-semi.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/empty-class.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/empty-literal-derived-class.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"body": [
1818
{
1919
"type": "ClassDeclaration",
20+
"decorators": [],
2021
"loc": {
2122
"start": {
2223
"line": 1,

tests/fixtures/ecma-features/classes/named-class-expression.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
],
3434
"expression": {
3535
"type": "ClassExpression",
36+
"decorators": [],
3637
"loc": {
3738
"start": {
3839
"line": 1,

tests/fixtures/ecma-features/classes/named-derived-class-expression.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
],
3434
"expression": {
3535
"type": "ClassExpression",
36+
"decorators": [],
3637
"loc": {
3738
"start": {
3839
"line": 1,

tests/fixtures/typescript/basics/class-with-implements-generic-multiple.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
"column": 1
3232
}
3333
},
34+
"decorators": [],
3435
"id": {
3536
"type": "Identifier",
3637
"range": [

tests/fixtures/typescript/basics/class-with-implements-generic.result.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
"column": 1
3232
}
3333
},
34+
"decorators": [],
3435
"id": {
3536
"type": "Identifier",
3637
"range": [
@@ -153,7 +154,7 @@ module.exports = {
153154
}
154155
},
155156
"name": "S"
156-
},
157+
}
157158
}
158159
]
159160
}
@@ -326,4 +327,4 @@ module.exports = {
326327
}
327328
}
328329
]
329-
};
330+
};

0 commit comments

Comments
 (0)