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

Commit

Permalink
feat: update TSIndexSignature and report on TS1071 (#115)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This changes the AST for TSIndexSignature node
  • Loading branch information
armano2 authored and JamesHenry committed Jan 12, 2019
1 parent 9298d8f commit d3a0c03
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 373 deletions.
3 changes: 1 addition & 2 deletions src/ast-node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export enum AST_NODE_TYPES {
ForStatement = 'ForStatement',
FunctionDeclaration = 'FunctionDeclaration',
FunctionExpression = 'FunctionExpression',
GenericTypeAnnotation = 'GenericTypeAnnotation',
Identifier = 'Identifier',
IfStatement = 'IfStatement',
Import = 'Import',
Expand All @@ -56,7 +55,7 @@ export enum AST_NODE_TYPES {
JSXFragment = 'JSXFragment',
JSXIdentifier = 'JSXIdentifier',
JSXMemberExpression = 'JSXMemberExpression',
JSXNamespacedName = 'JSXNamespacedName',
JSXNamespacedName = 'JSXNamespacedName', // https://github.com/Microsoft/TypeScript/issues/7411
JSXOpeningElement = 'JSXOpeningElement',
JSXOpeningFragment = 'JSXOpeningFragment',
JSXSpreadAttribute = 'JSXSpreadAttribute',
Expand Down
20 changes: 13 additions & 7 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2418,20 +2418,26 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
case SyntaxKind.IndexSignature: {
Object.assign(result, {
type: AST_NODE_TYPES.TSIndexSignature,
index: convertChild(node.parameters[0]),
typeAnnotation: node.type ? convertTypeAnnotation(node.type) : null,
readonly:
nodeUtils.hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
static: nodeUtils.hasModifier(SyntaxKind.StaticKeyword, node),
export:
nodeUtils.hasModifier(SyntaxKind.ExportKeyword, node) || undefined
parameters: node.parameters.map(convertChild),
typeAnnotation: node.type ? convertTypeAnnotation(node.type) : null
});

if (nodeUtils.hasModifier(SyntaxKind.ReadonlyKeyword, node)) {
result.readonly = true;
}

const accessibility = nodeUtils.getTSNodeAccessibility(node);
if (accessibility) {
result.accessibility = accessibility;
}

if (nodeUtils.hasModifier(SyntaxKind.ExportKeyword, node)) {
result.export = true;
}

if (nodeUtils.hasModifier(SyntaxKind.StaticKeyword, node)) {
result.static = true;
}
break;
}
case SyntaxKind.ConstructorType:
Expand Down
1 change: 1 addition & 0 deletions src/semantic-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function whitelistSupportedDiagnostics(
case 1048: // ts 3.2 "A rest parameter cannot have an initializer."
case 1049: // ts 3.2 "A 'set' accessor must have exactly one parameter."
case 1070: // ts 3.2 "'{0}' modifier cannot appear on a type member."
case 1071: // ts 3.2 "'{0}' modifier cannot appear on an index signature."
case 1090: // ts 3.2 "'{0}' modifier cannot appear on a parameter."
case 1096: // ts 3.2 "An index signature must have exactly one parameter."
case 1097: // ts 3.2 "'{0}' list cannot be empty."
Expand Down
17 changes: 7 additions & 10 deletions tests/ast-alignment/fixtures-to-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,26 +468,23 @@ tester.addFixturePatternConfig('typescript/errorRecovery', {
* TODO: remove me in next babel > 7.2.3
*/
'interface-empty-extends',
'class-extends-empty-implements',
/**
* TS1071
*/
'interface-index-signature-export',
'interface-index-signature-private',
'interface-index-signature-protected',
'interface-index-signature-public',
'interface-index-signature-static'
'class-extends-empty-implements'
]
});

tester.addFixturePatternConfig('typescript/types', {
fileType: 'ts',
ignore: [
/**
* AST difference
* Babel bug for range of Identifier in TSIndexSignature
* https://github.com/babel/babel/issues/9319
*/
'index-signature',
'index-signature-readonly',
'index-signature-without-type',
/**
* AST difference
*/
'literal-number-negative'
]
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type foo = {
[a: string];
}
47 changes: 42 additions & 5 deletions tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2212,15 +2212,50 @@ Object {
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-export.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-export.src.ts.src 1`] = `
Object {
"column": 2,
"index": 18,
"lineNumber": 2,
"message": "'export' modifier cannot appear on an index signature.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-private.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-private.src.ts.src 1`] = `
Object {
"column": 2,
"index": 18,
"lineNumber": 2,
"message": "'private' modifier cannot appear on an index signature.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-protected.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-protected.src.ts.src 1`] = `
Object {
"column": 2,
"index": 18,
"lineNumber": 2,
"message": "'protected' modifier cannot appear on an index signature.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-public.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-public.src.ts.src 1`] = `
Object {
"column": 2,
"index": 18,
"lineNumber": 2,
"message": "'public' modifier cannot appear on an index signature.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-static.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-index-signature-static.src.ts.src 1`] = `
Object {
"column": 2,
"index": 18,
"lineNumber": 2,
"message": "'static' modifier cannot appear on an index signature.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-method-export.src.ts.src 1`] = `
Object {
Expand Down Expand Up @@ -2382,6 +2417,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/index-signature-readonly.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/index-signature-without-type.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/indexed.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/intersection-type.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Loading

0 comments on commit d3a0c03

Please sign in to comment.