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

refactor(ts-estree): improve definition of parameters #209

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 1 commit into from
Feb 5, 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
4,876 changes: 3,533 additions & 1,343 deletions 4,876 packages/parser/tests/lib/__snapshots__/typescript.ts.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo {
bar(@special(true) [ bar ]: any) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo {
bar(@special(true) { bar }: any) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo {
bar(@special(true) ...foo: any) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@dec
function b(){}
15 changes: 8 additions & 7 deletions 15 packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,19 @@ export class Converter {
*/
private convertParameters(
parameters: ts.NodeArray<ts.ParameterDeclaration>
): (es.TSParameterProperty | es.RestElement | es.AssignmentPattern)[] {
): es.Parameter[] {
if (!parameters || !parameters.length) {
return [];
}
return parameters.map(param => {
const convertedParam = this.convertChild(param);
if (!param.decorators || !param.decorators.length) {
return convertedParam;
const convertedParam = this.convertChild(param) as es.Parameter;

if (param.decorators && param.decorators.length) {
convertedParam.decorators = param.decorators.map(el =>
this.convertChild(el)
);
}
return Object.assign(convertedParam, {
decorators: param.decorators.map(el => this.convertChild(el))
});
return convertedParam;
});
}

Expand Down
14 changes: 13 additions & 1 deletion 14 packages/typescript-estree/src/typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,13 @@ export type ObjectLiteralElementLike =
| RestElement
| SpreadElement
| TSAbstractMethodDefinition;
export type Parameter = AssignmentPattern | RestElement | TSParameterProperty;
export type Parameter =
| AssignmentPattern
| RestElement
| ArrayPattern
| ObjectPattern
| Identifier
| TSParameterProperty;
export type PrimaryExpression =
| ArrayExpression
| ArrayPattern
Expand Down Expand Up @@ -541,6 +547,7 @@ export interface ArrayPattern extends BaseNode {
elements: Expression[];
typeAnnotation?: TSTypeAnnotation;
optional?: boolean;
decorators?: Decorator[];
}

export interface ArrowFunctionExpression extends BaseNode {
Expand All @@ -565,6 +572,7 @@ export interface AssignmentPattern extends BaseNode {
right?: Expression;
typeAnnotation?: TSTypeAnnotation;
optional?: boolean;
decorators?: Decorator[];
}

export interface AwaitExpression extends BaseNode {
Expand Down Expand Up @@ -715,6 +723,7 @@ export interface Identifier extends BaseNode {
name: string;
typeAnnotation?: TSTypeAnnotation;
optional?: boolean;
decorators?: Decorator[];
}

export interface IfStatement extends BaseNode {
Expand Down Expand Up @@ -875,6 +884,7 @@ export interface ObjectPattern extends BaseNode {
properties: ObjectLiteralElementLike[];
typeAnnotation?: TSTypeAnnotation;
optional?: boolean;
decorators?: Decorator[];
}

export interface Program extends BaseNode {
Expand All @@ -901,6 +911,7 @@ export interface RestElement extends BaseNode {
typeAnnotation?: TSTypeAnnotation;
optional?: boolean;
value?: AssignmentPattern;
decorators?: Decorator[];
}

export interface ReturnStatement extends BaseNode {
Expand Down Expand Up @@ -1218,6 +1229,7 @@ export interface TSParameterProperty extends BaseNode {
static?: boolean;
export?: boolean;
parameter: AssignmentPattern | BindingName | RestElement;
decorators?: Decorator[];
}

export interface TSParenthesizedType extends BaseNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,15 @@ tester.addFixturePatternConfig('typescript/decorators/method-decorators', {
fileType: 'ts'
});
tester.addFixturePatternConfig('typescript/decorators/parameter-decorators', {
fileType: 'ts'
fileType: 'ts',
ignore: [
/**
* babel does not support decorators on array and rest parameters
* TODO: report this to babel
*/
'parameter-array-pattern-decorator',
'parameter-rest-element-decorator'
]
});
tester.addFixturePatternConfig('typescript/decorators/property-decorators', {
fileType: 'ts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand All @@ -2246,6 +2248,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/property-decorators/property-decorator-factory-instance-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/property-decorators/property-decorator-factory-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down Expand Up @@ -2299,6 +2305,15 @@ Object {
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-function.src 1`] = `
Object {
"column": 0,
"index": 0,
"lineNumber": 1,
"message": "Decorators are not valid here.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-interface-declaration.src 1`] = `
Object {
"column": 0,
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.