Skip to content

Commit

Permalink
chore: make EnumMember.computed optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Dec 19, 2019
1 parent 3a8d6db commit e91a7fe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
4 changes: 3 additions & 1 deletion packages/typescript-estree/src/convert.ts
Expand Up @@ -2485,11 +2485,13 @@ export class Converter {
const result = this.createNode<TSESTree.TSEnumMember>(node, {
type: AST_NODE_TYPES.TSEnumMember,
id: this.convertChild(node.name),
computed: node.name.kind === ts.SyntaxKind.ComputedPropertyName,
});
if (node.initializer) {
result.initializer = this.convertChild(node.initializer);
}
if (node.name.kind === ts.SyntaxKind.ComputedPropertyName) {
result.computed = true;
}
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-estree/src/ts-estree/ts-estree.ts
Expand Up @@ -625,7 +625,7 @@ interface TSEnumMemberBase extends BaseNode {
type: AST_NODE_TYPES.TSEnumMember;
id:
| PropertyNameNonComputed
// this should only happen in semantically invalid code (errors 1164 and 2452)
// this should only happen in semantically invalid code (ts error 1164)
| PropertyNameComputed;
initializer?: Expression;
computed?: boolean;
Expand Down Expand Up @@ -1291,7 +1291,7 @@ export interface TSEnumMemberComputedName extends TSEnumMemberBase {

export interface TSEnumMemberNonComputedName extends TSEnumMemberBase {
id: PropertyNameNonComputed;
computed: false;
computed?: false;
}

export interface TSExportAssignment extends BaseNode {
Expand Down
Expand Up @@ -616,11 +616,6 @@ tester.addFixturePatternConfig('typescript/basics', {
'class-with-readonly-property',
'object-with-escaped-properties',
'type-reference-comments',
// babel doesn't allow computed enum members
'const-enum',
'export-declare-const-named-enum',
'export-declare-named-enum',
'export-named-enum',
],
ignoreSourceType: [
/**
Expand Down Expand Up @@ -764,10 +759,6 @@ tester.addFixturePatternConfig('typescript/types', {

tester.addFixturePatternConfig('typescript/declare', {
fileType: 'ts',
ignore: [
// babel doesn't allow computed enum members
'enum',
],
});

tester.addFixturePatternConfig('typescript/namespaces-and-modules', {
Expand Down
Expand Up @@ -37483,7 +37483,6 @@ Object {
},
"members": Array [
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -37538,7 +37537,6 @@ Object {
"type": "TSEnumMember",
},
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -43244,7 +43242,6 @@ Object {
},
"members": Array [
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -43299,7 +43296,6 @@ Object {
"type": "TSEnumMember",
},
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -43633,7 +43629,6 @@ Object {
},
"members": Array [
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -43688,7 +43683,6 @@ Object {
"type": "TSEnumMember",
},
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -45291,7 +45285,6 @@ Object {
},
"members": Array [
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -45346,7 +45339,6 @@ Object {
"type": "TSEnumMember",
},
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -107153,7 +107145,6 @@ Object {
},
"members": Array [
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -107189,7 +107180,6 @@ Object {
"type": "TSEnumMember",
},
Object {
"computed": false,
"id": Object {
"loc": Object {
"end": Object {
Expand Down

0 comments on commit e91a7fe

Please sign in to comment.