diff --git a/tests/fixtures/parsers/typescript-parsers/type-alias.js b/tests/fixtures/parsers/typescript-parsers/type-alias.js new file mode 100644 index 00000000000..f1d68c48694 --- /dev/null +++ b/tests/fixtures/parsers/typescript-parsers/type-alias.js @@ -0,0 +1,155 @@ +"use strict"; + +exports.parse = () => ({ + type: "Program", + range: [0, 16], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 16 } + }, + body: [ + { + type: "VariableDeclaration", + range: [0, 16], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 16 } + }, + kind: "type", + declarations: [ + { + type: "VariableDeclarator", + id: { + type: "Identifier", + range: [ + 5, + 8 + ], + loc: { + start: { line: 1, column: 5 }, + end: { line: 1, column: 8 } + }, + name: "Foo" + }, + init: { + type: "TSTypeReference", + range: [14, 15], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 15 } + }, + typeName: { + type: "Identifier", + range: [14, 15], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 15 } + }, + name: "T" + } + }, + range: [5, 16], + loc: { + start: { line: 1, column: 5 }, + end: { line: 1, column: 16 } + }, + typeParameters: { + type: "TSTypeParameterDeclaration", + range: [8, 11], + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 11 } + }, + params: [ + { + type: "TSTypeParameter", + range: [9, 10], + loc: { + start: { line: 1, column: 9 }, + end: { line: 1, column: 10 } + }, + name: "T" + } + ] + } + } + ] + } + ], + sourceType: "script", + tokens: [ + { + type: "Identifier", + value: "type", + range: [0, 4], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 4 } + } + }, + { + type: "Identifier", + value: "Foo", + range: [5, 8], + loc: { + start: { line: 1, column: 5 }, + end: { line: 1, column: 8 } + } + }, + { + type: "Punctuator", + value: "<", + range: [8, 9], + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 9 } + } + }, + { + type: "Identifier", + value: "T", + range: [9, 10], + loc: { + start: { line: 1, column: 9 }, + end: { line: 1, column: 10 } + } + }, + { + type: "Punctuator", + value: ">", + range: [10, 11], + loc: { + start: { line: 1, column: 10 }, + end: { line: 1, column: 11 } + } + }, + { + type: "Punctuator", + value: "=", + range: [12, 13], + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 13 } + } + }, + { + type: "Identifier", + value: "T", + range: [14, 15], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 15 } + } + }, + { + type: "Punctuator", + value: ";", + range: [15, 16], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 16 } + } + } + ], + comments: [] +}) diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index 57e28addcbb..34eada46e42 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -44,7 +44,10 @@ ruleTester.run("space-infix-ops", rule, { { code: "function foo(a: number = 0) { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-parameter-type-annotation") }, { code: "function foo(): Bar { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-return-type-annotation") }, { code: "var foo: Bar = '';", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/variable-declaration-init-type-annotation") }, - { code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") } + { code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") }, + + // TypeScript Type Aliases + { code: "type Foo = T;", parserOptions: { ecmaVersion: 6 }, parser: parser("typescript-parsers/type-alias") } ], invalid: [ {