Skip to content

feat(typescript-estree): add support for declare class properties #1136

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
Oct 24, 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
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default util.createRule<Options, MessageIds>({
type,
static: false,
readonly: false,
declare: false,
...base,
} as TSESTree.ClassProperty;
}
Expand Down
330 changes: 330 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,171 @@ Object {
}
`;

exports[`typescript fixtures/basics/abstract-class-with-declare-properties.src 1`] = `
Object {
"$id": 4,
"block": Object {
"range": Array [
0,
230,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
230,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
229,
],
"type": "ClassDeclaration",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "class",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {
"AbstractDeclProps": Object {
"$ref": 1,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 1,
"defs": Array [
Object {
"name": Object {
"name": "AbstractDeclProps",
"range": Array [
15,
32,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
229,
],
"type": "ClassDeclaration",
},
"parent": undefined,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "AbstractDeclProps",
"range": Array [
15,
32,
],
"type": "Identifier",
},
],
"name": "AbstractDeclProps",
"references": Array [],
"scope": Object {
"$ref": 2,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "module",
"upperScope": Object {
"$ref": 4,
},
"variableMap": Object {
"AbstractDeclProps": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "AbstractDeclProps",
"range": Array [
15,
32,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
229,
],
"type": "ClassDeclaration",
},
"parent": null,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "AbstractDeclProps",
"range": Array [
15,
32,
],
"type": "Identifier",
},
],
"name": "AbstractDeclProps",
"references": Array [],
"scope": Object {
"$ref": 3,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 4,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/abstract-class-with-optional-method.src 1`] = `
Object {
"$id": 4,
Expand Down Expand Up @@ -4605,6 +4770,171 @@ Object {
}
`;

exports[`typescript fixtures/basics/class-with-declare-properties.src 1`] = `
Object {
"$id": 4,
"block": Object {
"range": Array [
0,
271,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
271,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
270,
],
"type": "ClassDeclaration",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "class",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {
"DeclProps": Object {
"$ref": 1,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 1,
"defs": Array [
Object {
"name": Object {
"name": "DeclProps",
"range": Array [
6,
15,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
270,
],
"type": "ClassDeclaration",
},
"parent": undefined,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "DeclProps",
"range": Array [
6,
15,
],
"type": "Identifier",
},
],
"name": "DeclProps",
"references": Array [],
"scope": Object {
"$ref": 2,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "module",
"upperScope": Object {
"$ref": 4,
},
"variableMap": Object {
"DeclProps": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "DeclProps",
"range": Array [
6,
15,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
270,
],
"type": "ClassDeclaration",
},
"parent": null,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "DeclProps",
"range": Array [
6,
15,
],
"type": "Identifier",
},
],
"name": "DeclProps",
"references": Array [],
"scope": Object {
"$ref": 3,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 4,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/class-with-definite-assignment.src 1`] = `
Object {
"$id": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract class AbstractDeclProps {
declare prop1: string;
declare abstract prop2: string;
declare public abstract prop3: string;
declare readonly abstract prop4: string;
declare public readonly abstract prop5: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DeclProps {
declare prop1: string;
declare public prop2: string;
declare static prop3: string;
declare readonly prop3: string;
declare public readonly prop4: string;
declare public static prop5: string;
declare public static readonly prop6: string;
}
1 change: 1 addition & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ export class Converter {
computed: isComputedProperty(node.name),
static: hasModifier(SyntaxKind.StaticKeyword, node),
readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
declare: hasModifier(SyntaxKind.DeclareKeyword, node),
});

if (node.type) {
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/ts-estree/ts-estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ interface ClassPropertyBase extends BaseNode {
value: Expression | null;
computed: boolean;
static: boolean;
declare: boolean;
readonly?: boolean;
decorators?: Decorator[];
accessibility?: Accessibility;
Expand Down
Loading