Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(ts-estree): convert decorators on var and fn decs #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions 92 packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91249,6 +91249,43 @@ Object {
],
"type": "BlockStatement",
},
"decorators": Array [
Object {
"expression": Object {
"loc": Object {
"end": Object {
"column": 4,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"name": "dec",
"range": Array [
1,
4,
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 4,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
4,
],
"type": "Decorator",
},
],
"expression": false,
"generator": false,
"id": Object {
Expand Down Expand Up @@ -91791,6 +91828,61 @@ Object {
"type": "VariableDeclarator",
},
],
"decorators": Array [
Object {
"expression": Object {
"arguments": Array [],
"callee": Object {
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"name": "deco",
"range": Array [
1,
5,
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"range": Array [
1,
7,
],
"type": "CallExpression",
},
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
7,
],
"type": "Decorator",
},
],
"kind": "const",
"loc": Object {
"end": Object {
Expand Down
22 changes: 22 additions & 0 deletions 22 packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,17 @@ export class Converter {
);
}

/**
* Semantically, decorators are not allowed on function declarations,
* but the TypeScript compiler will parse them and produce a valid AST,
* so we handle them here too.
*/
if (node.decorators) {
(result as any).decorators = node.decorators.map(el =>
armano2 marked this conversation as resolved.
Show resolved Hide resolved
this.convertChild(el)
);
}

// check for exports
return fixExports(node, result, this.ast);
}
Expand Down Expand Up @@ -730,6 +741,17 @@ export class Converter {
kind: getDeclarationKind(node.declarationList)
});

/**
* Semantically, decorators are not allowed on variable declarations,
* but the TypeScript compiler will parse them and produce a valid AST,
* so we handle them here too.
*/
if (node.decorators) {
(result as any).decorators = node.decorators.map(el =>
this.convertChild(el)
);
}

if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
result.declare = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90557,6 +90557,43 @@ Object {
],
"type": "BlockStatement",
},
"decorators": Array [
Object {
"expression": Object {
"loc": Object {
"end": Object {
"column": 4,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"name": "dec",
"range": Array [
1,
4,
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 4,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
4,
],
"type": "Decorator",
},
],
"expression": false,
"generator": false,
"id": Object {
Expand Down Expand Up @@ -91097,6 +91134,61 @@ Object {
"type": "VariableDeclarator",
},
],
"decorators": Array [
Object {
"expression": Object {
"arguments": Array [],
"callee": Object {
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"name": "deco",
"range": Array [
1,
5,
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 1,
"line": 1,
},
},
"range": Array [
1,
7,
],
"type": "CallExpression",
},
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
7,
],
"type": "Decorator",
},
],
"kind": "const",
"loc": Object {
"end": Object {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.