diff --git a/.gitignore b/.gitignore index d2ccb92..2ff4964 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ coverage node_modules npm-debug.log _test.js -.DS_Store \ No newline at end of file +.DS_Store +.vscode \ No newline at end of file diff --git a/package.json b/package.json index 646e8a3..4b8a2c6 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "license": "BSD-2-Clause", "devDependencies": { "babel-code-frame": "^6.26.0", - "babylon": "^7.0.0-beta.22", + "babylon": "7.0.0-beta.24", "eslint": "4.6.1", "eslint-config-eslint": "4.0.0", "eslint-plugin-node": "5.1.1", @@ -42,7 +42,7 @@ "eslint" ], "scripts": { - "test": "node Makefile.js test", + "test": "node Makefile.js test && npm run ast-alignment-tests", "jest": "jest", "ast-alignment-tests": "jest --config={} ./tests/ast-alignment/spec.js", "lint": "node Makefile.js lint", diff --git a/tests/ast-alignment/fixtures-to-test.js b/tests/ast-alignment/fixtures-to-test.js new file mode 100644 index 0000000..c9632d4 --- /dev/null +++ b/tests/ast-alignment/fixtures-to-test.js @@ -0,0 +1,493 @@ +"use strict"; + +const path = require("path"); +const glob = require("glob"); + +/** + * JSX fixtures which have known issues for typescript-eslint-parser + */ +const jsxFilesWithKnownIssues = require("../jsx-known-issues").map(f => f.replace("jsx/", "")); + +/** + * Current random error difference on jsx/invalid-no-tag-name.src.js + * TSEP - SyntaxError + * Babylon - RangeError + * + * Reported here: https://github.com/babel/babylon/issues/674 + */ +jsxFilesWithKnownIssues.push("invalid-no-tag-name"); + +/** + * Custom constructs/concepts used in this file: + * + * type Pattern = string; // used for node-glob matching + * + * interface FixturePatternConfig { + * pattern: Pattern, + * config?: { + * babylonParserOptions: any, + * typeScriptESLintParserOptions: any + * } + * } + */ + +/** + * Globally track which fixtures need to be parsed with sourceType: "module" + * so that they can be added with the correct FixturePatternConfig + */ +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 + */ +function createFixturePatternConfigFor(fixturesSubPath, config) { + if (!fixturesSubPath) { + return ""; + } + config = config || {}; + config.ignore = config.ignore || []; + config.fileType = config.fileType || "js"; + config.parseWithSourceTypeModule = config.parseWithSourceTypeModule || []; + /** + * The TypeScript compiler gives us the "externalModuleIndicator" to allow typescript-eslint-parser do dynamically detect the "sourceType". + * Babylon does not have an equivalent feature (although perhaps it might come in the future https://github.com/babel/babylon/issues/440), + * so we have to specify the "sourceType" we want to use. + * + * By default we have configured babylon to use "script", but for any fixtures specified in the parseWithSourceTypeModule array we need "module". + * + * First merge the fixtures which need to be parsed with sourceType: "module" into the + * ignore list, and then add their full config into the global array. + */ + if (config.parseWithSourceTypeModule.length) { + config.ignore = [].concat(config.ignore, config.parseWithSourceTypeModule); + fixturesRequiringSourceTypeModule = [].concat(fixturesRequiringSourceTypeModule, config.parseWithSourceTypeModule.map( + fixture => ({ + // It needs to be the full path from within fixtures/ for the pattern + pattern: `${fixturesSubPath}/${fixture}.src.${config.fileType}`, + config: { babylonParserOptions: { sourceType: "module" } } + }) + )); + } + return { + pattern: `${fixturesSubPath}/!(${config.ignore.join("|")}).src.${config.fileType}` + }; +} + +/** + * An array of FixturePatternConfigs + */ +let fixturePatternConfigsToTest = [ + createFixturePatternConfigFor("basics"), + + createFixturePatternConfigFor("comments", { + ignore: [ + "export-default-anonymous-class", // needs to be parsed with `sourceType: "module"` + /** + * Template strings seem to also be affected by the difference in opinion between different parsers in: + * https://github.com/babel/babylon/issues/673 + */ + "no-comment-template", // Purely AST diffs + "template-string-block" // Purely AST diffs + ] + }), + + createFixturePatternConfigFor("ecma-features/templateStrings", { + ignore: [ + "**/*" + ] + }), + + createFixturePatternConfigFor("ecma-features/experimentalObjectRestSpread", { + ignore: [ + /** + * "ExperimentalSpreadProperty" in espree/typescript-eslint-parser vs "SpreadElement" in Babylon + * comes up a lot in this section + */ + "**/*" + ] + }), + + createFixturePatternConfigFor("ecma-features/arrowFunctions", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "error-dup-params", // babylon parse errors + "error-dup-params", // babylon parse errors + "error-strict-dup-params", // babylon parse errors + "error-strict-octal", // babylon parse errors + "error-two-lines" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/binaryLiterals"), + createFixturePatternConfigFor("ecma-features/blockBindings"), + + createFixturePatternConfigFor("ecma-features/classes", { + ignore: [ + /** + * super() is being used outside of constructor. Other parsers (e.g. espree, acorn) do not error on this. + */ + "class-one-method-super", // babylon parse errors + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "invalid-class-declaration", // babylon parse errors + "invalid-class-setter-declaration" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/defaultParams"), + + createFixturePatternConfigFor("ecma-features/destructuring", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "invalid-defaults-object-assign" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/destructuring-and-arrowFunctions"), + createFixturePatternConfigFor("ecma-features/destructuring-and-blockBindings"), + createFixturePatternConfigFor("ecma-features/destructuring-and-defaultParams"), + createFixturePatternConfigFor("ecma-features/destructuring-and-forOf"), + + createFixturePatternConfigFor("ecma-features/destructuring-and-spread", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "error-complex-destructured-spread-first" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/experimentalAsyncIteration"), + createFixturePatternConfigFor("ecma-features/experimentalDynamicImport"), + createFixturePatternConfigFor("ecma-features/exponentiationOperators"), + + createFixturePatternConfigFor("ecma-features/forOf", { + ignore: [ + /** + * TypeScript, espree and acorn parse this fine - esprima, flow and babylon do not... + */ + "for-of-with-function-initializer" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/generators"), + createFixturePatternConfigFor("ecma-features/globalReturn"), + + createFixturePatternConfigFor("ecma-features/modules", { + ignore: [ + /** + * TypeScript, flow and babylon parse this fine - esprima, espree and acorn do not... + */ + "invalid-export-default", // typescript-eslint-parser parse errors + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "invalid-export-named-default", // babylon parse errors + "invalid-import-default-module-specifier", // babylon parse errors + "invalid-import-module-specifier", // babylon parse errors + /** + * Deleting local variable in strict mode + */ + "error-delete", // babylon parse errors + /** + * 'with' in strict mode + */ + "error-strict" // babylon parse errors + ], + parseWithSourceTypeModule: [ + "export-default-array", + "export-default-class", + "export-default-expression", + "export-default-function", + "export-default-named-class", + "export-default-named-function", + "export-default-number", + "export-default-object", + "export-default-value", + "export-from-batch", + "export-from-default", + "export-from-named-as-default", + "export-from-named-as-specifier", + "export-from-named-as-specifiers", + "export-from-specifier", + "export-from-specifiers", + "export-function", + "export-named-as-default", + "export-named-as-specifier", + "export-named-as-specifiers", + "export-named-class", + "export-named-empty", + "export-named-specifier", + "export-named-specifiers-comma", + "export-named-specifiers", + "export-var-anonymous-function", + "export-var-number", + "export-var", + "import-default-and-named-specifiers", + "import-default-and-namespace-specifiers", + "import-default-as", + "import-default", + "import-jquery", + "import-module", + "import-named-as-specifier", + "import-named-as-specifiers", + "import-named-empty", + "import-named-specifier", + "import-named-specifiers-comma", + "import-named-specifiers", + "import-namespace-specifier", + "import-null-as-nil", + "invalid-await", + "invalid-class" + ] + }), + + createFixturePatternConfigFor("ecma-features/newTarget", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "invalid-new-target", // babylon parse errors + "invalid-unknown-property" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/objectLiteralComputedProperties"), + + createFixturePatternConfigFor("ecma-features/objectLiteralDuplicateProperties", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "error-proto-property", // babylon parse errors + "error-proto-string-property" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/objectLiteralShorthandMethods"), + createFixturePatternConfigFor("ecma-features/objectLiteralShorthandProperties"), + createFixturePatternConfigFor("ecma-features/octalLiterals"), + createFixturePatternConfigFor("ecma-features/regex"), + createFixturePatternConfigFor("ecma-features/regexUFlag"), + createFixturePatternConfigFor("ecma-features/regexYFlag"), + + createFixturePatternConfigFor("ecma-features/restParams", { + ignore: [ + /** + * Expected babylon parse errors - all of these files below produce parse errors in espree + * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser + * does not actually error on them and will produce an AST. + */ + "error-no-default", // babylon parse errors + "error-not-last" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("ecma-features/spread"), + createFixturePatternConfigFor("ecma-features/unicodeCodePointEscapes"), + createFixturePatternConfigFor("jsx", { ignore: jsxFilesWithKnownIssues }), + createFixturePatternConfigFor("jsx-useJSXTextNode"), + + /* ================================================== */ + + /** + * TYPESCRIPT-SPECIFIC FILES + */ + + createFixturePatternConfigFor("typescript/babylon-convergence", { fileType: "ts" }), + + createFixturePatternConfigFor("typescript/basics", { + fileType: "ts", + ignore: [ + /** + * Other babylon parse errors relating to invalid syntax. + */ + "abstract-class-with-abstract-constructor", // babylon parse errors + "class-with-export-parameter-properties", // babylon parse errors + "class-with-optional-methods", // babylon parse errors + "class-with-static-parameter-properties", // babylon parse errors + "interface-with-all-property-types", // babylon parse errors + "interface-with-construct-signature-with-parameter-accessibility", // babylon parse errors + "class-with-implements-and-extends", // babylon parse errors + /** + * typescript-eslint-parser erroring, but babylon not. + */ + "arrow-function-with-type-parameters", // typescript-eslint-parser parse errors + /** + * Babylon: ClassDeclaration + abstract: true + * tsep: TSAbstractClassDeclaration + */ + "abstract-class-with-abstract-properties", + /** + * Babylon: ClassProperty + abstract: true + * tsep: TSAbstractClassProperty + */ + "abstract-class-with-abstract-readonly-property", + /** + * Babylon: TSExpressionWithTypeArguments + * tsep: ClassImplements + */ + "class-with-implements-generic-multiple", + "class-with-implements-generic", + "class-with-implements", + "class-with-extends-and-implements", + /** + * Babylon: TSDeclareFunction + declare: true + * tsep: DeclareFunction + */ + "declare-function", + /** + * Other major AST differences (e.g. fundamentally different node types) + */ + "class-with-mixin", + "function-with-types-assignation", + "interface-extends-multiple", + "interface-extends", + "interface-type-parameters", + "interface-with-extends-type-parameters", + "interface-with-generic", + "interface-with-jsdoc", + "interface-with-optional-properties", + "interface-without-type-annotation", + "type-alias-declaration-with-constrained-type-parameter", + "type-alias-declaration", + "type-alias-object-without-annotation", + "typed-this", + "class-with-optional-properties", + "class-with-optional-property-undefined", + "export-type-function-declaration", + "export-type-class-declaration", + "abstract-interface", + "export-type-alias-declaration", + /** + * tsep bug - Program.body[0].expression.left.properties[0].value.right is currently showing up + * as `ArrayPattern`, babylon, acorn and espree say it should be `ArrayExpression` + * TODO: Fix this + */ + "destructuring-assignment", + /** + * Babylon bug for optional or abstract methods? + */ + "abstract-class-with-abstract-method", // babylon parse errors + "abstract-class-with-optional-method", // babylon parse errors + "declare-class-with-optional-method", // babylon parse errors + /** + * Awaiting feedback on Babylon issue https://github.com/babel/babylon/issues/700 + */ + "class-with-private-parameter-properties", + "class-with-protected-parameter-properties", + "class-with-public-parameter-properties", + "class-with-readonly-parameter-properties" + ], + parseWithSourceTypeModule: [ + "export-named-enum", + "export-assignment", + "export-default-class-with-generic", + "export-default-class-with-multiple-generics", + "export-named-class-with-generic", + "export-named-class-with-multiple-generics" + ] + }), + + createFixturePatternConfigFor("typescript/decorators/accessor-decorators", { fileType: "ts" }), + createFixturePatternConfigFor("typescript/decorators/class-decorators", { fileType: "ts" }), + createFixturePatternConfigFor("typescript/decorators/method-decorators", { fileType: "ts" }), + createFixturePatternConfigFor("typescript/decorators/parameter-decorators", { fileType: "ts" }), + createFixturePatternConfigFor("typescript/decorators/property-decorators", { fileType: "ts" }), + + createFixturePatternConfigFor("typescript/expressions", { fileType: "ts" }), + + createFixturePatternConfigFor("typescript/errorRecovery", { + fileType: "ts", + ignore: [ + /** + * AST difference + */ + "interface-empty-extends", + /** + * TypeScript-specific tests taken from "errorRecovery". Babylon is not being as forgiving as the TypeScript compiler here. + */ + "class-empty-extends-implements", // babylon parse errors + "class-empty-extends", // babylon parse errors + "decorator-on-enum-declaration", // babylon parse errors + "interface-property-modifiers", // babylon parse errors + "enum-with-keywords" // babylon parse errors + ] + }), + + createFixturePatternConfigFor("typescript/namespaces-and-modules", { + fileType: "ts", + ignore: [ + /** + * Minor AST difference + */ + "nested-internal-module", + /** + * Babylon: TSDeclareFunction + * tsep: TSNamespaceFunctionDeclaration + */ + "declare-namespace-with-exported-function", + /** + * Babylon: FunctionDeclaration + * tsep: TSNamespaceFunctionDeclaration + */ + "module-with-default-exports" + ] + }) +]; + +/** + * Add in all the fixtures which need to be parsed with sourceType: "module" + */ +fixturePatternConfigsToTest = [].concat(fixturePatternConfigsToTest, fixturesRequiringSourceTypeModule); + +/** + * interface Fixture { + * filename: string, + * config?: any + * } + */ +const fixturesToTest = []; +const fixturesDirPath = path.join(__dirname, "../fixtures"); + +/** + * Resolve the glob patterns into actual Fixture files that we can run assertions for... + */ +fixturePatternConfigsToTest.forEach(fixturePatternConfig => { + /** + * Find the fixture files which match the given pattern + */ + const matchingFixtures = glob.sync(`${fixturesDirPath}/${fixturePatternConfig.pattern}`, {}); + matchingFixtures.forEach(filename => { + fixturesToTest.push({ + filename, + config: fixturePatternConfig.config + }); + }); +}); + +module.exports = fixturesToTest; diff --git a/tests/ast-alignment/known-issues.js b/tests/ast-alignment/known-issues.js deleted file mode 100644 index ab98bbf..0000000 --- a/tests/ast-alignment/known-issues.js +++ /dev/null @@ -1,90 +0,0 @@ -"use strict"; - -/** - * ================================================== - * KNOWN/DIAGNOSED ISSUES - * ================================================== - */ - -module.exports = [ - /** - * "ExperimentalSpreadProperty" in espree/typescript-eslint-parser vs "SpreadElement" in Babylon - * comes up a lot in this section - */ - // "ecma-features/experimentalObjectRestSpread/**/*.src.js", // mixture of babylon parse errors and AST diffs - - /* ================================================== */ - - /** - * Template strings seem to also be affected by the difference in opinion between different parsers in: - * https://github.com/babel/babylon/issues/673 - */ - // "comments/no-comment-template.src.js", // Purely AST diffs - // "comments/template-string-block.src.js", // Purely AST diffs - // "ecma-features/templateStrings/**/*.src.js", // mixture of babylon parse errors and AST diffs - - /* ================================================== */ - - /** - * TypeScript, espree and acorn parse this fine - esprima, flow and babylon do not... - */ - // "ecma-features/forOf/for-of-with-function-initializer.src.js", // babylon parse errors - - /* ================================================== */ - - /** - * TypeScript, flow and babylon parse this fine - esprima, espree and acorn do not... - */ - // "ecma-features/modules/invalid-export-default.src.js",, // typescript-eslint-parser parse errors - - /* ================================================== */ - - /** - * Babylon parse error because of more strict spec enforcement than other parsers. - */ - - /** - * super() is being used outside of constructor. Other parsers (e.g. espree, acorn) do not error on this. - */ - // "ecma-features/classes/class-one-method-super.src.js", // babylon parse errors - - /* ================================================== */ - - /** - * Expected babylon parse errors - all of these files below produce parse errors in espree - * as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser - * does not actually error on them and will produce an AST. - */ - // "ecma-features/arrowFunctions/error-dup-params.src.js", // babylon parse errors - // "ecma-features/arrowFunctions/error-dup-params.src.js", // babylon parse errors - // "ecma-features/arrowFunctions/error-strict-dup-params.src.js", // babylon parse errors - // "ecma-features/arrowFunctions/error-strict-octal.src.js", // babylon parse errors - // "ecma-features/arrowFunctions/error-two-lines.src.js", // babylon parse errors - // "ecma-features/classes/invalid-class-declaration.src.js", // babylon parse errors - // "ecma-features/classes/invalid-class-setter-declaration.src.js", // babylon parse errors - // "ecma-features/destructuring/invalid-defaults-object-assign.src.js", // babylon parse errors - // "ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.src.js", // babylon parse errors - // "ecma-features/objectLiteralDuplicateProperties/error-proto-property.src.js", // babylon parse errors - // "ecma-features/objectLiteralDuplicateProperties/error-proto-string-property.src.js", // babylon parse errors - // "ecma-features/modules/invalid-export-named-default.src.js", // babylon parse errors - // "ecma-features/modules/invalid-import-default-module-specifier.src.js", // babylon parse errors - // "ecma-features/modules/invalid-import-module-specifier.src.js", // babylon parse errors - // "ecma-features/newTarget/invalid-new-target.src.js", // babylon parse errors - // "ecma-features/newTarget/invalid-unknown-property.src.js", // babylon parse errors - // "ecma-features/restParams/error-no-default.src.js", // babylon parse errors - // "ecma-features/restParams/error-not-last.src.js", // babylon parse errors - /** - * Deleting local variable in strict mode - */ - // { - // pattern: "ecma-features/modules/error-delete.src.js", - // config: { babylonParserOptions: { sourceType: "module" } } - // }, - /** - * 'with' in strict mode - */ - // { - // pattern: "ecma-features/modules/error-strict.src.js", - // config: { babylonParserOptions: { sourceType: "module" } } - // }, -]; diff --git a/tests/ast-alignment/spec.js b/tests/ast-alignment/spec.js index 4f2c5ff..3c9114a 100644 --- a/tests/ast-alignment/spec.js +++ b/tests/ast-alignment/spec.js @@ -1,723 +1,14 @@ "use strict"; const fs = require("fs"); -const path = require("path"); -const glob = require("glob"); + const parse = require("./parse"); const parseUtils = require("./utils"); - -/** - * JSX fixtures which have known issues for typescript-eslint-parser - */ -const jsxFilesWithKnownIssues = require("../jsx-known-issues"); - -/** - * Current random error difference on jsx/invalid-no-tag-name.src.js - * TSEP - SyntaxError - * Babylon - RangeError - * - * Reported here: https://github.com/babel/babylon/issues/674 - */ -jsxFilesWithKnownIssues.push("jsx/invalid-no-tag-name"); - -const jsxPattern = `jsx/!(${jsxFilesWithKnownIssues.map(f => f.replace("jsx/", "")).join("|")}).src.js`; - -const fixturesDirPath = path.join(__dirname, "../fixtures"); - -// Either a string of the pattern, or an object containing the pattern and some additional config -const fixturePatternsToTest = [ - "basics/**/*.src.js", - - "comments/block-trailing-comment.src.js", - "comments/comment-within-condition.src.js", - "comments/jsx-block-comment.src.js", - "comments/jsx-tag-comments.src.js", - "comments/line-comment-with-block-syntax.src.js", - "comments/mix-line-and-block-comments.src.js", - "comments/no-comment-regex.src.js", - "comments/surrounding-call-comments.src.js", - "comments/surrounding-debugger-comments.src.js", - "comments/surrounding-return-comments.src.js", - "comments/surrounding-throw-comments.src.js", - "comments/surrounding-while-loop-comments.src.js", - "comments/switch-fallthrough-comment-in-function.src.js", - "comments/switch-fallthrough-comment.src.js", - "comments/switch-no-default-comment-in-function.src.js", - "comments/switch-no-default-comment-in-nested-functions.src.js", - "comments/switch-no-default-comment.src.js", - - "ecma-features/arrowFunctions/as-param-with-params.src.js", - "ecma-features/arrowFunctions/as-param.src.js", - "ecma-features/arrowFunctions/basic.src.js", - "ecma-features/arrowFunctions/basic-in-binary-expression.src.js", - "ecma-features/arrowFunctions/block-body-not-object.src.js", - "ecma-features/arrowFunctions/block-body.src.js", - "ecma-features/arrowFunctions/error-missing-paren.src.js", - "ecma-features/arrowFunctions/error-not-arrow.src.js", - "ecma-features/arrowFunctions/error-numeric-param-multi.src.js", - "ecma-features/arrowFunctions/error-numeric-param.src.js", - "ecma-features/arrowFunctions/error-reverse-arrow.src.js", - "ecma-features/arrowFunctions/error-strict-default-param-eval.src.js", - "ecma-features/arrowFunctions/error-strict-eval-return.src.js", - "ecma-features/arrowFunctions/error-strict-eval.src.js", - "ecma-features/arrowFunctions/error-strict-param-arguments.src.js", - "ecma-features/arrowFunctions/error-strict-param-eval.src.js", - "ecma-features/arrowFunctions/error-strict-param-names.src.js", - "ecma-features/arrowFunctions/error-strict-param-no-paren-arguments.src.js", - "ecma-features/arrowFunctions/error-strict-param-no-paren-eval.src.js", - "ecma-features/arrowFunctions/error-wrapped-param.src.js", - "ecma-features/arrowFunctions/expression.src.js", - "ecma-features/arrowFunctions/iife.src.js", - "ecma-features/arrowFunctions/multiple-params.src.js", - "ecma-features/arrowFunctions/no-auto-return.src.js", - "ecma-features/arrowFunctions/not-strict-arguments.src.js", - "ecma-features/arrowFunctions/not-strict-eval-params.src.js", - "ecma-features/arrowFunctions/not-strict-eval.src.js", - "ecma-features/arrowFunctions/not-strict-octal.src.js", - "ecma-features/arrowFunctions/return-arrow-function.src.js", - "ecma-features/arrowFunctions/return-sequence.src.js", - "ecma-features/arrowFunctions/single-param-parens.src.js", - "ecma-features/arrowFunctions/single-param-return-identifier.src.js", - "ecma-features/arrowFunctions/single-param.src.js", - "ecma-features/binaryLiterals/**/*.src.js", - "ecma-features/blockBindings/**/*.src.js", - "ecma-features/classes/class-accessor-properties.src.js", - "ecma-features/classes/class-computed-static-method.src.js", - "ecma-features/classes/class-expression.src.js", - "ecma-features/classes/class-method-named-prototype.src.js", - "ecma-features/classes/class-method-named-static.src.js", - "ecma-features/classes/class-method-named-with-space.src.js", - "ecma-features/classes/class-one-method.src.js", - "ecma-features/classes/class-static-method-named-prototype.src.js", - "ecma-features/classes/class-static-method-named-static.src.js", - "ecma-features/classes/class-static-method.src.js", - "ecma-features/classes/class-static-methods-and-accessor-properties.src.js", - "ecma-features/classes/class-two-computed-static-methods.src.js", - "ecma-features/classes/class-two-methods-computed-constructor.src.js", - "ecma-features/classes/class-two-methods-semi.src.js", - "ecma-features/classes/class-two-methods-three-semi.src.js", - "ecma-features/classes/class-two-methods-two-semi.src.js", - "ecma-features/classes/class-two-methods.src.js", - "ecma-features/classes/class-two-static-methods-named-constructor.src.js", - "ecma-features/classes/class-with-constructor-parameters.src.js", - "ecma-features/classes/class-with-constructor-with-space.src.js", - "ecma-features/classes/class-with-constructor.src.js", - "ecma-features/classes/derived-class-assign-to-var.src.js", - "ecma-features/classes/derived-class-expression.src.js", - "ecma-features/classes/empty-class-double-semi.src.js", - "ecma-features/classes/empty-class-semi.src.js", - "ecma-features/classes/empty-class.src.js", - "ecma-features/classes/empty-literal-derived-class.src.js", - "ecma-features/classes/named-class-expression.src.js", - "ecma-features/classes/named-derived-class-expression.src.js", - "ecma-features/defaultParams/**/*.src.js", - "ecma-features/destructuring/array-member.src.js", - "ecma-features/destructuring/array-to-array.src.js", - "ecma-features/destructuring/array-var-undefined.src.js", - "ecma-features/destructuring/class-constructor-params-array.src.js", - "ecma-features/destructuring/class-constructor-params-defaults-array.src.js", - "ecma-features/destructuring/class-constructor-params-defaults-object.src.js", - "ecma-features/destructuring/class-constructor-params-object.src.js", - "ecma-features/destructuring/class-method-params-array.src.js", - "ecma-features/destructuring/class-method-params-defaults-array.src.js", - "ecma-features/destructuring/class-method-params-defaults-object.src.js", - "ecma-features/destructuring/class-method-params-object.src.js", - "ecma-features/destructuring/defaults-array-all.src.js", - "ecma-features/destructuring/defaults-array-longform-nested-multi.src.js", - "ecma-features/destructuring/defaults-array-multi.src.js", - "ecma-features/destructuring/defaults-array-nested-all.src.js", - "ecma-features/destructuring/defaults-array-nested-multi.src.js", - "ecma-features/destructuring/defaults-array.src.js", - "ecma-features/destructuring/defaults-object-all.src.js", - "ecma-features/destructuring/defaults-object-longform-all.src.js", - "ecma-features/destructuring/defaults-object-longform-multi.src.js", - "ecma-features/destructuring/defaults-object-longform.src.js", - "ecma-features/destructuring/defaults-object-mixed-multi.src.js", - "ecma-features/destructuring/defaults-object-multi.src.js", - "ecma-features/destructuring/defaults-object-nested-all.src.js", - "ecma-features/destructuring/defaults-object-nested-multi.src.js", - "ecma-features/destructuring/defaults-object.src.js", - "ecma-features/destructuring/destructured-array-catch.src.js", - "ecma-features/destructuring/destructured-object-catch.src.js", - "ecma-features/destructuring/named-param.src.js", - "ecma-features/destructuring/nested-array.src.js", - "ecma-features/destructuring/nested-object.src.js", - "ecma-features/destructuring/object-var-named.src.js", - "ecma-features/destructuring/object-var-undefined.src.js", - "ecma-features/destructuring/param-defaults-array.src.js", - "ecma-features/destructuring/param-defaults-object-nested.src.js", - "ecma-features/destructuring/param-defaults-object.src.js", - "ecma-features/destructuring/params-array-wrapped.src.js", - "ecma-features/destructuring/params-array.src.js", - "ecma-features/destructuring/params-multi-object.src.js", - "ecma-features/destructuring/params-nested-array.src.js", - "ecma-features/destructuring/params-nested-object.src.js", - "ecma-features/destructuring/params-object-wrapped.src.js", - "ecma-features/destructuring/params-object.src.js", - "ecma-features/destructuring/sparse-array.src.js", - "ecma-features/destructuring-and-arrowFunctions/**/*.src.js", - "ecma-features/destructuring-and-blockBindings/**/*.src.js", - "ecma-features/destructuring-and-defaultParams/**/*.src.js", - "ecma-features/destructuring-and-forOf/**/*.src.js", - "ecma-features/destructuring-and-spread/complex-destructured.src.js", - "ecma-features/destructuring-and-spread/destructured-array-literal.src.js", - "ecma-features/destructuring-and-spread/destructuring-param.src.js", - "ecma-features/destructuring-and-spread/multi-destructured.src.js", - "ecma-features/destructuring-and-spread/single-destructured.src.js", - "ecma-features/destructuring-and-spread/var-complex-destructured.src.js", - "ecma-features/destructuring-and-spread/var-destructured-array-literal.src.js", - "ecma-features/destructuring-and-spread/var-multi-destructured.src.js", - "ecma-features/destructuring-and-spread/var-single-destructured.src.js", - "ecma-features/experimentalAsyncIteration/**/*.src.js", - "ecma-features/experimentalDynamicImport/**/*.src.js", - "ecma-features/exponentiationOperators/**/*.src.js", - "ecma-features/forOf/for-of-with-var-and-braces.src.js", - "ecma-features/forOf/for-of-with-var-and-no-braces.src.js", - "ecma-features/forOf/invalid-for-of-with-const-and-no-braces.src.js", - "ecma-features/forOf/invalid-for-of-with-let-and-no-braces.src.js", - "ecma-features/generators/**/*.src.js", - "ecma-features/globalReturn/**/*.src.js", - "ecma-features/modules/error-function.src.js", - "ecma-features/modules/invalid-export-batch-missing-from-clause.src.js", - "ecma-features/modules/invalid-export-batch-token.src.js", - "ecma-features/modules/invalid-export-default-equal.src.js", - "ecma-features/modules/invalid-export-default-token.src.js (1ms)", - "ecma-features/modules/invalid-export-named-extra-comma.src.js", - "ecma-features/modules/invalid-export-named-middle-comma.src.js", - "ecma-features/modules/invalid-import-default-after-named-after-default.src.js", - "ecma-features/modules/invalid-import-default-after-named.src.js", - "ecma-features/modules/invalid-import-default-missing-module-specifier.src.js", - "ecma-features/modules/invalid-import-default.src.js (1ms)", - "ecma-features/modules/invalid-import-missing-module-specifier.src.js", - "ecma-features/modules/invalid-import-named-after-named.src.js", - "ecma-features/modules/invalid-import-named-after-namespace.src.js", - "ecma-features/modules/invalid-import-named-as-missing-from.src.js", - "ecma-features/modules/invalid-import-named-extra-comma.src.js", - "ecma-features/modules/invalid-import-named-middle-comma.src.js (1ms)", - "ecma-features/modules/invalid-import-namespace-after-named.src.js", - "ecma-features/modules/invalid-import-namespace-missing-as.src.js", - "ecma-features/newTarget/simple-new-target.src.js", - "ecma-features/objectLiteralComputedProperties/**/*.src.js", - "ecma-features/objectLiteralDuplicateProperties/strict-duplicate-properties.src.js", - "ecma-features/objectLiteralDuplicateProperties/strict-duplicate-string-properties.src.js", - "ecma-features/objectLiteralShorthandMethods/**/*.src.js", - "ecma-features/objectLiteralShorthandProperties/**/*.src.js", - "ecma-features/octalLiterals/**/*.src.js", - "ecma-features/regex/**/*.src.js", - "ecma-features/regexUFlag/**/*.src.js", - "ecma-features/regexYFlag/**/*.src.js", - "ecma-features/restParams/basic-rest.src.js", - "ecma-features/restParams/class-constructor.src.js", - "ecma-features/restParams/class-method.src.js", - "ecma-features/restParams/func-expression-multi.src.js", - "ecma-features/restParams/func-expression.src.js", - "ecma-features/restParams/invalid-rest-param.src.js", - "ecma-features/restParams/single-rest.src.js", - "ecma-features/spread/**/*.src.js", - "ecma-features/unicodeCodePointEscapes/**/*.src.js", - - jsxPattern, - - "jsx-useJSXTextNode/**/*.src.js", - - /** - * The TypeScript compiler gives us the "externalModuleIndicator" to allow typescript-eslint-parser do dynamically detect the "sourceType". - * Babylon does not have an equivalent feature (although perhaps it might come in the future https://github.com/babel/babylon/issues/440), - * so we have to specify the "sourceType" we want to use. - * - * By default we have configured babylon to use "script", but for the examples below we need "module". - */ - { - pattern: "comments/export-default-anonymous-class.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-array.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-class.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-expression.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-function.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-named-class.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-named-function.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-number.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-object.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-default-value.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-batch.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-default.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-named-as-default.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-named-as-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-named-as-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-from-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-function.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-as-default.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-as-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-as-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-class.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-empty.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-specifiers-comma.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-named-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-var-anonymous-function.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-var-number.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/export-var.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-default-and-named-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-default-and-namespace-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-default-as.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-default.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-jquery.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-module.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-as-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-as-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-empty.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-specifiers-comma.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-named-specifiers.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-namespace-specifier.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/import-null-as-nil.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/invalid-await.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "ecma-features/modules/invalid-class.src.js", - config: { babylonParserOptions: { sourceType: "module" } } - }, - - /* ================================================== */ - - /** - * TYPESCRIPT-SPECIFIC FILES - */ - - /** - * No issues - */ - "typescript/basics/async-function-expression.src.ts", - "typescript/basics/async-function-with-var-declaration.src.ts", - "typescript/basics/function-with-await.src.ts", - "typescript/errorRecovery/class-extends-empty-implements.src.ts", - "typescript/basics/const-enum.src.ts", - "typescript/basics/class-with-readonly-property.src.ts", - "typescript/expressions/call-expression-type-arguments.src.ts", - "typescript/expressions/new-expression-type-arguments.src.ts", - "typescript/basics/function-with-types.src.ts", - "typescript/basics/non-null-assertion-operator.src.ts", - "typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts", - "typescript/basics/class-with-accessibility-modifiers.src.ts", - "typescript/basics/class-with-optional-computed-property.src.ts", - "typescript/basics/object-with-escaped-properties.src.ts", - "typescript/decorators/parameter-decorators/parameter-decorator-constructor.src.ts", - "typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src.ts", - "typescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src.ts", - "typescript/decorators/parameter-decorators/parameter-decorator-instance-member.src.ts", - "typescript/decorators/parameter-decorators/parameter-decorator-static-member.src.ts", - "typescript/basics/function-with-object-type-with-optional-properties.src.ts", - "typescript/basics/function-with-object-type-without-annotation.src.ts", - "typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts", - "typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts", - "typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts", - "typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts", - "typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts", - "typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts", - "typescript/decorators/method-decorators/method-decorator-instance-member.src.ts", - "typescript/decorators/method-decorators/method-decorator-static-member.src.ts", - "typescript/decorators/property-decorators/property-decorator-factory-instance-member.src.ts", - "typescript/decorators/property-decorators/property-decorator-factory-static-member.src.ts", - "typescript/decorators/property-decorators/property-decorator-instance-member.src.ts", - "typescript/decorators/property-decorators/property-decorator-static-member.src.ts", - "typescript/decorators/class-decorators/class-decorator-factory.src.ts", - "typescript/decorators/class-decorators/class-decorator.src.ts", - "typescript/babylon-convergence/type-parameters.src.ts", - "typescript/babylon-convergence/type-parameter-whitespace-loc.src.ts", - "typescript/basics/class-with-type-parameter-default.src.ts", - "typescript/basics/class-with-type-parameter-underscore.src.ts", - "typescript/basics/class-with-type-parameter.src.ts", - "typescript/basics/function-with-type-parameters-that-have-comments.src.ts", - "typescript/basics/function-with-type-parameters-with-constraint.src.ts", - "typescript/basics/function-with-type-parameters.src.ts", - "typescript/basics/type-parameters-comments.src.ts", - "typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts", - "typescript/basics/var-with-type.src.ts", - "typescript/basics/class-with-extends-generic-multiple.src.ts", - "typescript/basics/class-with-extends-generic.src.ts", - "typescript/basics/nested-type-arguments.src.ts", - "typescript/basics/null-and-undefined-type-annotations.src.ts", - "typescript/basics/var-with-dotted-type.src.ts", - "typescript/basics/variable-declaration-type-annotation-spacing.src.ts", - "typescript/basics/class-with-generic-method-default.src.ts", - "typescript/basics/class-with-generic-method.src.ts", - "typescript/basics/type-guard.src.ts", - "typescript/basics/never-type-param.src.ts", - { - pattern: "typescript/basics/export-named-enum.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "typescript/basics/export-assignment.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "typescript/basics/export-default-class-with-generic.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "typescript/basics/export-default-class-with-multiple-generics.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "typescript/basics/export-named-class-with-generic.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - }, - { - pattern: "typescript/basics/export-named-class-with-multiple-generics.src.ts", - config: { babylonParserOptions: { sourceType: "module" } } - } - - /** - * TypeScript-specific tests taken from "errorRecovery". Babylon is not being as forgiving as the TypeScript compiler here. - */ - // "typescript/errorRecovery/class-empty-extends-implements.src.ts", // babylon parse errors - // "typescript/errorRecovery/class-empty-extends.src.ts", // babylon parse errors - // "typescript/errorRecovery/decorator-on-enum-declaration.src.ts", // babylon parse errors - // "typescript/errorRecovery/interface-property-modifiers.src.ts", // babylon parse errors - // "typescript/errorRecovery/enum-with-keywords.src.ts" // babylon parse errors - - /** - * Other babylon parse errors relating to invalid syntax. - */ - // "typescript/basics/abstract-class-with-abstract-constructor.src.ts", // babylon parse errors - // "typescript/basics/class-with-export-parameter-properties.src.ts", // babylon parse errors - // "typescript/basics/class-with-optional-methods.src.ts", // babylon parse errors - // "typescript/basics/class-with-static-parameter-properties.src.ts", // babylon parse errors - // "typescript/basics/interface-with-all-property-types.src.ts", // babylon parse errors - // "typescript/basics/interface-with-construct-signature-with-parameter-accessibility.src.ts", // babylon parse errors - - /** - * typescript-eslint-parser erroring, but babylon not. - */ - // "typescript/basics/arrow-function-with-type-parameters.src.ts" // typescript-eslint-parser parse errors - - /* ================================================== */ - - /** - * TypeScript AST differences which need to be resolved - */ - - /** - * Identified major AST differences - */ - - /** - * Babylon: ClassDeclaration + abstract: true - * tsep: TSAbstractClassDeclaration - */ - // "typescript/basics/abstract-class-with-abstract-properties.src.ts", - - /** - * Babylon: ClassProperty + abstract: true - * tsep: TSAbstractClassProperty - */ - // "typescript/basics/abstract-class-with-abstract-readonly-property.src.ts", - - /** - * Babylon: TSExpressionWithTypeArguments - * tsep: ClassImplements - */ - // "typescript/basics/class-with-implements-generic-multiple.src.ts", - // "typescript/basics/class-with-implements-generic.src.ts", - // "typescript/basics/class-with-implements.src.ts", - - /** - * Babylon: TSDeclareFunction + declare: true - * tsep: DeclareFunction - */ - // "typescript/basics/declare-function.src.ts", - - /** - * Babylon: TSDeclareFunction - * tsep: TSNamespaceFunctionDeclaration - */ - // "typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts", - - /** - * Babylon: FunctionDeclaration - * tsep: TSNamespaceFunctionDeclaration - */ - // "typescript/namespaces-and-modules/module-with-default-exports.src.ts", - - /** - * Other major AST differences (e.g. fundamentally different node types) - */ - // "typescript/basics/class-with-mixin.src.ts", - // "typescript/basics/function-with-types-assignation.src.ts", - // "typescript/basics/interface-extends-multiple.src.ts", - // "typescript/basics/interface-extends.src.ts", - // "typescript/basics/interface-type-parameters.src.ts", - // "typescript/basics/interface-with-extends-type-parameters.src.ts", - // "typescript/basics/interface-with-generic.src.ts", - // "typescript/basics/interface-with-jsdoc.src.ts", - // "typescript/basics/interface-with-optional-properties.src.ts", - // "typescript/basics/interface-without-type-annotation.src.ts", - // "typescript/basics/type-alias-declaration-with-constrained-type-parameter.src.ts", - // "typescript/basics/type-alias-declaration.src.ts", - // "typescript/basics/type-alias-object-without-annotation.src.ts", - // "typescript/basics/typed-this.src.ts", - // "typescript/errorRecovery/interface-empty-extends.src.ts", - // "typescript/basics/class-with-optional-properties.src.ts", - // "typescript/basics/class-with-optional-property-undefined.src.ts", - // "typescript/namespaces-and-modules/nested-internal-module.src.ts", - // "typescript/basics/export-type-function-declaration.src.ts", - // "typescript/basics/export-type-class-declaration.src.ts", - // "typescript/basics/abstract-interface.src.ts", - - /** - * tsep bug - Program.body[0].expression.left.properties[0].value.right is currently showing up - * as `ArrayPattern`, babylon, acorn and espree say it should be `ArrayExpression` - * TODO: Fix this - */ - // "typescript/basics/destructuring-assignment.src.ts", - - /** - * Babylon bug for optional or abstract methods? - */ - // "typescript/basics/abstract-class-with-abstract-method.src.ts", // babylon parse errors - // "typescript/basics/abstract-class-with-optional-method.src.ts", // babylon parse errors - // "typescript/basics/declare-class-with-optional-method.src.ts", // babylon parse errors - - /** - * Awaiting feedback on Babylon issue https://github.com/babel/babylon/issues/700 - */ - // "typescript/basics/class-with-private-parameter-properties.src.ts", - // "typescript/basics/class-with-protected-parameter-properties.src.ts", - // "typescript/basics/class-with-public-parameter-properties.src.ts", - // "typescript/basics/class-with-readonly-parameter-properties.src.ts", -]; - -// Either a string of the pattern, or an object containing the pattern and some additional config -const fixturesToTest = []; - -fixturePatternsToTest.forEach(fixturePattern => { - const globPattern = (typeof fixturePattern === "string") ? fixturePattern : fixturePattern.pattern; - const matchingFixtures = glob.sync(`${fixturesDirPath}/${globPattern}`, {}); - matchingFixtures.forEach(filename => { - if (typeof fixturePattern === "string") { - fixturesToTest.push(filename); - } else { - fixturesToTest.push({ - filename, - config: fixturePattern.config - }); - } - }); -}); - -/* eslint-disable */ -/** - * Common predicates for Babylon AST preprocessing - */ -const always = () => true; -const ifNumber = (val) => typeof val === "number"; -/* eslint-enable */ - -/** - * - Babylon wraps the "Program" node in an extra "File" node, normalize this for simplicity for now... - * - Remove "start" and "end" values from Babylon nodes to reduce unimportant noise in diffs ("loc" data will still be in - * each final AST and compared). - * - * @param {Object} ast raw babylon AST - * @returns {Object} processed babylon AST - */ -function preprocessBabylonAST(ast) { - return parseUtils.omitDeep(ast.program, [ - { - key: "start", - // only remove the "start" number (not the "start" object within loc) - predicate: ifNumber - }, - { - key: "end", - // only remove the "end" number (not the "end" object within loc) - predicate: ifNumber - }, - { - key: "identifierName", - predicate: always - }, - { - key: "extra", - predicate: always - }, - { - key: "directives", - predicate: always - }, - { - key: "directive", - predicate: always - }, - { - key: "innerComments", - predicate: always - }, - { - key: "leadingComments", - predicate: always - }, - { - key: "trailingComments", - predicate: always - }, - { - key: "guardedHandlers", - predicate: always - } - ]); -} - -/** - * There is currently a really awkward difference in location data for Program nodes - * between different parsers in the ecosystem. Hack around this by removing the data - * before comparing the ASTs. - * - * See: https://github.com/babel/babylon/issues/673 - * - * @param {Object} ast the raw AST with a Program node at its top level - * @returns {Object} the ast with the location data removed from the Program node - */ -function removeLocationDataFromProgramNode(ast) { - delete ast.loc; - delete ast.range; - return ast; -} +const fixturesToTest = require("./fixtures-to-test"); fixturesToTest.forEach(fixture => { - const filename = (typeof fixture === "string") ? fixture : fixture.filename; + const filename = fixture.filename; const source = fs.readFileSync(filename, "utf8").replace(/\r\n/g, "\n"); /** @@ -778,11 +69,11 @@ fixturesToTest.forEach(fixture => { * Perform some extra formatting steps on the babylon AST before comparing */ expect( - removeLocationDataFromProgramNode( - preprocessBabylonAST(babylonTypeScriptPluginResult.ast) + parseUtils.removeLocationDataFromProgramNode( + parseUtils.preprocessBabylonAST(babylonTypeScriptPluginResult.ast) ) ).toEqual( - removeLocationDataFromProgramNode(typeScriptESLintParserResult.ast) + parseUtils.removeLocationDataFromProgramNode(typeScriptESLintParserResult.ast) ); }); diff --git a/tests/ast-alignment/utils.js b/tests/ast-alignment/utils.js index bf8460a..22cca72 100644 --- a/tests/ast-alignment/utils.js +++ b/tests/ast-alignment/utils.js @@ -68,7 +68,87 @@ function omitDeep(obj, keysToOmit) { return obj; } +/* eslint-disable */ +/** + * Common predicates for Babylon AST preprocessing + */ +const always = () => true; +const ifNumber = (val) => typeof val === "number"; +/* eslint-enable */ + +/** + * - Babylon wraps the "Program" node in an extra "File" node, normalize this for simplicity for now... + * - Remove "start" and "end" values from Babylon nodes to reduce unimportant noise in diffs ("loc" data will still be in + * each final AST and compared). + * + * @param {Object} ast raw babylon AST + * @returns {Object} processed babylon AST + */ +function preprocessBabylonAST(ast) { + return omitDeep(ast.program, [ + { + key: "start", + // only remove the "start" number (not the "start" object within loc) + predicate: ifNumber + }, + { + key: "end", + // only remove the "end" number (not the "end" object within loc) + predicate: ifNumber + }, + { + key: "identifierName", + predicate: always + }, + { + key: "extra", + predicate: always + }, + { + key: "directives", + predicate: always + }, + { + key: "directive", + predicate: always + }, + { + key: "innerComments", + predicate: always + }, + { + key: "leadingComments", + predicate: always + }, + { + key: "trailingComments", + predicate: always + }, + { + key: "guardedHandlers", + predicate: always + } + ]); +} + +/** + * There is currently a really awkward difference in location data for Program nodes + * between different parsers in the ecosystem. Hack around this by removing the data + * before comparing the ASTs. + * + * See: https://github.com/babel/babylon/issues/673 + * + * @param {Object} ast the raw AST with a Program node at its top level + * @returns {Object} the ast with the location data removed from the Program node + */ +function removeLocationDataFromProgramNode(ast) { + delete ast.loc; + delete ast.range; + return ast; +} + module.exports = { normalizeNodeTypes, - omitDeep + preprocessBabylonAST, + removeLocationDataFromProgramNode };