From 6e09c5daf1fdaf3c146fe71449c3309b451a7ae4 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 13 Dec 2017 11:01:25 +0000 Subject: [PATCH] Breaking: No prefix on FnDec within namespace (fixes #127) --- lib/convert.js | 7 ----- tests/ast-alignment/fixtures-to-test.js | 9 ++---- tests/integration/typescript.spec.js | 34 +++++++++++----------- tests/lib/__snapshots__/typescript.js.snap | 18 ++++++------ tools/test-utils.js | 2 +- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index db823d7..00eb207 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -622,13 +622,6 @@ module.exports = function convert(config) { } } - /** - * Prefix FunctionDeclarations within TypeScript namespaces with "TS" - */ - if (node.parent && node.parent.kind === SyntaxKind.ModuleBlock) { - functionDeclarationType = AST_NODE_TYPES.TSNamespaceFunctionDeclaration; - } - Object.assign(result, { type: functionDeclarationType, id: convertChild(node.name), diff --git a/tests/ast-alignment/fixtures-to-test.js b/tests/ast-alignment/fixtures-to-test.js index f2d19f6..e368c94 100644 --- a/tests/ast-alignment/fixtures-to-test.js +++ b/tests/ast-alignment/fixtures-to-test.js @@ -40,7 +40,7 @@ let fixturesRequiringSourceTypeModule = []; /** * Utility to generate a FixturePatternConfig object containing the glob pattern for specific subsections of the fixtures/ directory, * including the capability to ignore specific nested patterns. - * + * * @param {string} fixturesSubPath the sub-path within the fixtures/ directory * @param {Object?} config an optional configuration object with optional sub-paths to ignore and/or parse with sourceType: module * @returns {FixturePatternConfig} an object containing the glob pattern and optional additional config @@ -466,12 +466,7 @@ let fixturePatternConfigsToTest = [ * Babylon: TSDeclareFunction * tsep: TSNamespaceFunctionDeclaration */ - "declare-namespace-with-exported-function", - /** - * Babylon: FunctionDeclaration - * tsep: TSNamespaceFunctionDeclaration - */ - "module-with-default-exports" + "declare-namespace-with-exported-function" ] }) ]; diff --git a/tests/integration/typescript.spec.js b/tests/integration/typescript.spec.js index aa1e041..6a83a13 100644 --- a/tests/integration/typescript.spec.js +++ b/tests/integration/typescript.spec.js @@ -157,6 +157,23 @@ describe("TypeScript", () => { ); }); + it("should correctly apply no-unreachable on TS-constructs (#127)", () => { + verifyAndAssertMessages( + unpad(` + export namespace foo { + export function bar() { + return; + } + } + export type Qux = true; + `), + { + "no-unreachable": 2 + }, + [] + ); + }); + // it("should not produce a false positive for no-restricted-globals rule (#350)", () => { // verifyAndAssertMessages( // unpad(` @@ -171,23 +188,6 @@ describe("TypeScript", () => { // ); // }); - // it("should correctly apply no-unreachable on TS-constructs (#127)", () => { - // verifyAndAssertMessages( - // unpad(` - // export namespace foo { - // export function bar() { - // return; - // } - // } - // export type Qux = true; - // `), - // { - // "no-unreachable": 2 - // }, - // [] - // ); - // }); - // it("should not throw a TypeError in the indent rule for invalid code (#309)", () => { // verifyAndAssertMessages( // unpad(` diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 2ee0cc0..d4f07b2 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -1179,7 +1179,7 @@ Object { }, }, }, - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, ], @@ -2478,7 +2478,7 @@ Object { }, }, }, - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, ], @@ -12300,7 +12300,7 @@ Object { 18, 21, ], - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, Object { @@ -12396,7 +12396,7 @@ Object { "type": "TSStringKeyword", }, }, - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, Object { @@ -12493,7 +12493,7 @@ Object { "type": "TSStringKeyword", }, }, - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, ], @@ -19988,7 +19988,7 @@ Object { "type": "TSAnyKeyword", }, }, - "type": "FunctionExpression", + "type": "TSEmptyBodyFunctionExpression", }, }, ], @@ -20409,7 +20409,7 @@ Object { "type": "TSStringKeyword", }, }, - "type": "DeclareFunction", + "type": "TSEmptyBodyDeclareFunction", }, ], "loc": Object { @@ -62800,7 +62800,7 @@ Object { }, }, }, - "type": "TSNamespaceFunctionDeclaration", + "type": "TSEmptyBodyFunctionDeclaration", }, "loc": Object { "end": Object { @@ -63500,7 +63500,7 @@ Object { 93, 110, ], - "type": "TSNamespaceFunctionDeclaration", + "type": "FunctionDeclaration", }, "loc": Object { "end": Object { diff --git a/tools/test-utils.js b/tools/test-utils.js index 1321d98..a005750 100644 --- a/tools/test-utils.js +++ b/tools/test-utils.js @@ -47,7 +47,7 @@ function createSnapshotTestBlock(code, config) { * @returns {Object} the AST object */ function parse() { - const ast = parser.parse(code, config); + const ast = parser.parseForESLint(code, config).ast; return getRaw(ast); }